Patch traduction. merci Nicolas

This commit is contained in:
Regis Houssin 2006-04-29 11:03:37 +00:00
parent 8a598504af
commit 40a74211df
2 changed files with 55 additions and 43 deletions

View File

@ -353,49 +353,62 @@ class Product
} }
/** /**
* \brief update ou crée les traductions des infos produits * \brief update ou crée les traductions des infos produits
*/ */
function setMultiLangs() function setMultiLangs()
{ {
global $langs; global $langs;
$langs_available = $langs->get_available_languages(); $langs_available = $langs->get_available_languages();
$current_lang = $langs->getDefaultLang(); $current_lang = $langs->getDefaultLang();
foreach ($langs_available as $value) foreach ($langs_available as $value)
{ {
$sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."product_det";
$sql.= " WHERE fk_product=".$this->id." AND lang='".$value."'";
$result = $this->db->query($sql);
if ($value == $current_lang) if ($value == $current_lang)
{ {
$sqlU = "UPDATE ".MAIN_DB_PREFIX."product_det"; if (mysql_num_rows($result)) // si aucune ligne dans la base
$sqlU.= " SET label='".$this->libelle."'"; {
$sqlU.= " description='".$this->description."'"; $sql2 = "UPDATE ".MAIN_DB_PREFIX."product_det";
$sqlU.= " note='".$this->note."'"; $sql2.= " SET label='".$this->libelle."',";
$sqlU.= " WHERE fk_product=".$this->id." AND lang='".$value."'"; $sql2.= " description='".$this->description."',";
$sql2.= " note='".$this->note."'";
$sqlI = "INSERT INTO ".MAIN_DB_PREFIX."product_det (fk_product, lang, label, description, note)"; $sql2.= " WHERE fk_product=".$this->id." AND lang='".$value."'";
$sqlI.= " VALUES(".$this->id.",'".$value."','". $this->libelle; }
$sqlI.= "','".$this->description; else
$sqlI.= "','".$this->note."')"; {
$sql2 = "INSERT INTO ".MAIN_DB_PREFIX."product_det (fk_product, lang, label, description, note)";
$sql2.= " VALUES(".$this->id.",'".$value."','". $this->libelle;
$sql2.= "','".$this->description;
$sql2.= "','".$this->note."')";
}
if (!$this->db->query($sql2)) return -1;
} }
else else
{ {
$sqlU = "UPDATE ".MAIN_DB_PREFIX."product_det"; if (mysql_num_rows($result)) // si aucune ligne dans la base
$sqlU.= " SET label='".$this->multilangs["$value"]["libelle"]."'"; {
$sqlU.= " description='".$this->multilangs["$value"]["libelle"]."'"; $sql2 = "UPDATE ".MAIN_DB_PREFIX."product_det";
$sqlU.= " note='".$this->multilangs["$value"]["note"]."'"; $sql2.= " SET label='".$this->multilangs["$value"]["libelle"]."',";
$sqlU.= " WHERE fk_product=".$this->id." AND lang='".$value."'"; $sql2.= " description='".$this->multilangs["$value"]["description"]."',";
$sql2.= " note='".$this->multilangs["$value"]["note"]."'";
$sqlI = "INSERT INTO ".MAIN_DB_PREFIX."product_det (fk_product, lang, label, description, note)"; $sql2.= " WHERE fk_product=".$this->id." AND lang='".$value."'";
$sqlI.= " VALUES(".$this->id.",'".$value."','". $this->multilangs["$value"]["libelle"]; }
$sqlI.= "','".$this->multilangs["$value"]["description"]; else
$sqlI.= "','".$this->multilangs["$value"]["note"]."')"; {
$sql2 = "INSERT INTO ".MAIN_DB_PREFIX."product_det (fk_product, lang, label, description, note)";
$sql2.= " VALUES(".$this->id.",'".$value."','". $this->multilangs["$value"]["libelle"];
$sql2.= "','".$this->multilangs["$value"]["description"];
$sql2.= "','".$this->multilangs["$value"]["note"]."')";
}
// on ne sauvegarde pas des champs vides
if ( $this->multilangs["$value"]["libelle"] || $this->multilangs["$value"]["description"] || $this->multilangs["$value"]["note"] )
if (!$this->db->query($sql2)) return -1;
} }
// on ne sauvegarde pas des champs vides
if ( $this->multilangs["$value"]["libelle"] || $this->multilangs["$value"]["description"] || $this->multilangs["$value"]["note"] )
if (!$this->db->query($sqlU)) // si aucun champ n'est mis a jour
if (!$this->db->query($sqlI)) return -1;
} }
return 1; return 1;
} }
@ -425,16 +438,16 @@ class Product
{ {
while ( $obj = $this->db->fetch_object($result) ) while ( $obj = $this->db->fetch_object($result) )
{ {
$this->multilangs["$obj->lang"]["libelle"] = $obj->label;
$this->multilangs["$obj->lang"]["description"] = $obj->description;
$this->multilangs["$obj->lang"]["note"] = $obj->note;
if( $obj->lang == $current_lang ) // si on a les traduct. dans la langue courant on les charge en infos principales. if( $obj->lang == $current_lang ) // si on a les traduct. dans la langue courant on les charge en infos principales.
{ {
$this->libelle = $obj->label; $this->libelle = $obj->label;
$this->description = $obj->description; $this->description = $obj->description;
$this->note = $obj->note; $this->note = $obj->note;
} }
$this->multilangs["$obj->lang"]["libelle"] = $obj->label;
$this->multilangs["$obj->lang"]["description"] = $obj->description;
$this->multilangs["$obj->lang"]["note"] = $obj->note;
} }
} }
else else

