removing all useless %env / $env
[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 C4::Interface::CGI::Output;
28 use CGI;
29
30 #op
31 use C4::Date;
32 use C4::Members;
33
34 my $input = new CGI;
35 my ($template, $loggedinuser, $cookie);
36
37         ($template, $loggedinuser, $cookie)
38     = get_template_and_user({template_name => "members/guarantor_search.tmpl",
39                              query => $input,
40                              type => "intranet",
41                              authnotrequired => 0,
42                              flagsrequired => {borrowers => 1},
43                              debug => 1,
44                              });
45 # }
46 my $theme = $input->param('theme') || "default";
47                         # only used if allowthemeoverride is set
48
49
50 my $member=$input->param('member');
51 my $orderby=$input->param('orderby');
52 $orderby = "surname,firstname" unless $orderby;
53 $member =~ s/,//g;   #remove any commas from search string
54 $member =~ s/\*/%/g;
55 if ($member eq ''){
56                 $template->param(results=>0);
57 }else{
58                 $template->param(results=>1);
59 }       
60
61 my ($count,$results);
62 my @resultsdata;
63 my $background = 0;
64
65 if ($member ne ''){
66         if(length($member) == 1)
67         {
68                 ($count,$results)=GuarantornameSearch($member,$orderby,"simple");
69         }
70         else
71         {
72                 ($count,$results)=GuarantornameSearch($member,$orderby,"advanced");
73         }
74         for (my $i=0; $i < $count; $i++){
75         #find out stats
76         my ($od,$issue,$fines)=borrdata2($results->[$i]{'borrowerid'});
77         my $guarantorinfo=uc($results->[$i]{'surname'})." , ".ucfirst($results->[$i]{'firstname'});
78         my %row = (
79                 background => $background,
80                 count => $i+1,
81                 borrowernumber => $results->[$i]{'borrowernumber'},
82                 cardnumber => $results->[$i]{'cardnumber'},
83                 surname => $results->[$i]{'surname'},
84                 firstname => $results->[$i]{'firstname'},
85                 categorycode => $results->[$i]{'categorycode'},
86                 address => $results->[$i]{'address'},
87                 city => $results->[$i]{'city'},
88                 branchcode => $results->[$i]{'branchcode'},
89                 guarantorinfo =>$guarantorinfo,
90                 #op
91                 dateofbirth =>format_date($results->[$i]{'dateofbirth'}),
92                 #fi op  
93                 
94                 odissue => "$od/$issue",
95                 fines => $fines,
96                 borrowernotes => $results->[$i]{'borrowernotes'});
97         if ( $background ) { $background = 0; } else {$background = 1; }
98         push(@resultsdata, \%row);
99                 }
100 }
101 $template->param( 
102                         member          => $member,
103                         numresults              => $count,
104                         
105                         resultsloop     => \@resultsdata );
106
107 output_html_with_http_headers $input, $cookie, $template->output;