From ab942ff56cc4ff8721e59e372c4a62f792417d48 Mon Sep 17 00:00:00 2001 From: Alex ORLUC <alex.orluc@maarch.org> Date: Mon, 29 Apr 2019 18:02:53 +0200 Subject: [PATCH] FEAT #10460 TIME 0:10 rename file --- modules/sendmail/address_autocompletion.php | 112 +++++++++++++++++ modules/sendmail/adresss_autocomletion.php | 114 ------------------ modules/sendmail/mail_form.php | 4 +- modules/sendmail/mail_form_to_contact.php | 2 +- .../sendmail/xml/IVS/requests_definitions.xml | 2 +- 5 files changed, 116 insertions(+), 118 deletions(-) create mode 100644 modules/sendmail/address_autocompletion.php delete mode 100755 modules/sendmail/adresss_autocomletion.php diff --git a/modules/sendmail/address_autocompletion.php b/modules/sendmail/address_autocompletion.php new file mode 100644 index 00000000000..9c9cd1526cc --- /dev/null +++ b/modules/sendmail/address_autocompletion.php @@ -0,0 +1,112 @@ +<?php +/** +* Copyright Maarch since 2008 under licence GPLv3. +* See LICENCE.txt file at the root folder for more details. +* This file is part of Maarch software. + +* @brief address_autocompletion +* @author dev <dev@maarch.org> +* @ingroup sendmail +*/ + +require_once("core".DIRECTORY_SEPARATOR."class".DIRECTORY_SEPARATOR."class_request.php"); + +$db = new Database(); + +$timestart=microtime(true); + +$args = explode(' ', $_REQUEST['what']); +$args[] = $_REQUEST['what']; +$num_args = count($args); +if ($num_args == 0) { + return "<ul></ul>"; +} + +$query = "SELECT result, SUM(confidence) AS score, count(1) AS num FROM ("; +$subQuery = array(); +$subQuery[1] = "SELECT UPPER(lastname) || ' ' || firstname || ' (' || mail || ')' AS result, " + . ' %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(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 || " + . "' (' || email || ')' AS result, " + . ' %d AS confidence, email' + . " FROM view_contacts" + . " WHERE " + . " enabled = 'Y' AND email <> ''" + . " AND (" + . " (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'))"; + +$queryParts = array(); + +for ($i=1; $i<3; $i++) { + foreach ($args as $arg) { + if (strlen($arg) == 0) { + continue; + } + # Full match of one given arg + $expr = $arg; + $conf = 100; + $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, $expr); + + # Partial match (contains) + $expr = "%" . $arg . "%"; + $conf = 33; + $queryParts[] = sprintf($subQuery[$i], $conf, $expr, $expr, $expr, $expr, $expr, $expr, $expr); + } +} + +$query .= implode(' UNION ALL ', $queryParts); +$query .= ") matches" + . " GROUP BY result " + . " ORDER BY score DESC, result ASC"; + +$stmt = $db->query($query); +$nb = $stmt->rowCount(); +$m = 30; +if ($nb >= $m) { + $l = $m; +} else { + $l = $nb; +} + +$timeend=microtime(true); +$time = number_format(($timeend-$timestart), 3); + +$found = false; +echo "<ul title='$l contacts found in " . $time."sec'>"; +for ($i=0; $i<$l; $i++) { + $res = $stmt->fetchObject(); + $score = round($res->score / $num_args); + if ($i%2==1) { + $color = 'LightYellow'; + } else { + $color = 'white'; + } + echo "<li style='font-size: 8pt; background-color:$color;' title='confiance:".$score."%' id='".$res->email."'>". $res->result ."</li>"; +} +if ($nb == 0) { + echo "<li></li>"; +} +echo "</ul>"; +if ($nb == 0) { + echo "<p align='left' style='background-color:LemonChiffon;' title=\"Aucun résultat trouvé, veuillez compléter votre recherche.\" >...</p>"; +} +if ($nb > $m) { + echo "<p align='left' style='background-color:LemonChiffon;' title=\"La liste n'a pas pu être affichée intégralement, veuillez compléter votre recherche.\" >...</p>"; +} diff --git a/modules/sendmail/adresss_autocomletion.php b/modules/sendmail/adresss_autocomletion.php deleted file mode 100755 index da9b066f8c6..00000000000 --- a/modules/sendmail/adresss_autocomletion.php +++ /dev/null @@ -1,114 +0,0 @@ -<?php -/* -* -* Copyright 2013 Maarch -* -* This file is part of Maarch Framework. -* -* Maarch Framework is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. -* -* Maarch Framework is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with Maarch Framework. If not, see <http://www.gnu.org/licenses/>. -*/ - -/** -* @brief List of email adress for autocompletion -* -* @file adresss_autocomletion.php -* @author Yves Christian Kpakpo <dev@maarch.org> -* @date $date$ -* @version $Revision$ -* @ingroup sendmail -*/ -require_once("core".DIRECTORY_SEPARATOR."class".DIRECTORY_SEPARATOR."class_request.php"); -$db = new Database(); - - $timestart=microtime(true); - - $args = explode(' ', $_REQUEST['what']); - $args[] = $_REQUEST['what']; - $num_args = count($args); - if($num_args == 0) return "<ul></ul>"; - - $query = "SELECT result, SUM(confidence) AS score, count(1) AS num FROM ("; - $subQuery = array(); - $subQuery[1] = "SELECT UPPER(lastname) || ' ' || firstname || ' (' || mail || ')' AS result, " - . ' %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(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 || " - . "' (' || email || ')' AS result, " - . ' %d AS confidence, email' - . " FROM view_contacts" - . " WHERE " - . " enabled = 'Y' AND email <> ''" - . " AND (" - . " (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'))"; - - - - $queryParts = array(); -for($i=1;$i<3;$i++){ - foreach($args as $arg) { - if(strlen($arg) == 0) continue; - # Full match of one given arg - $expr = $arg; - $conf = 100; - $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, $expr); - - # Partial match (contains) - $expr = "%" . $arg . "%"; - $conf = 33; - $queryParts[] = sprintf($subQuery[$i], $conf, $expr, $expr, $expr, $expr, $expr, $expr, $expr); - } -} - $query .= implode (' UNION ALL ', $queryParts); - $query .= ") matches" - . " GROUP BY result " - . " ORDER BY score DESC, result ASC"; - - $stmt = $db->query($query); - $nb = $stmt->rowCount(); - $m = 30; - if($nb >= $m) $l = $m; - else $l = $nb; - - $timeend=microtime(true); - $time = number_format(($timeend-$timestart), 3); - - $found = false; - echo "<ul title='$l contacts found in " . $time."sec'>"; - for($i=0; $i<$l; $i++) { - $res = $stmt->fetchObject(); - $score = round($res->score / $num_args); - if($i%2==1) $color = 'LightYellow'; - else $color = 'white'; - echo "<li style='font-size: 8pt; background-color:$color;' title='confiance:".$score."%' id='".$res->email."'>". $res->result ."</li>"; - } - if($nb == 0) echo "<li></li>"; - echo "</ul>"; - if($nb == 0) echo "<p align='left' style='background-color:LemonChiffon;' title=\"Aucun résultat trouvé, veuillez compléter votre recherche.\" >...</p>"; - if($nb > $m) echo "<p align='left' style='background-color:LemonChiffon;' title=\"La liste n'a pas pu être affichée intégralement, veuillez compléter votre recherche.\" >...</p>"; - diff --git a/modules/sendmail/mail_form.php b/modules/sendmail/mail_form.php index 8af493c3821..f23cb70e58f 100755 --- a/modules/sendmail/mail_form.php +++ b/modules/sendmail/mail_form.php @@ -195,7 +195,7 @@ if ($mode == 'add') { $content .= '<div id="adressList" class="autocomplete"></div>'; $content .= '<script type="text/javascript">addEmailAdress(\'email\', \'adressList\', \'' .$_SESSION['config']['businessappurl'] - .'index.php?display=true&module=sendmail&page=adresss_autocomletion\', \'what\', \'2\');</script>'; + .'index.php?display=true&module=sendmail&page=address_autocompletion\', \'what\', \'2\');</script>'; $content .= ' <select name="target" id="target">' .'<option id="target_target_to" value="to">'._SEND_TO_SHORT.'</option>' .'<option id="target_cc" value="cc">'._COPY_TO_SHORT.'</option>' @@ -650,7 +650,7 @@ if ($mode == 'add') { $content .= '<div id="adressList" class="autocomplete"></div>'; $content .= '<script type="text/javascript">addEmailAdress(\'email\', \'adressList\', \'' .$_SESSION['config']['businessappurl'] - .'index.php?display=true&module=sendmail&page=adresss_autocomletion\', \'what\', \'2\');</script> '; + .'index.php?display=true&module=sendmail&page=address_autocompletion\', \'what\', \'2\');</script> '; $content .= '<select name="target" id="target">' .'<option id="target_target_to" value="to">'._SEND_TO_SHORT.'</option>' .'<option id="target_cc" value="cc">'._COPY_TO_SHORT.'</option>' diff --git a/modules/sendmail/mail_form_to_contact.php b/modules/sendmail/mail_form_to_contact.php index aff223ed0ae..5ee9a74b221 100755 --- a/modules/sendmail/mail_form_to_contact.php +++ b/modules/sendmail/mail_form_to_contact.php @@ -151,7 +151,7 @@ if ($mode == 'add') { $content .= '<div id="adressList" class="autocomplete"></div>'; $content .= '<script type="text/javascript">addEmailAdress(\'email\', \'adressList\', \'' .$_SESSION['config']['businessappurl'] - .'index.php?display=true&module=sendmail&page=adresss_autocomletion\', \'what\', \'2\');</script>'; + .'index.php?display=true&module=sendmail&page=address_autocompletion\', \'what\', \'2\');</script>'; $content .= ' <select name="target" id="target">' .'<option id="target_target_to" value="to">'._SEND_TO_SHORT.'</option>' .'<option id="target_cc" value="cc">'._COPY_TO_SHORT.'</option>' diff --git a/modules/sendmail/xml/IVS/requests_definitions.xml b/modules/sendmail/xml/IVS/requests_definitions.xml index 2c9805f632d..0566e21e217 100755 --- a/modules/sendmail/xml/IVS/requests_definitions.xml +++ b/modules/sendmail/xml/IVS/requests_definitions.xml @@ -35,7 +35,7 @@ <parameter name="display" value="true" /> </requestDefinition> <requestDefinition method="POST" path="/apps/maarch_entreprise/index.php" validationRule="adress_comletion" > - <parameter name="page" value="adresss_autocomletion"/> + <parameter name="page" value="address_autocompletion"/> <parameter name="module" value="sendmail"/> <parameter name="display" value="true" /> </requestDefinition> -- GitLab