View | Details | Raw Unified | Return to bug 11020
Collapse All | Expand All

(-)a/C4/Reserves.pm (-14 / +26 lines)
Lines 117-123 BEGIN { Link Here
117
        
117
        
118
        &CheckReserves
118
        &CheckReserves
119
        &CanBookBeReserved
119
        &CanBookBeReserved
120
	&CanItemBeReserved
120
    &CanItemBeReserved
121
        &CancelReserve
121
        &CancelReserve
122
        &CancelExpiredReserves
122
        &CancelExpiredReserves
123
123
Lines 162-169 sub AddReserve { Link Here
162
        undef $expdate; # make reserves.expirationdate default to null rather than '0000-00-00'
162
        undef $expdate; # make reserves.expirationdate default to null rather than '0000-00-00'
163
    }
163
    }
164
    if ( C4::Context->preference( 'AllowHoldDateInFuture' ) ) {
164
    if ( C4::Context->preference( 'AllowHoldDateInFuture' ) ) {
165
	# Make room in reserves for this before those of a later reserve date
165
    # Make room in reserves for this before those of a later reserve date
166
	$priority = _ShiftPriorityByDateAndPriority( $biblionumber, $resdate, $priority );
166
    $priority = _ShiftPriorityByDateAndPriority( $biblionumber, $resdate, $priority );
167
    }
167
    }
168
    my $waitingdate;
168
    my $waitingdate;
