7 use C4::Auth qw( checkauth );
12 use Koha::DateUtils qw( dt_from_string );
15 my $dbh = C4::Context->dbh();
17 checkauth($input, 0, {tools=> 'edit_calendar'}, 'intranet');
20 our $branchcode = $input->param('showBranchName');
21 my $originalbranchcode = $branchcode;
22 our $weekday = $input->param('showWeekday');
23 our $day = $input->param('showDay');
24 our $month = $input->param('showMonth');
25 our $year = $input->param('showYear');
26 our $title = $input->param('showTitle');
27 our $description = $input->param('showDescription');
28 our $holidaytype = $input->param('showHolidayType');
29 my $datecancelrange_dt = eval { dt_from_string( scalar $input->param('datecancelrange') ) };
30 my $calendardate = sprintf("%04d-%02d-%02d", $year, $month, $day);
31 our $showoperation = $input->param('showOperation');
32 my $allbranches = $input->param('allBranches');
34 $title || ($title = '');
36 $description =~ s/\r/\\r/g;
37 $description =~ s/\n/\\n/g;
42 # We make an array with holiday's days
44 if ($datecancelrange_dt){
45 my $first_dt = DateTime->new(year => $year, month => $month, day => $day);
47 for (my $dt = $first_dt->clone();
48 $dt <= $datecancelrange_dt;
51 push @holiday_list, $dt->clone();
56 my $libraries = Koha::Libraries->search;
57 while ( my $library = $libraries->next ) {
58 edit_holiday($showoperation, $library->branchcode, $weekday, $day, $month, $year, $title, $description, $holidaytype, @holiday_list);
61 edit_holiday($showoperation, $branchcode, $weekday, $day, $month, $year, $title, $description, $holidaytype, @holiday_list);
64 print $input->redirect("/cgi-bin/koha/tools/holidays.pl?branch=$originalbranchcode&calendardate=$calendardate");
67 ($showoperation, $branchcode, $weekday, $day, $month, $year, $title, $description, $holidaytype, @holiday_list) = @_;
68 my $calendar = C4::Calendar->new(branchcode => $branchcode);
70 if ($showoperation eq 'exception') {
71 $calendar->insert_exception_holiday(day => $day,
75 description => $description);
76 } elsif ($showoperation eq 'exceptionrange' ) {
78 foreach my $date (@holiday_list){
79 $calendar->insert_exception_holiday(
80 day => $date->{local_c}->{day},
81 month => $date->{local_c}->{month},
82 year => $date->{local_c}->{year},
84 description => $description
88 } elsif ($showoperation eq 'edit') {
89 if ( $holidaytype eq 'weekday' ) {
90 my $isHoliday = $calendar->isHoliday( $day, $month, $year );
92 $calendar->ModWeekdayholiday(
95 description => $description
99 $calendar->insert_week_day_holiday(
102 description => $description
106 elsif ( $holidaytype eq 'daymonth' ) {
107 my $isHoliday = $calendar->isHoliday( $day, $month, $year );
109 $calendar->ModDaymonthholiday(
113 description => $description
117 $calendar->insert_day_month_holiday(
121 description => $description
125 elsif ( $holidaytype eq 'ymd' ) {
126 my $isHoliday = $calendar->isHoliday( $day, $month, $year );
128 $calendar->ModSingleholiday(
133 description => $description
137 $calendar->insert_single_holiday(
142 description => $description
146 elsif ( $holidaytype eq 'exception' ) {
147 my $isHoliday = $calendar->isHoliday( $day, $month, $year );
149 $calendar->ModExceptionholiday(
154 description => $description
158 $calendar->insert_exception_holiday(
163 description => $description
167 } elsif ($showoperation eq 'delete') {
168 $calendar->delete_holiday(weekday => $weekday,
172 }elsif ($showoperation eq 'deleterange') {
174 foreach my $date (@holiday_list){
175 $calendar->delete_holiday_range(weekday => $weekday,
176 day => $date->{local_c}->{day},
177 month => $date->{local_c}->{month},
178 year => $date->{local_c}->{year});
181 }elsif ($showoperation eq 'deleterangerepeat') {
183 foreach my $date (@holiday_list){
184 $calendar->delete_holiday_range_repeatable(weekday => $weekday,
185 day => $date->{local_c}->{day},
186 month => $date->{local_c}->{month});
189 }elsif ($showoperation eq 'deleterangerepeatexcept') {
191 foreach my $date (@holiday_list){
192 $calendar->delete_exception_holiday_range(weekday => $weekday,
193 day => $date->{local_c}->{day},
194 month => $date->{local_c}->{month},
195 year => $date->{local_c}->{year});