id = intval($id); $this->_init_parameters(); $this->fetch_data(); } protected function _get_field($type='text', $display=0, $mandatory=0, $readonly=0) { return array( 'type' => $type, 'display' => $display, 'mandatory' => $mandatory, 'readonly' => $readonly ); } protected function _init_parameters() { $this->parameters = array( 'fields' => array( 'name' => $this->_get_field('text', 1, 1), 'firstname' => $this->_get_field('text', 1, 1), 'group' => $this->_get_field(), 'email' => $this->_get_field('email', 1, 1, 1), 'tel' => $this->_get_field(), 'attachments' => $this->_get_field('file') ), 'recipients_mode' => 'by_persons', 'email_object_free_entry' => 0, 'email_content' => $this->_get_email_content_template(), 'confirm_email' => 1 ); } protected function fetch_data() { $query = 'select contact_form_parameters from contact_forms where id_contact_form='.$this->id; $result = pmb_mysql_query($query); if($result && pmb_mysql_num_rows($result)) { $row = pmb_mysql_fetch_object($result); if($row->contact_form_parameters) { $parameters = encoding_normalize::json_decode($row->contact_form_parameters, true); if(is_array($parameters)) { foreach ($this->parameters['fields'] as $name=>$field) { if(!empty($parameters['fields'][$name]) && is_array($parameters['fields'][$name])) { if(!$this->parameters['fields'][$name]['readonly']) { $this->parameters['fields'][$name]['display'] = $parameters['fields'][$name]['display']; $this->parameters['fields'][$name]['mandatory'] = $parameters['fields'][$name]['mandatory']; } } else { $this->updated_in_database = false; } } if($parameters['recipients_mode']) { $this->parameters['recipients_mode'] = $parameters['recipients_mode']; } if($parameters['email_object_free_entry']) { $this->parameters['email_object_free_entry'] = $parameters['email_object_free_entry']; } if($parameters['email_content']) { $this->parameters['email_content'] = $parameters['email_content']; } if($parameters['confirm_email'] == 0) { $this->parameters['confirm_email'] = 0; } } else { $this->updated_in_database = false; } if(!$this->updated_in_database) { $this->save(); $this->updated_in_database = true; } } } } protected function _get_display_field($name) { global $msg, $charset; return htmlentities($msg['admin_opac_contact_form_parameter_display_field'], ENT_QUOTES, $charset)." parameters['fields'][$name]['display'] ? "checked='checked'" : "")." ".($this->parameters['fields'][$name]['readonly'] ? "disabled='disabled'" : "")." /> ".($this->parameters['fields'][$name]['readonly'] ? "" : "")." ".htmlentities($msg['admin_opac_contact_form_parameter_mandatory_field'], ENT_QUOTES, $charset)." parameters['fields'][$name]['mandatory'] ? "checked='checked'" : "")." ".($this->parameters['fields'][$name]['readonly'] ? "disabled='disabled'" : "")." /> ".($this->parameters['fields'][$name]['readonly'] ? "" : "")." "; } public static function gen_recipients_mode_selector($selected='', $onchange='') { global $msg, $charset; return " "; } protected function _get_display_toggle($name) { global $msg, $charset; return " parameters[$name] ? "checked='checked'" : "")." /> "; } protected function _get_display_permalink() { global $opac_url_base; return "".$opac_url_base."index.php?lvl=contact_form&id=".$this->id.""; } /** * Liste des paramètres */ public function get_display_content_list() { global $msg, $charset; $display = " ".htmlentities($msg['admin_opac_contact_form_parameter_name'], ENT_QUOTES, $charset)." ".$this->_get_display_field('name')." ".htmlentities($msg['admin_opac_contact_form_parameter_firstname'], ENT_QUOTES, $charset)." ".$this->_get_display_field('firstname')." ".htmlentities($msg['admin_opac_contact_form_parameter_group'], ENT_QUOTES, $charset)." ".$this->_get_display_field('group')." ".htmlentities($msg['admin_opac_contact_form_parameter_email'], ENT_QUOTES, $charset)." ".$this->_get_display_field('email')." ".htmlentities($msg['admin_opac_contact_form_parameter_tel'], ENT_QUOTES, $charset)." ".$this->_get_display_field('tel')." ".htmlentities($msg['admin_opac_contact_form_parameter_attachments'], ENT_QUOTES, $charset)." ".$this->_get_display_field('attachments')." ".htmlentities($msg['admin_opac_contact_form_parameter_recipients_mode'], ENT_QUOTES, $charset)." ".self::gen_recipients_mode_selector($this->parameters['recipients_mode'])." ".htmlentities($msg['admin_opac_contact_form_parameter_email_object_free_entry'], ENT_QUOTES, $charset)." ".$this->_get_display_toggle('email_object_free_entry')." ".htmlentities($msg['admin_opac_contact_form_parameter_email_content'], ENT_QUOTES, $charset)." ".htmlentities($msg['admin_opac_contact_form_parameter_confirm_email'], ENT_QUOTES, $charset)." ".$this->_get_display_toggle('confirm_email')." ".htmlentities($msg['admin_opac_contact_form_parameter_permalink'], ENT_QUOTES, $charset)." ".$this->_get_display_permalink()." "; return $display; } /** * Header de la liste */ public function get_display_header_list() { global $msg, $charset; $display = " ".htmlentities($msg['admin_opac_contact_form_parameter_label'],ENT_QUOTES,$charset)." ".htmlentities($msg['admin_opac_contact_form_parameter_value'],ENT_QUOTES,$charset)." "; return $display; } /** * Affiche la recherche + la liste des décomptes */ public function get_display_list() { global $msg, $charset, $base_path; global $current_module; $display = "
"; if($this->message != "") { $display .= "".htmlentities($this->message, ENT_QUOTES, $charset).""; } //Affichage de la liste des paramètres $display .= ""; $display .= $this->get_display_header_list(); $display .= $this->get_display_content_list(); $display .= "
"; return $display; } public function set_properties_from_form() { global $parameter_fields; global $parameter_recipients_mode; global $parameter_email_object_free_entry; global $parameter_email_content; global $parameter_confirm_email; if(is_array($parameter_fields)) { foreach ($this->parameters['fields'] as $name=>$field) { if(isset($parameter_fields[$name]['display'])) { $this->parameters['fields'][$name]['display'] = $parameter_fields[$name]['display']; } else { $this->parameters['fields'][$name]['display'] = 0; } if(isset($parameter_fields[$name]['mandatory'])) { $this->parameters['fields'][$name]['mandatory'] = $parameter_fields[$name]['mandatory']; } else { $this->parameters['fields'][$name]['mandatory'] = 0; } } } $this->parameters['recipients_mode'] = $parameter_recipients_mode; $this->parameters['email_object_free_entry'] = ($parameter_email_object_free_entry ? 1 : 0); if(trim($parameter_email_content)) { $this->parameters['email_content'] = stripslashes($parameter_email_content); } else { $this->parameters['email_content'] = $this->_get_email_content_template(); } $this->parameters['confirm_email'] = ($parameter_confirm_email ? 1 : 0); } public function save() { global $msg; $query = "update contact_forms set contact_form_parameters = '".addslashes(encoding_normalize::json_encode($this->parameters))."' where id_contact_form='".$this->id."'"; $result = pmb_mysql_query($query); if($result) { $this->message = $msg['admin_opac_contact_form_parameters_save_success']; return true; } else { $this->message = $msg['admin_opac_contact_form_parameters_save_error']; return false; } } protected function _get_email_content_template() { global $include_path; $email_content = ''; if (file_exists($include_path.'/templates/contact_forms/email_content_subst.html')) { $template_path = $include_path.'/templates/contact_forms/email_content_subst.html'; } else { $template_path = $include_path.'/templates/contact_forms/email_content.html'; } if (file_exists($template_path)) { $email_content = file_get_contents($template_path); } return $email_content; } public function get_parameters() { return $this->parameters; } public function get_message() { return $this->message; } public function set_message($message) { $this->message = $message; } }