| @@ -19,14 +19,14 @@ | ||
| 19 | 19 | acym_setVar('layout', 'settings'); |
| 20 | 20 | |
| 21 | 21 | $tab = acym_getVar('string', 'step', ListsController::LIST_EDITION_TABS_GENERAL); |
| 22 | 22 | |
| 23 | + // In the front with the SEF activated, the tab is not always set | |
| 23 | 24 | if (empty($tab)) { |
| 24 | 25 | $tab = ListsController::LIST_EDITION_TABS_GENERAL; |
| 25 | 26 | } |
| 26 | 27 | |
| 27 | 28 | $data = []; |
| 28 | - $data['svg'] = acym_loaderLogo(false); | |
| 29 | 29 | $data['workflowHelper'] = new WorkflowHelper(); |
| 30 | 30 | $data['currentTab'] = $tab; |
| 31 | 31 | $data['tabs'] = [ |
| 32 | 32 | 'general' => ListsController::LIST_EDITION_TABS_GENERAL, |
| @@ -63,13 +63,16 @@ | ||
| 63 | 63 | $listInformation->frontLabel = ''; |
| 64 | 64 | $listInformation->description = ''; |
| 65 | 65 | $listInformation->active = 1; |
| 66 | 66 | $listInformation->visible = 1; |
| 67 | - $randColor = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f']; | |
| 68 | - $listInformation->color = '#'.$randColor[rand(0, 15)].$randColor[rand(0, 15)].$randColor[rand(0, 15)].$randColor[rand(0, 15)].$randColor[rand(0, 15)].$randColor[rand( | |
| 69 | - 0, | |
| 70 | - 15 | |
| 71 | - )]; | |
| 67 | + $listInformation->color = '#'.implode('', [ | |
| 68 | + ListClass::COLOR_PARTS[acym_rand(0, 15)], | |
| 69 | + ListClass::COLOR_PARTS[acym_rand(0, 15)], | |
| 70 | + ListClass::COLOR_PARTS[acym_rand(0, 15)], | |
| 71 | + ListClass::COLOR_PARTS[acym_rand(0, 15)], | |
| 72 | + ListClass::COLOR_PARTS[acym_rand(0, 15)], | |
| 73 | + ListClass::COLOR_PARTS[acym_rand(0, 15)], | |
| 74 | + ]); | |
| 72 | 75 | $listInformation->welcome_id = ''; |
| 73 | 76 | $listInformation->unsubscribe_id = ''; |
| 74 | 77 | $listInformation->access = []; |
| 75 | 78 | $listInformation->tracking = 1; |
| @@ -87,11 +90,11 @@ | ||
| 87 | 90 | return false; |
| 88 | 91 | } |
| 89 | 92 | |
| 90 | 93 | |
| 91 | - $subscribersCount = $listClass->getSubscribersCountPerStatusByListId([$listId]); | |
| 94 | + $subscribersCount = $listClass->getSubscribersCountPerStatusByListIds([$listId]); | |
| 92 | 95 | |
| 93 | - $this->breadcrumb[acym_escape($listInformation->name)] = acym_completeLink('lists&task=settings&listId='.$listId); | |
| 96 | + $this->breadcrumb[$listInformation->name] = acym_completeLink('lists&task=settings&listId='.$listId); | |
| 94 | 97 | |
| 95 | 98 | $listInformation->access = empty($listInformation->access) ? [] : explode(',', $listInformation->access); |
| 96 | 99 | |
| 97 | 100 | $currentUser = acym_currentUserId(); |
| @@ -174,25 +177,9 @@ | ||
| 174 | 177 | |
| 175 | 178 | return; |
| 176 | 179 | } |
| 177 | 180 | |
| 178 | - $entityHelper = new EntitySelectHelper(); | |
| 179 | - | |
| 180 | - $data['subscribersEntitySelect'] = acym_modal( | |
| 181 | - acym_translation('ACYM_MANAGE_SUBSCRIBERS'), | |
| 182 | - $entityHelper->entitySelect( | |
| 183 | - 'user', | |
| 184 | - ['join' => 'join_list-'.$listId], | |
| 185 | - $entityHelper->getColumnsForUser('userlist.user_id'), | |
| 186 | - ['text' => acym_translation('ACYM_CONFIRM'), 'action' => 'saveSubscribers'], | |
| 187 | - true, | |
| 188 | - '', | |
| 189 | - 'subscriber' | |
| 190 | - ), | |
| 191 | - 'acym__lists__settings__subscribers__entity__modal', | |
| 192 | - '', | |
| 193 | - 'class="cell medium-6 large-shrink button button-secondary"' | |
| 194 | - ); | |
| 181 | + $data['subscribersEntitySelect'] = $listId; | |
| 195 | 182 | } |
| 196 | 183 | |
| 197 | 184 | private function prepareListStat(array &$data, int $listId): void |
| 198 | 185 | { |
| @@ -228,13 +215,14 @@ | ||
| 228 | 215 | $listClass = new ListClass(); |
| 229 | 216 | $subEvolStat = $listClass->getYearSubEvolutionPerList($listId); |
| 230 | 217 | if (empty($subEvolStat['subscribers']) && empty($subEvolStat['unsubscribers'])) return; |
| 231 | 218 | |
| 232 | - $firstMonth = date('n') + 1; | |
| 219 | + // Init tables ordered by month number starting on month from one year ago | |
| 220 | + $firstMonth = gmdate('n') + 1; | |
| 233 | 221 | $zeroReached = false; |
| 234 | 222 | $evolSub = []; |
| 235 | 223 | $evolUnsub = []; |
| 236 | - for ($i = 0 ; $i < 12 ; $i++) { | |
| 224 | + for ($i = 0; $i < 12; $i++) { | |
| 237 | 225 | $month = ($firstMonth + $i) % 13; |
| 238 | 226 | if ($month == 0) $zeroReached = true; |
| 239 | 227 | if ($zeroReached) $month += 1; |
| 240 | 228 | $evolSub[$month] = $month.'_0'; |
| @@ -267,13 +255,16 @@ | ||
| 267 | 255 | if (empty($data['listInformation']->{$full.'_id'}) && !empty($mailId)) { |
| 268 | 256 | $data['listInformation']->{$full.'_id'} = $mailId; |
| 269 | 257 | $listInfoSave = clone $data['listInformation']; |
| 270 | 258 | unset($listInfoSave->subscribers); |
| 271 | - if (!$listClass->save($listInfoSave)) acym_enqueueMessage(acym_translation('ACYM_ERROR_SAVE_LIST'), 'error'); | |
| 259 | + $savedListId = $listClass->save($listInfoSave); | |
| 260 | + if (empty($savedListId)) { | |
| 261 | + acym_enqueueMessage(acym_translation('ACYM_ERROR_SAVE_LIST'), 'error'); | |
| 262 | + } | |
| 272 | 263 | } |
| 273 | 264 | |
| 274 | 265 | $returnLink = acym_completeLink('lists&task=settings&listId='.$data['listInformation']->id.'&edition=1&'.$short.'mailid={mailid}'); |
| 275 | - $favoriteTemplate = $this->config->get('favorite_template', 0); | |
| 266 | + $favoriteTemplate = $mailClass->getFavoriteTemplateId(); | |
| 276 | 267 | $startFrom = empty($favoriteTemplate) ? '' : '&from='.$favoriteTemplate; |
| 277 | 268 | |
| 278 | 269 | if (empty($data['listInformation']->{$full.'_id'})) { |
| 279 | 270 | $data['tmpls'][$short.'TmplUrl'] = acym_completeLink( |
| @@ -294,8 +285,10 @@ | ||
| 294 | 285 | } |
| 295 | 286 | |
| 296 | 287 | public function unsetMail(string $type): void |
| 297 | 288 | { |
| 289 | + wp_verify_nonce(acym_getVar('cmd', '_wpnonce'), 'acymnonce') || die('Invalid Token'); | |
| 290 | + | |
| 298 | 291 | $listClass = new ListClass(); |
| 299 | 292 | $id = acym_getVar('int', 'listId', 0); |
| 300 | 293 | $list = $listClass->getOneById($id); |
| 301 | 294 | |
| @@ -306,14 +299,15 @@ | ||
| 306 | 299 | return; |
| 307 | 300 | } |
| 308 | 301 | |
| 309 | 302 | if (!$listClass->hasUserAccess($id)) { |
| 310 | - die('Access denied for list '.acym_escape($id)); | |
| 303 | + die('Access denied for list '.esc_html($id)); | |
| 311 | 304 | } |
| 312 | 305 | |
| 313 | 306 | $list->$type = null; |
| 314 | 307 | |
| 315 | - if ($listClass->save($list)) { | |
| 308 | + $savedListId = $listClass->save($list); | |
| 309 | + if (!empty($savedListId)) { | |
| 316 | 310 | acym_setVar('listId', $id); |
| 317 | 311 | $this->settings(); |
| 318 | 312 | } else { |
| 319 | 313 | acym_enqueueMessage(acym_translation('ACYM_ERROR_SAVE_LIST'), 'error'); |
| @@ -337,47 +331,50 @@ | ||
| 337 | 331 | } |
| 338 | 332 | |
| 339 | 333 | public function save(bool $goToListing = true): void |
| 340 | 334 | { |
| 341 | - acym_checkToken(); | |
| 335 | + wp_verify_nonce(acym_getVar('cmd', '_wpnonce'), 'acymnonce') || die('Invalid Token'); | |
| 342 | 336 | |
| 343 | - $listClass = new ListClass(); | |
| 344 | - $formData = (object)acym_getVar('array', 'list', []); | |
| 337 | + $step = acym_getVar('string', 'step'); | |
| 338 | + if ($step === self::LIST_EDITION_TABS_GENERAL) { | |
| 339 | + $listClass = new ListClass(); | |
| 340 | + $formData = (object)acym_getVar('array', 'list', []); | |
| 345 | 341 | |
| 346 | - $listId = acym_getVar('int', 'listId', 0); | |
| 347 | - if (!empty($listId)) { | |
| 348 | - $formData->id = $listId; | |
| 349 | - } | |
| 342 | + $listId = acym_getVar('int', 'listId', 0); | |
| 343 | + if (!empty($listId)) { | |
| 344 | + $formData->id = $listId; | |
| 345 | + } | |
| 350 | 346 | |
| 351 | - $allowedFields = acym_getColumns('list'); | |
| 352 | - $listInformation = new \stdClass(); | |
| 353 | - if (empty($formData->welcome_id)) unset($formData->welcome_id); | |
| 354 | - if (empty($formData->unsubscribe_id)) unset($formData->unsubscribe_id); | |
| 355 | - foreach ($formData as $name => $data) { | |
| 356 | - if (!in_array($name, $allowedFields)) { | |
| 357 | - continue; | |
| 347 | + $allowedFields = acym_getColumns('list'); | |
| 348 | + $listInformation = new \stdClass(); | |
| 349 | + if (empty($formData->welcome_id)) unset($formData->welcome_id); | |
| 350 | + if (empty($formData->unsubscribe_id)) unset($formData->unsubscribe_id); | |
| 351 | + foreach ($formData as $name => $data) { | |
| 352 | + if (!in_array($name, $allowedFields)) { | |
| 353 | + continue; | |
| 354 | + } | |
| 355 | + $listInformation->{$name} = $data; | |
| 358 | 356 | } |
| 359 | - $listInformation->{$name} = $data; | |
| 360 | - } | |
| 361 | 357 | |
| 362 | - $listInformation->tags = acym_getVar('array', 'list_tags', []); | |
| 358 | + $listInformation->tags = acym_getVar('array', 'list_tags', []); | |
| 363 | 359 | |
| 364 | - if (acym_isAdmin()) { | |
| 365 | - $listInformation->access = empty($listInformation->access) ? '' : ','.implode(',', $listInformation->access).','; | |
| 366 | - } elseif (!empty($formData->id) && !$listClass->hasUserAccess($formData->id)) { | |
| 367 | - die('Cannot save list '.acym_escape($formData->id)); | |
| 368 | - } | |
| 360 | + if (acym_isAdmin()) { | |
| 361 | + $listInformation->access = empty($listInformation->access) ? '' : ','.implode(',', $listInformation->access).','; | |
| 362 | + } elseif (!empty($formData->id) && !$listClass->hasUserAccess($formData->id)) { | |
| 363 | + die('Cannot save list '.esc_html($formData->id)); | |
| 364 | + } | |
| 369 | 365 | |
| 370 | - $listId = $listClass->save($listInformation); | |
| 366 | + $listId = $listClass->save($listInformation); | |
| 371 | 367 | |
| 372 | - if (!empty($listId)) { | |
| 373 | - acym_setVar('listId', $listId); | |
| 374 | - acym_enqueueMessage(acym_translationSprintf('ACYM_LIST_IS_SAVED', $listInformation->name), 'success'); | |
| 375 | - $this->_saveSubscribersTolist(); | |
| 376 | - } else { | |
| 377 | - acym_enqueueMessage(acym_translation('ACYM_ERROR_SAVING'), 'error'); | |
| 378 | - if (!empty($listClass->errors)) { | |
| 379 | - acym_enqueueMessage($listClass->errors, 'error'); | |
| 368 | + if (!empty($listId)) { | |
| 369 | + acym_setVar('listId', $listId); | |
| 370 | + acym_enqueueMessage(acym_translationSprintf('ACYM_LIST_IS_SAVED', $listInformation->name), 'success'); | |
| 371 | + $this->saveSubscribersTolist(); | |
| 372 | + } else { | |
| 373 | + acym_enqueueMessage(acym_translation('ACYM_ERROR_SAVING'), 'error'); | |
| 374 | + if (!empty($listClass->errors)) { | |
| 375 | + acym_enqueueMessage($listClass->errors, 'error'); | |
| 376 | + } | |
| 380 | 377 | } |
| 381 | 378 | } |
| 382 | 379 | |
| 383 | 380 | if ($goToListing) { |
| @@ -386,12 +383,14 @@ | ||
| 386 | 383 | $this->settings(); |
| 387 | 384 | } |
| 388 | 385 | } |
| 389 | 386 | |
| 390 | - private function _saveSubscribersTolist(): bool | |
| 387 | + private function saveSubscribersTolist(): bool | |
| 391 | 388 | { |
| 392 | - $usersIds = json_decode(acym_getVar('string', 'acym__entity_select__selected', '[]')); | |
| 393 | - $usersIdsUnselected = json_decode(acym_getVar('string', 'acym__entity_select__unselected', '[]')); | |
| 389 | + $selected = acym_getVar('string', 'acym__entity_select__selected', '[]'); | |
| 390 | + $unselected = acym_getVar('string', 'acym__entity_select__unselected', '[]'); | |
| 391 | + $usersIds = json_decode(empty($selected) ? '[]' : $selected, true); | |
| 392 | + $usersIdsUnselected = json_decode(empty($unselected) ? '[]' : $unselected, true); | |
| 394 | 393 | $listId = acym_getVar('int', 'listId', 0); |
| 395 | 394 | |
| 396 | 395 | $listClass = new ListClass(); |
| 397 | 396 | if (empty($listId) || !$listClass->hasUserAccess($listId)) return false; |
| @@ -419,11 +418,11 @@ | ||
| 419 | 418 | } |
| 420 | 419 | |
| 421 | 420 | public function saveSubscribers(): void |
| 422 | 421 | { |
| 423 | - acym_checkToken(); | |
| 422 | + wp_verify_nonce(acym_getVar('cmd', '_wpnonce'), 'acymnonce') || die('Invalid Token'); | |
| 424 | 423 | |
| 425 | - $this->_saveSubscribersTolist(); | |
| 424 | + $this->saveSubscribersTolist(); | |
| 426 | 425 | $listId = acym_getVar('int', 'listId', 0); |
| 427 | 426 | acym_setVar('listId', $listId); |
| 428 | 427 | |
| 429 | 428 | $this->settings(); |