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
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.tmpl",
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.
60 my $onlymine=(C4
::Context
->preference('IndependantBranches') &&
61 C4
::Context
->userenv &&
62 C4
::Context
->userenv->{flags
} % 2 !=1 &&
63 C4
::Context
->userenv->{branch
}?
1:0);
65 $branch = C4
::Context
->userenv->{'branch'};
67 my $branchname = GetBranchName
($branch);
68 my $branches = GetBranches
($onlymine);
70 for my $thisbranch (sort { $branches->{$a}->{branchname
} cmp $branches->{$b}->{branchname
} } keys %$branches) {
71 my $selected = 1 if $thisbranch eq $branch;
72 my %row =(value
=> $thisbranch,
73 selected
=> $selected,
74 branchname
=> $branches->{$thisbranch}->{'branchname'},
76 push @branchloop, \
%row;
78 # branches calculated - put branch codes in a single string so they can be passed in a form
79 my $branchcodes = join("|", keys %$branches);
81 # Get all the holidays
83 my $calendar = C4
::Calendar
->new(branchcode
=> $branch);
84 my $week_days_holidays = $calendar->get_week_days_holidays();
86 foreach my $weekday (keys %$week_days_holidays) {
87 # warn "WEEK DAY : $weekday";
89 %week_day = (KEY
=> $weekday,
90 TITLE
=> $week_days_holidays->{$weekday}{title
},
91 DESCRIPTION
=> $week_days_holidays->{$weekday}{description
});
92 push @week_days, \
%week_day;
95 my $day_month_holidays = $calendar->get_day_month_holidays();
96 my @day_month_holidays;
97 foreach my $monthDay (keys %$day_month_holidays) {
98 # Determine date format on month and day.
100 if (C4
::Context
->preference("dateformat") eq "metric") {
101 $day_monthdate = "$day_month_holidays->{$monthDay}{day}/$day_month_holidays->{$monthDay}{month}";
102 } elsif (C4
::Context
->preference("dateformat") eq "us") {
103 $day_monthdate = "$day_month_holidays->{$monthDay}{month}/$day_month_holidays->{$monthDay}{day}";
105 $day_monthdate = "$day_month_holidays->{$monthDay}{month}-$day_month_holidays->{$monthDay}{day}";
108 %day_month = (KEY
=> $monthDay,
109 DATE
=> $day_monthdate,
110 TITLE
=> $day_month_holidays->{$monthDay}{title
},
111 DESCRIPTION
=> $day_month_holidays->{$monthDay}{description
});
112 push @day_month_holidays, \
%day_month;
115 my $exception_holidays = $calendar->get_exception_holidays();
116 my @exception_holidays;
117 foreach my $yearMonthDay (keys %$exception_holidays) {
118 my $exceptiondate = C4
::Dates
->new($exception_holidays->{$yearMonthDay}{date
}, "iso");
119 my %exception_holiday;
120 %exception_holiday = (KEY
=> $yearMonthDay,
121 DATE
=> $exceptiondate->output("syspref"),
122 TITLE
=> $exception_holidays->{$yearMonthDay}{title
},
123 DESCRIPTION
=> $exception_holidays->{$yearMonthDay}{description
});
124 push @exception_holidays, \
%exception_holiday;
127 my $single_holidays = $calendar->get_single_holidays();
129 foreach my $yearMonthDay (keys %$single_holidays) {
130 my $holidaydate = C4
::Dates
->new($single_holidays->{$yearMonthDay}{date
}, "iso");
132 %holiday = (KEY
=> $yearMonthDay,
133 DATE
=> $holidaydate->output("syspref"),
134 TITLE
=> $single_holidays->{$yearMonthDay}{title
},
135 DESCRIPTION
=> $single_holidays->{$yearMonthDay}{description
});
136 push @holidays, \
%holiday;
139 $template->param(WEEK_DAYS_LOOP
=> \
@week_days,
140 branchloop
=> \
@branchloop,
141 HOLIDAYS_LOOP
=> \
@holidays,
142 EXCEPTION_HOLIDAYS_LOOP
=> \
@exception_holidays,
143 DAY_MONTH_HOLIDAYS_LOOP
=> \
@day_month_holidays,
144 calendardate
=> $calendardate,
146 branchcodes
=> $branchcodes,
148 branchname
=> $branchname
151 # Shows the template with the real values replaced
152 output_html_with_http_headers
$input, $cookie, $template->output;