Bug 7276 : Follow up, adding a sub to clear the cache
[koha.git] / patroncards / members-search.pl
1 #!/usr/bin/perl
2
3 # Copyright 2000-2002 Katipo Communications
4 #
5 # This file is part of Koha.
6 #
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 2 of the License, or (at your option) any later
10 # version.
11 #
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License along
17 # with Koha; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20 use strict;
21 use warnings;
22
23 use CGI;
24
25 use C4::Auth;
26 use C4::Output;
27 use C4::Members;
28 use C4::Debug;
29
30 my $cgi = CGI->new;
31
32 my $batch_id = $cgi->param('batch_id') || 0;
33 my $startfrom = $cgi->param('startfrom')||1;
34 my $resultsperpage = $cgi->param('resultsperpage')||C4::Context->preference("PatronsPerPage")||20;
35 my $category = $cgi->param('category') || undef;
36 my $member = $cgi->param('member') || undef;
37 my $orderby = $cgi->param('orderby') || undef;
38
39 my ($template, $loggedinuser, $cookie) = get_template_and_user({
40                 template_name => "patroncards/members-search.tmpl",
41                 query => $cgi,
42                 type => "intranet",
43                 authnotrequired => 0,
44                 flagsrequired => {borrowers => 1},
45                 debug => 1,});
46
47 $orderby = "surname,firstname" unless $orderby;
48 $member =~ s/,//g;   #remove any commas from search string
49 $member =~ s/\*/%/g;
50
51 if ($member || $category) {
52     my $results = $category ? Search({''=>$member, category_type=>$category}, $orderby)
53                             : Search($member, $orderby);
54     my $count = $results ? @$results : 0;
55
56     my @resultsdata = ();
57     my $to = ($count>($startfrom * $resultsperpage)?$startfrom * $resultsperpage:$count);
58     for (my $i = ($startfrom-1) * $resultsperpage; $i < $to; $i++){
59         #find out stats
60         my ($od,$issue,$fines) = GetMemberIssuesAndFines($results->[$i]{'borrowernumber'});
61         my %row = (
62             count               => $i + 1,
63             borrowernumber      => $results->[$i]{'borrowernumber'},
64             cardnumber          => $results->[$i]{'cardnumber'},
65             surname             => $results->[$i]{'surname'},
66             firstname           => $results->[$i]{'firstname'},
67             categorycode        => $results->[$i]{'categorycode'},
68             category_type       => $results->[$i]{'category_type'},
69             category_description        => $results->[$i]{'description'},
70             address             => $results->[$i]{'address'},
71             address2            => $results->[$i]{'address2'},
72             city                => $results->[$i]{'city'},
73             zipcode             => $results->[$i]{'zipcode'},
74             country             => $results->[$i]{'country'},
75             branchcode          => $results->[$i]{'branchcode'},
76             overdues            => $od,
77             issues              => $issue,
78             odissue             => "$od/$issue",
79             fines               => ($fines ? sprintf("%.2f",$fines) : ''),
80             borrowernotes       => $results->[$i]{'borrowernotes'},
81             sort1               => $results->[$i]{'sort1'},
82             sort2               => $results->[$i]{'sort2'},
83             dateexpiry          => C4::Dates->new($results->[$i]{'dateexpiry'},'iso')->output('syspref'),
84         );
85         push(@resultsdata, \%row);
86     }
87     my $base_url = '?' . join('&amp;', map { $_->{term} . '=' . $_->{val} } (
88                                             { term => 'member',         val => $member         },
89                                             { term => 'category',       val => $category       },
90                                             { term => 'orderby',        val => $orderby        },
91                                             { term => 'resultsperpage', val => $resultsperpage },
92                                             { term => 'batch_id',       val => $batch_id       },)
93                                         );
94     $template->param(
95         paginationbar   => pagination_bar(
96                                             $base_url,  int( $count / $resultsperpage ) + 1,
97                                             $startfrom, 'startfrom'
98                                          ),
99         startfrom       => $startfrom,
100         from            => ($startfrom-1) * $resultsperpage + 1,
101         to              => $to,
102         multipage       => ($count != $to || $startfrom != 1),
103         searching       => "1",
104         member          => $member,
105         category_type   => $category,
106         numresults      => $count,
107         resultsloop     => \@resultsdata,
108         batch_id        => $batch_id,
109     );
110 }
111 else {
112     $template->param( batch_id => $batch_id);
113 }
114
115 output_html_with_http_headers $cgi, $cookie, $template->output;
116
117 __END__
118
119 #script to do a borrower enquiry/bring up borrower details etc
120 #written 20/12/99 by chris@katipo.co.nz
121
122