From 10093d4ecec2d31ff8a4c3f5848ea62df0694036 Mon Sep 17 00:00:00 2001 From: Christophe Croullebois Date: Sat, 4 Feb 2012 16:43:51 +0100 Subject: [PATCH 1/1] Bug 7351 : feature that allows to delete a range of dates Two new options, one for single holidays, the other for the repeatable holidays. Note that the exceptions are not deleted. --- C4/Calendar.pm | 70 ++++++++++++++++++++ .../prog/en/modules/tools/holidays.tt | 32 ++++++++-- tools/exceptionHolidays.pl | 54 ++++++++++++++- 3 files changed, 148 insertions(+), 8 deletions(-) diff --git a/C4/Calendar.pm b/C4/Calendar.pm index dc9037b..06a1a5a 100644 --- a/C4/Calendar.pm +++ b/C4/Calendar.pm @@ -45,6 +45,8 @@ BEGIN { &isHoliday &addDate &daysBetween + &delete_holiday_range + &delete_holiday_range_repeatable ); } @@ -529,6 +531,74 @@ sub delete_holiday { return $self; } +=head2 delete_holiday_range + + delete_holiday_range(weekday => $weekday + day => $day, + month => $month, + year => $year); + +Delete a holiday for $self->{branchcode}. + +C<$weekday> Is the week day to delete. + +C<$day> Is the day month to make the date to delete. + +C<$month> Is month to make the date to delete. + +C<$year> Is year to make the date to delete. + +=cut + +sub delete_holiday_range { + my $self = shift @_; + my %options = @_; + + my $dbh = C4::Context->dbh(); + my $isSingleHoliday = $dbh->prepare("SELECT id FROM special_holidays WHERE (branchcode = ?) AND (day = ?) AND (month = ?) AND (year = ?)"); + $isSingleHoliday->execute($self->{branchcode}, $options{day}, $options{month}, $options{year}); + if ($isSingleHoliday->rows) { + my $id = $isSingleHoliday->fetchrow; + $isSingleHoliday->finish; # Close the last query + my $deleteHoliday = $dbh->prepare("DELETE FROM special_holidays WHERE id = ?"); + $deleteHoliday->execute($id); + } +} + +=head2 delete_holiday_range_repeatable + + delete_holiday_range_repeatable(weekday => $weekday + day => $day, + month => $month, + year => $year); + +Delete a holiday for $self->{branchcode}. + +C<$weekday> Is the week day to delete. + +C<$day> Is the day month to make the date to delete. + +C<$month> Is month to make the date to delete. + +C<$year> Is year to make the date to delete. + +=cut + +sub delete_holiday_range_repeatable { + my $self = shift @_; + my %options = @_; + + my $dbh = C4::Context->dbh(); + my $isDayMonthHoliday = $dbh->prepare("SELECT id FROM repeatable_holidays WHERE (branchcode = ?) AND (day = ?) AND (month = ?)"); + $isDayMonthHoliday->execute($self->{branchcode}, $options{day}, $options{month}); + if ($isDayMonthHoliday->rows) { + my $id = $isDayMonthHoliday->fetchrow; + $isDayMonthHoliday->finish; + my $deleteHoliday = $dbh->prepare("DELETE FROM repeatable_holidays WHERE (id = ?)"); + $deleteHoliday->execute($id); + } +} + =head2 isHoliday $isHoliday = isHoliday($day, $month $year); diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/holidays.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/holidays.tt index 686e3af..6042cae 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/holidays.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/holidays.tt @@ -83,8 +83,8 @@ function Help() { newin=window.open("/cgi-bin/koha/help.pl","KohaHelp",'width=600,height=600,toolbar=false,scrollbars=yes'); } - $(document).ready(function() { + $(document).ready(function() { [% IF ( dateformat_metric ) %] $.tablesorter.addParser({ // http://tablesorter.com/docs/example-parsers.html id: 'shortDates', is: function(s){ @@ -129,6 +129,7 @@ $(this).parent().find(".hint").toggle(); return false; }); $("#dateofrange").each(function () { this.value = "" }); + $("#datecancelrange").each(function () { this.value = "" }); }); //]]> @@ -185,7 +186,7 @@
  • - Date: + From Date: , [% IF ( dateformat_us ) %]//[% ELSIF ( dateformat_metric ) %]//[% ELSE %]//[% END %] @@ -196,6 +197,20 @@
  • +
  • + To Date : + + Show Calendar + +
  • @@ -209,10 +224,17 @@
  • [?]
    This will delete this holiday rule. If it is a repeatable holiday, this option checks for posible exceptions. If an exception exists, this option will remove the exception and set the date to a regular holiday.
  • +
  • . + [?] +
    This will delete the single holidays rules only. The repeatable holidays and exceptions will not be deleted
    +
  • +
  • . + [?] +
    This will delete the repeated holidays rules only. The repeatable holidays will be deleted but not exceptions
    +
  • - [?] -
    This will save changes to the holiday's title and description. If the information for a repeatable holiday is modified, it affects all of the dates on which the holiday is repeated.
  • - + [?] +
    This will save changes to the holiday's title and description. If the information for a repeatable holiday is modified, it affects all of the dates on which the holiday is repeated.
    diff --git a/tools/exceptionHolidays.pl b/tools/exceptionHolidays.pl index 64a4860..7d94eed 100755 --- a/tools/exceptionHolidays.pl +++ b/tools/exceptionHolidays.pl @@ -7,7 +7,7 @@ use CGI; use C4::Auth; use C4::Output; - +use DateTime; use C4::Calendar; @@ -19,10 +19,13 @@ my $weekday = $input->param('showWeekday'); my $day = $input->param('showDay'); my $month = $input->param('showMonth'); my $year = $input->param('showYear'); +my $day1; +my $month1; +my $year1; my $title = $input->param('showTitle'); my $description = $input->param('showDescription'); my $holidaytype = $input->param('showHolidayType'); - +my $datecancelrange = $input->param('datecancelrange'); my $calendardate = sprintf("%04d-%02d-%02d", $year, $month, $day); my $isodate = C4::Dates->new($calendardate, 'iso'); $calendardate = $isodate->output('syspref'); @@ -36,7 +39,20 @@ if ($description) { } else { $description = ''; } - +my @dateend = split(/[\/-]/, $datecancelrange); +if (C4::Context->preference("dateformat") eq "metric") { + $day1 = $dateend[0]; + $month1 = $dateend[1]; + $year1 = $dateend[2]; +}elsif (C4::Context->preference("dateformat") eq "us") { + $month1 = $dateend[0]; + $day1 = $dateend[1]; + $year1 = $dateend[2]; +} else { + $year1 = $dateend[0]; + $month1 = $dateend[1]; + $day1 = $dateend[2]; +} if ($input->param('showOperation') eq 'exception') { $calendar->insert_exception_holiday(day => $day, month => $month, @@ -71,5 +87,37 @@ if ($input->param('showOperation') eq 'exception') { day => $day, month => $month, year => $year); +}elsif ($input->param('showOperation') eq 'deleterange') { + if ($year1 && $month1 && $day1){ + #Make an array with holiday's days + my $first_dt = DateTime->new(year => $year, month => $month, day => $day); + my $end_dt = DateTime->new(year => $year1, month => $month1, day => $day1); + my @holiday_list = (); + for (my $dt = $first_dt->clone(); $dt <= $end_dt; $dt->add(days => 1) ){ + push @holiday_list, $dt->clone(); + } + 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 ($year1 && $month1 && $day1){ + #Make an array with holiday's days + my $first_dt = DateTime->new(year => $year, month => $month, day => $day); + my $end_dt = DateTime->new(year => $year1, month => $month1, day => $day1); + my @holiday_list = (); + for (my $dt = $first_dt->clone(); $dt <= $end_dt; $dt->add(days => 1) ){ + push @holiday_list, $dt->clone(); + } + foreach my $date (@holiday_list){ + $calendar->delete_holiday_range_repeatable(weekday => $weekday, + day => $date->{local_c}->{day}, + month => $date->{local_c}->{month}); + } + } } + print $input->redirect("/cgi-bin/koha/tools/holidays.pl?branch=$branchcode&calendardate=$calendardate"); -- 1.7.5.4