| @@ -1,214 +1,0 @@ | ||
| 1 | -<?php | |
| 2 | - | |
| 3 | -namespace AcyMailing\Controllers; | |
| 4 | - | |
| 5 | -use AcyMailing\Classes\CampaignClass; | |
| 6 | -use AcyMailing\Classes\MailClass; | |
| 7 | -use AcyMailing\Classes\ListClass; | |
| 8 | -use AcyMailing\Classes\UserClass; | |
| 9 | -use AcyMailing\Helpers\MailerHelper; | |
| 10 | -use AcyMailing\Core\AcymController; | |
| 11 | -use AcyMailing\Controllers\Campaigns\Actions; | |
| 12 | -use AcyMailing\Controllers\Campaigns\AutoCampaigns; | |
| 13 | -use AcyMailing\Controllers\Campaigns\Edition; | |
| 14 | -use AcyMailing\Controllers\Campaigns\Followup; | |
| 15 | -use AcyMailing\Controllers\Campaigns\ListEmails; | |
| 16 | -use AcyMailing\Controllers\Campaigns\Listing; | |
| 17 | -use AcyMailing\Controllers\Campaigns\Tests; | |
| 18 | - | |
| 19 | -class CampaignsController extends AcymController | |
| 20 | -{ | |
| 21 | - use Listing; | |
| 22 | - use Followup; | |
| 23 | - use ListEmails; | |
| 24 | - use AutoCampaigns; | |
| 25 | - use Edition; | |
| 26 | - use Actions; | |
| 27 | - use Tests; | |
| 28 | - | |
| 29 | - const TASK_TYPE_CAMPAIGN = 'campaigns'; | |
| 30 | - const TASK_TYPE_CAMPAIGN_AUTO = 'campaigns_auto'; | |
| 31 | - const TASK_TYPE_WELCOME = 'welcome'; | |
| 32 | - const TASK_TYPE_UNSUBSCRIBE = 'unsubscribe'; | |
| 33 | - const TASK_TYPE_FOLLOWUP = 'followup'; | |
| 34 | - const TASK_TYPE_SPECIFIC_LISTING = 'specificListing'; | |
| 35 | - const TASK_TYPE_MAILBOX_ACTION = 'mailbox_action'; | |
| 36 | - | |
| 37 | - const TASKS_TO_REMEMBER_FOR_LISTING = [ | |
| 38 | - '', | |
| 39 | - self::TASK_TYPE_CAMPAIGN, | |
| 40 | - self::TASK_TYPE_CAMPAIGN_AUTO, | |
| 41 | - self::TASK_TYPE_WELCOME, | |
| 42 | - self::TASK_TYPE_UNSUBSCRIBE, | |
| 43 | - self::TASK_TYPE_FOLLOWUP, | |
| 44 | - self::TASK_TYPE_SPECIFIC_LISTING, | |
| 45 | - self::TASK_TYPE_MAILBOX_ACTION, | |
| 46 | - ]; | |
| 47 | - | |
| 48 | - const CAMPAIGN_TYPE_TO_TASK = [ | |
| 49 | - 'now' => self::TASK_TYPE_CAMPAIGN, | |
| 50 | - 'scheduled' => self::TASK_TYPE_CAMPAIGN, | |
| 51 | - 'auto' => self::TASK_TYPE_CAMPAIGN_AUTO, | |
| 52 | - 'followup' => self::TASK_TYPE_FOLLOWUP, | |
| 53 | - 'welcome' => self::TASK_TYPE_WELCOME, | |
| 54 | - 'unsubscribe' => self::TASK_TYPE_UNSUBSCRIBE, | |
| 55 | - 'birthday' => self::TASK_TYPE_SPECIFIC_LISTING, | |
| 56 | - 'woocommerce_cart' => self::TASK_TYPE_SPECIFIC_LISTING, | |
| 57 | - ]; | |
| 58 | - | |
| 59 | - private string $stepContainerClass = ''; | |
| 60 | - | |
| 61 | - public function __construct() | |
| 62 | - { | |
| 63 | - parent::__construct(); | |
| 64 | - | |
| 65 | - $this->defaulttask = 'campaigns'; | |
| 66 | - $this->breadcrumb[acym_translation('ACYM_EMAILS')] = acym_completeLink('campaigns'); | |
| 67 | - $this->loadScripts = [ | |
| 68 | - 'recipients' => ['vue-applications' => ['entity_select']], | |
| 69 | - 'segment' => ['datepicker', 'vue-applications' => ['modal_users_summary']], | |
| 70 | - 'send_settings' => ['datepicker'], | |
| 71 | - 'summary' => ['vue-applications' => ['modal_users_summary']], | |
| 72 | - ]; | |
| 73 | - | |
| 74 | - if (acym_isAdmin()) { | |
| 75 | - $this->stepContainerClass = 'xxlarge-9'; | |
| 76 | - } | |
| 77 | - | |
| 78 | - acym_setVar('edition', '1'); | |
| 79 | - acym_header('X-XSS-Protection:0'); | |
| 80 | - $this->storeRedirectListing(); | |
| 81 | - } | |
| 82 | - | |
| 83 | - public function ajaxCountNumberOfRecipients(): void | |
| 84 | - { | |
| 85 | - $listsSelected = acym_getVar('array', 'listsSelected', []); | |
| 86 | - if (empty($listsSelected)) { | |
| 87 | - acym_sendAjaxResponse('', ['recipients' => 0]); | |
| 88 | - } | |
| 89 | - | |
| 90 | - $listClass = new ListClass(); | |
| 91 | - acym_sendAjaxResponse('', ['recipients' => $listClass->getTotalSubCount($listsSelected)]); | |
| 92 | - } | |
| 93 | - | |
| 94 | - public function deleteAttachmentAjax(): void | |
| 95 | - { | |
| 96 | - $mailId = acym_getVar('int', 'mail', 0); | |
| 97 | - $attachmentId = acym_getVar('int', 'id', 0); | |
| 98 | - | |
| 99 | - if (!empty($mailId) && $attachmentId >= 0) { | |
| 100 | - $mailClass = new MailClass(); | |
| 101 | - | |
| 102 | - if (!$mailClass->hasUserAccess($mailId)) { | |
| 103 | - acym_sendAjaxResponse(acym_translation('ACYM_COULD_NOT_DELETE_ATTACHMENT'), [], false); | |
| 104 | - } | |
| 105 | - | |
| 106 | - if ($mailClass->deleteOneAttachment($mailId, $attachmentId)) { | |
| 107 | - acym_sendAjaxResponse(acym_translation('ACYM_ATTACHMENT_WELL_DELETED')); | |
| 108 | - } | |
| 109 | - } | |
| 110 | - | |
| 111 | - acym_sendAjaxResponse(acym_translation('ACYM_COULD_NOT_DELETE_ATTACHMENT'), [], false); | |
| 112 | - } | |
| 113 | - | |
| 114 | - public function test(): void | |
| 115 | - { | |
| 116 | - $campaignId = acym_getVar('int', 'campaignId', 0); | |
| 117 | - $specificMailId = acym_getVar('int', 'mailId', 0); | |
| 118 | - | |
| 119 | - $campaignClass = new CampaignClass(); | |
| 120 | - $campaign = $campaignClass->getOneById($campaignId); | |
| 121 | - | |
| 122 | - if (empty($campaign)) { | |
| 123 | - acym_sendAjaxResponse(acym_translation('ACYM_CAMPAIGN_NOT_FOUND'), [], false); | |
| 124 | - } | |
| 125 | - | |
| 126 | - $mailerHelper = new MailerHelper(); | |
| 127 | - $mailerHelper->autoAddUser = true; | |
| 128 | - $mailerHelper->report = false; | |
| 129 | - if (!empty($specificMailId)) { | |
| 130 | - $mailerHelper->isAbTest = $campaignClass->isAbTestMail($specificMailId); | |
| 131 | - } | |
| 132 | - | |
| 133 | - $report = []; | |
| 134 | - $success = true; | |
| 135 | - $testNote = acym_getVar('string', 'test_note', ''); | |
| 136 | - | |
| 137 | - $userClass = new UserClass(); | |
| 138 | - $mailClass = new mailClass(); | |
| 139 | - $translatedMails = []; | |
| 140 | - if (acym_isMultilingual()) { | |
| 141 | - $translatedMails = $mailClass->getTranslationsById($campaign->mail_id, true, true); | |
| 142 | - } | |
| 143 | - | |
| 144 | - $rawTestEmails = explode(',', acym_getVar('string', 'test_emails')); | |
| 145 | - $testEmails = []; | |
| 146 | - foreach ($rawTestEmails as $email) { | |
| 147 | - $email = trim($email); | |
| 148 | - if (acym_isValidEmail($email) || is_numeric($email)) { | |
| 149 | - $testEmails[] = $email; | |
| 150 | - } | |
| 151 | - } | |
| 152 | - | |
| 153 | - if (empty($testEmails)) { | |
| 154 | - acym_sendAjaxResponse(acym_translation('ACYM_NO_VALID_TEST_EMAILS'), [], false); | |
| 155 | - | |
| 156 | - return; | |
| 157 | - } | |
| 158 | - | |
| 159 | - foreach ($testEmails as $oneAddress) { | |
| 160 | - $mailId = $specificMailId; | |
| 161 | - if (empty($mailId)) { | |
| 162 | - if (acym_isMultilingual()) { | |
| 163 | - if (is_numeric($oneAddress)) { | |
| 164 | - $user = $userClass->getOneById($oneAddress); | |
| 165 | - } else { | |
| 166 | - $user = $userClass->getOneByEmail($oneAddress); | |
| 167 | - } | |
| 168 | - if (empty($user)) { | |
| 169 | - $mailId = $campaign->mail_id; | |
| 170 | - } else { | |
| 171 | - $mailId = empty($translatedMails[$user->language]) ? $campaign->mail_id : $translatedMails[$user->language]->id; | |
| 172 | - } | |
| 173 | - } else { | |
| 174 | - $mailId = $campaign->mail_id; | |
| 175 | - } | |
| 176 | - } | |
| 177 | - | |
| 178 | - $options = [ | |
| 179 | - 'isTest' => true, | |
| 180 | - 'testNote' => $testNote, | |
| 181 | - ]; | |
| 182 | - if (!$mailerHelper->sendOne($mailId, $oneAddress, $options)) { | |
| 183 | - $success = false; | |
| 184 | - } | |
| 185 | - | |
| 186 | - if (!empty($mailerHelper->reportMessage)) { | |
| 187 | - $report[] = $mailerHelper->reportMessage; | |
| 188 | - } | |
| 189 | - } | |
| 190 | - | |
| 191 | - acym_sendAjaxResponse(implode('<br/>', $report), [], $success); | |
| 192 | - } | |
| 193 | - | |
| 194 | - public function saveAjax(): void | |
| 195 | - { | |
| 196 | - $result = $this->saveEditEmail(true); | |
| 197 | - if (!empty($result)) { | |
| 198 | - acym_sendAjaxResponse('', ['result' => $result]); | |
| 199 | - } else { | |
| 200 | - acym_sendAjaxResponse(acym_translation('ACYM_ERROR_SAVING'), [], false); | |
| 201 | - } | |
| 202 | - } | |
| 203 | - | |
| 204 | - public function saveAsTmplAjax(): void | |
| 205 | - { | |
| 206 | - if (!acym_isAdmin()) { | |
| 207 | - die('Access denied'); | |
| 208 | - } | |
| 209 | - | |
| 210 | - $mailController = new MailsController(); | |
| 211 | - $mailId = $mailController->store(true); | |
| 212 | - acym_sendAjaxResponse(!empty($mailId) ? '' : acym_translation('ACYM_ERROR_SAVING'), ['result' => $mailId], !empty($mailId)); | |
| 213 | - } | |
| 214 | -} | |