bug 2857: fix UTF-8 conversion issues in web services
[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
9
10 use C4::Calendar;
11
12 my $input = new CGI;
13 my $dbh = C4::Context->dbh();
14
15 my $branchcode = $input->param('newBranchName');
16 my $weekday = $input->param('newWeekday');
17 my $day = $input->param('newDay');
18 my $month = $input->param('newMonth');
19 my $year = $input->param('newYear');
20 my $title = $input->param('newTitle');
21 my $description = $input->param('newDescription');
22
23 $title || ($title = '');
24 if ($description) {
25         $description =~ s/\r/\\r/g;
26         $description =~ s/\n/\\n/g;
27 } else {
28         $description = '';
29 }
30 my $calendar = C4::Calendar->new(branchcode => $branchcode);
31
32 if ($input->param('newOperation') eq 'weekday') {
33         unless ( $weekday && ($weekday ne '') ) { 
34                 # was dow calculated by javascript?  original code implies it was supposed to be.
35                 # if not, we need it.
36                 $weekday = &Date::Calc::Day_of_Week($year, $month, $day) % 7 unless($weekday);
37         }
38         $calendar->insert_week_day_holiday(weekday => $weekday,
39                                                                    title => $title,
40                                                                    description => $description);
41 } elsif ($input->param('newOperation') eq 'repeatable') {
42         $calendar->insert_day_month_holiday(day => $day,
43                                             month => $month,
44                                                                     title => $title,
45                                                                     description => $description);
46 } elsif ($input->param('newOperation') eq 'holiday') {
47         $calendar->insert_single_holiday(day => $day,
48                                          month => $month,
49                                                              year => $year,
50                                                              title => $title,
51                                                              description => $description);
52
53 }
54 print $input->redirect("/cgi-bin/koha/tools/holidays.pl?branch=$branchcode");