Update Debian changelog for 3.2.1 release
[koha.git] / tools / newHolidays.pl
blob34469d85f98e545fbd2ac23ab0b01d97e683d471
1 #!/usr/bin/perl
3 use strict;
4 use warnings;
6 use CGI;
8 use C4::Auth;
9 use C4::Output;
12 use C4::Calendar;
14 my $input = new CGI;
15 my $dbh = C4::Context->dbh();
17 my $branchcode = $input->param('newBranchName');
18 my $originalbranchcode = $branchcode;
19 my $weekday = $input->param('newWeekday');
20 my $day = $input->param('newDay');
21 my $month = $input->param('newMonth');
22 my $year = $input->param('newYear');
23 my $title = $input->param('newTitle');
24 my $description = $input->param('newDescription');
25 my $newoperation = $input->param('newOperation');
26 my $allbranches = $input->param('allBranches');
28 my $calendardate = sprintf("%04d-%02d-%02d", $year, $month, $day);
29 my $isodate = C4::Dates->new($calendardate, 'iso');
30 $calendardate = $isodate->output('syspref');
32 $title || ($title = '');
33 if ($description) {
34 $description =~ s/\r/\\r/g;
35 $description =~ s/\n/\\n/g;
36 } else {
37 $description = '';
40 if($allbranches) {
41 my $branch;
42 my @branchcodes = split(/\|/, $input->param('branchCodes'));
43 foreach $branch (@branchcodes) {
44 add_holiday($newoperation, $branch, $weekday, $day, $month, $year, $title, $description);
46 } else {
47 add_holiday($newoperation, $branchcode, $weekday, $day, $month, $year, $title, $description);
50 print $input->redirect("/cgi-bin/koha/tools/holidays.pl?branch=$originalbranchcode&calendardate=$calendardate");
52 sub add_holiday {
53 ($newoperation, $branchcode, $weekday, $day, $month, $year, $title, $description) = @_;
54 my $calendar = C4::Calendar->new(branchcode => $branchcode);
56 if ($newoperation eq 'weekday') {
57 unless ( $weekday && ($weekday ne '') ) {
58 # was dow calculated by javascript? original code implies it was supposed to be.
59 # if not, we need it.
60 $weekday = &Date::Calc::Day_of_Week($year, $month, $day) % 7 unless($weekday);
62 unless($calendar->isHoliday($day, $month, $year)) {
63 $calendar->insert_week_day_holiday(weekday => $weekday,
64 title => $title,
65 description => $description);
67 } elsif ($newoperation eq 'repeatable') {
68 unless($calendar->isHoliday($day, $month, $year)) {
69 $calendar->insert_day_month_holiday(day => $day,
70 month => $month,
71 title => $title,
72 description => $description);
74 } elsif ($newoperation eq 'holiday') {
75 unless($calendar->isHoliday($day, $month, $year)) {
76 $calendar->insert_single_holiday(day => $day,
77 month => $month,
78 year => $year,
79 title => $title,
80 description => $description);