Bug 12132: display guarantees if a patron has them, regardless of category type
[koha.git] / members / guarantor_search.pl
1 #!/usr/bin/perl
2
3 # script to find a guarantor
4
5 # Copyright 2006 OUEST PROVENCE
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
26 use C4::Auth;
27 use C4::Output;
28 use C4::Dates qw/format_date/;
29 use C4::Members;
30
31 my $input = new CGI;
32 my ( $template, $loggedinuser, $cookie );
33
34 ( $template, $loggedinuser, $cookie ) = get_template_and_user(
35     {
36         template_name   => "members/guarantor_search.tt",
37         query           => $input,
38         type            => "intranet",
39         authnotrequired => 0,
40         flagsrequired   => { borrowers => 1 },
41         debug           => 1,
42     }
43 );
44
45 my $member        = $input->param('member') // '';
46 my $orderby       = $input->param('orderby');
47 my $category_type = $input->param('category_type');
48
49 $orderby = "surname,firstname" unless $orderby;
50 $member =~ s/,//g;     #remove any commas from search string
51 $member =~ s/\*/%/g;
52
53 $template->param( results => $member );
54
55 my $search_category = 'A';
56 if ( $category_type eq 'P' ) {
57     $search_category = 'I';
58 }
59
60 my ( $count, $results );
61 my @resultsdata;
62
63 if ( $member ne '' ) {
64     $results =
65       Search( { '' => $member, category_type => $search_category }, $orderby );
66
67     $count = $results ? @$results : 0;
68
69     for ( my $i = 0 ; $i < $count ; $i++ ) {
70         my %row = (
71             count          => $i + 1,
72             borrowernumber => $results->[$i]{'borrowernumber'},
73             cardnumber     => $results->[$i]{'cardnumber'},
74             surname        => $results->[$i]{'surname'},
75             firstname      => $results->[$i]{'firstname'},
76             categorycode   => $results->[$i]{'categorycode'},
77             streetnumber   => $results->[$i]{'streetnumber'},
78             address        => $results->[$i]{'address'},
79             address2       => $results->[$i]{'address2'},
80             city           => $results->[$i]{'city'},
81             state          => $results->[$i]{'state'},
82             zipcode        => $results->[$i]{'zipcode'},
83             country        => $results->[$i]{'country'},
84             branchcode     => $results->[$i]{'branchcode'},
85             dateofbirth    => format_date( $results->[$i]{'dateofbirth'} ),
86             borrowernotes  => $results->[$i]{'borrowernotes'}
87         );
88
89         push( @resultsdata, \%row );
90     }
91 }
92
93 $template->param(
94     member        => $member,
95     numresults    => $count,
96     category_type => $category_type,
97     resultsloop   => \@resultsdata
98 );
99
100 output_html_with_http_headers $input, $cookie, $template->output;