public function execute(HTTPRequestCustom $request) { $id = $request->get_int('id', 0); $code = -1; if (!empty($id)) { $config = ContactConfig::load(); $fields = $config->get_fields(); if (isset($fields[$id])) { $field = new ContactField(); $field->set_properties($fields[$id]); if ($field->is_deletable()) { unset($fields[$id]); $new_fields_list = array(); $position = 1; foreach ($fields as $key => $f) { $new_fields_list[$position] = $f; $position++; } $config->set_fields($new_fields_list); ContactConfig::save(); $code = $id; } } } return new JSONResponse(array('code' => $code)); }
public function retrieve_value() { $request = AppContext::get_request(); $config = ContactConfig::load(); $fields = $config->get_fields(); $recipients_field_id = $config->get_field_id_by_name('f_recipients'); $recipients_field = new ContactField(); $recipients_field->set_properties($fields[$recipients_field_id]); $recipients = $recipients_field->get_possible_values(); $nb_recipients = count($recipients); $recipients_keys = array_keys($recipients); $values = array(); for ($i = 0; $i <= $this->max_input; $i++) { $field_name = 'field_name_' . $this->get_html_id() . '_' . $i; if ($request->has_postparameter($field_name)) { $field_is_default = 'field_is_default_' . $this->get_html_id() . '_' . $i; $field_title = 'field_name_' . $this->get_html_id() . '_' . $i; $field_email = 'field_email_' . $this->get_html_id() . '_' . $i; $email = $i > 0 ? $request->get_poststring($field_email) : true; if ($request->get_poststring($field_title) && $email) { $id = $i < $nb_recipients ? $recipients_keys[$i] : preg_replace('/\\s+/', '', $request->get_poststring($field_name)); $values[$id] = array('is_default' => $request->get_postint($field_is_default, 0), 'title' => addslashes($request->get_poststring($field_title)), 'email' => $request->get_poststring($field_email, '')); } } } $this->set_value($values); }
public function execute(HTTPRequestCustom $request) { $this->init(); $this->update_fields($request); $fields_number = 0; foreach ($this->config->get_fields() as $id => $properties) { $field = new ContactField(); $field->set_properties($properties); $this->view->assign_block_vars('fields_list', array('C_DELETE' => $field->is_deletable(), 'C_READONLY' => $field->is_readonly(), 'C_DISPLAY' => $field->is_displayed(), 'C_REQUIRED' => $field->is_required(), 'ID' => $id, 'NAME' => $field->get_name(), 'U_EDIT' => ContactUrlBuilder::edit_field($id)->rel())); $fields_number++; } $this->view->put_all(array('C_FIELDS' => $fields_number, 'C_MORE_THAN_ONE_FIELD' => $fields_number > 1)); return new AdminContactDisplayResponse($this->view, LangLoader::get_message('admin.fields.manage.page_title', 'common', 'contact')); }
function display() { $template = $this->get_template_to_use(); $lang = LangLoader::get('common', 'contact'); $config = ContactConfig::load(); $tpl = new FileTemplate('contact/ContactFormFieldObjectPossibleValues.tpl'); $tpl->add_lang($lang); $this->assign_common_template_variables($template); $fields = $config->get_fields(); $recipients_field_id = $config->get_field_id_by_name('f_recipients'); $recipients_field = new ContactField(); $recipients_field->set_properties($fields[$recipients_field_id]); foreach ($recipients_field->get_possible_values() as $id => $options) { if (!empty($options)) { $tpl->assign_block_vars('recipients_list', array('ID' => $id, 'NAME' => stripslashes($options['title']))); } } $i = 0; foreach ($this->get_value() as $name => $options) { if (!empty($options)) { $tpl->assign_block_vars('fieldelements', array('ID' => $i, 'NAME' => stripslashes($options['title']), 'IS_DEFAULT' => (int) $options['is_default'])); foreach ($recipients_field->get_possible_values() as $id => $recipient_options) { if (!empty($recipient_options)) { $tpl->assign_block_vars('fieldelements.recipients_list', array('C_RECIPIENT_SELECTED' => $options['recipient'] == $id, 'ID' => $id, 'NAME' => stripslashes($recipient_options['title']))); } } $i++; } } if ($i == 0) { $tpl->assign_block_vars('fieldelements', array('ID' => $i, 'NAME' => '', 'IS_DEFAULT' => 0)); foreach ($recipients_field->get_possible_values() as $id => $options) { if (!empty($options)) { $tpl->assign_block_vars('fieldelements.recipients_list', array('ID' => $id, 'NAME' => stripslashes($options['title']))); } } $i++; } $tpl->put_all(array('NAME' => $this->get_html_id(), 'HTML_ID' => $this->get_html_id(), 'C_DISABLED' => $this->is_disabled(), 'MAX_INPUT' => $this->max_input, 'NBR_FIELDS' => $i)); $template->assign_block_vars('fieldelements', array('ELEMENT' => $tpl->render())); return $template; }
private function send_mail() { $message = ''; $current_user = AppContext::get_current_user(); $fields = $this->config->get_fields(); $recipients_field_id = $this->config->get_field_id_by_name('f_recipients'); $recipients_field = new ContactField(); $recipients_field->set_properties($fields[$recipients_field_id]); $recipients = $recipients_field->get_possible_values(); $recipients['admins']['email'] = implode(';', MailServiceConfig::load()->get_administrators_mails()); $subject_field_id = $this->config->get_field_id_by_name('f_subject'); $subject_field = new ContactField(); $subject_field->set_properties($fields[$subject_field_id]); $subjects = $subject_field->get_possible_values(); if ($subject_field->get_field_type() == 'ContactShortTextField') { $subject = $this->form->get_value('f_subject'); } else { $subject = $this->form->get_value('f_subject')->get_raw_value(); } $display_message_title = false; if ($this->config->is_tracking_number_enabled()) { $now = new Date(); $tracking_number = $this->config->get_last_tracking_number(); $tracking_number++; $message .= $this->lang['contact.tracking_number'] . ' : ' . ($this->config->is_date_in_tracking_number_enabled() ? $now->get_year() . $now->get_month() . $now->get_day() . '-' : '') . $tracking_number . ' '; $this->config->set_last_tracking_number($tracking_number); ContactConfig::save(); $subject = '[' . $tracking_number . '] ' . $subject; $display_message_title = true; } foreach ($this->config->get_fields() as $id => $properties) { $field = new ContactField(); $field->set_properties($properties); if ($field->is_displayed() && $field->is_authorized() && $field->is_deletable()) { try { $value = ContactFieldsService::get_value($this->form, $field); $message .= $field->get_name() . ': ' . $value . ' '; } catch (Exception $e) { throw new Exception($e->getMessage()); } $display_message_title = true; } } if ($display_message_title) { $message .= $this->lang['contact.form.message'] . ': '; } $message .= $this->form->get_value('f_message'); $mail = new Mail(); $mail->set_sender(MailServiceConfig::load()->get_default_mail_sender(), $this->lang['module_title']); $mail->set_reply_to($this->form->get_value('f_sender_mail'), $current_user->get_level() == User::VISITOR_LEVEL ? $this->lang['module_title'] : $current_user->get_display_name()); $mail->set_subject($subject); $mail->set_content($message); if ($recipients_field->is_displayed()) { if (in_array($recipients_field->get_field_type(), array('ContactSimpleSelectField', 'ContactSimpleChoiceField'))) { $recipients_mails = explode(';', $recipients[$this->form->get_value('f_recipients')->get_raw_value()]['email']); } else { $selected_recipients = $this->form->get_value('f_recipients'); $recipients_mails = array(); foreach ($selected_recipients as $recipient) { $mails = explode(';', $recipients[$recipient->get_id()]['email']); foreach ($mails as $m) { $recipients_mails[] = $m; } } } foreach ($recipients_mails as $mail_address) { $mail->add_recipient($mail_address); } } else { if ($subject_field->get_field_type() != 'ContactShortTextField') { $recipient = $subjects[$this->form->get_value('f_subject')->get_raw_value()]['recipient']; $recipients_mails = explode(';', $recipients[$recipient]['email']); foreach ($recipients_mails as $mail_address) { $mail->add_recipient($mail_address); } } else { $recipients_mails = explode(';', $recipients['admins']['email']); foreach ($recipients_mails as $mail_address) { $mail->add_recipient($mail_address); } } } $mail_service = AppContext::get_mail_service(); if ($this->config->is_sender_acknowledgment_enabled()) { $acknowledgment = new Mail(); $acknowledgment->set_sender(MailServiceConfig::load()->get_default_mail_sender(), Mail::SENDER_ADMIN); $acknowledgment->set_subject('[' . $this->lang['contact.acknowledgment_title'] . '] ' . $subject); $acknowledgment->set_content($this->lang['contact.acknowledgment'] . $message); $acknowledgment->add_recipient($this->form->get_value('f_sender_mail')); return $mail_service->try_to_send($mail) && $mail_service->try_to_send($acknowledgment); } return $mail_service->try_to_send($mail); }