Bug 10621: use correct from-address for subscription alert emails
[koha.git] / members / member.pl
blob47f7cb754459f18056ebb08d3379ef842fde3c12
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
9 # Copyright 2010 BibLibre
11 # This file is part of Koha.
13 # Koha is free software; you can redistribute it and/or modify it under the
14 # terms of the GNU General Public License as published by the Free Software
15 # Foundation; either version 2 of the License, or (at your option) any later
16 # version.
18 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
19 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
20 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
22 # You should have received a copy of the GNU General Public License along
23 # with Koha; if not, write to the Free Software Foundation, Inc.,
24 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 use strict;
27 #use warnings; FIXME - Bug 2505
28 use C4::Auth;
29 use C4::Output;
30 use CGI;
31 use C4::Members;
32 use C4::Branch;
33 use C4::Category;
34 use Koha::DateUtils;
35 use File::Basename;
37 my $input = new CGI;
38 my $quicksearch = $input->param('quicksearch');
39 my $startfrom = $input->param('startfrom')||1;
40 my $resultsperpage = $input->param('resultsperpage')||C4::Context->preference("PatronsPerPage")||20;
42 my ($template, $loggedinuser, $cookie)
43 = get_template_and_user({template_name => "members/member.tmpl",
44 query => $input,
45 type => "intranet",
46 authnotrequired => 0,
47 flagsrequired => {borrowers => 1},
48 });
50 my $theme = $input->param('theme') || "default";
52 my $patron = $input->Vars;
53 foreach (keys %$patron){
54 delete $$patron{$_} unless($$patron{$_});
56 my @categories=C4::Category->all;
58 my $branches = GetBranches;
59 my @branchloop;
61 foreach (sort { $branches->{$a}->{branchname} cmp $branches->{$b}->{branchname} } keys %$branches) {
62 my $selected;
63 $selected = 1 if $branches->{$_}->{branchcode} eq $$patron{branchcode};
64 my %row = ( value => $_,
65 selected => $selected,
66 branchname => $branches->{$_}->{branchname},
68 push @branchloop, \%row;
71 my %categories_dislay;
73 foreach my $category (@categories){
74 my $hash={
75 category_description=>$$category{description},
76 category_type=>$$category{category_type}
78 $categories_dislay{$$category{categorycode}} = $hash;
80 my $AddPatronLists = C4::Context->preference("AddPatronLists") || '';
81 $template->param(
82 "AddPatronLists_$AddPatronLists" => "1",
84 if ($AddPatronLists=~/code/){
85 $categories[0]->{'first'}=1;
88 my $member=$input->param('member');
89 my $orderbyparams=$input->param('orderby');
90 my @orderby;
91 if ($orderbyparams){
92 my @orderbyelt=split(/,/,$orderbyparams);
93 push @orderby, {$orderbyelt[0]=>$orderbyelt[1]||0};
95 else {
96 @orderby = ({surname=>0},{firstname=>0});
99 $member =~ s/,//g; #remove any commas from search string
100 $member =~ s/\*/%/g;
102 my $from = ( $startfrom - 1 ) * $resultsperpage;
103 my $to = $from + $resultsperpage;
105 my ($count,$results);
106 if ($member || keys %$patron) {
107 my $searchfields = $input->param('searchfields');
108 my @searchfields = $searchfields ? split( ',', $searchfields ) : ( "firstname", "surname", "othernames", "cardnumber", "userid", "email" );
110 if ( $searchfields eq "dateofbirth" ) {
111 $member = output_pref(dt_from_string($member), 'iso', undef, 1);
114 my $search_scope = ( $quicksearch ? "field_start_with" : "start_with" );
115 ($results) = Search( $member || $patron, \@orderby, undef, undef, \@searchfields, $search_scope );
118 if ($results) {
119 for my $field ('categorycode','branchcode'){
120 next unless ($patron->{$field});
121 @$results = grep { $_->{$field} eq $patron->{$field} } @$results;
123 $count = scalar(@$results);
126 if($count == 1){
127 print $input->redirect("/cgi-bin/koha/members/moremember.pl?borrowernumber=" . @$results[0]->{borrowernumber});
128 exit;
131 my @resultsdata;
132 $to=($count>$to?$to:$count);
133 my $index=$from;
134 foreach my $borrower(@$results[$from..$to-1]){
135 #find out stats
136 my ($od,$issue,$fines)=GetMemberIssuesAndFines($$borrower{'borrowernumber'});
138 $$borrower{'dateexpiry'}= C4::Dates->new($$borrower{'dateexpiry'},'iso')->output('syspref');
140 my %row = (
141 count => $index++,
142 %$borrower,
143 (defined $categories_dislay{ $borrower->{categorycode} }? %{ $categories_dislay{ $borrower->{categorycode} } }:()),
144 overdues => $od,
145 issues => $issue,
146 odissue => "$od/$issue",
147 fines => sprintf("%.2f",$fines),
148 branchname => $branches->{$borrower->{branchcode}}->{branchname},
150 push(@resultsdata, \%row);
153 if ($$patron{categorycode}){
154 foreach my $category (grep{$_->{categorycode} eq $$patron{categorycode}}@categories){
155 $$category{selected}=1;
158 my %parameters=
159 ( %$patron
160 , 'orderby' => $orderbyparams
161 , 'resultsperpage' => $resultsperpage
162 , 'type'=> 'intranet');
163 my $base_url =
164 'member.pl?&'
165 . join(
166 '&',
167 map { "$_=$parameters{$_}" } (keys %parameters)
170 my @letters = map { {letter => $_} } ( 'A' .. 'Z');
172 $template->param(
173 letters => \@letters,
174 paginationbar => pagination_bar(
175 $base_url,
176 int( $count / $resultsperpage ) + ($count % $resultsperpage ? 1 : 0),
177 $startfrom, 'startfrom'
179 startfrom => $startfrom,
180 from => ($startfrom-1)*$resultsperpage+1,
181 to => $to,
182 multipage => ($count != $to || $startfrom!=1),
183 advsearch => ($$patron{categorycode} || $$patron{branchcode}),
184 branchloop=>\@branchloop,
185 categories=>\@categories,
186 searching => "1",
187 actionname =>basename($0),
188 %$patron,
189 numresults => $count,
190 resultsloop => \@resultsdata,
193 output_html_with_http_headers $input, $cookie, $template->output;