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.tmpl",
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("IndependantBranches")){
86 if (C4
::Context
->userenv && C4
::Context
->userenv->{flags
} % 2 !=1 && C4
::Context
->userenv->{'branch'}){
87 $$patron{branchcode
}=C4
::Context
->userenv->{'branch'};
90 $$patron{firstname
}.="\%" if ($$patron{firstname
});
91 $$patron{surname
}.="\%" if ($$patron{surname
});
94 push @searchpatron, $member if ($member);
95 push @searchpatron, $patron if ( keys %$patron );
96 my $from = ( $startfrom - 1 ) * $resultsperpage;
97 my $to = $from + $resultsperpage;
101 [ { surname
=> 0 }, { firstname
=> 0 } ],
104 [ "firstname", "surname", "email", "othernames", "cardnumber" ],
109 $count = scalar(@
$results);
112 $to=($count>$to?
$to:$count);
114 foreach my $borrower(@
$results[$from..$to-1]){
116 $borrower->{'dateexpiry'}= C4
::Dates
->new($borrower->{'dateexpiry'},'iso')->output('syspref');
117 if ($categories_dislay{$borrower->{'categorycode'}}){
121 %{$categories_dislay{$$borrower{categorycode
}}},
123 push(@resultsdata, \
%row);
126 warn $borrower->{'cardnumber'} ." has a bad category code of " . $borrower->{'categorycode'} ."\n";
129 if ($$patron{branchcode
}){
130 foreach my $branch (grep{$_->{value
} eq $$patron{branchcode
}}@
$branches){
131 $$branch{selected
}=1;
134 if ($$patron{categorycode
}){
135 foreach my $category (grep{$_->{categorycode
} eq $$patron{categorycode
}}@categories){
136 $$category{selected
}=1;
141 'orderby' => $orderby,
142 'resultsperpage' => $resultsperpage,
143 'type'=> 'intranet');
145 'member-search.pl?&'
148 map { "$_=$parameters{$_}" } (keys %parameters)
152 paginationbar
=> pagination_bar
(
153 $base_url, int( $count / $resultsperpage ) + 1,
154 $startfrom, 'startfrom'
156 startfrom
=> $startfrom,
157 from
=> ($startfrom-1)*$resultsperpage+1,
159 multipage
=> ($count != $to+1 || $startfrom!=1),
162 branchloop
=>$branches,
163 categoryloop
=>\
@categories,
169 actionname
=> basename
($0),
171 numresults
=> $count,
172 resultsloop
=> \
@resultsdata,
175 output_html_with_http_headers
$cgi, $cookie, $template->output;