8 use C4::Interface::CGI::Output;
10 use C4::Calendar::Calendar;
13 my $branch = $input->param('branch');
14 $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', -id=>'branch',
30 -values => \@listValues,
33 -default => [$branch],
35 -onChange => "changeBranch()");
39 # Get all the holidays
40 my $calendar = C4::Calendar::Calendar->new(branchcode => $branch);
41 my $week_days_holidays = $calendar->get_week_days_holidays();
43 foreach my $weekday (keys %$week_days_holidays) {
45 %week_day = (KEY => $weekday,
46 TITLE => $week_days_holidays->{$weekday}{title},
47 DESCRIPTION => $week_days_holidays->{$weekday}{description});
48 push @week_days, \%week_day;
51 my $day_month_holidays = $calendar->get_day_month_holidays();
52 my @day_month_holidays;
53 foreach my $monthDay (keys %$day_month_holidays) {
55 %day_month = (KEY => $monthDay,
56 TITLE => $day_month_holidays->{$monthDay}{title},
57 DESCRIPTION => $day_month_holidays->{$monthDay}{description});
58 push @day_month_holidays, \%day_month;
61 my $exception_holidays = $calendar->get_exception_holidays();
62 my @exception_holidays;
63 foreach my $yearMonthDay (keys %$exception_holidays) {
64 my %exception_holiday;
65 %exception_holiday = (KEY => $yearMonthDay,
66 TITLE => $exception_holidays->{$yearMonthDay}{title},
67 DESCRIPTION => $exception_holidays->{$yearMonthDay}{description});
68 push @exception_holidays, \%exception_holiday;
71 my $single_holidays = $calendar->get_single_holidays();
73 foreach my $yearMonthDay (keys %$single_holidays) {
75 %holiday = (KEY => $yearMonthDay,
76 TITLE => $single_holidays->{$yearMonthDay}{title},
77 DESCRIPTION => $single_holidays->{$yearMonthDay}{description});
78 push @holidays, \%holiday;
81 # Get the template to use
82 my ($template, $loggedinuser, $cookie)
83 = get_template_and_user({template_name => "tools/holidays.tmpl",
87 flagsrequired => {parameters => 1},
91 # Replace the template values with the real ones
92 $template->param(BRANCHES => $branchesList);
93 $template->param(WEEK_DAYS_LOOP => \@week_days);
94 $template->param(HOLIDAYS_LOOP => \@holidays);
95 $template->param(EXCEPTION_HOLIDAYS_LOOP => \@exception_holidays);
96 $template->param(DAY_MONTH_HOLIDAYS_LOOP => \@day_month_holidays);
97 $template->param(branch => $branch);
99 # Shows the template with the real values replaced
100 output_html_with_http_headers $input, $cookie, $template->output;