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