diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php
index 7b153182b93..576d10b01bd 100644
--- a/htdocs/core/class/html.form.class.php
+++ b/htdocs/core/class/html.form.class.php
@@ -49,6 +49,7 @@ class Form
var $cache_availability=array();
var $cache_demand_reason=array();
var $cache_type_fees=array();
+ var $cache_currencies=array();
var $tva_taux_value;
var $tva_taux_libelle;
@@ -2713,6 +2714,52 @@ class Form
{
print $this->selectcurrency($selected,$htmlname);
}
+
+ /**
+ * Charge dans cache la liste des devises
+ *
+ * @return int Nb lignes chargees, 0 si deja chargees, <0 si ko
+ */
+ function load_cache_currencies()
+ {
+ global $langs;
+
+ $langs->load("dict");
+
+ if (count($this->cache_currencies)) return 0; // Cache deja charge
+
+ $sql = "SELECT code, code_iso, label";
+ $sql.= " FROM ".MAIN_DB_PREFIX."c_currencies";
+ $sql.= " WHERE active = 1";
+ $sql.= " ORDER BY code_iso ASC";
+
+ dol_syslog('Form::load_cache_currencies sql='.$sql, LOG_DEBUG);
+ $resql = $this->db->query($sql);
+ if ($resql)
+ {
+ $num = $this->db->num_rows($resql);
+ $i = 0;
+ while ($i < $num)
+ {
+ $obj = $this->db->fetch_object($resql);
+
+ // Si traduction existe, on l'utilise, sinon on prend le libelle par defaut
+ $this->cache_currencies[$obj->code]['code_iso'] = $obj->code_iso;
+ $this->cache_currencies[$obj->code]['label'] = ($obj->code_iso && $langs->trans("Currency".$obj->code_iso)!="Currency".$obj->code_iso?$langs->trans("Currency".$obj->code_iso):($obj->label!='-'?$obj->label:''));
+ $label[$obj->code] = $this->cache_currencies[$obj->code]['label'];
+ $i++;
+ }
+
+ array_multisort($label, SORT_ASC, $this->cache_currencies);
+
+ return $num;
+ }
+ else
+ {
+ dol_print_error($this->db);
+ return -1;
+ }
+ }
/**
* Retourne la liste des devises, dans la langue de l'utilisateur
@@ -2725,58 +2772,31 @@ class Form
global $conf,$langs,$user;
$langs->load("dict");
+
+ $this->load_cache_currencies();
$out='';
- $currencyArray=array();
- $label=array();
if ($selected=='euro' || $selected=='euros') $selected='EUR'; // Pour compatibilite
- $sql = "SELECT code_iso, label";
- $sql.= " FROM ".MAIN_DB_PREFIX."c_currencies";
- $sql.= " WHERE active = 1";
- $sql.= " ORDER BY code_iso ASC";
-
- $resql=$this->db->query($sql);
- if ($resql)
+ $out.= '';
+ if ($user->admin) $out.= info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionnarySetup"),1);
+ return $out;
}
/**