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();
61 my @branchcodes = split(/\|/, $input->param('branchCodes'));
62 foreach $branch (@branchcodes) {
63 add_holiday
($newoperation, $branch, $weekday, $day, $month, $year, $title, $description);
66 add_holiday
($newoperation, $branchcode, $weekday, $day, $month, $year, $title, $description);
69 print $input->redirect("/cgi-bin/koha/tools/holidays.pl?branch=$originalbranchcode&calendardate=$calendardate");
71 #FIXME: move add_holiday() to a better place
73 ($newoperation, $branchcode, $weekday, $day, $month, $year, $title, $description) = @_;
74 my $calendar = C4
::Calendar
->new(branchcode
=> $branchcode);
76 if ($newoperation eq 'weekday') {
77 unless ( $weekday && ($weekday ne '') ) {
78 # was dow calculated by javascript? original code implies it was supposed to be.
80 $weekday = &Date
::Calc
::Day_of_Week
($year, $month, $day) % 7 unless($weekday);
82 unless($calendar->isHoliday($day, $month, $year)) {
83 $calendar->insert_week_day_holiday(weekday
=> $weekday,
85 description
=> $description);
87 } elsif ($newoperation eq 'repeatable') {
88 unless($calendar->isHoliday($day, $month, $year)) {
89 $calendar->insert_day_month_holiday(day
=> $day,
92 description
=> $description);
94 } elsif ($newoperation eq 'holiday') {
95 unless($calendar->isHoliday($day, $month, $year)) {
96 $calendar->insert_single_holiday(day
=> $day,
100 description
=> $description);
103 } elsif ( $newoperation eq 'holidayrange' ) {
105 foreach my $date (@holiday_list){
106 unless ( $calendar->isHoliday( $date->{local_c
}->{day
}, $date->{local_c
}->{month
}, $date->{local_c
}->{year
} ) ) {
107 $calendar->insert_single_holiday(
108 day
=> $date->{local_c
}->{day
},
109 month
=> $date->{local_c
}->{month
},
110 year
=> $date->{local_c
}->{year
},
112 description
=> $description
117 } elsif ( $newoperation eq 'holidayrangerepeat' ) {
119 foreach my $date (@holiday_list){
120 unless ( $calendar->isHoliday( $date->{local_c
}->{day
}, $date->{local_c
}->{month
}, $date->{local_c
}->{year
} ) ) {
121 $calendar->insert_day_month_holiday(
122 day
=> $date->{local_c
}->{day
},
123 month
=> $date->{local_c
}->{month
},
125 description
=> $description
131 # we updated the single_holidays table, so wipe its cache
132 my $cache = Koha
::Caches
->get_instance();
133 $cache->clear_from_cache( 'single_holidays') ;