From c7ac3c060c3b8952395050478c24d808ce11cd72 Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Thu, 23 Feb 2012 08:39:05 -0500 Subject: [PATCH] Bug 4045 - No check for maximum number of allowed holds. Re-add the system preference maxreserves. All the code using maxreserves is still in place. Though it is not used in the Reserves module, it is used in all the scripts where holds are placed. Also adds a check so that a borrower cannot exceed the maximum number of allowed holds by using the multi-hold feature via the opac. Test Plan: 1) Apply this patch 2) Run updatedatabase 3) Set maxreserves to 3 4) Log into the opac as a patron 5) Place 3 holds 6) Attempt to place a 4th hold 7) Note you get an error message and cannot place a forth hold 8) Delete two of those holds 9) Attempt to place 3 or more holds as a multi-hold 10) You should see a warning that you cannot place this many holds 11) Try to anyway 12) You should see an alert to tell you to reduce the number of holds you are placing. 13) Reduce the number for holds you are placing to 2 14) Your holds should now be placed --- 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-tmpl/prog/en/modules/opac-reserve.tt | 15 ++++++++ opac/opac-reserve.pl | 38 ++++++++++++------- reserve/request.pl | 14 +++++--- 6 files changed, 81 insertions(+), 20 deletions(-) diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index 01472d7..23a2ef6 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/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) diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-reserve.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-reserve.tt index 0ed677b..c5d0bcd 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-reserve.tt +++ b/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(_("You cannot place this many new holds. Please reduce the number of selected holds to %s holds").format([% new_reserves_allowed %])); + return false; + } + [% END %] + if ($(".confirmjs:checked").size() == 0) { alert(MSG_NO_RECORD_SELECTED); return false; diff --git a/koha-tmpl/opac-tmpl/bootstrap/js/global.js b/koha-tmpl/opac-tmpl/bootstrap/js/global.js index 5342113..402026a 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/js/global.js +++ b/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); -} \ No newline at end of file +} diff --git a/koha-tmpl/opac-tmpl/prog/en/modules/opac-reserve.tt b/koha-tmpl/opac-tmpl/prog/en/modules/opac-reserve.tt index d846355..a5b28c4 100644 --- a/koha-tmpl/opac-tmpl/prog/en/modules/opac-reserve.tt +++ b/koha-tmpl/opac-tmpl/prog/en/modules/opac-reserve.tt @@ -7,10 +7,13 @@