C4/External/BakerTaylor.pm - Back end for B&T content.
[koha.git] / labels / pcard-member-search.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 $batch_id    = $input->param('batch_id');
34 my $batch_type  = $input->param('type');
35
36 warn "Passed Batch Id: $batch_id and Type: $batch_type";
37
38 my $quicksearch = $input->param('quicksearch');
39 my $startfrom = $input->param('startfrom')||1;
40 my $resultsperpage = $input->param('resultsperpage')||C4::Context->preference("PatronsPerPage")||20;
41
42 my ($template, $loggedinuser, $cookie);
43 if($quicksearch){
44     ($template, $loggedinuser, $cookie)
45     = get_template_and_user({template_name => "members/member-quicksearch-results.tmpl",
46                  query => $input,
47                  type => "intranet",
48                  authnotrequired => 0,
49                  flagsrequired => {borrowers => 1},
50                  debug => 1,
51                  });
52 } else {
53     ($template, $loggedinuser, $cookie)
54     = get_template_and_user({template_name => "labels/pcard-members-search.tmpl",
55                  query => $input,
56                  type => "intranet",
57                  authnotrequired => 0,
58                  flagsrequired => {borrowers => 1},
59                  debug => 1,
60                  });
61 }
62 my $theme = $input->param('theme') || "default";
63             # only used if allowthemeoverride is set
64 #my %tmpldata = pathtotemplate ( template => 'member.tmpl', theme => $theme, language => 'fi' );
65     # FIXME - Error-checking
66 #my $template = HTML::Template->new( filename => $tmpldata{'path'},
67 #                   die_on_bad_params => 0,
68 #                   loop_context_vars => 1 );
69
70
71 my $member=$input->param('member');
72 my $orderby=$input->param('orderby');
73 $orderby = "surname,firstname" unless $orderby;
74 $member =~ s/,//g;   #remove any commas from search string
75 $member =~ s/\*/%/g;
76
77 unless ($member) {
78     $template->param( batch_id => $batch_id, type => $batch_type,);
79     output_html_with_http_headers $input, $cookie, $template->output;
80     exit;
81 }
82
83 my ($count,$results);
84
85 if(length($member) == 1)
86 {
87     ($count,$results)=SearchMember($member,$orderby,"simple");
88 }
89 else
90 {
91     ($count,$results)=SearchMember($member,$orderby,"advanced");
92 }
93
94
95 my @resultsdata;
96 my $toggle = 0;
97 my $to=($count>($startfrom*$resultsperpage)?$startfrom*$resultsperpage:$count);
98 for (my $i=($startfrom-1)*$resultsperpage; $i < $to; $i++){
99   #find out stats
100   my ($od,$issue,$fines)=GetMemberIssuesAndFines($results->[$i]{'borrowernumber'});
101
102   my %row = (
103     toggle => $toggle,
104     count => $i+1,
105     borrowernumber => $results->[$i]{'borrowernumber'},
106     cardnumber => $results->[$i]{'cardnumber'},
107     surname => $results->[$i]{'surname'},
108     firstname => $results->[$i]{'firstname'},
109     categorycode => $results->[$i]{'categorycode'},
110     category_type => $results->[$i]{'category_type'},
111     category_description => $results->[$i]{'description'},
112     address => $results->[$i]{'address'},
113         address2 => $results->[$i]{'address2'},
114     city => $results->[$i]{'city'},
115         zipcode => $results->[$i]{'zipcode'},
116     branchcode => $results->[$i]{'branchcode'},
117     overdues => $od,
118     issues => $issue,
119     odissue => "$od/$issue",
120     fines =>  sprintf("%.2f",$fines),
121     borrowernotes => $results->[$i]{'borrowernotes'},
122     sort1 => $results->[$i]{'sort1'},
123     sort2 => $results->[$i]{'sort2'},
124     dateexpiry => C4::Dates->new($results->[$i]{'dateexpiry'},'iso')->output('syspref'),
125     );
126   if ( $toggle ) { $toggle = 0; } else {$toggle = 1; }
127   push(@resultsdata, \%row);
128 }
129 my $base_url =
130     'member.pl?&amp;'
131   . join(
132     '&amp;',
133     map { $_->{term} . '=' . $_->{val} } (
134         { term => 'member', val => $member},
135         { term => 'orderby', val => $orderby },
136         { term => 'resultsperpage', val => $resultsperpage },
137         { term => 'type',           val => 'intranet' },
138     )
139   );
140
141 $template->param(
142     paginationbar => pagination_bar(
143         $base_url,  int( $count / $resultsperpage ) + 1,
144         $startfrom, 'startfrom'
145     ),
146     startfrom => $startfrom,
147     from      => ($startfrom-1)*$resultsperpage+1,  
148     to        => $to,
149     multipage => ($count != $to || $startfrom!=1),
150 );
151
152 $template->param( 
153         searching       => "1",
154         member          => $member,
155         numresults      => $count,
156         resultsloop     => \@resultsdata,
157         batch_id        => $batch_id,
158         type            => $batch_type,
159             );
160
161 output_html_with_http_headers $input, $cookie, $template->output;