diff --git a/ChangeLog b/ChangeLog index 9ca1cc847e7..b6de1a1d94f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -85,6 +85,7 @@ For developers: - New: Add hook addHomeSetup. - New: Add trigger CATEGORY_LINK and CATEGORY_UNLINK. - New: A trigger can return an array of error strings instead of one error string. +- New: Add method to use a dictionnary as a combo box. WARNING: Following change may create regression for some external modules, but was necessary to make Dolibarr better: diff --git a/htdocs/core/class/html.formother.class.php b/htdocs/core/class/html.formother.class.php index 15bb2f9acf5..1ee016c6ee7 100644 --- a/htdocs/core/class/html.formother.class.php +++ b/htdocs/core/class/html.formother.class.php @@ -1084,6 +1084,67 @@ class FormOther } + /** + * Return a HTML select list of bank accounts + * + * @param string $htmlname Name of select zone + * @param string $dictionnarytable Dictionnary table + * @param string $keyfield Field for key + * @param string $labelfield Label field + * @param int $useempty 1=Add an empty value in list, 2=Add an empty value in list only if there is more than 2 entries. + * @return void + */ + function select_dictionnary($htmlname,$dictionnarytable,$keyfield='code',$labelfield='label',$selected='',$useempty=0) + { + global $langs, $conf; + + $langs->load("admin"); + + $sql = "SELECT rowid, ".$keyfield.", ".$labelfield; + $sql.= " FROM ".MAIN_DB_PREFIX.$dictionnarytable; + $sql.= " ORDER BY ".$labelfield; + + dol_syslog(get_class($this)."::select_dictionnary sql=".$sql); + $result = $this->db->query($sql); + if ($result) + { + $num = $this->db->num_rows($result); + $i = 0; + if ($num) + { + print '"; + } + else + { + print $langs->trans("DictionnaryEmpty"); + } + } + else { + dol_print_error($this->db); + } + } + } ?>