143e224c86
This patch removes C4::Dates from: Remove C4::Dates from: - tools/exceptionHolidays.pl - tools/holidays.pl - tools/newHolidays.pl - C4/Calendar.pm To test: - Go to Home > Tools > Calendar - Add, edit, delete the different types of holidays and exceptions - git grep 'C4::Calendar' and test such files - prove t/Calendar.t (Amended following comments #3 and #4 / mv) (Amended following comment #7 / 25.10.2015 / mv Signed-off-by: Mirko Tietgen <mirko@abunchofthings.net> http://bugs.koha-community.org/show_bug.cgi?id=14945 Signed-off-by: Nick Clemens <nick@bywatersolutions.com> Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org> Signed-off-by: Brendan Gallagher brendan@bywatersolutions.com Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
124 lines
4.7 KiB
Perl
Executable file
124 lines
4.7 KiB
Perl
Executable file
#!/usr/bin/perl
|
|
|
|
use strict;
|
|
use warnings;
|
|
|
|
use CGI qw ( -utf8 );
|
|
|
|
use C4::Auth;
|
|
use C4::Output;
|
|
use DateTime;
|
|
|
|
use C4::Calendar;
|
|
use Koha::DateUtils;
|
|
|
|
my $input = new CGI;
|
|
my $dbh = C4::Context->dbh();
|
|
|
|
my $branchcode = $input->param('showBranchName');
|
|
my $weekday = $input->param('showWeekday');
|
|
my $day = $input->param('showDay');
|
|
my $month = $input->param('showMonth');
|
|
my $year = $input->param('showYear');
|
|
my $title = $input->param('showTitle');
|
|
my $description = $input->param('showDescription');
|
|
my $holidaytype = $input->param('showHolidayType');
|
|
my $datecancelrange_dt = eval { dt_from_string( $input->param('datecancelrange') ) };
|
|
my $calendardate = sprintf("%04d-%02d-%02d", $year, $month, $day);
|
|
|
|
my $calendar = C4::Calendar->new(branchcode => $branchcode);
|
|
|
|
$title || ($title = '');
|
|
if ($description) {
|
|
$description =~ s/\r/\\r/g;
|
|
$description =~ s/\n/\\n/g;
|
|
} else {
|
|
$description = '';
|
|
}
|
|
|
|
# We make an array with holiday's days
|
|
my @holiday_list;
|
|
if ($datecancelrange_dt){
|
|
my $first_dt = DateTime->new(year => $year, month => $month, day => $day);
|
|
|
|
for (my $dt = $first_dt->clone();
|
|
$dt <= $datecancelrange_dt;
|
|
$dt->add(days => 1) )
|
|
{
|
|
push @holiday_list, $dt->clone();
|
|
}
|
|
}
|
|
if ($input->param('showOperation') eq 'exception') {
|
|
$calendar->insert_exception_holiday(day => $day,
|
|
month => $month,
|
|
year => $year,
|
|
title => $title,
|
|
description => $description);
|
|
} elsif ($input->param('showOperation') eq 'exceptionrange' ) {
|
|
if (@holiday_list){
|
|
foreach my $date (@holiday_list){
|
|
$calendar->insert_exception_holiday(
|
|
day => $date->{local_c}->{day},
|
|
month => $date->{local_c}->{month},
|
|
year => $date->{local_c}->{year},
|
|
title => $title,
|
|
description => $description
|
|
);
|
|
}
|
|
}
|
|
} elsif ($input->param('showOperation') eq 'edit') {
|
|
if($holidaytype eq 'weekday') {
|
|
$calendar->ModWeekdayholiday(weekday => $weekday,
|
|
title => $title,
|
|
description => $description);
|
|
} elsif ($holidaytype eq 'daymonth') {
|
|
$calendar->ModDaymonthholiday(day => $day,
|
|
month => $month,
|
|
title => $title,
|
|
description => $description);
|
|
} elsif ($holidaytype eq 'ymd') {
|
|
$calendar->ModSingleholiday(day => $day,
|
|
month => $month,
|
|
year => $year,
|
|
title => $title,
|
|
description => $description);
|
|
} elsif ($holidaytype eq 'exception') {
|
|
$calendar->ModExceptionholiday(day => $day,
|
|
month => $month,
|
|
year => $year,
|
|
title => $title,
|
|
description => $description);
|
|
}
|
|
} elsif ($input->param('showOperation') eq 'delete') {
|
|
$calendar->delete_holiday(weekday => $weekday,
|
|
day => $day,
|
|
month => $month,
|
|
year => $year);
|
|
}elsif ($input->param('showOperation') eq 'deleterange') {
|
|
if (@holiday_list){
|
|
foreach my $date (@holiday_list){
|
|
$calendar->delete_holiday_range(weekday => $weekday,
|
|
day => $date->{local_c}->{day},
|
|
month => $date->{local_c}->{month},
|
|
year => $date->{local_c}->{year});
|
|
}
|
|
}
|
|
}elsif ($input->param('showOperation') eq 'deleterangerepeat') {
|
|
if (@holiday_list){
|
|
foreach my $date (@holiday_list){
|
|
$calendar->delete_holiday_range_repeatable(weekday => $weekday,
|
|
day => $date->{local_c}->{day},
|
|
month => $date->{local_c}->{month});
|
|
}
|
|
}
|
|
}elsif ($input->param('showOperation') eq 'deleterangerepeatexcept') {
|
|
if (@holiday_list){
|
|
foreach my $date (@holiday_list){
|
|
$calendar->delete_exception_holiday_range(weekday => $weekday,
|
|
day => $date->{local_c}->{day},
|
|
month => $date->{local_c}->{month},
|
|
year => $date->{local_c}->{year});
|
|
}
|
|
}
|
|
}
|
|
print $input->redirect("/cgi-bin/koha/tools/holidays.pl?branch=$branchcode&calendardate=$calendardate");
|