id = intval($id); $this->fetch_data(); } /** * Data */ protected function fetch_data() { $this->label = ''; $this->amount = '0.00'; $this->footer = ''; $this->entity = null; if ($this->id) { $query = 'select * from thresholds where id_threshold = '.$this->id; $result = pmb_mysql_query($query); if (pmb_mysql_num_rows($result)) { $row = pmb_mysql_fetch_object($result); $this->label = $row->threshold_label; $this->amount = $row->threshold_amount; $this->amount_tax_included = $row->threshold_amount_tax_included; $this->footer = $row->threshold_footer; $this->entity = new entites($row->threshold_num_entity); } } } /** * Formulaire */ public function get_form(){ global $msg; global $threshold_content_form_tpl; $content_form = $threshold_content_form_tpl; $interface_form = new interface_form('threshold_form'); $interface_form->set_label($msg['threshold_form_edit']); $content_form = str_replace("!!entity_label!!",$this->entity->raison_sociale,$content_form); $content_form = str_replace("!!num_entity!!",$this->entity->id_entite,$content_form); $content_form = str_replace("!!label!!",$this->label,$content_form); $content_form = str_replace("!!amount!!",$this->amount,$content_form); $content_form = str_replace("!!amount_tax_included!!",($this->amount_tax_included ? "checked='checked'" : ""),$content_form); $content_form = str_replace("!!footer!!",$this->footer,$content_form); $content_form = str_replace('!!id!!', $this->id, $content_form); $interface_form->set_object_id($this->id) ->set_confirm_delete_msg($msg['threshold_delete_confirm']) ->set_content_form($content_form) ->set_table_name('thresholds') ->set_field_focus('threshold_label'); $url_base = $interface_form->get_url_base(); if(!empty($this->entity)) { $url_base .= "&id_entity=".$this->entity->id_entite; } $interface_form->set_url_base($url_base); return $interface_form->get_display(); } /** * Provenance du formulaire */ public function set_properties_from_form(){ global $threshold_label; global $threshold_amount; global $threshold_amount_tax_included; global $threshold_footer; global $threshold_num_entity; $this->label = stripslashes($threshold_label); $this->amount = floatval(stripslashes($threshold_amount)); $this->amount_tax_included = $threshold_amount_tax_included*1; $this->footer = stripslashes($threshold_footer); $this->entity = new entites($threshold_num_entity*1); } /** * Sauvegarde */ public function save(){ if($this->id) { $query = 'update thresholds set '; $where = 'where id_threshold= '.$this->id; } else { $query = 'insert into thresholds set '; $where = ''; } $query .= ' threshold_label = "'.addslashes($this->label).'", threshold_amount = "'.addslashes($this->amount).'", threshold_amount_tax_included = "'.addslashes($this->amount_tax_included).'", threshold_footer = "'.addslashes($this->footer).'", threshold_num_entity = "'.$this->entity->id_entite.'" '.$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(){ if($this->id) { $query = "delete from thresholds where id_threshold = ".$this->id; pmb_mysql_query($query); return true; } return false; } public function get_data() { return array( 'id' => $this->id, 'label' => $this->label, 'amount' => $this->amount, 'amount_tax_included' => $this->amount_tax_included, 'footer' => $this->footer ); } public function get_id() { return $this->id; } public function get_label() { return $this->label; } public function get_amount() { return $this->amount; } public function get_amount_tax_included() { return $this->amount_tax_included; } public function get_footer() { return $this->footer; } public function get_entity() { return $this->entity; } public function set_label($label) { $this->label = $label; } public function set_amount($amount) { $this->amount = $amount; } public function set_amount_tax_included($amount_tax_included) { $this->amount_tax_included = $amount_tax_included; } public function set_footer($footer) { $this->footer = $footer; } public function set_entity($id_entity) { $this->entity = new entites($id_entity); } }