3 # This file is part of Koha.
5 # Koha is free software; you can redistribute it and/or modify it under the
6 # terms of the GNU General Public License as published by the Free Software
7 # Foundation; either version 2 of the License, or (at your option) any later
10 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
11 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License along with
15 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
16 # Suite 330, Boston, MA 02111-1307 USA
18 #####Sets holiday periods for each branch. Datedues will be extended if branch is closed -TG
30 my $branch=C4::Context->preference('defaultbranch') || $input->param('branch');
34 my $dbh = C4::Context->dbh();
35 # Get the template to use
36 my ($template, $loggedinuser, $cookie)
37 = get_template_and_user({template_name => "tools/holidays.tmpl",
41 flagsrequired => {tools => 1},
45 # Set all the branches.
46 my $branches = $dbh->prepare("select branchcode, branchname from branches");
48 # It creates a list of branches
50 while (my ($branchcode, $branchname) = $branches->fetchrow) {
51 $list{$branchcode} = $branchname;
53 my @listValues = keys(%list);
54 if (!defined($branch)) {
55 $branch =$listValues[4];
57 my $branchesList = CGI::scrolling_list(-name => 'branch',
58 -values => \@listValues,
61 -default => [$branch],
64 -onChange => "changeBranch()");
68 if ( C4::Context->preference("IndependantBranches") ) {
69 $branch = C4::Context->userenv->{'branch'};
71 # Get all the holidays
72 warn "BRANCH : $branch";
74 my $calendar = C4::Calendar->new(branchcode => $branch);
75 my $week_days_holidays = $calendar->get_week_days_holidays();
77 foreach my $weekday (keys %$week_days_holidays) {
78 # warn "WEEK DAY : $weekday";
80 %week_day = (KEY => $weekday,
81 TITLE => $week_days_holidays->{$weekday}{title},
82 DESCRIPTION => $week_days_holidays->{$weekday}{description});
83 push @week_days, \%week_day;
86 my $day_month_holidays = $calendar->get_day_month_holidays();
87 my @day_month_holidays;
88 foreach my $monthDay (keys %$day_month_holidays) {
90 %day_month = (KEY => $monthDay,
91 TITLE => $day_month_holidays->{$monthDay}{title},
92 DESCRIPTION => $day_month_holidays->{$monthDay}{description});
93 push @day_month_holidays, \%day_month;
96 my $exception_holidays = $calendar->get_exception_holidays();
97 my @exception_holidays;
98 foreach my $yearMonthDay (keys %$exception_holidays) {
99 my %exception_holiday;
100 %exception_holiday = (KEY => $yearMonthDay,
101 TITLE => $exception_holidays->{$yearMonthDay}{title},
102 DESCRIPTION => $exception_holidays->{$yearMonthDay}{description});
103 push @exception_holidays, \%exception_holiday;
106 my $single_holidays = $calendar->get_single_holidays();
108 foreach my $yearMonthDay (keys %$single_holidays) {
110 %holiday = (KEY => $yearMonthDay,
111 TITLE => $single_holidays->{$yearMonthDay}{title},
112 DESCRIPTION => $single_holidays->{$yearMonthDay}{description});
113 push @holidays, \%holiday;
116 # Replace the template values with the real ones
117 # If we have independent branches on we need to only let the user set holidays for their branch
118 if ( C4::Context->preference("IndependantBranches") ) {
119 $template->param(BRANCHES => C4::Context->userenv->{'branchname'});
122 $template->param(BRANCHES => $branchesList);
124 $template->param(WEEK_DAYS_LOOP => \@week_days);
125 $template->param(HOLIDAYS_LOOP => \@holidays);
126 $template->param(EXCEPTION_HOLIDAYS_LOOP => \@exception_holidays);
127 $template->param(DAY_MONTH_HOLIDAYS_LOOP => \@day_month_holidays);
128 $template->param(branch => $branch);
130 # Shows the template with the real values replaced
131 output_html_with_http_headers $input, $cookie, $template->output;