id = intval($id);
$this->getData();
}
/* ---------------------------------------------------------------
getData() : récupération des propriétés
--------------------------------------------------------------- */
public function getData() {
if(!$this->id) {
$workflow = new workflow('ACTIONS');
$this->allowed_actions = $workflow->getTypeList();
return;
}
$requete = 'SELECT * FROM demandes_type WHERE id_type='.$this->id;
$result = pmb_mysql_query($requete);
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_type;
$this->allowed_actions = unserialize($data->allowed_actions);
if(!is_array($this->allowed_actions) || !count($this->allowed_actions)){
$workflow = new workflow('ACTIONS');
$this->allowed_actions = $workflow->getTypeList();
}
}
public function get_actions_form(){
global $msg,$charset;
$form = "
";
return $form;
}
public function get_form() {
global $demandes_type_content_form, $msg, $charset;
$content_form = $demandes_type_content_form;
$content_form = str_replace('!!id!!', $this->id, $content_form);
$interface_form = new interface_admin_form('simple_list_form');
if(!$this->id){
$interface_form->set_label($msg['demandes_ajout_type']);
}else{
$interface_form->set_label($msg['demandes_modif_type']);
}
$content_form = str_replace('!!libelle!!', htmlentities($this->libelle, ENT_QUOTES, $charset), $content_form);
$content_form = str_replace("!!actions!!",$this->get_actions_form(), $content_form);
$interface_form->set_object_id($this->id)
->set_confirm_delete_msg($msg['demandes_del_type'])
->set_content_form($content_form)
->set_table_name('demandes_type')
->set_field_focus('libelle');
return $interface_form->get_display();
}
public function set_properties_from_form() {
global $libelle, $default_action;
$this->libelle = stripslashes($libelle);
$allowed_actions = array();
foreach($this->allowed_actions as $allowed_action_form){
$val = "action_".$allowed_action_form['id'];
global ${$val};
$allowed_action_form['active'] = ${$val};
if($allowed_action_form['id'] == $default_action){
$allowed_action_form['default'] = 1;
}else{
$allowed_action_form['default'] = 0;
}
$allowed_actions[] = $allowed_action_form;
}
$this->allowed_actions = $allowed_actions;
}
public function save() {
if($this->id) {
$requete = "UPDATE demandes_type set libelle_type='".addslashes($this->libelle)."', allowed_actions = \"".addslashes(serialize($this->allowed_actions))."\" where id_type='".$this->id."'";
pmb_mysql_query($requete);
} else {
$requete = "INSERT INTO demandes_type set libelle_type='".addslashes($this->libelle)."', allowed_actions = \"".addslashes(serialize($this->allowed_actions))."\"";
pmb_mysql_query($requete);
$this->id = pmb_mysql_insert_id();
}
}
public static function check_data_from_form() {
global $libelle;
if(empty($libelle)) {
return false;
}
return true;
}
public static function delete($id) {
$id = intval($id);
if ($id) {
$total = pmb_mysql_num_rows(pmb_mysql_query("select * from demandes where type_demande = '".$id."'"));
if ($total==0) {
$requete = "DELETE FROM demandes_type where id_type='".$id."'";
pmb_mysql_query($requete);
return true;
} else {
pmb_error::get_instance(static::class)->add_message("321", 'demandes_used_type');
return false;
}
}
return true;
}
} /* fin de définition de la classe */