Merge branch 'master' of git://git.koha-community.org/koha into MSWin32
[wip/koha-chris_n.git] / tools / exceptionHolidays.pl
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use CGI;
7
8 use C4::Auth;
9 use C4::Output;
10
11
12 use C4::Calendar;
13
14 my $input = new CGI;
15 my $dbh = C4::Context->dbh();
16
17 my $branchcode = $input->param('showBranchName');
18 my $weekday = $input->param('showWeekday');
19 my $day = $input->param('showDay');
20 my $month = $input->param('showMonth');
21 my $year = $input->param('showYear');
22 my $title = $input->param('showTitle');
23 my $description = $input->param('showDescription');
24 my $holidaytype = $input->param('showHolidayType');
25
26 my $calendardate = sprintf("%04d-%02d-%02d", $year, $month, $day);
27 my $isodate = C4::Dates->new($calendardate, 'iso');
28 $calendardate = $isodate->output('syspref');
29
30 my $calendar = C4::Calendar->new(branchcode => $branchcode);
31
32 $title || ($title = '');
33 if ($description) {
34     $description =~ s/\r/\\r/g;
35     $description =~ s/\n/\\n/g;
36 } else {
37     $description = '';
38 }   
39
40 if ($input->param('showOperation') eq 'exception') {
41         $calendar->insert_exception_holiday(day => $day,
42                                                                                 month => $month,
43                                                                             year => $year,
44                                                                 title => $title,
45                                                                 description => $description);
46 } elsif ($input->param('showOperation') eq 'edit') {
47     if($holidaytype eq 'weekday') {
48       $calendar->ModWeekdayholiday(weekday => $weekday,
49                                    title => $title,
50                                    description => $description);
51     } elsif ($holidaytype eq 'daymonth') {
52       $calendar->ModDaymonthholiday(day => $day,
53                                     month => $month,
54                                     title => $title,
55                                     description => $description);
56     } elsif ($holidaytype eq 'ymd') {
57       $calendar->ModSingleholiday(day => $day,
58                                   month => $month,
59                                   year => $year,
60                                   title => $title,
61                                   description => $description);
62     } elsif ($holidaytype eq 'exception') {
63       $calendar->ModExceptionholiday(day => $day,
64                                   month => $month,
65                                   year => $year,
66                                   title => $title,
67                                   description => $description);
68     }
69 } elsif ($input->param('showOperation') eq 'delete') {
70         $calendar->delete_holiday(weekday => $weekday,
71                                   day => $day,
72                                   month => $month,
73                                               year => $year);
74 }
75 print $input->redirect("/cgi-bin/koha/tools/holidays.pl?branch=$branchcode&calendardate=$calendardate");