id = $id+0; $this->fetch_data(); } protected function fetch_data() { if($this->id) { $query = 'select object_label from contact_form_objects where id_object ='.$this->id; $result = pmb_mysql_query($query); $row = pmb_mysql_fetch_object($result); $this->label = $row->object_label; } } public function get_form() { global $msg, $charset; global $contact_form_object_form_tpl; $form = $contact_form_object_form_tpl; if($this->id) { $form = str_replace('!!title!!', htmlentities($msg['admin_opac_contact_form_object_form_edit'], ENT_QUOTES, $charset), $form); $button_delete = ""; $form = str_replace('!!delete!!', $button_delete, $form); } else { $form = str_replace('!!title!!', htmlentities($msg['admin_opac_contact_form_object_form_add'], ENT_QUOTES, $charset), $form); $form = str_replace('!!delete!!', '', $form); } $form = str_replace('!!label!!', $this->label, $form); $form = str_replace('!!id!!', $this->id, $form); return $form; } /** * Données provenant d'un formulaire */ public function set_properties_from_form() { global $object_label; $this->label = stripslashes($object_label); } /** * Sauvegarde */ public function save(){ if($this->id) { $query = 'update contact_form_objects set '; $where = 'where id_object= '.$this->id; } else { $query = 'insert into contact_form_objects set '; $where = ''; } $query .= ' object_label = "'.addslashes($this->label).'" '.$where; $result = pmb_mysql_query($query); if($result) { if(!$this->id) { $this->id = pmb_mysql_insert_id(); } return true; } else { return false; } } /** * Suppression */ public function delete(){ global $msg; if($this->id) { $contact_form_recipients = new contact_form_recipients('by_objects'); $contact_form_recipients->unset_recipient($this->id); $contact_form_recipients->save(); $query = "delete from contact_form_objects where id_object = ".$this->id; $result = pmb_mysql_query($query); return true; } return false; } public function get_id() { return $this->id; } public function get_label() { return $this->label; } public function set_label($label) { $this->label = $label; } }