PluginProbe
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress / 11.1.1
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress v11.1.1
11.1.1 11.1.0 11.0.5 11.0.4 11.0.3 11.0.2 11.0.1 11.0.0 10.11.1 10.11.0 10.10.2 10.10.1 10.10.0 10.9.1 trunk 10.0.0 10.0.1 10.1.0 10.1.1 10.1.2 10.1.3 10.1.4 10.2.0 10.2.1 10.2.2 All 62 releases
← All changes | back/Controllers/Fields/Edition.php +0 -235 10.2.2 → 11.1.1 View file →
@@ -1,235 +1,0 @@
1 -<?php
2 -
3 -namespace AcyMailing\Controllers\Fields;
4 -
5 -use AcyMailing\Classes\FieldClass;
6 -use AcyMailing\Types\OperatorType;
7 -
8 -trait Edition
9 -{
10 - public function edit(): void
11 - {
12 - acym_setVar('layout', 'edit');
13 - $fieldId = acym_getVar('int', 'fieldId');
14 - $fieldClass = new FieldClass();
15 - $languageFieldId = $fieldClass->getLanguageFieldId();
16 -
17 - if (empty($fieldId)) {
18 - $field = new \stdClass();
19 - $field->id = 0;
20 - $field->name = '';
21 - $field->active = 1;
22 - $field->type = 'text';
23 - $field->value = '';
24 - $field->option = '';
25 - $field->default_value = '';
26 - $field->required = 0;
27 - $field->backend_edition = 1;
28 - $field->backend_listing = 0;
29 - $field->frontend_edition = 1;
30 - $field->frontend_listing = 0;
31 - $field->fieldDB = new \stdClass();
32 - } else {
33 - $field = $fieldClass->getOneById($fieldId);
34 - $field->option = empty($field->option) ? new \stdClass() : json_decode($field->option);
35 - $field->value = empty($field->value) ? [] : json_decode($field->value);
36 - $field->fieldDB = empty($field->option->fieldDB) ? new \stdClass() : json_decode($field->option->fieldDB);
37 - if (!in_array($fieldId, [1, 2, $languageFieldId]) && !empty($field->fieldDB->table)) {
38 - $databaseExists = acym_loadResult('SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = '.acym_escapeDB($field->fieldDB->database));
39 - if (!empty($databaseExists)) {
40 - $tables = acym_loadResultArray('SHOW TABLES FROM `'.acym_secureDBColumn($field->fieldDB->database).'`');
41 - $field->fieldDB->tables = [];
42 - foreach ($tables as $one) {
43 - $field->fieldDB->tables[$one] = $one;
44 - }
45 - if (empty($field->fieldDB->table)) {
46 - $columns = [];
47 - } else {
48 - $tables = acym_loadResultArray(
49 - 'SELECT table_name
50 - FROM information_schema.tables
51 - WHERE table_schema = '.acym_escapeDB($field->fieldDB->database)
52 - );
53 - if (in_array($field->fieldDB->table, $tables)) {
54 - $columns = acym_loadResultArray(
55 - 'SHOW COLUMNS FROM `'.acym_secureDBColumn($field->fieldDB->table).'` FROM `'.acym_secureDBColumn($field->fieldDB->database).'`'
56 - );
57 - } else {
58 - $columns = [];
59 - }
60 - }
61 - $field->fieldDB->columns = [];
62 - foreach ($columns as $one) {
63 - $field->fieldDB->columns[$one] = $one;
64 - }
65 - array_unshift($field->fieldDB->columns, acym_translation('ACYM_CHOOSE_COLUMN'));
66 - }
67 - }
68 - }
69 -
70 - if (!empty($fieldId)) {
71 - $this->breadcrumb[acym_escape(acym_translation($field->name))] = acym_completeLink('fields&task=edit&fieldId='.$fieldId);
72 - } else {
73 - $this->breadcrumb[acym_translation('ACYM_NEW_CUSTOM_FIELD')] = acym_completeLink('fields&task=edit');
74 - }
75 -
76 - $allFields = $fieldClass->getAll();
77 -
78 - $allFieldsName = [];
79 - foreach ($allFields as $one) {
80 - $allFieldsName[$one->id] = $one->name;
81 - }
82 -
83 - $data = [
84 - 'field' => $field,
85 - 'database' => acym_getDatabases(),
86 - 'allFields' => $allFieldsName,
87 - 'operatorType' => new OperatorType(),
88 - 'languageFieldId' => $languageFieldId,
89 - ];
90 -
91 - $data['fieldType'] = [
92 - 'text' => acym_translation('ACYM_TEXT'),
93 - 'textarea' => acym_translation('ACYM_TEXTAREA'),
94 - 'radio' => acym_translation('ACYM_RADIO'),
95 - 'checkbox' => acym_translation('ACYM_CHECKBOX'),
96 - 'single_dropdown' => acym_translation('ACYM_SINGLE_DROPDOWN'),
97 - 'multiple_dropdown' => acym_translation('ACYM_MULTIPLE_DROPDOWN'),
98 - 'date' => acym_translation('ACYM_DATE'),
99 - 'file' => acym_translation('ACYM_FILE'),
100 - 'phone' => acym_translation('ACYM_PHONE'),
101 - 'custom_text' => acym_translation('ACYM_CUSTOM_TEXT'),
102 - 'language' => acym_translation('ACYM_LANGUAGE'),
103 - ];
104 -
105 - $this->prepareMultilingualOption($data);
106 -
107 - parent::display($data);
108 - }
109 -
110 - public function ajaxGetTables(): void
111 - {
112 - $database = acym_getVar('string', 'database');
113 - $allTables = acym_loadResultArray('SHOW TABLES FROM `'.$database.'`');
114 -
115 - acym_sendAjaxResponse('', ['tables' => $allTables]);
116 - }
117 -
118 - public function ajaxGetColumns(): void
119 - {
120 - $table = acym_getVar('string', 'table');
121 - $database = acym_getVar('string', 'database');
122 -
123 - $columns = acym_loadResultArray('SHOW COLUMNS FROM `'.$table.'` FROM `'.$database.'`');
124 - array_unshift($columns, 'ACYM_CHOOSE_COLUMN');
125 -
126 - acym_sendAjaxResponse('', ['columns' => $columns]);
127 - }
128 -
129 - public function apply(): void
130 - {
131 - $this->saveField();
132 - $this->edit();
133 - }
134 -
135 - public function save(): void
136 - {
137 - $this->saveField();
138 - $this->listing();
139 - }
140 -
141 - protected function saveField(): void
142 - {
143 - $fieldClass = new FieldClass();
144 - $newField = $this->setFieldToSave();
145 - $fieldId = empty($newField->name) ? null : $fieldClass->save($newField);
146 - if (!empty($fieldId)) {
147 - acym_setVar('fieldId', $fieldId);
148 - acym_enqueueMessage(acym_translation('ACYM_SUCCESSFULLY_SAVED'));
149 - } else {
150 - acym_enqueueMessage(acym_translation('ACYM_ERROR_SAVING'), 'error');
151 - }
152 - }
153 -
154 - private function setFieldToSave(): object
155 - {
156 - $fieldClass = new FieldClass();
157 - $languageFieldId = $fieldClass->getLanguageFieldId();
158 - $field = acym_getVar('array', 'field');
159 - $fieldDB = json_encode(acym_getVar('array', 'fieldDB'));
160 - $fieldId = acym_getVar('int', 'fieldId');
161 - if (in_array($fieldId, [2, $languageFieldId])) {
162 - $field['required'] = 1;
163 - }
164 -
165 - $newField = new \stdClass();
166 - if (empty($field['name'])) {
167 - return $newField;
168 - }
169 -
170 - if (in_array($fieldId, [1, 2])) {
171 - $field['type'] = 'text';
172 - } elseif ($fieldId == $languageFieldId) {
173 - $field['type'] = 'language';
174 - }
175 -
176 - $i = 0;
177 - $value = [];
178 - $fieldValues = empty($field['value']) ? [] : $field['value'];
179 - if (!empty($fieldValues['value'])) {
180 - foreach ($fieldValues['value'] as $one) {
181 - if (empty($one) && $one != '0' && ($i != 0 || !in_array($field['type'], ['single_dropdown', 'multiple_dropdown']))) {
182 - $i++;
183 - continue;
184 - }
185 -
186 - $value[$i] = [
187 - 'value' => $one,
188 - 'title' => $fieldValues['title'][$i],
189 - 'disabled' => $fieldValues['disabled'][$i],
190 - ];
191 - $i++;
192 - }
193 - }
194 -
195 - $field['name'] = strip_tags($field['name'], '<i><b><strong>');
196 - $field['namekey'] = empty($field['namekey']) ? $fieldClass->generateNamekey($field['name']) : $field['namekey'];
197 - $field['option']['format'] = $field['type'] === 'date' && empty($field['option']['format']) ? '%d%m%y' : strtolower($field['option']['format']);
198 - $field['option']['rows'] = ($field['type'] == 'textarea' && empty($field['option']['rows'])) ? '5' : $field['option']['rows'];
199 - $field['option']['columns'] = ($field['type'] == 'textarea' && empty($field['option']['columns'])) ? '30' : $field['option']['columns'];
200 -
201 - $field['value'] = json_encode($value);
202 - $field['option']['fieldDB'] = $fieldDB;
203 - if (!empty($field['option']['format'])) {
204 - $field['option']['format'] = preg_replace('/[^a-z\%]/', '', $field['option']['format']);
205 - $field['option']['format'] = preg_replace('/\%[^ymd]/', '', $field['option']['format']);
206 - }
207 -
208 - $newField->name = $field['name'];
209 - $newField->active = $field['active'];
210 - $newField->namekey = $field['namekey'];
211 - $newField->type = $field['type'];
212 - $newField->required = $field['required'];
213 - $newField->option = json_encode($field['option']);
214 - $newField->value = $field['value'];
215 - $newField->default_value = $field['default_value'];
216 - if (ACYM_CMS == 'joomla') {
217 - $newField->frontend_edition = $field['frontend_edition'];
218 - $newField->frontend_listing = $field['frontend_listing'];
219 - }
220 - $newField->backend_edition = $field['backend_edition'];
221 - $newField->backend_listing = $field['backend_listing'];
222 -
223 - if (empty($fieldId)) {
224 - $newField->ordering = $fieldClass->getOrdering() + 1;
225 - } else {
226 - $newField->id = $fieldId;
227 - }
228 -
229 - if (!empty($field['translation'])) {
230 - $newField->translation = $field['translation'];
231 - }
232 -
233 - return $newField;
234 - }
235 -}