From d9880aba74d253ec3f960d8579cc7d59a36c9ce3 Mon Sep 17 00:00:00 2001 From: =?utf8?q?S=C5=82awomir=20Paszkiewicz?= Date: Wed, 30 Mar 2011 10:49:44 +0000 Subject: [PATCH] - fix from 'http://cvs.lms.org.pl/viewvc/Development/lms/modules/quicksearch.php?r1=1.72&r2=1.73' Changed files: lms-quicksearch.php.patch -> 1.1 --- lms-quicksearch.php.patch | 99 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 lms-quicksearch.php.patch diff --git a/lms-quicksearch.php.patch b/lms-quicksearch.php.patch new file mode 100644 index 0000000..c234ef1 --- /dev/null +++ b/lms-quicksearch.php.patch @@ -0,0 +1,99 @@ +diff -ur lms/modules/quicksearch.php lms.new//modules/quicksearch.php +--- lms/modules/quicksearch.php 2011-03-18 09:59:24.000000000 +0100 ++++ lms.new//modules/quicksearch.php 2011-03-29 20:41:29.772258200 +0200 +@@ -1,7 +1,7 @@ + GetAll('SELECT id, email, address, post_address, deleted, ++ $candidates = $DB->GetAll('SELECT id, email, address, post_name, post_address, deleted, + '.$DB->Concat('UPPER(lastname)',"' '",'name').' AS username + FROM customersview + WHERE '.(preg_match('/^[0-9]+$/', $search) ? 'id = '.intval($search).' OR ' : '').' + LOWER('.$DB->Concat('lastname',"' '",'name').') ?LIKE? LOWER(\'%'.$search.'%\') + OR LOWER(address) ?LIKE? LOWER(\'%'.$search.'%\') ++ OR LOWER(post_name) ?LIKE? LOWER(\'%'.$search.'%\') + OR LOWER(post_address) ?LIKE? LOWER(\'%'.$search.'%\') + OR LOWER(email) ?LIKE? LOWER(\'%'.$search.'%\') + ORDER by deleted, username, email, address +@@ -105,6 +106,10 @@ + $descriptions[$row['id']] = escape_js(trans('Address:').' '.$row['address']); + continue; + } ++ else if (preg_match("~$search~i",$row['post_name'])) { ++ $descriptions[$row['id']] = escape_js(trans('Name:').' '.$row['post_name']); ++ continue; ++ } + else if (preg_match("~$search~i",$row['post_address'])) { + $descriptions[$row['id']] = escape_js(trans('Address:').' '.$row['post_address']); + continue; +@@ -156,20 +161,37 @@ + case 'node': + if(isset($_GET['ajax'])) // support for AutoSuggest + { +- $candidates = $DB->GetAll('SELECT n.id, n.name, INET_NTOA(ipaddr) as ip, +- INET_NTOA(ipaddr_pub) AS ip_pub, mac +- FROM vnodes n +- WHERE ('.(preg_match('/^[0-9]+$/',$search) ? 'n.id = '.intval($search).' OR ' : '').' +- LOWER(n.name) ?LIKE? LOWER(\'%'.$search.'%\') +- OR INET_NTOA(ipaddr) ?LIKE? \'%'.$search.'%\' +- OR INET_NTOA(ipaddr_pub) ?LIKE? \'%'.$search.'%\' +- OR LOWER(mac) ?LIKE? LOWER(\'%'.macformat($search).'%\') +- ) +- AND NOT EXISTS ( +- SELECT 1 FROM customerassignments a +- JOIN excludedgroups e ON (a.customergroupid = e.customergroupid) +- WHERE e.userid = lms_current_user() AND a.customerid = n.ownerid) +- ORDER BY n.name LIMIT 15'); ++ // Build different query for each database engine, ++ // MySQL is slow here when vnodes view is used ++ if ($CONFIG['database']['type'] == 'postgres') ++ $sql_query = 'SELECT n.id, n.name, INET_NTOA(ipaddr) as ip, ++ INET_NTOA(ipaddr_pub) AS ip_pub, mac ++ FROM vnodes n ++ WHERE %where ++ ORDER BY n.name LIMIT 15'; ++ else ++ $sql_query = 'SELECT n.id, n.name, INET_NTOA(ipaddr) as ip, ++ INET_NTOA(ipaddr_pub) AS ip_pub, mac ++ FROM nodes n ++ JOIN ( ++ SELECT nodeid, GROUP_CONCAT(mac SEPARATOR \',\') AS mac ++ FROM macs ++ GROUP BY nodeid ++ ) m ON (n.id = m.nodeid) ++ WHERE %where ++ ORDER BY n.name LIMIT 15'; ++ ++ $sql_where = '('.(preg_match('/^[0-9]+$/',$search) ? 'n.id = '.intval($search).' OR ' : '').' ++ LOWER(n.name) ?LIKE? LOWER(\'%'.$search.'%\') ++ OR INET_NTOA(ipaddr) ?LIKE? \'%'.$search.'%\' ++ OR INET_NTOA(ipaddr_pub) ?LIKE? \'%'.$search.'%\' ++ OR LOWER(mac) ?LIKE? LOWER(\'%'.macformat($search).'%\')) ++ AND NOT EXISTS ( ++ SELECT 1 FROM customerassignments a ++ JOIN excludedgroups e ON (a.customergroupid = e.customergroupid) ++ WHERE e.userid = lms_current_user() AND a.customerid = n.ownerid)'; ++ ++ $candidates = $DB->GetAll(str_replace('%where', $sql_where, $sql_query)); + + $eglible=array(); $actions=array(); $descriptions=array(); + if ($candidates) -- 2.44.0