3 # This file is part of Koha.
5 # Copyright 2014 BibLibre
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
29 my $dbh = C4::Context->dbh;
31 my ( $template, $loggedinuser, $cookie, $staff_flags ) = get_template_and_user(
32 { template_name => "acqui/add_user_search.tt",
36 flagsrequired => { acquisition => 'order_manage' },
40 my $q = $input->param('q') || '';
41 my $op = $input->param('op') || '';
43 my $referer = $input->referer();
45 # If this script is called by acqui/basket.pl
46 # the patrons to return should be superlibrarian or have the order_manage
48 my $search_patrons_with_acq_perm_only =
49 ( $referer =~ m|acqui/basket.pl| )
52 if( $op eq "do_search" ) {
53 my $results = C4::Members::Search( $q, "surname");
57 foreach my $res (@$results) {
58 my $should_be_returned = 1;
60 if ( $search_patrons_with_acq_perm_only ) {
61 $should_be_returned = 0;
62 my $perms = haspermission( $res->{userid} );
63 my $subperms = get_user_subpermissions( $res->{userid} );
65 if( $perms->{superlibrarian} == 1
66 || $perms->{acquisition} == 1
67 || $subperms->{acquisition}->{'order_manage'} ) {
68 $should_be_returned = 1;
71 if ( $should_be_returned ) {
73 borrowernumber => $res->{borrowernumber},
74 cardnumber => $res->{cardnumber},
75 surname => $res->{surname},
76 firstname => $res->{firstname},
77 categorycode => $res->{categorycode},
78 branchcode => $res->{branchcode},
80 push( @users_loop, \%row );
87 nresults => $nresults,
88 users_loop => \@users_loop,
93 patrons_with_acq_perm_only => $search_patrons_with_acq_perm_only,
95 output_html_with_http_headers( $input, $cookie, $template->output );