bug 2263 - transfer zipcode when selecting guarantor
[wip/koha-chris_n.git] / members / guarantor_search.pl
1 #!/usr/bin/perl
2
3
4 # script to find a guarantor
5
6 # Copyright 2006 OUEST PROVENCE
7 #
8 # This file is part of Koha.
9 #
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.
14 #
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.
18 #
19 # You should have received a copy of the GNU General Public License along with
20 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
21 # Suite 330, Boston, MA  02111-1307 USA
22
23 use strict;
24 use C4::Auth;
25 use C4::Output;
26 use CGI;
27 use C4::Dates qw/format_date/;
28 use C4::Members;
29
30 my $input = new CGI;
31 my ($template, $loggedinuser, $cookie);
32
33         ($template, $loggedinuser, $cookie)
34     = get_template_and_user({template_name => "members/guarantor_search.tmpl",
35                              query => $input,
36                              type => "intranet",
37                              authnotrequired => 0,
38                              flagsrequired => {borrowers => 1},
39                              debug => 1,
40                              });
41 # }
42 my $theme = $input->param('theme') || "default";
43                         # only used if allowthemeoverride is set
44
45
46 my $member=$input->param('member');
47 my $orderby=$input->param('orderby');
48 $orderby = "surname,firstname" unless $orderby;
49 $member =~ s/,//g;   #remove any commas from search string
50 $member =~ s/\*/%/g;
51 if ($member eq ''){
52                 $template->param(results=>0);
53 }else{
54                 $template->param(results=>1);
55 }       
56
57 my ($count,$results);
58 my @resultsdata;
59 my $background = 0;
60
61 if ($member ne ''){
62         if(length($member) == 1)
63         {
64                 ($count,$results)=SearchMember($member,$orderby,"simple",'A');
65         }
66         else
67         {
68                 ($count,$results)=SearchMember($member,$orderby,"advanced",'A');
69         }
70         for (my $i=0; $i < $count; $i++){
71         #find out stats
72         my ($od,$issue,$fines)=GetMemberIssuesAndFines($results->[$i]{'borrowerid'});
73         my $guarantorinfo=uc($results->[$i]{'surname'})." , ".ucfirst($results->[$i]{'firstname'});
74         my %row = (
75                 background => $background,
76                 count => $i+1,
77                 borrowernumber => $results->[$i]{'borrowernumber'},
78                 cardnumber => $results->[$i]{'cardnumber'},
79                 surname => $results->[$i]{'surname'},
80                 firstname => $results->[$i]{'firstname'},
81                 categorycode => $results->[$i]{'categorycode'},
82                 address => $results->[$i]{'address'},
83                 city => $results->[$i]{'city'},
84                 zipcode => $results->[$i]{'zipcode'},
85                 branchcode => $results->[$i]{'branchcode'},
86                 guarantorinfo =>$guarantorinfo,
87                 #op
88                 dateofbirth =>format_date($results->[$i]{'dateofbirth'}),
89                 #fi op  
90                 
91                 odissue => "$od/$issue",
92                 fines => $fines,
93                 borrowernotes => $results->[$i]{'borrowernotes'});
94         if ( $background ) { $background = 0; } else {$background = 1; }
95         push(@resultsdata, \%row);
96                 }
97 }
98 $template->param( 
99                         member          => $member,
100                         numresults              => $count,
101                         
102                         resultsloop     => \@resultsdata );
103
104 output_html_with_http_headers $input, $cookie, $template->output;