From f7de4124ff915a188aa2ea53b99c5875ae312bfc Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Wed, 8 Jan 2014 07:58:14 -0500 Subject: [PATCH] Bug 9303 [4] [QA Followup] * Set AUTO_INCREMENT value for issues.issue_id * Undo changes to GetReserve * Add borrowerRelationship syspref check * Syspref the feature for staff * Show setting on patron details page * Allow patrons to set visibility from "your personal details" * Add system preference to control ability to set visibility from "your personal details" * Show only guarantee's checkouts to guarantor, not visa-versa --- C4/Reserves.pm | 13 +---- installer/data/mysql/sysprefs.sql | 2 + installer/data/mysql/updatedatabase.pl | 39 ++++++++++++- .../prog/en/modules/admin/preferences/opac.pref | 7 ++ .../prog/en/modules/admin/preferences/patrons.pref | 6 ++ .../prog/en/modules/members/memberentrygen.tt | 29 +++++---- .../prog/en/modules/members/moremember.tt | 10 +++ .../bootstrap/en/modules/opac-memberentry.tt | 39 +++++++++++++ .../opac-tmpl/prog/en/modules/opac-memberentry.tt | 35 +++++++++++ koha-tmpl/opac-tmpl/prog/en/modules/opac-user.tt | 2 +- members/moremember.pl | 1 + opac/opac-user.pl | 13 ++--- opac/svc/patron/show_checkouts_to_relatives | 60 ++++++++++++++++++++ 13 files changed, 220 insertions(+), 36 deletions(-) create mode 100755 opac/svc/patron/show_checkouts_to_relatives diff --git a/C4/Reserves.pm b/C4/Reserves.pm index feeb4a3..60cf031 100644 --- a/C4/Reserves.pm +++ b/C4/Reserves.pm @@ -264,18 +264,7 @@ sub GetReserve { my $query = "SELECT * FROM reserves WHERE reserve_id = ?"; my $sth = $dbh->prepare( $query ); $sth->execute( $reserve_id ); - my $res = $sth->fetchrow_hashref(); - - unless ($res) { - $query = "SELECT * FROM old_reserves WHERE reserve_id = ?"; - $sth = $dbh->prepare($query); - $sth->execute($reserve_id); - $res = $sth->fetchrow_hashref(); - } - - carp("No hold for for reserve_id $reserve_id") unless $res; - - return $res; + return $sth->fetchrow_hashref(); } =head2 GetReservesFromBiblionumber diff --git a/installer/data/mysql/sysprefs.sql b/installer/data/mysql/sysprefs.sql index 5e4ce7c..e4b08e5 100644 --- a/installer/data/mysql/sysprefs.sql +++ b/installer/data/mysql/sysprefs.sql @@ -25,11 +25,13 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` ('AllowNotForLoanOverride','0','','If ON, Koha will allow the librarian to loan a not for loan item.','YesNo'), ('AllowOfflineCirculation','0','','If on, enables HTML5 offline circulation functionality.','YesNo'), ('AllowOnShelfHolds','0','','Allow hold requests to be placed on items that are not on loan','YesNo'), +('AllowPatronToSetRelativesCheckoutsVisibility', '0', NULL, 'If enabled, the patron can set checkouts to be visible to guarantor from opac-memberentry.pl', 'YesNo'), ('AllowPKIAuth','None','None|Common Name|emailAddress','Use the field from a client-side SSL certificate to look a user in the Koha database','Choice'), ('AllowPurchaseSuggestionBranchChoice','0','1','Allow user to choose branch when making a purchase suggestion','YesNo'), ('AllowRenewalLimitOverride','0',NULL,'if ON, allows renewal limits to be overridden on the circulation screen','YesNo'), ('AllowReturnToBranch','anywhere','anywhere|homebranch|holdingbranch|homeorholdingbranch','Where an item may be returned','Choice'), ('AllowSelfCheckReturns','0','','If enabled, patrons may return items through the Web-based Self Checkout','YesNo'), +('AllowStaffToSetRelativesCheckoutsVisibility','0',NULL,'If enabled, library staff can set a patron''s checkouts to be visible to linked patrons from the opac.', 'YesNo'), ('AllowTooManyOverride','1','','If on, allow staff to override and check out items when the patron has reached the maximum number of allowed checkouts','YesNo'), ('alphabet','A B C D E F G H I J K L M N O P Q R S T U V W X Y Z',NULL,'Alphabet than can be expanded into browse links, e.g. on Home > Patrons','free'), ('AlternateHoldingsField','',NULL,'The MARC field/subfield that contains alternate holdings information for bibs taht do not have items attached (e.g. 852abchi for libraries converting from MARC Magician).','free'), diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index 6164d64..9385729 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -37,6 +37,7 @@ use Getopt::Long; use C4::Context; use C4::Installer; use C4::Dates; +use Koha::Database; use MARC::Record; use MARC::File::XML ( BinaryEncoding => 'utf8' ); @@ -8569,14 +8570,48 @@ if(CheckVersion($DBversion)) { ALTER TABLE deletedborrowers ADD privacy_relative_checkouts BOOLEAN NOT NULL DEFAULT '0' }); $dbh->do(q{ - ALTER TABLE old_issues ADD issue_id INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST + ALTER TABLE old_issues + DROP PRIMARY KEY, + ADD issue_id INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST, + DROP INDEX itemnumber_idx, + ADD UNIQUE itemnumber_idx (itemnumber); }); $dbh->do(q{ - ALTER TABLE issues ADD issue_id INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST; + ALTER TABLE issues + DROP PRIMARY KEY, + ADD issue_id INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST, + DROP INDEX itemnumber_idx, + ADD UNIQUE itemnumber_idx (itemnumber); }); $dbh->do(qq{ UPDATE issues SET issue_id = issue_id + ( SELECT COUNT(*) FROM old_issues ) ORDER BY issue_id DESC }); + + my $schema = Koha::Database->new()->schema(); + my $max_issue_id = $schema->resultset('Issue')->get_column('issue_id')->max(); + $max_issue_id ||= $schema->resultset('OldIssue')->get_column('issue_id')->max(); + $max_issue_id ||= 0; + $max_issue_id++; + $dbh->do(qq{ + ALTER TABLE issues AUTO_INCREMENT = $max_issue_id + }); + + $dbh->do(q{ + INSERT INTO systempreferences (variable, value, options, explanation, type ) + VALUES ( + 'AllowStaffToSetRelativesCheckoutsVisibility', '0', NULL, + 'If enabled, library staff can set a patron''s checkouts to be visible to linked patrons from the opac.', 'YesNo' + ) + }); + + $dbh->do(q{ + INSERT INTO systempreferences (variable, value, options, explanation, type ) + VALUES ( + 'AllowPatronToSetRelativesCheckoutsVisibility', '0', NULL, + 'If enabled, the patron can set checkouts to be visible to guarantor from opac-memberentry.pl', 'YesNo' + ) + }); + print "Upgrade to $DBversion done (Bug 9303 - relative's checkouts in the opac)\n"; SetVersion($DBversion); } diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref index 1304cef..bb26bcb 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref @@ -588,6 +588,13 @@ OPAC: no: "Don't allow" - patrons to choose their own privacy settings for their reading history. This requires opacreadinghistory and AnonymousPatron - + - pref: AllowPatronToSetRelativesCheckoutsVisibility + default: 0 + choices: + yes: Allow + no: "Don't allow" + - patrons to choose their own privacy settings for showing checkouts to relatives from "your personal details" reguardless of the setting for OPACPrivacy. + - - Use borrowernumber - pref: AnonymousPatron class: integer diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/patrons.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/patrons.pref index 2469431..8364fe0 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/patrons.pref +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/patrons.pref @@ -134,6 +134,12 @@ Patrons: no: "Don't" - enable the ability to upload and attach arbitrary files to a borrower record. - + - pref: AllowStaffToSetRelativesCheckoutsVisibility + choices: + yes: Allow + no: "Don't allow" + - staff to set the ability for a patron's checkouts to be viewed by linked patrons in the OPAC. + - - Card numbers for patrons must be - pref: CardnumberLength - "characters long. The length can be a single number to specify an exact length, a range separated by a comma (i.e., 'Min,Max'), or a maximum with no minimum (i.e., ',Max')." diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt index 414b552..10cb802 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt @@ -1,5 +1,6 @@ [% IF ( opduplicate ) %][% SET focusAction = "clearDupe" %][% END %] [% USE KohaDates %] +[% USE Koha %] [% INCLUDE 'doc-head-open.inc' %] Koha › Patrons › [% IF ( opadd ) %]Add[% ELSIF ( opduplicate ) %]Duplicate[% ELSE %] Modify[% END %] [% IF ( categoryname ) %] [% categoryname %] patron[% ELSE %][% IF ( I ) %] Organization patron[% END %][% IF ( A ) %] Adult patron[% END %][% IF ( C ) %] Child patron[% END %][% IF ( P ) %] Professional patron[% END %][% IF ( S ) %] Staff patron[% END %][% END %][% UNLESS ( opadd ) %] [% surname %], [% firstname %][% END %] @@ -1170,19 +1171,21 @@ [% END %] [% IF ( mandatorypassword ) %]Required[% END %][% IF ( ERROR_password_mismatch ) %]Passwords do not match[% END %] -
  • - - -
    Allow linked patron accounts to view this patron's checkouts from the OPAC
    -
  • + [% IF Koha.Preference('AllowStaffToSetRelativesCheckoutsVisibility') %] +
  • + + +
    Allow linked patron accounts to view this patron's checkouts from the OPAC
    +
  • + [% END %] [% END # hide fieldset %][% END %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember.tt index 345c728..e72c281 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember.tt @@ -372,6 +372,16 @@ function validate1(date) { [% IF ( privacy1 ) %]Default[% END %] [% IF ( privacy2 ) %]Never[% END %] [% END %] + +
  • + Show checkouts to relatives + [% IF privacy_relative_checkouts %] + Yes + [% ELSE %] + No + [% END %] +
  • + [% IF ( sort1 ) %]
  • Sort field 1:[% lib1 %]
  • [% END %] [% IF ( sort2 ) %]
  • Sort field 2:[% lib2 %]
  • [% END %]
  • Username: [% userid %]
  • diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-memberentry.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-memberentry.tt index 4417171..c3b29cc 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-memberentry.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-memberentry.tt @@ -54,6 +54,29 @@
    You typed in the wrong characters in the box before submitting. Please try again.
    [% END %] + [% IF Koha.Preference('AllowPatronToSetRelativesCheckoutsVisibility') %] +
    + Privacy +
      +
    1. + + + + Update + + +
    2. +
    +
    + [% END %] +
    [% UNLESS hidden.defined('branchcode') %] @@ -777,6 +800,22 @@ [% ELSE %] $( "#borrower_dateofbirth" ).datepicker({ yearRange: "c-120:c" }); [% END %] + + [% IF Koha.Preference('AllowPatronToSetRelativesCheckoutsVisibility') %] + $('#update_privacy_relative_checkouts').click( function() { + $.post( "/cgi-bin/koha/svc/patron/show_checkouts_to_relatives", { privacy_relative_checkouts: $('#privacy_relative_checkouts').val() }) + .done(function( data ) { + var message; + if ( data.success ) { + message = _("Your setting has been updated!"); + } else { + message = _("Unable to update your setting!"); + } + + $('#update_privacy_relative_checkouts_message').fadeIn("slow").text( message ).delay( 5000 ).fadeOut("slow"); + }); + }); + [% END %] }); //]]> diff --git a/koha-tmpl/opac-tmpl/prog/en/modules/opac-memberentry.tt b/koha-tmpl/opac-tmpl/prog/en/modules/opac-memberentry.tt index 0e21010..d35706a 100644 --- a/koha-tmpl/opac-tmpl/prog/en/modules/opac-memberentry.tt +++ b/koha-tmpl/opac-tmpl/prog/en/modules/opac-memberentry.tt @@ -20,6 +20,20 @@ [% ELSE %] $( "#borrower_dateofbirth" ).datepicker({ yearRange: "c-120:c" }); [% END %] + + $('#update_privacy_relative_checkouts').click( function() { + $.post( "/cgi-bin/koha/svc/patron/show_checkouts_to_relatives", { privacy_relative_checkouts: $('#privacy_relative_checkouts').val() }) + .done(function( data ) { + var message; + if ( data.success ) { + message = _("Your setting has been updated!"); + } else { + message = _("Unable to update your setting!"); + } + + $('#update_privacy_relative_checkouts_message').fadeIn("slow").text( message ).delay( 5000 ).fadeOut("slow"); + }); + }); }); //]]> @@ -62,6 +76,27 @@
    You typed in the wrong characters in the box before submitting. Please try again.
    [% END %] +
    + Privacy +
      +
    1. + + + + + + +
    2. +
    +
    + [% UNLESS hidden.defined('branchcode') %] diff --git a/koha-tmpl/opac-tmpl/prog/en/modules/opac-user.tt b/koha-tmpl/opac-tmpl/prog/en/modules/opac-user.tt index 4879af5..65bf175 100644 --- a/koha-tmpl/opac-tmpl/prog/en/modules/opac-user.tt +++ b/koha-tmpl/opac-tmpl/prog/en/modules/opac-user.tt @@ -327,7 +327,7 @@ var MSG_CONFIRM_RESUME_HOLDS = _("Are you sure you want to resume all suspended [% END %] [% END %] - [% IF relatives %] + [% IF relatives && Koha.Preference('borrowerRelationship') %]
    diff --git a/members/moremember.pl b/members/moremember.pl index 4f77854..9e81eb7 100755 --- a/members/moremember.pl +++ b/members/moremember.pl @@ -444,6 +444,7 @@ $template->param( # reserveloop => \@reservedata, samebranch => $samebranch, quickslip => $quickslip, + privacy_relative_checkouts => $data->{'privacy_relative_checkouts'}, activeBorrowerRelationship => (C4::Context->preference('borrowerRelationship') ne ''), AutoResumeSuspendedHolds => C4::Context->preference('AutoResumeSuspendedHolds'), SuspendHoldsIntranet => C4::Context->preference('SuspendHoldsIntranet'), diff --git a/opac/opac-user.pl b/opac/opac-user.pl index 48d905c..67ee4f8 100755 --- a/opac/opac-user.pl +++ b/opac/opac-user.pl @@ -374,14 +374,11 @@ if ( $borr->{'opacnote'} ) { ); } -my @borrowernumbers = GetMemberRelatives($borrowernumber); -if ( @borrowernumbers ) { - my @relatives = Koha::Database->new()->schema()->resultset("Borrower")->search( - { privacy_relative_checkouts => 1, 'me.borrowernumber' => { -in => \@borrowernumbers, } }, - { prefetch => [ { 'issues' => { 'item' => 'biblio' } } ] } - ); - $template->param( relatives => \@relatives ); -} +my @relatives = Koha::Database->new()->schema()->resultset("Borrower")->search( + {privacy_relative_checkouts => 1, 'me.guarantorid' => $borrowernumber }, + { prefetch => [ { 'issues' => { 'item' => 'biblio' } } ] } +); +$template->param( relatives => \@relatives ); $template->param( borrower => $borr, diff --git a/opac/svc/patron/show_checkouts_to_relatives b/opac/svc/patron/show_checkouts_to_relatives new file mode 100755 index 0000000..8e26c52 --- /dev/null +++ b/opac/svc/patron/show_checkouts_to_relatives @@ -0,0 +1,60 @@ +#!/usr/bin/perl + +# Copyright 2014 ByWater Solutions +# +# 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 CGI; + +use C4::Auth; +use C4::Context; +use Koha::Database; + +use JSON qw( to_json ); + +my $cgi = CGI->new(); + +my $privacy_relative_checkouts = $cgi->param('privacy_relative_checkouts'); + +my ( $userid, $cookie, $sessionID, $flags ) = checkauth( $cgi, 1, {}, 'opac' ); + +my $borrowernumber = + C4::Context->userenv ? C4::Context->userenv->{number} : undef; + +my $success = 0; +if ( $borrowernumber && defined($privacy_relative_checkouts) ) { + my $patron = + Koha::Database->new()->schema()->resultset('Borrower') + ->find($borrowernumber); + + $success = $patron->update( + { privacy_relative_checkouts => $privacy_relative_checkouts } ); +} + +binmode STDOUT, ":encoding(UTF-8)"; +print $cgi->header( + -type => 'application/json', + -charset => 'UTF-8' +); + +print to_json( + { + success => $success ? 1 : 0, + privacy_relative_checkouts => $privacy_relative_checkouts, + } +); -- 1.7.2.5