bumped up MARC Perl module requirements
[koha_fer] / reserve / request.pl
index 1beb70c..e7cbad5 100755 (executable)
@@ -1,6 +1,5 @@
 #!/usr/bin/perl
 
-# $Id$
 
 #writen 2/1/00 by chris@katipo.oc.nz
 # Copyright 2000-2002 Katipo Communications
@@ -32,9 +31,8 @@ use CGI;
 use List::MoreUtils qw/uniq/;
 use Date::Calc qw/Today Date_to_Days/;
 use C4::Output;
-use C4::Interface::CGI::Output;
 use C4::Auth;
-use C4::Reserves2;
+use C4::Reserves;
 use C4::Biblio;
 use C4::Koha;
 use C4::Circulation;
@@ -69,7 +67,7 @@ my $date = sprintf( '%04d-%02d-%02d', Today() );
 
 if ($findborrower) {
     my ( $count, $borrowers ) =
-      BornameSearch($findborrower, 'cardnumber', 'web' );
+      SearchMember($findborrower, 'cardnumber', 'web' );
 
     my @borrowers = @$borrowers;
 
@@ -98,18 +96,22 @@ if ($cardnumber) {
 # FIXME At this time we have a simple count of reservs, but, later, we could improve the infos "title" ...
 
     my $number_reserves =
-      CountReservesFromBorrower( $borrowerinfo->{'borrowernumber'} );
+      GetReserveCount( $borrowerinfo->{'borrowernumber'} );
 
     if ( $number_reserves > C4::Context->preference('maxreserves') ) {
         $maxreserves = 1;
     }
 
-    # we check the date expiricy of the borrower
-    my $warning = (Date_to_Days(split /-/,$date) > Date_to_Days( split /-/,$borrowerinfo->{'dateexpiry'}));
-     
-    if ( $warning > 0 ) {
+    # we check the date expiricy of the borrower (only if there is an expiry date, otherwise, set to 1 (warn)
+    if ($borrowerinfo->{'dateexpiry'} ne '0000-00-00') {
+        my $warning = (Date_to_Days(split /-/,$date) > Date_to_Days( split /-/,$borrowerinfo->{'dateexpiry'}));
+        if ( $warning > 0 ) {
+            $expiry = 1;
+        }
+    } else {
         $expiry = 1;
     }
+     
 
     # check if the borrower make the reserv in a different branch
     if ( $borrowerinfo->{'branchcode'} ne C4::Context->userenv->{'branch'} ) {
@@ -117,12 +119,22 @@ if ($cardnumber) {
     }
 
     $template->param(
-        borrowersurname   => $borrowerinfo->{'surname'},
-        borrowerfirstname => $borrowerinfo->{'firstname'},
-        borrowerreservs   => $count_reserv,
-        maxreserves       => $maxreserves,
-        expiry            => $expiry,
-        diffbranch        => $diffbranch
+                borrowernumber => $borrowerinfo->{'borrowernumber'},
+                borrowersurname   => $borrowerinfo->{'surname'},
+                borrowerfirstname => $borrowerinfo->{'firstname'},
+                borrowerstreetaddress => $borrowerinfo->{'address'},
+                borrowercity => $borrowerinfo->{'city'},
+                borrowerphone => $borrowerinfo->{'phone'},
+                               borrowermobile => $borrowerinfo->{'mobile'},
+                               borrowerfax => $borrowerinfo->{'fax'},
+                               borrowerphonepro => $borrowerinfo->{'phonepro'},
+                borroweremail => $borrowerinfo->{'email'},
+                borroweremailpro => $borrowerinfo->{'emailpro'},
+                borrowercategory => $borrowerinfo->{'category'},
+                borrowerreservs   => $count_reserv,
+                maxreserves       => $maxreserves,
+                expiry            => $expiry,
+                diffbranch        => $diffbranch
     );
 }
 
@@ -161,7 +173,7 @@ if ($borrowerslist) {
 }
 
 # get existing reserves .....
-my ( $count, $reserves ) = FindReserves($biblionumber);
+my ( $count, $reserves ) = GetReservesFromBiblionumber($biblionumber);
 my $totalcount = $count;
 my $alreadyreserved;
 
@@ -210,7 +222,7 @@ foreach my $itemnumber (@itemnumbers) {
     push( @{ $itemnumbers_of_biblioitem{$biblioitemnumber} }, $itemnumber );
 }
 
-@branchcodes = uniq @branchcodes;
+@branchcodes = uniq @branchcodes;
 
 my @biblioitemnumbers = keys %itemnumbers_of_biblioitem;
 
@@ -260,7 +272,7 @@ foreach my $biblioitemnumber (@biblioitemnumbers) {
         }
 
         # checking reserve
-        my ($reservedate,$reservedfor,$expectedAt) = GetFirstReserveDateFromItem($itemnumber);
+        my ($reservedate,$reservedfor,$expectedAt) = GetReservesFromItemnumber($itemnumber);
         my $ItemBorrowerReserveInfo = GetMemberDetails( $reservedfor, 0);
 
         if ( defined $reservedate ) {
@@ -305,13 +317,25 @@ foreach my $biblioitemnumber (@biblioitemnumbers) {
 
         # If there is no loan, return and transfer, we show a checkbox.
         $item->{notforloan} = $item->{notforloan} || 0;
-
+       
+       # if independent branches is on we need to check if the person can reserve
+       # for branches they arent logged in to
+       if ( C4::Context->preference("IndependantBranches") ) { 
+           if (! C4::Context->preference("canreservefromotherbranches")){
+               # cant reserve items so need to check if item homebranch and userenv branch match if not we cant reserve
+               my $userenv = C4::Context->userenv; 
+               if ( ($userenv) && ( $userenv->{flags} != 1 ) ) {
+                   $item->{cantreserve} = 1 if ( $item->{homebranch} ne $userenv->{branch} );
+               } 
+           }
+       }
         # An item is available only if:
         if (
             not defined $reservedate    # not reserved yet
             and $issues->{'date_due'} eq ''         # not currently on loan
             and not $item->{itemlost}   # not lost
             and not $item->{notforloan} # not forbidden to loan
+           and not $item->{cantreserve}
             and $transfertwhen eq ''    # not currently on transfert
           )
         {
@@ -327,7 +351,7 @@ foreach my $biblioitemnumber (@biblioitemnumbers) {
 # existingreserves building
 my @reserveloop;
 my $branches = GetBranches();
-my ( $count, $reserves ) = FindReservesInQueue($biblionumber);
+my ( $count, $reserves ) = GetReservesFromBiblionumber($biblionumber);
 foreach my $res ( sort { $a->{found} cmp $b->{found} } @$reserves ) {
     my %reserve;
     my @optionloop;
@@ -351,7 +375,7 @@ foreach my $res ( sort { $a->{found} cmp $b->{found} } @$reserves ) {
 
     if ( ( $res->{'found'} eq 'W' ) or ( $res->{'priority'} eq '0' ) ) {
         my $item = $res->{'itemnumber'};
-        $item = getiteminformation($item,undef);
+        $item = GetBiblioFromItemNumber($item,undef);
         $reserve{'wait'}= 1; 
         $reserve{'holdingbranch'}=$item->{'holdingbranch'};
         $reserve{'biblionumber'}=$item->{'biblionumber'};
@@ -362,6 +386,8 @@ foreach my $res ( sort { $a->{found} cmp $b->{found} } @$reserves ) {
         if($reserve{'holdingbranch'} eq $reserve{'wbrcode'}){
             $reserve{'atdestination'} = 1;
         }
+        # set found to 1 if reserve is waiting for patron pickup
+        $reserve{'found'} = 1 if $res->{'found'} eq 'W';
     }
     
 #     get borrowers reserve info
@@ -398,6 +424,7 @@ foreach my $branchcode ( keys %{$branches} ) {
 }
 my $CGIbranch = CGI::scrolling_list(
     -name     => 'pickup',
+       -id          => 'pickup',
     -values   => \@values,
     -default  => $default,
     -labels   => \%label_of,