Skip to content

Commit

Permalink
3.0.6
Browse files Browse the repository at this point in the history
  • Loading branch information
kvalood committed Sep 29, 2018
1 parent 6be7d29 commit 978845a
Show file tree
Hide file tree
Showing 8 changed files with 332 additions and 278 deletions.
158 changes: 89 additions & 69 deletions admin.php
Expand Up @@ -16,8 +16,8 @@
class Admin extends BaseAdminController
{

public function __construct() {

public function __construct()
{
parent::__construct();
$lang = new MY_Lang();
$lang->load('xforms');
Expand All @@ -29,8 +29,8 @@ public function __construct() {
* Изменение статуса, видим или не видим, для поля формы
* @param int $field_id
*/
public function change_visible($field_id) {

public function change_visible($field_id)
{
$field = $this->xforms_model->get_field($field_id);

if ($field['visible'] == 1) {
Expand All @@ -47,32 +47,32 @@ public function change_visible($field_id) {
* @param string $data
* @return bool
*/
public function check_emails($data) {

public function check_emails($data)
{
return $this->form_validation->valid_emails($data);
}

/**
* Удаление полей формы
*/
public function delete_fields() {

public function delete_fields()
{
$this->xforms_model->delete_fields($this->input->post('id'));
}

/**
* Удаление формы
*/
public function delete_form() {

public function delete_form()
{
if (count($this->input->post()) > 0) {
$this->db->where('id', (int) $this->input->post('id'))->delete('xforms');
$this->db->where('fid', (int) $this->input->post('id'))->delete('xforms_field');
$this->db->where('id', (int)$this->input->post('id'))->delete('xforms');
$this->db->where('fid', (int)$this->input->post('id'))->delete('xforms_field');

// Удаляем email шаблон
$email_template = $this->db->select('id')->where('name', 'xforms_send_form_' . $this->input->post('id'))->get('mod_email_paterns')->row_array();
$this->db->where('id', (int) $email_template['id'])->delete('mod_email_paterns');
$this->db->where('id', (int) $email_template['id'])->delete('mod_email_paterns_i18n');
$this->db->where('id', (int)$email_template['id'])->delete('mod_email_paterns');
$this->db->where('id', (int)$email_template['id'])->delete('mod_email_paterns_i18n');
}
}

Expand All @@ -81,8 +81,8 @@ public function delete_form() {
* @param null|int $fid
* @param null|string $field
*/
public function field($fid = null, $field = null) {

public function field($fid = null, $field = null)
{
if ($this->input->post('type')) {
$this->form_validation->set_rules('value', 'Значение', 'trim|xss_clean');
$this->form_validation->set_rules('desc', 'Описание', 'trim|xss_clean|max_length[255]');
Expand All @@ -96,21 +96,22 @@ public function field($fid = null, $field = null) {
showMessage(validation_errors(), false, 'r');
} else {
$data = [
'fid' => $fid,
'type' => $this->input->post('type'),
'label' => $this->input->post('name'),
'value' => $this->input->post('value'),
'desc' => $this->input->post('desc'),
'operation' => $this->input->post('operation'),
'position' => $this->input->post('position'),
'maxlength' => $this->input->post('maxlength'),
'checked' => $this->input->post('check'),
'disabled' => $this->input->post('disable'),
'require' => $this->input->post('required'),
'validation' => $this->input->post('validation'),
'visible' => $this->input->post('visible'),
'allowed_types' => $this->input->post('allowed_types'),
];
'fid' => $fid,
'type' => $this->input->post('type'),
'label' => $this->input->post('name'),
'value' => $this->input->post('value'),
'error_message' => $this->input->post('error_message'),
'desc' => $this->input->post('desc'),
'operation' => $this->input->post('operation'),
'position' => $this->input->post('position'),
'maxlength' => $this->input->post('maxlength'),
'checked' => $this->input->post('check'),
'disabled' => $this->input->post('disable'),
'require' => $this->input->post('required'),
'validation' => $this->input->post('validation'),
'visible' => $this->input->post('visible'),
'allowed_types' => $this->input->post('allowed_types'),
];

if (!$field) {
$field_id = $this->xforms_model->add_field($data);
Expand All @@ -124,7 +125,7 @@ public function field($fid = null, $field = null) {
$path = '/admin/components/cp/xforms/field/' . $fid . '/' . $field_id;
} else {

$this->xforms_model->update_field((int) $field, $data);
$this->xforms_model->update_field((int)$field, $data);
showMessage(lang('Changes has been saved', 'xforms'));
$path = '/admin/components/cp/xforms/field/' . $fid . '/' . $field;
}
Expand All @@ -138,7 +139,7 @@ public function field($fid = null, $field = null) {
} else {
if ($field) {
assetManager::create()
->setData('field', $this->xforms_model->get_field((int) $field))
->setData('field', $this->xforms_model->get_field((int)$field))
->setData('fid', $fid)
->renderAdmin('field');
} else {
Expand All @@ -151,23 +152,22 @@ public function field($fid = null, $field = null) {
* EDIT and ADD field for form
* @param int $id
*/
public function fields($id) {

public function fields($id)
{
assetManager::create()
->setData('fields', $this->xforms_model->get_form_fields($id))
->setData('form_name', $this->xforms_model->get_form_name($id))
->setData('form_id', $id)
->renderAdmin('fields');

}

/**
* CREATE and EDIT form
* создание / редактирование формы
* @param null|int $id
*/
public function form($id = null) {

public function form($id = null)
{
// Сохраняем
if ($this->input->post()) {

Expand All @@ -177,7 +177,7 @@ public function form($id = null) {
$this->form_validation->set_rules('good', lang('Successful message', 'xforms'), 'trim|required');

// Валидируем заголовок темы и email только когда форма еще не создана
if(!$id) {
if (!$id) {
$this->form_validation->set_rules('subject', lang('Email subject', 'xforms'), 'trim|xss_clean|required|min_length[1]|max_length[255]');
$this->form_validation->set_rules('email', 'Email', 'callback_check_emails');
}
Expand All @@ -187,19 +187,19 @@ public function form($id = null) {
} else {
// Собираем данные
$data = [
'title' => $this->input->post('page_title'),
'url' => $this->input->post('page_url'),
'desc' => $this->input->post('desc'),
'success' => $this->input->post('good'),
'captcha' => $this->input->post('captcha'),
'direct_url' => $this->input->post('direct_url'),
'user_message_active' => $this->input->post('user_message_active'),
'action_files' => $this->input->post('action_files'),
];
'title' => $this->input->post('page_title'),
'url' => $this->input->post('page_url'),
'desc' => $this->input->post('desc'),
'success' => $this->input->post('good'),
'captcha' => $this->input->post('captcha'),
'direct_url' => $this->input->post('direct_url'),
'user_message_active' => $this->input->post('user_message_active'),
'action_files' => $this->input->post('action_files'),
];

$email_data = [
'subject' => $this->input->post('subject'),
'email' => $this->input->post('email'),
'subject' => $this->input->post('subject'),
'email' => $this->input->post('email'),
];

// Создаем / сохраняем
Expand All @@ -215,26 +215,26 @@ public function form($id = null) {
// Добавим шаблон "xforms_send" для отправки почты через модуль cmsemail
$this->load->dbforge();
$email_paterns = [
'name' => 'xforms_send_form_' . $id,
'from' => 'Администрация сайта',
'from_email' => '',
'type' => 'HTML',
'patern' => '',
'user_message_active' => 0,
'admin_message_active' => 1,
'admin_email' => $email_data['email']
'name' => 'xforms_send_form_' . $id,
'from' => 'Администрация сайта',
'from_email' => '',
'type' => 'HTML',
'patern' => '',
'user_message_active' => 0,
'admin_message_active' => 1,
'admin_email' => $email_data['email']
];
$this->db->insert('mod_email_paterns', $email_paterns);
$email_patterns_id = $this->db->insert_id();

$email_paterns_i18n = [
'id' => $email_patterns_id,
'locale' => 'ru',
'theme' => $email_data['subject'] ? $email_data['subject'] : 'ImageCMS - Отправка формы - ' . $id,
'user_message' => 'Здравствуйте. Мы свяжемся с вами в ближайшее время.',
'id' => $email_patterns_id,
'locale' => 'ru',
'theme' => $email_data['subject'] ? $email_data['subject'] : 'ImageCMS - Отправка формы - ' . $id,
'user_message' => 'Здравствуйте. Мы свяжемся с вами в ближайшее время.',
'admin_message' => '<p>Пришла заявка.</p><p>$message$</p>',
'description' => 'Отправка формы xforms - ' . $data['title'],
'variables' => 'a:1:{s:9:"$message$";s:46:"Список заполненных полей";}'
'description' => 'Отправка формы xforms - ' . $data['title'],
'variables' => 'a:1:{s:9:"$message$";s:46:"Список заполненных полей";}'
];
$this->db->insert('mod_email_paterns_i18n', $email_paterns_i18n);

Expand Down Expand Up @@ -264,8 +264,8 @@ public function form($id = null) {
/**
* Show list forms in admin panel
*/
public function index() {

public function index()
{
$xforms = $this->xforms_model->get_forms();
foreach ($xforms as $key => $f) {
$xforms[$key]['cmsemail_id'] = $this->db->select('id')->where('name', 'xforms_send_form_' . $f['id'])->get('mod_email_paterns')->row_array()['id'];
Expand All @@ -277,14 +277,34 @@ public function index() {
/**
* Sort fields in the form
*/
public function update_positions() {

public function update_positions()
{
$positions = $this->input->post('positions');

foreach ($positions as $key => $value) {
$this->db->where('id', (int) $value)->set('position', $key)->update('xforms_field');
$this->db->where('id', (int)$value)->set('position', $key)->update('xforms_field');
}

showMessage('Позиция обновлена');
}


/**
* Обновление модуля
*/
public function update()
{
/**
* с 3.0 версии до 3.0.6
* Добавим колонку с сообщением об ошибке
*/
$xforms_field = [
'error_message' => [
'type' => 'varchar',
'constraint' => 255,
]
];
$this->load->dbforge();
$this->dbforge->add_column('xforms_field', $xforms_field);
}
}
12 changes: 12 additions & 0 deletions assets/admin/field.tpl
Expand Up @@ -132,6 +132,18 @@
</div>
</div>

<div class="control-group">
<label class="control-label" for="error_message">
Сообщение об ошибке
</label>
<div class="controls">
<div class="o_h">
<input type="text" name="error_message" id="error_message" value="{$field.error_message}"/>
</div>
<span class="help-block">Показывается когда есть какое-нибудь Условие проверки или поле обязательно. (по умолчанию используются системные сообщения)</span>
</div>
</div>

<div class="control-group" style="display:{if $field.type == 'file'}block{else:}none{/if}">
<label class="control-label" for="allowed_types">Расширения файлов:</label>
<div class="controls">
Expand Down
4 changes: 4 additions & 0 deletions changelog.md
@@ -1,3 +1,7 @@
##### UPD: 07/08/18 - Версия 3.0.6
* Форматирование php кода.
* добавлен функционал вывода кастомных ошибок для полей.

##### UPD: 07/08/18 - Версия 3.0.5.1
* (bugfix) Ошибка создания формы из-за наличия отсутствующих полей в БД subject и email.

Expand Down

0 comments on commit 978845a

Please sign in to comment.