synch'ing 2.2 and head
[koha.git] / request.pl
index 379418a..f575402 100755 (executable)
 # Suite 330, Boston, MA  02111-1307 USA
 
 use strict;
-#use DBI;
 use C4::Search;
 use C4::Output;
+use C4::Interface::CGI::Output;
 use C4::Auth;
 use C4::Reserves2;
 use C4::Biblio;
 use C4::Koha;
 use C4::Circulation::Circ2;
 use HTML::Template;
-
+use C4::Acquisition;
 use CGI;
+use C4::Date;
+
 my $input = new CGI;
 
 # get biblio information....
@@ -62,30 +64,11 @@ for (my $i=1; $i<=$num; $i++){
        push(@optionloop, \%option);
 }
 
-
-# get branch information
-my $branch = $input->cookie('branch');
-($branch) || ($branch = 'L');
-my $branches = getbranches();
-# make branch selection options...
-my @branchloop;
-foreach my $br (keys %$branches) {
-       (next) unless $branches->{$br}->{'IS'};
-                       # Only branches with the 'IS' branchrelation
-                       # can issue books
-       my %abranch;
-       $abranch{'selected'}=($br eq $branch);
-       $abranch{'branch'}=$br;
-       $abranch{'branchname'}=$branches->{$br}->{'branchname'};
-       push(@branchloop,\%abranch);
-}
-
-
 # todays date
 my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =localtime(time);
 $year=$year+1900;
 $mon++;
-my $date="$mday/$mon/$year";
+my $date=format_date("$year-$mon-$mday");
 
 
 # get biblioitem information and build rows for form
@@ -123,6 +106,7 @@ foreach my $dat (sort {$b->{'dateaccessioned'} cmp $a->{'dateaccessioned'}} @dat
 
 #existingreserves building
 my @reserveloop;
+my $branches = getbranches();
 foreach my $res (sort {$a->{'found'} cmp $b->{'found'}} @$reserves){
        my %reserve;
 #    my $prioropt = priorityoptions($totalcount, $res->{'priority'});
@@ -133,10 +117,9 @@ foreach my $res (sort {$a->{'found'} cmp $b->{'found'}} @$reserves){
                $option{selected}=($i==$res->{'priority'});
                push(@optionloop, \%option);
        }
-#    my $bropt = branchoptions($res->{'branchcode'});
        my @branchloop;
        foreach my $br (keys %$branches) {
-               (next) unless $branches->{$br}->{'IS'};
+#              (next) unless $branches->{$br}->{'IS'};
                                # Only branches with the 'IS' branchrelation
                                # can issue books
                my %abranch;
@@ -150,16 +133,22 @@ foreach my $res (sort {$a->{'found'} cmp $b->{'found'}} @$reserves){
                my %env;
                my $item = $res->{'itemnumber'};
                $item = getiteminformation(\%env,$item);
+               $reserve{'holdingbranch'}=$item->{'holdingbranch'};
                $reserve{'barcode'}=$item->{'barcode'};
                $reserve{'biblionumber'}=$item->{'biblionumber'};
                $reserve{'wbrcode'} = $res->{'branchcode'};
                $reserve{'wbrname'} = $branches->{$res->{'branchcode'}}->{'branchname'};
+               if($reserve{'holdingbranch'} eq $reserve{'wbrcode'}){
+                       $reserve{'atdestination'} = 1;
+               }
     }
-    $reserve{'date'} = slashifyDate($res->{'reservedate'});
+       
+   $reserve{'date'} = format_date($res->{'reservedate'});
        $reserve{'borrowernumber'}=$res->{'borrowernumber'};
        $reserve{'biblionumber'}=$res->{'biblionumber'};
        $reserve{'bornum'}=$res->{'borrowernumber'};
        $reserve{'firstname'}=$res->{'firstname'};
+       $reserve{'surname'}=$res->{'surname'};
        $reserve{'bornum'}=$res->{'borrowernumber'};
        $reserve{'notes'}=$res->{'reservenotes'};
        $reserve{'wait'}=($res->{'found'} eq 'W');
@@ -172,13 +161,23 @@ foreach my $res (sort {$a->{'found'} cmp $b->{'found'}} @$reserves){
        push(@reserveloop,\%reserve);
 }
 
+my @branches;
+my @select_branch;
+my %select_branches;
+my ($count2,@branches)=branches();
+for (my $i=0;$i<$count2;$i++){
+       push @select_branch, $branches[$i]->{'branchcode'};#
+       $select_branches{$branches[$i]->{'branchcode'}} = $branches[$i]->{'branchname'};
+}
+my $CGIbranch=CGI::scrolling_list( -name     => 'pickup',
+                       -values   => \@select_branch,
+                       -labels   => \%select_branches,
+                       -size     => 1,
+                       -multiple => 0 );
+
 #get the time for the form name...
 my $time = time();
 
-
-
-
-
 #setup colours
 my ($template, $borrowernumber, $cookie)
     = get_template_and_user({template_name => "request.tmpl",
@@ -188,10 +187,15 @@ my ($template, $borrowernumber, $cookie)
                             flagsrequired => {parameters => 1},
                          });
 $template->param(      optionloop =>\@optionloop,
-                                                               branchloop => \@branchloop,
+                                                               CGIbranch => $CGIbranch,
                                                                reserveloop => \@reserveloop,
                                                                'time' => $time,
                                                                bibitemloop => \@bibitemloop,
-                                                               date => $date);
+                                                               date => $date,
+                                                               bib => $bib,
+                                                               title =>$dat->{title});
 # printout the page
-print $input->header(-expires=>'now'), $template->output;
+print $input->header(
+       -type => C4::Interface::CGI::Output::guesstype($template->output),
+       -expires=>'now'
+), $template->output;