15 my $dbh = C4
::Context
->dbh();
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 my $datecancelrange_dt = eval { dt_from_string
( scalar $input->param('datecancelrange') ) };
26 my $calendardate = sprintf("%04d-%02d-%02d", $year, $month, $day);
28 my $calendar = C4
::Calendar
->new(branchcode
=> $branchcode);
30 $title || ($title = '');
32 $description =~ s/\r/\\r/g;
33 $description =~ s/\n/\\n/g;
38 # We make an array with holiday's days
40 if ($datecancelrange_dt){
41 my $first_dt = DateTime
->new(year
=> $year, month
=> $month, day
=> $day);
43 for (my $dt = $first_dt->clone();
44 $dt <= $datecancelrange_dt;
47 push @holiday_list, $dt->clone();
50 if ($input->param('showOperation') eq 'exception') {
51 $calendar->insert_exception_holiday(day
=> $day,
55 description
=> $description);
56 } elsif ($input->param('showOperation') eq 'exceptionrange' ) {
58 foreach my $date (@holiday_list){
59 $calendar->insert_exception_holiday(
60 day
=> $date->{local_c
}->{day
},
61 month
=> $date->{local_c
}->{month
},
62 year
=> $date->{local_c
}->{year
},
64 description
=> $description
68 } elsif ($input->param('showOperation') eq 'edit') {
69 if($holidaytype eq 'weekday') {
70 $calendar->ModWeekdayholiday(weekday
=> $weekday,
72 description
=> $description);
73 } elsif ($holidaytype eq 'daymonth') {
74 $calendar->ModDaymonthholiday(day
=> $day,
77 description
=> $description);
78 } elsif ($holidaytype eq 'ymd') {
79 $calendar->ModSingleholiday(day
=> $day,
83 description
=> $description);
84 } elsif ($holidaytype eq 'exception') {
85 $calendar->ModExceptionholiday(day
=> $day,
89 description
=> $description);
91 } elsif ($input->param('showOperation') eq 'delete') {
92 $calendar->delete_holiday(weekday
=> $weekday,
96 }elsif ($input->param('showOperation') eq 'deleterange') {
98 foreach my $date (@holiday_list){
99 $calendar->delete_holiday_range(weekday
=> $weekday,
100 day
=> $date->{local_c
}->{day
},
101 month
=> $date->{local_c
}->{month
},
102 year
=> $date->{local_c
}->{year
});
105 }elsif ($input->param('showOperation') eq 'deleterangerepeat') {
107 foreach my $date (@holiday_list){
108 $calendar->delete_holiday_range_repeatable(weekday
=> $weekday,
109 day
=> $date->{local_c
}->{day
},
110 month
=> $date->{local_c
}->{month
});
113 }elsif ($input->param('showOperation') eq 'deleterangerepeatexcept') {
115 foreach my $date (@holiday_list){
116 $calendar->delete_exception_holiday_range(weekday
=> $weekday,
117 day
=> $date->{local_c
}->{day
},
118 month
=> $date->{local_c
}->{month
},
119 year
=> $date->{local_c
}->{year
});
123 print $input->redirect("/cgi-bin/koha/tools/holidays.pl?branch=$branchcode&calendardate=$calendardate");