rel_3_0 moved to HEAD
[koha.git] / members / member.pl
1 #!/usr/bin/perl
2
3 # $Id$
4
5 #script to do a borrower enquiery/brin up borrower details etc
6 #written 20/12/99 by chris@katipo.co.nz
7
8
9 # Copyright 2000-2002 Katipo Communications
10 #
11 # This file is part of Koha.
12 #
13 # Koha is free software; you can redistribute it and/or modify it under the
14 # terms of the GNU General Public License as published by the Free Software
15 # Foundation; either version 2 of the License, or (at your option) any later
16 # version.
17 #
18 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
19 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
20 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
21 #
22 # You should have received a copy of the GNU General Public License along with
23 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
24 # Suite 330, Boston, MA  02111-1307 USA
25
26 use strict;
27 use C4::Auth;
28 use C4::Output;
29 use C4::Interface::CGI::Output;
30 use CGI;
31 use C4::Members;
32
33
34 my $input = new CGI;
35 my $quicksearch = $input->param('quicksearch');
36 my ($template, $loggedinuser, $cookie);
37 if($quicksearch){
38         ($template, $loggedinuser, $cookie)
39     = get_template_and_user({template_name => "members/member-quicksearch-results.tmpl",
40                              query => $input,
41                              type => "intranet",
42                              authnotrequired => 0,
43                              flagsrequired => {borrowers => 1},
44                              debug => 1,
45                              });
46 } else {
47         ($template, $loggedinuser, $cookie)
48     = get_template_and_user({template_name => "members/member.tmpl",
49                              query => $input,
50                              type => "intranet",
51                              authnotrequired => 0,
52                              flagsrequired => {borrowers => 1},
53                              debug => 1,
54                              });
55 }
56 my $theme = $input->param('theme') || "default";
57                         # only used if allowthemeoverride is set
58 #my %tmpldata = pathtotemplate ( template => 'member.tmpl', theme => $theme, language => 'fi' );
59         # FIXME - Error-checking
60 #my $template = HTML::Template->new( filename => $tmpldata{'path'},
61 #                                   die_on_bad_params => 0,
62 #                                   loop_context_vars => 1 );
63
64
65 my $member=$input->param('member');
66 my $orderby=$input->param('orderby');
67 $orderby = "surname,firstname" unless $orderby;
68 $member =~ s/,//g;   #remove any commas from search string
69 $member =~ s/\*/%/g;
70 my $env;
71
72 my ($count,$results);
73
74 if(length($member) == 1)
75 {
76         ($count,$results)=BornameSearch($env,$member,$orderby,"simple");
77 }
78 else
79 {
80         ($count,$results)=BornameSearch($env,$member,$orderby,"advanced");
81 }
82
83
84 my @resultsdata;
85 my $background = 0;
86 for (my $i=0; $i < $count; $i++){
87   #find out stats
88   my ($od,$issue,$fines)=borrdata2($env,$results->[$i]{'borrowernumber'});
89
90   my %row = (
91         background => $background,
92         count => $i+1,
93         borrowernumber => $results->[$i]{'borrowernumber'},
94         cardnumber => $results->[$i]{'cardnumber'},
95         surname => $results->[$i]{'surname'},
96         firstname => $results->[$i]{'firstname'},
97         categorycode => $results->[$i]{'categorycode'},
98         category_type => $results->[$i]{'category_type'},
99         category_description => $results->[$i]{'description'},
100         streetaddress => $results->[$i]{'streetaddress'},
101         city => $results->[$i]{'city'},
102         branchcode => $results->[$i]{'branchcode'},
103                 overdues => $od,
104                 issues => $issue,
105         odissue => "$od/$issue",
106         fines =>  sprintf("%.2f",$fines),
107         borrowernotes => $results->[$i]{'borrowernotes'},
108         sort1 => $results->[$i]{'sort1'},
109         sort2 => $results->[$i]{'sort2'},
110         );
111   if ( $background ) { $background = 0; } else {$background = 1; }
112   push(@resultsdata, \%row);
113 }
114
115 $template->param( 
116                         member          => $member,
117                         numresults              => $count,
118                         resultsloop     => \@resultsdata,
119                         intranetcolorstylesheet => C4::Context->preference("intranetcolorstylesheet"),
120                 intranetstylesheet => C4::Context->preference("intranetstylesheet"),
121                 IntranetNav => C4::Context->preference("IntranetNav"),
122                         );
123
124 output_html_with_http_headers $input, $cookie, $template->output;