15 my $dbh = C4
::Context
->dbh();
17 checkauth
($input, 0, {tools
=> 'edit_calendar'}, 'intranet');
20 my $branchcode = $input->param('showBranchName');
21 my $weekday = $input->param('showWeekday');
22 my $day = $input->param('showDay');
23 my $month = $input->param('showMonth');
24 my $year = $input->param('showYear');
25 my $title = $input->param('showTitle');
26 my $description = $input->param('showDescription');
27 my $holidaytype = $input->param('showHolidayType');
28 my $datecancelrange_dt = eval { dt_from_string
( scalar $input->param('datecancelrange') ) };
29 my $calendardate = sprintf("%04d-%02d-%02d", $year, $month, $day);
31 my $calendar = C4
::Calendar
->new(branchcode
=> $branchcode);
33 $title || ($title = '');
35 $description =~ s/\r/\\r/g;
36 $description =~ s/\n/\\n/g;
41 # We make an array with holiday's days
43 if ($datecancelrange_dt){
44 my $first_dt = DateTime
->new(year
=> $year, month
=> $month, day
=> $day);
46 for (my $dt = $first_dt->clone();
47 $dt <= $datecancelrange_dt;
50 push @holiday_list, $dt->clone();
53 if ($input->param('showOperation') eq 'exception') {
54 $calendar->insert_exception_holiday(day
=> $day,
58 description
=> $description);
59 } elsif ($input->param('showOperation') eq 'exceptionrange' ) {
61 foreach my $date (@holiday_list){
62 $calendar->insert_exception_holiday(
63 day
=> $date->{local_c
}->{day
},
64 month
=> $date->{local_c
}->{month
},
65 year
=> $date->{local_c
}->{year
},
67 description
=> $description
71 } elsif ($input->param('showOperation') eq 'edit') {
72 if($holidaytype eq 'weekday') {
73 $calendar->ModWeekdayholiday(weekday
=> $weekday,
75 description
=> $description);
76 } elsif ($holidaytype eq 'daymonth') {
77 $calendar->ModDaymonthholiday(day
=> $day,
80 description
=> $description);
81 } elsif ($holidaytype eq 'ymd') {
82 $calendar->ModSingleholiday(day
=> $day,
86 description
=> $description);
87 } elsif ($holidaytype eq 'exception') {
88 $calendar->ModExceptionholiday(day
=> $day,
92 description
=> $description);
94 } elsif ($input->param('showOperation') eq 'delete') {
95 $calendar->delete_holiday(weekday
=> $weekday,
99 }elsif ($input->param('showOperation') eq 'deleterange') {
101 foreach my $date (@holiday_list){
102 $calendar->delete_holiday_range(weekday
=> $weekday,
103 day
=> $date->{local_c
}->{day
},
104 month
=> $date->{local_c
}->{month
},
105 year
=> $date->{local_c
}->{year
});
108 }elsif ($input->param('showOperation') eq 'deleterangerepeat') {
110 foreach my $date (@holiday_list){
111 $calendar->delete_holiday_range_repeatable(weekday
=> $weekday,
112 day
=> $date->{local_c
}->{day
},
113 month
=> $date->{local_c
}->{month
});
116 }elsif ($input->param('showOperation') eq 'deleterangerepeatexcept') {
118 foreach my $date (@holiday_list){
119 $calendar->delete_exception_holiday_range(weekday
=> $weekday,
120 day
=> $date->{local_c
}->{day
},
121 month
=> $date->{local_c
}->{month
},
122 year
=> $date->{local_c
}->{year
});
126 print $input->redirect("/cgi-bin/koha/tools/holidays.pl?branch=$branchcode&calendardate=$calendardate");