From 806fac60f466b79d9c60023df4425b134040bfdc Mon Sep 17 00:00:00 2001 From: Christophe Croullebois Date: Fri, 2 Dec 2011 16:03:19 +0100 Subject: [PATCH] Bug 6663: Features for holidays.pl with datepicker Allow to select a range between 2 dates and in one "submit" creates holidays only on these days. I have added also Holidays repeated yearly on a range. On suggestions I have added a datepicker for "To Date". Signed-off-by: Owen Leonard Signed-off-by: Paul Poulain --- .../prog/en/css/staff-global.css | 2 + .../prog/en/modules/tools/holidays.tt | 27 ++++- tools/holidays.pl | 1 + tools/newHolidays.pl | 98 ++++++++++++++++--- 4 files changed, 111 insertions(+), 17 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/en/css/staff-global.css b/koha-tmpl/intranet-tmpl/prog/en/css/staff-global.css index 7710eda7b4..6581c00d9c 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/css/staff-global.css +++ b/koha-tmpl/intranet-tmpl/prog/en/css/staff-global.css @@ -554,6 +554,8 @@ div.yui-b fieldset.brief li.radio { padding : .7em 0; } div.yui-b fieldset.brief li.radio label, +div.yui-b fieldset.brief li.dateinsert label, +div.yui-b fieldset.brief li.dateinsert span.label, div.yui-b fieldset.brief li.radio span.label { display : inline; } 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 ac867fe199..83fcc7f61a 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/holidays.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/holidays.tt @@ -103,6 +103,7 @@ $("a.helptext").click(function(){ $(this).parent().find(".hint").toggle(); return false; }); + $("#dateofrange").each(function () { this.value = "" }); }); //]]> @@ -209,7 +210,7 @@
  • - Date: + From Date: , [% IF ( dateformat_us ) %]//[% ELSIF ( dateformat_metric ) %]//[% ELSE %]//[% END %] @@ -220,6 +221,20 @@
  • +
  • + To Date : + + Show Calendar + +
  • @@ -239,6 +254,16 @@ [?]
    This will take this day and month as a reference to make it a holiday. Through this option, you can repeat this rule for every year. For example, selecting August 1st will make August 1st a holiday every year.
  • +
  • + . + [?] +
    Make a single holiday on a range. For example, selecting August 1st, 2012 and August 10st, 2012 will make all days between 1st and 10st holiday, but will not affect August 1st-10st in other years.
    +
  • +
  • + . + [?] +
    Make a single holiday on a range repeated yearly. For example, selecting August 1st, 2012 and August 10st, 2012 will make all days between 1st and 10st holiday, and will affect August 1st-10st in other years.
    +
  • . diff --git a/tools/holidays.pl b/tools/holidays.pl index 90ef56a987..b3912eb261 100755 --- a/tools/holidays.pl +++ b/tools/holidays.pl @@ -147,6 +147,7 @@ $template->param(WEEK_DAYS_LOOP => \@week_days, keydate => $keydate, branchcodes => $branchcodes, branch => $branch, + DHTMLcalendar_dateformat => C4::Dates->DHTMLcalendar(), branchname => $branchname ); diff --git a/tools/newHolidays.pl b/tools/newHolidays.pl index 34469d85f9..c36d328f80 100755 --- a/tools/newHolidays.pl +++ b/tools/newHolidays.pl @@ -10,25 +10,44 @@ use C4::Output; use C4::Calendar; +use DateTime; -my $input = new CGI; -my $dbh = C4::Context->dbh(); +my $input = new CGI; +my $dbh = C4::Context->dbh(); -my $branchcode = $input->param('newBranchName'); -my $originalbranchcode = $branchcode; -my $weekday = $input->param('newWeekday'); -my $day = $input->param('newDay'); -my $month = $input->param('newMonth'); -my $year = $input->param('newYear'); -my $title = $input->param('newTitle'); -my $description = $input->param('newDescription'); -my $newoperation = $input->param('newOperation'); -my $allbranches = $input->param('allBranches'); +my $branchcode = $input->param('newBranchName'); +my $originalbranchcode = $branchcode; +my $weekday = $input->param('newWeekday'); +my $day = $input->param('newDay'); +my $month = $input->param('newMonth'); +my $year = $input->param('newYear'); +my $day1; +my $month1; +my $year1; +my $dateofrange = $input->param('dateofrange'); +my $title = $input->param('newTitle'); +my $description = $input->param('newDescription'); +my $newoperation = $input->param('newOperation'); +my $allbranches = $input->param('allBranches'); -my $calendardate = sprintf("%04d-%02d-%02d", $year, $month, $day); -my $isodate = C4::Dates->new($calendardate, 'iso'); -$calendardate = $isodate->output('syspref'); +my $calendardate = sprintf("%04d-%02d-%02d", $year, $month, $day); +my $isodate = C4::Dates->new($calendardate, 'iso'); +$calendardate = $isodate->output('syspref'); +my @dateend = split(/[\/-]/, $dateofrange); +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]; +} $title || ($title = ''); if ($description) { $description =~ s/\r/\\r/g; @@ -80,5 +99,52 @@ sub add_holiday { description => $description); } - } + } elsif ( $newoperation eq 'holidayrange' ) { + #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){ + unless ( $calendar->isHoliday( $date->{local_c}->{day}, $date->{local_c}->{month}, $date->{local_c}->{year} ) ) { + $calendar->insert_single_holiday( + day => $date->{local_c}->{day}, + month => $date->{local_c}->{month}, + year => $date->{local_c}->{year}, + title => $title, + description => $description + ); + } + } + } elsif ( $newoperation eq 'holidayrangerepeat' ) { + #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){ + unless ( $calendar->isHoliday( $date->{local_c}->{day}, $date->{local_c}->{month}, $date->{local_c}->{year} ) ) { + $calendar->insert_day_month_holiday( + day => $date->{local_c}->{day}, + month => $date->{local_c}->{month}, + title => $title, + description => $description + ); + } + } + } } -- 2.39.5