Merge pull request #22380 from braders/core-483-show-customised-preferences-on-validation
[civicrm-core.git] / CRM / Mailing / Controller / Send.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
10 */
11
12 /**
13 *
14 * @package CRM
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
16 */
17 class CRM_Mailing_Controller_Send extends CRM_Core_Controller {
18
19 /**
20 * Class constructor.
21 *
22 * @param string $title
23 * @param bool|int $action
24 * @param bool $modal
25 *
26 * @throws \Exception
27 */
28 public function __construct($title = NULL, $action = CRM_Core_Action::NONE, $modal = TRUE) {
29 parent::__construct($title, $modal, NULL, FALSE, TRUE);
30
31 // New: civicrm/mailing/send?reset=1
32 // Re-use: civicrm/mailing/send?reset=1&mid=%%mid%%
33 // Continue: civicrm/mailing/send?reset=1&mid=%%mid%%&continue=true
34 $mid = CRM_Utils_Request::retrieve('mid', 'Positive');
35 $continue = CRM_Utils_Request::retrieve('continue', 'String');
36 if (!$mid) {
37 CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/a/', NULL, TRUE, '/mailing/new'));
38 }
39 if ($mid && $continue) {
40 //CRM-15979 - check if abtest exist for mailing then redirect accordingly
41 $abtest = CRM_Mailing_BAO_MailingAB::getABTest($mid);
42 if (!empty($abtest) && !empty($abtest->id)) {
43 $redirect = CRM_Utils_System::url('civicrm/a/', NULL, TRUE, '/abtest/' . $abtest->id);
44 }
45 else {
46 $redirect = CRM_Utils_System::url('civicrm/a/', NULL, TRUE, '/mailing/' . $mid);
47 }
48 CRM_Utils_System::redirect($redirect);
49 }
50 if ($mid && !$continue) {
51 $clone = civicrm_api3('Mailing', 'clone', ['id' => $mid]);
52 civicrm_api3('Mailing', 'create', [
53 'id' => $clone['id'],
54 'name' => ts('Copy of %1', [1 => $clone['values'][$clone['id']]['name']]),
55 ]);
56 CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/a/', NULL, TRUE, '/mailing/' . $clone['id']));
57 }
58 }
59
60 }