Bug 12706: Remove CGI::scrolling_list from serial_stats.pl
[koha.git] / tools / exceptionHolidays.pl
blob0a36a20e31b58320f0f94197abc5a3bf2d7b5227
1 #!/usr/bin/perl
3 use strict;
4 use warnings;
6 use CGI;
8 use C4::Auth;
9 use C4::Output;
10 use DateTime;
12 use C4::Calendar;
14 my $input = new CGI;
15 my $dbh = C4::Context->dbh();
17 my $branchcode = $input->param('showBranchName');
18 my $weekday = $input->param('showWeekday');
19 my $day = $input->param('showDay');
20 my $month = $input->param('showMonth');
21 my $year = $input->param('showYear');
22 my $day1;
23 my $month1;
24 my $year1;
25 my $title = $input->param('showTitle');
26 my $description = $input->param('showDescription');
27 my $holidaytype = $input->param('showHolidayType');
28 my $datecancelrange = $input->param('datecancelrange');
29 my $calendardate = sprintf("%04d-%02d-%02d", $year, $month, $day);
30 my $isodate = C4::Dates->new($calendardate, 'iso');
31 $calendardate = $isodate->output('syspref');
33 my $calendar = C4::Calendar->new(branchcode => $branchcode);
35 $title || ($title = '');
36 if ($description) {
37 $description =~ s/\r/\\r/g;
38 $description =~ s/\n/\\n/g;
39 } else {
40 $description = '';
43 # We format the date
44 my @dateend = split(/[\/-]/, $datecancelrange);
45 if (C4::Context->preference("dateformat") eq "metric") {
46 $day1 = $dateend[0];
47 $month1 = $dateend[1];
48 $year1 = $dateend[2];
49 }elsif (C4::Context->preference("dateformat") eq "us") {
50 $month1 = $dateend[0];
51 $day1 = $dateend[1];
52 $year1 = $dateend[2];
53 } else {
54 $year1 = $dateend[0];
55 $month1 = $dateend[1];
56 $day1 = $dateend[2];
59 # We make an array with holiday's days
60 my @holiday_list;
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();
66 $dt <= $end_dt;
67 $dt->add(days => 1) )
69 push @holiday_list, $dt->clone();
72 if ($input->param('showOperation') eq 'exception') {
73 $calendar->insert_exception_holiday(day => $day,
74 month => $month,
75 year => $year,
76 title => $title,
77 description => $description);
78 } elsif ($input->param('showOperation') eq 'exceptionrange' ) {
79 if (@holiday_list){
80 foreach my $date (@holiday_list){
81 $calendar->insert_exception_holiday(
82 day => $date->{local_c}->{day},
83 month => $date->{local_c}->{month},
84 year => $date->{local_c}->{year},
85 title => $title,
86 description => $description
90 } elsif ($input->param('showOperation') eq 'edit') {
91 if($holidaytype eq 'weekday') {
92 $calendar->ModWeekdayholiday(weekday => $weekday,
93 title => $title,
94 description => $description);
95 } elsif ($holidaytype eq 'daymonth') {
96 $calendar->ModDaymonthholiday(day => $day,
97 month => $month,
98 title => $title,
99 description => $description);
100 } elsif ($holidaytype eq 'ymd') {
101 $calendar->ModSingleholiday(day => $day,
102 month => $month,
103 year => $year,
104 title => $title,
105 description => $description);
106 } elsif ($holidaytype eq 'exception') {
107 $calendar->ModExceptionholiday(day => $day,
108 month => $month,
109 year => $year,
110 title => $title,
111 description => $description);
113 } elsif ($input->param('showOperation') eq 'delete') {
114 $calendar->delete_holiday(weekday => $weekday,
115 day => $day,
116 month => $month,
117 year => $year);
118 }elsif ($input->param('showOperation') eq 'deleterange') {
119 if (@holiday_list){
120 foreach my $date (@holiday_list){
121 $calendar->delete_holiday_range(weekday => $weekday,
122 day => $date->{local_c}->{day},
123 month => $date->{local_c}->{month},
124 year => $date->{local_c}->{year});
127 }elsif ($input->param('showOperation') eq 'deleterangerepeat') {
128 if (@holiday_list){
129 foreach my $date (@holiday_list){
130 $calendar->delete_holiday_range_repeatable(weekday => $weekday,
131 day => $date->{local_c}->{day},
132 month => $date->{local_c}->{month});
135 }elsif ($input->param('showOperation') eq 'deleterangerepeatexcept') {
136 if (@holiday_list){
137 foreach my $date (@holiday_list){
138 $calendar->delete_exception_holiday_range(weekday => $weekday,
139 day => $date->{local_c}->{day},
140 month => $date->{local_c}->{month},
141 year => $date->{local_c}->{year});
145 print $input->redirect("/cgi-bin/koha/tools/holidays.pl?branch=$branchcode&calendardate=$calendardate");