3 # This file is part of Koha.
5 # Koha is free software; you can redistribute it and/or modify it under the
6 # terms of the GNU General Public License as published by the Free Software
7 # Foundation; either version 2 of the License, or (at your option) any later
10 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
11 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License along with
15 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
16 # Suite 330, Boston, MA 02111-1307 USA
22 use C4::Auth; # checkauth, getborrowernumber.
27 use C4::Dates qw/format_date/;
30 use C4::Branch; # GetBranches
34 my $MAXIMUM_NUMBER_OF_RESERVES = C4::Context->preference("maxreserves");
37 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
39 template_name => "opac-reserve.tmpl",
43 flagsrequired => { borrow => 1 },
49 output_html_with_http_headers(shift,shift,shift); # $query, $cookie, $template->output;
53 # get borrower information ....
54 my ( $borr ) = GetMemberDetails( $borrowernumber );
56 # get branches and itemtypes
57 my $branches = GetBranches();
58 my $itemtypes = GetItemTypes();
60 # get biblionumber.....
61 my $biblionumber = $query->param('biblionumber');
62 if (! $biblionumber) {
63 $template->param(message=>1,no_biblionumber=>1);
64 &get_out($query, $cookie, $template->output);
66 $template->param( biblionumber => $biblionumber );
68 my $bibdata = GetBiblioData($biblionumber);
70 $template->param(message=>1,bad_biblionumber=>$biblionumber);
71 &get_out($query, $cookie, $template->output);
73 $template->param($bibdata); # FIXME: bad form.
75 # get the rank number....
76 my ( $rank, $reserves ) = GetReservesFromBiblionumber( $biblionumber);
77 $template->param( reservecount => $rank );
79 foreach my $res (@$reserves) {
80 if ( $res->{'found'} eq 'W' ) {
86 $template->param( rank => $rank );
88 # pass the pickup branch along....
89 my $branch = $query->param('branch');
90 $template->param( branch => $branch );
92 # make sure it's a real branch
93 if ( !$branches->{$branch} ) {
96 $template->param( branchname => $branches->{$branch}->{'branchname'} );
98 # make branch selection options...
103 my @CGIbranchlooparray;
105 foreach my $branch ( keys %$branches ) {
108 $line{branch} = $branches->{$branch}->{'branchname'};
109 $line{value} = $branch;
110 if ($line{value} eq C4::Context->userenv->{'branch'}) {
113 push @CGIbranchlooparray, \%line;
116 @CGIbranchlooparray = sort { $a->{branch} cmp $b->{branch} } @CGIbranchlooparray;
117 my $CGIbranchloop = \@CGIbranchlooparray;
118 $template->param( CGIbranch => $CGIbranchloop );
120 my @items = GetItemsInfo($biblionumber);
122 # an item was previously required to have an itemtype in order to be reserved.
123 # this behavior removed to fix bug 1891 .
124 # my @items = grep { (C4::Context->preference('item-level_itypes') ? $_->{'itype'} : $_->{'itemtype'} ) } @all_items ;
126 $template->param( itemcount => scalar(@items) );
130 foreach my $itm (@items) {
131 $debug and warn $itm->{'notforloan'};
132 my $fee = GetReserveFee( undef, $borrowernumber, $itm->{'biblionumber'}, 'a', ( $itm->{'biblioitemnumber'} ) );
133 $itm->{'reservefee'} = sprintf "%.02f", $fee;
134 # pass itype to itemtype for display purposes.
135 $itm->{'itemtype'} = $itm->{'itype'} if(C4::Context->preference('item-level_itypes'));
136 $itemhash{$itm->{'itemnumber'}}=$itm;
137 if (!$itm->{'notforloan'} && !($itm->{'itemnotforloan'} > 0)){
142 if ( $query->param('place_reserve') ) {
143 my @bibitems=$query->param('biblioitem');
144 my $notes=$query->param('notes');
145 my $checkitem=$query->param('checkitem');
148 <<<<<<< HEAD:opac/opac-reserve.pl
149 #if we have an item selectionned, and the pickup branch is the same as the holdingbranch of the document, we force the value $rank and $found.
150 if ($checkitem ne ''){
151 $rank = '0' unless C4::Context->preference('ReservesNeedReturns');
152 my $item = $checkitem;
153 $item = GetItem($item);
154 if ( $item->{'holdingbranch'} eq $branch ){
155 $found = 'W' unless C4::Context->preference('ReservesNeedReturns');
157 my @selectedItems = split /\//, $selectedItems;
159 # Make sure there is a biblionum/itemnum/branch triplet for each item.
160 # The itemnum can be 'any', meaning next available.
161 my $selectionCount = @selectedItems;
162 if (($selectionCount == 0) || (($selectionCount % 3) != 0)) {
163 $template->param(message=>1, bad_data=>1);
164 &get_out($query, $cookie, $template->output);
167 while (@selectedItems) {
168 my $biblioNum = shift(@selectedItems);
169 my $itemNum = shift(@selectedItems);
170 my $branch = shift(@selectedItems); # i.e., branch code, not name
172 my $singleBranchMode = $template->param('singleBranchMode');
173 if ($singleBranchMode) {
174 $branch = $borr->{'branchcode'};
175 >>>>>>> 9f01cc0... whitespace cleanup and remove editor comments:opac/opac-reserve.pl
180 @bibitems=sort @bibitems;
183 $realbi[0]=$bibitems[0];
184 for (my $i=1;$i<$count;$i++) {
186 if ($realbi[$i3] ne $bibitems[$i]) {
187 $realbi[$i2]=$bibitems[$i];
191 # here we actually do the reserveration. Stage 3.
192 if ($query->param('request') eq 'any'){
193 # place a request on 1st available
194 AddReserve($branch,$borrowernumber,$biblionumber,'a',\@realbi,$rank,$notes,$bibdata->{'title'},$checkitem,$found);
196 AddReserve($branch,$borrowernumber,$biblionumber,'a',\@realbi,$rank,$notes,$bibdata->{'title'},$checkitem, $found);
198 print $query->redirect("/cgi-bin/koha/opac-user.pl#opac-user-holds");
202 # Here we check that the borrower can actually make reserves Stage 1.
204 my $maxoutstanding = C4::Context->preference("maxoutstanding");
205 $template->param( noreserve => 1 ) unless $maxoutstanding;
206 if ( $borr->{'amountoutstanding'} > $maxoutstanding ) {
207 my $amount = sprintf "\$%.02f", $borr->{'amountoutstanding'};
208 $template->param( message => 1 );
210 $template->param( too_much_oweing => $amount );
212 if ( $borr->{gonenoaddress} eq 1 ) {
219 if ( $borr->{lost} eq 1 ) {
226 if ( $borr->{debarred} eq 1 ) {
233 my @reserves = GetReservesFromBorrowernumber( $borrowernumber );
234 $template->param( RESERVES => \@reserves );
235 if ( scalar(@reserves) >= $MAXIMUM_NUMBER_OF_RESERVES ) {
236 $template->param( message => 1 );
238 $template->param( too_many_reserves => scalar(@reserves));
240 foreach my $res (@reserves) {
241 if ( $res->{'biblionumber'} == $biblionumber && $res->{'borrowernumber'} == $borrowernumber) {
242 $template->param( message => 1 );
244 $template->param( already_reserved => 1 );
247 unless ($noreserves) {
248 $template->param( select_item_types => 1 );
253 my %itemnumbers_of_biblioitem;
254 my @itemnumbers = @{ get_itemnumbers_of($biblionumber)->{$biblionumber} };
255 my $iteminfos_of = GetItemInfosOf(@itemnumbers);
257 foreach my $itemnumber (@itemnumbers) {
258 my $biblioitemnumber = $iteminfos_of->{$itemnumber}->{biblioitemnumber};
259 push( @{ $itemnumbers_of_biblioitem{$biblioitemnumber} }, $itemnumber );
262 my @biblioitemnumbers = keys %itemnumbers_of_biblioitem;
264 my $notforloan_label_of = get_notforloan_label_of();
265 my $biblioiteminfos_of = GetBiblioItemInfosOf(@biblioitemnumbers);
268 foreach my $biblioitemnumber (@biblioitemnumbers) {
269 push @itemtypes, $biblioiteminfos_of->{$biblioitemnumber}{itemtype};
274 foreach my $biblioitemnumber (@biblioitemnumbers) {
275 my $biblioitem = $biblioiteminfos_of->{$biblioitemnumber};
277 <<<<<<< HEAD:opac/opac-reserve.pl
278 $biblioitem->{description} =
279 $itemtypes->{ $biblioitem->{itemtype} }{description};
281 # Get relevant biblio data.
282 my $biblioData = $biblioDataHash{$biblioNum};
284 $template->param(message=>1, bad_biblionumber=>$biblioNum);
285 &get_out($query, $cookie, $template->output);
287 >>>>>>> 9f01cc0... whitespace cleanup and remove editor comments:opac/opac-reserve.pl
290 my $itemnumber ( @{ $itemnumbers_of_biblioitem{$biblioitemnumber} } )
292 my $item = $itemhash{$itemnumber};
294 $item->{homebranchname} =
295 $branches->{ $item->{homebranch} }{branchname};
297 # if the holdingbranch is different than the homebranch, we show the
298 # holdingbranch of the document too
299 if ( $item->{homebranch} ne $item->{holdingbranch} ) {
300 $item->{holdingbranchname} =
301 $branches->{ $item->{holdingbranch} }{branchname};
304 <<<<<<< HEAD:opac/opac-reserve.pl
306 $item->{itemcallnumber} = $item->{itemcallnumber};
308 # if the item is currently on loan, we display its return date and
309 # change the background color
310 my $issues= GetItemIssue($itemnumber);
312 if (!$itemInfo->{'notforloan'} && !($itemInfo->{'itemnotforloan'} > 0)) {
313 $biblioLoopIter{forloan} = 1;
317 $biblioLoopIter{itemTypeDescription} = $itemTypes->{$biblioData->{itemtype}}{description};
319 $biblioLoopIter{itemLoop} = [];
320 my $numCopiesAvailable = 0;
321 foreach my $itemInfo (@{$biblioData->{itemInfos}}) {
322 my $itemNum = $itemInfo->{itemnumber};
323 my $itemLoopIter = {};
325 $itemLoopIter->{itemnumber} = $itemNum;
326 $itemLoopIter->{barcode} = $itemInfo->{barcode};
327 $itemLoopIter->{homeBranchName} = $branches->{$itemInfo->{homebranch}}{branchname};
328 $itemLoopIter->{callNumber} = $itemInfo->{itemcallnumber};
329 $itemLoopIter->{copynumber} = $itemInfo->{copynumber};
330 if ($itemLevelTypes) {
331 $itemLoopIter->{description} = $itemInfo->{description};
332 $itemLoopIter->{imageurl} = $itemInfo->{imageurl};
335 # If the holdingbranch is different than the homebranch, we show the
336 # holdingbranch of the document too.
337 if ( $itemInfo->{homebranch} ne $itemInfo->{holdingbranch} ) {
338 $itemLoopIter->{holdingBranchName} =
339 $branches->{ $itemInfo->{holdingbranch} }{branchname};
342 # If the item is currently on loan, we display its return date and
343 # change the background color.
344 my $issues= GetItemIssue($itemNum);
345 >>>>>>> 9f01cc0... whitespace cleanup and remove editor comments:opac/opac-reserve.pl
346 if ( $issues->{'date_due'} ) {
347 $item->{date_due} = format_date($issues->{'date_due'});
348 $item->{backgroundcolor} = 'onloan';
352 my ($reservedate,$reservedfor,$expectedAt) = GetReservesFromItemnumber($itemnumber);
353 my $ItemBorrowerReserveInfo = GetMemberDetails( $reservedfor, 0);
355 if ( defined $reservedate ) {
356 <<<<<<< HEAD:opac/opac-reserve.pl
357 $item->{backgroundcolor} = 'reserved';
358 $item->{reservedate} = format_date($reservedate);
359 $item->{ReservedForBorrowernumber} = $reservedfor;
360 $item->{ReservedForSurname} = $ItemBorrowerReserveInfo->{'surname'};
361 $item->{ReservedForFirstname} = $ItemBorrowerReserveInfo->{'firstname'};
362 $item->{ExpectedAtLibrary} = $expectedAt;
365 $itemLoopIter->{backgroundcolor} = 'reserved';
366 $itemLoopIter->{reservedate} = format_date($reservedate);
367 $itemLoopIter->{ReservedForBorrowernumber} = $reservedfor;
368 $itemLoopIter->{ReservedForSurname} = $ItemBorrowerReserveInfo->{'surname'};
369 $itemLoopIter->{ReservedForFirstname} = $ItemBorrowerReserveInfo->{'firstname'};
370 $itemLoopIter->{ExpectedAtLibrary} = $expectedAt;
371 >>>>>>> 9f01cc0... whitespace cleanup and remove editor comments:opac/opac-reserve.pl
374 # Management of the notforloan document
375 if ( $item->{notforloan} || $item->{itemnotforloan}) {
376 $item->{backgroundcolor} = 'other';
377 $item->{notforloanvalue} =
378 $notforloan_label_of->{ $item->{notforloan} };
381 # Management of lost or long overdue items
382 if ( $item->{itemlost} ) {
384 # FIXME localized strings should never be in Perl code
386 $item->{itemlost} == 1 ? "(lost)"
387 : $item->{itemlost} == 2 ? "(long overdue)"
389 $item->{backgroundcolor} = 'other';
392 # Check of the transfered documents
393 my ( $transfertwhen, $transfertfrom, $transfertto ) =
394 GetTransfers($itemnumber);
396 if ( $transfertwhen ne '' ) {
397 $item->{transfertwhen} = format_date($transfertwhen);
398 $item->{transfertfrom} =
399 $branches->{$transfertfrom}{branchname};
400 $item->{transfertto} = $branches->{$transfertto}{branchname};
401 $item->{nocancel} = 1;
404 # If there is no loan, return and transfer, we show a checkbox.
405 $item->{notforloan} = $item->{notforloan} || 0;
407 if (IsAvailableForItemLevelRequest($itemnumber)) {
408 $item->{available} = 1;
411 # FIXME: move this to a pm
412 my $dbh = C4::Context->dbh;
413 my $sth2 = $dbh->prepare("SELECT * FROM reserves WHERE borrowernumber=? AND itemnumber=? AND found='W'");
414 $sth2->execute($item->{ReservedForBorrowernumber},$item->{itemnumber});
415 while (my $wait_hashref = $sth2->fetchrow_hashref) {
416 $item->{waitingdate} = format_date($wait_hashref->{waitingdate});
418 <<<<<<< HEAD:opac/opac-reserve.pl
419 $item->{imageurl} = getitemtypeimagelocation( 'opac', $itemtypes->{ $item->{itype} }{imageurl} );
420 push @{ $biblioitem->{itemloop} }, $item;
422 $itemLoopIter->{imageurl} = getitemtypeimagelocation( 'opac', $itemTypes->{ $itemInfo->{itype} }{imageurl} );
424 push @{$biblioLoopIter{itemLoop}}, $itemLoopIter;
427 if ($numCopiesAvailable > 0) {
429 $biblioLoopIter{bib_available} = 1;
430 $biblioLoopIter{holdable} = 1;
432 if ($biblioLoopIter{already_reserved}) {
433 $biblioLoopIter{holdable} = undef;
434 >>>>>>> 9f01cc0... whitespace cleanup and remove editor comments:opac/opac-reserve.pl
437 push @bibitemloop, $biblioitem;
440 <<<<<<< HEAD:opac/opac-reserve.pl
442 if ( $numBibsAvailable == 0 ) {
443 $template->param( none_available => 1, message => 1 );
446 my $itemTableColspan = 5;
447 if (!$template->param('OPACItemHolds')) {
450 if ($template->param('singleBranchMode')) {
453 $template->param(itemtable_colspan => $itemTableColspan);
455 >>>>>>> 9f01cc0... whitespace cleanup and remove editor comments:opac/opac-reserve.pl
459 bibitemloop => \@bibitemloop,
461 output_html_with_http_headers $query, $cookie, $template->output;
463 <<<<<<< HEAD:opac/opac-reserve.pl
468 >>>>>>> 9f01cc0... whitespace cleanup and remove editor comments:opac/opac-reserve.pl