@@ -, +, @@ you are placing. --- installer/data/mysql/updatedatabase.pl | 7 ++++ .../opac-tmpl/bootstrap/en/modules/opac-reserve.tt | 13 +++++++ koha-tmpl/opac-tmpl/bootstrap/js/global.js | 14 +++++++- opac/opac-reserve.pl | 38 ++++++++++++------- reserve/request.pl | 14 +++++--- 5 files changed, 66 insertions(+), 20 deletions(-) --- a/installer/data/mysql/updatedatabase.pl +++ a/installer/data/mysql/updatedatabase.pl @@ -8551,6 +8551,13 @@ if (CheckVersion($DBversion)) { SetVersion($DBversion); } +$DBversion = "3.15.00.XXX"; +if ( CheckVersion($DBversion) ) { + $dbh->do("INSERT IGNORE INTO systempreferences (variable,value,explanation,options,type) VALUES ('maxreserves',50,'System-wide maximum number of holds a patron can place','','Integer')"); + print "Upgrade to $DBversion done (Re-add system preference maxreserves)\n"; + SetVersion($DBversion); +} + =head1 FUNCTIONS =head2 TableExists($table) --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-reserve.tt +++ a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-reserve.tt @@ -105,6 +105,12 @@ [% END %] + [% IF ( new_reserves_allowed ) %] +
+ Sorry, you can only place [% new_reserves_allowed %] more holds. Please uncheck the checkboxes for the items you wish to not place holds on. +
+ [% END %] +
@@ -563,6 +569,13 @@ var biblionumbers = ""; var selections = ""; + [% IF new_reserves_allowed %] + if ($(".confirmjs:checked").size() > [% new_reserves_allowed %] ) { + alert(MSG_MAX_HOLDS_EXCEEDED); + return false; + } + [% END %] + if ($(".confirmjs:checked").size() == 0) { alert(MSG_NO_RECORD_SELECTED); return false; --- a/koha-tmpl/opac-tmpl/bootstrap/js/global.js +++ a/koha-tmpl/opac-tmpl/bootstrap/js/global.js @@ -1,3 +1,15 @@ +// http://stackoverflow.com/questions/1038746/equivalent-of-string-format-in-jquery/5341855#5341855 +String.prototype.format = function() { return formatstr(this, arguments) } +function formatstr(str, col) { + col = typeof col === 'object' ? col : Array.prototype.slice.call(arguments, 1); + var idx = 0; + return str.replace(/%%|%s|%(\d+)\$s/g, function (m, n) { + if (m == "%%") { return "%"; } + if (m == "%s") { return col[idx++]; } + return col[n]; + }); +}; + function confirmDelete(message) { return (confirm(message) ? true : false); } @@ -22,4 +34,4 @@ function prefixOf (s, tok) { function suffixOf (s, tok) { var index = s.indexOf(tok); return s.substring(index + 1); -} +} --- a/opac/opac-reserve.pl +++ a/opac/opac-reserve.pl @@ -38,7 +38,7 @@ use Koha::DateUtils; use Date::Calc qw/Today Date_to_Days/; # use Data::Dumper; -my $MAXIMUM_NUMBER_OF_RESERVES = C4::Context->preference("maxreserves"); +my $maxreserves = C4::Context->preference("maxreserves"); my $query = new CGI; my ( $template, $borrowernumber, $cookie ) = get_template_and_user( @@ -114,6 +114,7 @@ if (($#biblionumbers < 0) && (! $query->param('place_reserve'))) { &get_out($query, $cookie, $template->output); } + # pass the pickup branch along.... my $branch = $query->param('branch') || $borr->{'branchcode'} || C4::Context->userenv->{branch} || '' ; ($branches->{$branch}) or $branch = ""; # Confirm branch is real @@ -183,7 +184,7 @@ foreach my $biblioNumber (@biblionumbers) { # if ( $query->param('place_reserve') ) { my $reserve_cnt = 0; - if ($MAXIMUM_NUMBER_OF_RESERVES) { + if ($maxreserves) { $reserve_cnt = GetReservesFromBorrowernumber( $borrowernumber ); } @@ -267,8 +268,8 @@ if ( $query->param('place_reserve') ) { } my $notes = $query->param('notes_'.$biblioNum)||''; - if ( $MAXIMUM_NUMBER_OF_RESERVES - && $reserve_cnt >= $MAXIMUM_NUMBER_OF_RESERVES ) + if ( $maxreserves + && $reserve_cnt >= $maxreserves ) { $canreserve = 0; } @@ -308,32 +309,41 @@ if ( $borr->{'amountoutstanding'} && ($borr->{'amountoutstanding'} > $maxoutstan if ( $borr->{gonenoaddress} && ($borr->{gonenoaddress} == 1) ) { $noreserves = 1; $template->param( - message => 1, - GNA => 1 - ); + message => 1, + GNA => 1 + ); } if ( $borr->{lost} && ($borr->{lost} == 1) ) { $noreserves = 1; $template->param( - message => 1, - lost => 1 - ); + message => 1, + lost => 1 + ); } if ( $borr->{'debarred'} ) { $noreserves = 1; $template->param( - message => 1, - debarred => 1 - ); + message => 1, + debarred => 1 + ); } my @reserves = GetReservesFromBorrowernumber( $borrowernumber ); +my $reserves_count = scalar(@reserves); $template->param( RESERVES => \@reserves ); -if ( $MAXIMUM_NUMBER_OF_RESERVES && (scalar(@reserves) >= $MAXIMUM_NUMBER_OF_RESERVES) ) { +if ( $maxreserves && ( $reserves_count >= $maxreserves ) ) { $template->param( message => 1 ); $noreserves = 1; $template->param( too_many_reserves => scalar(@reserves)); } + +unless ( $noreserves ) { + my $requested_reserves_count = scalar( @biblionumbers ); + if ( $maxreserves && ( $reserves_count + $requested_reserves_count > $maxreserves ) ) { + $template->param( new_reserves_allowed => $maxreserves - $reserves_count ); + } +} + foreach my $res (@reserves) { foreach my $biblionumber (@biblionumbers) { if ( $res->{'biblionumber'} == $biblionumber && $res->{'borrowernumber'} == $borrowernumber) { --- a/reserve/request.pl +++ a/reserve/request.pl @@ -78,6 +78,8 @@ $findborrower =~ s|,| |g; my $borrowernumber_hold = $input->param('borrowernumber') || ''; my $messageborrower; my $maxreserves; +my $warnings; +my $messages; my $date = C4::Dates->today('iso'); my $action = $input->param('action'); @@ -122,13 +124,14 @@ if ($borrowernumber_hold && !$action) { my @getreservloop; my $count_reserv = 0; -# we check the reserves of the borrower, and if he can reserv a document -# FIXME At this time we have a simple count of reservs, but, later, we could improve the infos "title" ... + # we check the reserves of the borrower, and if he can reserv a document + # FIXME At this time we have a simple count of reservs, but, later, we could improve the infos "title" ... my $number_reserves = GetReserveCount( $borrowerinfo->{'borrowernumber'} ); if ( C4::Context->preference('maxreserves') && ($number_reserves >= C4::Context->preference('maxreserves')) ) { + $warnings = 1; $maxreserves = 1; } @@ -136,7 +139,7 @@ if ($borrowernumber_hold && !$action) { my $expiry_date = $borrowerinfo->{dateexpiry}; my $expiry = 0; # flag set if patron account has expired if ($expiry_date and $expiry_date ne '0000-00-00' and - Date_to_Days(split /-/,$date) > Date_to_Days(split /-/,$expiry_date)) { + Date_to_Days(split /-/,$date) > Date_to_Days(split /-/,$expiry_date)) { $expiry = 1; } @@ -162,6 +165,8 @@ if ($borrowernumber_hold && !$action) { cardnumber => $borrowerinfo->{'cardnumber'}, expiry => $expiry, diffbranch => $diffbranch, + messages => $messages, + warnings => $warnings ); } @@ -417,8 +422,7 @@ foreach my $biblionumber (@biblionumbers) { $num_available++; } elsif ( C4::Context->preference('AllowHoldPolicyOverride') ) { - -# If AllowHoldPolicyOverride is set, it should override EVERY restriction, not just branch item rules + # If AllowHoldPolicyOverride is set, it should override EVERY restriction, not just branch item rules $item->{override} = 1; $num_override++; } --