From 892111c84d5bbfbc16b39ea93f734a200a8694f7 Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Sun, 20 Oct 2013 18:39:15 -0400 Subject: [PATCH] Bug 10694: (follow-up) fix various issues - new TT plugin for Borrowers, that at present supplies a method for determining if the patron is restricted - setting the default value of SpecifyReturnDate to false during upgrade to avoid an unwelcome surprise - validate the return date on the client side before allowing the form to be submitted. Signed-off-by: Petter Goksoyr Asen Signed-off-by: Katrin Fischer Signed-off-by: Galen Charlton --- Koha/Template/Plugin/Borrowers.pm | 58 +++++++++++++++++++ circ/returns.pl | 3 +- installer/data/mysql/updatedatabase.pl | 2 +- .../prog/en/includes/calendar.inc | 28 +++++++++ .../prog/en/modules/circ/returns.tt | 44 ++++++++++++-- 5 files changed, 129 insertions(+), 6 deletions(-) create mode 100644 Koha/Template/Plugin/Borrowers.pm diff --git a/Koha/Template/Plugin/Borrowers.pm b/Koha/Template/Plugin/Borrowers.pm new file mode 100644 index 0000000000..29a6fef09f --- /dev/null +++ b/Koha/Template/Plugin/Borrowers.pm @@ -0,0 +1,58 @@ +package Koha::Template::Plugin::Borrowers; + +# Copyright ByWater Solutions 2013 + +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3 of the License, or (at your option) any later +# version. +# +# Koha is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with Koha; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +use Modern::Perl; + +use base qw( Template::Plugin ); + +use Date::Calc qw/Today Add_Delta_YM check_date Date_to_Days/; + +use C4::Koha; + +=pod + +This plugin is a home for various patron related Template Toolkit functions +to help streamline Koha and to move logic from the Perl code into the +Templates when it makes sense to do so. + +To use, first, include the line '[% USE Borrowers %]' at the top +of the template to enable the plugin. + +For example: [% IF Borrowers.IsDebarred( borrower.borrowernumber ) %] +removes the necessity of setting a template variable in Perl code to +find out if a patron is restricted even if that variable is not evaluated +in any way in the script. + +=cut + +sub IsDebarred { + my ( $self, $borrower ) = @_; + + return unless $borrower; + + if ( $borrower->{'debarred'} && check_date( split( /-/, $borrower->{'debarred'} ) ) ) { + if ( Date_to_Days(Date::Calc::Today) < Date_to_Days( split( /-/, $borrower->{'debarred'} ) ) ) { + return 1; + } + } + + return 0; +} + +1; diff --git a/circ/returns.pl b/circ/returns.pl index 895823f40a..84ecf0e31c 100755 --- a/circ/returns.pl +++ b/circ/returns.pl @@ -274,7 +274,8 @@ if ($barcode) { itemtype => $biblio->{'itemtype'}, ccode => $biblio->{'ccode'}, itembiblionumber => $biblio->{'biblionumber'}, - additional_materials => $biblio->{'materials'} + borrower => $borrower, + additional_materials => $biblio->{'materials'}, ); my %input = ( diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index c10188d50e..9a82fab9ae 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -8350,7 +8350,7 @@ if ( CheckVersion($DBversion) ) { INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES - ('SpecifyReturnDate',1,'Define whether to display \"Specify Return Date\" form in Circulation','','YesNo') + ('SpecifyReturnDate',0,'Define whether to display \"Specify Return Date\" form in Circulation','','YesNo') }); print "Upgrade to $DBversion done (Bug 10694 - Allow arbitrary backdating of returns)\n"; SetVersion($DBversion); diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/calendar.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/calendar.inc index 13370446a3..8eb3fcb496 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/calendar.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/calendar.inc @@ -21,6 +21,34 @@ function Date_from_syspref(dstring) { } } +function DateTime_from_syspref(date_time) { + var parts = date_time.split(" "); + var date = parts[0]; + var time = parts[1]; + parts = time.split(":"); + var hour = parts[0]; + var minute = parts[1]; + + if ( hour < 0 || hour > 23 ) { + return 0; + } + if ( minute < 0 || minute > 59 ) { + return 0; + } + + var datetime = Date_from_syspref( date ); + + if ( isNaN( datetime.getTime() ) ) { + return 0; + } + + datetime.setHours( hour ); + datetime.setMinutes( minute ); + + return datetime; +} + + /* Instead of including multiple localization files as you would normally see with jQueryUI we expose the localization strings in the default configuration */ jQuery(function($){ diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/returns.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/returns.tt index 1d413b754f..895894cb9f 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/returns.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/returns.tt @@ -1,13 +1,14 @@ [% USE KohaDates %] [% USE Branches %] [% USE Koha %] +[% USE Borrowers %] [% INCLUDE 'doc-head-open.inc' %] Koha › Circulation › Check in [% title |html %] [% INCLUDE 'doc-head-close.inc' %] [% INCLUDE 'calendar.inc' %] - +