From 7d166176af416dc306cdf82a8d0b1c0235504931 Mon Sep 17 00:00:00 2001 From: finlayt Date: Fri, 11 Oct 2002 05:24:26 +0000 Subject: [PATCH] fixed so that it displays using itemtypes only --- opac/opac-reserve.pl | 113 +++++++++++++++++++++++++++++++------------ 1 file changed, 83 insertions(+), 30 deletions(-) diff --git a/opac/opac-reserve.pl b/opac/opac-reserve.pl index 86f5ab8268..920814a759 100755 --- a/opac/opac-reserve.pl +++ b/opac/opac-reserve.pl @@ -10,6 +10,9 @@ use C4::Koha; use C4::Circulation::Circ2; use C4::Reserves2; +my $MAXIMUM_NUMBER_OF_RESERVES = 5; + + my $query = new CGI; @@ -38,9 +41,9 @@ foreach my $res (@$reserves) { $rank--; } } -$rank++; -$template->param(rank => $rank); +$template->param(rank => $rank); +$rank++; # pass the pickup branch along.... @@ -56,55 +59,105 @@ my $branchoptions = ''; foreach my $br (keys %$branches) { (next) unless $branches->{$br}->{'IS'}; my $selected = ""; - if ($br eq $branch) { + if ($br eq 'L') { $selected = "selected"; } $branchoptions .= "\n"; } $template->param( branchoptions => $branchoptions); +#### THIS IS A BIT OF A HACK BECAUSE THE BIBLIOITEMS DATA IS A LITTLE MESSED UP! +# get the itemtype data.... +my @items = ItemInfo(undef, $biblionumber, 'intra'); +my %types; +foreach my $itm (@items) { + my $ity = $itm->{'itemtype'}; + unless ($types {$ity}) { + $types{$ity}->{'itemtype'} = $ity; + $types{$ity}->{'branchinfo'}->{$itm->{'branchcode'}} = 1; + $types{$ity}->{'description'} = $itm->{'description'}; + } else { + $types{$ity}->{'branchinfo'}->{$itm->{'branchcode'}} ++; + } +} -#get the bibitem data.... -my ($count,@data) = bibitems($biblionumber); - -foreach my $bibitem (@data) { - my @barcodes = barcodes($bibitem->{'biblioitemnumber'}); - my $barcodestext = ""; - foreach my $num (@barcodes) { - my $message = $num->{'itemlost'} == 1 ? "(lost)" : - $num->{'itemlost'} == 2 ? "(long overdue)" : "($branches->{$num->{'holdingbranch'}}->{'branchname'})"; - $barcodestext .= "$num->{'barcode'} $message
"; +foreach my $type (values %types) { + my $copies = ""; + foreach my $bc (keys %{$type->{'branchinfo'}}) { + $copies .= $branches->{$bc}->{'branchname'}."(".$type->{'branchinfo'}->{$bc}.")"; } - $barcodestext = substr($barcodestext, 0, -4); - $bibitem->{'copies'} = $barcodestext; + $type->{'copies'} = $copies; } +my @types = values %types; -my @reqbibs = $query->param('reqbib'); -if ($query->param('bibitemsselected')) { - $template->param(bibitemsselected => 1); - my @tempdata; - foreach my $bibitem (@data) { - foreach my $reqbib (@reqbibs){ - push @tempdata, $bibitem if ($bibitem->{'biblioitemnumber'} == $reqbib) ; +if ($query->param('item_types_selected')) { +# this is what happens after the itemtypes have been selected. Stage 2 + my @itemtypes = $query->param('itemtype'); + if (@itemtypes) { + warn "Itemtypes : @itemtypes\n"; + my %newtypes; + foreach my $itmtype (@itemtypes) { + $newtypes{$itmtype} = $types{$itmtype}; } + my @types = values %newtypes; + $template->param(TYPES => \@types); + $template->param(item_types_selected => 1); + } else { + $template->param(message => 1); + $template->param(no_items_selected => 1); } - @data = @tempdata; -} elsif ($query->param('placereserve')) { -# here we actually do the reserveration.... + + +} elsif ($query->param('place_reserve')) { +# here we actually do the reserveration. Stage 3. my $title = $bibdata->{'title'}; + my @reqbibs; + my @itemtypes = $query->param('itemtype'); + foreach my $item (@items) { + foreach my $type (@itemtypes) { + if ($item->{'itemtype'} == $type) { + my $addbibitem = 1; + foreach my $bibitemno (@reqbibs) { + $addbibitem = 0 if $bibitemno == $item->{'biblioitemnumber'}; + } + push @reqbibs, $item->{'biblioitemnumber'} if $addbibitem; + } + } + } CreateReserve(undef,$branch,$borrowernumber,$biblionumber,'o',\@reqbibs,$rank,'',$title); warn "reserve created\n"; print $query->redirect("/cgi-bin/koha/opac-user.pl"); } else { - $template->param(selectbibitems => 1); +# Here we check that the borrower can actually make reserves Stage 1. + my $noreserves = 0; + if ($borr->{'amountoutstanding'} > 5) { + my $amount = sprintf "\$%.02f", $borr->{'amountoutstanding'}; + $template->param(message => 1); + $noreserves = 1; + $template->param(too_much_oweing => $amount); + } + my ($resnum, $reserves) = FindReserves(undef, $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); + } + } + $template->param(TYPES => \@types); + unless ($noreserves) { + $template->param(select_item_types => 1); + } } -# check that you can actually make the reserve. - - -$template->param(BIBLIOITEMS => \@data); $template->param(loggedinuser => $loggedinuser); print "Content-Type: text/html\n\n", $template->output; -- 2.39.5