id = intval($id); $this->fetch_datas(); } // end of member function __construct public function fetch_datas(){ $this->name = ""; $this->code = ""; $this->order =0; if($this->id){ $query = "select * from nomenclature_voices where id_voice = ".$this->id ." order by voice_order asc, voice_name"; $result = pmb_mysql_query($query); if(pmb_mysql_num_rows($result)){ if($row = pmb_mysql_fetch_object($result)){ $this->name = $row->voice_name; $this->code = $row->voice_code; $this->order= $row->voice_order; } } } } public function get_form() { global $nomenclature_voice_content_form_tpl,$msg,$charset; $content_form = $nomenclature_voice_content_form_tpl; $content_form = str_replace('!!id!!', $this->id, $content_form); $interface_form = new interface_admin_nomenclature_form('nomenclature_voice_form'); if(!$this->id){ $interface_form->set_label($msg['admin_nomenclature_voice_form_add']); }else{ $interface_form->set_label($msg['admin_nomenclature_voice_form_edit']); } $content_form = str_replace('!!name!!', htmlentities($this->name, ENT_QUOTES, $charset), $content_form); $content_form = str_replace('!!code!!', htmlentities($this->code, ENT_QUOTES, $charset), $content_form); $interface_form->set_object_id($this->id) ->set_object_type('voice') ->set_confirm_delete_msg($msg['confirm_suppr_de']." ".$this->name." ?") ->set_content_form($content_form) ->set_table_name('nomenclature_voices') ->set_field_focus('code'); return $interface_form->get_display(); } public function set_properties_from_form() { global $name, $code; $this->name = stripslashes($name); $this->code = stripslashes($code); } public function save() { global $msg; $fields=" voice_name='".addslashes($this->name)."', voice_code='".addslashes($this->code)."' "; if(!$this->id){ // Ajout $requete="select max(voice_order) as ordre from nomenclature_voices"; $resultat=pmb_mysql_query($requete); $ordre_max=@pmb_mysql_result($resultat,0,0); $req="INSERT INTO nomenclature_voices SET $fields, voice_order=".($ordre_max+1); pmb_mysql_query($req); $this->id = pmb_mysql_insert_id(); } else { $req="UPDATE nomenclature_voices SET $fields where id_voice=".$this->id; pmb_mysql_query($req); } print display_notification($msg['account_types_success_saved']); } public static function delete($id) { $id = intval($id); if($id) { $req="DELETE from nomenclature_voices WHERE id_voice=".$id; pmb_mysql_query($req); } return true; } public function get_data(){ return( array( "id" => $this->id, "code" => $this->code, "name" => $this->name, "order" => $this->order ) ); } public function get_name( ) { return $this->name; } public function set_name( $name ) { $this->name = $name; } public function get_code( ) { return $this->code; } public function set_code( $code ) { $this->code = $code; } public function get_order( ) { return $this->order; } public function set_order( $order ) { $this->order = $order; } public function get_id(){ return $this->id; } public static function get_voice_name_from_id($id) { $voice_name = ''; $id = intval($id); $query = "select voice_name from nomenclature_voices where id_voice=".$id; $result = pmb_mysql_query($query); if (pmb_mysql_num_rows($result)) { $row = pmb_mysql_fetch_object($result); $voice_name = $row->voice_name; } return $voice_name; } } // end of nomenclature_voice