_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('text', 1, 1, 1),
'tel' => $this->_get_field()
),
'recipients_mode' => 'by_persons',
'email_content' => $this->_get_email_content_template(),
'confirm_email' => 1
);
}
protected function fetch_data() {
$query = 'select valeur_param from parametres where type_param="pmb" and sstype_param="contact_form_parameters"';
$result = pmb_mysql_query($query);
if($result && pmb_mysql_num_rows($result)) {
$row = pmb_mysql_fetch_object($result);
if($row->valeur_param) {
$parameters = unserialize($row->valeur_param);
foreach ($this->parameters['fields'] as $name=>$field) {
if(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_content']) {
$this->parameters['email_content'] = $parameters['email_content'];
}
if($parameters['confirm_email'] == 0) {
$this->parameters['confirm_email'] = 0;
}
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 $base_path, $msg, $charset;
return "
";
}
protected function _get_display_toggle($name) {
global $msg, $charset;
return "
parameters[$name] ? "checked='checked'" : "")." />
";
}
/**
* 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_recipients_mode'], ENT_QUOTES, $charset)." |
".self::gen_recipients_mode_selector($this->parameters['recipients_mode'])."
|
".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')." |
";
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;
global $current_module;
$display = "
";
return $display;
}
public function set_properties_from_form() {
global $parameter_fields;
global $parameter_recipients_mode;
global $parameter_email_content;
global $parameter_confirm_email;
if(is_array($parameter_fields)) {
foreach ($parameter_fields as $name=>$field) {
$this->parameters['fields'][$name]['display'] = $field['display'];
$this->parameters['fields'][$name]['mandatory'] = $field['mandatory'];
}
}
$this->parameters['recipients_mode'] = $parameter_recipients_mode;
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 parametres set
valeur_param = '".addslashes(serialize($this->parameters))."'
where type_param='pmb' and sstype_param='contact_form_parameters'";
$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_form/email_content_subst.html')) {
$template_path = $include_path.'/templates/contact_form/email_content_subst.html';
} else {
$template_path = $include_path.'/templates/contact_form/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;
}
}