From 921aac798ed451da364376d36cd00efbaaaa300f Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 11 Oct 2010 21:32:53 +0000 Subject: [PATCH] Fix: Use a better way to bold search criteria (no use of javascript regex, but use php regex). Usage of * was making javascript crazy. Fix: When field is manually cleaned, we must also clean hidden fields. New: Can define number of char before showing first answer --- htdocs/admin/societe.php | 8 +++---- htdocs/core/class/html.form.class.php | 2 +- htdocs/langs/en_US/admin.lang | 2 +- htdocs/langs/fr_FR/admin.lang | 2 +- htdocs/lib/ajax.lib.php | 32 ++++++++++++++++++--------- htdocs/societe/ajaxcompanies.php | 32 +++++++++++++++++++-------- 6 files changed, 52 insertions(+), 26 deletions(-) diff --git a/htdocs/admin/societe.php b/htdocs/admin/societe.php index df6f8256d13..bde1f3f3e00 100644 --- a/htdocs/admin/societe.php +++ b/htdocs/admin/societe.php @@ -63,9 +63,9 @@ if ($_GET["action"] == 'setcodecompta') } } -if ($_POST["action"] == 'usesearchtoselectcompany') +if ($_POST["action"] == 'COMPANY_USE_SEARCH_TO_SELECT') { - if (dolibarr_set_const($db, "COMPANY_USE_SEARCH_TO_SELECT", $_POST["activate_usesearchtoselectcompany"],'chaine',0,'',$conf->entity)) + if (dolibarr_set_const($db, "COMPANY_USE_SEARCH_TO_SELECT", $_POST["activate_COMPANY_USE_SEARCH_TO_SELECT"],'chaine',0,'',$conf->entity)) { Header("Location: ".$_SERVER["PHP_SELF"]); exit; @@ -452,7 +452,7 @@ print ' '."\n"; $var=!$var; print '
'; print ''; -print ''; +print ''; print ""; print ''.$langs->trans("UseSearchToSelectCompany").''; if (! $conf->use_javascript_ajax) @@ -464,7 +464,7 @@ if (! $conf->use_javascript_ajax) else { print ''; - print $html->selectyesno("activate_usesearchtoselectcompany",$conf->global->COMPANY_USE_SEARCH_TO_SELECT,1); + print $html->selectyesno("activate_COMPANY_USE_SEARCH_TO_SELECT",$conf->global->COMPANY_USE_SEARCH_TO_SELECT,1); print ''; print ''; print ""; diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 4f64b689aea..3490b381483 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -922,7 +922,7 @@ class Form } if (strval($filtertype) != '') $sql.=" AND p.fk_product_type=".$filtertype; // Add criteria on ref/label - if (! empty($conf->global->PRODUCT_DONOTSEARCH_ANYWHERE)) + if (! empty($conf->global->PRODUCT_DONOTSEARCH_ANYWHERE)) // Can use index { if ($filterkey && $filterkey != '') { diff --git a/htdocs/langs/en_US/admin.lang b/htdocs/langs/en_US/admin.lang index 504d74f4bcf..43b5186dbc7 100644 --- a/htdocs/langs/en_US/admin.lang +++ b/htdocs/langs/en_US/admin.lang @@ -45,7 +45,7 @@ ErrorDecimalLargerThanAreForbidden=Error, a precision higher than %s is n DictionnarySetup=Dictionary setup DisableJavascript=Disable JavaScript and Ajax functions ConfirmAjax=Use Ajax confirmation popups -UseSearchToSelectCompany=Use a search form to choose a company (instead of using a list box) +UseSearchToSelectCompany=Use a search form to choose a company (instead of using a list box).
Also if you have a large number of third parties (> 100 000), you can increase speed by setting constant SOCIETE_DONOTSEARCH_ANYWHERE to 1 in Setup->Other. Search will then be limited to start of string. ViewFullDateActions=Show full dates actions in the third sheet NotAvailableWhenAjaxDisabled=Not available when Ajax disabled JavascriptDisabled=JavaScript disabled diff --git a/htdocs/langs/fr_FR/admin.lang b/htdocs/langs/fr_FR/admin.lang index 8c23247e3c9..36ae8968f2b 100644 --- a/htdocs/langs/fr_FR/admin.lang +++ b/htdocs/langs/fr_FR/admin.lang @@ -45,7 +45,7 @@ ErrorDecimalLargerThanAreForbidden= Erreur, les précisions supérieures à % DictionnarySetup= Dictionnaires DisableJavascript= Désactiver les fonctions Javascript et Ajax ConfirmAjax= Utiliser les popups de confirmation Ajax -UseSearchToSelectCompany= Utiliser un formulaire de recherche pour le choix d'un tiers (plutôt qu'une liste déroulante) +UseSearchToSelectCompany= Utiliser un formulaire de recherche pour le choix d'un tiers (plutôt qu'une liste déroulante).
Notez que si vous avez un nombre important de produits ou services (> 100 000), vous pouvez améliorer les performances en définissant la constante SOCIETE_DONOTSEARCH_ANYWHERE à 1 dans Configuration->Divers. La recherche sera alors limitée au début de la chaine. ViewFullDateActions= Visualiser les dates des actions en entier dans la fiche tiers NotAvailableWhenAjaxDisabled= Non disponible quand Ajax désactivé JavascriptDisabled= Javascript désactivé diff --git a/htdocs/lib/ajax.lib.php b/htdocs/lib/ajax.lib.php index d65fd0e9c26..74b54df8cd9 100644 --- a/htdocs/lib/ajax.lib.php +++ b/htdocs/lib/ajax.lib.php @@ -82,6 +82,8 @@ function ajax_updater($htmlname,$keysearch,$url,$option='',$indicator='working') */ function ajax_autocompleter($selected='',$htmlname,$url,$option='') { + global $conf; + $script=''; $script.= ''; @@ -89,17 +91,27 @@ function ajax_autocompleter($selected='',$htmlname,$url,$option='') $script.= ''; - + $msg.= "\n"; - + return $msg; } diff --git a/htdocs/societe/ajaxcompanies.php b/htdocs/societe/ajaxcompanies.php index 544c50a7347..0b36ad4d777 100644 --- a/htdocs/societe/ajaxcompanies.php +++ b/htdocs/societe/ajaxcompanies.php @@ -55,7 +55,7 @@ dol_syslog(join(',',$_GET)); if (! empty($_GET['newcompany']) || ! empty($_GET['socid']) || ! empty($_GET['id_fourn'])) { $return_arr = array(); - + // Define filter on text typed $socid = $_GET['newcompany']?$_GET['newcompany']:''; if (! $socid) $socid = $_GET['socid']?$_GET['socid']:''; @@ -66,10 +66,21 @@ if (! empty($_GET['newcompany']) || ! empty($_GET['socid']) || ! empty($_GET['id $sql.= " WHERE s.entity = ".$conf->entity; if ($socid) { - $sql.=" AND (nom LIKE '%" . $socid . "%'"; - $sql.=" OR code_client LIKE '%" . $socid . "%'"; - $sql.=" OR code_fournisseur LIKE '%" . $socid . "%'"; - if ($conf->global->SOCIETE_ALLOW_SEARCH_ON_ROWID) $sql.=" OR rowid = '" . $socid . "'"; + $sql.=" AND ("; + // Add criteria on name/code + if (! empty($conf->global->SOCIETE_DONOTSEARCH_ANYWHERE)) // Can use index + { + $sql.="nom LIKE '" . $db->escape($socid) . "%'"; + $sql.=" OR code_client LIKE '" . $db->escape($socid) . "%'"; + $sql.=" OR code_fournisseur LIKE '" . $db->escape($socid) . "%'"; + } + else + { + $sql.="nom LIKE '%" . $db->escape($socid) . "%'"; + $sql.=" OR code_client LIKE '%" . $db->escape($socid) . "%'"; + $sql.=" OR code_fournisseur LIKE '%" . $db->escape($socid) . "%'"; + } + if ($conf->global->SOCIETE_ALLOW_SEARCH_ON_ROWID) $sql.=" OR rowid = '" . $db->escape($socid) . "'"; $sql.=")"; } if (! empty($_GET["filter"])) $sql.= " AND ".$_GET["filter"]; // Add other filters @@ -79,14 +90,17 @@ if (! empty($_GET['newcompany']) || ! empty($_GET['socid']) || ! empty($_GET['id $resql=$db->query($sql); if ($resql) { - while ($row = $db->fetch_array($resql)) { - $row_array['label'] = $row['nom']; + while ($row = $db->fetch_array($resql)) + { + $label=$row['nom']; + if ($socid) $label=preg_replace('/('.preg_quote($socid).')/','$1',$label,1); + $row_array['label'] = $label; $row_array['value'] = $row['nom']; $row_array['key'] = $row['rowid']; - + array_push($return_arr,$row_array); } - + echo json_encode($return_arr); } }