Merge branch 'develop' of https://github.com/Dolibarr/dolibarr into develop

This commit is contained in:
Laurent Destailleur 2011-10-31 12:03:52 +01:00
commit 7c7d03b718
2 changed files with 64 additions and 26 deletions

View File

@ -49,6 +49,7 @@ class Form
var $cache_conditions_paiements=array(); var $cache_conditions_paiements=array();
var $cache_availability=array(); var $cache_availability=array();
var $cache_demand_reason=array(); var $cache_demand_reason=array();
var $cache_type_fees=array();
var $tva_taux_value; var $tva_taux_value;
var $tva_taux_libelle; var $tva_taux_libelle;
@ -520,16 +521,63 @@ class Form
} }
/** /**
* Return list of types of notes * Load into cache cache_types_fees, array of types of fees
* *
* @param selected Preselected type * @return int Nb of lines loaded, 0 if already loaded, <0 if ko
* @param htmlname Name of field in form * TODO move in DAO class
* @param showempty Add an empty field */
function load_cache_types_fees()
{
global $langs;
$langs->load("trips");
if (count($this->cache_types_fees)) return 0; // Cache already load
$sql = "SELECT c.code, c.libelle as label";
$sql.= " FROM ".MAIN_DB_PREFIX."c_type_fees as c";
$sql.= " ORDER BY lower(c.libelle) ASC";
dol_syslog(get_class($this).'::load_cache_types_fees 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
$label=($obj->code != $langs->trans($obj->code) ? $langs->trans($obj->code) : $langs->trans($obj->label));
$this->cache_types_fees[$obj->code] = $label;
$i++;
}
return $num;
}
else
{
dol_print_error($this->db);
return -1;
}
}
/**
* Return list of types of notes
*
* @param string $selected Preselected type
* @param string $htmlname Name of field in form
* @param int $showempty Add an empty field
* @return void
*/ */
function select_type_fees($selected='',$htmlname='type',$showempty=0) function select_type_fees($selected='',$htmlname='type',$showempty=0)
{ {
global $db,$langs,$user; global $user, $langs;
$langs->load("trips");
dol_syslog(get_class($this)."::select_type_fees ".$selected.", ".$htmlname, LOG_DEBUG);
$this->load_cache_types_fees();
print '<select class="flat" name="'.$htmlname.'">'; print '<select class="flat" name="'.$htmlname.'">';
if ($showempty) if ($showempty)
@ -539,25 +587,15 @@ class Form
print '>&nbsp;</option>'; print '>&nbsp;</option>';
} }
$sql = "SELECT c.code, c.libelle as type FROM ".MAIN_DB_PREFIX."c_type_fees as c"; foreach($this->cache_types_fees as $key => $value)
$sql.= " ORDER BY lower(c.libelle) ASC";
$resql=$db->query($sql);
if ($resql)
{ {
$num = $db->num_rows($resql); print '<option value="'.$key.'"';
$i = 0; if ($key == $selected) print ' selected="selected"';
print '>';
while ($i < $num) print $value;
{ print '</option>';
$obj = $db->fetch_object($resql);
print '<option value="'.$obj->code.'"';
if ($obj->code == $selected) print ' selected="selected"';
print '>';
if ($obj->code != $langs->trans($obj->code)) print $langs->trans($obj->code);
else print $langs->trans($obj->type);
$i++;
}
} }
print '</select>'; print '</select>';
if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionnarySetup"),1); if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionnarySetup"),1);
} }
@ -1744,7 +1782,8 @@ class Form
} }
return $num; return $num;
} }
else { else
{
dol_print_error($this->db); dol_print_error($this->db);
return -1; return -1;
} }

View File

@ -1 +0,0 @@
/home/ldestail/git/nltechno/htdocs