[Koha-patches] [PATCH] Bug 1687: Can't assign holidays to all branches at once.

Garry Collum gcollum at gmail.com
Sun May 24 18:10:23 CEST 2009


This patch adds a select box to the new holiday form that allows the user to copy the holiday to all branches. If a holiday for a particular location already exists for a location, that holiday and location is not changed.
---
 .../prog/en/modules/tools/holidays.tmpl            |    5 ++
 tools/holidays.pl                                  |    4 +-
 tools/newHolidays.pl                               |   48 +++++++++++++++-----
 3 files changed, 44 insertions(+), 13 deletions(-)

diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/holidays.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/holidays.tmpl
index 34dc4f3..b4e6e68 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/holidays.tmpl
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/holidays.tmpl
@@ -233,6 +233,7 @@ h1 select { width: 20em; }
 	<!-- ***************************** Panel to deal with new holidays **********************  -->
 	<div class="panel" id="newHoliday">
 	 	<form action="/cgi-bin/koha/tools/newHolidays.pl" method="post">
+				<input type="hidden" name="branchCodes" id="branchCodes" value="<!-- TMPL_VAR NAME="branchcodes" -->" /> 
 			<h2>Add new holiday</h2>
 			<p>
 				<label for="newBranchName">Library</label>
@@ -264,6 +265,10 @@ h1 select { width: 20em; }
 				<label for="newOperationYear">Holiday repeated yearly on the same date</label>.
 				<a href="#" onclick=" additionalInformation('This will take this day and month as a reference to make it 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.')"><img src="<!-- TMPL_VAR NAME="themelang" -->/../img/more.gif" border="0" alt="More information" /></a>
 				<p>
+				<input type="checkbox" name="allBranches" id="allBranches" />
+				<label for="allBranches">Copy to all locations</label>.
+				<a href="#" onclick=" additionalInformation('If checked, this holiday will be copied to all locations. If the holiday already exists for a location, no change is made.')"><img src="<!-- TMPL_VAR NAME="themelang" -->/../img/more.gif" border="0" alt="More information" /></a>
+				</p><p>
 					<input type="submit" name="submit" value="Save" />
 					<input type="button" name="cancel2" value="Cancel" onclick=" hidePanel('newHoliday');hidePanel('information')" />
 				</p>
diff --git a/tools/holidays.pl b/tools/holidays.pl
index c92e521..93808f0 100755
--- a/tools/holidays.pl
+++ b/tools/holidays.pl
@@ -72,7 +72,8 @@ for my $thisbranch (sort { $branches->{$a}->{branchname} cmp $branches->{$b}->{b
             );
     push @branchloop, \%row;
 }
-
+# branches calculated - put branch codes in a single string so they can be passed in a form
+my $branchcodes = join("|", keys %$branches);
 
 # Get all the holidays
 
@@ -139,6 +140,7 @@ $template->param(WEEK_DAYS_LOOP => \@week_days,
 				DAY_MONTH_HOLIDAYS_LOOP => \@day_month_holidays,
 				calendardate => $calendardate,
 				keydate => $keydate,
+				branchcodes => $branchcodes,
 				branch => $branch
 	);
 
diff --git a/tools/newHolidays.pl b/tools/newHolidays.pl
index 7e85de8..08cb7dd 100755
--- a/tools/newHolidays.pl
+++ b/tools/newHolidays.pl
@@ -13,12 +13,15 @@ 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 $calendardate = sprintf("%04d-%02d-%02d", $year, $month, $day);
 my $isodate = C4::Dates->new($calendardate, 'iso');
@@ -31,28 +34,49 @@ if ($description) {
 } else {
 	$description = '';
 }
-my $calendar = C4::Calendar->new(branchcode => $branchcode);
 
-if ($input->param('newOperation') eq 'weekday') {
-	unless ( $weekday && ($weekday ne '') ) { 
-		# was dow calculated by javascript?  original code implies it was supposed to be.
-		# if not, we need it.
-		$weekday = &Date::Calc::Day_of_Week($year, $month, $day) % 7 unless($weekday);
+if($allbranches) {
+	my $branch;
+	my @branchcodes = split(/\|/, $input->param('branchCodes')); 
+	foreach $branch (@branchcodes) {
+		add_holiday($newoperation, $branch, $weekday, $day, $month, $year, $title, $description);
 	}
-	$calendar->insert_week_day_holiday(weekday => $weekday,
+} else {
+	add_holiday($newoperation, $branchcode, $weekday, $day, $month, $year, $title, $description);
+}
+
+print $input->redirect("/cgi-bin/koha/tools/holidays.pl?branch=$originalbranchcode&calendardate=$calendardate");
+
+sub add_holiday {
+	($newoperation, $branchcode, $weekday, $day, $month, $year, $title, $description) = @_;  
+	my $calendar = C4::Calendar->new(branchcode => $branchcode);
+
+	if ($newoperation eq 'weekday') {
+		unless ( $weekday && ($weekday ne '') ) { 
+			# was dow calculated by javascript?  original code implies it was supposed to be.
+			# if not, we need it.
+			$weekday = &Date::Calc::Day_of_Week($year, $month, $day) % 7 unless($weekday);
+		}
+		unless($calendar->isHoliday($day, $month, $year)) {
+			$calendar->insert_week_day_holiday(weekday => $weekday,
 							           title => $title,
 							           description => $description);
-} elsif ($input->param('newOperation') eq 'repeatable') {
-	$calendar->insert_day_month_holiday(day => $day,
+		}
+	} elsif ($newoperation eq 'repeatable') {
+		unless($calendar->isHoliday($day, $month, $year)) {
+			$calendar->insert_day_month_holiday(day => $day,
 	                                    month => $month,
 							            title => $title,
 							            description => $description);
-} elsif ($input->param('newOperation') eq 'holiday') {
-	$calendar->insert_single_holiday(day => $day,
+		}
+	} elsif ($newoperation eq 'holiday') {
+		unless($calendar->isHoliday($day, $month, $year)) {
+			$calendar->insert_single_holiday(day => $day,
 	                                 month => $month,
 						             year => $year,
 						             title => $title,
 						             description => $description);
+		}
 
+	}
 }
-print $input->redirect("/cgi-bin/koha/tools/holidays.pl?branch=$branchcode&calendardate=$calendardate");
-- 
1.5.6.5




More information about the Koha-patches mailing list