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 $calendar->ModWeekdayholiday(weekday
=> $weekday,
92 description
=> $description);
93 } elsif ($holidaytype eq 'daymonth') {
94 $calendar->ModDaymonthholiday(day
=> $day,
97 description
=> $description);
98 } elsif ($holidaytype eq 'ymd') {
99 $calendar->ModSingleholiday(day
=> $day,
103 description
=> $description);
104 } elsif ($holidaytype eq 'exception') {
105 $calendar->ModExceptionholiday(day
=> $day,
109 description
=> $description);
111 } elsif ($showoperation eq 'delete') {
112 $calendar->delete_holiday(weekday
=> $weekday,
116 }elsif ($showoperation eq 'deleterange') {
118 foreach my $date (@holiday_list){
119 $calendar->delete_holiday_range(weekday
=> $weekday,
120 day
=> $date->{local_c
}->{day
},
121 month
=> $date->{local_c
}->{month
},
122 year
=> $date->{local_c
}->{year
});
125 }elsif ($showoperation eq 'deleterangerepeat') {
127 foreach my $date (@holiday_list){
128 $calendar->delete_holiday_range_repeatable(weekday
=> $weekday,
129 day
=> $date->{local_c
}->{day
},
130 month
=> $date->{local_c
}->{month
});
133 }elsif ($showoperation eq 'deleterangerepeatexcept') {
135 foreach my $date (@holiday_list){
136 $calendar->delete_exception_holiday_range(weekday
=> $weekday,
137 day
=> $date->{local_c
}->{day
},
138 month
=> $date->{local_c
}->{month
},
139 year
=> $date->{local_c
}->{year
});