3 #FIXME: perltidy this file
20 my $dbh = C4
::Context
->dbh();
22 our $branchcode = $input->param('newBranchName');
23 my $originalbranchcode = $branchcode;
24 our $weekday = $input->param('newWeekday');
25 our $day = $input->param('newDay');
26 our $month = $input->param('newMonth');
27 our $year = $input->param('newYear');
28 my $dateofrange = $input->param('dateofrange');
29 our $title = $input->param('newTitle');
30 our $description = $input->param('newDescription');
31 our $newoperation = $input->param('newOperation');
32 my $allbranches = $input->param('allBranches');
35 my $first_dt = DateTime
->new(year
=> $year, month
=> $month, day
=> $day);
36 my $end_dt = eval { dt_from_string
( $dateofrange ); };
38 my $calendardate = output_pref
( { dt
=> $first_dt, dateonly
=> 1, dateformat
=> 'iso' } );
40 $title || ($title = '');
42 $description =~ s/\r/\\r/g;
43 $description =~ s/\n/\\n/g;
48 # We make an array with holiday's days
51 for (my $dt = $first_dt->clone();
55 push @holiday_list, $dt->clone();
60 my $libraries = Koha
::Libraries
->search;
61 while ( my $library = $libraries->next ) {
62 add_holiday
($newoperation, $library->branchcode, $weekday, $day, $month, $year, $title, $description);
65 add_holiday
($newoperation, $branchcode, $weekday, $day, $month, $year, $title, $description);
68 print $input->redirect("/cgi-bin/koha/tools/holidays.pl?branch=$originalbranchcode&calendardate=$calendardate");
70 #FIXME: move add_holiday() to a better place
72 ($newoperation, $branchcode, $weekday, $day, $month, $year, $title, $description) = @_;
73 my $calendar = C4
::Calendar
->new(branchcode
=> $branchcode);
75 if ($newoperation eq 'weekday') {
76 unless ( $weekday && ($weekday ne '') ) {
77 # was dow calculated by javascript? original code implies it was supposed to be.
79 $weekday = &Date
::Calc
::Day_of_Week
($year, $month, $day) % 7 unless($weekday);
81 unless($calendar->isHoliday($day, $month, $year)) {
82 $calendar->insert_week_day_holiday(weekday
=> $weekday,
84 description
=> $description);
86 } elsif ($newoperation eq 'repeatable') {
87 unless($calendar->isHoliday($day, $month, $year)) {
88 $calendar->insert_day_month_holiday(day
=> $day,
91 description
=> $description);
93 } elsif ($newoperation eq 'holiday') {
94 unless($calendar->isHoliday($day, $month, $year)) {
95 $calendar->insert_single_holiday(day
=> $day,
99 description
=> $description);
102 } elsif ( $newoperation eq 'holidayrange' ) {
104 foreach my $date (@holiday_list){
105 unless ( $calendar->isHoliday( $date->{local_c
}->{day
}, $date->{local_c
}->{month
}, $date->{local_c
}->{year
} ) ) {
106 $calendar->insert_single_holiday(
107 day
=> $date->{local_c
}->{day
},
108 month
=> $date->{local_c
}->{month
},
109 year
=> $date->{local_c
}->{year
},
111 description
=> $description
116 } elsif ( $newoperation eq 'holidayrangerepeat' ) {
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_day_month_holiday(
121 day
=> $date->{local_c
}->{day
},
122 month
=> $date->{local_c
}->{month
},
124 description
=> $description
130 # we updated the single_holidays table, so wipe its cache
131 my $cache = Koha
::Caches
->get_instance();
132 $cache->clear_from_cache( 'single_holidays') ;