Bug 11126 [QA Followup] - Make reserves returned by _Findgroupreserve sorted by priority
[koha.git] / patroncards / members-search.pl
blob8d46417970dd554dc6a603986d42a98d8e8ec00a
1 #!/usr/bin/perl
3 # Copyright 2000-2002 Katipo Communications
5 # This file is part of Koha.
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.
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.
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.
20 use strict;
21 use warnings;
23 use CGI;
25 use C4::Auth;
26 use C4::Output;
27 use C4::Members;
28 use C4::Debug;
30 my $cgi = CGI->new;
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') || '';
37 my $orderby = $cgi->param('orderby') || undef;
39 my @categories=C4::Category->all;
40 my %categories_display;
41 my $no_categories;
43 foreach my $category (@categories) {
44 my $hash={
45 category_description=>$$category{description},
46 category_type=>$$category{category_type}
48 $categories_display{$$category{categorycode}} = $hash;
52 my ($template, $loggedinuser, $cookie) = get_template_and_user({
53 template_name => "patroncards/members-search.tt",
54 query => $cgi,
55 type => "intranet",
56 authnotrequired => 0,
57 flagsrequired => {borrowers => 1},
58 debug => 1,});
60 if(scalar(@categories) < 1){ $no_categories = 1; }
61 if($no_categories && C4::Context->preference("AddPatronLists")=~/code/){
62 $template->param(no_categories => 1);
63 } else {
64 $template->param(
65 categories=>\@categories,
66 category => $category
70 $orderby = "surname,firstname" unless $orderby;
71 $member =~ s/,//g; #remove any commas from search string
72 $member =~ s/\*/%/g;
74 if ($member || $category) {
75 my $results = $category ? Search({''=>$member, categorycode=>$category}, $orderby)
76 : Search($member, $orderby);
77 my $count = $results ? @$results : 0;
79 my @resultsdata = ();
80 my $to = ($count>($startfrom * $resultsperpage)?$startfrom * $resultsperpage:$count);
81 for (my $i = ($startfrom-1) * $resultsperpage; $i < $to; $i++){
82 #find out stats
83 my ($od,$issue,$fines) = GetMemberIssuesAndFines($results->[$i]{'borrowernumber'});
84 my %row = (
85 count => $i + 1,
86 %{$categories_display{$results->[$i]{categorycode}}},
87 borrowernumber => $results->[$i]{'borrowernumber'},
88 cardnumber => $results->[$i]{'cardnumber'},
89 surname => $results->[$i]{'surname'},
90 firstname => $results->[$i]{'firstname'},
91 categorycode => $results->[$i]{'categorycode'},
92 address => $results->[$i]{'address'},
93 address2 => $results->[$i]{'address2'},
94 city => $results->[$i]{'city'},
95 zipcode => $results->[$i]{'zipcode'},
96 country => $results->[$i]{'country'},
97 branchcode => $results->[$i]{'branchcode'},
98 overdues => $od,
99 issues => $issue,
100 odissue => "$od/$issue",
101 fines => ($fines ? sprintf("%.2f",$fines) : ''),
102 borrowernotes => $results->[$i]{'borrowernotes'},
103 sort1 => $results->[$i]{'sort1'},
104 sort2 => $results->[$i]{'sort2'},
105 dateexpiry => C4::Dates->new($results->[$i]{'dateexpiry'},'iso')->output('syspref'),
107 push(@resultsdata, \%row);
109 my $base_url = '?' . join('&amp;', map { $_->{term} . '=' . $_->{val} } (
110 { term => 'member', val => $member },
111 { term => 'category', val => $category },
112 { term => 'orderby', val => $orderby },
113 { term => 'resultsperpage', val => $resultsperpage },
114 { term => 'batch_id', val => $batch_id },)
116 $template->param(
117 paginationbar => pagination_bar(
118 $base_url, int( $count / $resultsperpage ) + 1,
119 $startfrom, 'startfrom'
121 startfrom => $startfrom,
122 from => ($startfrom-1) * $resultsperpage + 1,
123 to => $to,
124 multipage => ($count != $to || $startfrom != 1),
125 searching => "1",
126 member => $member,
127 category_type => $category,
128 numresults => $count,
129 resultsloop => \@resultsdata,
130 batch_id => $batch_id,
133 else {
134 $template->param( batch_id => $batch_id);
137 $template->param( 'alphabet' => C4::Context->preference('alphabet') || join ' ', 'A' .. 'Z' );
139 output_html_with_http_headers $cgi, $cookie, $template->output;
141 __END__
143 #script to do a borrower enquiry/bring up borrower details etc
144 #written 20/12/99 by chris@katipo.co.nz