rel_3_0 moved to HEAD
[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 my $env;
61
62 my ($count,$results);
63 my @resultsdata;
64 my $background = 0;
65
66 if ($member ne ''){
67         if(length($member) == 1)
68         {
69                 ($count,$results)=GuarantornameSearch($env,$member,$orderby,"simple");
70         }
71         else
72         {
73                 ($count,$results)=GuarantornameSearch($env,$member,$orderby,"advanced");
74         }
75         for (my $i=0; $i < $count; $i++){
76         #find out stats
77         my ($od,$issue,$fines)=borrdata2($env,$results->[$i]{'borrowerid'});
78         my $guarantorinfo=uc($results->[$i]{'surname'})." , ".ucfirst($results->[$i]{'firstname'});
79         my %row = (
80                 background => $background,
81                 count => $i+1,
82                 borrowernumber => $results->[$i]{'borrowernumber'},
83                 cardnumber => $results->[$i]{'cardnumber'},
84                 surname => $results->[$i]{'surname'},
85                 firstname => $results->[$i]{'firstname'},
86                 categorycode => $results->[$i]{'categorycode'},
87                 address => $results->[$i]{'address'},
88                 city => $results->[$i]{'city'},
89                 branchcode => $results->[$i]{'branchcode'},
90                 guarantorinfo =>$guarantorinfo,
91                 #op
92                 dateofbirth =>format_date($results->[$i]{'dateofbirth'}),
93                 #fi op  
94                 
95                 odissue => "$od/$issue",
96                 fines => $fines,
97                 borrowernotes => $results->[$i]{'borrowernotes'});
98         if ( $background ) { $background = 0; } else {$background = 1; }
99         push(@resultsdata, \%row);
100                 }
101 }
102 $template->param( 
103                         member          => $member,
104                         numresults              => $count,
105                         
106                         resultsloop     => \@resultsdata );
107
108 output_html_with_http_headers $input, $cookie, $template->output;