Bug 3326: Work around Zebra's handling of & entities
[koha_fer] / C4 / Reserves.pm
index 35a45b4..2dd2688 100644 (file)
@@ -194,7 +194,9 @@ sub AddReserve {
         my $borrower = C4::Members::GetMember(borrowernumber => $borrowernumber);
         my $biblio   = GetBiblioData($biblionumber);
         my $letter = C4::Letters::getletter( 'reserves', 'HOLDPLACED');
-        my $admin_email_address = C4::Context->preference('KohaAdminEmailAddress');
+       my $branchcode = $borrower->{branchcode};
+        my $branch_details = C4::Branch::GetBranchDetail($branchcode);
+        my $admin_email_address =$branch_details->{'branchemail'} || C4::Context->preference('KohaAdminEmailAddress');
 
         my %keys = (%$borrower, %$biblio);
         foreach my $key (keys %keys) {
@@ -380,76 +382,11 @@ sub GetReservesFromBorrowernumber {
 sub CanBookBeReserved{
     my ($borrowernumber, $biblionumber) = @_;
 
-    my $dbh           = C4::Context->dbh;
-    my $biblio        = GetBiblioData($biblionumber);
-    my $borrower      = C4::Members::GetMember(borrowernumber=>$borrowernumber);
-    my $controlbranch = C4::Context->preference('ReservesControlBranch');
-    my $itype         = C4::Context->preference('item-level_itypes');
-    my $reservesrights= 0;
-    my $reservescount = 0;
-    
-    # we retrieve the user rights
-    my @args;
-    my $rightsquery = "SELECT categorycode, itemtype, branchcode, reservesallowed 
-                       FROM issuingrules 
-                       WHERE categorycode IN (?, '*')";
-    push @args,$borrower->{categorycode};
-
-    if($controlbranch eq "ItemHomeLibrary"){
-        $rightsquery .= " AND branchcode = '*'";
-    }elsif($controlbranch eq "PatronLibrary"){
-        $rightsquery .= " AND branchcode IN (?,'*')";
-        push @args, $borrower->{branchcode};
-    }
-    
-    if(not $itype){
-        $rightsquery .= " AND itemtype IN (?,'*')";
-        push @args, $biblio->{itemtype};
-    }else{
-        $rightsquery .= " AND itemtype = '*'";
-    }
-    
-    $rightsquery .= " ORDER BY categorycode DESC, itemtype DESC, branchcode DESC";
-    my $sthrights = $dbh->prepare($rightsquery);
-    $sthrights->execute(@args);
-    
-    if(my $row = $sthrights->fetchrow_hashref()){
-       $reservesrights = $row->{reservesallowed};
-    }
-    
-    @args = ();
-    # we count how many reserves the borrower have
-    my $countquery = "SELECT count(*) as count
-                      FROM reserves
-                      LEFT JOIN items USING (itemnumber)
-                      LEFT JOIN biblioitems ON (reserves.biblionumber=biblioitems.biblionumber)
-                      LEFT JOIN borrowers USING (borrowernumber)
-                      WHERE borrowernumber = ?
-                    ";
-    push @args, $borrowernumber;
-    
-    if(not $itype){
-           $countquery .= "AND itemtype = ?";
-           push @args, $biblio->{itemtype};
+    my @items = GetItemsInfo($biblionumber);
+    foreach my $item (@items){
+        return 1 if CanItemBeReserved($borrowernumber, $item->{itemnumber});
     }
-    
-    if($controlbranch eq "PatronLibrary"){
-        $countquery .= " AND borrowers.branchcode = ? ";
-        push @args, $borrower->{branchcode};
-    }
-    
-    my $sthcount = $dbh->prepare($countquery);
-    $sthcount->execute(@args);
-    
-    if(my $row = $sthcount->fetchrow_hashref()){
-       $reservescount = $row->{count};
-    }
-    if($reservescount < $reservesrights){
-        return 1;
-    }else{
-        return 0;
-    }
-    
+    return 0;
 }
 
 =head2 CanItemBeReserved
@@ -1006,7 +943,7 @@ sub CancelReserve {
         $sth->execute( $biblio, $borr );
 
         # now fix the priority on the others....
-        _FixPriority( $priority, $biblio );
+        _FixPriority( $biblio, $borr );
     }
 }
 
@@ -1152,7 +1089,7 @@ sub ModReserveFill {
     # now fix the priority on the others (if the priority wasn't
     # already sorted!)....
     unless ( $priority == 0 ) {
-        _FixPriority( $priority, $biblionumber );
+        _FixPriority( $biblionumber, $borrowernumber );
     }
 }
 
@@ -1677,6 +1614,7 @@ sub _Findgroupreserve {
         SELECT reserves.biblionumber               AS biblionumber,
                reserves.borrowernumber             AS borrowernumber,
                reserves.reservedate                AS reservedate,
+               reserves.waitingdate                AS waitingdate,
                reserves.branchcode                 AS branchcode,
                reserves.cancellationdate           AS cancellationdate,
                reserves.found                      AS found,
@@ -1841,7 +1779,7 @@ sub _ShiftPriorityByDateAndPriority {
 
 =head1 AUTHOR
 
-Koha Development Team <info@koha.org>
+Koha Development Team <http://koha-community.org/>
 
 =cut