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

(-)a/C4/Reserves.pm (-1 / +60 lines)
Lines 133-138 BEGIN { Link Here
133
        &SuspendAll
133
        &SuspendAll
134
134
135
        &GetReservesControlBranch
135
        &GetReservesControlBranch
136
        &PreventHoldsAnyAvailableItem
136
    );
137
    );
137
    @EXPORT_OK = qw( MergeHolds );
138
    @EXPORT_OK = qw( MergeHolds );
138
}    
139
}    
Lines 788-794 If several reserves exist, the reserve with the lower priority is given. Link Here
788
## the sub is only used once in the codebase.
789
## the sub is only used once in the codebase.
789
sub GetReserveStatus {
790
sub GetReserveStatus {
790
    my ($itemnumber, $biblionumber) = @_;
791
    my ($itemnumber, $biblionumber) = @_;
791
792
    my $dbh = C4::Context->dbh;
792
    my $dbh = C4::Context->dbh;
793
793
794
    my ($sth, $found, $priority);
794
    my ($sth, $found, $priority);
Lines 2214-2219 sub GetReservesControlBranch { Link Here
2214
    return $branchcode;
2214
    return $branchcode;
2215
}
2215
}
2216
2216
2217
=head2 PreventHoldsAnyAvailableItem
2218
Checks if an item is available to have a hold placed on it.
2219
Specifically relates to items currently on the shelf (without a datedue).
2220
2221
Returns true when any item attached to the bib is on the shelf and available
2222
2223
=cut
2224
2225
sub PreventHoldsAnyAvailableItem {
2226
    my $biblionumber = shift;
2227
    my @items = GetItemsInfo( $biblionumber );
2228
    my $prevent_hold = 0;
2229
    my $not_out = 0;
2230
    my $checked_out = 0;
2231
    my $dbh = C4::Context->dbh;
2232
    my $notforloan_query;
2233
    if (C4::Context->preference('item-level_itypes')) {
2234
        $notforloan_query = "SELECT itemtypes.notforloan
2235
                             FROM items
2236
                             JOIN itemtypes ON (itemtypes.itemtype = items.itype)
2237
                             WHERE itemnumber = ?";
2238
    } else {
2239
        $notforloan_query = "SELECT itemtypes.notforloan
2240
                             FROM items
2241
                             JOIN biblioitems USING (biblioitemnumber)
2242
                             JOIN itemtypes USING (itemtype)
2243
                             WHERE itemnumber = ?";
2244
    }
2245
    my $sth = $dbh->prepare($notforloan_query);
2246
    
2247
    foreach my $item (@items) {    
2248
	$sth->execute( 	$item->{itemnumber} );
2249
        my $notforloan_itemtype = 0;
2250
        if (my ($notforloan) = $sth->fetchrow_array) {
2251
            $notforloan_itemtype = 1 if $notforloan;
2252
        }
2253
2254
	if ( not $item->{datedue} ) {
2255
      my $reserve_status = GetReserveStatus( $item->{itemnumber} );
2256
	   if ($item->{itemlost}
2257
		or ( $item->{notforloan} > 0 )
2258
		or ( $item->{damaged} and not C4::Context->preference('AllowHoldsOnDamagedItems') )
2259
		or $item->{wthdrawn}
2260
		or $notforloan_itemtype
2261
      or $reserve_status eq "Waiting"
2262
      or $reserve_status eq "Reserved")
2263
      {
2264
		    next;
2265
	    }
2266
	    else {$prevent_hold++}
2267
2268
	}
2269
2270
    }
2271
2272
    return $prevent_hold;
2273
2274
}
2275
2217
=head1 AUTHOR
2276
=head1 AUTHOR
2218
2277
2219
Koha Development Team <http://koha-community.org/>
2278
Koha Development Team <http://koha-community.org/>
(-)a/koha-tmpl/opac-tmpl/prog/en/includes/opac-detail-sidebar.inc (-4 / +6 lines)
Lines 2-12 Link Here
2
    [% UNLESS ( norequests ) %]
2
    [% UNLESS ( norequests ) %]
3
        [% IF ( opacuserlogin ) %]
3
        [% IF ( opacuserlogin ) %]
4
            [% IF ( RequestOnOpac ) %]
4
            [% IF ( RequestOnOpac ) %]
5
                [% IF ( AllowOnShelfHolds ) %]
5
                [% UNLESS ( PreventHoldsAnyAvailableItem ) %]            
6
                    <li><a class="reserve" href="/cgi-bin/koha/opac-reserve.pl?biblionumber=[% biblionumber %]">Place hold</a></li>
6
                    [% IF ( AllowOnShelfHolds ) %]
7
                [% ELSE %]
8
                    [% IF ( ItemsIssued ) %]
9
                        <li><a class="reserve" href="/cgi-bin/koha/opac-reserve.pl?biblionumber=[% biblionumber %]">Place hold</a></li>
7
                        <li><a class="reserve" href="/cgi-bin/koha/opac-reserve.pl?biblionumber=[% biblionumber %]">Place hold</a></li>
8
                    [% ELSE %]
9
                        [% IF ( ItemsIssued ) %]
10
                            <li><a class="reserve" href="/cgi-bin/koha/opac-reserve.pl?biblionumber=[% biblionumber %]">Place hold</a></li>
11
                        [% END %]
10
                    [% END %]
12
                    [% END %]
11
                [% END %]
13
                [% END %]
12
            [% END %]
14
            [% END %]
(-)a/koha-tmpl/opac-tmpl/prog/en/modules/opac-results-grouped.tt (-6 / +8 lines)
Lines 273-285 function highlightOn() { Link Here
273
                                [% IF ( RequestOnOpac ) %]
273
                                [% IF ( RequestOnOpac ) %]
274
					[% UNLESS ( GROUP_RESULT.norequests ) %]
274
					[% UNLESS ( GROUP_RESULT.norequests ) %]
275
						[% IF ( opacuserlogin ) %]
275
						[% IF ( opacuserlogin ) %]
276
							[% IF ( AllowOnShelfHolds ) %]
276
						  [% UNLESS SEARCH_RESULT.prevent_holds %]
277
                                <a class="hold" href="/cgi-bin/koha/opac-reserve.pl?biblionumber=[% GROUP_RESULT.biblionumber %]">Place hold</a><!-- add back when available 0 holds in queue-->
277
								[% IF ( AllowOnShelfHolds ) %]
278
							[% ELSE %]
278
											  <a class="hold" href="/cgi-bin/koha/opac-reserve.pl?biblionumber=[% GROUP_RESULT.biblionumber %]">Place hold</a><!-- add back when available 0 holds in queue-->
279
								[% IF ( GROUP_RESULT.itemsissued ) %]
279
								[% ELSE %]
280
                                    <a class="hold" href="/cgi-bin/koha/opac-reserve.pl?biblionumber=[% GROUP_RESULT.biblionumber %]">Place hold</a><!-- add back when available 0 holds in queue-->
280
									[% IF ( GROUP_RESULT.itemsissued ) %]
281
													<a class="hold" href="/cgi-bin/koha/opac-reserve.pl?biblionumber=[% GROUP_RESULT.biblionumber %]">Place hold</a><!-- add back when available 0 holds in queue-->
282
									[% END %]
281
								[% END %]
283
								[% END %]
282
							[% END %]
284
						  [% END %]
283
						[% END %]
285
						[% END %]
284
					[% END %]
286
					[% END %]
285
				[% END %]
287
				[% END %]
(-)a/koha-tmpl/opac-tmpl/prog/en/modules/opac-results.tt (-4 / +6 lines)
Lines 667-677 $(document).ready(function(){ Link Here
667
                [% IF ( RequestOnOpac ) %]
667
                [% IF ( RequestOnOpac ) %]
668
                    [% UNLESS ( SEARCH_RESULT.norequests ) %]
668
                    [% UNLESS ( SEARCH_RESULT.norequests ) %]
669
                        [% IF ( opacuserlogin ) %]
669
                        [% IF ( opacuserlogin ) %]
670
                            [% IF ( AllowOnShelfHolds ) %]
670
                            [% UNLESS SEARCH_RESULT.prevent_holds %]  
671
                                <a class="hold" href="/cgi-bin/koha/opac-reserve.pl?biblionumber=[% SEARCH_RESULT.biblionumber %]">Place hold</a><!-- add back when available 0 holds in queue-->
671
                                [% IF ( AllowOnShelfHolds ) %]
672
                            [% ELSE %]
673
                                [% IF ( SEARCH_RESULT.itemsissued ) %]
674
                                    <a class="hold" href="/cgi-bin/koha/opac-reserve.pl?biblionumber=[% SEARCH_RESULT.biblionumber %]">Place hold</a><!-- add back when available 0 holds in queue-->
672
                                    <a class="hold" href="/cgi-bin/koha/opac-reserve.pl?biblionumber=[% SEARCH_RESULT.biblionumber %]">Place hold</a><!-- add back when available 0 holds in queue-->
673
                                [% ELSE %]
674
                                    [% IF ( SEARCH_RESULT.itemsissued ) %]
675
                                        <a class="hold" href="/cgi-bin/koha/opac-reserve.pl?biblionumber=[% SEARCH_RESULT.biblionumber %]">Place hold</a><!-- add back when available 0 holds in queue-->
676
                                    [% END %]
675
                                [% END %]
677
                                [% END %]
676
                            [% END %]
678
                            [% END %]
677
                        [% END %]
679
                        [% END %]
(-)a/opac/opac-detail.pl (-1 / +6 lines)
Lines 401-412 if ($session->param('busc')) { Link Here
401
}
401
}
402
402
403
403
404
my $prevent_holds = 0;
405
if ( not C4::Context->preference('AllowOnShelfHolds') ) {
406
    $prevent_holds = PreventHoldsAnyAvailableItem( $biblionumber );
404
407
408
}
409
410
$template->param( 'PreventHoldsAnyAvailableItem' => $prevent_holds );
405
$template->param( 'AllowOnShelfHolds' => C4::Context->preference('AllowOnShelfHolds') );
411
$template->param( 'AllowOnShelfHolds' => C4::Context->preference('AllowOnShelfHolds') );
406
$template->param( 'ItemsIssued' => CountItemsIssued( $biblionumber ) );
412
$template->param( 'ItemsIssued' => CountItemsIssued( $biblionumber ) );
407
413
408
414
409
410
$template->param('OPACShowCheckoutName' => C4::Context->preference("OPACShowCheckoutName") );
415
$template->param('OPACShowCheckoutName' => C4::Context->preference("OPACShowCheckoutName") );
411
$template->param('OPACShowBarcode' => C4::Context->preference("OPACShowBarcode") );
416
$template->param('OPACShowBarcode' => C4::Context->preference("OPACShowBarcode") );
412
417
(-)a/opac/opac-reserve.pl (-6 / +12 lines)
Lines 352-360 my $itemdata_enumchron = 0; Link Here
352
my $anyholdable = 0;
352
my $anyholdable = 0;
353
my $itemLevelTypes = C4::Context->preference('item-level_itypes');
353
my $itemLevelTypes = C4::Context->preference('item-level_itypes');
354
$template->param('item_level_itypes' => $itemLevelTypes);
354
$template->param('item_level_itypes' => $itemLevelTypes);
355
355
my $prevent_holds = 0;
356
foreach my $biblioNum (@biblionumbers) {
356
foreach my $biblioNum (@biblionumbers) {
357
357
    if ( not C4::Context->preference('AllowOnShelfHolds') ) {
358
        $prevent_holds = PreventHoldsAnyAvailableItem($biblioNum)
359
    }
360
    
358
    my $record = GetMarcBiblio($biblioNum);
361
    my $record = GetMarcBiblio($biblioNum);
359
    # Init the bib item with the choices for branch pickup
362
    # Init the bib item with the choices for branch pickup
360
    my %biblioLoopIter = ( branchloop => $branchloop );
363
    my %biblioLoopIter = ( branchloop => $branchloop );
Lines 500-510 foreach my $biblioNum (@biblionumbers) { Link Here
500
            $policy_holdallowed = 0;
503
            $policy_holdallowed = 0;
501
        }
504
        }
502
505
503
        if (IsAvailableForItemLevelRequest($itemNum) and $policy_holdallowed and CanItemBeReserved($borrowernumber,$itemNum) and ($itemLoopIter->{already_reserved} ne 1)) {
506
        unless ($prevent_holds > 0 ) {
504
            $itemLoopIter->{available} = 1;
507
            if (IsAvailableForItemLevelRequest($itemNum) and $policy_holdallowed and CanItemBeReserved($borrowernumber,$itemNum) and ($itemLoopIter->{already_reserved} ne 1)) {
505
            $numCopiesAvailable++;
508
                $itemLoopIter->{available} = 1;
509
                $numCopiesAvailable++;
510
            }
506
        }
511
        }
507
512
513
508
	# FIXME: move this to a pm
514
	# FIXME: move this to a pm
509
        my $dbh = C4::Context->dbh;
515
        my $dbh = C4::Context->dbh;
510
        my $sth2 = $dbh->prepare("SELECT * FROM reserves WHERE borrowernumber=? AND itemnumber=? AND found='W'");
516
        my $sth2 = $dbh->prepare("SELECT * FROM reserves WHERE borrowernumber=? AND itemnumber=? AND found='W'");
Lines 544-550 foreach my $biblioNum (@biblionumbers) { Link Here
544
    push @$biblioLoop, \%biblioLoopIter;
550
    push @$biblioLoop, \%biblioLoopIter;
545
}
551
}
546
552
547
if ( $numBibsAvailable == 0 || $anyholdable == 0) {
553
if ( $numBibsAvailable == 0 || $anyholdable == 0 || $prevent_holds > 0 ) {
548
    $template->param( none_available => 1 );
554
    $template->param( none_available => 1 );
549
}
555
}
550
556
(-)a/opac/opac-search.pl (-2 / +11 lines)
Lines 52-58 use C4::Branch; # GetBranches Link Here
52
use C4::SocialData;
52
use C4::SocialData;
53
use C4::Ratings;
53
use C4::Ratings;
54
use C4::External::OverDrive;
54
use C4::External::OverDrive;
55
55
use C4::Reserves;
56
use POSIX qw(ceil floor strftime);
56
use POSIX qw(ceil floor strftime);
57
use URI::Escape;
57
use URI::Escape;
58
use JSON qw/decode_json encode_json/;
58
use JSON qw/decode_json encode_json/;
Lines 675-683 for (my $i=0;$i<@servers;$i++) { Link Here
675
                my $j = 0;
675
                my $j = 0;
676
                foreach (@newresults) {
676
                foreach (@newresults) {
677
                    my $bibnum = ($_->{biblionumber})?$_->{biblionumber}:0;
677
                    my $bibnum = ($_->{biblionumber})?$_->{biblionumber}:0;
678
                # Check if holds are allowed 
679
                    my $prevent_holds = 0;
680
                    if ( not C4::Context->preference('AllowOnShelfHolds') ) {
681
                        $prevent_holds = PreventHoldsAnyAvailableItem($bibnum) if $bibnum;
682
                    }
683
                    if ( $prevent_holds ) {
684
                        $_->{prevent_holds} =1;
685
                    }
686
                    
678
                    $pasarParams .= $bibnum . ',';
687
                    $pasarParams .= $bibnum . ',';
679
                    $j++;
688
                    $j++;
680
                    last if ($j == $results_per_page);
689
                    last if ($j == $results_per_page);
690
681
                }
691
                }
682
                chop $pasarParams if ($pasarParams =~ /,$/);
692
                chop $pasarParams if ($pasarParams =~ /,$/);
683
                $pasarParams .= '&amp;total=' . int($total) if ($pasarParams !~ /total=(?:[0-9]+)?/);
693
                $pasarParams .= '&amp;total=' . int($total) if ($pasarParams !~ /total=(?:[0-9]+)?/);
684
- 

Return to bug 6837