Bug 18235: (QA follow-up) Add missing filters
[koha.git] / tools / exceptionHolidays.pl
blob90b17bc6cfaa6fde8d559f828805586b5083d9a3
1 #!/usr/bin/perl
3 use Modern::Perl;
5 use CGI qw ( -utf8 );
7 use C4::Auth;
8 use C4::Output;
9 use DateTime;
11 use C4::Calendar;
12 use Koha::DateUtils;
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 $title = $input->param('showTitle');
23 my $description = $input->param('showDescription');
24 my $holidaytype = $input->param('showHolidayType');
25 my $datecancelrange_dt = eval { dt_from_string( scalar $input->param('datecancelrange') ) };
26 my $calendardate = sprintf("%04d-%02d-%02d", $year, $month, $day);
28 my $calendar = C4::Calendar->new(branchcode => $branchcode);
30 $title || ($title = '');
31 if ($description) {
32 $description =~ s/\r/\\r/g;
33 $description =~ s/\n/\\n/g;
34 } else {
35 $description = '';
38 # We make an array with holiday's days
39 my @holiday_list;
40 if ($datecancelrange_dt){
41 my $first_dt = DateTime->new(year => $year, month => $month, day => $day);
43 for (my $dt = $first_dt->clone();
44 $dt <= $datecancelrange_dt;
45 $dt->add(days => 1) )
47 push @holiday_list, $dt->clone();
50 if ($input->param('showOperation') eq 'exception') {
51 $calendar->insert_exception_holiday(day => $day,
52 month => $month,
53 year => $year,
54 title => $title,
55 description => $description);
56 } elsif ($input->param('showOperation') eq 'exceptionrange' ) {
57 if (@holiday_list){
58 foreach my $date (@holiday_list){
59 $calendar->insert_exception_holiday(
60 day => $date->{local_c}->{day},
61 month => $date->{local_c}->{month},
62 year => $date->{local_c}->{year},
63 title => $title,
64 description => $description
68 } elsif ($input->param('showOperation') eq 'edit') {
69 if($holidaytype eq 'weekday') {
70 $calendar->ModWeekdayholiday(weekday => $weekday,
71 title => $title,
72 description => $description);
73 } elsif ($holidaytype eq 'daymonth') {
74 $calendar->ModDaymonthholiday(day => $day,
75 month => $month,
76 title => $title,
77 description => $description);
78 } elsif ($holidaytype eq 'ymd') {
79 $calendar->ModSingleholiday(day => $day,
80 month => $month,
81 year => $year,
82 title => $title,
83 description => $description);
84 } elsif ($holidaytype eq 'exception') {
85 $calendar->ModExceptionholiday(day => $day,
86 month => $month,
87 year => $year,
88 title => $title,
89 description => $description);
91 } elsif ($input->param('showOperation') eq 'delete') {
92 $calendar->delete_holiday(weekday => $weekday,
93 day => $day,
94 month => $month,
95 year => $year);
96 }elsif ($input->param('showOperation') eq 'deleterange') {
97 if (@holiday_list){
98 foreach my $date (@holiday_list){
99 $calendar->delete_holiday_range(weekday => $weekday,
100 day => $date->{local_c}->{day},
101 month => $date->{local_c}->{month},
102 year => $date->{local_c}->{year});
105 }elsif ($input->param('showOperation') eq 'deleterangerepeat') {
106 if (@holiday_list){
107 foreach my $date (@holiday_list){
108 $calendar->delete_holiday_range_repeatable(weekday => $weekday,
109 day => $date->{local_c}->{day},
110 month => $date->{local_c}->{month});
113 }elsif ($input->param('showOperation') eq 'deleterangerepeatexcept') {
114 if (@holiday_list){
115 foreach my $date (@holiday_list){
116 $calendar->delete_exception_holiday_range(weekday => $weekday,
117 day => $date->{local_c}->{day},
118 month => $date->{local_c}->{month},
119 year => $date->{local_c}->{year});
123 print $input->redirect("/cgi-bin/koha/tools/holidays.pl?branch=$branchcode&calendardate=$calendardate");