diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php
index 60ff30c6433..664997129df 100644
--- a/htdocs/core/class/html.form.class.php
+++ b/htdocs/core/class/html.form.class.php
@@ -931,36 +931,40 @@ class Form
/**
* Output html form to select a third party
*
- * @param string $selected Preselected type
- * @param string $htmlname Name of field in form
- * @param string $filter optional filters criteras (example: 's.rowid <> x', 's.client IN (1,3)')
- * @param string $showempty Add an empty field (Can be '1' or text key to use on empty line like 'SelectThirdParty')
- * @param int $showtype Show third party type in combolist (customer, prospect or supplier)
- * @param int $forcecombo Force to use combo box
- * @param array $events Ajax event options to run on change. Example: array(array('method'=>'getContacts', 'url'=>dol_buildpath('/core/ajax/contacts.php',1), 'htmlname'=>'contactid', 'params'=>array('add-customer-contact'=>'disabled')))
- * @param int $limit Maximum number of elements
- * @param string $morecss Add more css styles to the SELECT component
- * @param string $moreparam Add more parameters onto the select tag. For example 'style="width: 95%"' to avoid select2 component to go over parent container
- * @return string HTML string with select box for thirdparty.
+ * @param string $selected Preselected type
+ * @param string $htmlname Name of field in form
+ * @param string $filter optional filters criteras (example: 's.rowid <> x', 's.client IN (1,3)')
+ * @param string $showempty Add an empty field (Can be '1' or text key to use on empty line like 'SelectThirdParty')
+ * @param int $showtype Show third party type in combolist (customer, prospect or supplier)
+ * @param int $forcecombo Force to use combo box
+ * @param array $events Ajax event options to run on change. Example: array(array('method'=>'getContacts', 'url'=>dol_buildpath('/core/ajax/contacts.php',1), 'htmlname'=>'contactid', 'params'=>array('add-customer-contact'=>'disabled')))
+ * @param int $limit Maximum number of elements
+ * @param string $morecss Add more css styles to the SELECT component
+ * @param string $moreparam Add more parameters onto the select tag. For example 'style="width: 95%"' to avoid select2 component to go over parent container
+ * @param string $selected_input_value Value of preselected input text (for use with ajax)
+ * @param int $hidelabel Hide label (0=no, 1=yes, 2=show search icon (before) and placeholder, 3 search icon after)
+ * @param array $ajaxoptions Options for ajax_autocompleter
+ * @return string HTML string with select box for thirdparty.
*/
- function select_company($selected='', $htmlname='socid', $filter='', $showempty='', $showtype=0, $forcecombo=0, $events=array(), $limit=0, $morecss='minwidth100', $moreparam='')
+ function select_company($selected='', $htmlname='socid', $filter='', $showempty='', $showtype=0, $forcecombo=0, $events=array(), $limit=0, $morecss='minwidth100', $moreparam='', $selected_input_value='', $hidelabel=1, $ajaxoptions=array())
{
+ global $conf,$user,$langs;
+
$out='';
- /* TODO Use ajax_autocompleter like for products (not finished)
if (! empty($conf->use_javascript_ajax) && ! empty($conf->global->COMPANY_USE_SEARCH_TO_SELECT) && ! $forcecombo)
{
$placeholder='';
-
if ($selected && empty($selected_input_value))
{
- require_once DOL_DOCUMENT_ROOT.'/societe/ajaxcompanies.php';
- $societe = new Societe($this->db);
- $societe->fetch($selected);
- $selected_input_value=$societe->ref;
+ require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
+ $societetmp = new Societe($this->db);
+ $societetmp->fetch($selected);
+ $selected_input_value=$societetmp->name;
+ unset($societetmp);
}
- // mode=1 means customers products
- $urloption='htmlname='.$htmlname.'&outjson=1&price_level='.$price_level.'&type='.$filtertype.'&mode=1&status='.$status.'&finished='.$finished;
+ // mode 1
+ $urloption='htmlname='.$htmlname.'&outjson=1&filter='.$filter;
print ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT.'/societe/ajax/company.php', $urloption, $conf->global->COMPANY_USE_SEARCH_TO_SELECT, 0, $ajaxoptions);
if (empty($hidelabel)) print $langs->trans("RefOrLabel").' : ';
else if ($hidelabel > 1) {
@@ -970,15 +974,15 @@ class Form
print img_picto($langs->trans("Search"), 'search');
}
}
- print '';
+ print 'global->THIRDPARTY_SEARCH_AUTOFOCUS) ? 'autofocus' : '').' />';
if ($hidelabel == 3) {
print img_picto($langs->trans("Search"), 'search');
}
}
else
- {*/
+ {
$out.=$this->select_thirdparty_list($selected, $htmlname, $filter, $showempty, $showtype, $forcecombo, $events, '', 0, $limit, $morecss, $moreparam);
- //}
+ }
return $out;
}
@@ -1004,7 +1008,8 @@ class Form
{
global $conf,$user,$langs;
- $out=''; $num=0;
+ $out='';
+ $num=0;
$outarray=array();
// On recherche les societes
@@ -1020,19 +1025,18 @@ class Form
if ($filterkey && $filterkey != '')
{
$sql.=" AND (";
- if (! empty($conf->global->COMPANY_DONOTSEARCH_ANYWHERE)) // Can use index
- {
- $sql.="(s.name LIKE '".$this->db->escape($filterkey)."%')";
+ $prefix=empty($conf->global->COMPANY_DONOTSEARCH_ANYWHERE)?'%':''; // Can use index if COMPANY_DONOTSEARCH_ANYWHERE is on
+ // For natural search
+ $scrit = explode(' ', $filterkey);
+ $i=0;
+ if (count($scrit) > 1) $sql.="(";
+ foreach ($scrit as $crit) {
+ if ($i > 0) $sql.=" AND ";
+ $sql.="(s.nom LIKE '".$this->db->escape($prefix.$crit)."%')";
+ $i++;
}
- else
- {
- // For natural search
- $scrit = explode(' ', $filterkey);
- foreach ($scrit as $crit) {
- $sql.=" AND (s.name LIKE '%".$this->db->escape($crit)."%')";
- }
- }
- if (! empty($conf->barcode->enabled))
+ if (count($scrit) > 1) $sql.=")";
+ if (! empty($conf->barcode->enabled))
{
$sql .= " OR s.barcode LIKE '".$this->db->escape($filterkey)."%'";
}
@@ -1041,20 +1045,22 @@ class Form
$sql.=$this->db->order("nom","ASC");
if ($limit > 0) $sql.=$this->db->plimit($limit);
+ // Build output string
dol_syslog(get_class($this)."::select_thirdparty_list", LOG_DEBUG);
$resql=$this->db->query($sql);
if ($resql)
{
+ $events = null;
+
if ($conf->use_javascript_ajax && ! $forcecombo)
{
include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
$comboenhancement =ajax_combobox($htmlname, $events, $conf->global->COMPANY_USE_SEARCH_TO_SELECT);
$out.= $comboenhancement;
- $nodatarole=($comboenhancement?' data-role="none"':'');
}
// Construct $out and $outarray
- $out.= '