id_source = intval($id); if(!$this->id_source){ $this->libelle_source =''; } else { $req="select libelle_source from suggestions_source where id_source='".$this->id_source."'"; $res = pmb_mysql_query($req); if(!pmb_mysql_num_rows($res)) { pmb_error::get_instance(static::class)->add_message("not_found", "not_found_object"); return; } $src = pmb_mysql_fetch_object($res); $this->libelle_source = $src->libelle_source; } } /* * Formulaire d'ajout/modification */ public function get_form(){ global $src_content_form, $msg, $charset; $content_form = $src_content_form; $content_form = str_replace('!!id!!', $this->id_source, $content_form); $interface_form = new interface_admin_form('srcform'); if(!$this->id_source){ $interface_form->set_label($msg['acquisition_ajout_src']); }else{ $interface_form->set_label($msg['acquisition_modif_src']); } $content_form = str_replace('!!libelle!!', htmlentities($this->libelle_source, ENT_QUOTES, $charset), $content_form); $interface_form->set_object_id($this->id_source) ->set_confirm_delete_msg($msg['confirm_suppr_de']." ".$this->libelle_source." ?") ->set_content_form($content_form) ->set_table_name('suggestions_source') ->set_field_focus('libelle'); return $interface_form->get_display(); } public function set_properties_from_form() { global $libelle; $this->libelle_source = stripslashes($libelle); } /* * Création/Modification */ public function save(){ if(!$this->id_source){ $req = "insert into suggestions_source set libelle_source='".addslashes($this->libelle_source)."'"; } else { $req="update suggestions_source set libelle_source='".addslashes($this->libelle_source)."' where id_source='".$this->id_source."'"; } pmb_mysql_query($req); } //Suppression d'une source public static function delete($id){ global $msg; $id = intval($id); if(static::hasSuggestions($id)){ pmb_error::get_instance(static::class)->add_message('321', $msg['acquisition_sugg_source_used']); return false; } else { $req="delete from suggestions_source where id_source='".$id."'"; pmb_mysql_query($req); return true; } return true; } //Vérifie si la source de suggestions est utilisee dans les suggestions public static function hasSuggestions($id){ $id = intval($id); $q = "select count(1) from suggestions where sugg_source = '".$id."' "; $r = pmb_mysql_query($q); return pmb_mysql_result($r, 0, 0); } } ?>