Merge pull request #22482 from eileenmcnaughton/token
[civicrm-core.git] / CRM / Mailing / Page / Report.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
18 /**
19 * Page to display / edit the header / footer of a mailing.
20 */
21 class CRM_Mailing_Page_Report extends CRM_Core_Page_Basic {
22 public $_mailing_id;
23
24 /**
25 * Get BAO Name.
26 *
27 * @return string
28 * Classname of BAO
29 */
30 public function getBAOName() {
31 return 'CRM_Mailing_BAO_Mailing';
32 }
33
34 /**
35 * An array of action links.
36 *
37 * @return null
38 */
39 public function &links() {
40 return CRM_Core_DAO::$_nullObject;
41 }
42
43 /**
44 * @return null
45 */
46 public function editForm() {
47 return NULL;
48 }
49
50 /**
51 * @return string
52 */
53 public function editName() {
54 return 'CiviMail Report';
55 }
56
57 /**
58 * Get user context.
59 *
60 * @param null $mode
61 *
62 * @return string
63 * user context.
64 */
65 public function userContext($mode = NULL) {
66 return 'civicrm/mailing/report';
67 }
68
69 /**
70 * @param null $mode
71 *
72 * @return string
73 */
74 public function userContextParams($mode = NULL) {
75 return 'reset=1&mid=' . $this->_mailing_id;
76 }
77
78 /**
79 * @return string
80 */
81 public function run() {
82 $this->_mailing_id = CRM_Utils_Request::retrieve('mid', 'Positive', $this);
83 //CRM-15979 - check if abtest exist for mailing then redirect accordingly
84 $abtest = CRM_Mailing_BAO_MailingAB::getABTest($this->_mailing_id);
85 if (!empty($abtest) && !empty($abtest->id)) {
86 CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/a/', NULL, TRUE, '/abtest/' . $abtest->id));
87 }
88 // check that the user has permission to access mailing id
89 CRM_Mailing_BAO_Mailing::checkPermission($this->_mailing_id);
90
91 $report = CRM_Mailing_BAO_Mailing::report($this->_mailing_id);
92
93 // get contents of mailing
94 CRM_Mailing_BAO_Mailing::getMailingContent($report, $this);
95
96 // assign backurl
97 $context = CRM_Utils_Request::retrieve('context', 'Alphanumeric', $this);
98 $cid = CRM_Utils_Request::retrieve('cid', 'Positive', $this);
99
100 if ($context == 'activitySelector') {
101 $backUrl = CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$cid}&selectedChild=activity");
102 $backUrlTitle = ts('Back to Activities');
103 }
104 elseif ($context == 'activity') {
105 $atype = CRM_Utils_Request::retrieve('atype', 'Positive', $this);
106 $aid = CRM_Utils_Request::retrieve('aid', 'Positive', $this);
107
108 $backUrl = CRM_Utils_System::url('civicrm/activity/view',
109 "atype={$atype}&action=view&reset=1&id={$aid}&cid={$cid}&context=activity"
110 );
111 $backUrlTitle = ts('Back to Activity');
112 }
113 elseif ($context == 'mailing') {
114 $backUrl = CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$cid}&selectedChild=mailing");
115 $backUrlTitle = ts('Back to Mailing');
116 }
117 else {
118 $backUrl = CRM_Utils_System::url('civicrm/mailing', 'reset=1');
119 $backUrlTitle = ts('Back to CiviMail');
120 }
121 $this->assign('backUrl', $backUrl);
122 $this->assign('backUrlTitle', $backUrlTitle);
123
124 $this->assign('report', $report);
125 CRM_Utils_System::setTitle(ts('CiviMail Report: %1',
126 [1 => $report['mailing']['name']]
127 ));
128 $this->assign('public_url', CRM_Mailing_BAO_Mailing::getPublicViewUrl($this->_mailing_id));
129
130 return CRM_Core_Page::run();
131 }
132
133 }