| @@ -1,0 +1,125 @@ | ||
| 1 | +<?php | |
| 2 | + | |
| 3 | +namespace AcyMailing\Controllers\Automations; | |
| 4 | + | |
| 5 | +use AcyMailing\Classes\ActionClass; | |
| 6 | +use AcyMailing\Classes\AutomationClass; | |
| 7 | +use AcyMailing\Classes\ConditionClass; | |
| 8 | +use AcyMailing\Classes\MailClass; | |
| 9 | +use AcyMailing\Classes\StepClass; | |
| 10 | +use AcyMailing\Classes\TagClass; | |
| 11 | +use AcyMailing\Helpers\WorkflowHelper; | |
| 12 | + | |
| 13 | +trait Action | |
| 14 | +{ | |
| 15 | + public function action(): void | |
| 16 | + { | |
| 17 | + | |
| 18 | + if (!acym_level(ACYM_ENTERPRISE)) { | |
| 19 | + acym_redirect(acym_completeLink('dashboard&task=upgrade&version=enterprise', false, true)); | |
| 20 | + } | |
| 21 | + } | |
| 22 | + | |
| 23 | + private function getSaveActions(bool $isMassAction = false): array | |
| 24 | + { | |
| 25 | + $automationID = acym_getVar('int', 'id'); | |
| 26 | + $actionId = acym_getVar('int', 'actionId'); | |
| 27 | + $action = acym_getVar('array', 'acym_action'); | |
| 28 | + $actionClass = new ActionClass(); | |
| 29 | + $stepAutomationId = acym_getVar('int', 'stepAutomationId'); | |
| 30 | + $conditionId = acym_getVar('int', 'conditionId'); | |
| 31 | + | |
| 32 | + if ((!empty($conditionId))) { | |
| 33 | + $action['condition_id'] = $conditionId; | |
| 34 | + } | |
| 35 | + | |
| 36 | + if (!empty($actionId)) { | |
| 37 | + $action['id'] = $actionId; | |
| 38 | + } | |
| 39 | + | |
| 40 | + if (empty($action['actions'])) { | |
| 41 | + $action['actions'] = []; | |
| 42 | + } | |
| 43 | + | |
| 44 | + if ($isMassAction) { | |
| 45 | + $massAction = acym_getVar('array', 'massAction', [], 'SESSION'); | |
| 46 | + $massAction['actions'] = $action['actions']; | |
| 47 | + acym_setSession('massAction', $massAction); | |
| 48 | + | |
| 49 | + return []; | |
| 50 | + } | |
| 51 | + | |
| 52 | + $action['actions'] = json_encode($action['actions']); | |
| 53 | + | |
| 54 | + foreach ($action as $column => $value) { | |
| 55 | + acym_secureDBColumn($column); | |
| 56 | + } | |
| 57 | + | |
| 58 | + //We need an object to save it so we make a object | |
| 59 | + $action = (object)$action; | |
| 60 | + | |
| 61 | + $action->id = $actionClass->save($action); | |
| 62 | + | |
| 63 | + return [ | |
| 64 | + 'automationId' => $automationID, | |
| 65 | + 'stepId' => $stepAutomationId, | |
| 66 | + 'actionId' => $action->id, | |
| 67 | + ]; | |
| 68 | + } | |
| 69 | + | |
| 70 | + public function saveExitActions(): void | |
| 71 | + { | |
| 72 | + wp_verify_nonce(acym_getVar('cmd', '_wpnonce'), 'acymnonce') || die('Invalid Token'); | |
| 73 | + | |
| 74 | + $this->getSaveActions(); | |
| 75 | + | |
| 76 | + acym_enqueueMessage(acym_translation('ACYM_SUCCESSFULLY_SAVED')); | |
| 77 | + | |
| 78 | + $this->listing(); | |
| 79 | + } | |
| 80 | + | |
| 81 | + public function saveActions(): void | |
| 82 | + { | |
| 83 | + wp_verify_nonce(acym_getVar('cmd', '_wpnonce'), 'acymnonce') || die('Invalid Token'); | |
| 84 | + | |
| 85 | + $ids = $this->getSaveActions(); | |
| 86 | + | |
| 87 | + acym_setVar('id', $ids['automationId']); | |
| 88 | + acym_setVar('stepId', $ids['stepId']); | |
| 89 | + acym_setVar('actionId', $ids['actionId']); | |
| 90 | + $this->filter(); | |
| 91 | + } | |
| 92 | + | |
| 93 | + public function createMail(): void | |
| 94 | + { | |
| 95 | + wp_verify_nonce(acym_getVar('cmd', '_wpnonce'), 'acymnonce') || die('Invalid Token'); | |
| 96 | + | |
| 97 | + $id = acym_getVar('int', 'id'); | |
| 98 | + $idAdmin = acym_getVar('boolean', 'automation_admin'); | |
| 99 | + $type = MailClass::TYPE_AUTOMATION; | |
| 100 | + if ($idAdmin) { | |
| 101 | + $type = 'automation_admin'; | |
| 102 | + } | |
| 103 | + | |
| 104 | + $and = acym_getVar('string', 'and_action'); | |
| 105 | + $this->getSaveActions(empty($id)); | |
| 106 | + | |
| 107 | + $actions = acym_getVar('array', 'acym_action'); | |
| 108 | + $mailId = $actions['actions'][$and]['acy_add_queue']['mail_id']; | |
| 109 | + $mailId = empty($mailId) ? '' : '&id='.$mailId; | |
| 110 | + | |
| 111 | + $mailClass = new MailClass(); | |
| 112 | + $favoriteTemplate = $mailClass->getFavoriteTemplateId(); | |
| 113 | + $startFrom = empty($favoriteTemplate) || !empty($mailId) ? '' : '&from='.$favoriteTemplate; | |
| 114 | + | |
| 115 | + acym_redirect( | |
| 116 | + acym_completeLink( | |
| 117 | + 'mails&task=edit&step=editEmail&type='.$type.$mailId.'&return='.urlencode( | |
| 118 | + acym_completeLink('automation&task=edit&step=action&id='.$id.'&fromMailEditor=1&mailid={mailid}&and='.$and) | |
| 119 | + ).$startFrom, | |
| 120 | + false, | |
| 121 | + true | |
| 122 | + ) | |
| 123 | + ); | |
| 124 | + } | |
| 125 | +} | |