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