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 / Campaigns / Followup.php

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

380 lines 13.1 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\Campaigns;
4
5 use AcyMailing\Classes\FollowupClass;
6 use AcyMailing\Classes\MailClass;
7 use AcyMailing\Classes\ListClass;
8 use AcyMailing\Classes\SegmentClass;
9 use AcyMailing\Helpers\WorkflowHelper;
10 use stdClass;
11
12
13 trait Followup
14 {
15 public function followup()
16 {
17 acym_setVar('layout', 'followup');
18
19 $data = [
20 'campaign_type' => MailClass::TYPE_FOLLOWUP,
21 'element_to_display' => lcfirst(acym_translation('ACYM_FOLLOW_UP')),
22 ];
23 $this->getAllParamsRequest($data);
24 $this->prepareEmailsListing($data, $data['campaign_type'], 'followup');
25 $this->prepareToolbar($data);
26 $this->prepareListingClasses($data);
27 $this->prepareFollowupListing($data);
28
29 parent::display($data);
30 }
31
32 private function prepareFollowupListing(&$data)
33 {
34 $followupClass = new FollowupClass();
35 $triggers = [];
36 acym_trigger('getFollowupTriggers', [&$triggers]);
37 $data['allTriggers'] = $triggers;
38
39 foreach ($data['allCampaigns'] as $key => $oneFollowup) {
40 if (!empty($triggers[$oneFollowup->trigger])) {
41 $oneFollowup->condition = json_decode($oneFollowup->condition, true);
42 $data['allCampaigns'][$key]->condition = $followupClass->getConditionSummary($oneFollowup->condition, $oneFollowup->trigger);
43 $data['allCampaigns'][$key]->mail_ids = $followupClass->getEmailsByIds($oneFollowup->id);
44 }
45 }
46 }
47
48 public function deleteFollowup()
49 {
50 acym_checkToken();
51 $ids = acym_getVar('array', 'elements_checked', []);
52 $allChecked = acym_getVar('string', 'checkbox_all');
53 $currentPage = explode('_', acym_getVar('string', 'page'));
54 $pageNumber = $this->getVarFiltersListing('int', end($currentPage).'_pagination_page', 1);
55
56 if (!empty($ids)) {
57 $followupClass = new FollowupClass();
58 $followupClass->delete($ids);
59 if ($allChecked == 'on') {
60 $this->setVarFiltersListing(end($currentPage).'_pagination_page', $pageNumber - 1);
61 }
62 }
63
64 $this->listing();
65 }
66
67 public function followupTrigger()
68 {
69 acym_setVar('layout', 'followup_trigger');
70
71 $id = acym_getVar('int', 'id', 0);
72
73 if (!empty($id)) {
74 $followupClass = new FollowupClass();
75 $followup = $followupClass->getOneById($id);
76 } else {
77 $followup = new stdClass();
78 }
79
80 $this->setTaskListing('followup');
81
82 $data = [
83 'workflowHelper' => new WorkflowHelper(),
84 'followup' => $followup,
85 ];
86
87 $linkId = empty($id) ? '' : '&id='.$id;
88
89 $this->breadcrumb[empty($id) ? acym_translation('ACYM_NEW_FOLLOW_UP') : $followup->name] = acym_completeLink('campaigns&task=edit&step=followupTrigger'.$linkId);
90
91 parent::display($data);
92 }
93
94 public function followupCondition()
95 {
96 acym_setVar('layout', 'followup_condition');
97
98 $id = acym_getVar('int', 'id', 0);
99 $trigger = acym_getVar('string', 'trigger', '');
100
101 if (!empty($id)) {
102 $followupClass = new FollowupClass();
103 $followup = $followupClass->getOneById($id);
104 } else {
105 $followup = new stdClass();
106 }
107
108 if (empty($trigger) && empty($followup->trigger)) {
109 acym_enqueueMessage(acym_translation('ACYM_COULD_NOT_LOAD_DATA'), 'error');
110 $this->listing();
111
112 return;
113 }
114
115 $listClass = new ListClass();
116 $lists = $listClass->getAllForSelect(false);
117
118 $segmentClass = new SegmentClass();
119 $segments = $segmentClass->getAllForSelect(false);
120
121 $statusArray = [
122 'is' => acym_strtolower(acym_translation('ACYM_IS')),
123 'is_not' => acym_strtolower(acym_translation('ACYM_IS_NOT')),
124 ];
125
126 $additionalCondition = [];
127 acym_trigger('getAcymAdditionalConditionFollowup', [&$additionalCondition, empty($trigger) ? $followup->trigger : $trigger, $followup, $statusArray]);
128
129 $actualTrigger = empty($trigger) ? $followup->trigger : $trigger;
130
131 $data = [
132 'workflowHelper' => new WorkflowHelper(),
133 'followup' => $followup,
134 'additionalCondition' => $additionalCondition,
135 'trigger' => $actualTrigger,
136 'lists_multiselect' => '<span class="cell large-4 medium-6 acym__followup__condition__select__in-text">'.acym_selectMultiple(
137 $lists,
138 'followup[condition][lists]',
139 !empty($followup->condition) && !empty($followup->condition['lists']) ? $followup->condition['lists'] : [],
140 ['class' => 'acym__select']
141 ).'</span>',
142 'segments_multiselect' => '<span class="cell large-4 medium-6 acym__followup__condition__select__in-text">'.acym_selectMultiple(
143 $segments,
144 'followup[condition][segments]',
145 !empty($followup->condition) && !empty($followup->condition['segments']) ? $followup->condition['segments'] : [],
146 ['class' => 'acym__select']
147 ).'</span>',
148 'select_status_lists' => '<span class="cell xxlarge-1 medium-2 acym__followup__condition__select__in-text">'.acym_select(
149 $statusArray,
150 'followup[condition][lists_status]',
151 !empty($followup->condition) && !empty($followup->condition['lists_status']) ? $followup->condition['lists_status'] : '',
152 ['class' => 'acym__select']
153 ).'</span>',
154 'select_status_segments' => '<span class="cell xxlarge-1 medium-2 acym__followup__condition__select__in-text">'.acym_select(
155 $statusArray,
156 'followup[condition][segments_status]',
157 !empty($followup->condition) && !empty($followup->condition['segments_status']) ? $followup->condition['segments_status'] : '',
158 ['class' => 'acym__select']
159 ).'</span>',
160 'lists_subscribe_translation' => $actualTrigger == 'user_subscribe' ? 'ACYM_FOLLOW_UP_CONDITION_USER_SUBSCRIBING' : 'ACYM_FOLLOW_UP_CONDITION_USER_SUBSCRIBE',
161 ];
162
163 $linkId = empty($id) ? '&trigger='.$trigger : '&id='.$id;
164
165 $this->breadcrumb[empty($followup->name) ? acym_translation('ACYM_NEW_FOLLOW_UP') : $followup->name] = acym_completeLink(
166 'campaigns&task=edit&step=followupCondition'.$linkId
167 );
168
169 parent::display($data);
170 }
171
172 public function followupEmail()
173 {
174 acym_setVar('layout', 'followup_email');
175
176 $id = acym_getVar('int', 'id', 0);
177
178 if (empty($id)) {
179 acym_enqueueMessage(acym_translation('ACYM_COULD_NOT_LOAD_DATA'), 'error');
180 $this->listing();
181
182 return;
183 }
184
185 $followupClass = new FollowupClass();
186 $followup = $followupClass->getOneByIdWithMails($id);
187
188 if (empty($followup)) {
189 acym_enqueueMessage(acym_translation('ACYM_COULD_NOT_LOAD_DATA'), 'error');
190 $this->listing();
191
192 return;
193 }
194
195 $favoriteTemplate = $this->config->get('favorite_template', 0);
196 $startFrom = empty($favoriteTemplate) ? '' : '&from='.$favoriteTemplate;
197 $data = [
198 'workflowHelper' => new WorkflowHelper(),
199 'followup' => $followup,
200 'linkNewEmail' => acym_completeLink(
201 'mails&task=edit&step=editEmail&type=followup&followup_id='.$id.'&return='.urlencode(
202 acym_completeLink('campaigns&task=edit&step=followupEmail&id='.$id)
203 ).$startFrom,
204 false,
205 true
206 ),
207 ];
208
209 $this->breadcrumb[empty($followup->name) ? acym_translation('ACYM_NEW_FOLLOW_UP') : $followup->name] = acym_completeLink(
210 'campaigns&task=edit&step=followupEmail&id='.$followup->id
211 );
212
213 if (intval($followup->active) === 1) {
214 $newlyCreatedEmail = acym_getVar('int', 'newEmailId');
215 if (!empty($newlyCreatedEmail)) {
216 $numberOfSubscribers = $followupClass->getNumberSubscribersByListId($followup->list_id, true);
217 if (!empty($numberOfSubscribers)) {
218 $message = '<span class="acym__followup__add_queue" data-acym-email-id="'.intval($newlyCreatedEmail).'">';
219 $message .= acym_translationSprintf('ACYM_FOLLOWUP_ADD_QUEUE', $numberOfSubscribers);
220 $message .= '</span>';
221 acym_enqueueMessage($message, 'info', false);
222 }
223 }
224 }
225
226 parent::display($data);
227 }
228
229 public function followupDuplicateMail()
230 {
231 $mailId = acym_getVar('int', 'action_mail_id', 0);
232 $id = acym_getVar('int', 'id', 0);
233 $followupClass = new FollowupClass();
234 if (!$followupClass->duplicateMail($mailId, $id)) acym_enqueueMessage(acym_translation('ACYM_COULD_NOT_DUPLICATE_MAIL'), 'error');
235
236 $this->followupEmail();
237 }
238
239 public function followupDeleteMail()
240 {
241 $mailId = acym_getVar('int', 'action_mail_id', 0);
242 $followupClass = new FollowupClass();
243 if (!$followupClass->deleteMail($mailId)) acym_enqueueMessage(acym_translation('ACYM_COULD_NOT_DELETE_MAIL'), 'error');
244
245 $step = acym_getVar('cmd', 'step', 'followupEmail');
246 $this->$step();
247 }
248
249 public function followupDraft()
250 {
251 $this->followupFinalize(0);
252 }
253
254 public function followupActivate()
255 {
256 $this->followupFinalize(1);
257 }
258
259 public function followupFinalize($status)
260 {
261 $followupId = acym_getVar('int', 'id', 0);
262 $followupClass = new FollowupClass();
263 $followup = $followupClass->getOneById($followupId);
264 $followup->active = $status;
265 $followupClass->save($followup);
266
267 $this->followup();
268 }
269
270 public function saveFollowupCondition()
271 {
272 if (!acym_isAdmin()) {
273 die('Access denied for follow-ups');
274 }
275
276 $id = acym_getVar('int', 'id', 0);
277 $trigger = acym_getVar('string', 'trigger', '');
278 $followupData = acym_getVar('array', 'followup', []);
279
280 $followupClass = new FollowupClass();
281
282 if (!empty($id)) {
283 $followup = $followupClass->getOneById($id);
284 $followup->condition = json_encode($followupData['condition']);
285 } else {
286 $followup = new stdClass();
287 $followup->name = '';
288 $followup->display_name = '';
289 $followup->creation_date = date('Y-m-d H:i:s', time() - date('Z'));
290 $followup->trigger = $trigger;
291 $followup->condition = json_encode($followupData['condition']);
292 $followup->active = 0;
293 $followup->send_once = 1;
294 }
295
296 $followup->id = $followupClass->save($followup);
297 if (empty($followup->id)) {
298 acym_enqueueMessage(acym_translation('ACYM_ERROR_SAVING').': '.acym_getDBError(), 'error');
299 $this->listing();
300
301 return false;
302 }
303
304 acym_setVar('id', $followup->id);
305
306 return $this->edit();
307 }
308
309 public function saveFollowupEmail($redirect = true)
310 {
311 if (!acym_isAdmin()) {
312 die('Access denied for follow-ups');
313 }
314
315 $id = acym_getVar('int', 'id', 0);
316 $followupData = acym_getVar('array', 'followup', []);
317 if (empty($id) || empty($followupData)) return false;
318
319 $followupClass = new FollowupClass();
320 $followup = $followupClass->getOneById($id);
321
322 if (empty($followup)) return false;
323
324 foreach ($followupData as $key => $data) {
325 if (!isset($followup->$key)) continue;
326 $followup->$key = $data;
327 }
328
329 $followup->id = $followupClass->save($followup);
330 acym_setVar('id', $followup->id);
331
332 if ($redirect) {
333 return $this->edit();
334 }
335
336 return true;
337 }
338
339 public function followupSummary()
340 {
341 acym_setVar('layout', 'followup_summary');
342
343 $id = acym_getVar('int', 'id', 0);
344
345 if (empty($id)) {
346 acym_enqueueMessage(acym_translation('ACYM_FOLLOWUP_NOT_FOUND'), 'error');
347 $this->listing();
348
349 return;
350 }
351
352 $followupClass = new FollowupClass();
353 $followup = $followupClass->getOneByIdWithMails($id);
354
355 $data = [
356 'workflowHelper' => new WorkflowHelper(),
357 'followup' => $followup,
358 'condition' => $followupClass->getConditionSummary($followup->condition, $followup->trigger),
359 ];
360
361 $this->breadcrumb[empty($followup->name) ? acym_translation('ACYM_NEW_FOLLOW_UP') : $followup->name] = acym_completeLink(
362 'campaigns&task=edit&step=followupCondition'.$followup->id
363 );
364
365 parent::display($data);
366 }
367
368 public function createNewFollowupMail()
369 {
370 $this->saveFollowupEmail(false);
371 $linkNewEmail = acym_getVar('string', 'linkNewEmail', '');
372
373 if (empty($linkNewEmail)) {
374 $this->edit();
375 } else {
376 acym_redirect($linkNewEmail);
377 }
378 }
379 }
380