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');
25 my $title = $input->param('showTitle');
26 my $description = $input->param('showDescription');
27 my $holidaytype = $input->param('showHolidayType');
28 my $datecancelrange = $input->param('datecancelrange');
29 my $calendardate = sprintf("%04d-%02d-%02d", $year, $month, $day);
30 my $isodate = C4
::Dates
->new($calendardate, 'iso');
31 $calendardate = $isodate->output('syspref');
33 my $calendar = C4
::Calendar
->new(branchcode
=> $branchcode);
35 $title || ($title = '');
37 $description =~ s/\r/\\r/g;
38 $description =~ s/\n/\\n/g;
44 my @dateend = split(/[\/-]/, $datecancelrange);
45 if (C4
::Context
->preference("dateformat") eq "metric") {
47 $month1 = $dateend[1];
49 }elsif (C4
::Context
->preference("dateformat") eq "us") {
50 $month1 = $dateend[0];
55 $month1 = $dateend[1];
59 # We make an array with holiday's days
61 if ($year1 && $month1 && $day1){
62 my $first_dt = DateTime
->new(year
=> $year, month
=> $month, day
=> $day);
63 my $end_dt = DateTime
->new(year
=> $year1, month
=> $month1, day
=> $day1);
65 for (my $dt = $first_dt->clone();
69 push @holiday_list, $dt->clone();
72 if ($input->param('showOperation') eq 'exception') {
73 $calendar->insert_exception_holiday(day
=> $day,
77 description
=> $description);
78 } elsif ($input->param('showOperation') eq 'exceptionrange' ) {
80 foreach my $date (@holiday_list){
81 $calendar->insert_exception_holiday(
82 day
=> $date->{local_c
}->{day
},
83 month
=> $date->{local_c
}->{month
},
84 year
=> $date->{local_c
}->{year
},
86 description
=> $description
90 } elsif ($input->param('showOperation') eq 'edit') {
91 if($holidaytype eq 'weekday') {
92 $calendar->ModWeekdayholiday(weekday
=> $weekday,
94 description
=> $description);
95 } elsif ($holidaytype eq 'daymonth') {
96 $calendar->ModDaymonthholiday(day
=> $day,
99 description
=> $description);
100 } elsif ($holidaytype eq 'ymd') {
101 $calendar->ModSingleholiday(day
=> $day,
105 description
=> $description);
106 } elsif ($holidaytype eq 'exception') {
107 $calendar->ModExceptionholiday(day
=> $day,
111 description
=> $description);
113 } elsif ($input->param('showOperation') eq 'delete') {
114 $calendar->delete_holiday(weekday
=> $weekday,
118 }elsif ($input->param('showOperation') eq 'deleterange') {
120 foreach my $date (@holiday_list){
121 $calendar->delete_holiday_range(weekday
=> $weekday,
122 day
=> $date->{local_c
}->{day
},
123 month
=> $date->{local_c
}->{month
},
124 year
=> $date->{local_c
}->{year
});
127 }elsif ($input->param('showOperation') eq 'deleterangerepeat') {
129 foreach my $date (@holiday_list){
130 $calendar->delete_holiday_range_repeatable(weekday
=> $weekday,
131 day
=> $date->{local_c
}->{day
},
132 month
=> $date->{local_c
}->{month
});
135 }elsif ($input->param('showOperation') eq 'deleterangerepeatexcept') {
137 foreach my $date (@holiday_list){
138 $calendar->delete_exception_holiday_range(weekday
=> $weekday,
139 day
=> $date->{local_c
}->{day
},
140 month
=> $date->{local_c
}->{month
},
141 year
=> $date->{local_c
}->{year
});
145 print $input->redirect("/cgi-bin/koha/tools/holidays.pl?branch=$branchcode&calendardate=$calendardate");