Skip to content

Commit 978845a

Browse files
committed
3.0.6
1 parent 6be7d29 commit 978845a

File tree

8 files changed

+332
-278
lines changed

8 files changed

+332
-278
lines changed

admin.php

Lines changed: 89 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
class Admin extends BaseAdminController
1717
{
1818

19-
public function __construct() {
20-
19+
public function __construct()
20+
{
2121
parent::__construct();
2222
$lang = new MY_Lang();
2323
$lang->load('xforms');
@@ -29,8 +29,8 @@ public function __construct() {
2929
* Изменение статуса, видим или не видим, для поля формы
3030
* @param int $field_id
3131
*/
32-
public function change_visible($field_id) {
33-
32+
public function change_visible($field_id)
33+
{
3434
$field = $this->xforms_model->get_field($field_id);
3535

3636
if ($field['visible'] == 1) {
@@ -47,32 +47,32 @@ public function change_visible($field_id) {
4747
* @param string $data
4848
* @return bool
4949
*/
50-
public function check_emails($data) {
51-
50+
public function check_emails($data)
51+
{
5252
return $this->form_validation->valid_emails($data);
5353
}
5454

5555
/**
5656
* Удаление полей формы
5757
*/
58-
public function delete_fields() {
59-
58+
public function delete_fields()
59+
{
6060
$this->xforms_model->delete_fields($this->input->post('id'));
6161
}
6262

6363
/**
6464
* Удаление формы
6565
*/
66-
public function delete_form() {
67-
66+
public function delete_form()
67+
{
6868
if (count($this->input->post()) > 0) {
69-
$this->db->where('id', (int) $this->input->post('id'))->delete('xforms');
70-
$this->db->where('fid', (int) $this->input->post('id'))->delete('xforms_field');
69+
$this->db->where('id', (int)$this->input->post('id'))->delete('xforms');
70+
$this->db->where('fid', (int)$this->input->post('id'))->delete('xforms_field');
7171

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

@@ -81,8 +81,8 @@ public function delete_form() {
8181
* @param null|int $fid
8282
* @param null|string $field
8383
*/
84-
public function field($fid = null, $field = null) {
85-
84+
public function field($fid = null, $field = null)
85+
{
8686
if ($this->input->post('type')) {
8787
$this->form_validation->set_rules('value', 'Значение', 'trim|xss_clean');
8888
$this->form_validation->set_rules('desc', 'Описание', 'trim|xss_clean|max_length[255]');
@@ -96,21 +96,22 @@ public function field($fid = null, $field = null) {
9696
showMessage(validation_errors(), false, 'r');
9797
} else {
9898
$data = [
99-
'fid' => $fid,
100-
'type' => $this->input->post('type'),
101-
'label' => $this->input->post('name'),
102-
'value' => $this->input->post('value'),
103-
'desc' => $this->input->post('desc'),
104-
'operation' => $this->input->post('operation'),
105-
'position' => $this->input->post('position'),
106-
'maxlength' => $this->input->post('maxlength'),
107-
'checked' => $this->input->post('check'),
108-
'disabled' => $this->input->post('disable'),
109-
'require' => $this->input->post('required'),
110-
'validation' => $this->input->post('validation'),
111-
'visible' => $this->input->post('visible'),
112-
'allowed_types' => $this->input->post('allowed_types'),
113-
];
99+
'fid' => $fid,
100+
'type' => $this->input->post('type'),
101+
'label' => $this->input->post('name'),
102+
'value' => $this->input->post('value'),
103+
'error_message' => $this->input->post('error_message'),
104+
'desc' => $this->input->post('desc'),
105+
'operation' => $this->input->post('operation'),
106+
'position' => $this->input->post('position'),
107+
'maxlength' => $this->input->post('maxlength'),
108+
'checked' => $this->input->post('check'),
109+
'disabled' => $this->input->post('disable'),
110+
'require' => $this->input->post('required'),
111+
'validation' => $this->input->post('validation'),
112+
'visible' => $this->input->post('visible'),
113+
'allowed_types' => $this->input->post('allowed_types'),
114+
];
114115

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

127-
$this->xforms_model->update_field((int) $field, $data);
128+
$this->xforms_model->update_field((int)$field, $data);
128129
showMessage(lang('Changes has been saved', 'xforms'));
129130
$path = '/admin/components/cp/xforms/field/' . $fid . '/' . $field;
130131
}
@@ -138,7 +139,7 @@ public function field($fid = null, $field = null) {
138139
} else {
139140
if ($field) {
140141
assetManager::create()
141-
->setData('field', $this->xforms_model->get_field((int) $field))
142+
->setData('field', $this->xforms_model->get_field((int)$field))
142143
->setData('fid', $fid)
143144
->renderAdmin('field');
144145
} else {
@@ -151,23 +152,22 @@ public function field($fid = null, $field = null) {
151152
* EDIT and ADD field for form
152153
* @param int $id
153154
*/
154-
public function fields($id) {
155-
155+
public function fields($id)
156+
{
156157
assetManager::create()
157158
->setData('fields', $this->xforms_model->get_form_fields($id))
158159
->setData('form_name', $this->xforms_model->get_form_name($id))
159160
->setData('form_id', $id)
160161
->renderAdmin('fields');
161-
162162
}
163163

164164
/**
165165
* CREATE and EDIT form
166166
* создание / редактирование формы
167167
* @param null|int $id
168168
*/
169-
public function form($id = null) {
170-
169+
public function form($id = null)
170+
{
171171
// Сохраняем
172172
if ($this->input->post()) {
173173

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

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

200200
$email_data = [
201-
'subject' => $this->input->post('subject'),
202-
'email' => $this->input->post('email'),
201+
'subject' => $this->input->post('subject'),
202+
'email' => $this->input->post('email'),
203203
];
204204

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

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

@@ -264,8 +264,8 @@ public function form($id = null) {
264264
/**
265265
* Show list forms in admin panel
266266
*/
267-
public function index() {
268-
267+
public function index()
268+
{
269269
$xforms = $this->xforms_model->get_forms();
270270
foreach ($xforms as $key => $f) {
271271
$xforms[$key]['cmsemail_id'] = $this->db->select('id')->where('name', 'xforms_send_form_' . $f['id'])->get('mod_email_paterns')->row_array()['id'];
@@ -277,14 +277,34 @@ public function index() {
277277
/**
278278
* Sort fields in the form
279279
*/
280-
public function update_positions() {
281-
280+
public function update_positions()
281+
{
282282
$positions = $this->input->post('positions');
283283

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

288288
showMessage('Позиция обновлена');
289289
}
290+
291+
292+
/**
293+
* Обновление модуля
294+
*/
295+
public function update()
296+
{
297+
/**
298+
* с 3.0 версии до 3.0.6
299+
* Добавим колонку с сообщением об ошибке
300+
*/
301+
$xforms_field = [
302+
'error_message' => [
303+
'type' => 'varchar',
304+
'constraint' => 255,
305+
]
306+
];
307+
$this->load->dbforge();
308+
$this->dbforge->add_column('xforms_field', $xforms_field);
309+
}
290310
}

assets/admin/field.tpl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,18 @@
132132
</div>
133133
</div>
134134

135+
<div class="control-group">
136+
<label class="control-label" for="error_message">
137+
Сообщение об ошибке
138+
</label>
139+
<div class="controls">
140+
<div class="o_h">
141+
<input type="text" name="error_message" id="error_message" value="{$field.error_message}"/>
142+
</div>
143+
<span class="help-block">Показывается когда есть какое-нибудь Условие проверки или поле обязательно. (по умолчанию используются системные сообщения)</span>
144+
</div>
145+
</div>
146+
135147
<div class="control-group" style="display:{if $field.type == 'file'}block{else:}none{/if}">
136148
<label class="control-label" for="allowed_types">Расширения файлов:</label>
137149
<div class="controls">

changelog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
##### UPD: 07/08/18 - Версия 3.0.6
2+
* Форматирование php кода.
3+
* добавлен функционал вывода кастомных ошибок для полей.
4+
15
##### UPD: 07/08/18 - Версия 3.0.5.1
26
* (bugfix) Ошибка создания формы из-за наличия отсутствующих полей в БД subject и email.
37

0 commit comments

Comments
 (0)