- # here we actually do the reserveration. Stage 3.
- if ($query->param('request') eq 'any'){
- # place a request on 1st available
- AddReserve($branch,$borrowernumber,$biblionumber,'a',\@realbi,$rank,$notes,$bibdata->{'title'},$checkitem,$found);
- } else {
- AddReserve($branch,$borrowernumber,$biblionumber,'a',\@realbi,$rank,$notes,$bibdata->{'title'},$checkitem, $found);
+
+ while (@selectedItems) {
+ my $biblioNum = shift(@selectedItems);
+ my $itemNum = shift(@selectedItems);
+ my $branch = shift(@selectedItems); # i.e., branch code, not name
+
+ my $singleBranchMode = $template->param('singleBranchMode');
+ if ($singleBranchMode || ! $OPACChooseBranch) { # single branch mode or disabled user choosing
+ $branch = $borr->{'branchcode'};
+ }
+
+ #item may belong to a host biblio, if yes change biblioNum to hosts bilbionumber
+ if ($itemNum ne '') {
+ my $hostbiblioNum = GetBiblionumberFromItemnumber($itemNum);
+ if ($hostbiblioNum ne $biblioNum) {
+ $biblioNum = $hostbiblioNum;
+ }
+ }
+
+ my $biblioData = $biblioDataHash{$biblioNum};
+ my $found;
+
+ # Check for user supplied reserve date
+ my $startdate;
+ if (
+ C4::Context->preference( 'AllowHoldDateInFuture' ) &&
+ C4::Context->preference( 'OPACAllowHoldDateInFuture' )
+ ) {
+ $startdate = $query->param("reserve_date_$biblioNum");
+ }
+
+ my $expiration_date = $query->param("expiration_date_$biblioNum");
+
+ # If a specific item was selected and the pickup branch is the same as the
+ # holdingbranch, force the value $rank and $found.
+ my $rank = $biblioData->{rank};
+ if ($itemNum ne ''){
+ $canreserve = 1 if CanItemBeReserved($borrowernumber,$itemNum);
+ $rank = '0' unless C4::Context->preference('ReservesNeedReturns');
+ my $item = GetItem($itemNum);
+ if ( $item->{'holdingbranch'} eq $branch ){
+ $found = 'W' unless C4::Context->preference('ReservesNeedReturns');
+ }
+ }
+ else {
+ $canreserve = 1 if CanBookBeReserved($borrowernumber,$biblioNum);
+ # Inserts a null into the 'itemnumber' field of 'reserves' table.
+ $itemNum = undef;
+ }
+
+ # Here we actually do the reserveration. Stage 3.
+ AddReserve($branch, $borrowernumber, $biblioNum, 'a', [$biblioNum], $rank, $startdate, $expiration_date, $notes,
+ $biblioData->{'title'}, $itemNum, $found) if ($canreserve);