diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php
index a6147a78791..45c2f47fffc 100644
--- a/htdocs/core/class/html.form.class.php
+++ b/htdocs/core/class/html.form.class.php
@@ -835,13 +835,14 @@ class Form
if ($conf->global->PRODUIT_USE_SEARCH_TO_SELECT)
{
- if ($conf->global->MAIN_USE_JQUERY)
+ if ($conf->global->MAIN_USE_NEW_JQUERY)
{
- print ajax_autocompleter2('',$htmlname,DOL_URL_ROOT.'/product/ajaxproducts.php','&price_level='.$price_level.'&type='.$filtertype.'&mode=1&status='.$status.'&finished='.$finished,'');
+ // mode=1 means customers products
+ print ajax_autocompleter2('',$htmlname,DOL_URL_ROOT.'/product/ajaxproducts.php','outjson=1&price_level='.$price_level.'&type='.$filtertype.'&mode=1&status='.$status.'&finished='.$finished,'');
print '
';
- print ''.$langs->trans("RefOrLabel").': ';
- print ' ';
+ print ''.$langs->trans("RefOrLabel").': ';
+ print ' ';
print '
';
}
else
@@ -863,7 +864,7 @@ class Form
}
else
{
- $this->select_produits_do($selected,$htmlname,$filtertype,$limit,$price_level,'',$status,$finished);
+ $this->select_produits_do($selected,$htmlname,$filtertype,$limit,$price_level,'',$status,$finished,0);
}
}
@@ -876,8 +877,11 @@ class Form
* \param price_level Level of price to show
* \param filterkey Filter on product
* \param status -1=Return all products, 0=Products not on sell, 1=Products on sell
+ * \param finished Filter on finished field: 2=No filter
+ * \param disableout Disable print output
+ * \return array Array of keys for json
*/
- function select_produits_do($selected='',$htmlname='productid',$filtertype='',$limit=20,$price_level=0,$filterkey='',$status=1,$finished=2)
+ function select_produits_do($selected='',$htmlname='productid',$filtertype='',$limit=20,$price_level=0,$filterkey='',$status=1,$finished=2,$disableout=0)
{
global $langs,$conf,$user,$db;
@@ -940,7 +944,7 @@ class Form
// Build output string
$outselect='';
- $outjson='';
+ $outjson=array();
dol_syslog("Form::select_produits_do search product sql=".$sql, LOG_DEBUG);
$result=$this->db->query($sql);
@@ -951,7 +955,7 @@ class Form
$outselect.='use_javascript_ajax && $num && $conf->global->PRODUIT_USE_SEARCH_TO_SELECT) $outselect.=' onchange="publish_selvalue(this);"';
$outselect.='>';
-
+
if ($conf->use_javascript_ajax)
{
if (! $num)
@@ -971,11 +975,18 @@ class Form
$i = 0;
while ($num && $i < $num)
{
+ $outkey='';
+ $outval='';
+ $outref='';
+
$objp = $this->db->fetch_object($result);
$label=$objp->label;
if (! empty($objp->label_translated)) $label=$objp->label_translated;
+ $outkey=$objp->rowid;
+ $outref=$objp->ref;
+
$opt = 'rowid == $selected)?' selected="true"':'';
if ($conf->stock->enabled && $objp->fk_product_type == 0 && isset($objp->stock))
@@ -989,12 +1000,15 @@ class Form
$opt.= ' style="background-color:#FF0000; color:#F5F5F5;"';
}
}
- $opt.= '>'.$objp->ref.' - ';
- $opt.= dol_trunc($label,32).' - ';
+ $opt.= '>';
+ $opt.= $langs->convToOutputCharset($objp->ref).' - '.$langs->convToOutputCharset(dol_trunc($label,32)).' - ';
+ $outval.=$objp->ref.' - '.dol_trunc($label,32).' - ';
$found=0;
$currencytext=$langs->trans("Currency".$conf->monnaie);
+ $currencytextnoent=$langs->transnoentities("Currency".$conf->monnaie);
if (strlen($currencytext) > 10) $currencytext=$conf->monnaie; // If text is too long, we use the short code
+ if (strlen($currencytextnoent) > 10) $currencytextnoent=$conf->monnaie; // If text is too long, we use the short code
// Multiprice
if ($price_level >= 1) // If we need a particular price level (from 1 to 6)
@@ -1015,9 +1029,15 @@ class Form
{
$found=1;
if ($objp2->price_base_type == 'HT')
- $opt.= price($objp2->price,1).' '.$currencytext.' '.$langs->trans("HT");
+ {
+ $opt.= price($objp2->price,1).' '.$currencytext.' '.$langs->trans("HT");
+ $outval.= price($objp2->price,1).' '.$currencytextnoent.' '.$langs->transnoentities("HT");
+ }
else
- $opt.= price($objp2->price_ttc,1).' '.$currencytext.' '.$langs->trans("TTC");
+ {
+ $opt.= price($objp2->price_ttc,1).' '.$currencytext.' '.$langs->trans("TTC");
+ $outval.= price($objp2->price_ttc,1).' '.$currencytextnoent.' '.$langs->transnoentities("TTC");
+ }
}
}
else
@@ -1030,14 +1050,21 @@ class Form
if (! $found)
{
if ($objp->price_base_type == 'HT')
- $opt.= price($objp->price,1).' '.$currencytext.' '.$langs->trans("HT");
+ {
+ $opt.= price($objp->price,1).' '.$currencytext.' '.$langs->trans("HT");
+ $outval.= price($objp->price,1).' '.$currencytextnoent.' '.$langs->transnoentities("HT");
+ }
else
- $opt.= price($objp->price_ttc,1).' '.$currencytext.' '.$langs->trans("TTC");
+ {
+ $opt.= price($objp->price_ttc,1).' '.$currencytext.' '.$langs->trans("TTC");
+ $outval.= price($objp->price_ttc,1).' '.$currencytextnoent.' '.$langs->transnoentities("TTC");
+ }
}
if ($conf->stock->enabled && isset($objp->stock) && $objp->fk_product_type == 0)
{
$opt.= ' - '.$langs->trans("Stock").':'.$objp->stock;
+ $outval.=' - '.$langs->transnoentities("Stock").':'.$objp->stock;
}
if ($objp->duration)
@@ -1053,10 +1080,17 @@ class Form
$dur=array("h"=>$langs->trans("Hour"),"d"=>$langs->trans("Day"),"w"=>$langs->trans("Week"),"m"=>$langs->trans("Month"),"y"=>$langs->trans("Year"));
}
$opt.= ' - '.$duration_value.' '.$langs->trans($dur[$duration_unit]);
+ $outval.=' - '.$duration_value.' '.$langs->transnoentities($dur[$duration_unit]);
}
$opt.= " \n";
+
+ // Add new entry
+ // "key" value of json key array is used by jQuery automatically as selected value
+ // "label" value of json key array is used by jQuery automatically as text for combo box
$outselect.=$opt;
+ array_push($outjson,array('key'=>$outkey,'value'=>$outref,'label'=>$outval));
+
$i++;
}
@@ -1064,7 +1098,8 @@ class Form
$this->db->free($result);
- print $outselect;
+ if (empty($disableout)) print $outselect;
+ return $outjson;
}
else
{
@@ -1085,12 +1120,25 @@ class Form
global $langs,$conf;
if ($conf->global->PRODUIT_USE_SEARCH_TO_SELECT)
{
- print $langs->trans("RefOrLabel").' : ';
- print ajax_updater($htmlname,'keysearch',DOL_URL_ROOT.'/product/ajaxproducts.php','&socid='.$socid.'&type='.$filtertype.'&mode=2','working');
+ if ($conf->global->MAIN_USE_NEW_JQUERY)
+ {
+ // mode=2 means suppliers products
+ print ajax_autocompleter2('',$htmlname,DOL_URL_ROOT.'/product/ajaxproducts.php','outjson=1&price_level='.$price_level.'&type='.$filtertype.'&mode=2&status='.$status.'&finished='.$finished,'');
+
+ print '';
+ print ''.$langs->trans("RefOrLabel").': ';
+ print ' ';
+ print '
';
+ }
+ else
+ {
+ print $langs->trans("RefOrLabel").' : ';
+ print ajax_updater($htmlname,'keysearch',DOL_URL_ROOT.'/product/ajaxproducts.php','&socid='.$socid.'&type='.$filtertype.'&mode=2','working');
+ }
}
else
{
- $this->select_produits_fournisseurs_do($socid,$selected,$htmlname,$filtertype,$filtre,'');
+ $this->select_produits_fournisseurs_do($socid,$selected,$htmlname,$filtertype,$filtre,'',-1,0);
}
}
@@ -1101,9 +1149,12 @@ class Form
* \param htmlname Nom de la zone select
* \param filtertype Filter on product type (''=nofilter, 0=product, 1=service)
* \param filtre Pour filtre sql
- * \param filterkey Filtre des produits si ajax est utilise
+ * \param filterkey Filtre des produits
+ * \param status -1=Return all products, 0=Products not on sell, 1=Products on sell
+ * \param disableout Disable print output
+ * \return array Array of keys for json
*/
- function select_produits_fournisseurs_do($socid,$selected='',$htmlname='productid',$filtertype='',$filtre='',$filterkey='')
+ function select_produits_fournisseurs_do($socid,$selected='',$htmlname='productid',$filtertype='',$filtre='',$filterkey='',$statut=-1,$disableout=0)
{
global $langs,$conf;
@@ -1135,7 +1186,7 @@ class Form
// Build output string
$outselect='';
- $outjson='';
+ $outjson=array();
dol_syslog("Form::select_produits_fournisseurs_do sql=".$sql,LOG_DEBUG);
$result=$this->db->query($sql);
@@ -1168,44 +1219,72 @@ class Form
$i = 0;
while ($i < $num)
{
+ $outkey='';
+ $outval='';
+ $outref='';
+
$objp = $this->db->fetch_object($result);
+ $outkey=$objp->idprodfournprice;
+ $outref=$objp->ref;
+
$opt = 'idprodfournprice) $opt.= ' selected="true"';
if ($objp->fprice == '') $opt.=' disabled="disabled"';
- $opt.= '>'.$objp->ref.' ('.$objp->ref_fourn.') - ';
- $opt.= dol_trunc($objp->label,18).' - ';
+ $opt.= '>';
+
+ $opt.=$langs->convToOutputCharset($objp->ref).' ('.$langs->convToOutputCharset($objp->ref_fourn).') - ';
+ $outval.=$objp->ref.' ('.$objp->ref_fourn.') - ';
+ $opt.=$langs->convToOutputCharset(dol_trunc($objp->label,18)).' - ';
+ $outval.=dol_trunc($objp->label,18).' - ';
+
if ($objp->fprice != '') // Keep != ''
{
$currencytext=$langs->trans("Currency".$conf->monnaie);
- if (strlen($currencytext) > 10) $currencytext=$conf->monnaie; // If text is too long, we use the short code
+ $currencytextnoent=$langs->transnoentities("Currency".$conf->monnaie);
+ if (strlen($currencytext) > 10) $currencytext=$conf->monnaie; // If text is too long, we use the short code
+ if (strlen($currencytextnoent) > 10) $currencytextnoent=$conf->monnaie; // If text is too long, we use the short code
- $opt.= price($objp->fprice);
- $opt.= ' '.$currencytext."/".$objp->quantity;
+ $opt.= price($objp->fprice).' '.$currencytext."/".$objp->quantity;
+ $outval.= price($objp->fprice).' '.$currencytextnoent."/".$objp->quantity;
if ($objp->quantity == 1)
{
$opt.= strtolower($langs->trans("Unit"));
+ $outval.=strtolower($langs->transnoentities("Unit"));
}
else
{
$opt.= strtolower($langs->trans("Units"));
+ $outval.=strtolower($langs->transnoentities("Units"));
}
if ($objp->quantity >= 1)
{
- $opt.=" (";
- $opt.= price($objp->unitprice).' '.$currencytext."/".strtolower($langs->trans("Unit"));
- $opt.=")";
+ $opt.=" (".price($objp->unitprice).' '.$currencytext."/".strtolower($langs->trans("Unit")).")";
+ $outval.=" (".price($objp->unitprice).' '.$currencytextnoent."/".strtolower($langs->transnoentities("Unit")).")";
+ }
+ if ($objp->duration)
+ {
+ $opt .= " - ".$objp->duration;
+ $outval.=" - ".$objp->duration;
+ }
+ if (! $socid)
+ {
+ $opt .= " - ".dol_trunc($objp->nom,8);
+ $outval.=" - ".dol_trunc($objp->nom,8);
}
- if ($objp->duration) $opt .= " - ".$objp->duration;
- if (! $socid) $opt .= " - ".dol_trunc($objp->nom,8);
}
else
{
$opt.= $langs->trans("NoPriceDefinedForThisSupplier");
+ $outval.=$langs->transnoentities("NoPriceDefinedForThisSupplier");
}
$opt .= " \n";
+ // Add new entry
+ // "key" value of json key array is used by jQuery automatically as selected value
+ // "label" value of json key array is used by jQuery automatically as text for combo box
$outselect.=$opt;
+ array_push($outjson,array('key'=>$outkey,'value'=>$outref,'label'=>$outval));
$i++;
}
@@ -1213,7 +1292,8 @@ class Form
$this->db->free($result);
- print $outselect;
+ if (empty($disableout)) print $outselect;
+ return $outjson;
}
else
{
diff --git a/htdocs/lib/ajax.lib.php b/htdocs/lib/ajax.lib.php
index 9c8b254bcef..e49af4db173 100644
--- a/htdocs/lib/ajax.lib.php
+++ b/htdocs/lib/ajax.lib.php
@@ -156,23 +156,22 @@ function ajax_autocompleter($selected='',$htmlname,$url,$indicator='working')
*/
function ajax_autocompleter2($selected='', $htmlname, $url, $option='')
{
- $script = ' ';
+ $script = ' ';
$script.= '';
return $script;
diff --git a/htdocs/main.inc.php b/htdocs/main.inc.php
index b43baeaa292..f6a11acb930 100644
--- a/htdocs/main.inc.php
+++ b/htdocs/main.inc.php
@@ -777,7 +777,14 @@ function top_htmlhead($head, $title='', $disablejs=0, $disablehead=0, $arrayofjs
else print "".$appli." ";
print "\n";
- // Output style sheets (optioncss='print' or '')
+ if (! defined('DISABLE_JQUERY'))
+ {
+ print ''."\n";
+ print ' '."\n";
+ }
+
+ print ''."\n";
+ // Output style sheets (optioncss='print' or '')
print ' '."\n";
// CSS forced by modules (relative url starting with /)
if (is_array($conf->css_modules))
@@ -796,12 +803,6 @@ function top_htmlhead($head, $title='', $disablejs=0, $disablehead=0, $arrayofjs
}
}
- if (! defined('DISABLE_JQUERY'))
- {
- print ''."\n";
- print ' '."\n";
- }
-
if (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) print ' '."\n";
if (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) print ' '."\n";
if (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) print ' '."\n";
diff --git a/htdocs/product/ajaxproducts.php b/htdocs/product/ajaxproducts.php
index 937053187c8..db7697c05e2 100644
--- a/htdocs/product/ajaxproducts.php
+++ b/htdocs/product/ajaxproducts.php
@@ -55,40 +55,32 @@ $langs->load("main");
dol_syslog(join(',',$_POST));
-// Generation liste de produits
-if (! empty($_GET['keysearch']) || ! empty($_GET['term']))
+if (! isset($_GET['keysearch']) && ! isset($_GET['term'])) return;
+
+// When used from jQuery, the search term is added as GET param "term".
+$searchkey=isset($_GET['keysearch'])?$_GET['keysearch']:$_GET['term'];
+$outjson=isset($_GET['outjson'])?$_GET['outjson']:0;
+
+// Get list of product.
+//var_dump($_GET); exit;
+//print $_GET["price_level"]; exit;
+$status=-1;
+if (isset($_GET['status'])) $status=$_GET['status'];
+
+$form = new Form($db);
+if (empty($_GET['mode']) || $_GET['mode'] == 1)
{
- //var_dump($_GET); exit;
- //print $_GET["price_level"]; exit;
- $status=-1;
- if (isset($_GET['status'])) $status=$_GET['status'];
- $form = new Form($db);
- if (empty($_GET['mode']) || $_GET['mode'] == 1)
- {
- $form->select_produits_do("",$_GET["htmlname"],$_GET["type"],"",$_GET["price_level"],$_GET["keysearch"],$status);
- }
- if ($_GET['mode'] == 2)
- {
- $form->select_produits_fournisseurs_do($_GET["socid"],"",$_GET["htmlname"],$_GET["type"],"",$_GET["keysearch"]);
- }
+ $arrayresult=$form->select_produits_do("",$_GET["htmlname"],$_GET["type"],"",$_GET["price_level"],$searchkey,$status,2,$outjson);
}
-else if (! empty($_GET['markup']))
+if ($_GET['mode'] == 2)
{
- print $_GET['markup'];
- //print $_GET['count'];
- //$field = " ";
- //print ' ';
- //print $field;
-}
-else if (! empty($_GET['selling']))
-{
- //print $_GET['markup'];
- //print $_GET['count'];
- print ' ';
+ $arrayresult=$form->select_produits_fournisseurs_do($_GET["socid"],"",$_GET["htmlname"],$_GET["type"],"",$searchkey,$statut,$outjson);
}
$db->close();
+if ($outjson) print json_encode($arrayresult);
+
//print "