diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php
index d68d9c8d59f..d753803dc54 100644
--- a/htdocs/core/class/html.form.class.php
+++ b/htdocs/core/class/html.form.class.php
@@ -655,6 +655,72 @@ class Form
if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionnarySetup"),1);
}
+
+ /**
+ * Return list of company for customer in Ajax if Ajax activated or go to select_thirparty_list
+ *
+ * @param int $selected Preselected products
+ * @param string $htmlname Name of HTML seletc field (must be unique in page)
+ * @param int $filtertype Filter on product type (''=nofilter, 0=product, 1=service)
+ * @param int $limit Limit on number of returned lines
+ * @param array $ajaxoptions Options for ajax_autocompleter
+ * @return void
+ */
+ function select_thirdparty($selected='', $htmlname='productid', $filtertype='', $limit=20, $ajaxoptions=array())
+ {
+ global $langs,$conf;
+
+ if (! empty($conf->use_javascript_ajax) && ! empty($conf->global->COMPANY_USE_SEARCH_TO_SELECT))
+ {
+ $placeholder='';
+
+ if ($selected && empty($selected_input_value))
+ {
+ require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
+ $societe = new Societe($this->db);
+ $societe->fetch($selected);
+ $selected_input_value=$societe->ref;
+ }
+ // mode=1 means customers products
+ $urloption='htmlname='.$htmlname.'&outjson=1&price_level='.$price_level.'&type='.$filtertype.'&mode=1&status='.$status.'&finished='.$finished;
+ 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) {
+ if (! empty($conf->global->MAIN_HTML5_PLACEHOLDER)) $placeholder=' placeholder="'.$langs->trans("RefOrLabel").'"';
+ else $placeholder=' title="'.$langs->trans("RefOrLabel").'"';
+ if ($hidelabel == 2) {
+ print img_picto($langs->trans("Search"), 'search');
+ }
+ }
+ print '';
+ if ($hidelabel == 3) {
+ print img_picto($langs->trans("Search"), 'search');
+ }
+ }
+ else
+ {
+ print $this->select_thirdparty_list($selected,$htmlname,$filtertype,1,0,1,array(),'',0,$limit);
+ }
+ }
+
+ /**
+ * Output html form to select a third party
+ *
+ * @param string $selected Preselected type
+ * @param string $htmlname Name of field in form
+ * @param string $filter Optionnal filters criteras (example: 's.rowid <> x')
+ * @param int $showempty Add an empty field
+ * @param int $showtype Show third party type in combolist (customer, prospect or supplier)
+ * @param int $forcecombo Force to use combo box
+ * @param array $event Event options. Example: array(array('method'=>'getContacts', 'url'=>dol_buildpath('/core/ajax/contacts.php',1), 'htmlname'=>'contactid', 'params'=>array('add-customer-contact'=>'disabled')))
+ * @return string HTML string with
+ * @deprecated Use select_thirdparty instead
+ */
+ function select_company($selected='',$htmlname='socid',$filter='',$showempty=0, $showtype=0, $forcecombo=0, $event=array())
+ {
+ return $this->select_thirdparty_list($selected='',$htmlname='socid',$filter='',$showempty=0, $showtype=0, $forcecombo=0, $event=array());
+ }
+
/**
* Output html form to select a third party
*
@@ -665,13 +731,17 @@ class Form
* @param int $showtype Show third party type in combolist (customer, prospect or supplier)
* @param int $forcecombo Force to use combo box
* @param array $event Event options. Example: array(array('method'=>'getContacts', 'url'=>dol_buildpath('/core/ajax/contacts.php',1), 'htmlname'=>'contactid', 'params'=>array('add-customer-contact'=>'disabled')))
+ * @param string $filterkey Filter on key value
+ * @param int $outputmode 0=HTML select string, 1=Array
+ * @param int $limit Limit number of answers
* @return string HTML string with
*/
- function select_company($selected='',$htmlname='socid',$filter='',$showempty=0, $showtype=0, $forcecombo=0, $event=array())
+ function select_thirdparty_list($selected='',$htmlname='socid',$filter='',$showempty=0, $showtype=0, $forcecombo=0, $event=array(), $filterkey='', $outputmode=0, $limit=20)
{
global $conf,$user,$langs;
$out='';
+ $outarray=array();
// On recherche les societes
$sql = "SELECT s.rowid, s.nom, s.client, s.fournisseur, s.code_client, s.code_fournisseur";
@@ -682,9 +752,33 @@ class Form
if ($filter) $sql.= " AND (".$filter.")";
if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
if (! empty($conf->global->COMPANY_HIDE_INACTIVE_IN_COMBOBOX)) $sql.= " AND s.status<>0 ";
+ // Add criteria
+ if ($filterkey && $filterkey != '')
+ {
+ $sql.=" AND (";
+ if (! empty($conf->global->COMPANY_DONOTSEARCH_ANYWHERE)) // Can use index
+ {
+ $sql.="(s.name LIKE '".$filterkey."%'";
+ $sql.=")";
+ }
+ else
+ {
+ // For natural search
+ $scrit = explode(' ', $filterkey);
+ foreach ($scrit as $crit) {
+ $sql.=" AND (s.name LIKE '%".$crit."%'";
+ $sql.=")";
+ }
+ }
+ if (! empty($conf->barcode->enabled))
+ {
+ $sql .= " OR s.barcode LIKE '".$filterkey."'";
+ }
+ $sql.=")";
+ }
$sql.= " ORDER BY nom ASC";
- dol_syslog(get_class($this)."::select_company sql=".$sql);
+ dol_syslog(get_class($this)."::select_thirdparty_list sql=".$sql);
$resql=$this->db->query($sql);
if ($resql)
{
@@ -692,32 +786,9 @@ class Form
{
//$minLength = (is_numeric($conf->global->COMPANY_USE_SEARCH_TO_SELECT)?$conf->global->COMPANY_USE_SEARCH_TO_SELECT:2);
$out.= ajax_combobox($htmlname, $event, $conf->global->COMPANY_USE_SEARCH_TO_SELECT);
- /*
-<<<<<<< HEAD
- if ($selected && empty($selected_input_value))
- {
- require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
- $product = new Product($this->db);
- $product->fetch($selected);
- $selected_input_value=$product->ref;
- }
-=======
- if ($selected && empty($selected_input_value))
- {
- require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
- $product = new Product($this->db);
- $product->fetch($selected);
- $selected_input_value=$product->ref;
- }
->>>>>>> refs/remotes/origin/3.3
- // mode=1 means customers products
- $ajaxoptions=array();
- $urloption='htmlname='.$htmlname.'&outjson=1&filter='.urlencode($filter).'&showtype='.$showtype;
- $out.=ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT.'/societe/ajax/company.php', $urloption, $conf->global->COMPANY_USE_SEARCH_TO_SELECT, 0, $ajaxoptions);
- $out.='';
- */
}
+ // Construct $out and $outarray
$out.= '