3 # This file is part of Koha.
5 # Koha is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
10 # Koha is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with Koha; if not, see <http://www.gnu.org/licenses>.
18 #####Sets holiday periods for each branch. Datedues will be extended if branch is closed -TG
27 use C4
::Branch
; # GetBranches
32 my $dbh = C4
::Context
->dbh();
33 # Get the template to use
34 my ($template, $loggedinuser, $cookie)
35 = get_template_and_user
({template_name
=> "tools/holidays.tt",
39 flagsrequired
=> {tools
=> 'edit_calendar'},
43 # keydate - date passed to calendar.js. calendar.js does not process dashes within a date.
45 # calendardate - date passed in url for human readability (syspref)
47 my $today = C4
::Dates
->new();
48 my $calendarinput = C4
::Dates
->new($input->param('calendardate')) || $today;
49 # if the url has an invalid date default to 'now.'
50 unless($calendardate = $calendarinput->output('syspref')) {
51 $calendardate = $today->output('syspref');
53 unless($keydate = $calendarinput->output('iso')) {
54 $keydate = $today->output('iso');
58 my $branch= $input->param('branch') || C4
::Context
->userenv->{'branch'};
59 # Set all the branches.
61 ( C4
::Context
->preference('IndependentBranches')
62 && C4
::Context
->userenv
63 && !C4
::Context
->IsSuperLibrarian()
64 && C4
::Context
->userenv->{branch
} ?
1 : 0 );
66 $branch = C4
::Context
->userenv->{'branch'};
68 my $branchname = GetBranchName
($branch);
69 my $branches = GetBranches
($onlymine);
72 sort { $branches->{$a}->{branchname
} cmp $branches->{$b}->{branchname
} }
75 { value
=> $thisbranch,
76 selected
=> $thisbranch eq $branch,
77 branchname
=> $branches->{$thisbranch}->{'branchname'},
81 # branches calculated - put branch codes in a single string so they can be passed in a form
82 my $branchcodes = join '|', keys %{$branches};
84 # Get all the holidays
86 my $calendar = C4
::Calendar
->new(branchcode
=> $branch);
87 my $week_days_holidays = $calendar->get_week_days_holidays();
89 foreach my $weekday (keys %$week_days_holidays) {
90 # warn "WEEK DAY : $weekday";
92 %week_day = (KEY
=> $weekday,
93 TITLE
=> $week_days_holidays->{$weekday}{title
},
94 DESCRIPTION
=> $week_days_holidays->{$weekday}{description
});
95 push @week_days, \
%week_day;
98 my $day_month_holidays = $calendar->get_day_month_holidays();
99 my @day_month_holidays;
100 foreach my $monthDay (keys %$day_month_holidays) {
101 # Determine date format on month and day.
103 my $day_monthdate_sort;
104 if (C4
::Context
->preference("dateformat") eq "metric") {
105 $day_monthdate_sort = "$day_month_holidays->{$monthDay}{month}-$day_month_holidays->{$monthDay}{day}";
106 $day_monthdate = "$day_month_holidays->{$monthDay}{day}/$day_month_holidays->{$monthDay}{month}";
107 } elsif (C4
::Context
->preference("dateformat") eq "us") {
108 $day_monthdate = "$day_month_holidays->{$monthDay}{month}/$day_month_holidays->{$monthDay}{day}";
109 $day_monthdate_sort = $day_monthdate;
111 $day_monthdate = "$day_month_holidays->{$monthDay}{month}-$day_month_holidays->{$monthDay}{day}";
112 $day_monthdate_sort = $day_monthdate;
115 %day_month = (KEY
=> $monthDay,
116 DATE_SORT
=> $day_monthdate_sort,
117 DATE
=> $day_monthdate,
118 TITLE
=> $day_month_holidays->{$monthDay}{title
},
119 DESCRIPTION
=> $day_month_holidays->{$monthDay}{description
});
120 push @day_month_holidays, \
%day_month;
123 my $exception_holidays = $calendar->get_exception_holidays();
124 my @exception_holidays;
125 foreach my $yearMonthDay (keys %$exception_holidays) {
126 my $exceptiondate = C4
::Dates
->new($exception_holidays->{$yearMonthDay}{date
}, "iso");
127 my %exception_holiday;
128 %exception_holiday = (KEY
=> $yearMonthDay,
129 DATE_SORT
=> $exception_holidays->{$yearMonthDay}{date
},
130 DATE
=> $exceptiondate->output("syspref"),
131 TITLE
=> $exception_holidays->{$yearMonthDay}{title
},
132 DESCRIPTION
=> $exception_holidays->{$yearMonthDay}{description
});
133 push @exception_holidays, \
%exception_holiday;
136 my $single_holidays = $calendar->get_single_holidays();
138 foreach my $yearMonthDay (keys %$single_holidays) {
139 my $holidaydate = C4
::Dates
->new($single_holidays->{$yearMonthDay}{date
}, "iso");
141 %holiday = (KEY
=> $yearMonthDay,
142 DATE_SORT
=> $single_holidays->{$yearMonthDay}{date
},
143 DATE
=> $holidaydate->output("syspref"),
144 TITLE
=> $single_holidays->{$yearMonthDay}{title
},
145 DESCRIPTION
=> $single_holidays->{$yearMonthDay}{description
});
146 push @holidays, \
%holiday;
150 WEEK_DAYS_LOOP
=> \
@week_days,
151 branchloop
=> \
@branchloop,
152 HOLIDAYS_LOOP
=> \
@holidays,
153 EXCEPTION_HOLIDAYS_LOOP
=> \
@exception_holidays,
154 DAY_MONTH_HOLIDAYS_LOOP
=> \
@day_month_holidays,
155 calendardate
=> $calendardate,
157 branchcodes
=> $branchcodes,
159 branchname
=> $branchname,
163 # Shows the template with the real values replaced
164 output_html_with_http_headers
$input, $cookie, $template->output;