View File

@ -77,7 +77,7 @@ if ($_POST["action"] == 'vadd' &&
} }
// sauvegarde en base // sauvegarde en base
if ( $product->update($product->id, $user) > 0 ) if ( $product->setMultiLangs() > 0 )
{ {
$_GET["action"] = ''; $_GET["action"] = '';
$mesg = 'Fiche mise à jour'; $mesg = 'Fiche mise à jour';
@ -108,13 +108,13 @@ if ($_POST["action"] == 'vedit' &&
} }
else else
{ {
$value["libelle"] = $_POST["libelle-".$key]; $product->multilangs[$key]["libelle"] = $_POST["libelle-".$key];
$value["description"] = $_POST["desc-".$key]; $product->multilangs[$key]["description"] = $_POST["desc-".$key];
$value["note"] = $_POST["note-".$key]; $product->multilangs[$key]["note"] = $_POST["note-".$key];
} }
} }
if ( $product->update($product->id, $user) > 0 ) if ( $product->setMultiLangs() > 0 )
{ {
$_GET["action"] = ''; $_GET["action"] = '';
$mesg = 'Fiche mise à jour'; $mesg = 'Fiche mise à jour';
@ -271,16 +271,18 @@ if ($_GET["action"] == 'edit')
} }
else else
{ {
$cnt_trans = 0;
foreach ( $product->multilangs as $key => $value) foreach ( $product->multilangs as $key => $value)
{ {
$cnt_trans++;
print "<br /><b><u>$key :</u></b><br />"; print "<br /><b><u>$key :</u></b><br />";
print '<table class="border" width="100%">'; print '<table class="border" width="100%">';
print '<tr><td width="15%">'.$langs->trans('Label').'</td><td>'.$product->multilangs[$key]["libelle"].'</td></tr>'; print '<tr><td width="15%">'.$langs->trans('Label').'</td><td>'.$product->multilangs[$key]["libelle"].'</td></tr>';
print '<tr><td width="15%">'.$langs->trans('Description').'</td><td>'.$product->multilangs[$key]["description"].'</td></tr>'; print '<tr><td width="15%">'.$langs->trans('Description').'</td><td>'.$product->multilangs[$key]["description"].'</td></tr>';
print '<tr><td width="15%">'.$langs->trans('Note').'</td><td>'.$product->multilangs[$key]["note"].'</td></tr>'; print '<tr><td width="15%">'.$langs->trans('Note').'</td><td>'.$product->multilangs[$key]["note"].'</td></tr>';
print '</tr>';
print '</table>'; print '</table>';
} }
if ( !$cnt_trans ) print '<br />'. $langs->trans('NoTranslation');
} }
print "</div>\n"; print "</div>\n";
@ -322,10 +324,7 @@ if ($_GET["action"] == 'add' || $user->rights->produit->modifier)
print '<input type="hidden" name="action" value="vadd">'; print '<input type="hidden" name="action" value="vadd">';
print '<input type="hidden" name="id" value="'.$_GET["id"].'">'; print '<input type="hidden" name="id" value="'.$_GET["id"].'">';
print '<table class="border" width="100%">'; print '<table class="border" width="100%">';
print '<tr><td valign="top" width="15%">'.$langs->trans('Translation').'</td><td>'.$select.'</td></tr>';; print '<tr><td valign="top" width="15%">'.$langs->trans('Translation').'</td><td>'.$select.'</td></tr>';
//print '<tr><td valign="top" width="15%">'.$langs->trans('Label').'</td><td><input name="libelle" size="40" value="'.$product->multilangs[$key]["libelle"].'"></td></tr>';
//print '<tr><td valign="top" width="15%">'.$langs->trans('Description').'</td><td><textarea name="desc" rows="3" cols="80">'.$product->multilangs[$key]["description"].'</textarea></td></tr>';
//print '<tr><td valign="top" width="15%">'.$langs->trans('Note').'</td><td><textarea name="note" rows="3" cols="80">'.$product->multilangs[$key]["note"].'</textarea></td></tr>';
print '<tr><td valign="top" width="15%">'.$langs->trans('Label').'</td><td><input name="libelle" size="40"></td></tr>'; print '<tr><td valign="top" width="15%">'.$langs->trans('Label').'</td><td><input name="libelle" size="40"></td></tr>';
print '<tr><td valign="top" width="15%">'.$langs->trans('Description').'</td><td><textarea name="desc" rows="3" cols="80"></textarea></td></tr>'; print '<tr><td valign="top" width="15%">'.$langs->trans('Description').'</td><td><textarea name="desc" rows="3" cols="80"></textarea></td></tr>';
print '<tr><td valign="top" width="15%">'.$langs->trans('Note').'</td><td><textarea name="note" rows="3" cols="80"></textarea></td></tr>'; print '<tr><td valign="top" width="15%">'.$langs->trans('Note').'</td><td><textarea name="note" rows="3" cols="80"></textarea></td></tr>';