Bug 6536: Include SRU searching in Breeding.pm
[koha.git] / acqui / aqbasketuser_search.pl
1 #!/usr/bin/perl
2
3 # script to find a basket user
4
5 # Copyright 2012 BibLibre SARL
6 #
7 # This file is part of Koha.
8 #
9 # Koha is free software; you can redistribute it and/or modify it under the
10 # terms of the GNU General Public License as published by the Free Software
11 # Foundation; either version 2 of the License, or (at your option) any later
12 # version.
13 #
14 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
15 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
16 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License along
19 # with Koha; if not, write to the Free Software Foundation, Inc.,
20 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21
22 use Modern::Perl;
23
24 use CGI;
25 use C4::Auth;
26 use C4::Output;
27 use C4::Members;
28
29 my $input = new CGI;
30
31 my $dbh = C4::Context->dbh;
32
33 my ( $template, $loggedinuser, $cookie, $staff_flags ) = get_template_and_user(
34     {   template_name   => "acqui/aqbasketuser_search.tt",
35         query           => $input,
36         type            => "intranet",
37         authnotrequired => 0,
38         flagsrequired   => { acquisition => 'order_manage' },
39     }
40 );
41
42 my $q = $input->param('q') || '';
43 my $op = $input->param('op') || '';
44
45 if( $op eq "do_search" ) {
46     my $results = C4::Members::Search( $q, "surname");
47
48     my @users_loop;
49     my $nresults = 0;
50     foreach my $res (@$results) {
51         my $perms = haspermission( $res->{userid} );
52         my $subperms = get_user_subpermissions( $res->{userid} );
53
54         if( $perms->{superlibrarian} == 1
55          || $perms->{acquisition} == 1
56          || $subperms->{acquisition}->{'order_manage'} ) {
57             my %row = (
58                 borrowernumber  => $res->{borrowernumber},
59                 cardnumber      => $res->{cardnumber},
60                 surname         => $res->{surname},
61                 firstname       => $res->{firstname},
62                 categorycode    => $res->{categorycode},
63                 branchcode      => $res->{branchcode},
64             );
65             push( @users_loop, \%row );
66             $nresults ++;
67         }
68     }
69
70     $template->param(
71         q           => $q,
72         nresults    => $nresults,
73         users_loop  => \@users_loop,
74     );
75 }
76
77 output_html_with_http_headers( $input, $cookie, $template->output );