Bug 6510 - [REVISED] Sort by in intranet search alters search and number of hits
[koha.git] / members / guarantor_search.pl
blob9eb60de2cf9d0aadc0baf331c9bd173ad78b1518
1 #!/usr/bin/perl
4 # script to find a guarantor
6 # Copyright 2006 OUEST PROVENCE
8 # This file is part of Koha.
10 # Koha is free software; you can redistribute it and/or modify it under the
11 # terms of the GNU General Public License as published by the Free Software
12 # Foundation; either version 2 of the License, or (at your option) any later
13 # version.
15 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
16 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
17 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License along
20 # with Koha; if not, write to the Free Software Foundation, Inc.,
21 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 use strict;
24 #use warnings; FIXME - Bug 2505
25 use C4::Auth;
26 use C4::Output;
27 use CGI;
28 use C4::Dates qw/format_date/;
29 use C4::Members;
31 my $input = new CGI;
32 my ($template, $loggedinuser, $cookie);
34 ($template, $loggedinuser, $cookie)
35 = get_template_and_user({template_name => "members/guarantor_search.tmpl",
36 query => $input,
37 type => "intranet",
38 authnotrequired => 0,
39 flagsrequired => {borrowers => 1},
40 debug => 1,
41 });
42 # }
43 my $theme = $input->param('theme') || "default";
44 # only used if allowthemeoverride is set
47 my $member=$input->param('member');
48 my $orderby=$input->param('orderby');
49 my $category_type=$input->param('category_type');
50 $orderby = "surname,firstname" unless $orderby;
51 $member =~ s/,//g; #remove any commas from search string
52 $member =~ s/\*/%/g;
53 if ($member eq ''){
54 $template->param(results=>0);
55 }else{
56 $template->param(results=>1);
59 my $search_category = 'A';
60 if ($category_type eq 'P'){
61 $search_category = 'I';
64 my ($count,$results);
65 my @resultsdata;
66 my $background = 0;
68 if ($member ne ''){
69 if(length($member) == 1)
71 ($count,$results)=SearchMember($member,$orderby,"simple",$search_category);
73 else
75 ($count,$results)=SearchMember($member,$orderby,"advanced",$search_category);
77 for (my $i=0; $i < $count; $i++){
78 #find out stats
79 my ($od,$issue,$fines)=GetMemberIssuesAndFines($results->[$i]{'borrowerid'});
80 my $guarantorinfo=uc($results->[$i]{'surname'})." , ".ucfirst($results->[$i]{'firstname'});
81 my %row = (
82 background => $background,
83 count => $i+1,
84 borrowernumber => $results->[$i]{'borrowernumber'},
85 cardnumber => $results->[$i]{'cardnumber'},
86 surname => $results->[$i]{'surname'},
87 firstname => $results->[$i]{'firstname'},
88 categorycode => $results->[$i]{'categorycode'},
89 streetnumber => $results->[$i]{'streetnumber'},
90 address => $results->[$i]{'address'},
91 address2 => $results->[$i]{'address2'},
92 city => $results->[$i]{'city'},
93 state => $results->[$i]{'state'},
94 zipcode => $results->[$i]{'zipcode'},
95 country => $results->[$i]{'country'},
96 branchcode => $results->[$i]{'branchcode'},
97 guarantorinfo =>$guarantorinfo,
98 #op
99 dateofbirth =>format_date($results->[$i]{'dateofbirth'}),
100 #fi op
102 odissue => "$od/$issue",
103 fines => $fines,
104 borrowernotes => $results->[$i]{'borrowernotes'});
105 if ( $background ) { $background = 0; } else {$background = 1; }
106 push(@resultsdata, \%row);
109 $template->param(
110 member => $member,
111 numresults => $count,
112 category_type => $category_type,
113 resultsloop => \@resultsdata );
115 output_html_with_http_headers $input, $cookie, $template->output;