169
169
Lines 372-378 sub GetReservesFromItemnumber { Link Here
372
    WHERE  itemnumber=?
372
    WHERE  itemnumber=?
373
    ";
373
    ";
374
    unless ( $all_dates ) {
374
    unless ( $all_dates ) {
375
	$query .= " AND reservedate <= CURRENT_DATE()";
375
    $query .= " AND reservedate <= CURRENT_DATE()";
376
    }
376
    }
377
    my $sth_res = $dbh->prepare($query);
377
    my $sth_res = $dbh->prepare($query);
378
    $sth_res->execute($itemnumber);
378
    $sth_res->execute($itemnumber);
Lines 416-437 sub GetReservesFromBorrowernumber { Link Here
416
#-------------------------------------------------------------------------------------
416
#-------------------------------------------------------------------------------------
417
=head2 CanBookBeReserved
417
=head2 CanBookBeReserved
418
418
419
  $error = &CanBookBeReserved($borrowernumber, $biblionumber)
419
  $error = &CanBookBeReserved($borrowernumber, $biblionumber, $pickupLibrary)
420
421
C<$pickupLibrary> OPTIONAL, undef OR the branchcode of the item transfer destination.
420
422
421
=cut
423
=cut
422
424
423
sub CanBookBeReserved{
425
sub CanBookBeReserved{
424
    my ($borrowernumber, $biblionumber) = @_;
426
    my ($borrowernumber, $biblionumber, $pickupLibrary) = @_;
425
427
426
    my $items = GetItemnumbersForBiblio($biblionumber);
428
    my $itemNumbers = GetItemnumbersForBiblio($biblionumber);
427
    #get items linked via host records
429
    #get items linked via host records
428
    my @hostitems = get_hostitemnumbers_of($biblionumber);
430
    my @hostitems = get_hostit
431
emnumbers_of($biblionumber);
429
    if (@hostitems){
432
    if (@hostitems){
430
    push (@$items,@hostitems);
433
        push (@$itemNumbers,@hostitems);
431
    }
434
    }
432
435
433
    foreach my $item (@$items){
436
    foreach my $itemNumber (@$itemNumbers){
434
        return 1 if CanItemBeReserved($borrowernumber, $item);
437
438
        if (defined $pickupLibrary) {
439
                return 0 if (! CanItemBeReserved($borrowernumber, $itemNumber) );
440
                my $item = GetItem($itemNumber);
441
                my ($transferOk, $errorMsg) = C4::Circulation::CanItemBeTransferred($pickupLibrary, $item->{holdingbranch}, $item, undef);
442
                return 1 if ($transferOk);
443
        }
444
        else {
445
                return 1 if ( CanItemBeReserved($borrowernumber, $itemNumber) );
446
        }
435
    }
447
    }
436
    return 0;
448
    return 0;
437
}
449
}
Lines 849-855 sub CheckReserves { Link Here
849
    my $sth;
861
    my $sth;
850
    my $select;
862
    my $select;
851
    if (C4::Context->preference('item-level_itypes')){
863
    if (C4::Context->preference('item-level_itypes')){
852
	$select = "
864
    $select = "
853
           SELECT items.biblionumber,
865
           SELECT items.biblionumber,
854
           items.biblioitemnumber,
866
           items.biblioitemnumber,
855
           itemtypes.notforloan,
867
           itemtypes.notforloan,
Lines 861-867 sub CheckReserves { Link Here
861
        ";
873
        ";
862
    }
874
    }
863
    else {
875
    else {
864
	$select = "
876
    $select = "
865
           SELECT items.biblionumber,
877
           SELECT items.biblionumber,
866
           items.biblioitemnumber,
878
           items.biblioitemnumber,
867
           itemtypes.notforloan,
879
           itemtypes.notforloan,
Lines 1957-1963 sub _ShiftPriorityByDateAndPriority { Link Here
1957
    $sth = $dbh->prepare( $query );
1969
    $sth = $dbh->prepare( $query );
1958
    $sth->execute( $new_priority, $biblio );
1970
    $sth->execute( $new_priority, $biblio );
1959
    while ( my $row = $sth->fetchrow_hashref ) {
1971
    while ( my $row = $sth->fetchrow_hashref ) {
1960
	$sth_update->execute( $biblio, $row->{borrowernumber}, $row->{reservedate} );
1972
    $sth_update->execute( $biblio, $row->{borrowernumber}, $row->{reservedate} );
1961
    }
1973
    }
1962
1974
1963
    return $new_priority;  # so the caller knows what priority they wind up receiving
1975
    return $new_priority;  # so the caller knows what priority they wind up receiving
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/reserve/request.tt (-28 / +82 lines)
Lines 130-135 function checkMultiHold() { Link Here
130
	});
130
	});
131
131
132
    $('#hold-request-form').preventDoubleFormSubmit();
132
    $('#hold-request-form').preventDoubleFormSubmit();
133
	$('#reloadPickupLocationForm').preventDoubleFormSubmit();
134
135
	//Setting the trigger to reload branchTransferLimits
136
	$('#pickup').change(function() {
137
			var newSelection = $(this).val();
138
139
			//Make sure the pickup location is changed to the first select as well.
140
			// The branch selection uses only the first given pickuplocations branch value.
141
			$('#reloadPickupLocationForm > input[name="pickup"]').val(newSelection);
142
143
			$('#reloadPickupLocationForm').submit();
144
	});
145
133
146
134
[% UNLESS ( borrowernumber || borrower_list ) %]
147
[% UNLESS ( borrowernumber || borrower_list ) %]
135
    [% IF ( CircAutocompl ) %]
148
    [% IF ( CircAutocompl ) %]
Lines 352-361 function checkMultiHold() { Link Here
352
        [% END %]
365
        [% END %]
353
366
354
</ol>
367
</ol>
355
   [% UNLESS ( multi_hold ) %]
368
369
370
371
	[% UNLESS ( multi_hold ) %]
356
        <fieldset class="action">
372
        <fieldset class="action">
357
            [% IF ( borrowernumber ) %]
373
            [% IF ( borrowernumber ) %]
358
                [% IF ( override_required ) %]
374
				[% IF ( bookBranchTransferDenied ) %]
375
					<input type="submit" disabled="disabled" value="Place hold" />
376
                [% ELSIF ( override_required ) %]
359
                    <input type="submit" class="warning" value="Place hold" />
377
                    <input type="submit" class="warning" value="Place hold" />
360
                [% ELSIF ( none_available ) %]
378
                [% ELSIF ( none_available ) %]
361
                    <input type="submit" disabled="disabled" value="Place hold" />
379
                    <input type="submit" disabled="disabled" value="Place hold" />
Lines 367-378 function checkMultiHold() { Link Here
367
        [% FOREACH bibitemloo IN bibitemloop %]
385
        [% FOREACH bibitemloo IN bibitemloop %]
368
          <ol>
386
          <ol>
369
            [% UNLESS ( item_level_itypes ) %]
387
            [% UNLESS ( item_level_itypes ) %]
370
              <li><span class="label">Item type:</span> [% bibitemloo.description %]</li>
388
				<li><span class="label">Item type:</span> [% bibitemloo.description %]</li>
371
            [% END %]
389
            [% END %]
372
390
373
            [% IF ( bibitemloo.publicationyear ) %]<li><span class="label">Publication year:</span> [% bibitemloo.publicationyear %]</li>[% END %]
391
            [% IF ( bibitemloo.publicationyear ) %]
392
				<li><span class="label">Publication year:</span> [% bibitemloo.publicationyear %]</li>
393
			[% END %]
374
          </ol>
394
          </ol>
375
395
396
			[% IF ( bibitemloo.suggestAnotherPickupLocation ) %]
397
				<div id="suggestAnotherPickupLocation_[% bibitemloo.biblionumber %]" class="dialog alert">None of the available items can be transferred to your pickup location. You could try another pickup location.</div>
398
			[% END %]
399
376
        <table id="requestspecific">
400
        <table id="requestspecific">
377
        <caption>Place a hold on a specific copy</caption>
401
        <caption>Place a hold on a specific copy</caption>
378
		<tr>
402
		<tr>
Lines 396-407 function checkMultiHold() { Link Here
396
            <td>
420
            <td>
397
            [% IF ( itemloo.available ) %]
421
            [% IF ( itemloo.available ) %]
398
                <input type="radio" name="checkitem" value="[% itemloo.itemnumber %]" />
422
                <input type="radio" name="checkitem" value="[% itemloo.itemnumber %]" />
423
			[% ELSIF ( itemloo.branchTransferDenied ) %]
424
			    <input disabled="disabled" type="radio" name="checkitem" value="[% itemloo.itemnumber %]" />
425
                <img src="/intranet-tmpl/[% theme %]/img/famfamfam/silk/cross.png" title="Cannot transfer this item to your pickup location" alt="Cannot transfer this item to your pickup location" />
399
            [% ELSIF ( itemloo.override ) %]
426
            [% ELSIF ( itemloo.override ) %]
400
                <input type="radio" name="checkitem" class="needsoverride" value="[% itemloo.itemnumber %]" />
427
                <input type="radio" name="checkitem" class="needsoverride" value="[% itemloo.itemnumber %]" />
401
                <img src="/intranet-tmpl/[% theme %]/img/famfamfam/silk/error.png" alt="Requires override of hold policy" />
428
                <img src="/intranet-tmpl/[% theme %]/img/famfamfam/silk/error.png" title="Requires override of hold policy" alt="Requires override of hold policy" />
402
            [% ELSE %]
429
            [% ELSE %]
403
                <input disabled="disabled" type="radio" name="checkitem" value="[% itemloo.itemnumber %]" />
430
                <input disabled="disabled" type="radio" name="checkitem" value="[% itemloo.itemnumber %]" />
404
                <img src="/intranet-tmpl/[% theme %]/img/famfamfam/silk/cross.png" alt="Cannot be put on hold" />
431
                <img src="/intranet-tmpl/[% theme %]/img/famfamfam/silk/cross.png" title="Cannot be put on hold" alt="Cannot be put on hold" />
405
            [% END %]
432
            [% END %]
406
            </td>
433
            </td>
407
            [% IF ( item_level_itypes ) %]
434
            [% IF ( item_level_itypes ) %]
Lines 476-481 function checkMultiHold() { Link Here
476
503
477
  [% ELSE %]<!-- UNLESS multi_hold -->
504
  [% ELSE %]<!-- UNLESS multi_hold -->
478
505
506
479
    <table id="requesttitles">
507
    <table id="requesttitles">
480
      <tr>
508
      <tr>
481
        <th>Title</th>
509
        <th>Title</th>
Lines 493-499 function checkMultiHold() { Link Here
493
        [% END %]
521
        [% END %]
494
          <td>
522
          <td>
495
            <ul>
523
            <ul>
496
              <li><a href="/cgi-bin/koha/catalogue/detail.pl?biblionumber=[% biblioloo.biblionumber %]">[% biblioloo.title |html %]</a></li>
524
              <li>
525
			    [% IF ( biblioloo.suggestAnotherPickupLocation ) %]
526
					<img src="/intranet-tmpl/[% theme %]/img/famfamfam/silk/cross.png" title="Cannot transfer this item to your pickup location" alt="Cannot transfer this item to your pickup location" />
527
				[% END %]
528
				<a href="/cgi-bin/koha/catalogue/detail.pl?biblionumber=[% biblioloo.biblionumber %]">[% biblioloo.title |html %]</a>
529
			  </li>
497
              [% IF ( biblioloo.publicationyear ) %]
530
              [% IF ( biblioloo.publicationyear ) %]
498
                <li><span class="label">Publication year:</span> [% biblioloo.publicationyear %]</li>
531
                <li><span class="label">Publication year:</span> [% biblioloo.publicationyear %]</li>
499
              [% END %]
532
              [% END %]
Lines 539-549 function checkMultiHold() { Link Here
539
      [% END %]
572
      [% END %]
540
    </table>
573
    </table>
541
574
575
	[% IF ( bookBranchTransferDenied ) %]
576
		<div class="dialog alert">
577
			Some books cannot be transferred to your pickup location. Please try another pickup location, or reserve fewer items at once.
578
		</div>
579
	[% END %]
580
542
  [% END %]<!-- /multi_hold -->
581
  [% END %]<!-- /multi_hold -->
543
582
544
    <fieldset class="action">
583
    <fieldset class="action">
545
        [% IF ( borrowernumber ) %]
584
        [% IF ( borrowernumber ) %]
546
            [% IF ( override_required ) %]
585
			[% IF ( bookBranchTransferDenied ) %]
586
				<input type="submit" disabled="disabled" value="Place hold" />
587
            [% ELSIF ( override_required ) %]
547
                <input type="submit" class="warning" value="Place hold" />
588
                <input type="submit" class="warning" value="Place hold" />
548
            [% ELSIF ( none_available ) %]
589
            [% ELSIF ( none_available ) %]
549
                <input type="submit" disabled="disabled" value="Place hold" />
590
                <input type="submit" disabled="disabled" value="Place hold" />
Lines 600-625 function checkMultiHold() { Link Here
600
          <input type="hidden" name="borrowernumber" value="[% reserveloo.borrowernumber %]" />
641
          <input type="hidden" name="borrowernumber" value="[% reserveloo.borrowernumber %]" />
601
          <input type="hidden" name="biblionumber" value="[% reserveloo.biblionumber %]" />
642
          <input type="hidden" name="biblionumber" value="[% reserveloo.biblionumber %]" />
602
          <select name="rank-request">
643
          <select name="rank-request">
603
              [% IF ( reserveloo.wait ) %]
644
    [% IF ( reserveloo.wait ) %]
604
                  [% IF ( reserveloo.intransit ) %]
645
        [% IF ( reserveloo.intransit ) %]
605
                      <option value="T" selected="selected">In transit</option>
646
            <option value="T" selected="selected">In transit</option>
606
                  [% ELSE %]
647
        [% ELSE %]
607
                      <option value="W" selected="selected">Waiting</option>
648
            <option value="W" selected="selected">Waiting</option>
608
                  [% END %]
649
        [% END %]
609
              [% END %]
650
    [% END %]
610
651
	[% IF ( CAN_user_reserveforothers_modify_holds_priority ) %][% FOREACH optionloo IN reserveloo.optionloop %]
611
              [% IF ( CAN_user_reserveforothers_modify_holds_priority ) %]
652
        [% IF ( optionloo.selected ) %]<option value="[% optionloo.num %]" selected="selected">[% optionloo.num %]</option>[% ELSE %]<option value="[% optionloo.num %]">[% optionloo.num %]</option>[% END %]
612
                  [% FOREACH optionloo IN reserveloo.optionloop %]
653
        [% END %][% ELSE %]<option value=""></option>[% END %]
613
                      [% IF ( optionloo.selected ) %]
654
            <option value="del">del</option>
614
                          <option value="[% optionloo.num %]" selected="selected">[% optionloo.num %]</option>
615
                      [% ELSE %]
616
                          <option value="[% optionloo.num %]">[% optionloo.num %]</option>
617
                      [% END %]
618
                  [% END %]
619
              [% ELSIF !reserveloo.wait %]
620
                  <option value="[% reserveloo.priority %]" selected="selected">[% reserveloo.priority %]</option>
621
              [% END %]
622
              <option value="del">del</option>
623
          </select>
655
          </select>
624
        </td>
656
        </td>
625
657
Lines 774-777 function checkMultiHold() { Link Here
774
806
775
</div>
807
</div>
776
</div>
808
</div>
809
[% IF ( multi_hold ) %]
810
<form id="reloadPickupLocationForm" name="reloadPickupLocationForm" method="post" action="request.pl">
811
	<input type="hidden" name="borrowernumber" value="[% borrowernumber %]" />
812
    <input type="hidden" name="type" value="str8" />
813
	<input type="hidden" name="multi_hold" value="[% multi_hold %]"/>
814
	<input type="hidden" name="biblionumbers" id="multi_hold_bibs" value="[% biblionumbers %]"/>
815
	<input type="hidden" name="bad_bibs" id="bad_bibs" value=""/>
816
	<input type="hidden" name="request" value="any"/>
817
	<input type="hidden" name="pickup" value="fromJavascript" />
818
    [% FOREACH biblioloo IN biblioloop %]
819
        <input type="hidden" name="title_[% biblioloo.biblionumber %]" value="[% biblioloo.title |html %]"/>
820
        <input type="hidden" name="rank_[% biblioloo.biblionumber %]" value="[% biblioloo.rank %]"/>
821
    [% END %]
822
</form>
823
[% ELSE %]
824
<form id="reloadPickupLocationForm" name="reloadPickupLocationForm" method="post" action="request.pl">
825
	<input type="hidden" name="borrowernumber" value="[% borrowernumber %]" />
826
	<input type="hidden" name="biblionumber" value="[% biblionumber %]" />
827
	<input type="hidden" name="pickup" value="fromJavascript" />
828
</form>
829
[% END %]
830
777
[% INCLUDE 'intranet-bottom.inc' %]
831
[% INCLUDE 'intranet-bottom.inc' %]
(-)a/reserve/placerequest.pl (-82 / +142 lines)
Lines 3-9 Link Here
3
#script to place reserves/requests
3
#script to place reserves/requests
4
#writen 2/1/00 by chris@katipo.oc.nz
4
#writen 2/1/00 by chris@katipo.oc.nz
5
5
6
7
# Copyright 2000-2002 Katipo Communications
6
# Copyright 2000-2002 Katipo Communications
8
#
7
#
9
# This file is part of Koha.
8
# This file is part of Koha.
Lines 35-142 use C4::Auth qw/checkauth/; Link Here
35
34
36
my $input = CGI->new();
35
my $input = CGI->new();
37
36
38
checkauth($input, 0, { reserveforothers => 'place_holds' }, 'intranet');
37
checkauth( $input, 0, { reserveforothers => 'place_holds' }, 'intranet' );
38
39
my @bibitems = $input->param('biblioitem');
39
40
40
my @bibitems=$input->param('biblioitem');
41
# FIXME I think reqbib does not exist anymore, it's used in line 82, to AddReserve of contraint type 'o'
41
# FIXME I think reqbib does not exist anymore, it's used in line 82, to AddReserve of contraint type 'o'
42
#       I bet it's a 2.x feature, reserving a given biblioitem, that is useless in Koha 3.0
42
#       I bet it's a 2.x feature, reserving a given biblioitem, that is useless in Koha 3.0
43
#       we can remove this line, the AddReserve of constrainttype 'o',
43
#       we can remove this line, the AddReserve of constrainttype 'o',
44
#       and probably remove the reserveconstraint table as well, I never could fill anything in this table.
44
#       and probably remove the reserveconstraint table as well, I never could fill anything in this table.
45
my @reqbib=$input->param('reqbib'); 
45
my @reqbib         = $input->param('reqbib');
46
my $biblionumber=$input->param('biblionumber');
46
my $biblionumber   = $input->param('biblionumber');
47
my $borrowernumber=$input->param('borrowernumber');
47
my $borrowernumber = $input->param('borrowernumber');
48
my $notes=$input->param('notes');
48
my $notes          = $input->param('notes');
49
my $branch=$input->param('pickup');
49
my $branch         = $input->param('pickup');
50
my $startdate=$input->param('reserve_date') || '';
50
my $startdate      = $input->param('reserve_date') || '';
51
my @rank=$input->param('rank-request');
51
my @rank           = $input->param('rank-request');
52
my $type=$input->param('type');
52
my $type           = $input->param('type');
53
my $title=$input->param('title');
53
my $title          = $input->param('title');
54
my $borrower=GetMember('borrowernumber'=>$borrowernumber);
54
my $borrower       = GetMember( 'borrowernumber' => $borrowernumber );
55
my $checkitem=$input->param('checkitem');
55
my $checkitem      = $input->param('checkitem');
56
my $expirationdate = $input->param('expiration_date');
56
my $expirationdate = $input->param('expiration_date');
57
57
58
my $multi_hold = $input->param('multi_hold');
58
my $multi_hold = $input->param('multi_hold');
59
my $biblionumbers = $multi_hold ? $input->param('biblionumbers') : ($biblionumber . '/');
59
my $biblionumbers =
60
  $multi_hold ? $input->param('biblionumbers') : ( $biblionumber . '/' );
60
my $bad_bibs = $input->param('bad_bibs');
61
my $bad_bibs = $input->param('bad_bibs');
61
62
63
my $transferOk
64
  ;    # Used to check if this reservation passes UseBranchTransferLimits check.
65
my $errorMessages
66
  ;    # Used to concatenate generated error messages from multiple biblios.
67
62
my %bibinfos = ();
68
my %bibinfos = ();
63
my @biblionumbers = split '/', $biblionumbers;
69
my @biblionumbers = split '/', $biblionumbers;
64
foreach my $bibnum (@biblionumbers) {
70
foreach my $bibnum (@biblionumbers) {
65
    my %bibinfo = ();
71
	my %bibinfo = ();
66
    $bibinfo{title} = $input->param("title_$bibnum");
72
	$bibinfo{title}    = $input->param("title_$bibnum");
67
    $bibinfo{rank} = $input->param("rank_$bibnum");
73
	$bibinfo{rank}     = $input->param("rank_$bibnum");
68
    $bibinfos{$bibnum} = \%bibinfo;
74
	$bibinfos{$bibnum} = \%bibinfo;
69
}
75
}
70
71
my $found;
76
my $found;
72
77
73
# if we have an item selectionned, and the pickup branch is the same as the holdingbranch
78
# if we have an item selectionned, and the pickup branch is the same as the holdingbranch
74
# of the document, we force the value $rank and $found .
79
# of the document, we force the value $rank and $found .
75
if ($checkitem ne ''){
80
if ( defined $checkitem && $checkitem ne '' ) {
76
    $rank[0] = '0' unless C4::Context->preference('ReservesNeedReturns');
81
	$rank[0] = '0' unless C4::Context->preference('ReservesNeedReturns');
77
    my $item = $checkitem;
82
	my $item = $checkitem;
78
    $item = GetItem($item);
83
	$item = GetItem($item);
79
    if ( $item->{'holdingbranch'} eq $branch ){
84
	if ( $item->{'holdingbranch'} eq $branch ) {
80
        $found = 'W' unless C4::Context->preference('ReservesNeedReturns');
85
		$found = 'W' unless C4::Context->preference('ReservesNeedReturns');
81
    }
86
	}
82
}
87
}
83
88
84
if ($type eq 'str8' && $borrower){
89
if ( $type eq 'str8' && $borrower ) {
85
90
86
    foreach my $biblionumber (keys %bibinfos) {
91
	foreach my $biblionumber ( keys %bibinfos ) {
87
        my $count=@bibitems;
92
		my $count = @bibitems;
88
        @bibitems=sort @bibitems;
93
		@bibitems = sort @bibitems;
89
        my $i2=1;
94
		my $i2 = 1;
90
        my @realbi;
95
		my @realbi;
91
        $realbi[0]=$bibitems[0];
96
		$realbi[0] = $bibitems[0];
92
        for (my $i=1;$i<$count;$i++) {
97
		for ( my $i = 1 ; $i < $count ; $i++ ) {
93
            my $i3=$i2-1;
98
			my $i3 = $i2 - 1;
94
            if ($realbi[$i3] ne $bibitems[$i]) {
99
			if ( $realbi[$i3] ne $bibitems[$i] ) {
95
                $realbi[$i2]=$bibitems[$i];
100
				$realbi[$i2] = $bibitems[$i];
96
                $i2++;
101
				$i2++;
97
            }
102
			}
98
        }
103
		}
99
        my $const;
104
		my $const;
100
105
101
	if ($checkitem ne ''){
106
		if ( defined $checkitem && $checkitem ne '' ) {
102
		my $item = GetItem($checkitem);
107
			my $item = GetItem($checkitem);
103
        	if ($item->{'biblionumber'} ne $biblionumber) {
108
104
                	$biblionumber = $item->{'biblionumber'};
109
	#Making sure the biblionumber is present. Pretty robust! And possibly scary?
105
        	}
110
			if ( $item->{'biblionumber'} ne $biblionumber ) {
111
				$biblionumber = $item->{'biblionumber'};
112
			}
113
			my $errorMsg;
114
			( $transferOk, $errorMsg ) =
115
			  CanItemBeTransferred( $branch, $item->{holdingbranch},
116
				$item, undef );
117
			if ( !$transferOk ) {
118
				$errorMessages .= $errorMsg . ', ';
119
			}
120
		}
121
		else {
122
			#Final check if UseBranchTransferLimits validate for this Biblio.
123
			$transferOk =
124
			  CanBookBeReserved( $borrowernumber, $biblionumber, $branch );
125
		}
126
127
		if ($transferOk) {
128
129
			if ($multi_hold) {
130
				my $bibinfo = $bibinfos{$biblionumber};
131
				AddReserve(
132
					$branch,         $borrower->{'borrowernumber'},
133
					$biblionumber,   'a',
134
					[$biblionumber], $bibinfo->{rank},
135
					$startdate,      $expirationdate,
136
					$notes,          $bibinfo->{title},
137
					$checkitem,      $found
138
				);
139
			}
140
			else {
141
				if ( $input->param('request') eq 'any' ) {
142
143
					# place a request on 1st available
144
					AddReserve(
145
						$branch,       $borrower->{'borrowernumber'},
146
						$biblionumber, 'a',
147
						\@realbi,      $rank[0],
148
						$startdate,    $expirationdate,
149
						$notes,        $title,
150
						$checkitem,    $found
151
					);
152
				}
153
				elsif ( $reqbib[0] ne '' ) {
154
155
				 # FIXME : elsif probably never reached, (see top of the script)
156
				 # place a request on a given item
157
					AddReserve(
158
						$branch,       $borrower->{'borrowernumber'},
159
						$biblionumber, 'o',
160
						\@reqbib,      $rank[0],
161
						$startdate,    $expirationdate,
162
						$notes,        $title,
163
						$checkitem,    $found
164
					);
165
				}
166
				else {
167
					AddReserve(
168
						$branch,       $borrower->{'borrowernumber'},
169
						$biblionumber, 'a',
170
						\@realbi,      $rank[0],
171
						$startdate,    $expirationdate,
172
						$notes,        $title,
173
						$checkitem,    $found
174
					);
175
				}
176
			}
177
		}
106
	}
178
	}
107
179
	if ($errorMessages) {
108
180
		print $input->header();
109
181
		print "The following branch transfer limits are blocked:\n"
110
        if ($multi_hold) {
182
		  . $errorMessages;
111
            my $bibinfo = $bibinfos{$biblionumber};
183
	}
112
            AddReserve($branch,$borrower->{'borrowernumber'},$biblionumber,'a',[$biblionumber],
184
	elsif ($multi_hold) {
113
                       $bibinfo->{rank},$startdate,$expirationdate,$notes,$bibinfo->{title},$checkitem,$found);
185
		if ($bad_bibs) {
114
        } else {
186
			$biblionumbers .= $bad_bibs;
115
            if ($input->param('request') eq 'any'){
187
		}
116
                # place a request on 1st available
188
		print $input->redirect(
117
                AddReserve($branch,$borrower->{'borrowernumber'},$biblionumber,'a',\@realbi,$rank[0],$startdate,$expirationdate,$notes,$title,$checkitem,$found);
189
			"request.pl?biblionumbers=$biblionumbers&multi_hold=1");
118
            } elsif ($reqbib[0] ne ''){
190
	}
119
                # FIXME : elsif probably never reached, (see top of the script)
191
	else {
120
                # place a request on a given item
192
		print $input->redirect("request.pl?biblionumber=$biblionumber");
121
                AddReserve($branch,$borrower->{'borrowernumber'},$biblionumber,'o',\@reqbib,$rank[0],$startdate,$expirationdate,$notes,$title,$checkitem, $found);
193
	}
122
            } else {
194
}
123
                AddReserve($branch,$borrower->{'borrowernumber'},$biblionumber,'a',\@realbi,$rank[0],$startdate,$expirationdate,$notes,$title,$checkitem, $found);
195
elsif ( $borrower eq '' ) {
124
            }
125
        }
126
    }
127
128
    if ($multi_hold) {
129
        if ($bad_bibs) {
130
            $biblionumbers .= $bad_bibs;
131
        }
132
        print $input->redirect("request.pl?biblionumbers=$biblionumbers&multi_hold=1");
133
    } else {
134
        print $input->redirect("request.pl?biblionumber=$biblionumber");
135
    }
136
} elsif ($borrower eq ''){
137
	print $input->header();
196
	print $input->header();
138
	print "Invalid borrower number please try again";
197
	print "Invalid borrower number please try again";
139
# Not sure that Dump() does HTML escaping. Use firebug or something to trace
198
140
# instead.
199
	# Not sure that Dump() does HTML escaping. Use firebug or something to trace
141
#	print $input->Dump;
200
	# instead.
201
	#	print $input->Dump;
142
}
202
}
(-)a/reserve/request.pl (-488 / +572 lines)
Lines 1-6 Link Here
1
#!/usr/bin/perl
1
#!/usr/bin/perl
2
2
3
4
#writen 2/1/00 by chris@katipo.oc.nz
3
#writen 2/1/00 by chris@katipo.oc.nz
5
# Copyright 2000-2002 Katipo Communications
4
# Copyright 2000-2002 Katipo Communications
6
# Parts Copyright 2011 Catalyst IT
5
# Parts Copyright 2011 Catalyst IT
Lines 41-75 use C4::Koha; Link Here
41
use C4::Circulation;
40
use C4::Circulation;
42
use C4::Dates qw/format_date/;
41
use C4::Dates qw/format_date/;
43
use C4::Members;
42
use C4::Members;
44
use C4::Search;		# enabled_staff_search_views
43
use C4::Search;    # enabled_staff_search_views
45
use Koha::DateUtils;
44
use Koha::DateUtils;
46
45
47
my $dbh = C4::Context->dbh;
46
my $dbh = C4::Context->dbh;
48
my $sth;
47
my $sth;
49
my $input = new CGI;
48
my $input = new CGI;
50
my ( $template, $borrowernumber, $cookie, $flags ) = get_template_and_user(
49
my ( $template, $borrowernumber, $cookie, $flags ) = get_template_and_user(
51
    {
50
	{
52
        template_name   => "reserve/request.tmpl",
51
		template_name   => "reserve/request.tmpl",
53
        query           => $input,
52
		query           => $input,
54
        type            => "intranet",
53
		type            => "intranet",
55
        authnotrequired => 0,
54
		authnotrequired => 0,
56
        flagsrequired   => { reserveforothers => 'place_holds' },
55
		flagsrequired   => { reserveforothers => 'place_holds' },
57
    }
56
	}
58
);
57
);
59
58
60
my $multihold = $input->param('multi_hold');
59
my $multihold = $input->param('multi_hold');
61
$template->param(multi_hold => $multihold);
60
$template->param( multi_hold => $multihold );
62
my $showallitems = $input->param('showallitems');
61
my $showallitems = $input->param('showallitems');
63
62
64
# get Branches and Itemtypes
63
# get Branches and Itemtypes
65
my $branches = GetBranches();
64
my $branches  = GetBranches();
66
my $itemtypes = GetItemTypes();
65
my $itemtypes = GetItemTypes();
67
66
68
my $userbranch = '';
67
my $userbranch = '';
69
if (C4::Context->userenv && C4::Context->userenv->{'branch'}) {
68
if ( C4::Context->userenv && C4::Context->userenv->{'branch'} ) {
70
    $userbranch = C4::Context->userenv->{'branch'};
69
	$userbranch = C4::Context->userenv->{'branch'};
71
}
70
}
72
71
my $pickupBranch =
72
  $input->param('pickup') ? $input->param('pickup') : $userbranch;
73
73
74
# Select borrowers infos
74
# Select borrowers infos
75
my $findborrower = $input->param('findborrower');
75
my $findborrower = $input->param('findborrower');
Lines 79-168 my $borrowernumber_hold = $input->param('borrowernumber') || ''; Link Here
79
my $messageborrower;
79
my $messageborrower;
80
my $maxreserves;
80
my $maxreserves;
81
81
82
my $date = C4::Dates->today('iso');
82
my $date   = C4::Dates->today('iso');
83
my $action = $input->param('action');
83
my $action = $input->param('action');
84
$action ||= q{};
84
$action ||= q{};
85
85
86
if ( $action eq 'move' ) {
86
if ( $action eq 'move' ) {
87
  my $where = $input->param('where');
87
	my $where      = $input->param('where');
88
  my $reserve_id = $input->param('reserve_id');
88
	my $reserve_id = $input->param('reserve_id');
89
  AlterPriority( $where, $reserve_id );
89
	AlterPriority( $where, $reserve_id );
90
} elsif ( $action eq 'cancel' ) {
90
}
91
  my $reserve_id = $input->param('reserve_id');
91
elsif ( $action eq 'cancel' ) {
92
  CancelReserve({ reserve_id => $reserve_id });
92
	my $reserve_id = $input->param('reserve_id');
93
} elsif ( $action eq 'setLowestPriority' ) {
93
	CancelReserve( { reserve_id => $reserve_id } );
94
  my $reserve_id = $input->param('reserve_id');
94
}
95
  ToggleLowestPriority( $reserve_id );
95
elsif ( $action eq 'setLowestPriority' ) {
96
} elsif ( $action eq 'toggleSuspend' ) {
96
	my $reserve_id = $input->param('reserve_id');
97
  my $reserve_id = $input->param('reserve_id');
97
	ToggleLowestPriority($reserve_id);
98
  my $suspend_until  = $input->param('suspend_until');
98
}
99
  ToggleSuspend( $reserve_id, $suspend_until );
99
elsif ( $action eq 'toggleSuspend' ) {
100
	my $reserve_id    = $input->param('reserve_id');
101
	my $suspend_until = $input->param('suspend_until');
102
	ToggleSuspend( $reserve_id, $suspend_until );
100
}
103
}
101
104
102
if ($findborrower) {
105
if ($findborrower) {
103
    my $borrowers = Search($findborrower, 'cardnumber');
106
	my $borrowers = Search( $findborrower, 'cardnumber' );
104
107
105
    if ($borrowers && @$borrowers) {
108
	if ( $borrowers && @$borrowers ) {
106
        if ( @$borrowers == 1 ) {
109
		if ( @$borrowers == 1 ) {
107
            $borrowernumber_hold = $borrowers->[0]->{'borrowernumber'};
110
			$borrowernumber_hold = $borrowers->[0]->{'borrowernumber'};
108
        }
111
		}
109
        else {
112
		else {
110
            $template->param( borrower_list => sort_borrowerlist($borrowers));
113
			$template->param( borrower_list => sort_borrowerlist($borrowers) );
111
        }
114
		}
112
    } else {
115
	}
113
        $messageborrower = "'$findborrower'";
116
	else {
114
    }
117
		$messageborrower = "'$findborrower'";
118
	}
115
}
119
}
116
120
117
# If we have the borrowernumber because we've performed an action, then we
121
# If we have the borrowernumber because we've performed an action, then we
118
# don't want to try to place another reserve.
122
# don't want to try to place another reserve.
119
if ($borrowernumber_hold && !$action) {
123
if ( $borrowernumber_hold && !$action ) {
120
    my $borrowerinfo = GetMember( borrowernumber => $borrowernumber_hold );
124
	my $borrowerinfo = GetMember( borrowernumber => $borrowernumber_hold );
121
    my $diffbranch;
125
	my $diffbranch;
122
    my @getreservloop;
126
	my @getreservloop;
123
    my $count_reserv = 0;
127
	my $count_reserv = 0;
124
128
125
#   we check the reserves of the borrower, and if he can reserv a document
129
#   we check the reserves of the borrower, and if he can reserv a document
126
# FIXME At this time we have a simple count of reservs, but, later, we could improve the infos "title" ...
130
# FIXME At this time we have a simple count of reservs, but, later, we could improve the infos "title" ...
127
131
128
    my $number_reserves =
132
	my $number_reserves = GetReserveCount( $borrowerinfo->{'borrowernumber'} );
129
      GetReserveCount( $borrowerinfo->{'borrowernumber'} );
133
130
134
	if ( C4::Context->preference('maxreserves')
131
    if ( C4::Context->preference('maxreserves') && ($number_reserves >= C4::Context->preference('maxreserves')) ) {
135
		&& ( $number_reserves >= C4::Context->preference('maxreserves') ) )
132
        $maxreserves = 1;
136
	{
133
    }
137
		$maxreserves = 1;
134
138
	}
135
    # we check the date expiry of the borrower (only if there is an expiry date, otherwise, set to 1 (warn)
139
136
    my $expiry_date = $borrowerinfo->{dateexpiry};
140
# we check the date expiry of the borrower (only if there is an expiry date, otherwise, set to 1 (warn)
137
    my $expiry = 0; # flag set if patron account has expired
141
	my $expiry_date = $borrowerinfo->{dateexpiry};
138
    if ($expiry_date and $expiry_date ne '0000-00-00' and
142
	my $expiry = 0;    # flag set if patron account has expired
139
            Date_to_Days(split /-/,$date) > Date_to_Days(split /-/,$expiry_date)) {
143
	if (    $expiry_date
140
        $expiry = 1;
144
		and $expiry_date ne '0000-00-00'
141
    }
145
		and Date_to_Days( split /-/, $date ) >
142
146
		Date_to_Days( split /-/, $expiry_date ) )
143
    # check if the borrower make the reserv in a different branch
147
	{
144
    if ( $borrowerinfo->{'branchcode'} ne C4::Context->userenv->{'branch'} ) {
148
		$expiry = 1;
145
        $diffbranch = 1;
149
	}
146
    }
150
147
151
	# check if the borrower make the reserv in a different branch
148
    $template->param(
152
	if ( $borrowerinfo->{'branchcode'} ne C4::Context->userenv->{'branch'} ) {
149
                borrowernumber      => $borrowerinfo->{'borrowernumber'},
153
		$diffbranch = 1;
150
                borrowersurname     => $borrowerinfo->{'surname'},
154
	}
151
                borrowerfirstname   => $borrowerinfo->{'firstname'},
155
152
                borrowerstreetaddress   => $borrowerinfo->{'address'},
156
	$template->param(
153
                borrowercity        => $borrowerinfo->{'city'},
157
		borrowernumber        => $borrowerinfo->{'borrowernumber'},
154
                borrowerphone       => $borrowerinfo->{'phone'},
158
		borrowersurname       => $borrowerinfo->{'surname'},
155
                borrowermobile      => $borrowerinfo->{'mobile'},
159
		borrowerfirstname     => $borrowerinfo->{'firstname'},
156
                borrowerfax         => $borrowerinfo->{'fax'},
160
		borrowerstreetaddress => $borrowerinfo->{'address'},
157
                borrowerphonepro    => $borrowerinfo->{'phonepro'},
161
		borrowercity          => $borrowerinfo->{'city'},
158
                borroweremail       => $borrowerinfo->{'email'},
162
		borrowerphone         => $borrowerinfo->{'phone'},
159
                borroweremailpro    => $borrowerinfo->{'emailpro'},
163
		borrowermobile        => $borrowerinfo->{'mobile'},
160
                borrowercategory    => $borrowerinfo->{'category'},
164
		borrowerfax           => $borrowerinfo->{'fax'},
161
                borrowerreservs     => $count_reserv,
165
		borrowerphonepro      => $borrowerinfo->{'phonepro'},
162
                cardnumber          => $borrowerinfo->{'cardnumber'},
166
		borroweremail         => $borrowerinfo->{'email'},
163
                expiry              => $expiry,
167
		borroweremailpro      => $borrowerinfo->{'emailpro'},
164
                diffbranch          => $diffbranch,
168
		borrowercategory      => $borrowerinfo->{'category'},
165
    );
169
		borrowerreservs       => $count_reserv,
170
		cardnumber            => $borrowerinfo->{'cardnumber'},
171
		expiry                => $expiry,
172
		diffbranch            => $diffbranch,
173
	);
166
}
174
}
167
175
168
$template->param( messageborrower => $messageborrower );
176
$template->param( messageborrower => $messageborrower );
Lines 173-606 my $borrowerinfo = GetMember( borrowernumber => $borrowernumber_hold ); Link Here
173
my @biblionumbers = ();
181
my @biblionumbers = ();
174
my $biblionumbers = $input->param('biblionumbers');
182
my $biblionumbers = $input->param('biblionumbers');
175
if ($multihold) {
183
if ($multihold) {
176
    @biblionumbers = split '/', $biblionumbers;
184
	@biblionumbers = split '/', $biblionumbers;
177
} else {
185
}
178
    push @biblionumbers, $input->param('biblionumber');
186
else {
187
	push @biblionumbers, $input->param('biblionumber');
179
}
188
}
180
189
181
my $itemdata_enumchron = 0;
190
my $itemdata_enumchron = 0;
182
my @biblioloop = ();
191
my @biblioloop         = ();
183
foreach my $biblionumber (@biblionumbers) {
192
foreach my $biblionumber (@biblionumbers) {
184
193
185
    my %biblioloopiter = ();
194
	my %biblioloopiter = ();
186
195
187
    my $dat = GetBiblioData($biblionumber);
196
	my $dat = GetBiblioData($biblionumber);
188
197
189
    unless ( CanBookBeReserved($borrowerinfo->{borrowernumber}, $biblionumber) ) {
198
	unless (
190
        $maxreserves = 1;
199
		CanBookBeReserved( $borrowerinfo->{borrowernumber}, $biblionumber ) )
191
    }
200
	{
192
201
		$maxreserves = 1;
193
    my $alreadypossession;
202
	}
194
    if (not C4::Context->preference('AllowHoldsOnPatronsPossessions') and CheckIfIssuedToPatron($borrowerinfo->{borrowernumber},$biblionumber)) {
203
195
        $alreadypossession = 1;
204
	my $alreadypossession;
196
    }
205
	if ( not C4::Context->preference('AllowHoldsOnPatronsPossessions')
197
206
		and
198
    # get existing reserves .....
207
		CheckIfIssuedToPatron( $borrowerinfo->{borrowernumber}, $biblionumber )
199
    my ( $count, $reserves ) = GetReservesFromBiblionumber($biblionumber,1);
208
	  )
200
    my $totalcount = $count;
209
	{
201
    my $holds_count = 0;
210
		$alreadypossession = 1;
202
    my $alreadyreserved = 0;
211
	}
203
212
204
    foreach my $res (@$reserves) {
213
	# get existing reserves .....
205
        if ( defined $res->{found} && $res->{found} eq 'W' ) {
214
	my ( $count, $reserves ) = GetReservesFromBiblionumber( $biblionumber, 1 );
206
            $count--;
215
	my $totalcount      = $count;
207
        }
216
	my $holds_count     = 0;
208
217
	my $alreadyreserved = 0;
209
        if ( defined $borrowerinfo && defined($borrowerinfo->{borrowernumber}) && ($borrowerinfo->{borrowernumber} eq $res->{borrowernumber}) ) {
218
210
            $holds_count++;
219
	foreach my $res (@$reserves) {
211
        }
220
		if ( defined $res->{found} && $res->{found} eq 'W' ) {
212
    }
221
			$count--;
213
222
		}
214
    if ( $holds_count ) {
223
215
            $alreadyreserved = 1;
224
		if (   defined $borrowerinfo
216
            $biblioloopiter{warn} = 1;
225
			&& defined( $borrowerinfo->{borrowernumber} )
217
            $biblioloopiter{alreadyres} = 1;
226
			&& ( $borrowerinfo->{borrowernumber} eq $res->{borrowernumber} ) )
218
    }
227
		{
219
228
			$holds_count++;
220
    $template->param(
229
		}
221
        alreadyreserved => $alreadyreserved,
230
	}
222
        alreadypossession => $alreadypossession,
231
223
    );
232
	if ($holds_count) {
224
233
		$alreadyreserved            = 1;
225
    # FIXME think @optionloop, is maybe obsolete, or  must be switchable by a systeme preference fixed rank or not
234
		$biblioloopiter{warn}       = 1;
226
    # make priorities options
235
		$biblioloopiter{alreadyres} = 1;
227
236
	}
228
    my @optionloop;
237
229
    for ( 1 .. $count + 1 ) {
238
	$template->param(
230
        push(
239
		alreadyreserved   => $alreadyreserved,
231
             @optionloop,
240
		alreadypossession => $alreadypossession,
232
             {
241
	);
233
              num      => $_,
242
234
              selected => ( $_ == $count + 1 ),
243
# FIXME think @optionloop, is maybe obsolete, or  must be switchable by a systeme preference fixed rank or not
235
             }
244
# make priorities options
236
            );
245
237
    }
246
	my @optionloop;
238
    # adding a fixed value for priority options
247
	for ( 1 .. $count + 1 ) {
239
    my $fixedRank = $count+1;
248
		push(
240
249
			@optionloop,
241
    my @branchcodes;
250
			{
242
    my %itemnumbers_of_biblioitem;
251
				num      => $_,
243
    my @itemnumbers;
252
				selected => ( $_ == $count + 1 ),
244
253
			}
245
    ## $items is array of 'item' table numbers
254
		);
246
    if (my $items = get_itemnumbers_of($biblionumber)->{$biblionumber}){
255
	}
247
        @itemnumbers  = @$items;
256
248
    }
257
	# adding a fixed value for priority options
249
    my @hostitems = get_hostitemnumbers_of($biblionumber);
258
	my $fixedRank = $count + 1;
250
    if (@hostitems){
259
251
        $template->param('hostitemsflag' => 1);
260
	my @branchcodes;
252
        push(@itemnumbers, @hostitems);
261
	my %itemnumbers_of_biblioitem;
253
    }
262
	my @itemnumbers;
254
263
255
    if (!@itemnumbers) {
264
	## $items is array of 'item' table numbers
256
        $template->param('noitems' => 1);
265
	if ( my $items = get_itemnumbers_of($biblionumber)->{$biblionumber} ) {
257
        $biblioloopiter{noitems} = 1;
266
		@itemnumbers = @$items;
258
    }
259
260
    ## Hash of item number to 'item' table fields
261
    my $iteminfos_of = GetItemInfosOf(@itemnumbers);
262
263
    ## Here we go backwards again to create hash of biblioitemnumber to itemnumbers,
264
    ## when by definition all of the itemnumber have the same biblioitemnumber
265
    foreach my $itemnumber (@itemnumbers) {
266
        my $biblioitemnumber = $iteminfos_of->{$itemnumber}->{biblioitemnumber};
267
        push( @{ $itemnumbers_of_biblioitem{$biblioitemnumber} }, $itemnumber );
268
    }
269
270
    ## Should be same as biblionumber
271
    my @biblioitemnumbers = keys %itemnumbers_of_biblioitem;
272
273
    my $notforloan_label_of = get_notforloan_label_of();
274
275
    ## Hash of biblioitemnumber to 'biblioitem' table records
276
    my $biblioiteminfos_of  = GetBiblioItemInfosOf(@biblioitemnumbers);
277
278
    my @bibitemloop;
279
280
    foreach my $biblioitemnumber (@biblioitemnumbers) {
281
        my $biblioitem = $biblioiteminfos_of->{$biblioitemnumber};
282
        my $num_available = 0;
283
        my $num_override  = 0;
284
        my $hiddencount   = 0;
285
286
        $biblioitem->{description} =
287
          $itemtypes->{ $biblioitem->{itemtype} }{description};
288
	if($biblioitem->{biblioitemnumber} ne $biblionumber){
289
		$biblioitem->{hostitemsflag}=1;
290
	}
267
	}
291
        $biblioloopiter{description} = $biblioitem->{description};
268
	my @hostitems = get_hostitemnumbers_of($biblionumber);
292
        $biblioloopiter{itypename} = $biblioitem->{description};
269
	if (@hostitems) {
293
        $biblioloopiter{imageurl} =
270
		$template->param( 'hostitemsflag' => 1 );
294
          getitemtypeimagelocation('intranet', $itemtypes->{$biblioitem->{itemtype}}{imageurl});
271
		push( @itemnumbers, @hostitems );
295
272
	}
296
        foreach my $itemnumber ( @{ $itemnumbers_of_biblioitem{$biblioitemnumber} } )    {
273
297
            my $item = $iteminfos_of->{$itemnumber};
274
	if ( !@itemnumbers ) {
298
275
		$template->param( 'noitems' => 1 );
299
            unless (C4::Context->preference('item-level_itypes')) {
276
		$biblioloopiter{noitems} = 1;
300
                $item->{itype} = $biblioitem->{itemtype};
277
	}
301
            }
278
302
279
	## Hash of item number to 'item' table fields
303
            $item->{itypename} = $itemtypes->{ $item->{itype} }{description};
280
	my $iteminfos_of = GetItemInfosOf(@itemnumbers);
304
            $item->{imageurl} = getitemtypeimagelocation( 'intranet', $itemtypes->{ $item->{itype} }{imageurl} );
281
305
            $item->{homebranchname} = $branches->{ $item->{homebranch} }{branchname};
282
	## Here we go backwards again to create hash of biblioitemnumber to itemnumbers,
306
283
	## when by definition all of the itemnumber have the same biblioitemnumber
307
            # if the holdingbranch is different than the homebranch, we show the
284
	foreach my $itemnumber (@itemnumbers) {
308
            # holdingbranch of the document too
285
		my $biblioitemnumber = $iteminfos_of->{$itemnumber}->{biblioitemnumber};
309
            if ( $item->{homebranch} ne $item->{holdingbranch} ) {
286
		push( @{ $itemnumbers_of_biblioitem{$biblioitemnumber} }, $itemnumber );
310
                $item->{holdingbranchname} =
287
	}
311
                  $branches->{ $item->{holdingbranch} }{branchname};
288
312
            }
289
	## Should be same as biblionumber
313
290
	my @biblioitemnumbers = keys %itemnumbers_of_biblioitem;
314
		if($item->{biblionumber} ne $biblionumber){
291
315
			$item->{hostitemsflag}=1;
292
	my $notforloan_label_of = get_notforloan_label_of();
316
		        $item->{hosttitle} = GetBiblioData($item->{biblionumber})->{title};
293
294
	## Hash of biblioitemnumber to 'biblioitem' table records
295
	my $biblioiteminfos_of = GetBiblioItemInfosOf(@biblioitemnumbers);
296
297
	my @bibitemloop;
298
299
	foreach my $biblioitemnumber (@biblioitemnumbers) {
300
		my $biblioitem    = $biblioiteminfos_of->{$biblioitemnumber};
301
		my $num_available = 0;
302
		my $num_override  = 0;
303
		my $hiddencount   = 0;
304
305
#Collect the amout of items that pass the CanItemBeTransferred-check. This is needed to tell
306
#  the user if some or all Items cannot be transferred to the pickup location.
307
		my $branchTransferableItemsCount = 0;
308
309
		$biblioitem->{description} =
310
		  $itemtypes->{ $biblioitem->{itemtype} }{description};
311
		if ( $biblioitem->{biblioitemnumber} ne $biblionumber ) {
312
			$biblioitem->{hostitemsflag} = 1;
317
		}
313
		}
318
		
314
		$biblioloopiter{description} = $biblioitem->{description};
319
            #   add information
315
		$biblioloopiter{itypename}   = $biblioitem->{description};
320
            $item->{itemcallnumber} = $item->{itemcallnumber};
316
		$biblioloopiter{imageurl} =
321
317
		  getitemtypeimagelocation( 'intranet',
322
            # if the item is currently on loan, we display its return date and
318
			$itemtypes->{ $biblioitem->{itemtype} }{imageurl} );
323
            # change the background color
319
324
            my $issues= GetItemIssue($itemnumber);
320
		foreach
325
            if ( $issues->{'date_due'} ) {
321
		  my $itemnumber ( @{ $itemnumbers_of_biblioitem{$biblioitemnumber} } )
326
                $item->{date_due} = format_sqldatetime($issues->{date_due});
322
		{
327
                $item->{backgroundcolor} = 'onloan';
323
			my $item = $iteminfos_of->{$itemnumber};
328
            }
324
329
325
			unless ( C4::Context->preference('item-level_itypes') ) {
330
            # checking reserve
326
				$item->{itype} = $biblioitem->{itemtype};
331
            my ($reservedate,$reservedfor,$expectedAt,$reserve_id) = GetReservesFromItemnumber($itemnumber);
327
			}
332
            my $ItemBorrowerReserveInfo = GetMember( borrowernumber => $reservedfor );
328
333
329
			$item->{itypename} = $itemtypes->{ $item->{itype} }{description};
334
            if ( defined $reservedate ) {
330
			$item->{imageurl}  = getitemtypeimagelocation( 'intranet',
335
                $item->{backgroundcolor} = 'reserved';
331
				$itemtypes->{ $item->{itype} }{imageurl} );
336
                $item->{reservedate}     = format_date($reservedate);
332
			$item->{homebranchname} =
337
                $item->{ReservedForBorrowernumber}     = $reservedfor;
333
			  $branches->{ $item->{homebranch} }{branchname};
338
                $item->{ReservedForSurname}     = $ItemBorrowerReserveInfo->{'surname'};
334
339
                $item->{ReservedForFirstname}     = $ItemBorrowerReserveInfo->{'firstname'};
335
			# if the holdingbranch is different than the homebranch, we show the
340
                $item->{ExpectedAtLibrary}     = $branches->{$expectedAt}{branchname};
336
			# holdingbranch of the document too
341
337
			if ( $item->{homebranch} ne $item->{holdingbranch} ) {
342
            }
338
				$item->{holdingbranchname} =
343
339
				  $branches->{ $item->{holdingbranch} }{branchname};
344
            # Management of the notforloan document
340
			}
345
            if ( $item->{notforloan} ) {
341
346
                $item->{backgroundcolor} = 'other';
342
			if ( $item->{biblionumber} ne $biblionumber ) {
347
                $item->{notforloanvalue} =
343
				$item->{hostitemsflag} = 1;
348
                  $notforloan_label_of->{ $item->{notforloan} };
344
				$item->{hosttitle} =
349
            }
345
				  GetBiblioData( $item->{biblionumber} )->{title};
350
346
			}
351
            # Management of lost or long overdue items
347
352
            if ( $item->{itemlost} ) {
348
			#   add information
353
349
			$item->{itemcallnumber} = $item->{itemcallnumber};
354
                # FIXME localized strings should never be in Perl code
350
355
                $item->{message} =
351
			# if the item is currently on loan, we display its return date and
356
                  $item->{itemlost} == 1 ? "(lost)"
352
			# change the background color
357
                    : $item->{itemlost} == 2 ? "(long overdue)"
353
			my $issues = GetItemIssue($itemnumber);
358
                      : "";
354
			if ( $issues->{'date_due'} ) {
359
                $item->{backgroundcolor} = 'other';
355
				$item->{date_due} = format_sqldatetime( $issues->{date_due} );
360
                if (GetHideLostItemsPreference($borrowernumber) && !$showallitems) {
356
				$item->{backgroundcolor} = 'onloan';
361
                    $item->{hide} = 1;
357
			}
362
                    $hiddencount++;
358
363
                }
359
			# checking reserve
364
            }
360
			my ( $reservedate, $reservedfor, $expectedAt, $reserve_id ) =
365
361
			  GetReservesFromItemnumber($itemnumber);
366
            # Check the transit status
362
			my $ItemBorrowerReserveInfo =
367
            my ( $transfertwhen, $transfertfrom, $transfertto ) =
363
			  GetMember( borrowernumber => $reservedfor );
368
              GetTransfers($itemnumber);
364
369
365
			if ( defined $reservedate ) {
370
            if ( defined $transfertwhen && $transfertwhen ne '' ) {
366
				$item->{backgroundcolor}           = 'reserved';
371
                $item->{transfertwhen} = format_date($transfertwhen);
367
				$item->{reservedate}               = format_date($reservedate);
372
                $item->{transfertfrom} =
368
				$item->{ReservedForBorrowernumber} = $reservedfor;
373
                  $branches->{$transfertfrom}{branchname};
369
				$item->{ReservedForSurname} =
374
                $item->{transfertto} = $branches->{$transfertto}{branchname};
370
				  $ItemBorrowerReserveInfo->{'surname'};
375
                $item->{nocancel} = 1;
371
				$item->{ReservedForFirstname} =
376
            }
372
				  $ItemBorrowerReserveInfo->{'firstname'};
377
373
				$item->{ExpectedAtLibrary} =
378
            # If there is no loan, return and transfer, we show a checkbox.
374
				  $branches->{$expectedAt}{branchname};
379
            $item->{notforloan} = $item->{notforloan} || 0;
375
380
376
			}
381
            # if independent branches is on we need to check if the person can reserve
377
382
            # for branches they arent logged in to
378
			# Management of the notforloan document
383
            if ( C4::Context->preference("IndependentBranches") ) {
379
			if ( $item->{notforloan} ) {
384
                if (! C4::Context->preference("canreservefromotherbranches")){
380
				$item->{backgroundcolor} = 'other';
385
                    # cant reserve items so need to check if item homebranch and userenv branch match if not we cant reserve
381
				$item->{notforloanvalue} =
386
                    my $userenv = C4::Context->userenv;
382
				  $notforloan_label_of->{ $item->{notforloan} };
387
                    if ( ($userenv) && ( $userenv->{flags} % 2 != 1 ) ) {
383
			}
388
                        $item->{cantreserve} = 1 if ( $item->{homebranch} ne $userenv->{branch} );
384
389
                    }
385
			# Management of lost or long overdue items
390
                }
386
			if ( $item->{itemlost} ) {
391
            }
387
392
388
				# FIXME localized strings should never be in Perl code
393
            my $branch = C4::Circulation::_GetCircControlBranch($item, $borrowerinfo);
389
				$item->{message} =
394
390
					$item->{itemlost} == 1 ? "(lost)"
395
            my $branchitemrule = GetBranchItemRule( $branch, $item->{'itype'} );
391
				  : $item->{itemlost} == 2 ? "(long overdue)"
396
            my $policy_holdallowed = 1;
392
				  :                          "";
397
393
				$item->{backgroundcolor} = 'other';
398
            $item->{'holdallowed'} = $branchitemrule->{'holdallowed'};
394
				if ( GetHideLostItemsPreference($borrowernumber)
399
395
					&& !$showallitems )
400
            if ( $branchitemrule->{'holdallowed'} == 0 ||
396
				{
401
                 ( $branchitemrule->{'holdallowed'} == 1 &&
397
					$item->{hide} = 1;
402
                     $borrowerinfo->{'branchcode'} ne $item->{'homebranch'} ) ) {
398
					$hiddencount++;
403
                $policy_holdallowed = 0;
399
				}
404
            }
400
			}
405
            
401
406
            if (
402
			# Check the transit status
407
                   $policy_holdallowed
403
			my ( $transfertwhen, $transfertfrom, $transfertto ) =
408
                && !$item->{cantreserve}
404
			  GetTransfers($itemnumber);
409
                && IsAvailableForItemLevelRequest($itemnumber)
405
410
                && CanItemBeReserved(
406
			if ( defined $transfertwhen && $transfertwhen ne '' ) {
411
                    $borrowerinfo->{borrowernumber}, $itemnumber
407
				$item->{transfertwhen} = format_date($transfertwhen);
412
                )
408
				$item->{transfertfrom} =
413
              )
409
				  $branches->{$transfertfrom}{branchname};
414
            {
410
				$item->{transfertto} = $branches->{$transfertto}{branchname};
415
                $item->{available} = 1;
411
				$item->{nocancel}    = 1;
416
                $num_available++;
412
			}
417
            }
413
418
            elsif ( C4::Context->preference('AllowHoldPolicyOverride') ) {
414
			# If there is no loan, return and transfer, we show a checkbox.
415
			$item->{notforloan} = $item->{notforloan} || 0;
416
417
	  # if independent branches is on we need to check if the person can reserve
418
	  # for branches they arent logged in to
419
			if ( C4::Context->preference("IndependentBranches") ) {
420
				if ( !C4::Context->preference("canreservefromotherbranches") ) {
421
422
# cant reserve items so need to check if item homebranch and userenv branch match if not we cant reserve
423
					my $userenv = C4::Context->userenv;
424
					if ( ($userenv) && ( $userenv->{flags} % 2 != 1 ) ) {
425
						$item->{cantreserve} = 1
426
						  if ( $item->{homebranch} ne $userenv->{branch} );
427
					}
428
				}
429
			}
430
431
			# UseBranchTransferLimits checking
432
			my ( $transferOk, $errorMessage ) =
433
			  CanItemBeTransferred( $pickupBranch, $item->{holdingbranch},
434
				$item, undef );
435
			if ( !$transferOk ) {
436
				$item->{cantreserve}          = 1;
437
				$item->{branchTransferDenied} = 1;
438
			}
439
			else {
440
				$branchTransferableItemsCount++;
441
			}
442
443
			my $branch =
444
			  C4::Circulation::_GetCircControlBranch( $item, $borrowerinfo );
445
446
			my $branchitemrule = GetBranchItemRule( $branch, $item->{'itype'} );
447
			my $policy_holdallowed = 1;
448
449
			$item->{'holdallowed'} = $branchitemrule->{'holdallowed'};
450
451
			if (
452
				$branchitemrule->{'holdallowed'} == 0
453
				|| (   $branchitemrule->{'holdallowed'} == 1
454
					&& $borrowerinfo->{'branchcode'} ne $item->{'homebranch'} )
455
			  )
456
			{
457
				$policy_holdallowed = 0;
458
			}
459
460
			if (
461
				   $policy_holdallowed
462
				&& !$item->{cantreserve}
463
				&& IsAvailableForItemLevelRequest($itemnumber)
464
				&& CanItemBeReserved(
465
					$borrowerinfo->{borrowernumber}, $itemnumber
466
				)
467
			  )
468
			{
469
				$item->{available} = 1;
470
				$num_available++;
471
			}
472
			elsif ( C4::Context->preference('AllowHoldPolicyOverride') ) {
419
473
420
# If AllowHoldPolicyOverride is set, it should override EVERY restriction, not just branch item rules
474
# If AllowHoldPolicyOverride is set, it should override EVERY restriction, not just branch item rules
421
                $item->{override} = 1;
475
				$item->{override} = 1;
422
                $num_override++;
476
				$num_override++;
423
            }
477
			}
424
478
425
            # If none of the conditions hold true, then neither override nor available is set and the item cannot be checked
479
# If none of the conditions hold true, then neither override nor available is set and the item cannot be checked
426
480
427
            # FIXME: move this to a pm
481
			# FIXME: move this to a pm
428
            my $sth2 = $dbh->prepare("SELECT * FROM reserves WHERE borrowernumber=? AND itemnumber=? AND found='W'");
482
			my $sth2 = $dbh->prepare(
429
            $sth2->execute($item->{ReservedForBorrowernumber},$item->{itemnumber});
483
"SELECT * FROM reserves WHERE borrowernumber=? AND itemnumber=? AND found='W'"
430
            while (my $wait_hashref = $sth2->fetchrow_hashref) {
484
			);
431
                $item->{waitingdate} = format_date($wait_hashref->{waitingdate});
485
			$sth2->execute( $item->{ReservedForBorrowernumber},
432
            }
486
				$item->{itemnumber} );
433
487
			while ( my $wait_hashref = $sth2->fetchrow_hashref ) {
434
            # Show serial enumeration when needed
488
				$item->{waitingdate} =
435
            if ($item->{enumchron}) {
489
				  format_date( $wait_hashref->{waitingdate} );
436
                $itemdata_enumchron = 1;
490
			}
437
            }
491
438
492
			# Show serial enumeration when needed
439
            push @{ $biblioitem->{itemloop} }, $item;
493
			if ( $item->{enumchron} ) {
440
        }
494
				$itemdata_enumchron = 1;
441
495
			}
442
        if ( $num_override == scalar( @{ $biblioitem->{itemloop} } ) ) { # That is, if all items require an override
496
443
            $template->param( override_required => 1 );
497
			push @{ $biblioitem->{itemloop} }, $item;
444
        } elsif ( $num_available == 0 ) {
498
		}
445
            $template->param( none_available => 1 );
499
446
            $biblioloopiter{warn} = 1;
500
		if ( $num_override == scalar( @{ $biblioitem->{itemloop} } ) )
447
            $biblioloopiter{none_avail} = 1;
501
		{    # That is, if all items require an override
448
        }
502
			$template->param( override_required => 1 );
449
        $template->param( hiddencount => $hiddencount);
503
		}
450
504
		elsif ( $num_available == 0 ) {
451
        push @bibitemloop, $biblioitem;
505
			$template->param( none_available => 1 );
452
    }
506
			$biblioloopiter{warn}       = 1;
453
507
			$biblioloopiter{none_avail} = 1;
454
    # existingreserves building
508
		}
455
    my @reserveloop;
509
		if ( $branchTransferableItemsCount == 0 ) {
456
    ( $count, $reserves ) = GetReservesFromBiblionumber($biblionumber,1);
510
			$biblioloopiter{suggestAnotherPickupLocation} = 1;
457
    foreach my $res ( sort {
511
			$biblioitem->{suggestAnotherPickupLocation} = 1;
458
            my $a_found = $a->{found} || '';
512
			$template->param( bookBranchTransferDenied => 1 );
459
            my $b_found = $a->{found} || '';
513
		}
460
            $a_found cmp $b_found;
514
461
        } @$reserves ) {
515
		$template->param( hiddencount => $hiddencount );
462
        my %reserve;
516
463
        my @optionloop;
517
		push @bibitemloop, $biblioitem;
464
        for ( my $i = 1 ; $i <= $totalcount ; $i++ ) {
518
	}
465
            push(
519
466
                 @optionloop,
520
	# existingreserves building
467
                 {
521
	my @reserveloop;
468
                  num      => $i,
522
	( $count, $reserves ) = GetReservesFromBiblionumber( $biblionumber, 1 );
469
                  selected => ( $i == $res->{priority} ),
523
	foreach my $res (
470
                 }
524
		sort {
471
                );
525
			my $a_found = $a->{found} || '';
472
        }
526
			my $b_found = $a->{found} || '';
473
527
			$a_found cmp $b_found;
474
        if ( defined $res->{'found'} && ($res->{'found'} eq 'W' || $res->{'found'} eq 'T' )) {
528
		} @$reserves
475
            my $item = $res->{'itemnumber'};
529
	  )
476
            $item = GetBiblioFromItemNumber($item,undef);
530
	{
477
            $reserve{'wait'}= 1;
531
		my %reserve;
478
            $reserve{'holdingbranch'}=$item->{'holdingbranch'};
532
		my @optionloop;
479
            $reserve{'biblionumber'}=$item->{'biblionumber'};
533
		for ( my $i = 1 ; $i <= $totalcount ; $i++ ) {
480
            $reserve{'barcodenumber'}   = $item->{'barcode'};
534
			push(
481
            $reserve{'wbrcode'} = $res->{'branchcode'};
535
				@optionloop,
482
            $reserve{'itemnumber'}  = $res->{'itemnumber'};
536
				{
483
            $reserve{'wbrname'} = $branches->{$res->{'branchcode'}}->{'branchname'};
537
					num      => $i,
484
            if($reserve{'holdingbranch'} eq $reserve{'wbrcode'}){
538
					selected => ( $i == $res->{priority} ),
485
                $reserve{'atdestination'} = 1;
539
				}
486
            }
540
			);
487
            # set found to 1 if reserve is waiting for patron pickup
541
		}
488
            $reserve{'found'} = 1 if $res->{'found'} eq 'W';
542
489
            $reserve{'intransit'} = 1 if $res->{'found'} eq 'T';
543
		if ( defined $res->{'found'}
490
        } elsif ($res->{priority} > 0) {
544
			&& ( $res->{'found'} eq 'W' || $res->{'found'} eq 'T' ) )
491
            if (defined($res->{itemnumber})) {
545
		{
492
                my $item = GetItem($res->{itemnumber});
546
			my $item = $res->{'itemnumber'};
493
                $reserve{'itemnumber'}  = $res->{'itemnumber'};
547
			$item = GetBiblioFromItemNumber( $item, undef );
494
                $reserve{'barcodenumber'}   = $item->{'barcode'};
548
			$reserve{'wait'}          = 1;
495
                $reserve{'item_level_hold'} = 1;
549
			$reserve{'holdingbranch'} = $item->{'holdingbranch'};
496
            }
550
			$reserve{'biblionumber'}  = $item->{'biblionumber'};
497
        }
551
			$reserve{'barcodenumber'} = $item->{'barcode'};
498
552
			$reserve{'wbrcode'}       = $res->{'branchcode'};
499
        #     get borrowers reserve info
553
			$reserve{'itemnumber'}    = $res->{'itemnumber'};
500
        my $reserveborrowerinfo = GetMember( borrowernumber => $res->{'borrowernumber'} );
554
			$reserve{'wbrname'} =
501
        if (C4::Context->preference('HidePatronName')){
555
			  $branches->{ $res->{'branchcode'} }->{'branchname'};
502
	    $reserve{'hidename'} = 1;
556
503
	    $reserve{'cardnumber'} = $reserveborrowerinfo->{'cardnumber'};
557
			if ( $reserve{'holdingbranch'} eq $reserve{'wbrcode'} ) {
558
				$reserve{'atdestination'} = 1;
559
			}
560
561
			# set found to 1 if reserve is waiting for patron pickup
562
			$reserve{'found'}     = 1 if $res->{'found'} eq 'W';
563
			$reserve{'intransit'} = 1 if $res->{'found'} eq 'T';
564
		}
565
		elsif ( $res->{priority} > 0 ) {
566
			if ( defined( $res->{itemnumber} ) ) {
567
				my $item = GetItem( $res->{itemnumber} );
568
				$reserve{'itemnumber'}      = $res->{'itemnumber'};
569
				$reserve{'barcodenumber'}   = $item->{'barcode'};
570
				$reserve{'item_level_hold'} = 1;
571
			}
572
		}
573
574
		#     get borrowers reserve info
575
		my $reserveborrowerinfo =
576
		  GetMember( borrowernumber => $res->{'borrowernumber'} );
577
		if ( C4::Context->preference('HidePatronName') ) {
578
			$reserve{'hidename'}   = 1;
579
			$reserve{'cardnumber'} = $reserveborrowerinfo->{'cardnumber'};
580
		}
581
		$reserve{'expirationdate'} = format_date( $res->{'expirationdate'} )
582
		  unless ( !defined( $res->{'expirationdate'} )
583
			|| $res->{'expirationdate'} eq '0000-00-00' );
584
		$reserve{'date'}           = format_date( $res->{'reservedate'} );
585
		$reserve{'borrowernumber'} = $res->{'borrowernumber'};
586
		$reserve{'biblionumber'}   = $res->{'biblionumber'};
587
		$reserve{'borrowernumber'} = $res->{'borrowernumber'};
588
		$reserve{'firstname'}      = $reserveborrowerinfo->{'firstname'};
589
		$reserve{'surname'}        = $reserveborrowerinfo->{'surname'};
590
		$reserve{'notes'}          = $res->{'reservenotes'};
591
		$reserve{'wait'}           = (
592
				 ( defined $res->{'found'} and $res->{'found'} eq 'W' )
593
			  or ( $res->{'priority'} eq '0' )
594
		);
595
		$reserve{'constrainttypea'} = ( $res->{'constrainttype'} eq 'a' );
596
		$reserve{'constrainttypeo'} = ( $res->{'constrainttype'} eq 'o' );
597
		$reserve{'voldesc'}         = $res->{'volumeddesc'};
598
		$reserve{'ccode'}           = $res->{'ccode'};
599
		$reserve{'barcode'}         = $res->{'barcode'};
600
		$reserve{'priority'}        = $res->{'priority'};
601
		$reserve{'lowestPriority'}  = $res->{'lowestPriority'};
602
		$reserve{'optionloop'}      = \@optionloop;
603
		$reserve{'suspend'}         = $res->{'suspend'};
604
		$reserve{'suspend_until'}   = $res->{'suspend_until'};
605
		$reserve{'reserve_id'}      = $res->{'reserve_id'};
606
607
		if ( C4::Context->preference('IndependentBranches')
608
			&& $flags->{'superlibrarian'} != 1 )
609
		{
610
			$reserve{'branchloop'} =
611
			  [ GetBranchDetail( $res->{'branchcode'} ) ];
612
		}
613
		else {
614
			$reserve{'branchloop'} = GetBranchesLoop( $res->{'branchcode'} );
615
		}
616
617
		push( @reserveloop, \%reserve );
618
	}
619
620
	# get the time for the form name...
621
	my $time = time();
622
623
	$template->param(
624
		branchloop => GetBranchesLoop($pickupBranch),
625
		time       => $time,
626
		fixedRank  => $fixedRank,
627
	);
628
629
	# display infos
630
	$template->param(
631
		optionloop         => \@optionloop,
632
		bibitemloop        => \@bibitemloop,
633
		itemdata_enumchron => $itemdata_enumchron,
634
		date               => $date,
635
		biblionumber       => $biblionumber,
636
		findborrower       => $findborrower,
637
		title              => $dat->{title},
638
		author             => $dat->{author},
639
		holdsview          => 1,
640
		C4::Search::enabled_staff_search_views,
641
	);
642
	if ( defined $borrowerinfo && exists $borrowerinfo->{'branchcode'} ) {
643
		$template->param(
644
			borrower_branchname =>
645
			  $branches->{ $borrowerinfo->{'branchcode'} }->{'branchname'},
646
			borrower_branchcode => $borrowerinfo->{'branchcode'},
647
		);
504
	}
648
	}
505
        $reserve{'expirationdate'} = format_date( $res->{'expirationdate'} )
649
506
            unless ( !defined($res->{'expirationdate'}) || $res->{'expirationdate'} eq '0000-00-00' );
650
	$biblioloopiter{biblionumber} = $biblionumber;
507
        $reserve{'date'}           = format_date( $res->{'reservedate'} );
651
	$biblioloopiter{title}        = $dat->{title};
508
        $reserve{'borrowernumber'} = $res->{'borrowernumber'};
652
	$biblioloopiter{rank}         = $fixedRank;
509
        $reserve{'biblionumber'}   = $res->{'biblionumber'};
653
	$biblioloopiter{reserveloop}  = \@reserveloop;
510
        $reserve{'borrowernumber'} = $res->{'borrowernumber'};
654
511
        $reserve{'firstname'}      = $reserveborrowerinfo->{'firstname'};
655
	if (@reserveloop) {
512
        $reserve{'surname'}        = $reserveborrowerinfo->{'surname'};
656
		$template->param( reserveloop => \@reserveloop );
513
        $reserve{'notes'}          = $res->{'reservenotes'};
657
	}
514
        $reserve{'wait'}           =
658
515
          ( ( defined $res->{'found'} and $res->{'found'} eq 'W' ) or ( $res->{'priority'} eq '0' ) );
659
	push @biblioloop, \%biblioloopiter;
516
        $reserve{'constrainttypea'} = ( $res->{'constrainttype'} eq 'a' );
517
        $reserve{'constrainttypeo'} = ( $res->{'constrainttype'} eq 'o' );
518
        $reserve{'voldesc'}         = $res->{'volumeddesc'};
519
        $reserve{'ccode'}           = $res->{'ccode'};
520
        $reserve{'barcode'}         = $res->{'barcode'};
521
        $reserve{'priority'}    = $res->{'priority'};
522
        $reserve{'lowestPriority'}    = $res->{'lowestPriority'};
523
        $reserve{'optionloop'} = \@optionloop;
524
        $reserve{'suspend'} = $res->{'suspend'};
525
        $reserve{'suspend_until'} = $res->{'suspend_until'};
526
        $reserve{'reserve_id'} = $res->{'reserve_id'};
527
528
        if ( C4::Context->preference('IndependentBranches') && $flags->{'superlibrarian'} != 1 ) {
529
              $reserve{'branchloop'} = [ GetBranchDetail($res->{'branchcode'}) ];
530
        } else {
531
              $reserve{'branchloop'} = GetBranchesLoop($res->{'branchcode'});
532
        }
533
534
        push( @reserveloop, \%reserve );
535
    }
536
537
    # get the time for the form name...
538
    my $time = time();
539
540
    $template->param(
541
                     branchloop  => GetBranchesLoop($userbranch),
542
                     time        => $time,
543
                     fixedRank   => $fixedRank,
544
                    );
545
546
    # display infos
547
    $template->param(
548
                     optionloop        => \@optionloop,
549
                     bibitemloop       => \@bibitemloop,
550
                     itemdata_enumchron => $itemdata_enumchron,
551
                     date              => $date,
552
                     biblionumber      => $biblionumber,
553
                     findborrower      => $findborrower,
554
                     title             => $dat->{title},
555
                     author            => $dat->{author},
556
                     holdsview => 1,
557
                     C4::Search::enabled_staff_search_views,
558
                    );
559
    if (defined $borrowerinfo && exists $borrowerinfo->{'branchcode'}) {
560
        $template->param(
561
                     borrower_branchname => $branches->{$borrowerinfo->{'branchcode'}}->{'branchname'},
562
                     borrower_branchcode => $borrowerinfo->{'branchcode'},
563
        );
564
    }
565
566
    $biblioloopiter{biblionumber} = $biblionumber;
567
    $biblioloopiter{title} = $dat->{title};
568
    $biblioloopiter{rank} = $fixedRank;
569
    $biblioloopiter{reserveloop} = \@reserveloop;
570
571
    if (@reserveloop) {
572
        $template->param( reserveloop => \@reserveloop );
573
    }
574
575
    push @biblioloop, \%biblioloopiter;
576
}
660
}
577
661
578
$template->param( biblioloop => \@biblioloop );
662
$template->param( biblioloop    => \@biblioloop );
579
$template->param( biblionumbers => $biblionumbers );
663
$template->param( biblionumbers => $biblionumbers );
580
$template->param( maxreserves => $maxreserves );
664
$template->param( maxreserves   => $maxreserves );
581
665
582
if ($multihold) {
666
if ($multihold) {
583
    $template->param( multi_hold => 1 );
667
	$template->param( multi_hold => 1 );
584
}
668
}
585
669
586
if ( C4::Context->preference( 'AllowHoldDateInFuture' ) ) {
670
if ( C4::Context->preference('AllowHoldDateInFuture') ) {
587
    $template->param( reserve_in_future => 1 );
671
	$template->param( reserve_in_future => 1 );
588
}
672
}
589
673
590
$template->param(
674
$template->param(
591
    SuspendHoldsIntranet => C4::Context->preference('SuspendHoldsIntranet'),
675
	SuspendHoldsIntranet => C4::Context->preference('SuspendHoldsIntranet'),
592
    AutoResumeSuspendedHolds => C4::Context->preference('AutoResumeSuspendedHolds'),
676
	AutoResumeSuspendedHolds =>
677
	  C4::Context->preference('AutoResumeSuspendedHolds'),
593
);
678
);
594
679
595
# printout the page
680
# printout the page
596
output_html_with_http_headers $input, $cookie, $template->output;
681
output_html_with_http_headers $input, $cookie, $template->output;
597
682
598
sub sort_borrowerlist {
683
sub sort_borrowerlist {
599
    my $borrowerslist = shift;
684
	my $borrowerslist = shift;
600
    my $ref           = [];
685
	my $ref           = [];
601
    push @{$ref}, sort {
686
	push @{$ref}, sort {
602
        uc( $a->{surname} . $a->{firstname} ) cmp
687
		uc( $a->{surname} . $a->{firstname} ) cmp
603
          uc( $b->{surname} . $b->{firstname} )
688
		  uc( $b->{surname} . $b->{firstname} )
604
    } @{$borrowerslist};
689
	} @{$borrowerslist};
605
    return $ref;
690
	return $ref;
606
}
691
}
607
- 

Return to bug 11020