bugfixing holidays.pl
[koha_fer] / tools / holidays.pl
index 6994f87..9dd93f0 100755 (executable)
@@ -21,14 +21,16 @@ use CGI;
 
 use C4::Auth;
 use C4::Output;
-use C4::Interface::CGI::Output;
 
 
 use C4::Calendar;
 
 my $input = new CGI;
-#my $branch = $input->param('branch');
+
 my $branch=C4::Context->preference('defaultbranch') || $input->param('branch');
+
+
+
 my $dbh = C4::Context->dbh();
 # Get the template to use
 my ($template, $loggedinuser, $cookie)
@@ -63,8 +65,11 @@ my $branchesList = CGI::scrolling_list(-name => 'branch',
 
 $branches->finish;
 
+if ( C4::Context->preference("IndependantBranches") ) { 
+    $branch = C4::Context->userenv->{'branch'};
+}
 # Get all the holidays
-# warn "BRANCH : $branch";
+
 my $calendar = C4::Calendar->new(branchcode => $branch);
 my $week_days_holidays = $calendar->get_week_days_holidays();
 my @week_days;
@@ -108,7 +113,14 @@ foreach my $yearMonthDay (keys %$single_holidays) {
 }
 
 # Replace the template values with the real ones
-$template->param(BRANCHES => $branchesList);
+# If we have independent branches on we need to only let the user set holidays for their branch
+# (except if the user is superlibrarian, in which case he can choose the branch anyway)
+if ( C4::Context->preference("IndependantBranches") && !(C4::Context->userenv->{'flags'} % 2) ) { 
+       $template->param(BRANCHES => C4::Context->userenv->{'branchname'}."<input type='hidden' id='branch' value='".C4::Context->userenv->{'branch'}."'>");
+}
+else {
+       $template->param(BRANCHES => $branchesList);
+}
 $template->param(WEEK_DAYS_LOOP => \@week_days);
 $template->param(HOLIDAYS_LOOP => \@holidays);
 $template->param(EXCEPTION_HOLIDAYS_LOOP => \@exception_holidays);