Added offline circ sqlite database generator.
[koha.git] / labels / pcard-member-search.pl
blob63a4c51422f4f86b67404f2b59ecc5254edb812c
1 #!/usr/bin/perl
4 #script to do a borrower enquiry/bring up borrower details etc
5 #written 20/12/99 by chris@katipo.co.nz
8 # Copyright 2000-2002 Katipo Communications
10 # This file is part of Koha.
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.
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.
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
25 use strict;
26 use C4::Auth;
27 use C4::Output;
28 use CGI;
29 use C4::Members;
30 use C4::Debug;
33 my $input = new CGI;
34 my $batch_id = $input->param('batch_id');
35 my $batch_type = $input->param('type');
37 $debug and warn "[In pcard-member-search] Batch Id: $batch_id, and Type: $batch_type";
39 my $quicksearch = $input->param('quicksearch');
40 my $startfrom = $input->param('startfrom')||1;
41 my $resultsperpage = $input->param('resultsperpage')||C4::Context->preference("PatronsPerPage")||20;
43 my ($template, $loggedinuser, $cookie);
44 if($quicksearch){
45 ($template, $loggedinuser, $cookie)
46 = get_template_and_user({template_name => "members/member-quicksearch-results.tmpl", # FIXME: template doesn't exist
47 query => $input,
48 type => "intranet",
49 authnotrequired => 0,
50 flagsrequired => {borrowers => 1},
51 debug => 1,
52 });
53 } else {
54 ($template, $loggedinuser, $cookie)
55 = get_template_and_user({template_name => "labels/pcard-members-search.tmpl",
56 query => $input,
57 type => "intranet",
58 authnotrequired => 0,
59 flagsrequired => {borrowers => 1},
60 debug => 1,
61 });
63 my $theme = $input->param('theme') || "default";
64 # only used if allowthemeoverride is set
65 #my %tmpldata = pathtotemplate ( template => 'member.tmpl', theme => $theme, language => 'fi' );
66 # FIXME - Error-checking
67 #my $template = HTML::Template->new( filename => $tmpldata{'path'},
68 # die_on_bad_params => 0,
69 # loop_context_vars => 1 );
72 my $member=$input->param('member');
73 my $orderby=$input->param('orderby');
74 $orderby = "surname,firstname" unless $orderby;
75 $member =~ s/,//g; #remove any commas from search string
76 $member =~ s/\*/%/g;
78 unless ($member) {
79 $template->param( batch_id => $batch_id, type => $batch_type,);
80 output_html_with_http_headers $input, $cookie, $template->output;
81 exit;
84 my ($count,$results);
86 if(length($member) == 1)
88 ($count,$results)=SearchMember($member,$orderby,"simple");
90 else
92 ($count,$results)=SearchMember($member,$orderby,"advanced");
96 my @resultsdata;
97 my $toggle = 0;
98 my $to=($count>($startfrom*$resultsperpage)?$startfrom*$resultsperpage:$count);
99 for (my $i=($startfrom-1)*$resultsperpage; $i < $to; $i++){
100 #find out stats
101 my ($od,$issue,$fines)=GetMemberIssuesAndFines($results->[$i]{'borrowernumber'});
103 my %row = (
104 toggle => $toggle,
105 count => $i+1,
106 borrowernumber => $results->[$i]{'borrowernumber'},
107 cardnumber => $results->[$i]{'cardnumber'},
108 surname => $results->[$i]{'surname'},
109 firstname => $results->[$i]{'firstname'},
110 categorycode => $results->[$i]{'categorycode'},
111 category_type => $results->[$i]{'category_type'},
112 category_description => $results->[$i]{'description'},
113 address => $results->[$i]{'address'},
114 address2 => $results->[$i]{'address2'},
115 city => $results->[$i]{'city'},
116 zipcode => $results->[$i]{'zipcode'},
117 branchcode => $results->[$i]{'branchcode'},
118 overdues => $od,
119 issues => $issue,
120 odissue => "$od/$issue",
121 fines => sprintf("%.2f",$fines),
122 borrowernotes => $results->[$i]{'borrowernotes'},
123 sort1 => $results->[$i]{'sort1'},
124 sort2 => $results->[$i]{'sort2'},
125 dateexpiry => C4::Dates->new($results->[$i]{'dateexpiry'},'iso')->output('syspref'),
127 if ( $toggle ) { $toggle = 0; } else {$toggle = 1; }
128 push(@resultsdata, \%row);
130 my $base_url =
131 'pcard-member-search.pl?'
132 . join(
133 '&amp;',
134 map { $_->{term} . '=' . $_->{val} } (
135 { term => 'member', val => $member },
136 { term => 'orderby', val => $orderby },
137 { term => 'resultsperpage', val => $resultsperpage },
138 { term => 'type', val => $batch_type },
139 { term => 'batch_id', val => $batch_id },
143 $template->param(
144 paginationbar => pagination_bar(
145 $base_url, int( $count / $resultsperpage ) + 1,
146 $startfrom, 'startfrom'
148 startfrom => $startfrom,
149 from => ($startfrom-1)*$resultsperpage+1,
150 to => $to,
151 multipage => ($count != $to || $startfrom!=1),
154 $template->param(
155 searching => "1",
156 member => $member,
157 numresults => $count,
158 resultsloop => \@resultsdata,
159 batch_id => $batch_id,
160 type => $batch_type,
163 output_html_with_http_headers $input, $cookie, $template->output;