New: Add method to use a dictionnary as a combo box.
This commit is contained in:
parent
2bf4a2bdb8
commit
9a475e9ed2
@ -85,6 +85,7 @@ For developers:
|
|||||||
- New: Add hook addHomeSetup.
|
- New: Add hook addHomeSetup.
|
||||||
- New: Add trigger CATEGORY_LINK and CATEGORY_UNLINK.
|
- New: Add trigger CATEGORY_LINK and CATEGORY_UNLINK.
|
||||||
- New: A trigger can return an array of error strings instead of one error string.
|
- 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
|
WARNING: Following change may create regression for some external modules, but was necessary to make
|
||||||
Dolibarr better:
|
Dolibarr better:
|
||||||
|
|||||||
@ -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 '<select id="select'.$htmlname.'" class="flat selectdictionnary" name="'.$htmlname.'"'.($moreattrib?' '.$moreattrib:'').'>';
|
||||||
|
if ($useempty == 1 || ($useempty == 2 && $num > 1))
|
||||||
|
{
|
||||||
|
print '<option value="-1"> </option>';
|
||||||
|
}
|
||||||
|
|
||||||
|
while ($i < $num)
|
||||||
|
{
|
||||||
|
$obj = $this->db->fetch_object($result);
|
||||||
|
if ($selected == $obj->rowid || $selected == $obj->$keyfield)
|
||||||
|
{
|
||||||
|
print '<option value="'.$obj->$keyfield.'" selected="selected">';
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
print '<option value="'.$obj->$keyfield.'">';
|
||||||
|
}
|
||||||
|
print $obj->$labelfield;
|
||||||
|
print '</option>';
|
||||||
|
$i++;
|
||||||
|
}
|
||||||
|
print "</select>";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
print $langs->trans("DictionnaryEmpty");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
dol_print_error($this->db);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user