Still Code Cleaning.
[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 CGI;
30 use C4::Members;
31
32
33 my $input = new CGI;
34 my $quicksearch = $input->param('quicksearch');
35 my ($template, $loggedinuser, $cookie);
36 if($quicksearch){
37     ($template, $loggedinuser, $cookie)
38     = get_template_and_user({template_name => "members/member-quicksearch-results.tmpl",
39                  query => $input,
40                  type => "intranet",
41                  authnotrequired => 0,
42                  flagsrequired => {borrowers => 1},
43                  debug => 1,
44                  });
45 } else {
46     ($template, $loggedinuser, $cookie)
47     = get_template_and_user({template_name => "members/member.tmpl",
48                  query => $input,
49                  type => "intranet",
50                  authnotrequired => 0,
51                  flagsrequired => {borrowers => 1},
52                  debug => 1,
53                  });
54 }
55 my $theme = $input->param('theme') || "default";
56             # only used if allowthemeoverride is set
57 #my %tmpldata = pathtotemplate ( template => 'member.tmpl', theme => $theme, language => 'fi' );
58     # FIXME - Error-checking
59 #my $template = HTML::Template->new( filename => $tmpldata{'path'},
60 #                   die_on_bad_params => 0,
61 #                   loop_context_vars => 1 );
62
63
64 my $member=$input->param('member');
65 my $orderby=$input->param('orderby');
66 $orderby = "surname,firstname" unless $orderby;
67 $member =~ s/,//g;   #remove any commas from search string
68 $member =~ s/\*/%/g;
69
70 my ($count,$results);
71
72 if(length($member) == 1)
73 {
74     ($count,$results)=SearchMember($member,$orderby,"simple");
75 }
76 else
77 {
78     ($count,$results)=SearchMember($member,$orderby,"advanced");
79 }
80
81
82 my @resultsdata;
83 my $background = 0;
84 for (my $i=0; $i < $count; $i++){
85   #find out stats
86   my ($od,$issue,$fines)=GetMemberIssuesAndFines($results->[$i]{'borrowernumber'});
87
88   my %row = (
89     background => $background,
90     count => $i+1,
91     borrowernumber => $results->[$i]{'borrowernumber'},
92     cardnumber => $results->[$i]{'cardnumber'},
93     surname => $results->[$i]{'surname'},
94     firstname => $results->[$i]{'firstname'},
95     categorycode => $results->[$i]{'categorycode'},
96     category_type => $results->[$i]{'category_type'},
97     category_description => $results->[$i]{'description'},
98     streetaddress => $results->[$i]{'streetaddress'},
99     city => $results->[$i]{'city'},
100     branchcode => $results->[$i]{'branchcode'},
101     overdues => $od,
102     issues => $issue,
103     odissue => "$od/$issue",
104     fines =>  sprintf("%.2f",$fines),
105     borrowernotes => $results->[$i]{'borrowernotes'},
106     sort1 => $results->[$i]{'sort1'},
107     sort2 => $results->[$i]{'sort2'},
108     );
109   if ( $background ) { $background = 0; } else {$background = 1; }
110   push(@resultsdata, \%row);
111 }
112
113 $template->param( 
114         searching       => "1",
115         member          => $member,
116         numresults      => $count,
117         resultsloop     => \@resultsdata,
118         intranetcolorstylesheet => C4::Context->preference("intranetcolorstylesheet"),
119         intranetstylesheet => C4::Context->preference("intranetstylesheet"),
120         IntranetNav => C4::Context->preference("IntranetNav"),
121             );
122
123 output_html_with_http_headers $input, $cookie, $template->output;