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');
31 my $dateofrange = $input->param('dateofrange');
32 our $title = $input->param('newTitle');
33 our $description = $input->param('newDescription');
34 our $newoperation = $input->param('newOperation');
35 my $allbranches = $input->param('allBranches');
37 my $calendardate = sprintf("%04d-%02d-%02d", $year, $month, $day);
38 my $isodate = C4::Dates->new($calendardate, 'iso');
39 $calendardate = $isodate->output('syspref');
41 my @dateend = split(/[\/-]/, $dateofrange);
42 if (C4::Context->preference("dateformat") eq "metric") {
44 $month1 = $dateend[1];
46 }elsif (C4::Context->preference("dateformat") eq "us") {
47 $month1 = $dateend[0];
52 $month1 = $dateend[1];
55 $title || ($title = '');
57 $description =~ s/\r/\\r/g;
58 $description =~ s/\n/\\n/g;
63 # We make an array with holiday's days
65 if ($year1 && $month1 && $day1){
66 my $first_dt = DateTime->new(year => $year, month => $month, day => $day);
67 my $end_dt = DateTime->new(year => $year1, month => $month1, day => $day1);
69 for (my $dt = $first_dt->clone();
73 push @holiday_list, $dt->clone();
79 my @branchcodes = split(/\|/, $input->param('branchCodes'));
80 foreach $branch (@branchcodes) {
81 add_holiday($newoperation, $branch, $weekday, $day, $month, $year, $title, $description);
84 add_holiday($newoperation, $branchcode, $weekday, $day, $month, $year, $title, $description);
87 print $input->redirect("/cgi-bin/koha/tools/holidays.pl?branch=$originalbranchcode&calendardate=$calendardate");
89 #FIXME: move add_holiday() to a better place
91 ($newoperation, $branchcode, $weekday, $day, $month, $year, $title, $description) = @_;
92 my $calendar = C4::Calendar->new(branchcode => $branchcode);
94 if ($newoperation eq 'weekday') {
95 unless ( $weekday && ($weekday ne '') ) {
96 # was dow calculated by javascript? original code implies it was supposed to be.
98 $weekday = &Date::Calc::Day_of_Week($year, $month, $day) % 7 unless($weekday);
100 unless($calendar->isHoliday($day, $month, $year)) {
101 $calendar->insert_week_day_holiday(weekday => $weekday,
103 description => $description);
105 } elsif ($newoperation eq 'repeatable') {
106 unless($calendar->isHoliday($day, $month, $year)) {
107 $calendar->insert_day_month_holiday(day => $day,
110 description => $description);
112 } elsif ($newoperation eq 'holiday') {
113 unless($calendar->isHoliday($day, $month, $year)) {
114 $calendar->insert_single_holiday(day => $day,
118 description => $description);
121 } elsif ( $newoperation eq 'holidayrange' ) {
123 foreach my $date (@holiday_list){
124 unless ( $calendar->isHoliday( $date->{local_c}->{day}, $date->{local_c}->{month}, $date->{local_c}->{year} ) ) {
125 $calendar->insert_single_holiday(
126 day => $date->{local_c}->{day},
127 month => $date->{local_c}->{month},
128 year => $date->{local_c}->{year},
130 description => $description
135 } elsif ( $newoperation eq 'holidayrangerepeat' ) {
137 foreach my $date (@holiday_list){
138 unless ( $calendar->isHoliday( $date->{local_c}->{day}, $date->{local_c}->{month}, $date->{local_c}->{year} ) ) {
139 $calendar->insert_day_month_holiday(
140 day => $date->{local_c}->{day},
141 month => $date->{local_c}->{month},
143 description => $description
149 # we updated the single_holidays table, so wipe its cache
150 my $cache = Koha::Cache->get_instance();
151 $cache->clear_from_cache( 'single_holidays') ;