Bug 3814: SIP2 Server logging doesn't work on OpenSolaris
[koha.git] / serials / member-search.pl
blob6e26a0727d3b54b007a38f6cfe3141e126bbff14
1 #!/usr/bin/perl
3 # This file is part of Koha.
5 # Koha is free software; you can redistribute it and/or modify it under the
6 # terms of the GNU General Public License as published by the Free Software
7 # Foundation; either version 2 of the License, or (at your option) any later
8 # version.
10 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
11 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License along with
15 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
16 # Suite 330, Boston, MA 02111-1307 USA
18 =head1 member-search.pl
20 Member Search.pl script used to search for members to add to a routing list
22 =cut
24 use strict;
25 use warnings;
26 use CGI;
27 use C4::Auth; # get_template_and_user
28 use C4::Output;
29 use C4::Members; # BornameSearch
30 use C4::Branch;
31 use C4::Category;
32 use File::Basename;
34 my $cgi = new CGI;
35 my $theme = $cgi->param('theme') || "default";
36 my $resultsperpage = $cgi->param('resultsperpage')||C4::Context->preference("PatronsPerPage")||20;
37 my $startfrom = $cgi->param('startfrom')||1;
39 my $patron = $cgi->Vars;
40 foreach (keys %$patron){
41 delete $$patron{$_} unless($$patron{$_});
44 my @categories=C4::Category->all;
45 my $branches=(defined $$patron{branchcode}?GetBranchesLoop($$patron{branchcode}):GetBranchesLoop());
47 my %categories_dislay;
48 my ($template, $loggedinuser, $cookie);
49 ($template, $loggedinuser, $cookie)
50 = get_template_and_user({template_name => "serials/member-search.tmpl",
51 query => $cgi,
52 type => "intranet",
53 authnotrequired => 0,
54 flagsrequired => {borrowers => 1},
55 });
57 foreach my $category (@categories){
58 my $hash={
59 category_description=>$$category{description},
60 category_type=>$$category{category_type}
62 $categories_dislay{$$category{categorycode}} = $hash;
64 $template->param(
65 "AddPatronLists_".C4::Context->preference("AddPatronLists")=> "1",
67 if (C4::Context->preference("AddPatronLists")=~/code/){
68 $categories[0]->{'first'}=1;
71 my $member=$cgi->param('member');
72 my $orderby=$cgi->param('orderby');
73 $orderby = "surname,firstname" unless $orderby;
74 $member =~ s/,//g; #remove any commas from search string
75 $member =~ s/\*/%/g;
77 my ($count,$results);
79 if (C4::Context->preference("IndependantBranches")){
80 if (C4::Context->userenv && C4::Context->userenv->{flags} % 2 !=1 && C4::Context->userenv->{'branch'}){
81 $$patron{branchcode}=C4::Context->userenv->{'branch'} unless (C4::Context->userenv->{'branch'} eq "insecure");
84 $$patron{firstname}.="\%" if ($$patron{firstname});
85 $$patron{surname}.="\%" if ($$patron{surname});
87 my @searchpatron;
88 push @searchpatron, $member if ($member);
89 push @searchpatron, $patron if (keys %$patron);
90 my $from= ($startfrom-1)*$resultsperpage;
91 my $to=$from+$resultsperpage;
92 #($results)=Search(\@searchpatron,{surname=>1,firstname=>1},[$from,$to],undef,["firstname","surname","email","othernames"] ) if (@searchpatron);
93 ($results)=Search(\@searchpatron,{surname=>1,firstname=>1},undef,undef,["firstname","surname","email","othernames","cardnumber"],"start_with" ) if (@searchpatron);
94 if ($results){
95 $count =scalar(@$results);
97 my @resultsdata;
98 my $to=($count>$to?$to:$count);
99 my $index=$from;
100 foreach my $borrower(@$results[$from..$to-1]){
101 #find out stats
103 $$borrower{'dateexpiry'}= C4::Dates->new($$borrower{'dateexpiry'},'iso')->output('syspref');
105 my %row = (
106 count => $index++,
107 %$borrower,
108 %{$categories_dislay{$$borrower{categorycode}}},
110 push(@resultsdata, \%row);
113 if ($$patron{branchcode}){
114 foreach my $branch (grep{$_->{value} eq $$patron{branchcode}}@$branches){
115 $$branch{selected}=1;
118 if ($$patron{categorycode}){
119 foreach my $category (grep{$_->{categorycode} eq $$patron{categorycode}}@categories){
120 $$category{selected}=1;
123 my %parameters=
124 ( %$patron
125 , 'orderby' => $orderby
126 , 'resultsperpage' => $resultsperpage
127 , 'type'=> 'intranet');
128 my $base_url =
129 'member-search.pl?&'
130 . join(
131 '&',
132 map { "$_=$parameters{$_}" } (keys %parameters)
135 $template->param(
136 paginationbar => pagination_bar(
137 $base_url, int( $count / $resultsperpage ) + 1,
138 $startfrom, 'startfrom'
140 startfrom => $startfrom,
141 from => ($startfrom-1)*$resultsperpage+1,
142 to => $to,
143 multipage => ($count != $to+1 || $startfrom!=1),
145 $template->param(
146 branchloop=>$branches,
147 categoryloop=>\@categories,
151 $template->param(
152 searching => "1",
153 actionname => basename($0),
154 %$patron,
155 numresults => $count,
156 resultsloop => \@resultsdata,
159 output_html_with_http_headers $cgi, $cookie, $template->output;