rel_3_0 moved to HEAD
[koha.git] / tools / newHolidays.pl
1 #!/usr/bin/perl
2
3 use strict;
4 use CGI;
5
6 use C4::Auth;
7 use C4::Output;
8 use C4::Interface::CGI::Output;
9
10
11 use C4::Calendar;
12
13 my $input = new CGI;
14 my $dbh = C4::Context->dbh();
15
16 my $branchcode = $input->param('newBranchName');
17 my $weekday = $input->param('newWeekday');
18 my $day = $input->param('newDay');
19 my $month = $input->param('newMonth');
20 my $year = $input->param('newYear');
21 my $title = $input->param('newTitle');
22 my $description = $input->param('newDescription');
23
24 $title || ($title = '');
25 if ($description) {
26         $description =~ s/\r/\\r/g;
27         $description =~ s/\n/\\n/g;
28 } else {
29         $description = '';
30 }
31
32 my $calendar = C4::Calendar->new(branchcode => $branchcode);
33
34 if ($input->param('newOperation') eq 'weekday') {
35         $calendar->insert_week_day_holiday(weekday => $weekday,
36                                                                    title => $title,
37                                                                    description => $description);
38 } elsif ($input->param('newOperation') eq 'repeatable') {
39         $calendar->insert_day_month_holiday(day => $day,
40                                             month => $month,
41                                                                     title => $title,
42                                                                     description => $description);
43 } elsif ($input->param('newOperation') eq 'holiday') {
44         $calendar->insert_single_holiday(day => $day,
45                                          month => $month,
46                                                              year => $year,
47                                                              title => $title,
48                                                              description => $description);
49
50 }
51 print $input->redirect("/cgi-bin/koha/tools/holidays.pl?branch=$branchcode");