table = $trans_table; $this->field = $trans_field; $this->num = $id; $this->liste_langue = explode(",", $liste_langue); $this->fetch_data(); } // récupération des infos en base public function fetch_data() { global $dbh; $this->text = array(); $req = "SELECT * FROM translation WHERE trans_table='".$this->table."' and trans_field='$this->field' and trans_num='".$this->num."' "; $myQuery = pmb_mysql_query($req, $dbh); if(pmb_mysql_num_rows($myQuery)){ while(($myreq = pmb_mysql_fetch_object($myQuery))) { $langue = $myreq->trans_lang; $this->num = $myreq->trans_num; $this->text[$langue] = $myreq->trans_text; } } } /** * Retourne la traduction dans la langue voulue */ public function get_text($langue) { return $this->text[$langue]; } public function set_text($langue, $text) { $this->text[$langue] = $text; } public function delete() { global $dbh; $req="delete from translation WHERE trans_table='".$this->table."' and trans_field='$this->field' and trans_num='$this->num' "; pmb_mysql_query($req, $dbh); } public function get_form($label, $field_id, $field_name, $field_value, $class_saisie, $style_form="display: none;") { global $msg, $charset; global $translation_tpl_form_javascript, $translation_tpl_form, $translation_tpl_line_form; global $translation_tpl_form_javascript_flag; global $lang, $include_path; $langues = new XMLlist("$include_path/messages/languages.xml"); $langues->analyser(); $clang = $langues->table; $line = ""; $nb = 0; foreach($this->liste_langue as $langue) { if($langue != $lang) { $line.= str_replace("!!libelle_lang!!", $clang[$langue], $translation_tpl_line_form); $line = str_replace("!!lang!!", $langue, $line); $line = str_replace("!!text!!", htmlentities($this->text[$langue], ENT_QUOTES, $charset), $line); $nb++; } } $form = str_replace("!!lang_list!!", $line, $translation_tpl_form); if($nb) { $translation_button = ""; }else { $translation_button = ""; } if($label) { $form = str_replace("!!translation_button!!", $translation_button, $form); $form = str_replace("!!translation_button_no_label!!", '', $form); }else { $form = str_replace("!!translation_button!!", '', $form); $form = str_replace("!!translation_button_no_label!!", $translation_button, $form); } $form = str_replace("!!label!!", $label, $form); $form = str_replace("!!class_saisie!!", $class_saisie, $form); $form = str_replace("!!field_id!!", $field_id, $form); $form = str_replace("!!field_name!!", $field_name, $form); $form = str_replace("!!field_value!!", htmlentities($field_value, ENT_QUOTES, $charset), $form); $form = str_replace("!!class_form!!", "class_form", $form); $form = str_replace("!!style_form!!", $style_form, $form); if(!$translation_tpl_form_javascript_flag) { $form = $translation_tpl_form_javascript.$form; $translation_tpl_form_javascript_flag++; } return $form; } public function update($input_field, $is_multiple=false, $index=0) { global $dbh; // effacer les anciens $this->delete(); foreach($this->liste_langue as $langue) { $field = $langue.'_'.$input_field; global ${$field}; if($is_multiple) { $f = ${$field}; $text = $f[$index]; }else { $text = ${$field}; } if($text) { $req = "INSERT into translation Set trans_table='".$this->table."' , trans_field='$this->field' ,trans_lang='$langue', trans_num='".$this->num."' ,trans_text='$text' "; pmb_mysql_query($req, $dbh); } } } }