new virtual shelves changes, keyed by biblionumber -- approved
[koha.git] / tools / holidays.pl
1 #!/usr/bin/perl
2
3 # This file is part of Koha.
4 #
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
8 # version.
9 #
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.
13 #
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
17
18 #####Sets holiday periods for each branch. Datedues will be extended if branch is closed -TG
19 use strict;
20 use CGI;
21
22 use C4::Auth;
23 use C4::Output;
24
25
26 use C4::Calendar;
27
28 my $input = new CGI;
29 #my $branch = $input->param('branch');
30 my $branch=C4::Context->preference('defaultbranch') || $input->param('branch');
31 my $dbh = C4::Context->dbh();
32 # Get the template to use
33 my ($template, $loggedinuser, $cookie)
34     = get_template_and_user({template_name => "tools/holidays.tmpl",
35                              type => "intranet",
36                              query => $input,
37                              authnotrequired => 0,
38                              flagsrequired => {tools => 1},
39                              debug => 1,
40                            });
41
42 # Set all the branches.
43 my $branches = $dbh->prepare("select branchcode, branchname from branches");
44 $branches->execute;
45 # It creates a list of branches
46 my %list;
47 while (my ($branchcode, $branchname) = $branches->fetchrow) {
48     $list{$branchcode} = $branchname;
49 }
50 my @listValues = keys(%list);
51 if (!defined($branch)) {
52     $branch =$listValues[4];
53 }
54 my $branchesList = CGI::scrolling_list(-name => 'branch',
55                                        -values => \@listValues,
56                                        -labels => \%list,
57                                        -size => 1,
58                                        -default => [$branch],
59                                        -multiple => 0,
60                                        -id => "branch",
61                                        -onChange => "changeBranch()");
62
63 $branches->finish;
64
65 # Get all the holidays
66 # warn "BRANCH : $branch";
67 my $calendar = C4::Calendar->new(branchcode => $branch);
68 my $week_days_holidays = $calendar->get_week_days_holidays();
69 my @week_days;
70 foreach my $weekday (keys %$week_days_holidays) {
71 # warn "WEEK DAY : $weekday";
72     my %week_day;
73     %week_day = (KEY => $weekday,
74                  TITLE => $week_days_holidays->{$weekday}{title},
75                  DESCRIPTION => $week_days_holidays->{$weekday}{description});
76     push @week_days, \%week_day;
77 }
78
79 my $day_month_holidays = $calendar->get_day_month_holidays();
80 my @day_month_holidays;
81 foreach my $monthDay (keys %$day_month_holidays) {
82     my %day_month;
83     %day_month = (KEY => $monthDay,
84                   TITLE => $day_month_holidays->{$monthDay}{title},
85                   DESCRIPTION => $day_month_holidays->{$monthDay}{description});
86     push @day_month_holidays, \%day_month;
87 }
88
89 my $exception_holidays = $calendar->get_exception_holidays();
90 my @exception_holidays;
91 foreach my $yearMonthDay (keys %$exception_holidays) {
92     my %exception_holiday;
93     %exception_holiday = (KEY => $yearMonthDay,
94                           TITLE => $exception_holidays->{$yearMonthDay}{title},
95                           DESCRIPTION => $exception_holidays->{$yearMonthDay}{description});
96     push @exception_holidays, \%exception_holiday;
97 }
98
99 my $single_holidays = $calendar->get_single_holidays();
100 my @holidays;
101 foreach my $yearMonthDay (keys %$single_holidays) {
102     my %holiday;
103     %holiday = (KEY => $yearMonthDay,
104                 TITLE => $single_holidays->{$yearMonthDay}{title},
105                 DESCRIPTION => $single_holidays->{$yearMonthDay}{description});
106     push @holidays, \%holiday;
107 }
108
109 # Replace the template values with the real ones
110 $template->param(BRANCHES => $branchesList);
111 $template->param(WEEK_DAYS_LOOP => \@week_days);
112 $template->param(HOLIDAYS_LOOP => \@holidays);
113 $template->param(EXCEPTION_HOLIDAYS_LOOP => \@exception_holidays);
114 $template->param(DAY_MONTH_HOLIDAYS_LOOP => \@day_month_holidays);
115 $template->param(branch => $branch);
116
117 # Shows the template with the real values replaced
118 output_html_with_http_headers $input, $cookie, $template->output;