|
Lines 9-20
use CGI qw ( -utf8 );
Link Here
|
| 9 |
|
9 |
|
| 10 |
use C4::Auth; |
10 |
use C4::Auth; |
| 11 |
use C4::Output; |
11 |
use C4::Output; |
| 12 |
|
|
|
| 13 |
use Koha::Cache; |
12 |
use Koha::Cache; |
| 14 |
|
|
|
| 15 |
use C4::Calendar; |
13 |
use C4::Calendar; |
| 16 |
use DateTime; |
14 |
use DateTime; |
| 17 |
use Koha::DateUtils; |
15 |
use Koha::DateUtils; |
|
|
16 |
use DateTime::Format::Strptime; |
| 18 |
|
17 |
|
| 19 |
my $input = new CGI; |
18 |
my $input = new CGI; |
| 20 |
my $dbh = C4::Context->dbh(); |
19 |
my $dbh = C4::Context->dbh(); |
|
Lines 58-80
if ($end_dt){
Link Here
|
| 58 |
|
57 |
|
| 59 |
if($allbranches) { |
58 |
if($allbranches) { |
| 60 |
my $branch; |
59 |
my $branch; |
| 61 |
my @branchcodes = split(/\|/, $input->param('branchCodes')); |
60 |
my @branchcodes = split(/\|/, $input->param('branchCodes')); |
| 62 |
foreach $branch (@branchcodes) { |
61 |
foreach $branch (@branchcodes) { |
| 63 |
add_holiday($newoperation, $branch, $weekday, $day, $month, $year, $title, $description); |
62 |
add_holiday($newoperation, $branch, $weekday, $day, $month, $year, $title, $description); |
|
|
63 |
addHoliday($newoperation, $branch, $weekday, $day, $month, $title); |
| 64 |
} |
64 |
} |
| 65 |
} else { |
65 |
} else { |
| 66 |
add_holiday($newoperation, $branchcode, $weekday, $day, $month, $year, $title, $description); |
66 |
add_holiday($newoperation, $branchcode, $weekday, $day, $month, $year, $title, $description); |
|
|
67 |
addHoliday($newoperation, $branchcode, $weekday, $day, $month, $title); |
| 67 |
} |
68 |
} |
| 68 |
|
69 |
|
| 69 |
print $input->redirect("/cgi-bin/koha/tools/holidays.pl?branch=$originalbranchcode&calendardate=$calendardate"); |
70 |
print $input->redirect("/cgi-bin/koha/tools/holidays.pl?branch=$originalbranchcode&calendardate=$calendardate"); |
| 70 |
|
71 |
|
|
|
72 |
sub isOpened{ |
| 73 |
my ($branchcode, $date) = @_; |
| 74 |
my $isopened; |
| 75 |
my $query = "select isopened from discrete_calendar where branchcode=? and date=?"; |
| 76 |
my $stmt = $dbh->prepare($query); |
| 77 |
$stmt->execute($branchcode, $date); |
| 78 |
$isopened = $stmt->fetchrow_array; |
| 79 |
|
| 80 |
return $isopened; |
| 81 |
} |
| 82 |
sub addHoliday{ |
| 83 |
my ($newoperation, $branchcode, $weekday, $day, $month, $title) = @_; |
| 84 |
my $startDate = output_pref( { dt => $first_dt, dateonly => 1, dateformat => 'iso' } ); |
| 85 |
my $endDate = output_pref( { dt => $end_dt, dateonly => 1, dateformat => 'iso' } ); |
| 86 |
|
| 87 |
if($newoperation eq 'holiday'){ |
| 88 |
if (isOpened($branchcode,$startDate)) { |
| 89 |
insert_single_day($branchcode, $title); |
| 90 |
} |
| 91 |
}elsif($newoperation eq 'weekday'){ |
| 92 |
if (isOpened($branchcode,$startDate)) { |
| 93 |
insert_weekday_day($branchcode, $weekday, $title); |
| 94 |
} |
| 95 |
}elsif($newoperation eq 'repeatable'){ |
| 96 |
if (isOpened($branchcode,$startDate)) { |
| 97 |
insert_yearly_holiday($branchcode, $day, $month, $title); |
| 98 |
} |
| 99 |
}elsif($newoperation eq 'holidayrange'){ |
| 100 |
insert_range_holiday($branchcode, $title); |
| 101 |
}elsif($newoperation eq 'holidayrangerepeat'){ |
| 102 |
insert_range_holiday_repeat($branchcode, $title); |
| 103 |
} |
| 104 |
} |
| 105 |
|
| 106 |
sub insert_single_day{ |
| 107 |
my ($branchcode,$title) = @_; |
| 108 |
my $startDate = output_pref( { dt => $first_dt, dateonly => 1, dateformat => 'iso' } ); |
| 109 |
my $today = DateTime->today; |
| 110 |
my $query = "update discrete_calendar set isOpened=0, note=? where branchcode=? and date=? and date>=?"; |
| 111 |
my $stmt = $dbh->prepare($query); |
| 112 |
|
| 113 |
$stmt->execute($title, $branchcode, $startDate, $today); |
| 114 |
|
| 115 |
} |
| 116 |
|
| 117 |
sub insert_weekday_day{ |
| 118 |
my ($branchcode, $weekday, $title) = @_; |
| 119 |
$weekday+=1; |
| 120 |
my $startDate = output_pref( { dt => $first_dt, dateonly => 1, dateformat => 'iso' } ); |
| 121 |
my $today = DateTime->today; |
| 122 |
my $query = "update discrete_calendar set isOpened=0, note=? where branchcode=? and DAYOFWEEK(date)=? and date >=?"; |
| 123 |
my $stmt = $dbh->prepare($query); |
| 124 |
|
| 125 |
$stmt->execute($title,$branchcode,$weekday,$today); |
| 126 |
} |
| 127 |
|
| 128 |
sub insert_yearly_holiday{ |
| 129 |
my ($branchcode, $day, $month, $title) = @_; |
| 130 |
my $startDate = output_pref( { dt => $first_dt, dateonly => 1, dateformat => 'iso' } ); |
| 131 |
my $today = DateTime->today; |
| 132 |
my $query = "update discrete_calendar set isOpened=0, note=? where branchcode=? and MONTH(date)=? and DAY(date)=? and date >=?"; |
| 133 |
my $stmt = $dbh->prepare($query); |
| 134 |
|
| 135 |
$stmt->execute($title,$branchcode,$month,$day,$today); |
| 136 |
} |
| 137 |
|
| 138 |
sub insert_range_holiday{ |
| 139 |
my ($branchcode, $title) = @_; |
| 140 |
my $startDate = output_pref( { dt => $first_dt, dateonly => 1, dateformat => 'iso' } ); |
| 141 |
my $endDate = output_pref( { dt => $end_dt, dateonly => 1, dateformat => 'iso' } ); |
| 142 |
my $query = "update discrete_calendar set isOpened=0, note=? where branchcode=? and (date between ? and ?)"; |
| 143 |
my $stmt = $dbh->prepare($query); |
| 144 |
|
| 145 |
$stmt->execute($title,$branchcode, $startDate, $endDate); |
| 146 |
} |
| 147 |
|
| 148 |
sub insert_range_holiday_repeat{ |
| 149 |
my ($branchcode, $title) = @_; |
| 150 |
my $parser = DateTime::Format::Strptime->new( |
| 151 |
pattern => '%m-%d', |
| 152 |
on_error => 'croak', |
| 153 |
); |
| 154 |
my $startDate = $parser->format_datetime($first_dt); |
| 155 |
my $endDate = $parser->format_datetime($end_dt); |
| 156 |
my $today = DateTime->today; |
| 157 |
my $query = "update discrete_calendar set isOpened=0, note=? where branchcode=? and isOpened=1 and (DATE_FORMAT(date,'\%m-\%d') BETWEEN ? AND ? ) and date > ?"; |
| 158 |
my $stmt = $dbh->prepare($query); |
| 159 |
|
| 160 |
$stmt->execute($title,$branchcode, $startDate, $endDate,$today); |
| 161 |
} |
| 162 |
|
| 71 |
#FIXME: move add_holiday() to a better place |
163 |
#FIXME: move add_holiday() to a better place |
| 72 |
sub add_holiday { |
164 |
sub add_holiday { |
| 73 |
($newoperation, $branchcode, $weekday, $day, $month, $year, $title, $description) = @_; |
165 |
($newoperation, $branchcode, $weekday, $day, $month, $year, $title, $description) = @_; |
| 74 |
my $calendar = C4::Calendar->new(branchcode => $branchcode); |
166 |
my $calendar = C4::Calendar->new(branchcode => $branchcode); |
| 75 |
|
167 |
|
| 76 |
if ($newoperation eq 'weekday') { |
168 |
if ($newoperation eq 'weekday') { |
| 77 |
unless ( $weekday && ($weekday ne '') ) { |
169 |
unless ( $weekday && ($weekday ne '') ) { |
| 78 |
# was dow calculated by javascript? original code implies it was supposed to be. |
170 |
# was dow calculated by javascript? original code implies it was supposed to be. |
| 79 |
# if not, we need it. |
171 |
# if not, we need it. |
| 80 |
$weekday = &Date::Calc::Day_of_Week($year, $month, $day) % 7 unless($weekday); |
172 |
$weekday = &Date::Calc::Day_of_Week($year, $month, $day) % 7 unless($weekday); |
| 81 |
- |
|
|