16 my $dbh = C4
::Context
->dbh();
18 our $branchcode = $input->param('newBranchName');
19 my $originalbranchcode = $branchcode;
20 our $weekday = $input->param('newWeekday');
21 our $day = $input->param('newDay');
22 our $month = $input->param('newMonth');
23 our $year = $input->param('newYear');
27 my $dateofrange = $input->param('dateofrange');
28 our $title = $input->param('newTitle');
29 our $description = $input->param('newDescription');
30 our $newoperation = $input->param('newOperation');
31 my $allbranches = $input->param('allBranches');
33 my $calendardate = sprintf("%04d-%02d-%02d", $year, $month, $day);
34 my $isodate = C4
::Dates
->new($calendardate, 'iso');
35 $calendardate = $isodate->output('syspref');
37 my @dateend = split(/[\/-]/, $dateofrange);
38 if (C4
::Context
->preference("dateformat") eq "metric") {
40 $month1 = $dateend[1];
42 }elsif (C4
::Context
->preference("dateformat") eq "us") {
43 $month1 = $dateend[0];
48 $month1 = $dateend[1];
51 $title || ($title = '');
53 $description =~ s/\r/\\r/g;
54 $description =~ s/\n/\\n/g;
59 # We make an array with holiday's days
61 if ($year1 && $month1 && $day1){
62 my $first_dt = DateTime
->new(year
=> $year, month
=> $month, day
=> $day);
63 my $end_dt = DateTime
->new(year
=> $year1, month
=> $month1, day
=> $day1);
65 for (my $dt = $first_dt->clone();
69 push @holiday_list, $dt->clone();
75 my @branchcodes = split(/\|/, $input->param('branchCodes'));
76 foreach $branch (@branchcodes) {
77 add_holiday
($newoperation, $branch, $weekday, $day, $month, $year, $title, $description);
80 add_holiday
($newoperation, $branchcode, $weekday, $day, $month, $year, $title, $description);
83 print $input->redirect("/cgi-bin/koha/tools/holidays.pl?branch=$originalbranchcode&calendardate=$calendardate");
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