id = intval($id); $this->getData(); } /* --------------------------------------------------------------- getData() : récupération des propriétés --------------------------------------------------------------- */ public function getData() { if(!$this->id) return; $query = 'SELECT * FROM empr_codestat WHERE idcode='.$this->id; $result = pmb_mysql_query($query); if(!pmb_mysql_num_rows($result)) { pmb_error::get_instance(static::class)->add_message("not_found", "not_found_object"); return; } $data = pmb_mysql_fetch_object($result); $this->libelle = $data->libelle; } public function get_form() { global $msg; global $admin_statlec_content_form ; global $charset; $content_form = $admin_statlec_content_form; $content_form = str_replace('!!id!!', $this->id, $content_form); $interface_form = new interface_admin_form('lenderform'); if(!$this->id){ $interface_form->set_label($msg['101']); }else{ $interface_form->set_label($msg['102']); } $content_form = str_replace('!!libelle!!', htmlentities($this->libelle, ENT_QUOTES, $charset), $content_form); $interface_form->set_object_id($this->id) ->set_confirm_delete_msg($msg['confirm_suppr_de']." ".$this->libelle." ?") ->set_content_form($content_form) ->set_table_name('empr_codestat') ->set_field_focus('form_libelle'); return $interface_form->get_display(); } public function set_properties_from_form() { global $form_libelle; $this->libelle = stripslashes($form_libelle); } public function get_query_if_exists() { return "SELECT count(1) FROM empr_codestat WHERE (libelle='".addslashes($this->libelle)."' AND idcode!='".$this->id."' )"; } public function save() { // O.K., now if item already exists UPDATE else INSERT if($this->id) { $requete = "UPDATE empr_codestat SET libelle='".addslashes($this->libelle)."' WHERE idcode=".$this->id; $res = pmb_mysql_query($requete); } else { $requete = "SELECT count(1) FROM empr_codestat WHERE libelle='".addslashes($this->libelle)."' LIMIT 1 "; $res = pmb_mysql_query($requete); $nbr = pmb_mysql_result($res, 0, 0); if($nbr == 0) { $requete = "INSERT INTO empr_codestat (idcode,libelle) VALUES ('', '".addslashes($this->libelle)."') "; $res = pmb_mysql_query($requete); $this->id = pmb_mysql_insert_id(); } } $translation = new translation($this->id, "empr_codestat"); $translation->update("libelle", "form_libelle"); } public static function check_data_from_form() { global $form_libelle; if(empty($form_libelle)) { return false; } return true; } public static function delete($id) { $id = intval($id); if($id) { $total = 0; $total = pmb_mysql_result(pmb_mysql_query("select count(1) from empr where empr_codestat ='".$id."' "), 0, 0); if ($total==0) { translation::delete($id, "empr_codestat"); $requete = "DELETE FROM empr_codestat WHERE idcode=$id ;"; pmb_mysql_query($requete); $requete = "OPTIMIZE TABLE empr_codestat "; pmb_mysql_query($requete); return true; } else { pmb_error::get_instance(static::class)->add_message('294', '1707'); return false; } } return true; } public function get_translated_libelle() { return translation::get_translated_text($this->id, 'empr_codestat', 'libelle', $this->libelle); } } /* fin de définition de la classe */