New: Le choix de la devise principale se fait par liste droulante
This commit is contained in:
parent
2496a80138
commit
6024f76094
@ -52,6 +52,7 @@ if (isset($_POST["action"]) && $_POST["action"] == 'update')
|
||||
|
||||
|
||||
llxHeader();
|
||||
|
||||
$form = new Form($db);
|
||||
|
||||
print_titre($langs->trans("GlobalSetup"));
|
||||
@ -78,7 +79,8 @@ if (isset($_GET["action"]) && $_GET["action"] == 'edit')
|
||||
print '</td></tr>';
|
||||
|
||||
print '<tr class="impair"><td>'.$langs->trans("CompanyCurrency").'</td><td>';
|
||||
print '<input name="currency" value="'. MAIN_MONNAIE . '"></td></tr>';
|
||||
$form->select_currency(MAIN_MONNAIE,"currency");
|
||||
print '</td></tr>';
|
||||
|
||||
print '<tr class="pair"><td width="50%">'.$langs->trans("Capital").'</td><td>';
|
||||
print '<input name="capital" size="20" value="' . MAIN_INFO_CAPITAL . '"></td></tr>';
|
||||
@ -144,10 +146,12 @@ else
|
||||
print '<tr class="impair"><td width="50%">'.$langs->trans("CompanyName").'</td><td>' . MAIN_INFO_SOCIETE_NOM . '</td></tr>';
|
||||
|
||||
print '<tr class="pair"><td>'.$langs->trans("Country").'</td><td>';
|
||||
print $form->pays_name(MAIN_INFO_SOCIETE_PAYS);
|
||||
print $form->pays_name(MAIN_INFO_SOCIETE_PAYS,1);
|
||||
print '</td></tr>';
|
||||
|
||||
print '<tr class="impair"><td width="50%">'.$langs->trans("CompanyCurrency").'</td><td>' . MAIN_MONNAIE . '</td></tr>';
|
||||
print '<tr class="impair"><td width="50%">'.$langs->trans("CompanyCurrency").'</td><td>';
|
||||
print $form->currency_name(MAIN_MONNAIE,1);
|
||||
print '</td></tr>';
|
||||
|
||||
print '<tr class="pair"><td width="50%">'.$langs->trans("Capital").'</td><td>';
|
||||
print MAIN_INFO_CAPITAL . '</td></tr>';
|
||||
|
||||
@ -680,31 +680,69 @@ class Form
|
||||
|
||||
|
||||
/**
|
||||
* \brief Retourne le nom d'un pays
|
||||
* \param id id du pays
|
||||
* \brief Retourne le nom traduit ou code+nom d'un pays
|
||||
* \param id id du pays
|
||||
* \param withcode 1=affiche code + nom
|
||||
* \return string Nom traduit du pays
|
||||
*/
|
||||
function pays_name($id)
|
||||
{
|
||||
$sql = "SELECT rowid, libelle FROM ".MAIN_DB_PREFIX."c_pays";
|
||||
$sql .= " WHERE rowid=$id;";
|
||||
|
||||
if ($this->db->query($sql))
|
||||
{
|
||||
$num = $this->db->num_rows();
|
||||
|
||||
if ($num)
|
||||
{
|
||||
$obj = $this->db->fetch_object();
|
||||
return $obj->libelle;
|
||||
}
|
||||
else
|
||||
{
|
||||
return "Non défini";
|
||||
}
|
||||
function pays_name($id,$withcode=0)
|
||||
{
|
||||
global $langs;
|
||||
|
||||
$sql = "SELECT rowid, code, libelle FROM ".MAIN_DB_PREFIX."c_pays";
|
||||
$sql.= " WHERE rowid=$id;";
|
||||
|
||||
if ($this->db->query($sql))
|
||||
{
|
||||
$num = $this->db->num_rows();
|
||||
|
||||
if ($num)
|
||||
{
|
||||
$obj = $this->db->fetch_object();
|
||||
$label=$obj->code && $langs->trans("Country".$obj->code)!="Country".$obj->code?$langs->trans("Country".$obj->code):($obj->libelle!='-'?$obj->libelle:'');
|
||||
if ($withcode) return $label==$obj->code?"$obj->code":"$obj->code - $label";
|
||||
else return $label;
|
||||
}
|
||||
else
|
||||
{
|
||||
return $langs->trans("NotDefined");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Retourne le nom traduit ou code+nom d'une devise
|
||||
* \param code_iso Code iso de la devise
|
||||
* \param withcode 1=affiche code + nom
|
||||
* \return string Nom traduit de la devise
|
||||
*/
|
||||
function currency_name($code_iso,$withcode=0)
|
||||
{
|
||||
global $langs;
|
||||
|
||||
$sql = "SELECT label FROM ".MAIN_DB_PREFIX."c_currencies";
|
||||
$sql.= " WHERE code_iso='$code_iso';";
|
||||
|
||||
if ($this->db->query($sql))
|
||||
{
|
||||
$num = $this->db->num_rows();
|
||||
|
||||
if ($num)
|
||||
{
|
||||
$obj = $this->db->fetch_object();
|
||||
$label=$langs->trans("Currency".$obj->code_iso)!="Currency".$obj->code_iso?$langs->trans("Currency".$obj->code_iso):($obj->label!='-'?$obj->label:'');
|
||||
if ($withcode) return $label==$code_iso?"$code_iso":"$code_iso - $label";
|
||||
else return $label;
|
||||
}
|
||||
else
|
||||
{
|
||||
return $code_iso;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
@ -735,6 +773,60 @@ class Form
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* \brief Retourne la liste des devies, dans la langue de l'utilisateur
|
||||
* \param selected code devise pré-sélectionnée
|
||||
* \param htmlname nom de la liste deroulante
|
||||
* \todo trier liste sur noms après traduction plutot que avant
|
||||
*/
|
||||
function select_currency($selected='',$htmlname='currency_id')
|
||||
{
|
||||
global $conf,$langs;
|
||||
$langs->load("dict");
|
||||
|
||||
if ($selected=='euro' || $selected=='euros') $selected='EUR'; // Pour compatibilité
|
||||
|
||||
$sql = "SELECT code_iso, label, active FROM ".MAIN_DB_PREFIX."c_currencies";
|
||||
$sql .= " WHERE active = 1";
|
||||
$sql .= " ORDER BY code_iso ASC;";
|
||||
|
||||
if ($this->db->query($sql))
|
||||
{
|
||||
print '<select class="flat" name="'.$htmlname.'">';
|
||||
$num = $this->db->num_rows();
|
||||
$i = 0;
|
||||
if ($num)
|
||||
{
|
||||
$foundselected=false;
|
||||
while ($i < $num)
|
||||
{
|
||||
$obj = $this->db->fetch_object();
|
||||
if ($selected && $selected == $obj->code_iso)
|
||||
{
|
||||
$foundselected=true;
|
||||
print '<option value="'.$obj->code_iso.'" selected>';
|
||||
}
|
||||
else
|
||||
{
|
||||
print '<option value="'.$obj->code_iso.'">';
|
||||
}
|
||||
// Si traduction existe, on l'utilise, sinon on prend le libellé par défaut
|
||||
if ($obj->code_iso) { print $obj->code_iso . ' - '; }
|
||||
print ($obj->code_iso && $langs->trans("Currency".$obj->code_iso)!="Currency".$obj->code_iso?$langs->trans("Currency".$obj->code_iso):($obj->label!='-'?$obj->label:''));
|
||||
print '</option>';
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
print '</select>';
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
dolibarr_print_error($this->db);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* \brief Selection du taux de tva
|
||||
* \param name Nom champ html
|
||||
|
||||
Loading…
Reference in New Issue
Block a user