Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/Dolibarr/dolibarr into d…
Browse files Browse the repository at this point in the history
…evelop
  • Loading branch information
eldy committed Oct 31, 2011
2 parents dd02900 + eeedf86 commit 7c7d03b
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 26 deletions.
89 changes: 64 additions & 25 deletions htdocs/core/class/html.form.class.php
Expand Up @@ -49,6 +49,7 @@ class Form
var $cache_conditions_paiements=array();
var $cache_availability=array();
var $cache_demand_reason=array();
var $cache_type_fees=array();

var $tva_taux_value;
var $tva_taux_libelle;
Expand Down Expand Up @@ -518,18 +519,65 @@ function select_type_of_lines($selected='',$htmlname='type',$showempty=0,$hidete
}

}

/**
* 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
*/
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
* Return list of types of notes
*
* @param selected Preselected type
* @param htmlname Name of field in form
* @param showempty Add an empty field
* @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)
{
global $db,$langs,$user;
$langs->load("trips");
global $user, $langs;

dol_syslog(get_class($this)."::select_type_fees ".$selected.", ".$htmlname, LOG_DEBUG);

$this->load_cache_types_fees();

print '<select class="flat" name="'.$htmlname.'">';
if ($showempty)
Expand All @@ -538,26 +586,16 @@ function select_type_fees($selected='',$htmlname='type',$showempty=0)
if ($selected == -1) print ' selected="selected"';
print '>&nbsp;</option>';
}

$sql = "SELECT c.code, c.libelle as type FROM ".MAIN_DB_PREFIX."c_type_fees as c";
$sql.= " ORDER BY lower(c.libelle) ASC";
$resql=$db->query($sql);
if ($resql)

foreach($this->cache_types_fees as $key => $value)
{
$num = $db->num_rows($resql);
$i = 0;

while ($i < $num)
{
$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 '<option value="'.$key.'"';
if ($key == $selected) print ' selected="selected"';
print '>';
print $value;
print '</option>';
}

print '</select>';
if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionnarySetup"),1);
}
Expand Down Expand Up @@ -1744,7 +1782,8 @@ function load_cache_types_paiements()
}
return $num;
}
else {
else
{
dol_print_error($this->db);
return -1;
}
Expand Down
1 change: 0 additions & 1 deletion htdocs/custom

This file was deleted.

0 comments on commit 7c7d03b

Please sign in to comment.