bug: sticky due date isn't stick if there is a question about an issue
[koha.git] / circ / selectbranchprinter.pl
old mode 100644 (file)
new mode 100755 (executable)
index 2e51c22..f7173a1
@@ -1,6 +1,5 @@
 #!/usr/bin/perl
 
-
 # Copyright 2000-2002 Katipo Communications
 #
 # This file is part of Koha.
 
 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 DBI;
-
+use C4::Koha;
+use C4::Branch; # GetBranches
 
 # this is a reorganisation of circulationold.pl
 # dividing it up into three scripts......
 # this will be the first one that chooses branch and printer settings....
 
 #general design stuff...
-my $headerbackgroundcolor='#99cc33';
-my $circbackgroundcolor='#ffffcc';
-my $circbackgroundcolor='white';
-my $linecolor1='#ffffcc';
-my $linecolor2='white';
-my $backgroundimage="/images/background-mem.gif";
 
 # try to get the branch and printer settings from the http....
-my %env;
-my $query=new CGI;
-my $branches=getbranches(\%env);
-my $printers=getprinters(\%env);
-my $branch=$query->param('branch');
-my $printer=$query->param('printer');
-
-($branch) || ($branch=$query->cookie('branch'));
-($printer) || ($printer=$query->cookie('printer'));
-
-($branches->{$branch}) || ($branch=(keys %$branches)[0]);
-($printers->{$printer}) || ($printer=(keys %$printers)[0]);
+my $query    = new CGI;
+my $branches = GetBranches();
+my $printers = GetPrinters();
+my $branch   = $query->param('branch');
+my $printer  = $query->param('printer');
 
+# set header with cookie....
 
-# is you force a selection....
-my $oldbranch = $branch;
-my $oldprinter = $printer;
+my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
+    {
+        template_name   => "circ/selectbranchprinter.tmpl",
+        query           => $query,
+        type            => "intranet",
+        authnotrequired => 0,
+        flagsrequired   => { circulate => 1 },
+    }
+);
 
-$branch='';
-$printer='';
 
+($branch)  || ( $branch  = C4::Context->userenv->{'branch'} );
+($printer) || ( $printer = C4::Context->userenv->{'branchprinter'} );
+( $branches->{$branch} )  || ( $branch  = ( keys %$branches )[0] );
+( $printers->{$printer} ) || ( $printer = ( keys %$printers )[0] );
 
-$env{'branchcode'}=$branch;
-$env{'printer'}=$printer;
-$env{'queue'}=$printer;
+# if you force a selection....
+my $oldbranch  = $branch;
+my $oldprinter = $printer;
 
 # set up select options....
-my $branchcount=0;
-my $printercount=0;
-my $branchoptions;
-my $printeroptions;
-foreach (keys %$branches) {
-    (next) unless ($_);
-    (next) unless ($branches->{$_}->{'IS'});
+my $branchcount  = 0;
+my $printercount = 0;
+my @branchloop;
+for my $br (sort { $branches->{$a}->{branchname} cmp $branches->{$b}->{branchname} } keys %$branches) {
+    next unless $br =~ /\S/; # next unless $br is not blank.
+
     $branchcount++;
-    my $selected='';
-    ($selected='selected') if ($_ eq $oldbranch);
-    $branchoptions.="<option value=$_ $selected>$branches->{$_}->{'branchname'}\n";
+    my %branch;
+    $branch{selected} = ( $br eq $oldbranch );
+    $branch{name}     = $branches->{$br}->{'branchname'};
+    $branch{value}    = $br;
+    push( @branchloop, \%branch );
 }
-foreach (keys %$printers) {
-    (next) unless ($_);
+my @printerloop;
+foreach ( keys %$printers ) {
+    (next) unless ($_); # next unless if this printer is blank.
     $printercount++;
-    my $selected='';
-    ($selected='selected') if ($_ eq $oldprinter);
-    $printeroptions.="<option value=$_ $selected>$printers->{$_}->{'printername'}\n";
+    my %printer;
+    $printer{selected} = ( $_ eq $oldprinter );
+    $printer{name}     = $printers->{$_}->{'printername'};
+    $printer{value}    = $_;
+    push( @printerloop, \%printer );
 }
 
 # if there is only one....
-
-if ($printercount==1) {
-    ($printer)=keys %$printers;
+my $printername;
+my $branchname;
+
+my $oneprinter = ( $printercount == 1 );
+my $onebranch  = ( $branchcount == 1 );
+if ( $printercount == 1 ) {
+    my ($tmpprinter) = keys %$printers;
+    $printername = $printers->{$tmpprinter}->{printername};
 }
-if ($branchcount==1) {
-    ($branch)=keys %$branches;
+if ( $branchcount == 1 ) {
+    my ($tmpbranch) = keys %$branches;
+    $branchname = $branches->{$tmpbranch}->{branchname};
 }
 
-# set up printer and branch selection forms....
-my ($printerform, $branchform);
-if ($printercount>1) {
-    $printerform=<<"EOF";
-<select name=printer> $printeroptions </select>
-EOF
-} else {
-    my ($printer) = keys %$printers;
-    $printerform.="Printer: ".$printers->{$printer}->{printername};
-} 
-
-if ($branchcount>1) {
-    $branchform=<<"EOF";
-<select name=branch> $branchoptions </select>
-EOF
-} else {
-    my ($branch) = keys %$branches;
-    $branchform.= "Branch: ".$branches->{$branch}->{branchname};
-} 
-
-
-
-#############################################################################################
+################################################################################
 # Start writing page....
-# set header with cookie....
-
-print $query->header();
-
-print startpage();
-print startmenu('circulation');
-
-print << "EOF";
-<FONT SIZE=6><em>Circulation: Select Printer and Branch Settings</em></FONT><br>
-
-<center>
-<form method=post action=/cgi-bin/koha/circ/circulation.pl>
-<table border=1 cellpadding=5 cellspacing=0>
-<tr><td colspan=2 bgcolor=$headerbackgroundcolor align=center background=$backgroundimage>
-<font color=black><b>Please Set Branch and Printer</b></font></td></tr>
-<tr><td>
-$branchform
-</td>
-<td>
-$printerform
-</td></tr>
-</table>
-<input type="hidden" name="setcookies" value=1>
-<input type="submit" value="Submit" type="changesettings">
-</form>
-</center>
-
-EOF
-
 
-print endmenu('circulation');
-print endpage();
+$template->param(
+    oneprinter              => $oneprinter,
+    onebranch               => $onebranch,
+    printername             => $printername,
+    branchname              => $branchname,
+    printerloop             => \@printerloop,
+    branchloop              => \@branchloop,
+);
 
+output_html_with_http_headers $query, $cookie, $template->output;