Bug 8595: (follow-up) Changing other occurrences of 'host item' to 'host record'
[koha.git] / tools / exceptionHolidays.pl
blob1f3b9672fb0f5442b066b60c87e69a5b96966eb3
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 checkauth($input, 0, {tools=> 'edit_calendar'}, 'intranet');
20 my $branchcode = $input->param('showBranchName');
21 my $weekday = $input->param('showWeekday');
22 my $day = $input->param('showDay');
23 my $month = $input->param('showMonth');
24 my $year = $input->param('showYear');
25 my $title = $input->param('showTitle');
26 my $description = $input->param('showDescription');
27 my $holidaytype = $input->param('showHolidayType');
28 my $datecancelrange_dt = eval { dt_from_string( scalar $input->param('datecancelrange') ) };
29 my $calendardate = sprintf("%04d-%02d-%02d", $year, $month, $day);
31 my $calendar = C4::Calendar->new(branchcode => $branchcode);
33 $title || ($title = '');
34 if ($description) {
35 $description =~ s/\r/\\r/g;
36 $description =~ s/\n/\\n/g;
37 } else {
38 $description = '';
41 # We make an array with holiday's days
42 my @holiday_list;
43 if ($datecancelrange_dt){
44 my $first_dt = DateTime->new(year => $year, month => $month, day => $day);
46 for (my $dt = $first_dt->clone();
47 $dt <= $datecancelrange_dt;
48 $dt->add(days => 1) )
50 push @holiday_list, $dt->clone();
53 if ($input->param('showOperation') eq 'exception') {
54 $calendar->insert_exception_holiday(day => $day,
55 month => $month,
56 year => $year,
57 title => $title,
58 description => $description);
59 } elsif ($input->param('showOperation') eq 'exceptionrange' ) {
60 if (@holiday_list){
61 foreach my $date (@holiday_list){
62 $calendar->insert_exception_holiday(
63 day => $date->{local_c}->{day},
64 month => $date->{local_c}->{month},
65 year => $date->{local_c}->{year},
66 title => $title,
67 description => $description
71 } elsif ($input->param('showOperation') eq 'edit') {
72 if($holidaytype eq 'weekday') {
73 $calendar->ModWeekdayholiday(weekday => $weekday,
74 title => $title,
75 description => $description);
76 } elsif ($holidaytype eq 'daymonth') {
77 $calendar->ModDaymonthholiday(day => $day,
78 month => $month,
79 title => $title,
80 description => $description);
81 } elsif ($holidaytype eq 'ymd') {
82 $calendar->ModSingleholiday(day => $day,
83 month => $month,
84 year => $year,
85 title => $title,
86 description => $description);
87 } elsif ($holidaytype eq 'exception') {
88 $calendar->ModExceptionholiday(day => $day,
89 month => $month,
90 year => $year,
91 title => $title,
92 description => $description);
94 } elsif ($input->param('showOperation') eq 'delete') {
95 $calendar->delete_holiday(weekday => $weekday,
96 day => $day,
97 month => $month,
98 year => $year);
99 }elsif ($input->param('showOperation') eq 'deleterange') {
100 if (@holiday_list){
101 foreach my $date (@holiday_list){
102 $calendar->delete_holiday_range(weekday => $weekday,
103 day => $date->{local_c}->{day},
104 month => $date->{local_c}->{month},
105 year => $date->{local_c}->{year});
108 }elsif ($input->param('showOperation') eq 'deleterangerepeat') {
109 if (@holiday_list){
110 foreach my $date (@holiday_list){
111 $calendar->delete_holiday_range_repeatable(weekday => $weekday,
112 day => $date->{local_c}->{day},
113 month => $date->{local_c}->{month});
116 }elsif ($input->param('showOperation') eq 'deleterangerepeatexcept') {
117 if (@holiday_list){
118 foreach my $date (@holiday_list){
119 $calendar->delete_exception_holiday_range(weekday => $weekday,
120 day => $date->{local_c}->{day},
121 month => $date->{local_c}->{month},
122 year => $date->{local_c}->{year});
126 print $input->redirect("/cgi-bin/koha/tools/holidays.pl?branch=$branchcode&calendardate=$calendardate");