X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=members%2Fmember.pl;h=2fc7fb462a62b991c780d7f3759de297fc8d6b01;hb=fe9f7cef3be1768ec54acd7934b146d5d9d68927;hp=f8aa4f1a72419a058ac2295ea83d32277d798d10;hpb=65be03846d064dd6d9e7159550a269a352054b65;p=koha.git diff --git a/members/member.pl b/members/member.pl index f8aa4f1a72..2fc7fb462a 100755 --- a/members/member.pl +++ b/members/member.pl @@ -6,184 +6,74 @@ # Copyright 2000-2002 Katipo Communications -# Copyright 2010 BibLibre +# Copyright 2013 BibLibre # # This file is part of Koha. # -# Koha is free software; you can redistribute it and/or modify it under the -# terms of the GNU General Public License as published by the Free Software -# Foundation; either version 2 of the License, or (at your option) any later -# version. +# Koha is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. # -# Koha is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR -# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# Koha is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. # -# You should have received a copy of the GNU General Public License along -# with Koha; if not, write to the Free Software Foundation, Inc., -# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +# You should have received a copy of the GNU General Public License +# along with Koha; if not, see . -use strict; -#use warnings; FIXME - Bug 2505 +use Modern::Perl; use C4::Auth; use C4::Output; -use CGI; -use C4::Members; -use C4::Branch; -use C4::Category; -use File::Basename; +use CGI qw( -utf8 ); +use Koha::DateUtils; +use Koha::List::Patron; +use Koha::Patrons; my $input = new CGI; -my $quicksearch = $input->param('quicksearch'); -my $startfrom = $input->param('startfrom')||1; -my $resultsperpage = $input->param('resultsperpage')||C4::Context->preference("PatronsPerPage")||20; my ($template, $loggedinuser, $cookie) - = get_template_and_user({template_name => "members/member.tmpl", + = get_template_and_user({template_name => "members/member.tt", query => $input, type => "intranet", authnotrequired => 0, - flagsrequired => {borrowers => 1}, + flagsrequired => {borrowers => 'edit_borrowers'}, }); my $theme = $input->param('theme') || "default"; -my $patron = $input->Vars; -foreach (keys %$patron){ - delete $$patron{$_} unless($$patron{$_}); +my $searchmember = $input->param('searchmember'); +my $quicksearch = $input->param('quicksearch') // 0; + +if ( $quicksearch and $searchmember ) { + my $branchcode; + if ( C4::Context::only_my_library ) { + my $userenv = C4::Context->userenv; + $branchcode = $userenv->{'branch'}; + } + my $patron = Koha::Patrons->find( { cardnumber => $searchmember } ); + if( ( $branchcode and $patron and $patron->branchcode eq $branchcode ) or ( not $branchcode and $patron ) ){ + print $input->redirect("/cgi-bin/koha/members/moremember.pl?borrowernumber=" . $patron->borrowernumber); + exit; + } } -my @categories=C4::Category->all; -my $branches = GetBranches; -my @branchloop; +my $searchfieldstype = $input->param('searchfieldstype') || 'standard'; -foreach (sort { $branches->{$a}->{branchname} cmp $branches->{$b}->{branchname} } keys %$branches) { - my $selected; - $selected = 1 if $branches->{$_}->{branchcode} eq $$patron{branchcode}; - my %row = ( value => $_, - selected => $selected, - branchname => $branches->{$_}->{branchname}, - ); - push @branchloop, \%row; -} - -my %categories_dislay; - -foreach my $category (@categories){ - my $hash={ - category_description=>$$category{description}, - category_type=>$$category{category_type} - }; - $categories_dislay{$$category{categorycode}} = $hash; -} -my $AddPatronLists = C4::Context->preference("AddPatronLists") || ''; -$template->param( - "AddPatronLists_$AddPatronLists" => "1", - ); -if ($AddPatronLists=~/code/){ - $categories[0]->{'first'}=1; -} - -my $member=$input->param('member'); -my $orderbyparams=$input->param('orderby'); -my @orderby; -if ($orderbyparams){ - my @orderbyelt=split(/,/,$orderbyparams); - push @orderby, {$orderbyelt[0]=>$orderbyelt[1]||0}; -} -else { - @orderby = ({surname=>0},{firstname=>0}); -} - -my $searchfields = $input->param('searchfields'); -my @searchfields = $searchfields ? split( ',', $searchfields ) : ( "firstname", "surname", "othernames", "cardnumber", "userid", "email" ); - -$member =~ s/,//g; #remove any commas from search string -$member =~ s/\*/%/g; - -my $from = ( $startfrom - 1 ) * $resultsperpage; -my $to = $from + $resultsperpage; - -my ($count,$results); -if ($member || keys %$patron) { - #($results)=Search($member || $patron,{surname=>1,firstname=>1},[$from,$to],undef,["firstname","surname","email","othernames"] ); - my $search_scope = ( $quicksearch ? "field_start_with" : "start_with" ); - ($results) = Search( $member || $patron, \@orderby, undef, undef, \@searchfields, $search_scope ); -} - -if ($results) { - for my $field ('categorycode','branchcode'){ - next unless ($patron->{$field}); - @$results = grep { $_->{$field} eq $patron->{$field} } @$results; - } - $count = scalar(@$results); -} - -if($count == 1){ - print $input->redirect("/cgi-bin/koha/members/moremember.pl?borrowernumber=" . @$results[0]->{borrowernumber}); - exit; -} - -my @resultsdata; -$to=($count>$to?$to:$count); -my $index=$from; -foreach my $borrower(@$results[$from..$to-1]){ - #find out stats - my ($od,$issue,$fines)=GetMemberIssuesAndFines($$borrower{'borrowernumber'}); - - $$borrower{'dateexpiry'}= C4::Dates->new($$borrower{'dateexpiry'},'iso')->output('syspref'); - - my %row = ( - count => $index++, - %$borrower, - %{$categories_dislay{$$borrower{categorycode}}}, - overdues => $od, - issues => $issue, - odissue => "$od/$issue", - fines => sprintf("%.2f",$fines), - branchname => $branches->{$borrower->{branchcode}}->{branchname}, - ); - push(@resultsdata, \%row); -} - -if ($$patron{categorycode}){ - foreach my $category (grep{$_->{categorycode} eq $$patron{categorycode}}@categories){ - $$category{selected}=1; - } -} -my %parameters= - ( %$patron - , 'orderby' => $orderbyparams - , 'resultsperpage' => $resultsperpage - , 'type'=> 'intranet'); -my $base_url = - 'member.pl?&' - . join( - '&', - map { "$_=$parameters{$_}" } (keys %parameters) - ); +$template->param( 'alphabet' => C4::Context->preference('alphabet') || join ' ', 'A' .. 'Z' ); -my @letters = map { {letter => $_} } ( 'A' .. 'Z'); +my $view = $input->request_method() eq "GET" ? "show_form" : "show_results"; $template->param( - letters => \@letters, - paginationbar => pagination_bar( - $base_url, - int( $count / $resultsperpage ) + ($count % $resultsperpage ? 1 : 0), - $startfrom, 'startfrom' - ), - startfrom => $startfrom, - from => ($startfrom-1)*$resultsperpage+1, - to => $to, - multipage => ($count != $to || $startfrom!=1), - advsearch => ($$patron{categorycode} || $$patron{branchcode}), - branchloop=>\@branchloop, - categories=>\@categories, - searching => "1", - actionname =>basename($0), - %$patron, - numresults => $count, - resultsloop => \@resultsdata, - ); + patron_lists => [ GetPatronLists() ], + searchmember => $searchmember, + branchcode_filter => scalar $input->param('branchcode_filter'), + categorycode_filter => scalar $input->param('categorycode_filter'), + searchtype => scalar $input->param('searchtype') || 'contain', + searchfieldstype => $searchfieldstype, + PatronsPerPage => C4::Context->preference("PatronsPerPage") || 20, + view => $view, +); output_html_with_http_headers $input, $cookie, $template->output;