3 # Parts copyright Catalyst IT 2010
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
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 =head1 member-search.pl
22 Member Search.pl script used to search for members to add to a routing list
29 use C4
::Auth
; # get_template_and_user
31 use C4
::Members
; # BornameSearch
37 my $theme = $cgi->param('theme') || "default";
38 my $resultsperpage = $cgi->param('resultsperpage')||C4
::Context
->preference("PatronsPerPage")||20;
39 my $startfrom = $cgi->param('startfrom')||1;
41 my $patron = $cgi->Vars;
42 foreach (keys %$patron){
43 delete $$patron{$_} unless($$patron{$_});
46 my @categories=C4
::Category
->all;
47 my $branches=(defined $$patron{branchcode
}?GetBranchesLoop
($$patron{branchcode
}):GetBranchesLoop
());
48 my $subscriptionid = $cgi->param('subscriptionid');
49 my $searchstring = $cgi->param('member');
51 my %categories_dislay;
52 my ($template, $loggedinuser, $cookie);
53 ($template, $loggedinuser, $cookie)
54 = get_template_and_user
({template_name
=> "serials/member-search.tt",
58 flagsrequired
=> { serials
=> 'routing' },
61 foreach my $category (@categories){
63 category_description
=>$$category{description
},
64 category_type
=>$$category{category_type
}
66 $categories_dislay{$$category{categorycode
}} = $hash;
69 "AddPatronLists_".C4
::Context
->preference("AddPatronLists")=> "1",
71 if (C4
::Context
->preference("AddPatronLists")=~/code/){
72 $categories[0]->{'first'}=1;
75 my $member=$cgi->param('member');
76 my $orderby=$cgi->param('orderby');
77 $orderby = "surname,firstname" unless $orderby;
78 if (defined $member) {
79 $member =~ s/,//g; #remove any commas from search string
85 if ( C4
::Context
->preference("IndependentBranches") ) {
86 if ( C4
::Context
->userenv
87 && !C4
::Context
->IsSuperLibrarian()
88 && C4
::Context
->userenv->{'branch'} )
90 $$patron{branchcode
} = C4
::Context
->userenv->{'branch'};
93 $$patron{firstname
}.="\%" if ($$patron{firstname
});
94 $$patron{surname
}.="\%" if ($$patron{surname
});
97 push @searchpatron, $member if ($member);
98 push @searchpatron, $patron if ( keys %$patron );
99 my $from = ( $startfrom - 1 ) * $resultsperpage;
100 my $to = $from + $resultsperpage;
104 [ { surname
=> 0 }, { firstname
=> 0 } ],
107 [ "firstname", "surname", "email", "othernames", "cardnumber" ],
112 $count = scalar(@
$results);
115 $to=($count>$to?
$to:$count);
117 foreach my $borrower(@
$results[$from..$to-1]){
119 $borrower->{'dateexpiry'}= C4
::Dates
->new($borrower->{'dateexpiry'},'iso')->output('syspref');
120 if ($categories_dislay{$borrower->{'categorycode'}}){
124 %{$categories_dislay{$$borrower{categorycode
}}},
126 push(@resultsdata, \
%row);
129 warn $borrower->{'cardnumber'} ." has a bad category code of " . $borrower->{'categorycode'} ."\n";
132 if ($$patron{branchcode
}){
133 foreach my $branch (grep{$_->{value
} eq $$patron{branchcode
}}@
$branches){
134 $$branch{selected
}=1;
137 if ($$patron{categorycode
}){
138 foreach my $category (grep{$_->{categorycode
} eq $$patron{categorycode
}}@categories){
139 $$category{selected
}=1;
144 'orderby' => $orderby,
145 'resultsperpage' => $resultsperpage,
146 'type'=> 'intranet');
148 'member-search.pl?&'
151 map { "$_=$parameters{$_}" } (keys %parameters)
155 paginationbar
=> pagination_bar
(
156 $base_url, int( $count / $resultsperpage ) + 1,
157 $startfrom, 'startfrom'
159 startfrom
=> $startfrom,
160 from
=> ($startfrom-1)*$resultsperpage+1,
162 multipage
=> ($count != $to+1 || $startfrom!=1),
165 branchloop
=>$branches,
166 categoryloop
=>\
@categories,
172 actionname
=> basename
($0),
174 numresults
=> $count,
175 resultsloop
=> \
@resultsdata,
178 output_html_with_http_headers
$cgi, $cookie, $template->output;