1 diff -ur lms/modules/quicksearch.php lms.new//modules/quicksearch.php
2 --- lms/modules/quicksearch.php 2011-03-18 09:59:24.000000000 +0100
3 +++ lms.new//modules/quicksearch.php 2011-03-29 20:41:29.772258200 +0200
8 - * LMS version 1.11.12 Aris
9 + * LMS version 1.11-cvs
11 * (C) Copyright 2001-2011 LMS Developers
14 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
21 function macformat($mac)
24 if(isset($_GET['ajax'])) // support for AutoSuggest
26 - $candidates = $DB->GetAll('SELECT id, email, address, post_address, deleted,
27 + $candidates = $DB->GetAll('SELECT id, email, address, post_name, post_address, deleted,
28 '.$DB->Concat('UPPER(lastname)',"' '",'name').' AS username
30 WHERE '.(preg_match('/^[0-9]+$/', $search) ? 'id = '.intval($search).' OR ' : '').'
31 LOWER('.$DB->Concat('lastname',"' '",'name').') ?LIKE? LOWER(\'%'.$search.'%\')
32 OR LOWER(address) ?LIKE? LOWER(\'%'.$search.'%\')
33 + OR LOWER(post_name) ?LIKE? LOWER(\'%'.$search.'%\')
34 OR LOWER(post_address) ?LIKE? LOWER(\'%'.$search.'%\')
35 OR LOWER(email) ?LIKE? LOWER(\'%'.$search.'%\')
36 ORDER by deleted, username, email, address
38 $descriptions[$row['id']] = escape_js(trans('Address:').' '.$row['address']);
41 + else if (preg_match("~$search~i",$row['post_name'])) {
42 + $descriptions[$row['id']] = escape_js(trans('Name:').' '.$row['post_name']);
45 else if (preg_match("~$search~i",$row['post_address'])) {
46 $descriptions[$row['id']] = escape_js(trans('Address:').' '.$row['post_address']);
50 if(isset($_GET['ajax'])) // support for AutoSuggest
52 - $candidates = $DB->GetAll('SELECT n.id, n.name, INET_NTOA(ipaddr) as ip,
53 - INET_NTOA(ipaddr_pub) AS ip_pub, mac
55 - WHERE ('.(preg_match('/^[0-9]+$/',$search) ? 'n.id = '.intval($search).' OR ' : '').'
56 - LOWER(n.name) ?LIKE? LOWER(\'%'.$search.'%\')
57 - OR INET_NTOA(ipaddr) ?LIKE? \'%'.$search.'%\'
58 - OR INET_NTOA(ipaddr_pub) ?LIKE? \'%'.$search.'%\'
59 - OR LOWER(mac) ?LIKE? LOWER(\'%'.macformat($search).'%\')
62 - SELECT 1 FROM customerassignments a
63 - JOIN excludedgroups e ON (a.customergroupid = e.customergroupid)
64 - WHERE e.userid = lms_current_user() AND a.customerid = n.ownerid)
65 - ORDER BY n.name LIMIT 15');
66 + // Build different query for each database engine,
67 + // MySQL is slow here when vnodes view is used
68 + if ($CONFIG['database']['type'] == 'postgres')
69 + $sql_query = 'SELECT n.id, n.name, INET_NTOA(ipaddr) as ip,
70 + INET_NTOA(ipaddr_pub) AS ip_pub, mac
73 + ORDER BY n.name LIMIT 15';
75 + $sql_query = 'SELECT n.id, n.name, INET_NTOA(ipaddr) as ip,
76 + INET_NTOA(ipaddr_pub) AS ip_pub, mac
79 + SELECT nodeid, GROUP_CONCAT(mac SEPARATOR \',\') AS mac
82 + ) m ON (n.id = m.nodeid)
84 + ORDER BY n.name LIMIT 15';
86 + $sql_where = '('.(preg_match('/^[0-9]+$/',$search) ? 'n.id = '.intval($search).' OR ' : '').'
87 + LOWER(n.name) ?LIKE? LOWER(\'%'.$search.'%\')
88 + OR INET_NTOA(ipaddr) ?LIKE? \'%'.$search.'%\'
89 + OR INET_NTOA(ipaddr_pub) ?LIKE? \'%'.$search.'%\'
90 + OR LOWER(mac) ?LIKE? LOWER(\'%'.macformat($search).'%\'))
92 + SELECT 1 FROM customerassignments a
93 + JOIN excludedgroups e ON (a.customergroupid = e.customergroupid)
94 + WHERE e.userid = lms_current_user() AND a.customerid = n.ownerid)';
96 + $candidates = $DB->GetAll(str_replace('%where', $sql_where, $sql_query));
98 $eglible=array(); $actions=array(); $descriptions=array();