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
33 my $dbh = C4::Context->dbh();
34 # Get the template to use
35 my ($template, $loggedinuser, $cookie)
36 = get_template_and_user({template_name => "tools/holidays.tt",
40 flagsrequired => {tools => 'edit_calendar'},
44 # calendardate - date passed in url for human readability (syspref)
45 # if the url has an invalid date default to 'now.'
46 my $calendarinput_dt = eval { dt_from_string( scalar $input->param('calendardate') ); } || dt_from_string;
47 my $calendardate = output_pref( { dt => $calendarinput_dt, dateonly => 1 } );
49 # keydate - date passed to calendar.js. calendar.js does not process dashes within a date.
50 my $keydate = output_pref( { dt => $calendarinput_dt, dateonly => 1, dateformat => 'iso' } );
53 my $branch= $input->param('branch') || C4::Context->userenv->{'branch'};
55 # branches calculated - put branch codes in a single string so they can be passed in a form
56 my $branchcodes = join '|', keys %{$branches};
58 # Get all the holidays
60 my $calendar = C4::Calendar->new(branchcode => $branch);
61 my $week_days_holidays = $calendar->get_week_days_holidays();
63 foreach my $weekday (keys %$week_days_holidays) {
64 # warn "WEEK DAY : $weekday";
66 %week_day = (KEY => $weekday,
67 TITLE => $week_days_holidays->{$weekday}{title},
68 DESCRIPTION => $week_days_holidays->{$weekday}{description});
69 push @week_days, \%week_day;
72 my $day_month_holidays = $calendar->get_day_month_holidays();
73 my @day_month_holidays;
74 foreach my $monthDay (keys %$day_month_holidays) {
75 # Determine date format on month and day.
77 my $day_monthdate_sort;
78 if (C4::Context->preference("dateformat") eq "metric") {
79 $day_monthdate_sort = "$day_month_holidays->{$monthDay}{month}-$day_month_holidays->{$monthDay}{day}";
80 $day_monthdate = "$day_month_holidays->{$monthDay}{day}/$day_month_holidays->{$monthDay}{month}";
81 } elsif (C4::Context->preference("dateformat") eq "dmydot") {
82 $day_monthdate_sort = "$day_month_holidays->{$monthDay}{month}.$day_month_holidays->{$monthDay}{day}";
83 $day_monthdate = "$day_month_holidays->{$monthDay}{day}.$day_month_holidays->{$monthDay}{month}";
84 }elsif (C4::Context->preference("dateformat") eq "us") {
85 $day_monthdate = "$day_month_holidays->{$monthDay}{month}/$day_month_holidays->{$monthDay}{day}";
86 $day_monthdate_sort = $day_monthdate;
88 $day_monthdate = "$day_month_holidays->{$monthDay}{month}-$day_month_holidays->{$monthDay}{day}";
89 $day_monthdate_sort = $day_monthdate;
92 %day_month = (KEY => $monthDay,
93 DATE_SORT => $day_monthdate_sort,
94 DATE => $day_monthdate,
95 TITLE => $day_month_holidays->{$monthDay}{title},
96 DESCRIPTION => $day_month_holidays->{$monthDay}{description});
97 push @day_month_holidays, \%day_month;
100 my $exception_holidays = $calendar->get_exception_holidays();
101 my @exception_holidays;
102 foreach my $yearMonthDay (keys %$exception_holidays) {
103 my $exceptiondate = eval { dt_from_string( $exception_holidays->{$yearMonthDay}{date} ) };
104 my %exception_holiday;
105 %exception_holiday = (KEY => $yearMonthDay,
106 DATE_SORT => $exception_holidays->{$yearMonthDay}{date},
107 DATE => output_pref( { dt => $exceptiondate, dateonly => 1 } ),
108 TITLE => $exception_holidays->{$yearMonthDay}{title},
109 DESCRIPTION => $exception_holidays->{$yearMonthDay}{description});
110 push @exception_holidays, \%exception_holiday;
113 my $single_holidays = $calendar->get_single_holidays();
115 foreach my $yearMonthDay (keys %$single_holidays) {
116 my $holidaydate_dt = eval { dt_from_string( $single_holidays->{$yearMonthDay}{date} ) };
118 %holiday = (KEY => $yearMonthDay,
119 DATE_SORT => $single_holidays->{$yearMonthDay}{date},
120 DATE => output_pref( { dt => $holidaydate_dt, dateonly => 1 } ),
121 TITLE => $single_holidays->{$yearMonthDay}{title},
122 DESCRIPTION => $single_holidays->{$yearMonthDay}{description});
123 push @holidays, \%holiday;
127 WEEK_DAYS_LOOP => \@week_days,
128 HOLIDAYS_LOOP => \@holidays,
129 EXCEPTION_HOLIDAYS_LOOP => \@exception_holidays,
130 DAY_MONTH_HOLIDAYS_LOOP => \@day_month_holidays,
131 calendardate => $calendardate,
133 branchcodes => $branchcodes,
137 # Shows the template with the real values replaced
138 output_html_with_http_headers $input, $cookie, $template->output;