16 my $dbh = C4
::Context
->dbh();
18 my $branchcode = $input->param('showBranchName');
19 my $weekday = $input->param('showWeekday');
20 my $day = $input->param('showDay');
21 my $month = $input->param('showMonth');
22 my $year = $input->param('showYear');
23 my $title = $input->param('showTitle');
24 my $description = $input->param('showDescription');
25 my $holidaytype = $input->param('showHolidayType');
26 my $datecancelrange_dt = eval { dt_from_string
( $input->param('datecancelrange') ) };
27 my $calendardate = sprintf("%04d-%02d-%02d", $year, $month, $day);
29 my $calendar = C4
::Calendar
->new(branchcode
=> $branchcode);
31 $title || ($title = '');
33 $description =~ s/\r/\\r/g;
34 $description =~ s/\n/\\n/g;
39 # We make an array with holiday's days
41 if ($datecancelrange_dt){
42 my $first_dt = DateTime
->new(year
=> $year, month
=> $month, day
=> $day);
44 for (my $dt = $first_dt->clone();
45 $dt <= $datecancelrange_dt;
48 push @holiday_list, $dt->clone();
51 if ($input->param('showOperation') eq 'exception') {
52 $calendar->insert_exception_holiday(day
=> $day,
56 description
=> $description);
57 } elsif ($input->param('showOperation') eq 'exceptionrange' ) {
59 foreach my $date (@holiday_list){
60 $calendar->insert_exception_holiday(
61 day
=> $date->{local_c
}->{day
},
62 month
=> $date->{local_c
}->{month
},
63 year
=> $date->{local_c
}->{year
},
65 description
=> $description
69 } elsif ($input->param('showOperation') eq 'edit') {
70 if($holidaytype eq 'weekday') {
71 $calendar->ModWeekdayholiday(weekday
=> $weekday,
73 description
=> $description);
74 } elsif ($holidaytype eq 'daymonth') {
75 $calendar->ModDaymonthholiday(day
=> $day,
78 description
=> $description);
79 } elsif ($holidaytype eq 'ymd') {
80 $calendar->ModSingleholiday(day
=> $day,
84 description
=> $description);
85 } elsif ($holidaytype eq 'exception') {
86 $calendar->ModExceptionholiday(day
=> $day,
90 description
=> $description);
92 } elsif ($input->param('showOperation') eq 'delete') {
93 $calendar->delete_holiday(weekday
=> $weekday,
97 }elsif ($input->param('showOperation') eq 'deleterange') {
99 foreach my $date (@holiday_list){
100 $calendar->delete_holiday_range(weekday
=> $weekday,
101 day
=> $date->{local_c
}->{day
},
102 month
=> $date->{local_c
}->{month
},
103 year
=> $date->{local_c
}->{year
});
106 }elsif ($input->param('showOperation') eq 'deleterangerepeat') {
108 foreach my $date (@holiday_list){
109 $calendar->delete_holiday_range_repeatable(weekday
=> $weekday,
110 day
=> $date->{local_c
}->{day
},
111 month
=> $date->{local_c
}->{month
});
114 }elsif ($input->param('showOperation') eq 'deleterangerepeatexcept') {
116 foreach my $date (@holiday_list){
117 $calendar->delete_exception_holiday_range(weekday
=> $weekday,
118 day
=> $date->{local_c
}->{day
},
119 month
=> $date->{local_c
}->{month
},
120 year
=> $date->{local_c
}->{year
});
124 print $input->redirect("/cgi-bin/koha/tools/holidays.pl?branch=$branchcode&calendardate=$calendardate");