adding calendar popup to inventory/stocktaking
[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 use C4::Interface::CGI::Output;
25
26
27 use C4::Calendar;
28
29 my $input = new CGI;
30 #my $branch = $input->param('branch');
31 my $branch=C4::Context->preference('defaultbranch') || $input->param('branch');
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",
36                              type => "intranet",
37                              query => $input,
38                              authnotrequired => 0,
39                              flagsrequired => {tools => 1},
40                              debug => 1,
41                            });
42
43 # Set all the branches.
44 my $branches = $dbh->prepare("select branchcode, branchname from branches");
45 $branches->execute;
46 # It creates a list of branches
47 my %list;
48 while (my ($branchcode, $branchname) = $branches->fetchrow) {
49     $list{$branchcode} = $branchname;
50 }
51 my @listValues = keys(%list);
52 if (!defined($branch)) {
53     $branch =$listValues[4];
54 }
55 my $branchesList = CGI::scrolling_list(-name => 'branch',
56                                        -values => \@listValues,
57                                        -labels => \%list,
58                                        -size => 1,
59                                        -default => [$branch],
60                                        -multiple => 0,
61                                        -id => "branch",
62                                        -onChange => "changeBranch()");
63
64 $branches->finish;
65
66 # Get all the holidays
67 # warn "BRANCH : $branch";
68 my $calendar = C4::Calendar->new(branchcode => $branch);
69 my $week_days_holidays = $calendar->get_week_days_holidays();
70 my @week_days;
71 foreach my $weekday (keys %$week_days_holidays) {
72 # warn "WEEK DAY : $weekday";
73     my %week_day;
74     %week_day = (KEY => $weekday,
75                  TITLE => $week_days_holidays->{$weekday}{title},
76                  DESCRIPTION => $week_days_holidays->{$weekday}{description});
77     push @week_days, \%week_day;
78 }
79
80 my $day_month_holidays = $calendar->get_day_month_holidays();
81 my @day_month_holidays;
82 foreach my $monthDay (keys %$day_month_holidays) {
83     my %day_month;
84     %day_month = (KEY => $monthDay,
85                   TITLE => $day_month_holidays->{$monthDay}{title},
86                   DESCRIPTION => $day_month_holidays->{$monthDay}{description});
87     push @day_month_holidays, \%day_month;
88 }
89
90 my $exception_holidays = $calendar->get_exception_holidays();
91 my @exception_holidays;
92 foreach my $yearMonthDay (keys %$exception_holidays) {
93     my %exception_holiday;
94     %exception_holiday = (KEY => $yearMonthDay,
95                           TITLE => $exception_holidays->{$yearMonthDay}{title},
96                           DESCRIPTION => $exception_holidays->{$yearMonthDay}{description});
97     push @exception_holidays, \%exception_holiday;
98 }
99
100 my $single_holidays = $calendar->get_single_holidays();
101 my @holidays;
102 foreach my $yearMonthDay (keys %$single_holidays) {
103     my %holiday;
104     %holiday = (KEY => $yearMonthDay,
105                 TITLE => $single_holidays->{$yearMonthDay}{title},
106                 DESCRIPTION => $single_holidays->{$yearMonthDay}{description});
107     push @holidays, \%holiday;
108 }
109
110 # Replace the template values with the real ones
111 $template->param(BRANCHES => $branchesList);
112 $template->param(WEEK_DAYS_LOOP => \@week_days);
113 $template->param(HOLIDAYS_LOOP => \@holidays);
114 $template->param(EXCEPTION_HOLIDAYS_LOOP => \@exception_holidays);
115 $template->param(DAY_MONTH_HOLIDAYS_LOOP => \@day_month_holidays);
116 $template->param(branch => $branch);
117
118 # Shows the template with the real values replaced
119 output_html_with_http_headers $input, $cookie, $template->output;