Adding More filters for member.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 use C4::Branch;
31 use C4::Category;
32
33 my $input = new CGI;
34 my $quicksearch = $input->param('quicksearch');
35 my $startfrom = $input->param('startfrom')||1;
36 my $resultsperpage = $input->param('resultsperpage')||C4::Context->preference("PatronsPerPage")||20;
37
38 my ($template, $loggedinuser, $cookie);
39 if($quicksearch){
40     ($template, $loggedinuser, $cookie)
41     = get_template_and_user({template_name => "members/member-quicksearch-results.tmpl",
42                  query => $input,
43                  type => "intranet",
44                  authnotrequired => 0,
45                  flagsrequired => {borrowers => 1},
46                  debug => 1,
47                  });
48 } else {
49     ($template, $loggedinuser, $cookie)
50     = get_template_and_user({template_name => "members/member.tmpl",
51                  query => $input,
52                  type => "intranet",
53                  authnotrequired => 0,
54                  flagsrequired => {borrowers => 1},
55                  debug => 1,
56                  });
57 }
58 my $theme = $input->param('theme') || "default";
59
60
61 $template->param( 
62         "AddPatronLists_".C4::Context->preference("AddPatronLists")=> "1",
63             );
64 if (C4::Context->preference("AddPatronLists")=~/code/){
65     my $categories=GetBorrowercategoryList;
66     $categories->[0]->{'first'}=1;
67     $template->param(categories=>$categories);  
68 }  
69             # only used if allowthemeoverride is set
70 #my %tmpldata = pathtotemplate ( template => 'member.tmpl', theme => $theme, language => 'fi' );
71     # FIXME - Error-checking
72 #my $template = HTML::Template->new( filename => $tmpldata{'path'},
73 #                   die_on_bad_params => 0,
74 #                   loop_context_vars => 1 );
75
76 my $member=$input->param('member');
77 my $orderby=$input->param('orderby');
78 $orderby = "surname,firstname" unless $orderby;
79 $member =~ s/,//g;   #remove any commas from search string
80 $member =~ s/\*/%/g;
81
82 my ($count,$results);
83
84 my $patron = $input->Vars;
85 foreach (keys %$patron){
86         delete $$patron{$_} unless($$patron{$_}); 
87 }
88 ($results)=Search($patron,{surname=>1,firstname=>1}) if (keys %$patron);
89 $count =scalar(@$results);
90 use YAML;
91 warn Dump($results);
92 unless ($count){
93         if(length($member) == 1)
94         {
95                 ($count,$results)=SearchMember($member,$orderby,"simple");
96         }
97         else
98         {
99                 ($count,$results)=SearchMember($member,$orderby,"advanced");
100         }
101 }
102
103 my @resultsdata;
104 my $to=($count>($startfrom*$resultsperpage)?$startfrom*$resultsperpage:$count);
105 for (my $i=($startfrom-1)*$resultsperpage; $i < $to; $i++){
106   #find out stats
107   my ($od,$issue,$fines)=GetMemberIssuesAndFines($results->[$i]{'borrowernumber'});
108
109   $$results[$i]{'dateexpiry'}= C4::Dates->new($results->[$i]{'dateexpiry'},'iso')->output('syspref');
110
111   my %row = (
112     count => $i+1,
113         %{$results->[$i]},
114     overdues => $od,
115     issues => $issue,
116     odissue => "$od/$issue",
117     fines =>  sprintf("%.2f",$fines),
118     );
119   push(@resultsdata, \%row);
120 }
121 my $base_url =
122     'member.pl?&amp;'
123   . join(
124     '&amp;',
125     map { $_->{term} . '=' . $_->{val} } (
126         { term => 'member', val => $member},
127         { term => 'orderby', val => $orderby },
128         { term => 'resultsperpage', val => $resultsperpage },
129         { term => 'type',           val => 'intranet' },
130     )
131   );
132
133 my @categories=C4::Category->all;
134 $template->param(
135     paginationbar => pagination_bar(
136         $base_url,  int( $count / $resultsperpage ) + 1,
137         $startfrom, 'startfrom'
138     ),
139     startfrom => $startfrom,
140     from      => ($startfrom-1)*$resultsperpage+1,  
141     to        => $to,
142     multipage => ($count != $to || $startfrom!=1),
143         branchloop=>GetBranchesLoop(),
144         categoryloop=>\@categories,
145 );
146
147 $template->param( 
148         searching       => "1",
149         member          => $member,
150         numresults      => $count,
151         resultsloop     => \@resultsdata,
152             );
153
154 output_html_with_http_headers $input, $cookie, $template->output;