diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index dfb310c20f8..399985c4f2f 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -41,6 +41,8 @@ /** * Class to manage generation of HTML components * Only common components must be here. + * + * TODO Merge all function load_cache_* into one generic function */ class Form { @@ -101,7 +103,7 @@ class Form } } else - { + { $ret.='
| '; $ret.=$langs->trans($text); $ret.=' | '; @@ -712,22 +714,23 @@ class Form /** * Load into cache cache_types_fees, array of types of fees * - * @return int Nb of lines loaded, 0 if already loaded, <0 if ko - * TODO move in DAO class + * @return int Nb of lines loaded, <0 if KO */ function load_cache_types_fees() { global $langs; - $langs->load("trips"); + $num = count($this->cache_types_fees); + if ($num > 0) return 0; // Cache already loaded - if (count($this->cache_types_fees)) return 0; // Cache already load + dol_syslog(__METHOD__, LOG_DEBUG); + + $langs->load("trips"); $sql = "SELECT c.code, c.label"; $sql.= " FROM ".MAIN_DB_PREFIX."c_type_fees as c"; - //$sql.= " ORDER BY c.label ASC"; // No sort here, sort must be done after translation + $sql.= " WHERE active > 0"; - dol_syslog(get_class($this).'::load_cache_types_fees', LOG_DEBUG); $resql=$this->db->query($sql); if ($resql) { @@ -749,7 +752,7 @@ class Form return $num; } else - { + { dol_print_error($this->db); return -1; } @@ -767,7 +770,7 @@ class Form { global $user, $langs; - dol_syslog(get_class($this)."::select_type_fees ".$selected.", ".$htmlname, LOG_DEBUG); + dol_syslog(__METHOD__." selected=".$selected.", htmlname=".$htmlname, LOG_DEBUG); $this->load_cache_types_fees(); @@ -803,7 +806,7 @@ class Form * @param array $ajaxoptions Options for ajax_autocompleter * @param int $forcecombo Force to use combo box * @return string Return select box for thirdparty. - * @deprecated Use select_company instead. For exemple $form->select_thirdparty(GETPOST('socid'),'socid','',0) => $form->select_company(GETPOST('socid'),'socid','',1,0,0,array(),0) + * @deprecated 3.8 Use select_company instead. For exemple $form->select_thirdparty(GETPOST('socid'),'socid','',0) => $form->select_company(GETPOST('socid'),'socid','',1,0,0,array(),0) */ function select_thirdparty($selected='', $htmlname='socid', $filter='', $limit=20, $ajaxoptions=array(), $forcecombo=0) { @@ -2321,19 +2324,22 @@ class Form /** * Charge dans cache la liste des conditions de paiements possibles * - * @return int Nb lignes chargees, 0 si deja chargees, <0 si ko + * @return int Nb of lines loaded, <0 if KO */ function load_cache_conditions_paiements() { global $langs; - if (count($this->cache_conditions_paiements)) return 0; // Cache deja charge + $num = count($this->cache_conditions_paiements); + if ($num > 0) return 0; // Cache already loaded - $sql = "SELECT rowid, code, libelle"; + dol_syslog(__METHOD__, LOG_DEBUG); + + $sql = "SELECT rowid, code, libelle as label"; $sql.= " FROM ".MAIN_DB_PREFIX.'c_payment_term'; - $sql.= " WHERE active=1"; + $sql.= " WHERE active > 0"; $sql.= " ORDER BY sortorder"; - dol_syslog(get_class($this).'::load_cache_conditions_paiements', LOG_DEBUG); + $resql = $this->db->query($sql); if ($resql) { @@ -2344,14 +2350,18 @@ class Form $obj = $this->db->fetch_object($resql); // Si traduction existe, on l'utilise, sinon on prend le libelle par defaut - $libelle=($langs->trans("PaymentConditionShort".$obj->code)!=("PaymentConditionShort".$obj->code)?$langs->trans("PaymentConditionShort".$obj->code):($obj->libelle!='-'?$obj->libelle:'')); + $label=($langs->trans("PaymentConditionShort".$obj->code)!=("PaymentConditionShort".$obj->code)?$langs->trans("PaymentConditionShort".$obj->code):($obj->label!='-'?$obj->label:'')); $this->cache_conditions_paiements[$obj->rowid]['code'] =$obj->code; - $this->cache_conditions_paiements[$obj->rowid]['label']=$libelle; + $this->cache_conditions_paiements[$obj->rowid]['label']=$label; $i++; } - return 1; + + //$this->cache_conditions_paiements=dol_sort_array($this->cache_conditions_paiements, 'label'); // We use the sortorder + + return $num; } - else { + else + { dol_print_error($this->db); return -1; } @@ -2360,19 +2370,21 @@ class Form /** * Charge dans cache la liste des délais de livraison possibles * - * @return int Nb lignes chargees, 0 si deja chargees, <0 si ko + * @return int Nb of lines loaded, <0 if KO */ function load_cache_availability() { global $langs; - if (count($this->cache_availability)) return 0; // Cache deja charge + $num = count($this->cache_availability); + if ($num > 0) return 0; // Cache already loaded + + dol_syslog(__METHOD__, LOG_DEBUG); $sql = "SELECT rowid, code, label"; $sql.= " FROM ".MAIN_DB_PREFIX.'c_availability'; - $sql.= " WHERE active=1"; - $sql.= " ORDER BY rowid"; - dol_syslog(get_class($this).'::load_cache_availability', LOG_DEBUG); + $sql.= " WHERE active > 0"; + $resql = $this->db->query($sql); if ($resql) { @@ -2388,9 +2400,13 @@ class Form $this->cache_availability[$obj->rowid]['label']=$label; $i++; } - return 1; + + $this->cache_availability = dol_sort_array($this->cache_availability, 'label'); + + return $num; } - else { + else + { dol_print_error($this->db); return -1; } @@ -2411,6 +2427,8 @@ class Form $this->load_cache_availability(); + dol_syslog(__METHOD__." selected=".$selected.", htmlname=".$htmlname, LOG_DEBUG); + print '