Bug 1768: Calendar now retains the month on which the user was entering data.
[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 my $calendardate = sprintf("%04d-%02d-%02d", $year, $month, $day);
24 my $isodate = C4::Dates->new($calendardate, 'iso');
25 $calendardate = $isodate->output('syspref');
26
27 $title || ($title = '');
28 if ($description) {
29         $description =~ s/\r/\\r/g;
30         $description =~ s/\n/\\n/g;
31 } else {
32         $description = '';
33 }
34 my $calendar = C4::Calendar->new(branchcode => $branchcode);
35
36 if ($input->param('newOperation') eq 'weekday') {
37         unless ( $weekday && ($weekday ne '') ) { 
38                 # was dow calculated by javascript?  original code implies it was supposed to be.
39                 # if not, we need it.
40                 $weekday = &Date::Calc::Day_of_Week($year, $month, $day) % 7 unless($weekday);
41         }
42         $calendar->insert_week_day_holiday(weekday => $weekday,
43                                                                    title => $title,
44                                                                    description => $description);
45 } elsif ($input->param('newOperation') eq 'repeatable') {
46         $calendar->insert_day_month_holiday(day => $day,
47                                             month => $month,
48                                                                     title => $title,
49                                                                     description => $description);
50 } elsif ($input->param('newOperation') eq 'holiday') {
51         $calendar->insert_single_holiday(day => $day,
52                                          month => $month,
53                                                              year => $year,
54                                                              title => $title,
55                                                              description => $description);
56
57 }
58 print $input->redirect("/cgi-bin/koha/tools/holidays.pl?branch=$branchcode&calendardate=$calendardate");