2 #FIXME: perltidy this file
4 # This file is part of Koha.
6 # Koha is free software; you can redistribute it and/or modify it
7 # under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 3 of the License, or
9 # (at your option) any later version.
11 # Koha is distributed in the hope that it will be useful, but
12 # WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public Lic# along with Koha; if not, see <http://www.gnu.org/licenses>.
17 # along with Koha; if not, see <http://www.gnu.org/licenses>.
34 my $dbh = C4
::Context
->dbh();
36 our $branchcode = $input->param('newBranchName');
37 my $originalbranchcode = $branchcode;
38 our $weekday = $input->param('newWeekday');
39 our $day = $input->param('newDay');
40 our $month = $input->param('newMonth');
41 our $year = $input->param('newYear');
42 my $dateofrange = $input->param('dateofrange');
43 our $title = $input->param('newTitle');
44 our $description = $input->param('newDescription');
45 our $newoperation = $input->param('newOperation');
46 my $allbranches = $input->param('allBranches');
49 my $first_dt = DateTime
->new(year
=> $year, month
=> $month, day
=> $day);
50 my $end_dt = eval { dt_from_string
( $dateofrange ); };
52 my $calendardate = output_pref
( { dt
=> $first_dt, dateonly
=> 1, dateformat
=> 'iso' } );
54 $title || ($title = '');
56 $description =~ s/\r/\\r/g;
57 $description =~ s/\n/\\n/g;
62 # We make an array with holiday's days
65 for (my $dt = $first_dt->clone();
69 push @holiday_list, $dt->clone();
74 my $libraries = Koha
::Libraries
->search;
75 while ( my $library = $libraries->next ) {
76 add_holiday
($newoperation, $library->branchcode, $weekday, $day, $month, $year, $title, $description);
79 add_holiday
($newoperation, $branchcode, $weekday, $day, $month, $year, $title, $description);
82 print $input->redirect("/cgi-bin/koha/tools/holidays.pl?branch=$originalbranchcode&calendardate=$calendardate");
84 #FIXME: move add_holiday() to a better place
86 ($newoperation, $branchcode, $weekday, $day, $month, $year, $title, $description) = @_;
87 my $calendar = C4
::Calendar
->new(branchcode
=> $branchcode);
89 if ($newoperation eq 'weekday') {
90 unless ( $weekday && ($weekday ne '') ) {
91 # was dow calculated by javascript? original code implies it was supposed to be.
93 $weekday = &Date
::Calc
::Day_of_Week
($year, $month, $day) % 7 unless($weekday);
95 unless($calendar->isHoliday($day, $month, $year)) {
96 $calendar->insert_week_day_holiday(weekday
=> $weekday,
98 description
=> $description);
100 } elsif ($newoperation eq 'repeatable') {
101 unless($calendar->isHoliday($day, $month, $year)) {
102 $calendar->insert_day_month_holiday(day
=> $day,
105 description
=> $description);
107 } elsif ($newoperation eq 'holiday') {
108 unless($calendar->isHoliday($day, $month, $year)) {
109 $calendar->insert_single_holiday(day
=> $day,
113 description
=> $description);
116 } elsif ( $newoperation eq 'holidayrange' ) {
118 foreach my $date (@holiday_list){
119 unless ( $calendar->isHoliday( $date->{local_c
}->{day
}, $date->{local_c
}->{month
}, $date->{local_c
}->{year
} ) ) {
120 $calendar->insert_single_holiday(
121 day
=> $date->{local_c
}->{day
},
122 month
=> $date->{local_c
}->{month
},
123 year
=> $date->{local_c
}->{year
},
125 description
=> $description
130 } elsif ( $newoperation eq 'holidayrangerepeat' ) {
132 foreach my $date (@holiday_list){
133 unless ( $calendar->isHoliday( $date->{local_c
}->{day
}, $date->{local_c
}->{month
}, $date->{local_c
}->{year
} ) ) {
134 $calendar->insert_day_month_holiday(
135 day
=> $date->{local_c
}->{day
},
136 month
=> $date->{local_c
}->{month
},
138 description
=> $description
144 # we updated the single_holidays table, so wipe its cache
145 my $cache = Koha
::Caches
->get_instance();
146 $cache->clear_from_cache( 'single_holidays') ;