-$template->param(TYPE_ROWS => \@typerows);
-$width = 2*$width -1;
-$template->param(totalwidth => 2*$width-1);
-
-if ($query->param('item_types_selected')) {
- # this is what happens after the itemtypes have been selected. Stage 2
- my @itemtypes = $query->param('itemtype');
- my $fee = 0;
- my $proceed = 0;
- if (@itemtypes) {
- my %newtypes;
- foreach my $itmtype (@itemtypes) {
- $newtypes{$itmtype} = $itemtypes{$itmtype};
- }
- my @types = values %newtypes;
- $template->param(TYPES => \@types);
- foreach my $type (@itemtypes) {
- my @reqbibs;
- foreach my $item (@items) {
- if ($item->{'itemtype'} eq $type) {
- push @reqbibs, $item->{'biblioitemnumber'};
- }
- }
- $fee += CalcReserveFee(undef,$borrowernumber,$biblionumber,'o',\@reqbibs);
- }
- $proceed = 1;
- } elsif ($query->param('all')) {
- $template->param(all => 1);
- $fee = 1;
- $proceed = 1;
- }
- warn "branch :$branch:";
- if ($proceed && $branch) {
- $fee = sprintf "%.02f", $fee;
- $template->param(fee => $fee);
- $template->param(item_types_selected => 1);
- } else {
- $template->param(message => 1);
- $template->param(no_items_selected => 1) unless ($proceed);
- $template->param(no_branch_selected =>1) unless ($branch);
- }
-} elsif ($query->param('place_reserve')) {
- # here we actually do the reserveration. Stage 3.
- my $title = $bibdata->{'title'};
- my @itemtypes = $query->param('itemtype');
- foreach my $type (@itemtypes) {
- my @reqbibs;
- foreach my $item (@items) {
- if ($item->{'itemtype'} eq $type) {
- push @reqbibs, $item->{'biblioitemnumber'};
- }
- }
- CreateReserve(undef,$branch,$borrowernumber,$biblionumber,'o',\@reqbibs,$rank,'',$title);
- }
- if ($query->param('all')) {
- CreateReserve(undef,$branch,$borrowernumber,$biblionumber,'a', undef, $rank,'',$title);
- }
- print $query->redirect("/cgi-bin/koha/opac-user.pl");
-} else {
- # Here we check that the borrower can actually make reserves Stage 1.
- my $noreserves = 0;
- my $maxoutstanding = C4::Context->preference("maxoustanding");
- if ($borr->{'amountoutstanding'} > $maxoutstanding) {
- my $amount = sprintf "\$%.02f", $borr->{'amountoutstanding'};
- $template->param(message => 1);
- $noreserves = 1;
- $template->param(too_much_oweing => $amount);
- }
- my ($resnum, $reserves) = FindReserves('', $borrowernumber);
- $template->param(RESERVES => $reserves);
- if ($resnum >= $MAXIMUM_NUMBER_OF_RESERVES) {
- $template->param(message => 1);
- $noreserves = 1;
- $template->param(too_many_reserves => $resnum);
- }
- foreach my $res (@$reserves) {
- if ($res->{'biblionumber'} == $biblionumber) {
- $template->param(message => 1);
- $noreserves = 1;
- $template->param(already_reserved => 1);
- }
+
+unless ($noreserves) {
+ $template->param( select_item_types => 1 );
+}
+
+
+#
+#
+# Build the template parameters that will show the info
+# and items for each biblionumber.
+#
+#
+my $notforloan_label_of = get_notforloan_label_of();
+
+my $biblioLoop = [];
+my $numBibsAvailable = 0;
+my $itemdata_enumchron = 0;
+my $anyholdable;
+my $itemLevelTypes = C4::Context->preference('item-level_itypes');
+$template->param('item_level_itypes' => $itemLevelTypes);
+
+foreach my $biblioNum (@biblionumbers) {
+
+ my $record = GetMarcBiblio($biblioNum);
+ # Init the bib item with the choices for branch pickup
+ my %biblioLoopIter = ( branchChoicesLoop => $CGIbranchloop );
+
+ # Get relevant biblio data.
+ my $biblioData = $biblioDataHash{$biblioNum};
+ if (! $biblioData) {
+ $template->param(message=>1, bad_biblionumber=>$biblioNum);
+ &get_out($query, $cookie, $template->output);
+ }
+
+ $biblioLoopIter{biblionumber} = $biblioData->{biblionumber};
+ $biblioLoopIter{title} = $biblioData->{title};
+ $biblioLoopIter{subtitle} = GetRecordValue('subtitle', $record, GetFrameworkCode($biblioData->{biblionumber}));
+ $biblioLoopIter{author} = $biblioData->{author};
+ $biblioLoopIter{rank} = $biblioData->{rank};
+ $biblioLoopIter{reservecount} = $biblioData->{reservecount};
+ $biblioLoopIter{already_reserved} = $biblioData->{already_reserved};
+
+ if (!$itemLevelTypes && $biblioData->{itemtype}) {
+ $biblioLoopIter{description} = $itemTypes->{$biblioData->{itemtype}}{description};
+ $biblioLoopIter{imageurl} = getitemtypeimagesrc() . "/". $itemTypes->{$biblioData->{itemtype}}{imageurl};
+ }
+
+ foreach my $itemInfo (@{$biblioData->{itemInfos}}) {
+ $debug and warn $itemInfo->{'notforloan'};
+
+ # Get reserve fee.
+ my $fee = GetReserveFee(undef, $borrowernumber, $itemInfo->{'biblionumber'}, 'a',
+ ( $itemInfo->{'biblioitemnumber'} ) );
+ $itemInfo->{'reservefee'} = sprintf "%.02f", ($fee ? $fee : 0.0);
+
+ if ($itemLevelTypes && $itemInfo->{itype}) {
+ $itemInfo->{description} = $itemTypes->{$itemInfo->{itype}}{description};
+ $itemInfo->{imageurl} = getitemtypeimagesrc() . "/". $itemTypes->{$itemInfo->{itype}}{imageurl};
+ }
+
+ if (!$itemInfo->{'notforloan'} && !($itemInfo->{'itemnotforloan'} > 0)) {
+ $biblioLoopIter{forloan} = 1;
+ }
+ }
+
+ $biblioLoopIter{itemLoop} = [];
+ my $numCopiesAvailable = 0;
+ foreach my $itemInfo (@{$biblioData->{itemInfos}}) {
+ my $itemNum = $itemInfo->{itemnumber};
+ my $itemLoopIter = {};
+
+ $itemLoopIter->{itemnumber} = $itemNum;
+ $itemLoopIter->{barcode} = $itemInfo->{barcode};
+ $itemLoopIter->{homeBranchName} = $branches->{$itemInfo->{homebranch}}{branchname};
+ $itemLoopIter->{callNumber} = $itemInfo->{itemcallnumber};
+ $itemLoopIter->{enumchron} = $itemInfo->{enumchron};
+ $itemLoopIter->{copynumber} = $itemInfo->{copynumber};
+ if ($itemLevelTypes) {
+ $itemLoopIter->{description} = $itemInfo->{description};
+ $itemLoopIter->{imageurl} = $itemInfo->{imageurl};
+ }
+
+ # If the holdingbranch is different than the homebranch, we show the
+ # holdingbranch of the document too.
+ if ( $itemInfo->{homebranch} ne $itemInfo->{holdingbranch} ) {
+ $itemLoopIter->{holdingBranchName} =
+ $branches->{ $itemInfo->{holdingbranch} }{branchname};
+ }
+
+ # If the item is currently on loan, we display its return date and
+ # change the background color.
+ my $issues= GetItemIssue($itemNum);
+ if ( $issues->{'date_due'} ) {
+ $itemLoopIter->{dateDue} = format_sqlduedatetime($issues->{date_due});
+ $itemLoopIter->{backgroundcolor} = 'onloan';
+ }
+
+ # checking reserve
+ my ($reservedate,$reservedfor,$expectedAt) = GetReservesFromItemnumber($itemNum);
+ my $ItemBorrowerReserveInfo = GetMemberDetails( $reservedfor, 0);
+
+ # the item could be reserved for this borrower vi a host record, flag this
+ if ($reservedfor eq $borrowernumber){
+ $itemLoopIter->{already_reserved} = 1;