PluginProbe
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress / 10.0.1
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress v10.0.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
acymailing / back / Controllers / ToggleController.php

ToggleController.php in AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress 10.0.1, at back/Controllers/ToggleController.php

223 lines 9.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace AcyMailing\Controllers;
4
5 use AcyMailing\Classes\UserClass;
6 use AcyMailing\Core\AcymController;
7
8 class ToggleController extends AcymController
9 {
10 var $toggleableColumns = [];
11 var $icons = [];
12 var $tooltips = [];
13 var $deletableRows = [];
14
15 public function __construct()
16 {
17 parent::__construct();
18
19 $this->defaulttask = 'toggle';
20
21 $this->defineToggles();
22
23 acym_noCache();
24 }
25
26 protected function defineToggles()
27 {
28 $this->toggleableColumns['automation'] = ['active' => 'id'];
29 $this->toggleableColumns['field'] = [
30 'active' => 'id',
31 'required' => 'id',
32 'backend_edition' => 'id',
33 'backend_listing' => 'id',
34 'frontend_edition' => 'id',
35 'frontend_listing' => 'id',
36 ];
37 $this->toggleableColumns['list'] = ['active' => 'id', 'visible' => 'id'];
38 $this->toggleableColumns['rule'] = ['active' => 'id'];
39 $this->toggleableColumns['user'] = ['active' => 'id', 'confirmed' => 'id'];
40 $this->toggleableColumns['form'] = ['active' => 'id'];
41 $this->toggleableColumns['segment'] = ['active' => 'id'];
42 $this->toggleableColumns['campaign'] = ['visible' => 'id'];
43 $this->toggleableColumns['followup'] = ['active' => 'id'];
44 $this->toggleableColumns['mail_override'] = ['active' => 'id'];
45 $this->toggleableColumns['mailbox_action'] = ['active' => 'id'];
46 $this->toggleableColumns['scenario'] = ['active' => 'id'];
47
48 $this->icons['automation']['active'][1] = 'acymicon-check-circle acym__color__green';
49 $this->icons['automation']['active'][0] = 'acymicon-times-circle acym__color__red';
50 $this->icons['field']['active'][1] = 'acymicon-check-circle acym__color__green';
51 $this->icons['field']['active'][0] = 'acymicon-times-circle acym__color__red';
52 $this->icons['field']['required'][1] = 'acymicon-check-circle acym__color__green';
53 $this->icons['field']['required'][0] = 'acymicon-times-circle acym__color__red';
54 $this->icons['field']['backend_edition'][1] = 'acymicon-check-circle acym__color__green';
55 $this->icons['field']['backend_edition'][0] = 'acymicon-times-circle acym__color__red';
56 $this->icons['field']['backend_listing'][1] = 'acymicon-check-circle acym__color__green';
57 $this->icons['field']['backend_listing'][0] = 'acymicon-times-circle acym__color__red';
58 $this->icons['field']['frontend_edition'][1] = 'acymicon-check-circle acym__color__green';
59 $this->icons['field']['frontend_edition'][0] = 'acymicon-times-circle acym__color__red';
60 $this->icons['field']['frontend_listing'][1] = 'acymicon-check-circle acym__color__green';
61 $this->icons['field']['frontend_listing'][0] = 'acymicon-times-circle acym__color__red';
62 $this->icons['list']['active'][1] = 'acymicon-check-circle acym__color__green';
63 $this->icons['list']['active'][0] = 'acymicon-times-circle acym__color__red';
64 $this->icons['list']['visible'][1] = 'acymicon-eye';
65 $this->icons['list']['visible'][0] = 'acymicon-eye-slash acym__color__dark-gray';
66 $this->icons['rule']['active'][0] = 'acymicon-times-circle acym__color__red';
67 $this->icons['rule']['active'][1] = 'acymicon-check-circle acym__color__green';
68 $this->icons['user']['active'][1] = 'acymicon-check-circle acym__color__green';
69 $this->icons['user']['active'][0] = 'acymicon-times-circle acym__color__red';
70 $this->icons['user']['confirmed'][1] = 'acymicon-check-circle acym__color__green';
71 $this->icons['user']['confirmed'][0] = 'acymicon-times-circle acym__color__red';
72 $this->icons['form']['active'][1] = 'acymicon-check-circle acym__color__green';
73 $this->icons['form']['active'][0] = 'acymicon-times-circle acym__color__red';
74 $this->icons['segment']['active'][1] = 'acymicon-check-circle acym__color__green';
75 $this->icons['segment']['active'][0] = 'acymicon-times-circle acym__color__red';
76 $this->icons['campaign']['visible'][1] = 'acymicon-eye';
77 $this->icons['campaign']['visible'][0] = 'acymicon-eye-slash acym__color__dark-gray';
78 $this->icons['followup']['active'][1] = 'acymicon-check-circle acym__color__green';
79 $this->icons['followup']['active'][0] = 'acymicon-times-circle acym__color__red';
80 $this->icons['mail_override']['active'][1] = 'acymicon-check-circle acym__color__green';
81 $this->icons['mail_override']['active'][0] = 'acymicon-times-circle acym__color__red';
82 $this->icons['mailbox_action']['active'][1] = 'acymicon-check-circle acym__color__green';
83 $this->icons['mailbox_action']['active'][0] = 'acymicon-times-circle acym__color__red';
84 $this->icons['scenario']['active'][1] = 'acymicon-check-circle acym__color__green';
85 $this->icons['scenario']['active'][0] = 'acymicon-times-circle acym__color__red';
86
87 $this->tooltips['user']['active'][1] = 'ACYM_ACTIVATED';
88 $this->tooltips['user']['active'][0] = 'ACYM_DEACTIVATED';
89 $this->tooltips['user']['confirmed'][1] = 'ACYM_CONFIRMED';
90 $this->tooltips['user']['confirmed'][0] = 'ACYM_NOT_CONFIRMED';
91 $this->tooltips['list']['active'][1] = 'ACYM_ACTIVATED';
92 $this->tooltips['list']['active'][0] = 'ACYM_DEACTIVATED';
93 $this->tooltips['list']['visible'][1] = 'ACYM_VISIBLE';
94 $this->tooltips['list']['visible'][0] = 'ACYM_INVISIBLE';
95 $this->tooltips['campaign']['visible'][0] = 'ACYM_INVISIBLE';
96 $this->tooltips['campaign']['visible'][1] = 'ACYM_VISIBLE';
97 $this->tooltips['mail_override']['active'][0] = 'ACYM_INACTIVE';
98 $this->tooltips['mail_override']['active'][1] = 'ACYM_ACTIVE';
99
100 $this->deletableRows[] = 'mail';
101 $this->deletableRows[] = 'queue';
102 }
103
104 public function toggle()
105 {
106 acym_checkToken();
107
108 $table = acym_getVar('word', 'table', '');
109 $field = acym_getVar('cmd', 'field', '');
110 $id = acym_getVar('int', 'id', 0);
111 $newValue = acym_getVar('int', 'value', 0);
112 if (!empty($newValue)) $newValue = 1;
113
114 if (empty($table) || empty($field) || empty($id) || empty($this->toggleableColumns[$table][$field])) exit;
115
116 $preciseMethod = $table.ucfirst($field);
117 $globalMethod = $table.'Global';
118 if (method_exists($this, $preciseMethod)) {
119 $this->$preciseMethod($id, $table, $field, $newValue);
120 } elseif (method_exists($this, $globalMethod)) {
121 $this->$globalMethod($id, $table, $field, $newValue);
122 } else {
123 $this->doToggle($id, $table, $field, $newValue);
124 }
125
126 acym_trigger('onAcymToggle'.ucfirst($table).ucfirst($field), [&$id, &$newValue]);
127
128 if (empty($this->icons[$table][$field][$newValue])) {
129 acym_sendAjaxResponse(acym_translation('ACYM_UNAUTHORIZED_ACCESS'), [], false);
130 }
131
132 $data = [];
133 $data['value'] = 1 - $newValue;
134 $data['classes'] = 'acym_toggleable '.$this->icons[$table][$field][$newValue];
135
136 if (!empty($this->tooltips[$table][$field][$newValue])) {
137 $data['tooltip'] = ucfirst(acym_translation($this->tooltips[$table][$field][$newValue]));
138 }
139
140 acym_sendAjaxResponse('', $data);
141 }
142
143 protected function doToggle($id, $table, $field, $newValue)
144 {
145 $updateQuery = 'UPDATE '.acym_secureDBColumn(ACYM_DBPREFIX.$table);
146 $updateQuery .= ' SET `'.acym_secureDBColumn($field).'` = '.intval($newValue);
147 $updateQuery .= ' WHERE `'.acym_secureDBColumn($this->toggleableColumns[$table][$field]).'` = '.intval($id);
148 $updateQuery .= ' LIMIT 1';
149 acym_query($updateQuery);
150 }
151
152 public function delete()
153 {
154 if (!acym_isAdmin()) exit;
155 acym_checkToken();
156
157 $table = acym_getVar('word', 'table', '');
158 $id = acym_getVar('cmd', 'id', 0);
159 $method = acym_getVar('word', 'method', 'delete');
160
161 if (empty($table) || !in_array($table, $this->deletableRows) || empty($id)) {
162 exit;
163 }
164
165 $namespaceClass = 'AcyMailing\\Classes\\'.ucfirst($table).'Class';
166 $elementClass = new $namespaceClass;
167 $elementClass->$method($id);
168
169 exit;
170 }
171
172 public function setDoNotRemindMe()
173 {
174 $newValue = acym_getVar('string', 'value');
175
176 if (empty($newValue)) {
177 acym_sendAjaxResponse(acym_translation('ACYM_ERROR_SAVING'), [], false);
178 }
179
180 $newConfig = new \stdClass();
181 $newConfig->remindme = json_decode($this->config->get('remindme', '[]'));
182 if (!in_array($newValue, $newConfig->remindme)) array_push($newConfig->remindme, $newValue);
183 $newConfig->remindme = json_encode($newConfig->remindme);
184
185 if ($this->config->save($newConfig)) {
186 acym_sendAjaxResponse(acym_translation('ACYM_THANKS'));
187 } else {
188 acym_sendAjaxResponse(acym_translation('ACYM_ERROR_SAVING'), [], false);
189 }
190 }
191
192 public function subscribeOnClick()
193 {
194 $userId = acym_getVar('int', 'userid');
195 $listId = acym_getVar('int', 'listid');
196
197 $userClass = new UserClass();
198 $result = $userClass->subscribe($userId, [$listId]);
199
200 if ($result) {
201 acym_sendAjaxResponse();
202 } else {
203 acym_sendAjaxResponse('', [], false);
204 }
205 }
206
207 public function unsubscribeOnClick()
208 {
209 $userId = acym_getVar('int', 'userid');
210 $listId = acym_getVar('int', 'listid');
211
212 $userClass = new UserClass();
213 $result = $userClass->unsubscribe($userId, [$listId]);
214
215 if ($result) {
216 acym_sendAjaxResponse();
217 } else {
218 acym_sendAjaxResponse('', [], false);
219 }
220 }
221
222 }
223