2 #####Sets holiday periods for each branch. Datedues will be extended if branch is closed -TG
8 use C4::Interface::CGI::Output;
14 #my $branch = $input->param('branch');
15 my $branch=C4::Context->preference('defaultbranch') || $input->param('branch');
16 my $dbh = C4::Context->dbh();
17 # Get the template to use
18 my ($template, $loggedinuser, $cookie)
19 = get_template_and_user({template_name => "tools/holidays.tmpl",
23 flagsrequired => {parameters => 1},
27 # Set all the branches.
28 my $branches = $dbh->prepare("select branchcode, branchname from branches");
30 # It creates a list of branches
32 while (my ($branchcode, $branchname) = $branches->fetchrow) {
33 $list{$branchcode} = $branchname;
35 my @listValues = keys(%list);
36 if (!defined($branch)) {
37 $branch =$listValues[4];
39 my $branchesList = CGI::scrolling_list(-name => 'branch',
40 -values => \@listValues,
43 -default => [$branch],
46 -onChange => "changeBranch()");
50 # Get all the holidays
51 warn "BRANCH : $branch";
52 my $calendar = C4::Calendar->new(branchcode => $branch);
53 my $week_days_holidays = $calendar->get_week_days_holidays();
55 foreach my $weekday (keys %$week_days_holidays) {
56 warn "WEEK DAY : $weekday";
58 %week_day = (KEY => $weekday,
59 TITLE => $week_days_holidays->{$weekday}{title},
60 DESCRIPTION => $week_days_holidays->{$weekday}{description});
61 push @week_days, \%week_day;
64 my $day_month_holidays = $calendar->get_day_month_holidays();
65 my @day_month_holidays;
66 foreach my $monthDay (keys %$day_month_holidays) {
68 %day_month = (KEY => $monthDay,
69 TITLE => $day_month_holidays->{$monthDay}{title},
70 DESCRIPTION => $day_month_holidays->{$monthDay}{description});
71 push @day_month_holidays, \%day_month;
74 my $exception_holidays = $calendar->get_exception_holidays();
75 my @exception_holidays;
76 foreach my $yearMonthDay (keys %$exception_holidays) {
77 my %exception_holiday;
78 %exception_holiday = (KEY => $yearMonthDay,
79 TITLE => $exception_holidays->{$yearMonthDay}{title},
80 DESCRIPTION => $exception_holidays->{$yearMonthDay}{description});
81 push @exception_holidays, \%exception_holiday;
84 my $single_holidays = $calendar->get_single_holidays();
86 foreach my $yearMonthDay (keys %$single_holidays) {
88 %holiday = (KEY => $yearMonthDay,
89 TITLE => $single_holidays->{$yearMonthDay}{title},
90 DESCRIPTION => $single_holidays->{$yearMonthDay}{description});
91 push @holidays, \%holiday;
94 # Replace the template values with the real ones
95 $template->param(BRANCHES => $branchesList);
96 $template->param(WEEK_DAYS_LOOP => \@week_days);
97 $template->param(HOLIDAYS_LOOP => \@holidays);
98 $template->param(EXCEPTION_HOLIDAYS_LOOP => \@exception_holidays);
99 $template->param(DAY_MONTH_HOLIDAYS_LOOP => \@day_month_holidays);
100 $template->param(branch => $branch);
102 # Shows the template with the real values replaced
103 output_html_with_http_headers $input, $cookie, $template->output;