From 5d8d84bba2f1dfc293b5226b574395f5e0e3f3df Mon Sep 17 00:00:00 2001 From: Emmi Takkinen Date: Fri, 7 Feb 2020 12:43:54 +0200 Subject: [PATCH] Bug 4985: Edit a calendar entry for all branches This patch adds functionality to calendar tool to make edits or deletes to all branches at once. To test: -Apply patch -Add holiday for a library and copy it to all or some libraries -Edit previosly made holiday (edit, delete etc.) and check out "Copy changes to all libraries." checkbox => Changes are made to all libraries sharing changed holiday Sponsored by: Koha-Suomi Oy Signed-off-by: Christofer Signed-off-by: Jonathan Druart Signed-off-by: Sally Signed-off-by: Katrin Fischer Signed-off-by: Jonathan Druart (cherry picked from commit ce2219425d9b97952f5904024fb7575a0809487b) Signed-off-by: Lucas Gass (cherry picked from commit 6f85f47365a1460d1e68280835d69008424fea45) Signed-off-by: Aleisha Amohia (cherry picked from commit dbb2717123362bf620184f3ac548d90918d6c1ce) Signed-off-by: Victor Grousset/tuxayo --- .../prog/en/modules/tools/holidays.tt | 6 + tools/exceptionHolidays.pl | 147 ++++++++++-------- 2 files changed, 88 insertions(+), 65 deletions(-) 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 f7771c0953..7900be3f35 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/holidays.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/holidays.tt @@ -111,6 +111,12 @@ td.repeatableyearly a.ui-state-default { background: #FFCC66 none; color : Bl
  • [?]
    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.
  • +
  • + + . + [?] +
    If checked, changes for this holiday will be copied to all libraries. If the holiday doesn't exists for a library, no change is made.
    +
  • diff --git a/tools/exceptionHolidays.pl b/tools/exceptionHolidays.pl index 1f3b9672fb..680fe17130 100755 --- a/tools/exceptionHolidays.pl +++ b/tools/exceptionHolidays.pl @@ -18,6 +18,7 @@ checkauth($input, 0, {tools=> 'edit_calendar'}, 'intranet'); my $branchcode = $input->param('showBranchName'); +my $originalbranchcode = $branchcode; my $weekday = $input->param('showWeekday'); my $day = $input->param('showDay'); my $month = $input->param('showMonth'); @@ -27,8 +28,8 @@ my $description = $input->param('showDescription'); my $holidaytype = $input->param('showHolidayType'); my $datecancelrange_dt = eval { dt_from_string( scalar $input->param('datecancelrange') ) }; my $calendardate = sprintf("%04d-%02d-%02d", $year, $month, $day); - -my $calendar = C4::Calendar->new(branchcode => $branchcode); +my $showoperation = $input->param('showOperation'); +my $allbranches = $input->param('allBranches'); $title || ($title = ''); if ($description) { @@ -50,77 +51,93 @@ if ($datecancelrange_dt){ 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 - ); + +if($allbranches) { + my $libraries = Koha::Libraries->search; + while ( my $library = $libraries->next ) { + edit_holiday($showoperation, $library->branchcode, $weekday, $day, $month, $year, $title, $description, $holidaytype); + } +} else { + edit_holiday($showoperation, $branchcode, $weekday, $day, $month, $year, $title, $description, $holidaytype); +} + +print $input->redirect("/cgi-bin/koha/tools/holidays.pl?branch=$originalbranchcode&calendardate=$calendardate"); + +sub edit_holiday { + ($showoperation, $branchcode, $weekday, $day, $month, $year, $title, $description, $holidaytype) = @_; + my $calendar = C4::Calendar->new(branchcode => $branchcode); + + if ($showoperation eq 'exception') { + $calendar->insert_exception_holiday(day => $day, + month => $month, + year => $year, + title => $title, + description => $description); + } elsif ($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, + } elsif ($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 '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, + } elsif ($holidaytype eq 'exception') { + $calendar->ModExceptionholiday(day => $day, + month => $month, + year => $year, + title => $title, + description => $description); + } + } elsif ($showoperation eq 'delete') { + $calendar->delete_holiday(weekday => $weekday, + day => $day, + month => $month, + year => $year); + }elsif ($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 ($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 ($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}); } - } -}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"); -- 2.39.5