Result of a cherry-pick, tidying up a comment
[koha.git] / circ / selectbranchprinter.pl
old mode 100644 (file)
new mode 100755 (executable)
index 4fd00c8..f7173a1
 
 use strict;
 use CGI qw/:standard/;
-use C4::Circulation::Circ2;
+
+use C4::Context;
+use C4::Circulation;
 use C4::Output;
 use C4::Auth;
 use C4::Print;
-use C4::Interface::CGI::Output;
 use C4::Koha;
 use C4::Branch; # GetBranches
 
@@ -34,33 +35,39 @@ use C4::Branch; # GetBranches
 #general design stuff...
 
 # try to get the branch and printer settings from the http....
-my %env;
 my $query    = new CGI;
 my $branches = GetBranches();
-my $printers = GetPrinters( \%env );
+my $printers = GetPrinters();
 my $branch   = $query->param('branch');
 my $printer  = $query->param('printer');
 
-my %cookie = $query->cookie('userenv');
-($branch)  || ( $branch  = $cookie{'branch'} );
-($printer) || ( $printer = $cookie{'printer'} );
+# set header with cookie....
+
+my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
+    {
+        template_name   => "circ/selectbranchprinter.tmpl",
+        query           => $query,
+        type            => "intranet",
+        authnotrequired => 0,
+        flagsrequired   => { circulate => 1 },
+    }
+);
+
 
+($branch)  || ( $branch  = C4::Context->userenv->{'branch'} );
+($printer) || ( $printer = C4::Context->userenv->{'branchprinter'} );
 ( $branches->{$branch} )  || ( $branch  = ( keys %$branches )[0] );
 ( $printers->{$printer} ) || ( $printer = ( keys %$printers )[0] );
 
-# is you force a selection....
+# if you force a selection....
 my $oldbranch  = $branch;
 my $oldprinter = $printer;
 
-$env{'branchcode'} = $branch;
-$env{'printer'}    = $printer;
-$env{'queue'}      = $printer;
-
 # set up select options....
 my $branchcount  = 0;
 my $printercount = 0;
 my @branchloop;
-foreach my $br ( keys %$branches ) {
+for my $br (sort { $branches->{$a}->{branchname} cmp $branches->{$b}->{branchname} } keys %$branches) {
     next unless $br =~ /\S/; # next unless $br is not blank.
 
     $branchcount++;
@@ -98,17 +105,7 @@ if ( $branchcount == 1 ) {
 
 ################################################################################
 # Start writing page....
-# set header with cookie....
 
-my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
-    {
-        template_name   => "circ/selectbranchprinter.tmpl",
-        query           => $query,
-        type            => "intranet",
-        authnotrequired => 0,
-        flagsrequired   => { circulate => 1 },
-    }
-);
 $template->param(
     oneprinter              => $oneprinter,
     onebranch               => $onebranch,
@@ -116,10 +113,6 @@ $template->param(
     branchname              => $branchname,
     printerloop             => \@printerloop,
     branchloop              => \@branchloop,
-    intranetcolorstylesheet =>
-      C4::Context->preference("intranetcolorstylesheet"),
-    intranetstylesheet => C4::Context->preference("intranetstylesheet"),
-    IntranetNav        => C4::Context->preference("IntranetNav"),
 );
 
 output_html_with_http_headers $query, $cookie, $template->output;