From e5e2493f45a28623c056023159f4166c2dac63a0 Mon Sep 17 00:00:00 2001 From: "G. Richardson" Date: Mon, 25 Feb 2013 16:06:57 +0100 Subject: [PATCH] =?utf8?q?Korrektur=20f=C3=BCr=20Commit=202def6461e=20-=20?= =?utf8?q?Kundenbericht?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit je nachdem ob die Abfrage mit UNION oder nicht durchgeführt wird muß die ORDER BY Spalte angepasst werden. allowed-HASH ähnlich wie in DO eingeführt. --- SL/CT.pm | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/SL/CT.pm b/SL/CT.pm index 63b252d9e..dd9d627b8 100644 --- a/SL/CT.pm +++ b/SL/CT.pm @@ -614,12 +614,36 @@ sub search { my $where = "1 = 1"; my @values; - my %allowed_sort_columns = - map { $_, 1 } qw( - id customernumber vendornumber name contact phone fax email street - taxnumber business invnumber ordnumber quonumber zipcode city country salesman + my %allowed_sort_columns = ( + "id" => "id", + "customernumber" => "customernumber", + "vendornumber" => "vendornumber", + "name" => "ct.name", + "contact" => "contact", + "phone" => "phone", + "fax" => "fax", + "email" => "email", + "street" => "street", + "taxnumber" => "taxnumber", + "business" => "business", + "invnumber" => "invnumber", + "ordnumber" => "ordnumber", + "quonumber" => "quonumber", + "zipcode" => "zipcode", + "city" => "city", + "country" => "country", + "salesman" => "e.name" ); - my $sortorder = $form->{sort} && $allowed_sort_columns{$form->{sort}} ? $form->{sort} : "name"; + + my $sortorder; + if ( $join_records ) { + # in UNION case order by hash key, e.g. salesman + # the UNION created an implicit select around the result + $sortorder = $form->{sort} && $allowed_sort_columns{$form->{sort}} ? $form->{sort} : "name"; + } else { + # in not UNION case order by hash value, e.g. e.name + $sortorder = $form->{sort} && $allowed_sort_columns{$form->{sort}} ? $allowed_sort_columns{$form->{sort}} : "ct.name"; + }; $form->{sort} = $sortorder; my $sortdir = !defined $form->{sortdir} ? 'ASC' : $form->{sortdir} ? 'ASC' : 'DESC'; @@ -788,7 +812,7 @@ sub search { } $query .= qq| ORDER BY $sortorder|; - + $form->{CT} = selectall_hashref_query($form, $dbh, $query, @values); $main::lxdebug->leave_sub(); -- 2.20.1