Trad: Mcanique de traduction des listes droulantes des dictionnaires de donnes.

This commit is contained in:
Laurent Destailleur 2004-09-18 16:36:33 +00:00
parent a0f6fa1c26
commit f00ac2232f
2 changed files with 212 additions and 167 deletions

View File

@ -3,7 +3,6 @@
* Copyright (C) 2004 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be>
* Copyright (C) 2004 Sebastien Di Cintio <sdicintio@ressource-toi.org>
* Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -23,15 +22,28 @@
* $Source$
*/
/*!
\file htdocs/html.form.class.php
\brief Fichier de la classe des fonctions prédéfinie de composants html
\version $Revision$
*/
/*! \class Form
\brief Classe permettant la génération de composants html
*/
class Form
{
var $db;
var $errorstr;
/*
* \brief Constructeur
* \param DB handler d'accès base de donnée
*/
function Form($DB)
{
$this->db = $DB;
return 1;
@ -47,6 +59,9 @@ class Form
*/
function select_departement($selected='',$htmlname='departement_id')
{
global $conf,$langs;
$langs->load("dict");
// On recherche les départements/cantons/province active d'une region et pays actif
$sql = "SELECT d.rowid, d.code_departement as code , d.nom, d.active, p.libelle as libelle_pays, p.code as code_pays FROM ";
$sql .= MAIN_DB_PREFIX ."c_departements as d, ".MAIN_DB_PREFIX."c_regions as r,".MAIN_DB_PREFIX."c_pays as p";
@ -55,44 +70,47 @@ class Form
$sql .= "ORDER BY code_pays, code ASC";
if ($this->db->query($sql))
{
print '<select name="'.$htmlname.'">';
$num = $this->db->num_rows();
$i = 0;
if ($num)
{
$pays='';
while ($i < $num)
{
$obj = $this->db->fetch_object( $i);
if ($obj->code == 0) {
print '<option value="0">&nbsp;</option>';
}
else {
if ($pays == '' || $pays != $obj->libelle_pays) {
// Affiche la rupture
print '<option value="-1">----- '.$obj->libelle_pays." -----</option>\n";
$pays=$obj->libelle_pays;
}
if ($selected > 0 && $selected == $obj->rowid)
{
print '<option value="'.$obj->code.'" selected>['.$obj->code.'] '.$obj->nom.'</option>';
}
else
{
print '<option value="'.$obj->code.'">['.$obj->code.'] '.$obj->nom.'</option>';
}
}
$i++;
}
}
print '</select>';
}
else {
dolibarr_print_error($this->db);
{
print '<select name="'.$htmlname.'">';
$num = $this->db->num_rows();
$i = 0;
if ($num)
{
$pays='';
while ($i < $num)
{
$obj = $this->db->fetch_object( $i);
if ($obj->code == 0) {
print '<option value="0">&nbsp;</option>';
}
else {
if ($pays == '' || $pays != $obj->libelle_pays) {
// Affiche la rupture
print '<option value="-1">----- '.$obj->libelle_pays." -----</option>\n";
$pays=$obj->libelle_pays;
}
if ($selected > 0 && $selected == $obj->rowid)
{
print '<option value="'.$obj->rowid.'" selected>';
}
else
{
print '<option value="'.$obj->rowid.'">';
}
# Si traduction existe, on l'utilise, sinon on prend le libellé par défaut
print '['.$obj->code.'] '.($langs->trans($obj->code)!=$obj->code?$langs->trans($obj->code):($obj->nom!='-'?$obj->nom:''));
print '</option>';
}
$i++;
}
}
print '</select>';
}
}
else {
dolibarr_print_error($this->db);
}
}
/*
* \brief Retourne la liste déroulante des regions actives dont le pays est actif
@ -103,6 +121,9 @@ class Form
*/
function select_region($selected='',$htmlname='region_id')
{
global $conf,$langs;
$langs->load("dict");
$sql = "SELECT r.rowid, r.code_region as code, r.nom as libelle, r.active, p.libelle as libelle_pays FROM ".MAIN_DB_PREFIX."c_regions as r, ".MAIN_DB_PREFIX."c_pays as p";
$sql .= " WHERE r.fk_pays=p.rowid AND r.active = 1 and p.active = 1 ORDER BY libelle_pays, libelle ASC";
@ -147,37 +168,53 @@ class Form
}
/*
* \brief Retourne la liste déroulante des pays actifs
*
* \brief Retourne la liste déroulante des pays actifs, dans la langue de l'utilisateur
* \param selected code pays pré-sélectionné
* \param htmlname nom de la liste deroulante
*/
function select_pays($selected='',$htmlname='pays_id')
{
$sql = "SELECT rowid, libelle, active FROM ".MAIN_DB_PREFIX."c_pays";
$sql .= " WHERE active = 1 ORDER BY libelle ASC;";
global $conf,$langs;
$langs->load("dict");
$sql = "SELECT rowid, libelle, code, active FROM ".MAIN_DB_PREFIX."c_pays";
$sql .= " WHERE active = 1";
$sql .= " ORDER BY libelle ASC;";
if ($this->db->query($sql))
{
print '<select name="'.$htmlname.'">';
$num = $this->db->num_rows();
$i = 0;
if ($num)
{
while ($i < $num)
{
$obj = $this->db->fetch_object( $i);
if ($selected == $obj->rowid)
{
print '<option value="'.$obj->rowid.'" selected>'.$obj->libelle.'</option>';
}
else
{
print '<option value="'.$obj->rowid.'">'.$obj->libelle.'</option>';
}
$i++;
}
}
print '</select>';
}
{
print '<select name="'.$htmlname.'">';
$num = $this->db->num_rows();
$i = 0;
if ($num)
{
$foundselected=false;
while ($i < $num)
{
$obj = $this->db->fetch_object( $i);
if ($selected > 0 && $selected == $obj->rowid)
{
$foundselected=true;
print '<option value="'.$obj->rowid.'" selected>';
}
else
{
print '<option value="'.$obj->rowid.'">';
}
# Si traduction existe, on l'utilise, sinon on prend le libellé par défaut
print ($langs->trans($obj->code)!=$obj->code?$langs->trans($obj->code):($obj->libelle!='-'?$obj->libelle:''));
if ($obj->code) { print ' ('.$obj->code.')'; }
print '</option>';
$i++;
}
}
print '</select>';
return 0;
}
else {
dolibarr_print_error($this->db);
return 1;
}
}
@ -324,45 +361,48 @@ class Form
/*
* Retourne la liste déroulante des civilite actives
*
* \brief Retourne la liste déroulante des civilite actives
* \param selected civilite pré-sélectionnée
*/
function select_civilite($selected='')
{
global $conf;
global $conf,$langs;
$langs->load("dict");
$sql = "SELECT rowid, code, civilite, active FROM ".MAIN_DB_PREFIX."c_civilite";
$sql .= " WHERE active = 1";
$sql .= " AND lang='".$conf->langage."'";
if ($this->db->query($sql))
{
print '<select name="civilite_id">';
$num = $this->db->num_rows();
$i = 0;
if ($num)
{
while ($i < $num)
{
$obj = $this->db->fetch_object( $i);
if ($selected == $obj->rowid)
{
print '<option value="'.$obj->code.'" selected>'.$obj->civilite.'</option>';
}
else
{
print '<option value="'.$obj->code.'">'.$obj->civilite.'</option>';
}
$i++;
}
}
print '</select>';
}
{
print '<select name="civilite_id">';
$num = $this->db->num_rows();
$i = 0;
if ($num)
{
while ($i < $num)
{
$obj = $this->db->fetch_object( $i);
if ($selected == $obj->rowid)
{
print '<option value="'.$obj->code.'" selected>';
}
else
{
print '<option value="'.$obj->code.'">';
}
# Si traduction existe, on l'utilise, sinon on prend le libellé par défaut
print ($langs->trans($obj->code)!=$obj->code?$langs->trans($obj->code):($obj->civilite!='-'?$obj->civilite:''));
print '</option>';
$i++;
}
}
print '</select>';
}
else {
dolibarr_print_error($this->db);
}
dolibarr_print_error($this->db);
}
}
/*
@ -370,57 +410,65 @@ class Form
* avec un affichage avec rupture sur le pays
*
*/
function select_forme_juridique($selected='')
function select_forme_juridique($selected='')
{
global $conf,$langs;
$langs->load("dict");
// On recherche les formes juridiques actives des pays actifs
$sql = "SELECT f.rowid, f.code as code , f.libelle as nom, f.active, p.libelle as libelle_pays, p.code as code_pays FROM llx_c_forme_juridique as f, llx_c_pays as p";
$sql .= " WHERE f.fk_pays=p.rowid";
$sql .= " AND f.active = 1 AND p.active = 1 ORDER BY code_pays, code ASC";
if ($this->db->query($sql))
{
// On recherche les formes juridiques actives des pays actifs
$sql = "SELECT f.rowid, f.code as code , f.libelle as nom, f.active, p.libelle as libelle_pays, p.code as code_pays FROM llx_c_forme_juridique as f, llx_c_pays as p";
$sql .= " WHERE f.fk_pays=p.rowid";
$sql .= " AND f.active = 1 AND p.active = 1 ORDER BY code_pays, code ASC";
if ($this->db->query($sql))
print '<select name="forme_juridique_code">';
$num = $this->db->num_rows();
$i = 0;
if ($num)
{
print '<select name="forme_juridique_code">';
$num = $this->db->num_rows();
$i = 0;
if ($num)
$pays='';
while ($i < $num)
{
$pays='';
while ($i < $num)
{
$obj = $this->db->fetch_object( $i);
if ($obj->code == 0) {
print '<option value="0">&nbsp;</option>';
}
else {
if ($pays == '' || $pays != $obj->libelle_pays) {
// Affiche la rupture
print '<option value="0">----- '.$obj->libelle_pays." -----</option>\n";
$pays=$obj->libelle_pays;
}
if ($selected > 0 && $selected == $obj->code)
{
print '<option value="'.$obj->code.'" selected>['.$obj->code.'] '.$obj->nom.'</option>';
}
else
{
print '<option value="'.$obj->code.'">['.$obj->code.'] '.$obj->nom.'</option>';
}
}
$i++;
$obj = $this->db->fetch_object( $i);
if ($obj->code == 0) {
print '<option value="0">&nbsp;</option>';
}
else {
if ($pays == '' || $pays != $obj->libelle_pays) {
// Affiche la rupture
print '<option value="0">----- '.$obj->libelle_pays." -----</option>\n";
$pays=$obj->libelle_pays;
}
if ($selected > 0 && $selected == $obj->code)
{
print '<option value="'.$obj->code.'" selected>';
}
else
{
print '<option value="'.$obj->code.'">';
}
# Si traduction existe, on l'utilise, sinon on prend le libellé par défaut
print '['.$obj->code.'] '.($langs->trans($obj->code)!=$obj->code?$langs->trans($obj->code):($obj->nom!='-'?$obj->nom:''));
print '</option>';
}
$i++;
}
print '</select>';
}
else {
dolibarr_print_error($this->db);
}
}
print '</select>';
}
else {
dolibarr_print_error($this->db);
}
}
/*
*
*
*
* \brief Affiche formulaire de demande de confirmation
* \param page page
* \param title title
* \param question question
* \param action action
*/
function form_confirm($page, $title, $question, $action)
{

View File

@ -124,31 +124,29 @@ if ($_GET["action"] == 'create')
print $langs->trans('Town').'&nbsp;<input type="text" name="ville"></td>';
print '<td>'.$langs->trans('State').'</td><td>';
print $form->select_departement($soc->departement_id);
$form->select_departement($soc->departement_id);
print '</td></tr>';
print '<tr><td>'.$langs->trans('Country').'</td><td colspan="3">';
print $form->select_pays(MAIN_INFO_SOCIETE_PAYS);
$form->select_pays(defined(MAIN_INFO_SOCIETE_PAYS)?MAIN_INFO_SOCIETE_PAYS:'');
print '</td></tr>';
print '<tr><td>'.$langs->trans('Phone').'</td><td><input type="text" name="tel"></td>';
print '<td>'.$langs->trans('Fax').'</td><td><input type="text" name="fax"></td></tr>';
print '<tr><td>'.$langs->trans('Web').'</td><td colspan="3">http://<input size="40" type="text" name="url"></td></tr>';
print '<tr><td>'.$langs->trans('Web').'</td><td colspan="3"><input size="40" type="text" name="url"></td></tr>';
print '<tr><td>'.$langs->trans('ProfIdSiren').'</td><td><input type="text" name="siren"></td>';
print '<td>'.$langs->trans('ProfIdSiret').'</td><td><input type="text" name="siret" size="15" maxlength="14" value="'.$soc->siret.'"></td></tr>';
print '<tr><td>'.$langs->trans('ProfIdApe').'</td><td><input type="text" name="ape" size="5" maxlength="4" value="'.$soc->ape.'"></td>';
print '<td>Capital</td><td><input type="text" name="capital" size="10" value="'.$soc->capital.'"> '.MAIN_MONNAIE.'</td></tr>';
print '<tr><td>Forme juridique</td><td colspan="3">';
print $form->select_forme_juridique($soc->forme_juridique_code);
$form->select_forme_juridique($soc->forme_juridique_code);
print '</td></tr>';
print '<tr><td>Effectif</td><td colspan="3">';
print $form->select_array("effectif_id",$soc->effectif_array(), $soc->effectif_id);
$form->select_array("effectif_id",$soc->effectif_array(), $soc->effectif_id);
print '</td></tr>';
print '<tr><td colspan="2">'.$langs->trans('TVAIntra').'</td><td colspan="2">';
@ -165,7 +163,7 @@ if ($_GET["action"] == 'create')
print '</select></td>';
print '<td>'.$langs->trans('Supplier').'</td><td>';
print $form->selectyesnonum("fournisseur",$soc->fournisseur);
$form->selectyesnonum("fournisseur",$soc->fournisseur);
print '</td></tr>';
print '<tr><td colspan="4" align="center"><input type="submit" value="'.$langs->trans('Add').'"></td></tr>';
@ -194,27 +192,27 @@ elseif ($_GET["action"] == 'edit')
print '<input type="hidden" name="action" value="update">';
print '<table class="border" width="100%" cellpadding="3" cellspacing="0">';
print '<tr><td>Nom</td><td><input type="text" size="40" name="nom" value="'.$soc->nom.'"></td>';
print '<tr><td>'.$langs->trans('Name').'</td><td><input type="text" size="40" name="nom" value="'.$soc->nom.'"></td>';
print '<td>Préfix</td><td colspan="3"><input type="text" size="5" name="prefix_comm" value="'.$soc->prefix_comm.'"></td></tr>';
print '<td>'.$langs->trans('Prefix').'</td><td colspan="3"><input type="text" size="5" name="prefix_comm" value="'.$soc->prefix_comm.'"></td></tr>';
print '<tr><td valign="top">'.$langs->trans('Adresse').'</td><td colspan="3"><textarea name="adresse" cols="30" rows="3" wrap="soft">';
print '<tr><td valign="top">'.$langs->trans('Address').'</td><td colspan="3"><textarea name="adresse" cols="30" rows="3" wrap="soft">';
print $soc->adresse;
print '</textarea></td></tr>';
print '<tr><td>'.$langs->trans('Zip').'</td><td><input size="6" type="text" name="cp" value="'.$soc->cp.'">&nbsp;';
print 'Ville&nbsp;<input type="text" name="ville" value="'.$soc->ville.'"></td>';
print $langs->trans('Town').'&nbsp;<input type="text" name="ville" value="'.$soc->ville.'"></td>';
print '<td>'.$langs->trans('State').'</td><td>';
print $form->select_departement($soc->departement_id);
$form->select_departement($soc->departement_id);
print '</td></tr>';
print '<tr><td>'.$langs->trans('Country').'</td><td colspan="3">';
print $form->select_pays($soc->pays_id);
$form->select_pays($soc->pays_id);
print '</td></tr>';
print '<tr><td>'.$langs->trans('Téléphone').'</td><td><input type="text" name="tel" value="'.$soc->tel.'"></td>';
print '<tr><td>'.$langs->trans('Phone').'</td><td><input type="text" name="tel" value="'.$soc->tel.'"></td>';
print '<td>'.$langs->trans('Fax').'</td><td><input type="text" name="fax" value="'.$soc->fax.'"></td></tr>';
print '<tr><td>'.$langs->trans('Web').'</td><td colspan="3">http://<input type="text" name="url" size="40" value="'.$soc->url.'"></td></tr>';
print '<tr><td>'.$langs->trans('Web').'</td><td colspan="3"><input type="text" name="url" size="40" value="'.$soc->url.'"></td></tr>';
print '<tr><td>'.$langs->trans('ProfIdSiren').'</td><td><input type="text" name="siren" size="10" maxlength="9" value="'.$soc->siren.'"></td>';
print '<td>'.$langs->trans('ProfIdSiret').'</td><td><input type="text" name="siret" size="15" maxlength="14" value="'.$soc->siret.'"></td></tr>';
@ -222,13 +220,12 @@ elseif ($_GET["action"] == 'edit')
print '<tr><td>'.$langs->trans('ProfIdApe').'</td><td><input type="text" name="ape" size="5" maxlength="4" value="'.$soc->ape.'"></td>';
print '<td>Capital</td><td><input type="text" name="capital" size="10" value="'.$soc->capital.'"> '.MAIN_MONNAIE.'</td></tr>';
print '<tr><td>Forme juridique</td><td colspan="3">';
print $form->select_forme_juridique($soc->forme_juridique_code);
$form->select_forme_juridique($soc->forme_juridique_code);
print '</td></tr>';
print '<tr><td>Effectif</td><td colspan="3">';
print $form->select_array("effectif_id",$soc->effectif_array(), $soc->effectif_id);
$form->select_array("effectif_id",$soc->effectif_array(), $soc->effectif_id);
print '</td></tr>';
print '<tr><td colspan="2">'.$langs->trans('TVAIntra').'</td><td colspan="2">';
@ -239,16 +236,16 @@ elseif ($_GET["action"] == 'edit')
print '</td></tr>';
print '<tr><td>'.$langs->trans('ProspectCustomer').'</td><td><select name="client">';
print '<option value="2"'.($soc->client==2?' selected':'').'>Prospect</option>';
print '<option value="1"'.($soc->client==1?' selected':'').'>Client</option>';
print '<option value="2"'.($soc->client==2?' selected':'').'>'.$langs->trans('Prospect').'</option>';
print '<option value="1"'.($soc->client==1?' selected':'').'>'.$langs->trans('Customer').'</option>';
print '<option value="0"'.($soc->client==0?' selected':'').'>Ni client, ni prospect</option>';
print '</select></td>';
print '<td>'.$langs->trans('Supplier').'</td><td>';
print $form->selectyesnonum("fournisseur",$soc->fournisseur);
$form->selectyesnonum("fournisseur",$soc->fournisseur);
print '</td></tr>';
print '<tr><td align="center" colspan="4"><input type="submit" value="Mettre à jour"></td></tr>';
print '<tr><td align="center" colspan="4"><input type="submit" value="'.$langs->trans("Update").'"></td></tr>';
print '</table>';
print '</form>';
@ -312,13 +309,13 @@ else
*/
print '<table class="border" cellpadding="3" cellspacing="0" width="100%">';
print '<tr><td width="20%">Nom</td><td>'.$soc->nom.'</td><td>Préfix</td><td>'.$soc->prefix_comm.'</td></tr>';
print '<tr><td width="20%">'.$langs->trans('Name').'</td><td>'.$soc->nom.'</td><td>'.$langs->trans('Prefix').'</td><td>'.$soc->prefix_comm.'</td></tr>';
print "<tr><td valign=\"top\">".$langs->trans('Adresse')."</td><td colspan=\"3\">".nl2br($soc->adresse)."<br>".$soc->cp." ".$soc->ville." ".$soc->pays."</td></tr>";
print "<tr><td valign=\"top\">".$langs->trans('Address')."</td><td colspan=\"3\">".nl2br($soc->adresse)."<br>".$soc->cp." ".$soc->ville." ".$soc->pays."</td></tr>";
print '<tr><td>'.$langs->trans('Téléphone').'</td><td>'.dolibarr_print_phone($soc->tel).'</td>';
print '<tr><td>'.$langs->trans('Phone').'</td><td>'.dolibarr_print_phone($soc->tel).'</td>';
print '<td>'.$langs->trans('Fax').'</td><td>'.dolibarr_print_phone($soc->fax).'</td></tr>';
print '<tr><td>Web</td><td colspan="3">';
print '<tr><td>'.$langs->trans('Web').'</td><td colspan="3">';
if ($soc->url) { print '<a href="http://'.$soc->url.'">http://'.$soc->url.'</a>'; }
print '</td></tr>';