X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;ds=inline;f=members%2Fmember.pl;h=9b793f4ab8602a1c90a24f0abc21b5dd6cdf96b4;hb=822f898f66ddc0f77894c3a3494f6e104e3aa745;hp=700f200efd1ad6cb28543e63aec500572c8dfb6f;hpb=db8bda86ea9325651e29a24df7cefbc0c86bee20;p=koha.git diff --git a/members/member.pl b/members/member.pl index 700f200efd..9b793f4ab8 100755 --- a/members/member.pl +++ b/members/member.pl @@ -6,6 +6,7 @@ # Copyright 2000-2002 Katipo Communications +# Copyright 2010 BibLibre # # This file is part of Koha. # @@ -31,7 +32,6 @@ use C4::Members; use C4::Branch; use C4::Category; use File::Basename; -use YAML; my $input = new CGI; my $quicksearch = $input->param('quicksearch'); @@ -50,11 +50,21 @@ my $theme = $input->param('theme') || "default"; my $patron = $input->Vars; foreach (keys %$patron){ - delete $$patron{$_} unless($$patron{$_}); + delete $$patron{$_} unless($$patron{$_}); } - my @categories=C4::Category->all; -my $branches=(defined $$patron{branchcode}?GetBranchesLoop($$patron{branchcode}):GetBranchesLoop()); + +my $branches = GetBranches; +my @branchloop; + +foreach (sort { $branches->{$a}->{branchname} cmp $branches->{$b}->{branchname} } keys %$branches) { + my $selected = 1 if $branches->{$_}->{branchcode} eq $$patron{branchcode}; + my %row = ( value => $_, + selected => $selected, + branchname => $branches->{$_}->{branchname}, + ); + push @branchloop, \%row; +} my %categories_dislay; @@ -65,10 +75,11 @@ foreach my $category (@categories){ }; $categories_dislay{$$category{categorycode}} = $hash; } +my $AddPatronLists = C4::Context->preference("AddPatronLists") || ''; $template->param( - "AddPatronLists_".C4::Context->preference("AddPatronLists")=> "1", + "AddPatronLists_$AddPatronLists" => "1", ); -if (C4::Context->preference("AddPatronLists")=~/code/){ +if ($AddPatronLists=~/code/){ $categories[0]->{'first'}=1; } @@ -80,27 +91,40 @@ if ($orderbyparams){ push @orderby, {$orderbyelt[0]=>$orderbyelt[1]||0}; } else { - @orderby = ({firstname=>1},{surname=>1}); + @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 ); +} -my @searchpatron; -push @searchpatron, $member if ($member); -push @searchpatron, $patron if (keys %$patron); -my $from= ($startfrom-1)*$resultsperpage; -my $to=$from+$resultsperpage; - #($results)=Search(\@searchpatron,{surname=>1,firstname=>1},[$from,$to],undef,["firstname","surname","email","othernames"] ) if (@searchpatron); - my $search_scope=($quicksearch?"field_start_with":"contain"); - ($results)=Search(\@searchpatron,\@orderby,undef,undef,["firstname","surname","email","othernames","cardnumber","userid"],$search_scope ) if (@searchpatron); -if ($results){ - $count =scalar(@$results); +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; -my $to=($count>$to?$to:$count); +$to=($count>$to?$to:$count); my $index=$from; foreach my $borrower(@$results[$from..$to-1]){ #find out stats @@ -120,11 +144,6 @@ foreach my $borrower(@$results[$from..$to-1]){ push(@resultsdata, \%row); } -if ($$patron{branchcode}){ - foreach my $branch (grep{$_->{value} eq $$patron{branchcode}}@$branches){ - $$branch{selected}=1; - } -} if ($$patron{categorycode}){ foreach my $category (grep{$_->{categorycode} eq $$patron{categorycode}}@categories){ $$category{selected}=1; @@ -143,26 +162,22 @@ my $base_url = ); my @letters = map { {letter => $_} } ( 'A' .. 'Z'); -$template->param( letters => \@letters ); $template->param( + letters => \@letters, paginationbar => pagination_bar( - $base_url, int( $count / $resultsperpage ) + 1, + $base_url, + int( $count / $resultsperpage ) + ($count % $resultsperpage ? 1 : 0), $startfrom, 'startfrom' ), startfrom => $startfrom, from => ($startfrom-1)*$resultsperpage+1, to => $to, - multipage => ($count != $to+1 || $startfrom!=1), -); -$template->param( - branchloop=>$branches, - categoryloop=>\@categories, -); - - -$template->param( - searching => "1", + multipage => ($count != $to || $startfrom!=1), + advsearch => ($$patron{categorycode} || $$patron{branchcode}), + branchloop=>\@branchloop, + categories=>\@categories, + searching => "1", actionname =>basename($0), %$patron, numresults => $count,