[26/40] Refactoring auto label batch generation feature in bulk import tool and addin...
[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 my $holidaytype = $input->param('showHolidayType');
23
24 my $calendardate = sprintf("%04d-%02d-%02d", $year, $month, $day);
25 my $isodate = C4::Dates->new($calendardate, 'iso');
26 $calendardate = $isodate->output('syspref');
27
28 my $calendar = C4::Calendar->new(branchcode => $branchcode);
29
30 $title || ($title = '');
31 if ($description) {
32     $description =~ s/\r/\\r/g;
33     $description =~ s/\n/\\n/g;
34 } else {
35     $description = '';
36 }   
37
38 if ($input->param('showOperation') eq 'exception') {
39         $calendar->insert_exception_holiday(day => $day,
40                                                                                 month => $month,
41                                                                             year => $year,
42                                                                 title => $title,
43                                                                 description => $description);
44 } elsif ($input->param('showOperation') eq 'edit') {
45     if($holidaytype eq 'weekday') {
46       $calendar->ModWeekdayholiday(weekday => $weekday,
47                                    title => $title,
48                                    description => $description);
49     } elsif ($holidaytype eq 'daymonth') {
50       $calendar->ModDaymonthholiday(day => $day,
51                                     month => $month,
52                                     title => $title,
53                                     description => $description);
54     } elsif ($holidaytype eq 'ymd') {
55       $calendar->ModSingleholiday(day => $day,
56                                   month => $month,
57                                   year => $year,
58                                   title => $title,
59                                   description => $description);
60     } elsif ($holidaytype eq 'exception') {
61       $calendar->ModExceptionholiday(day => $day,
62                                   month => $month,
63                                   year => $year,
64                                   title => $title,
65                                   description => $description);
66     }
67 } elsif ($input->param('showOperation') eq 'delete') {
68         $calendar->delete_holiday(weekday => $weekday,
69                                   day => $day,
70                                   month => $month,
71                                               year => $year);
72 }
73 print $input->redirect("/cgi-bin/koha/tools/holidays.pl?branch=$branchcode&calendardate=$calendardate");