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