diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 25a5596aa5d..8e03d9b32d8 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -1480,7 +1480,7 @@ class Form $outval.=$objRef.' ('.$objRefFourn.') - '; $opt.=dol_trunc($objp->label,18).' - '; $outval.=dol_trunc($label,18).' - '; - + if (! empty($objp->idprodfournprice)) { $currencytext=$langs->trans("Currency".$conf->currency); @@ -1488,24 +1488,28 @@ class Form if (dol_strlen($currencytext) > 10) $currencytext=$conf->currency; // If text is too long, we use the short code if (dol_strlen($currencytextnoent) > 10) $currencytextnoent=$conf->currency; // If text is too long, we use the short code - $opt.= price($objp->fprice).' '.$currencytext."/".$objp->quantity; - $outval.= price($objp->fprice).' '.$currencytextnoent."/".$objp->quantity; + $outqty=$objp->quantity; $outdiscount=$objp->remise_percent; if ($objp->quantity == 1) { - $opt.= strtolower($langs->trans("Unit")); - $outval.=strtolower($langs->transnoentities("Unit")); + $opt.= price($objp->fprice).' '.$currencytext."/"; + $outval.= price($objp->fprice).' '.$currencytextnoent."/"; + $opt.= $langs->trans("Unit"); // Do not use strtolower because it breaks utf8 encoding + $outval.=$langs->transnoentities("Unit"); } else { - $opt.= strtolower($langs->trans("Units")); - $outval.=strtolower($langs->transnoentities("Units")); + $opt.= price($objp->fprice).' '.$currencytext."/".$objp->quantity; + $outval.= price($objp->fprice).' '.$currencytextnoent."/".$objp->quantity; + $opt.= $langs->trans("Units"); // Do not use strtolower because it breaks utf8 encoding + $outval.=$langs->transnoentities("Units"); } + if ($objp->quantity >= 1) { - $opt.=" (".price($objp->unitprice).' '.$currencytext."/".strtolower($langs->trans("Unit")).")"; - $outval.=" (".price($objp->unitprice).' '.$currencytextnoent."/".strtolower($langs->transnoentities("Unit")).")"; + $opt.=" (".price($objp->unitprice).' '.$currencytext."/".$langs->trans("Unit").")"; // Do not use strtolower because it breaks utf8 encoding + $outval.=" (".price($objp->unitprice).' '.$currencytextnoent."/".$langs->transnoentities("Unit").")"; // Do not use strtolower because it breaks utf8 encoding } if ($objp->remise_percent >= 1) { @@ -1529,13 +1533,22 @@ class Form $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, 'qty'=>$outqty, 'discount'=>$outdiscount, 'disabled'=>(empty($objp->idprodfournprice)?true:false))); - + // Exemple of var_dump $outjson + // array(1) {[0]=>array(6) {[key"]=>string(1) "2" ["value"]=>string(3) "ppp" + // ["label"]=>string(76) "ppp (fff2) - ppp - 20,00 Euros/1unité (20,00 Euros/unité)" + // ["qty"]=>string(1) "1" ["discount"]=>string(1) "0" ["disabled"]=>bool(false) + //} + //var_dump($outval); var_dump(utf8_check($outval)); var_dump(json_encode($outval)); + //$outval=array('label'=>'ppp (fff2) - ppp - 20,00 Euros/ Unité (20,00 Euros/unité)'); + //var_dump($outval); var_dump(utf8_check($outval)); var_dump(json_encode($outval)); + $i++; } $outselect.=''; diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 2fc74e99f60..a576079919e 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -446,6 +446,30 @@ function dol_escape_htmltag($stringtoescape,$keepb=0) return dol_htmlentities($tmp,ENT_COMPAT,'UTF-8'); } + +/** + * Convert a string to lower. Never use strtolower because it does not works with UTF8 strings. + * + * @param string $utf8_string String to encode + * @return string String converted + */ +function dol_strtolower($utf8_string) +{ + return mb_strtolower($utf8_string, "UTF-8"); +} + +/** + * Convert a string to upper. Never use strtolower because it does not works with UTF8 strings. + * + * @param string $utf8_string String to encode + * @return string String converted + */ +function dol_strtoupper($utf8_string) +{ + return mb_strtoupper($utf8_string, "UTF-8"); +} + + /** * Write log message into outputs. Possible outputs can be: * A file if SYSLOG_FILE_ON defined: file name is then defined by SYSLOG_FILE diff --git a/htdocs/core/lib/json.lib.php b/htdocs/core/lib/json.lib.php index cf3fa89c655..aca24a5810b 100644 --- a/htdocs/core/lib/json.lib.php +++ b/htdocs/core/lib/json.lib.php @@ -33,7 +33,8 @@ if (! function_exists('json_encode')) */ function json_encode($elements) { - return dol_json_encode($elements); + return 'ttt'; + //return dol_json_encode($elements); } }