Bug 1687: Can't assign holidays to all branches at once.
[koha.git] / tools / exceptionHolidays.pl
1 #!/usr/bin/perl
2
3 use strict;
4 use CGI;
5
6 use C4::Auth;
7 use C4::Output;
8
9
10 use C4::Calendar;
11
12 my $input = new CGI;
13 my $dbh = C4::Context->dbh();
14
15 my $branchcode = $input->param('showBranchName');
16 my $weekday = $input->param('showWeekday');
17 my $day = $input->param('showDay');
18 my $month = $input->param('showMonth');
19 my $year = $input->param('showYear');
20 my $title = $input->param('showTitle');
21 my $description = $input->param('showDescription');
22
23 my $calendardate = sprintf("%04d-%02d-%02d", $year, $month, $day);
24 my $isodate = C4::Dates->new($calendardate, 'iso');
25 $calendardate = $isodate->output('syspref');
26
27 my $calendar = C4::Calendar->new(branchcode => $branchcode);
28
29 $title || ($title = '');
30 if ($description) {
31     $description =~ s/\r/\\r/g;
32     $description =~ s/\n/\\n/g;
33 } else {
34     $description = '';
35 }   
36
37 if ($input->param('showOperation') eq 'exception') {
38         $calendar->insert_exception_holiday(day => $day,
39                                                                                 month => $month,
40                                                                             year => $year,
41                                                                 title => $title,
42                                                                 description => $description);
43 } elsif ($input->param('showOperation') eq 'delete') {
44         $calendar->delete_holiday(weekday => $weekday,
45                                   day => $day,
46                                   month => $month,
47                                               year => $year);
48 }
49 print $input->redirect("/cgi-bin/koha/tools/holidays.pl?branch=$branchcode&calendardate=$calendardate");