From 3d0e729a21877348923c3969d999dcd62db0f85a Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Thu, 24 Jul 2014 13:33:06 +0200 Subject: [PATCH 2/9] Bug 12648: Refactoring to prepare user search for reuse A previous enhancement allows to link basket with patrons. Next patches will use the same way to link order with patrons. In order to avoir c/p of code, this patch refactores this part of code. Test plan: 1/ Verify there is no regression on adding/modifying users to a basket. (acqui/basket.pl?basketno=XXX, "Managed by", "Add user"). 2/ Note that you get a friendly message if the user is already present in the list and when the user has correctly been added to the list. 3/ Note that the list uses the member search service (ie. DataTable + serverside processing). Signed-off-by: Paola Rossi --- C4/Utils/DataTables/Members.pm | 6 +- acqui/add_user_search.pl | 95 ++++++++++++++++++++ acqui/aqbasketuser_search.pl | 77 ---------------- .../prog/en/modules/acqui/add_user_search.tt | 95 ++++++++++++++++++++ .../prog/en/modules/acqui/aqbasketuser_search.tt | 79 ---------------- .../intranet-tmpl/prog/en/modules/acqui/basket.tt | 32 +++---- .../en/modules/acqui/tables/members_results.tt | 21 +++++ svc/members/search | 2 +- 8 files changed, 233 insertions(+), 174 deletions(-) create mode 100755 acqui/add_user_search.pl delete mode 100755 acqui/aqbasketuser_search.pl create mode 100644 koha-tmpl/intranet-tmpl/prog/en/modules/acqui/add_user_search.tt delete mode 100644 koha-tmpl/intranet-tmpl/prog/en/modules/acqui/aqbasketuser_search.tt create mode 100644 koha-tmpl/intranet-tmpl/prog/en/modules/acqui/tables/members_results.tt diff --git a/C4/Utils/DataTables/Members.pm b/C4/Utils/DataTables/Members.pm index 95f6a82..6a97ea3 100644 --- a/C4/Utils/DataTables/Members.pm +++ b/C4/Utils/DataTables/Members.pm @@ -13,9 +13,13 @@ sub search { my $categorycode = $params->{categorycode}; my $branchcode = $params->{branchcode}; my $searchtype = $params->{searchtype}; - my $searchfieldstype = $params->{searchfieldstype}; + my $searchfieldstype = $params->{searchfieldstype} || 'standard'; my $dt_params = $params->{dt_params}; + unless ( $searchmember ) { + $searchmember = $dt_params->{sSearch}; + } + my ($iTotalRecords, $iTotalDisplayRecords); # If branches are independant and user is not superlibrarian diff --git a/acqui/add_user_search.pl b/acqui/add_user_search.pl new file mode 100755 index 0000000..ff7a579 --- /dev/null +++ b/acqui/add_user_search.pl @@ -0,0 +1,95 @@ +#!/usr/bin/perl + +# This file is part of Koha. +# +# Copyright 2014 BibLibre +# +# 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, see . + +use Modern::Perl; + +use CGI; +use C4::Auth; +use C4::Output; +use C4::Members; + +my $input = new CGI; + +my $dbh = C4::Context->dbh; + +my ( $template, $loggedinuser, $cookie, $staff_flags ) = get_template_and_user( + { template_name => "acqui/add_user_search.tt", + query => $input, + type => "intranet", + authnotrequired => 0, + flagsrequired => { acquisition => 'order_manage' }, + } +); + +my $q = $input->param('q') || ''; +my $op = $input->param('op') || ''; + +my $referer = $input->referer(); + +# If this script is called by acqui/basket.pl +# the patrons to return should be superlibrarian or have the order_manage +# acquisition flag. +my $search_patrons_with_acq_perm_only = + ( $referer =~ m|acqui/basket.pl| ) + ? 1 : 0; + +if( $op eq "do_search" ) { + my $results = C4::Members::Search( $q, "surname"); + + my @users_loop; + my $nresults = 0; + foreach my $res (@$results) { + my $should_be_returned = 1; + + if ( $search_patrons_with_acq_perm_only ) { + $should_be_returned = 0; + my $perms = haspermission( $res->{userid} ); + my $subperms = get_user_subpermissions( $res->{userid} ); + + if( $perms->{superlibrarian} == 1 + || $perms->{acquisition} == 1 + || $subperms->{acquisition}->{'order_manage'} ) { + $should_be_returned = 1; + } + } + if ( $should_be_returned ) { + my %row = ( + borrowernumber => $res->{borrowernumber}, + cardnumber => $res->{cardnumber}, + surname => $res->{surname}, + firstname => $res->{firstname}, + categorycode => $res->{categorycode}, + branchcode => $res->{branchcode}, + ); + push( @users_loop, \%row ); + $nresults ++; + } + } + + $template->param( + q => $q, + nresults => $nresults, + users_loop => \@users_loop, + ); +} + +$template->param( + patrons_with_acq_perm_only => $search_patrons_with_acq_perm_only, +); +output_html_with_http_headers( $input, $cookie, $template->output ); diff --git a/acqui/aqbasketuser_search.pl b/acqui/aqbasketuser_search.pl deleted file mode 100755 index 6c020ca..0000000 --- a/acqui/aqbasketuser_search.pl +++ /dev/null @@ -1,77 +0,0 @@ -#!/usr/bin/perl - -# script to find a basket user - -# Copyright 2012 BibLibre SARL -# -# 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 2 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::Output; -use C4::Members; - -my $input = new CGI; - -my $dbh = C4::Context->dbh; - -my ( $template, $loggedinuser, $cookie, $staff_flags ) = get_template_and_user( - { template_name => "acqui/aqbasketuser_search.tt", - query => $input, - type => "intranet", - authnotrequired => 0, - flagsrequired => { acquisition => 'order_manage' }, - } -); - -my $q = $input->param('q') || ''; -my $op = $input->param('op') || ''; - -if( $op eq "do_search" ) { - my $results = C4::Members::Search( $q, "surname"); - - my @users_loop; - my $nresults = 0; - foreach my $res (@$results) { - my $perms = haspermission( $res->{userid} ); - my $subperms = get_user_subpermissions( $res->{userid} ); - - if( $perms->{superlibrarian} == 1 - || $perms->{acquisition} == 1 - || $subperms->{acquisition}->{'order_manage'} ) { - my %row = ( - borrowernumber => $res->{borrowernumber}, - cardnumber => $res->{cardnumber}, - surname => $res->{surname}, - firstname => $res->{firstname}, - categorycode => $res->{categorycode}, - branchcode => $res->{branchcode}, - ); - push( @users_loop, \%row ); - $nresults ++; - } - } - - $template->param( - q => $q, - nresults => $nresults, - users_loop => \@users_loop, - ); -} - -output_html_with_http_headers( $input, $cookie, $template->output ); diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/add_user_search.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/add_user_search.tt new file mode 100644 index 0000000..02c8035 --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/add_user_search.tt @@ -0,0 +1,95 @@ +[% USE Koha %] +[% INCLUDE 'doc-head-open.inc' %] +Koha › Patron search +[% INCLUDE 'doc-head-close.inc' %] + +[% INCLUDE 'datatables.inc' %] + + + + + +