Bug 8753 - Use Koha::Borrowers instead of C4::Members
[koha.git] / tools / exceptionHolidays.pl
blob0b1818d7d35063e92387d79c3dccc3800fc62ebf
1 #!/usr/bin/perl
3 use strict;
4 use warnings;
6 use CGI qw ( -utf8 );
8 use C4::Auth;
9 use C4::Output;
10 use DateTime;
12 use C4::Calendar;
13 use Koha::DateUtils;
15 my $input = new CGI;
16 my $dbh = C4::Context->dbh();
18 my $branchcode = $input->param('showBranchName');
19 my $weekday = $input->param('showWeekday');
20 my $day = $input->param('showDay');
21 my $month = $input->param('showMonth');
22 my $year = $input->param('showYear');
23 my $title = $input->param('showTitle');
24 my $description = $input->param('showDescription');
25 my $holidaytype = $input->param('showHolidayType');
26 my $datecancelrange_dt = eval { dt_from_string( $input->param('datecancelrange') ) };
27 my $calendardate = sprintf("%04d-%02d-%02d", $year, $month, $day);
29 my $calendar = C4::Calendar->new(branchcode => $branchcode);
31 $title || ($title = '');
32 if ($description) {
33 $description =~ s/\r/\\r/g;
34 $description =~ s/\n/\\n/g;
35 } else {
36 $description = '';
39 # We make an array with holiday's days
40 my @holiday_list;
41 if ($datecancelrange_dt){
42 my $first_dt = DateTime->new(year => $year, month => $month, day => $day);
44 for (my $dt = $first_dt->clone();
45 $dt <= $datecancelrange_dt;
46 $dt->add(days => 1) )
48 push @holiday_list, $dt->clone();
51 if ($input->param('showOperation') eq 'exception') {
52 $calendar->insert_exception_holiday(day => $day,
53 month => $month,
54 year => $year,
55 title => $title,
56 description => $description);
57 } elsif ($input->param('showOperation') eq 'exceptionrange' ) {
58 if (@holiday_list){
59 foreach my $date (@holiday_list){
60 $calendar->insert_exception_holiday(
61 day => $date->{local_c}->{day},
62 month => $date->{local_c}->{month},
63 year => $date->{local_c}->{year},
64 title => $title,
65 description => $description
69 } elsif ($input->param('showOperation') eq 'edit') {
70 if($holidaytype eq 'weekday') {
71 $calendar->ModWeekdayholiday(weekday => $weekday,
72 title => $title,
73 description => $description);
74 } elsif ($holidaytype eq 'daymonth') {
75 $calendar->ModDaymonthholiday(day => $day,
76 month => $month,
77 title => $title,
78 description => $description);
79 } elsif ($holidaytype eq 'ymd') {
80 $calendar->ModSingleholiday(day => $day,
81 month => $month,
82 year => $year,
83 title => $title,
84 description => $description);
85 } elsif ($holidaytype eq 'exception') {
86 $calendar->ModExceptionholiday(day => $day,
87 month => $month,
88 year => $year,
89 title => $title,
90 description => $description);
92 } elsif ($input->param('showOperation') eq 'delete') {
93 $calendar->delete_holiday(weekday => $weekday,
94 day => $day,
95 month => $month,
96 year => $year);
97 }elsif ($input->param('showOperation') eq 'deleterange') {
98 if (@holiday_list){
99 foreach my $date (@holiday_list){
100 $calendar->delete_holiday_range(weekday => $weekday,
101 day => $date->{local_c}->{day},
102 month => $date->{local_c}->{month},
103 year => $date->{local_c}->{year});
106 }elsif ($input->param('showOperation') eq 'deleterangerepeat') {
107 if (@holiday_list){
108 foreach my $date (@holiday_list){
109 $calendar->delete_holiday_range_repeatable(weekday => $weekday,
110 day => $date->{local_c}->{day},
111 month => $date->{local_c}->{month});
114 }elsif ($input->param('showOperation') eq 'deleterangerepeatexcept') {
115 if (@holiday_list){
116 foreach my $date (@holiday_list){
117 $calendar->delete_exception_holiday_range(weekday => $weekday,
118 day => $date->{local_c}->{day},
119 month => $date->{local_c}->{month},
120 year => $date->{local_c}->{year});
124 print $input->redirect("/cgi-bin/koha/tools/holidays.pl?branch=$branchcode&calendardate=$calendardate");