From 54ade6f531f93c2ec2efbbcdbd3a0b52ca75ce65 Mon Sep 17 00:00:00 2001
From: Alex ORLUC <alex@alex-MAARCH>
Date: Tue, 31 Jan 2017 12:13:13 +0100
Subject: [PATCH] FIX #4744 change query autocompletion

---
 modules/sendmail/adresss_autocomletion.php | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/modules/sendmail/adresss_autocomletion.php b/modules/sendmail/adresss_autocomletion.php
index 6d868725817..da9b066f8c6 100644
--- a/modules/sendmail/adresss_autocomletion.php
+++ b/modules/sendmail/adresss_autocomletion.php
@@ -44,7 +44,7 @@ $db = new Database();
                 . ' %d AS confidence, mail AS email '
                 . "FROM users"
                 . " WHERE enabled ='Y' AND "
-		. "(LOWER(lastname) LIKE LOWER('%s') OR LOWER(firstname) LIKE LOWER('%s') OR LOWER(user_id) LIKE LOWER('%s') OR LOWER(user_id) LIKE LOWER('%s') OR LOWER(user_id) LIKE LOWER('%s') OR LOWER(mail) LIKE LOWER('%s'))";
+		. "(LOWER(lastname) LIKE LOWER('%s') OR LOWER(firstname) LIKE LOWER('%s') OR LOWER(user_id) LIKE LOWER('%s') OR LOWER(user_id) LIKE LOWER('%s') OR LOWER(user_id) LIKE LOWER('%s') OR LOWER(user_id) LIKE LOWER('%s') OR LOWER(mail) LIKE LOWER('%s'))";
 
     $subQuery[2]= 
         "SELECT CASE WHEN contact_lastname = '' THEN UPPER(lastname) ELSE UPPER(contact_lastname) END || ' ' || CASE WHEN contact_firstname = '' THEN firstname ELSE contact_firstname END || CASE WHEN society = '' THEN '' ELSE ' - '||society END || "
@@ -57,6 +57,7 @@ $db = new Database();
                 . " (LOWER(contact_lastname) LIKE LOWER('%s') OR LOWER(lastname) LIKE LOWER('%s'))"
                 . " OR (LOWER(contact_firstname) LIKE LOWER('%s') OR LOWER(firstname) LIKE LOWER('%s'))"
                 . " OR LOWER(society) LIKE LOWER('%s')"
+                . " OR LOWER(society_short) LIKE LOWER('%s')"
         . " OR LOWER(email) LIKE LOWER('%s')"
             .")"
         ."and (is_private = 'N' or ( user_id = '".$_SESSION['user']['UserId']."' and is_private = 'Y'))";
@@ -70,17 +71,17 @@ for($i=1;$i<3;$i++){
         # Full match of one given arg
         $expr = $arg;
         $conf = 100;
-        $queryParts[] = sprintf($subQuery[$i], $conf, $expr, $expr, $expr, $expr, $expr, $expr); 
+        $queryParts[] = sprintf($subQuery[$i], $conf, $expr, $expr, $expr, $expr, $expr, $expr, $expr); 
 
         # Partial match (starts with)
         $expr = $arg . "%"; ;
         $conf = 34; # If found, partial match contains will also be so score is sum of both confidences, i.e. 67)
-        $queryParts[] = sprintf($subQuery[$i], $conf, $expr, $expr, $expr, $expr, $expr, $expr);
+        $queryParts[] = sprintf($subQuery[$i], $conf, $expr, $expr, $expr, $expr, $expr, $expr, $expr);
       
         # Partial match (contains)
         $expr = "%" . $arg . "%";
         $conf = 33;
-        $queryParts[] = sprintf($subQuery[$i], $conf, $expr, $expr, $expr, $expr, $expr, $expr);
+        $queryParts[] = sprintf($subQuery[$i], $conf, $expr, $expr, $expr, $expr, $expr, $expr, $expr);
     }
 }
     $query .= implode (' UNION ALL ', $queryParts);
-- 
GitLab