id = intval($id);
$this->set_mode($mode);
$this->_init_recipients();
$this->fetch_data();
}
/**
* Initialisation
*/
protected function _init_recipients() {
$this->recipients = array(
'by_persons' => array(),
'by_objects' => array(),
'by_locations' => array()
);
}
/**
* Données provenant de la base de données
*/
protected function fetch_data() {
$query = 'select contact_form_recipients 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_recipients) {
$recipients = encoding_normalize::json_decode($row->contact_form_recipients, true);
if(is_array($recipients)) {
$this->recipients = $recipients;
}
}
}
}
protected function _get_recipients_lines($id) {
global $msg, $charset;
return "
".htmlentities($msg['admin_opac_contact_form_recipient_name'], ENT_QUOTES, $charset)."
recipients[$this->mode][$id]['name'], ENT_QUOTES, $charset) : '')."' />
".htmlentities($msg['admin_opac_contact_form_recipient_email'], ENT_QUOTES, $charset)."
recipients[$this->mode][$id]['email'], ENT_QUOTES, $charset) : '')."' />
".htmlentities($msg['admin_opac_contact_form_recipient_copy_email'], ENT_QUOTES, $charset)."
recipients[$this->mode][$id]['copy_email'], ENT_QUOTES, $charset) : '')."' />
".htmlentities($msg['admin_opac_contact_form_recipient_transmitter_email'], ENT_QUOTES, $charset)."
recipients[$this->mode][$id]['transmitter_email'], ENT_QUOTES, $charset) : '')."' />
";
}
protected function _get_display_lines_email_object_free_entry() {
global $msg, $charset;
$display = "
".htmlentities($msg['admin_opac_contact_form_recipients_email_object_free_entry'], ENT_QUOTES, $charset)." ";
$display .= $this->_get_recipients_lines(0);
$display .= "
";
return $display;
}
protected function _get_display_content_list_by_objects() {
$display = "";
$contact_form_objects=new contact_form_objects($this->id);
if(count($contact_form_objects->get_objects())) {
foreach ($contact_form_objects->get_objects() as $object) {
$display .= "
".$object->get_label()." ";
$display .= $this->_get_recipients_lines($object->get_id());
$display .= "
";
}
}
return $display;
}
protected function _get_display_content_list_by_locations() {
$display = "";
$query = "select idlocation, location_libelle from docs_location order by location_libelle";
$result = pmb_mysql_query($query);
while($row = pmb_mysql_fetch_object($result)) {
$display .= "
".$row->location_libelle." ";
$display .= $this->_get_recipients_lines($row->idlocation);
$display .= "
";
}
return $display;
}
protected function _get_display_content_list_by_persons() {
global $msg, $charset;
global $base_path;
$display = "".htmlentities($msg['admin_opac_contact_form_recipient_add'], ENT_QUOTES, $charset)." mode."&id=".$this->id."';\" /> ";
if(count($this->recipients['by_persons'])) {
foreach ($this->recipients['by_persons'] as $key=>$person) {
$display .= "
";
}
}
return $display;
}
/**
* Liste des destinataires par mode
*/
public function get_display_content_list() {
$display = "";
switch ($this->mode) {
case 'by_persons':
$display .= $this->_get_display_content_list_by_persons();
break;
case 'by_objects':
$display .= $this->_get_display_lines_email_object_free_entry();
$display .= $this->_get_display_content_list_by_objects();
break;
case 'by_locations':
$display .= $this->_get_display_content_list_by_locations();
break;
}
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 liste
*/
public function get_display_list() {
global $base_path, $msg, $charset;
global $current_module;
$display = "";
$reci = encoding_normalize::json_encode($this->recipients[$this->mode]);
$display .= "";
return $display;
}
public static function is_incomplete($recipient) {
if((trim($recipient['name']) == '') || (trim($recipient['email']) == '')) {
return true;
} else {
return false;
}
}
public function set_properties_from_form() {
global $recipients;
$this->recipients[$this->mode] = stripslashes_array($recipients[$this->mode]);
}
public function save() {
global $msg;
$query = "update contact_forms set
contact_form_recipients = '".addslashes(encoding_normalize::json_encode($this->recipients))."'
where id_contact_form='".$this->id."'";
$result = pmb_mysql_query($query);
if($result) {
$this->message = $msg['admin_opac_contact_form_recipients_save_success'];
return true;
} else {
$this->message = $msg['admin_opac_contact_form_recipients_save_error'];
return false;
}
}
public function add() {
if(!is_array($this->recipients[$this->mode])) {
$this->recipients[$this->mode] = array();
}
$this->recipients[$this->mode][] = array();
}
public function delete($id) {
if(isset($this->recipients[$this->mode][$id])) {
unset($this->recipients[$this->mode][$id]);
}
}
public function unset_recipient($id) {
if(is_array($this->recipients[$this->mode][$id])) {
unset($this->recipients[$this->mode][$id]);
}
}
public function get_recipients() {
return $this->recipients;
}
public function get_mode() {
return $this->mode;
}
public function set_mode($mode) {
if(!$mode) {
$contact_form_parameters = new contact_form_parameters($this->id);
$parameters = $contact_form_parameters->get_parameters();
$mode = $parameters['recipients_mode'];
}
$this->mode = $mode;
}
public function get_message() {
return $this->message;
}
public function set_message($message) {
$this->message = $message;
}
}