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

(-)a/C4/Reserves.pm (+66 lines)
Lines 133-138 BEGIN { Link Here
133
        &SuspendAll
133
        &SuspendAll
134
134
135
        &GetReservesControlBranch
135
        &GetReservesControlBranch
136
	&PreventOPACHoldsAnyAvailableItem
136
    );
137
    );
137
    @EXPORT_OK = qw( MergeHolds );
138
    @EXPORT_OK = qw( MergeHolds );
138
}    
139
}    
Lines 2214-2219 sub GetReservesControlBranch { Link Here
2214
    return $branchcode;
2215
    return $branchcode;
2215
}
2216
}
2216
2217
2218
2219
=head2 PreventOPACHoldsAnyAvailableItem
2220
Checks if an item is available to have a hold placed on it from the OPAC only.
2221
Specifically relates to items currently on the shelf (without a datedue).
2222
If 'AllowOnShelfHolds' syspref is allowed then this will always return false i.e
2223
PreventOPACHoldsAnyAvailableItem will not prevent OPAC holds.
2224
2225
Is controlled by the 'PreventOPACHoldsAnyAvailableItem' system preference.
2226
2227
The system preference has 2 states:
2228
2229
* off: Not in effect. Allowing of hold will be determined elsewhere in the system.
2230
* on: Each bibnumber will be checked for attached items. Each item is checked for
2231
its availability. The only status that prevents a hold is when an item is on the
2232
shelf and available. All other status should be ignored.
2233
2234
Returns true when any item attached to the bib is on the shelf and available
2235
2236
=cut
2237
2238
sub PreventOPACHoldsAnyAvailableItem {
2239
    my $biblionumber = shift;
2240
    
2241
    if ( C4::Context->preference('AllowOnShelfHolds') or not C4::Context->preference('PreventOPACHoldsAnyAvailableItem') ) {
2242
	return 0; # we shouldn't be in here
2243
    }
2244
    
2245
    my @items = GetItemsInfo( $biblionumber );
2246
    my $prevent_hold = 0;
2247
    my $dbh = C4::Context->dbh;
2248
    my $notforloan_query;
2249
    if (C4::Context->preference('item-level_itypes')) {
2250
        $notforloan_query = "SELECT itemtypes.notforloan
2251
                             FROM items
2252
                             JOIN itemtypes ON (itemtypes.itemtype = items.itype)
2253
                             WHERE itemnumber = ?";
2254
    } else {
2255
        $notforloan_query = "SELECT itemtypes.notforloan
2256
                             FROM items
2257
                             JOIN biblioitems USING (biblioitemnumber)
2258
                             JOIN itemtypes USING (itemtype)
2259
                             WHERE itemnumber = ?";
2260
    }
2261
    my $sth = $dbh->prepare($notforloan_query);
2262
    foreach my $item (@items) {    
2263
	$sth->execute( 	$item->{itemnumber} );
2264
        my $notforloan_itemtype = 0;
2265
        if (my ($notforloan) = $sth->fetchrow_array) {
2266
            $notforloan_itemtype = 1 if $notforloan;
2267
        }
2268
2269
	if ( not $item->{datedue} ) {
2270
	    if ($item->{itemlost}
2271
		or ( $item->{notforloan} > 0 )
2272
		or ( $item->{damaged} and not C4::Context->preference('AllowHoldsOnDamagedItems') )
2273
		or $item->{wthdrawn}
2274
		or $notforloan_itemtype)  {
2275
		    next;
2276
	    }
2277
	    else {$prevent_hold++}
2278
	}
2279
    }
2280
    return $prevent_hold;
2281
}
2282
2217
=head1 AUTHOR
2283
=head1 AUTHOR
2218
2284
2219
Koha Development Team <http://koha-community.org/>
2285
Koha Development Team <http://koha-community.org/>
(-)a/installer/data/mysql/sysprefs.sql (+1 lines)
Lines 301-306 INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` Link Here
301
('Persona','0','','Use Mozilla Persona for login','YesNo'),
301
('Persona','0','','Use Mozilla Persona for login','YesNo'),
302
('PrefillItem','0','','When a new item is added, should it be prefilled with last created item values?','YesNo'),
302
('PrefillItem','0','','When a new item is added, should it be prefilled with last created item values?','YesNo'),
303
('previousIssuesDefaultSortOrder','asc','asc|desc','Specify the sort order of Previous Issues on the circulation page','Choice'),
303
('previousIssuesDefaultSortOrder','asc','asc|desc','Specify the sort order of Previous Issues on the circulation page','Choice'),
304
('PreventOPACHoldsAnyAvailableItem,'0',NULL,'Define how OPAC users can place holds on items that are checked in (on the self),'Choice'),
304
('printcirculationslips','1','','If ON, enable printing circulation receipts','YesNo'),
305
('printcirculationslips','1','','If ON, enable printing circulation receipts','YesNo'),
305
('PrintNoticesMaxLines','0','','If greater than 0, sets the maximum number of lines an overdue notice will print. If the number of items is greater than this number, the notice will end with a warning asking the borrower to check their online account for a full list of overdue items.','Integer'),
306
('PrintNoticesMaxLines','0','','If greater than 0, sets the maximum number of lines an overdue notice will print. If the number of items is greater than this number, the notice will end with a warning asking the borrower to check their online account for a full list of overdue items.','Integer'),
306
('QueryAutoTruncate','1',NULL,'If ON, query truncation is enabled by default','YesNo'),
307
('QueryAutoTruncate','1',NULL,'If ON, query truncation is enabled by default','YesNo'),
(-)a/installer/data/mysql/updatedatabase.pl (+6 lines)
Lines 7743-7748 if(CheckVersion($DBversion)) { Link Here
7743
    SetVersion($DBversion);
7743
    SetVersion($DBversion);
7744
}
7744
}
7745
7745
7746
$DBversion = "3.13.00.XXX";
7747
   if ( CheckVersion($DBversion) ) {
7748
       $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('PreventOPACHoldsAnyAvailableItem', '0', 'Define how OPAC users can place holds on items that are checked in (on the self)', NULL ,'Choice')");
7749
       print "Upgrade to $DBversion done (Bug 6837: Enchances AllowOnShelfHolds SystemPref, give more granular control over OPAC holds )\n";
7750
       SetVersion($DBversion);
7751
   }
7746
=head1 FUNCTIONS
7752
=head1 FUNCTIONS
7747
7753
7748
=head2 TableExists($table)
7754
=head2 TableExists($table)
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref (+7 lines)
Lines 370-375 Circulation: Link Here
370
                  no: "Don't allow"
370
                  no: "Don't allow"
371
            - hold requests to be placed on items that are not checked out.
371
            - hold requests to be placed on items that are not checked out.
372
        -
372
        -
373
            - pref: PreventOPACHoldsAnyAvailableItem
374
              type: choice
375
              choices:
376
                  yes: Prevent
377
                  no: Do not explicitly prevent
378
            -  holds to be placed when ANY item is on the shelf. (Preference is ignored if AllowOnShelfHolds is ON)
379
        -
373
            - pref: AllowHoldDateInFuture
380
            - pref: AllowHoldDateInFuture
374
              choices:
381
              choices:
375
                  yes: Allow
382
                  yes: Allow
(-)a/koha-tmpl/opac-tmpl/prog/en/includes/opac-detail-sidebar.inc (-5 / +7 lines)
Lines 2-13 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 (PreventOPACHoldsAnyAvailableItem) %]
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>
10
                    [% END %]
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 %]
12
                [% END %]
11
                [% END %]
13
                [% END %]
12
            [% END %]
14
            [% END %]
13
        [% END %]
15
        [% 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 / +8 lines)
Lines 401-409 if ($session->param('busc')) { Link Here
401
}
401
}
402
402
403
403
404
# Check if we can place a hold on this bib where there is an item out but others available
405
my $prevent_holds = 0;
406
if ( C4::Context->preference('PreventOPACHoldsAnyAvailableItem') && not C4::Context->preference('AllowOnShelfHolds') ) {
407
    $prevent_holds = PreventOPACHoldsAnyAvailableItem( $biblionumber );
408
    print "HOLDS: $prevent_holds<br />";
409
}
404
410
411
$template->param( 'PreventOPACHoldsAnyAvailableItem' => $prevent_holds );
405
$template->param( 'AllowOnShelfHolds' => C4::Context->preference('AllowOnShelfHolds') );
412
$template->param( 'AllowOnShelfHolds' => C4::Context->preference('AllowOnShelfHolds') );
406
$template->param( 'ItemsIssued' => CountItemsIssued( $biblionumber ) );
413
$template->param( 'ItemsIssued' => CountItemsIssued( $biblionumber ) ) if not $prevent_holds;
407
414
408
415
409
416
(-)a/opac/opac-search.pl (-2 / +8 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-680 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
		    my $prevent_holds = 0;
679
		    if ( C4::Context->preference('PreventOPACHoldsAnyAvailableItem') && not C4::Context->preference('AllowOnShelfHolds') ) {
680
			$prevent_holds = PreventOPACHoldsAnyAvailableItem($bibnum) if $bibnum;
681
		    }
682
		    if ( $prevent_holds ) {
683
			$_->{prevent_holds} =1;
684
		    }
678
                    $pasarParams .= $bibnum . ',';
685
                    $pasarParams .= $bibnum . ',';
679
                    $j++;
686
                    $j++;
680
                    last if ($j == $results_per_page);
687
                    last if ($j == $results_per_page);
681
- 

Return to bug 6837