8 use C4::Interface::CGI::Output;
10 use C4::Calendar::Calendar;
13 my $branch = $input->param('branch');
14 my $branch=C4::Context->preference('defaultbranch') unless $branch;
15 my $dbh = C4::Context->dbh();
17 # Set all the branches.
18 my $branches = $dbh->prepare("select branchcode, branchname from branches");
20 # It creates a list of branches
22 while (my ($branchcode, $branchname) = $branches->fetchrow) {
23 $list{$branchcode} = $branchname;
25 my @listValues = keys(%list);
26 if (!defined($branch)) {
27 $branch =$listValues[4];
29 my $branchesList = CGI::scrolling_list(-name => 'branch',
30 -values => \@listValues,
33 -default => [$branch],
36 -onChange => "changeBranch()");
40 # Get all the holidays
41 my $calendar = C4::Calendar::Calendar->new(branchcode => $branch);
42 my $week_days_holidays = $calendar->get_week_days_holidays();
44 foreach my $weekday (keys %$week_days_holidays) {
46 %week_day = (KEY => $weekday,
47 TITLE => $week_days_holidays->{$weekday}{title},
48 DESCRIPTION => $week_days_holidays->{$weekday}{description});
49 push @week_days, \%week_day;
52 my $day_month_holidays = $calendar->get_day_month_holidays();
53 my @day_month_holidays;
54 foreach my $monthDay (keys %$day_month_holidays) {
56 %day_month = (KEY => $monthDay,
57 TITLE => $day_month_holidays->{$monthDay}{title},
58 DESCRIPTION => $day_month_holidays->{$monthDay}{description});
59 push @day_month_holidays, \%day_month;
62 my $exception_holidays = $calendar->get_exception_holidays();
63 my @exception_holidays;
64 foreach my $yearMonthDay (keys %$exception_holidays) {
65 my %exception_holiday;
66 %exception_holiday = (KEY => $yearMonthDay,
67 TITLE => $exception_holidays->{$yearMonthDay}{title},
68 DESCRIPTION => $exception_holidays->{$yearMonthDay}{description});
69 push @exception_holidays, \%exception_holiday;
72 my $single_holidays = $calendar->get_single_holidays();
74 foreach my $yearMonthDay (keys %$single_holidays) {
76 %holiday = (KEY => $yearMonthDay,
77 TITLE => $single_holidays->{$yearMonthDay}{title},
78 DESCRIPTION => $single_holidays->{$yearMonthDay}{description});
79 push @holidays, \%holiday;
82 # Get the template to use
83 my ($template, $loggedinuser, $cookie)
84 = get_template_and_user({template_name => "tools/holidays.tmpl",
88 flagsrequired => {parameters => 1},
92 # Replace the template values with the real ones
93 $template->param(BRANCHES => $branchesList);
94 $template->param(WEEK_DAYS_LOOP => \@week_days);
95 $template->param(HOLIDAYS_LOOP => \@holidays);
96 $template->param(EXCEPTION_HOLIDAYS_LOOP => \@exception_holidays);
97 $template->param(DAY_MONTH_HOLIDAYS_LOOP => \@day_month_holidays);
98 $template->param(branch => $branch);
100 # Shows the template with the real values replaced
101 output_html_with_http_headers $input, $cookie, $template->output;