|
Lines 15-34
use Koha::Caches;
Link Here
|
| 15 |
use C4::Calendar; |
15 |
use C4::Calendar; |
| 16 |
use DateTime; |
16 |
use DateTime; |
| 17 |
use Koha::DateUtils; |
17 |
use Koha::DateUtils; |
|
|
18 |
use Koha::Calendar; |
| 18 |
|
19 |
|
| 19 |
my $input = new CGI; |
20 |
my $input = new CGI; |
| 20 |
my $dbh = C4::Context->dbh(); |
21 |
my $dbh = C4::Context->dbh(); |
| 21 |
|
22 |
|
| 22 |
our $branchcode = $input->param('newBranchName'); |
23 |
my $branchcode = $input->param('newBranchName'); |
| 23 |
my $originalbranchcode = $branchcode; |
24 |
my $originalbranchcode = $branchcode; |
| 24 |
our $weekday = $input->param('newWeekday'); |
25 |
my $weekday = $input->param('newWeekday'); |
| 25 |
our $day = $input->param('newDay'); |
26 |
my $day = $input->param('newDay'); |
| 26 |
our $month = $input->param('newMonth'); |
27 |
my $month = $input->param('newMonth'); |
| 27 |
our $year = $input->param('newYear'); |
28 |
my $year = $input->param('newYear'); |
| 28 |
my $dateofrange = $input->param('dateofrange'); |
29 |
my $dateofrange = $input->param('dateofrange'); |
| 29 |
our $title = $input->param('newTitle'); |
30 |
my $title = $input->param('newTitle'); |
| 30 |
our $description = $input->param('newDescription'); |
31 |
my $description = $input->param('newDescription'); |
| 31 |
our $newoperation = $input->param('newOperation'); |
32 |
my $newoperation = $input->param('newOperation'); |
| 32 |
my $allbranches = $input->param('allBranches'); |
33 |
my $allbranches = $input->param('allBranches'); |
| 33 |
|
34 |
|
| 34 |
|
35 |
|
|
Lines 46-52
if ($description) {
Link Here
|
| 46 |
} |
47 |
} |
| 47 |
|
48 |
|
| 48 |
# We make an array with holiday's days |
49 |
# We make an array with holiday's days |
| 49 |
our @holiday_list; |
50 |
my @holiday_list; |
| 50 |
if ($end_dt){ |
51 |
if ($end_dt){ |
| 51 |
for (my $dt = $first_dt->clone(); |
52 |
for (my $dt = $first_dt->clone(); |
| 52 |
$dt <= $end_dt; |
53 |
$dt <= $end_dt; |
|
Lines 59-133
if ($end_dt){
Link Here
|
| 59 |
if($allbranches) { |
60 |
if($allbranches) { |
| 60 |
my $libraries = Koha::Libraries->search; |
61 |
my $libraries = Koha::Libraries->search; |
| 61 |
while ( my $library = $libraries->next ) { |
62 |
while ( my $library = $libraries->next ) { |
| 62 |
add_holiday($newoperation, $library->branchcode, $weekday, $day, $month, $year, $title, $description); |
63 |
Koha::Calendar::add_holiday($newoperation, $library->branchcode, $weekday, $day, $month, $year, $title, $description, @holiday_list); |
| 63 |
} |
64 |
} |
| 64 |
} else { |
65 |
} else { |
| 65 |
add_holiday($newoperation, $branchcode, $weekday, $day, $month, $year, $title, $description); |
66 |
Koha::Calendar::add_holiday($newoperation, $branchcode, $weekday, $day, $month, $year, $title, $description, @holiday_list); |
| 66 |
} |
67 |
} |
| 67 |
|
68 |
|
| 68 |
print $input->redirect("/cgi-bin/koha/tools/holidays.pl?branch=$originalbranchcode&calendardate=$calendardate"); |
69 |
print $input->redirect("/cgi-bin/koha/tools/holidays.pl?branch=$originalbranchcode&calendardate=$calendardate"); |
| 69 |
|
|
|
| 70 |
#FIXME: move add_holiday() to a better place |
| 71 |
sub add_holiday { |
| 72 |
($newoperation, $branchcode, $weekday, $day, $month, $year, $title, $description) = @_; |
| 73 |
my $calendar = C4::Calendar->new(branchcode => $branchcode); |
| 74 |
|
| 75 |
if ($newoperation eq 'weekday') { |
| 76 |
unless ( $weekday && ($weekday ne '') ) { |
| 77 |
# was dow calculated by javascript? original code implies it was supposed to be. |
| 78 |
# if not, we need it. |
| 79 |
$weekday = &Date::Calc::Day_of_Week($year, $month, $day) % 7 unless($weekday); |
| 80 |
} |
| 81 |
unless($calendar->isHoliday($day, $month, $year)) { |
| 82 |
$calendar->insert_week_day_holiday(weekday => $weekday, |
| 83 |
title => $title, |
| 84 |
description => $description); |
| 85 |
} |
| 86 |
} elsif ($newoperation eq 'repeatable') { |
| 87 |
unless($calendar->isHoliday($day, $month, $year)) { |
| 88 |
$calendar->insert_day_month_holiday(day => $day, |
| 89 |
month => $month, |
| 90 |
title => $title, |
| 91 |
description => $description); |
| 92 |
} |
| 93 |
} elsif ($newoperation eq 'holiday') { |
| 94 |
unless($calendar->isHoliday($day, $month, $year)) { |
| 95 |
$calendar->insert_single_holiday(day => $day, |
| 96 |
month => $month, |
| 97 |
year => $year, |
| 98 |
title => $title, |
| 99 |
description => $description); |
| 100 |
} |
| 101 |
|
| 102 |
} elsif ( $newoperation eq 'holidayrange' ) { |
| 103 |
if (@holiday_list){ |
| 104 |
foreach my $date (@holiday_list){ |
| 105 |
unless ( $calendar->isHoliday( $date->{local_c}->{day}, $date->{local_c}->{month}, $date->{local_c}->{year} ) ) { |
| 106 |
$calendar->insert_single_holiday( |
| 107 |
day => $date->{local_c}->{day}, |
| 108 |
month => $date->{local_c}->{month}, |
| 109 |
year => $date->{local_c}->{year}, |
| 110 |
title => $title, |
| 111 |
description => $description |
| 112 |
); |
| 113 |
} |
| 114 |
} |
| 115 |
} |
| 116 |
} elsif ( $newoperation eq 'holidayrangerepeat' ) { |
| 117 |
if (@holiday_list){ |
| 118 |
foreach my $date (@holiday_list){ |
| 119 |
unless ( $calendar->isHoliday( $date->{local_c}->{day}, $date->{local_c}->{month}, $date->{local_c}->{year} ) ) { |
| 120 |
$calendar->insert_day_month_holiday( |
| 121 |
day => $date->{local_c}->{day}, |
| 122 |
month => $date->{local_c}->{month}, |
| 123 |
title => $title, |
| 124 |
description => $description |
| 125 |
); |
| 126 |
} |
| 127 |
} |
| 128 |
} |
| 129 |
} |
| 130 |
# we updated the single_holidays table, so wipe its cache |
| 131 |
my $cache = Koha::Caches->get_instance(); |
| 132 |
$cache->clear_from_cache( 'single_holidays') ; |
| 133 |
} |
| 134 |
- |