← All changes
|
back/dynamics/subscriber/SubscriberAutomationActions.php
+69
-98
10.1.4
→
11.1.0
View file →
| @@ -6,8 +6,11 @@ | ||
| 6 | 6 | use AcyMailing\Helpers\MailerHelper; |
| 7 | 7 | |
| 8 | 8 | trait SubscriberAutomationActions |
| 9 | 9 | { |
| 10 | + /** | |
| 11 | + * Function called with ajax to search email to remove from the queue | |
| 12 | + */ | |
| 10 | 13 | public function searchEmails() |
| 11 | 14 | { |
| 12 | 15 | $id = acym_getVar('int', 'id'); |
| 13 | 16 | if (!empty($id)) { |
| @@ -45,10 +48,32 @@ | ||
| 45 | 48 | echo json_encode($return); |
| 46 | 49 | exit; |
| 47 | 50 | } |
| 48 | 51 | |
| 49 | - public function onAcymDeclareActions(&$actions) | |
| 52 | + protected function initAutomationActions(): void | |
| 50 | 53 | { |
| 54 | + $this->automationActions = [ | |
| 55 | + 'acy_user' => acym_translation('ACYM_ACTION_ON_USERS'), | |
| 56 | + 'acy_user_value' => acym_translation('ACYM_SET_USER_VALUE'), | |
| 57 | + 'acy_add_queue' => acym_translation('ACYM_ADD_EMAIL_QUEUE'), | |
| 58 | + 'acy_send_email' => acym_translation('ACYM_SEND_EMAIL'), | |
| 59 | + 'acy_remove_queue' => acym_translation('ACYM_REMOVE_EMAIL_QUEUE'), | |
| 60 | + ]; | |
| 61 | + | |
| 62 | + if ($this->config->get('require_confirmation', '1') === '1') { | |
| 63 | + $this->automationActions['resend_confirmation'] = acym_translation('ACYM_RESEND_CONFIRMATION'); | |
| 64 | + } | |
| 65 | + } | |
| 66 | + | |
| 67 | + public function onAcymDeclareActionsScenario(array &$actions): void | |
| 68 | + { | |
| 69 | + $this->onAcymDeclareActions($actions); | |
| 70 | + | |
| 71 | + unset($actions['acy_add_queue']); | |
| 72 | + } | |
| 73 | + | |
| 74 | + public function displayActionOptions_acy_user(): void | |
| 75 | + { | |
| 51 | 76 | $userActions = [ |
| 52 | 77 | 'confirm' => acym_translation('ACYM_CONFIRM_USER'), |
| 53 | 78 | 'unconfirm' => acym_translation('ACYM_UNCONFIRM_USER'), |
| 54 | 79 | 'active' => acym_translation('ACYM_ACTIVE_USER'), |
| @@ -55,15 +80,13 @@ | ||
| 55 | 80 | 'block' => acym_translation('ACYM_BLOCK_USER'), |
| 56 | 81 | 'delete' => acym_translation('ACYM_DELETE_USER'), |
| 57 | 82 | ]; |
| 58 | 83 | |
| 59 | - $actions['acy_user'] = new stdClass(); | |
| 60 | - $actions['acy_user']->name = acym_translation('ACYM_ACTION_ON_USERS'); | |
| 61 | - | |
| 62 | - ob_start(); | |
| 63 | 84 | include acym_getPartial('actions', 'acy_user'); |
| 64 | - $actions['acy_user']->option = ob_get_clean(); | |
| 85 | + } | |
| 65 | 86 | |
| 87 | + public function displayActionOptions_acy_user_value(): void | |
| 88 | + { | |
| 66 | 89 | $userClass = new UserClass(); |
| 67 | 90 | $userFields = $userClass->getAllColumnsUserAndCustomField(true); |
| 68 | 91 | unset($userFields['id']); |
| 69 | 92 | unset($userFields['cms_id']); |
| @@ -83,88 +106,38 @@ | ||
| 83 | 106 | ]; |
| 84 | 107 | |
| 85 | 108 | $fieldClass = new FieldClass(); |
| 86 | 109 | $customFields = $fieldClass->getAllFieldsForUser(); |
| 87 | - $customFieldValues = []; | |
| 88 | - foreach ($customFields as $field) { | |
| 89 | - if (in_array($field->type, ['single_dropdown', 'radio', 'checkbox', 'multiple_dropdown']) && !empty($field->value)) { | |
| 90 | - $values = []; | |
| 91 | - $field->value = json_decode($field->value, true); | |
| 92 | - foreach ($field->value as $value) { | |
| 93 | - $valueTmp = new stdClass(); | |
| 94 | - $valueTmp->text = $value['title']; | |
| 95 | - $valueTmp->value = $value['value']; | |
| 96 | - if ($value['disabled'] == 'y') $valueTmp->disable = true; | |
| 97 | - $values[$value['value']] = $valueTmp; | |
| 98 | - } | |
| 99 | - $customFieldValues[$field->id] = '<div class="acym__automation__one-field intext_select_automation cell" style="display: none">'; | |
| 100 | - $customFieldValues[$field->id] .= acym_select( | |
| 101 | - $values, | |
| 102 | - '[actions][__and__][acy_user_value][value]', | |
| 103 | - null, | |
| 104 | - [ | |
| 105 | - 'class' => 'acym__select acym__automation__actions__fields__select', | |
| 106 | - 'data-action-field' => $field->id, | |
| 107 | - ] | |
| 108 | - ); | |
| 109 | - $customFieldValues[$field->id] .= '</div>'; | |
| 110 | - } elseif ('date' == $field->type) { | |
| 111 | - $field->option = json_decode($field->option, true); | |
| 112 | - $customFieldValues[$field->id] = acym_tooltip( | |
| 113 | - [ | |
| 114 | - 'hoveredText' => '<input class="acym__automation__one-field acym__automation__actions__fields__select intext_input_automation cell" type="text" name="[actions][__and__][acy_user_value][value]" style="display: none" data-action-field="'.$field->id.'">', | |
| 115 | - 'textShownInTooltip' => acym_translationSprintf('ACYM_DATE_AUTOMATION_INPUT', $field->option['format']), | |
| 116 | - 'classContainer' => 'intext_select_automation cell', | |
| 117 | - ] | |
| 118 | - ); | |
| 119 | - } | |
| 120 | - } | |
| 121 | 110 | |
| 122 | - $actions['acy_user_value'] = new stdClass(); | |
| 123 | - $actions['acy_user_value']->name = acym_translation('ACYM_SET_USER_VALUE'); | |
| 124 | - ob_start(); | |
| 125 | 111 | include acym_getPartial('actions', 'acy_user_value'); |
| 126 | - $actions['acy_user_value']->option = ob_get_clean(); | |
| 112 | + } | |
| 127 | 113 | |
| 128 | - $actions['acy_add_queue'] = new stdClass(); | |
| 129 | - $actions['acy_add_queue']->name = acym_translation('ACYM_ADD_EMAIL_QUEUE'); | |
| 130 | - ob_start(); | |
| 114 | + public function displayActionOptions_acy_add_queue(): void | |
| 115 | + { | |
| 131 | 116 | include acym_getPartial('actions', 'acy_add_queue'); |
| 132 | - $actions['acy_add_queue']->option = ob_get_clean(); | |
| 117 | + } | |
| 133 | 118 | |
| 134 | - $actions['acy_send_email'] = new stdClass(); | |
| 135 | - $actions['acy_send_email']->name = acym_translation('ACYM_SEND_EMAIL'); | |
| 136 | - ob_start(); | |
| 119 | + public function displayActionOptions_acy_send_email(): void | |
| 120 | + { | |
| 137 | 121 | include acym_getPartial('actions', 'acy_send_email'); |
| 138 | - $actions['acy_send_email']->option = ob_get_clean(); | |
| 122 | + } | |
| 139 | 123 | |
| 140 | - $actions['acy_remove_queue'] = new stdClass(); | |
| 141 | - $actions['acy_remove_queue']->name = acym_translation('ACYM_REMOVE_EMAIL_QUEUE'); | |
| 142 | - $ajaxParams = json_encode( | |
| 143 | - [ | |
| 144 | - 'plugin' => __CLASS__, | |
| 145 | - 'trigger' => 'searchEmails', | |
| 146 | - ] | |
| 147 | - ); | |
| 148 | - ob_start(); | |
| 124 | + public function displayActionOptions_acy_remove_queue(): void | |
| 125 | + { | |
| 126 | + $ajaxParams = [ | |
| 127 | + 'plugin' => __CLASS__, | |
| 128 | + 'trigger' => 'searchEmails', | |
| 129 | + ]; | |
| 130 | + | |
| 149 | 131 | include acym_getPartial('actions', 'acy_remove_queue'); |
| 150 | - $actions['acy_remove_queue']->option = ob_get_clean(); | |
| 151 | - | |
| 152 | - if ($this->config->get('require_confirmation', '1') === '1') { | |
| 153 | - $actions['resend_confirmation'] = new stdClass(); | |
| 154 | - $actions['resend_confirmation']->name = acym_translation('ACYM_RESEND_CONFIRMATION'); | |
| 155 | - $actions['resend_confirmation']->option = '<input type="hidden" name="acym_action[actions][__and__][resend_confirmation][save]" />'; | |
| 156 | - } | |
| 157 | 132 | } |
| 158 | 133 | |
| 159 | - public function onAcymDeclareActionsScenario(&$actions) | |
| 134 | + public function displayActionOptions_resend_confirmation(): void | |
| 160 | 135 | { |
| 161 | - $this->onAcymDeclareActions($actions); | |
| 162 | - | |
| 163 | - unset($actions['acy_add_queue']); | |
| 136 | + // The action doesn't save if there are no options | |
| 137 | + echo '<input type="hidden" name="acym_action[actions][__and__][resend_confirmation][save]" />'; | |
| 164 | 138 | } |
| 165 | 139 | |
| 166 | - | |
| 167 | 140 | public function onAcymProcessAction_acy_user(&$query, $action) |
| 168 | 141 | { |
| 169 | 142 | if ($action['action'] == 'delete') { |
| 170 | 143 | $userClass = new UserClass(); |
| @@ -171,13 +144,14 @@ | ||
| 171 | 144 | $usersToDelete = acym_loadResultArray($query->getQuery(['user.id'])); |
| 172 | 145 | if (!empty($usersToDelete)) $userClass->delete($usersToDelete, true); |
| 173 | 146 | } else { |
| 174 | 147 | $fieldToUpdate = ''; |
| 175 | - if ($action['action'] == 'confirm') $fieldToUpdate = 'confirmed = 1'; | |
| 176 | - if ($action['action'] == 'unconfirm') $fieldToUpdate = 'confirmed = 0'; | |
| 177 | - if ($action['action'] == 'active') $fieldToUpdate = 'active = 1'; | |
| 178 | - if ($action['action'] == 'block') $fieldToUpdate = 'active = 0'; | |
| 148 | + if ($action['action'] === 'confirm') $fieldToUpdate = 'confirmed = 1'; | |
| 149 | + if ($action['action'] === 'unconfirm') $fieldToUpdate = 'confirmed = 0'; | |
| 150 | + if ($action['action'] === 'active') $fieldToUpdate = 'active = 1, deactivation_date = NULL'; | |
| 151 | + if ($action['action'] === 'block') $fieldToUpdate = 'active = 0, deactivation_date = UTC_TIMESTAMP()'; | |
| 179 | 152 | |
| 153 | + | |
| 180 | 154 | $queryToProcess = 'UPDATE #__acym_user AS `user` SET '.$fieldToUpdate.' WHERE ('.implode(') AND (', $query->where).')'; |
| 181 | 155 | $nbRows = acym_query($queryToProcess); |
| 182 | 156 | |
| 183 | 157 | return acym_translationSprintf('ACYM_X_USERS_X', $nbRows, acym_translation('ACYM_ACTION_'.strtoupper($action['action']))); |
| @@ -190,44 +164,39 @@ | ||
| 190 | 164 | $value = acym_replaceDateTags($value); |
| 191 | 165 | |
| 192 | 166 | if (empty($action['operator'])) $action['operator'] = '='; |
| 193 | 167 | |
| 194 | - if (in_array($action['operator'], ['+', '-'])) { | |
| 195 | - $value = intval($value); | |
| 196 | - } else { | |
| 197 | - $value = acym_escapeDB($value); | |
| 198 | - } | |
| 199 | - | |
| 200 | 168 | $usersColumns = acym_getColumns('user'); |
| 201 | 169 | |
| 202 | 170 | if (in_array($action['field'], $usersColumns)) { |
| 203 | 171 | $execute = 'UPDATE #__acym_user AS user'; |
| 204 | 172 | |
| 205 | - $column = "user.`".acym_secureDBColumn($action['field'])."`"; | |
| 173 | + $column = 'user.`'.acym_secureDBColumn($action['field']).'`'; | |
| 206 | 174 | } else { |
| 207 | 175 | $fieldClass = new FieldClass(); |
| 208 | 176 | $field = $fieldClass->getOneById($action['field']); |
| 209 | - if (empty($field)) return 'Unknown field: '.$action['field']; | |
| 210 | - if ('date' == $field->type) $value = acym_escapeDB(json_encode(explode('/', trim($value, '"\'')))); | |
| 177 | + if (empty($field)) { | |
| 178 | + return 'Unknown field: '.$action['field']; | |
| 179 | + } | |
| 211 | 180 | |
| 212 | - $allColumn = "`user_id`, `field_id`, `value`"; | |
| 213 | - $column = "`value`"; | |
| 181 | + $allColumn = '`user_id`, `field_id`, `value`'; | |
| 182 | + $column = '`value`'; | |
| 214 | 183 | } |
| 215 | 184 | |
| 216 | - if ($action['operator'] == '=') { | |
| 217 | - $newValue = $value; | |
| 185 | + if ($action['operator'] === '=') { | |
| 186 | + $newValue = acym_escapeDB($value); | |
| 218 | 187 | } elseif (in_array($action['operator'], ['+', '-'])) { |
| 219 | - $newValue = $column.' '.$action['operator']." ".$value; | |
| 220 | - } elseif ($action['operator'] == 'add_end') { | |
| 221 | - $newValue = "CONCAT(".$column.", ".$value.")"; | |
| 222 | - } elseif ($action['operator'] == 'add_begin') { | |
| 223 | - $newValue = "CONCAT(".$value.", ".$column.")"; | |
| 188 | + $newValue = $column.' '.$action['operator'].' '.intval($value); | |
| 189 | + } elseif ($action['operator'] === 'add_end') { | |
| 190 | + $newValue = 'CONCAT('.$column.', '.acym_escapeDB($value).')'; | |
| 191 | + } elseif ($action['operator'] === 'add_begin') { | |
| 192 | + $newValue = 'CONCAT('.acym_escapeDB($value).', '.$column.')'; | |
| 224 | 193 | } else { |
| 225 | - return 'Unknown operator: '.acym_escape($action['operator']); | |
| 194 | + return 'Unknown operator: '.esc_attr($action['operator']); | |
| 226 | 195 | } |
| 227 | 196 | |
| 228 | 197 | if (in_array($action['field'], $usersColumns)) { |
| 229 | - $execute .= " SET ".$column." = ".$newValue; | |
| 198 | + $execute .= ' SET '.$column.' = '.$newValue; | |
| 230 | 199 | if (!empty($query->where)) $execute .= ' WHERE ('.implode(') AND (', $query->where).')'; |
| 231 | 200 | } else { |
| 232 | 201 | $customFieldAlreadyExists = acym_loadResult('SELECT COUNT(user_id) FROM #__acym_user_has_field WHERE field_id = '.intval($action['field'])); |
| 233 | 202 | $execute = 'INSERT INTO #__acym_user_has_field ('.$allColumn.') SELECT id AS user_id, '.intval( |
| @@ -285,8 +254,9 @@ | ||
| 285 | 254 | $sendDate = acym_replaceDate($action['time']); |
| 286 | 255 | $sendDate = acym_date($sendDate, 'Y-m-d H:i:s', false); |
| 287 | 256 | $mailClass = new MailClass(); |
| 288 | 257 | |
| 258 | + //We generate the new mail if it's a template | |
| 289 | 259 | $mail = $mailClass->getOneById($action['mail_id']); |
| 290 | 260 | |
| 291 | 261 | if (empty($mail)) return ''; |
| 292 | 262 | |
| @@ -382,12 +352,13 @@ | ||
| 382 | 352 | $mail = $mailClass->getOneById($automationAction['acy_add_queue']['mail_id']); |
| 383 | 353 | if (empty($mail)) { |
| 384 | 354 | $automationAction = '<span class="acym__color__red">'.acym_translation('ACYM_SELECT_AN_EMAIL').'</span>'; |
| 385 | 355 | } else { |
| 356 | + $queueTime = empty($automationAction['acy_add_queue']['time']) ? '[time]' : $automationAction['acy_add_queue']['time']; | |
| 386 | 357 | $automationAction = acym_translationSprintf( |
| 387 | 358 | 'ACYM_ACTION_ADD_QUEUE_SUMMARY', |
| 388 | 359 | $mail->name, |
| 389 | - acym_date(acym_replaceDate($automationAction['acy_add_queue']['time']), 'd M Y H:i') | |
| 360 | + acym_date(acym_replaceDate($queueTime), 'd M Y H:i') | |
| 390 | 361 | ); |
| 391 | 362 | } |
| 392 | 363 | } |
| 393 | 364 | |