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);
 }
 private function init()
 {
     $this->lang = LangLoader::get('admin-user-common');
     $this->view = new FileTemplate('contact/AdminContactFieldsListController.tpl');
     $this->view->add_lang($this->lang);
     $this->config = ContactConfig::load();
 }
 private function init()
 {
     $this->lang = LangLoader::get('common', 'contact');
     $this->view = new FileTemplate('contact/ContactController.tpl');
     $this->view->add_lang($this->lang);
     $this->config = ContactConfig::load();
 }
 private function init(HTTPRequestCustom $request)
 {
     $this->lang = LangLoader::get('common', 'contact');
     $this->admin_user_common_lang = LangLoader::get('admin-user-common');
     $this->config = ContactConfig::load();
     $this->id = $request->get_getint('id', 0);
 }
 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 execute(HTTPRequestCustom $request)
 {
     $id = $request->get_int('id', 0);
     $display = -1;
     if ($id !== 0) {
         $config = ContactConfig::load();
         $fields = $config->get_fields();
         if ($fields[$id]['displayed']) {
             $display = $fields[$id]['displayed'] = 0;
         } else {
             $display = $fields[$id]['displayed'] = 1;
         }
         $config->set_fields($fields);
         ContactConfig::save();
     }
     return new JSONResponse(array('id' => $id, 'display' => $display));
 }
 public function validate(FormField $field)
 {
     $field_name = ContactField::rewrite_field_name($field->get_value());
     $valid = true;
     if (!empty($this->field_id)) {
         foreach (ContactConfig::load()->get_fields() as $id => $f) {
             if ($id != $this->field_id && $f['field_name'] == $field_name) {
                 $valid = false;
             }
         }
     } else {
         foreach (ContactConfig::load()->get_fields() as $id => $f) {
             if ($f['field_name'] == $field_name) {
                 $valid = false;
             }
         }
     }
     return $valid;
 }
 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;
 }
 public function execute(HTTPRequestCustom $request)
 {
     $id = $request->get_value('id', 0);
     $name = $request->get_value('name', '');
     $field_name = ContactField::rewrite_field_name($name);
     $result = 0;
     if (!empty($id)) {
         foreach (ContactConfig::load()->get_fields() as $key => $f) {
             if ($key != $id && $f['field_name'] == $field_name) {
                 $result = 1;
             }
         }
     } else {
         foreach (ContactConfig::load()->get_fields() as $key => $f) {
             if ($f['field_name'] == $field_name) {
                 $result = 1;
             }
         }
     }
     return new JSONResponse(array('result' => $result));
 }
 private function init()
 {
     $this->lang = LangLoader::get('common', 'contact');
     $this->config = ContactConfig::load();
 }
 private function get_authorizations($bit)
 {
     return AppContext::get_current_user()->check_auth(ContactConfig::load()->get_authorizations(), $bit);
 }