diff --git a/C4/SQLHelper.pm b/C4/SQLHelper.pm
index 05e3cc66f0..1d600346ab 100644
--- a/C4/SQLHelper.pm
+++ b/C4/SQLHelper.pm
@@ -116,10 +116,13 @@ sub SearchInTable{
}
if ($orderby){
#Order by desc by default
- my @orders=map{ "$_".($$orderby{$_}? " DESC" : "") } keys %$orderby;
- $sql.= do { local $"=', ';
- qq{ ORDER BY @orders}
- };
+ my @orders;
+ foreach my $order (@$orderby){
+ push @orders,map{ "$_".($$order{$_}? " DESC " : "") } keys %$order;
+ }
+ $sql.= do { local $"=', ';
+ qq{ ORDER BY @orders}
+ };
}
if ($limit){
$sql.=qq{ LIMIT }.join(",",@$limit);
@@ -417,25 +420,21 @@ sub _Process_Operands{
unless ($searchtype){
return \@tmpkeys,\@values;
}
- if ($searchtype eq "contain"){
- my $col_field=(index($field,".")>0?substr($field, index($field,".")+1):$field);
- if ($field=~/(?0?substr($field, index($field,".")+1):$field);
+ if ($field=~/(?0?substr($field, index($field,".")+1):$field);
- if ($field=~/(?
Enter patron card number or partial name:
@@ -93,4 +112,11 @@ YAHOO.util.Event.onContentReady("header_search", function() {
Search the Catalog
-
\ No newline at end of file
+
+
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/member.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/members/member.tmpl
index 05b47479e2..a794b6029f 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/member.tmpl
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/member.tmpl
@@ -1,16 +1,6 @@
Koha › Patrons › Search Results
-
-
@@ -124,9 +114,16 @@ $(document).ready(function() {
-
-
-
+
+
diff --git a/members/member.pl b/members/member.pl
index 51a3bf33f0..2937706b65 100755
--- a/members/member.pl
+++ b/members/member.pl
@@ -30,6 +30,7 @@ use C4::Members;
use C4::Branch;
use C4::Category;
use File::Basename;
+use YAML;
my $input = new CGI;
my $quicksearch = $input->param('quicksearch');
@@ -81,23 +82,28 @@ if (C4::Context->preference("AddPatronLists")=~/code/){
}
my $member=$input->param('member');
-my $orderby=$input->param('orderby');
-$orderby = "surname,firstname" unless $orderby;
+my $orderbyparams=$input->param('orderby');
+my @orderby;
+if ($orderbyparams){
+ my @orderbyelt=split(/,/,$orderbyparams);
+ push @orderby, {$orderbyelt[0]=>$orderbyelt[1]||0};
+}
+else {
+ @orderby = ({surname=>1},{firstname=>1});
+}
+warn Data::Dumper::Dumper(@orderby);
$member =~ s/,//g; #remove any commas from search string
$member =~ s/\*/%/g;
my ($count,$results);
-$$patron{firstname}.="\%" if ($$patron{firstname});
-$$patron{surname}.="\%" if ($$patron{surname});
-
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);
- ($results)=Search(\@searchpatron,{surname=>1,firstname=>1},undef,undef,["firstname","surname","email","othernames","cardnumber","userid"],"start_with" ) if (@searchpatron);
+ ($results)=Search(\@searchpatron,\@orderby,undef,undef,["firstname","surname","email","othernames","cardnumber","userid"],"start_with" ) if (@searchpatron);
if ($results){
$count =scalar(@$results);
}
@@ -134,7 +140,7 @@ if ($$patron{categorycode}){
}
my %parameters=
( %$patron
- , 'orderby' => $orderby
+ , 'orderby' => $orderbyparams
, 'resultsperpage' => $resultsperpage
, 'type'=> 'intranet');
my $base_url =
diff --git a/t/db_dependent/SQLHelper.t b/t/db_dependent/SQLHelper.t
index ffa8d43115..3c2fd48a9a 100755
--- a/t/db_dependent/SQLHelper.t
+++ b/t/db_dependent/SQLHelper.t
@@ -10,7 +10,7 @@ use YAML;
use C4::Debug;
use C4::SQLHelper qw(:all);
-use Test::More tests => 16;
+use Test::More tests => 18;
#1
BEGIN {
@@ -22,10 +22,8 @@ my @categories=C4::Category->all;
my $branches=C4::Branch->GetBranches;
my @branchcodes=keys %$branches;
my ($borrid, $borrtmp);
-$borrtmp=InsertInTable("borrowers",{firstname=>"Jean",surname=>"cocteau",city=>" ",zipcode=>" ",email=>"email",categorycode=>$categories[0]->{categorycode}, branchcode=>$branchcodes[0]});
-#2
ok($borrid=InsertInTable("borrowers",{firstname=>"Jean",surname=>"Valjean",city=>" ",zipcode=>" ",email=>"email",categorycode=>$categories[0]->{categorycode}, branchcode=>$branchcodes[0]}),"Insert In Table");
-#3
+$borrtmp=InsertInTable("borrowers",{firstname=>"Jean",surname=>"cocteau",city=>" ",zipcode=>" ",email=>"email",categorycode=>$categories[0]->{categorycode}, branchcode=>$branchcodes[0]});
ok(my $status=UpdateInTable("borrowers",{borrowernumber=>$borrid,firstname=>"Jean",surname=>"Valjean",city=>"Dampierre",zipcode=>" ",email=>"email", branchcode=>$branchcodes[1]}),"Update In Table");
my $borrowers=SearchInTable("borrowers");
#4
@@ -36,6 +34,10 @@ ok(@$borrowers==1, "Search In Table by primary key on table");
$borrowers=SearchInTable("borrowers",{firstname=>"Jean"});
#6
ok(@$borrowers>0, "Search In Table hashref");
+$borrowers=SearchInTable("borrowers",{firstname=>"Jean"},[{firstname=>1},{borrowernumber=>1}],undef, [qw(borrowernumber)]);
+ok(($$borrowers[0]{borrowernumber} + 0) > ($$borrowers[1]{borrowernumber} + 0), "Search In Table Order");
+$borrowers=SearchInTable("borrowers",{firstname=>"Jean"},[{surname=>0},{firstname=>1}], undef, [qw(firstname surname)]);
+ok(uc($$borrowers[0]{surname}) lt uc($$borrowers[1]{surname}), "Search In Table Order");
$borrowers=SearchInTable("borrowers","Jean");
#7
ok(@$borrowers>0, "Search In Table string");
@@ -63,6 +65,8 @@ ok(@$borrowers==0, "Search In Table columns filter surname Val in exact search
$borrowers=eval{SearchInTable("borrowers",["Val",{member=>"Jean"}],undef,undef,[qw(borrowernumber)],[qw(firstname title)],"exact")};
#15
ok(@$borrowers==0 && !($@), "Search In Table fails gracefully when no correct field passed in hash");
+$borrowers=eval{SearchInTable("borrowers",["Jean"],undef,undef,undef,[qw(firstname surname borrowernumber)],"start_with")};
+ok(@$borrowers==0 && !($@), "Search In Table fails gracefully when no correct field passed in hash");
$status=DeleteInTable("borrowers",{borrowernumber=>$borrid});
#16