Skip to content
Snippets Groups Projects
Commit 5e131976 authored by Laurent Destailleur's avatar Laurent Destailleur
Browse files

Simplification du cache de htmlform

parent abb57def
Branches
Tags
No related merge requests found
......@@ -44,14 +44,14 @@ class Form
var $db;
var $error;
var $cache_types_paiements_code=array();
var $cache_types_paiements_libelle=array();
var $cache_conditions_paiements_code=array();
var $cache_conditions_paiements_libelle=array();
// Cache arrays
var $cache_types_paiements=array();
var $cache_conditions_paiements=array();
var $tva_taux_value;
var $tva_taux_libelle;
/**
\brief Constructeur
\param DB handler d'accs base de donne
......@@ -1285,7 +1285,7 @@ class Form
{
global $langs;
if (sizeof($this->cache_conditions_paiements_code)) return 0; // Cache dja charg
if (sizeof($this->cache_conditions_paiements)) return 0; // Cache dja charg
dolibarr_syslog('Form::load_cache_conditions_paiements',LOG_DEBUG);
......@@ -1296,7 +1296,7 @@ class Form
$resql = $this->db->query($sql);
if ($resql)
{
$num = $this->db->num_rows($result);
$num = $this->db->num_rows($resql);
$i = 0;
while ($i < $num)
{
......@@ -1304,8 +1304,8 @@ class Form
// Si traduction existe, on l'utilise, sinon on prend le libell par dfaut
$libelle=($langs->trans("PaymentConditionShort".$obj->code)!=("PaymentConditionShort".$obj->code)?$langs->trans("PaymentConditionShort".$obj->code):($obj->libelle!='-'?$obj->libelle:''));
$this->cache_conditions_paiements_code[$obj->rowid]=$obj->code;
$this->cache_conditions_paiements_libelle[$obj->rowid]=$libelle;
$this->cache_conditions_paiements[$obj->rowid]['code'] =$obj->code;
$this->cache_conditions_paiements[$obj->rowid]['label']=$libelle;
$i++;
}
return 1;
......@@ -1324,7 +1324,7 @@ class Form
{
global $langs;
if (sizeof($this->cache_types_paiements_code)) return 0; // Cache dja charg
if (sizeof($this->cache_types_paiements)) return 0; // Cache dja charg
dolibarr_syslog('Form::load_cache_types_paiements',LOG_DEBUG);
......@@ -1335,7 +1335,7 @@ class Form
$resql = $this->db->query($sql);
if ($resql)
{
$num = $this->db->num_rows($result);
$num = $this->db->num_rows($resql);
$i = 0;
while ($i < $num)
{
......@@ -1343,9 +1343,9 @@ class Form
// Si traduction existe, on l'utilise, sinon on prend le libell par dfaut
$libelle=($langs->trans("PaymentTypeShort".$obj->code)!=("PaymentTypeShort".$obj->code)?$langs->trans("PaymentTypeShort".$obj->code):($obj->libelle!='-'?$obj->libelle:''));
$this->cache_types_paiements_code[$obj->id]=$obj->code;
$this->cache_types_paiements_libelle[$obj->id]=$libelle;
$this->cache_types_paiements_type[$obj->id]=$obj->type;
$this->cache_types_paiements[$obj->id]['code'] =$obj->code;
$this->cache_types_paiements[$obj->id]['label']=$libelle;
$this->cache_types_paiements[$obj->id]['type'] =$obj->type;
$i++;
}
return $num;
......@@ -1373,7 +1373,7 @@ class Form
print '<select class="flat" name="'.$htmlname.'">';
if ($addempty) print '<option value="0">&nbsp;</option>';
foreach($this->cache_conditions_paiements_code as $id => $code)
foreach($this->cache_conditions_paiements as $id => $arrayconditions)
{
if ($selected == $id)
{
......@@ -1383,39 +1383,12 @@ class Form
{
print '<option value="'.$id.'">';
}
print $this->cache_conditions_paiements_libelle[$id];
print $arrayconditions['label'];
print '</option>';
}
print '</select>';
}
/**
* \brief Selection HT ou TTC
* \param selected Id pr-slectionn
* \param htmlname Nom de la zone select
*/
function select_PriceBaseType($selected='',$htmlname='price_base_type')
{
global $langs;
print '<select class="flat" name="'.$htmlname.'">';
$options = array(
'HT'=>$langs->trans("HT"),
'TTC'=>$langs->trans("TTC")
);
foreach($options as $id => $value)
{
if ($selected == $id)
{
print '<option value="'.$id.'" selected="true">'.$value;
}
else
{
print '<option value="'.$id.'">'.$value;
}
print '</option>';
}
print '</select>';
}
/**
* \brief Retourne la liste des modes de paiements possibles
......@@ -1440,26 +1413,55 @@ class Form
print '<select class="flat" name="'.$htmlname.'">';
if ($empty) print '<option value="">&nbsp;</option>';
foreach($this->cache_types_paiements_code as $id => $code)
foreach($this->cache_types_paiements as $id => $arraytypes)
{
// On passe si on a demand de filtrer sur des modes de paiments particuliers
if (sizeof($filterarray) && ! in_array($this->cache_types_paiements_type[$id],$filterarray)) continue;
if (sizeof($filterarray) && ! in_array($arraytypes['type'],$filterarray)) continue;
if ($format == 0) print '<option value="'.$id.'"';
if ($format == 1) print '<option value="'.$code.'"';
if ($format == 2) print '<option value="'.$code.'"';
if ($format == 1) print '<option value="'.$arraytypes['code'].'"';
if ($format == 2) print '<option value="'.$arraytypes['code'].'"';
// Si selected est text, on compare avec code, sinon avec id
if (eregi('[a-z]', $selected) && $selected == $code) print ' selected="true"';
if (eregi('[a-z]', $selected) && $selected == $arraytypes['code']) print ' selected="true"';
elseif ($selected == $id) print ' selected="true"';
print '>';
if ($format == 0) $value=$this->cache_types_paiements_libelle[$id];
if ($format == 1) $value=$code;
if ($format == 2) $value=$this->cache_types_paiements_libelle[$id];
if ($format == 0) $value=$arraytypes['label'];
if ($format == 1) $value=$arraytypes['code'];
if ($format == 2) $value=$arraytypes['label'];
print $value?$value:'&nbsp;';
print '</option>';
}
print '</select>';
}
/**
* \brief Selection HT ou TTC
* \param selected Id pr-slectionn
* \param htmlname Nom de la zone select
*/
function select_PriceBaseType($selected='',$htmlname='price_base_type')
{
global $langs;
print '<select class="flat" name="'.$htmlname.'">';
$options = array(
'HT'=>$langs->trans("HT"),
'TTC'=>$langs->trans("TTC")
);
foreach($options as $id => $value)
{
if ($selected == $id)
{
print '<option value="'.$id.'" selected="true">'.$value;
}
else
{
print '<option value="'.$id.'">'.$value;
}
print '</option>';
}
print '</select>';
}
/**
* \brief Retourne la liste droulante des diffrents tats d'une propal.
* Les valeurs de la liste sont les id de la table c_propalst
......@@ -1904,7 +1906,7 @@ class Form
if ($selected)
{
$this->load_cache_conditions_paiements();
print $this->cache_conditions_paiements_libelle[$selected];
print $this->cache_conditions_paiements[$selected]['label'];
} else {
print "&nbsp;";
}
......@@ -1969,7 +1971,7 @@ class Form
if ($selected)
{
$this->load_cache_types_paiements();
print $this->cache_types_paiements_libelle[$selected];
print $this->cache_types_paiements[$selected]['label'];
} else {
print "&nbsp;";
}
......@@ -2150,7 +2152,7 @@ class Form
$sql = "SELECT code_iso, label, active FROM ".MAIN_DB_PREFIX."c_currencies";
$sql .= " WHERE active = 1";
$sql .= " ORDER BY code_iso ASC;";
$sql .= " ORDER BY code_iso ASC";
if ($this->db->query($sql))
{
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment