Merge pull request #13337 from GinkgoFJG/crmPageTitle
[civicrm-core.git] / CRM / Mailing / Page / Report.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
fee14197 4 | CiviCRM version 5 |
6a488035 5 +--------------------------------------------------------------------+
6b83d5bd 6 | Copyright CiviCRM LLC (c) 2004-2019 |
6a488035
TO
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
13 | |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
18 | |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
d25dd0ee 26 */
6a488035
TO
27
28/**
29 *
30 * @package CRM
6b83d5bd 31 * @copyright CiviCRM LLC (c) 2004-2019
6a488035
TO
32 */
33
34/**
25606795 35 * Page to display / edit the header / footer of a mailing.
6a488035
TO
36 */
37class CRM_Mailing_Page_Report extends CRM_Core_Page_Basic {
38 public $_mailing_id;
39
40 /**
fe482240 41 * Get BAO Name.
6a488035 42 *
a6c01b45
CW
43 * @return string
44 * Classname of BAO
6a488035 45 */
00be9182 46 public function getBAOName() {
6a488035
TO
47 return 'CRM_Mailing_BAO_Mailing';
48 }
49
e0ef6999 50 /**
7535623a 51 * An array of action links.
52 *
e0ef6999
EM
53 * @return null
54 */
00be9182 55 public function &links() {
6a488035
TO
56 return CRM_Core_DAO::$_nullObject;
57 }
58
e0ef6999
EM
59 /**
60 * @return null
61 */
00be9182 62 public function editForm() {
6a488035
TO
63 return NULL;
64 }
65
e0ef6999
EM
66 /**
67 * @return string
68 */
00be9182 69 public function editName() {
6a488035
TO
70 return 'CiviMail Report';
71 }
72
73 /**
74 * Get user context.
75 *
6c8f6e67
EM
76 * @param null $mode
77 *
a6c01b45
CW
78 * @return string
79 * user context.
6a488035 80 */
00be9182 81 public function userContext($mode = NULL) {
6a488035
TO
82 return 'civicrm/mailing/report';
83 }
84
e0ef6999
EM
85 /**
86 * @param null $mode
87 *
88 * @return string
89 */
00be9182 90 public function userContextParams($mode = NULL) {
6a488035
TO
91 return 'reset=1&mid=' . $this->_mailing_id;
92 }
93
e0ef6999
EM
94 /**
95 * @return string
96 */
00be9182 97 public function run() {
6a488035 98 $this->_mailing_id = CRM_Utils_Request::retrieve('mid', 'Positive', $this);
e81bac46 99 //CRM-15979 - check if abtest exist for mailing then redirect accordingly
100 $abtest = CRM_Mailing_BAO_MailingAB::getABTest($this->_mailing_id);
101 if (!empty($abtest) && !empty($abtest->id)) {
102 CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/a/', NULL, TRUE, '/abtest/' . $abtest->id));
103 }
6a488035
TO
104 // check that the user has permission to access mailing id
105 CRM_Mailing_BAO_Mailing::checkPermission($this->_mailing_id);
106
107 $report = CRM_Mailing_BAO_Mailing::report($this->_mailing_id);
108
25606795 109 // get contents of mailing
6a488035
TO
110 CRM_Mailing_BAO_Mailing::getMailingContent($report, $this);
111
25606795 112 // assign backurl
edc80cda 113 $context = CRM_Utils_Request::retrieve('context', 'Alphanumeric', $this);
6a488035
TO
114 $cid = CRM_Utils_Request::retrieve('cid', 'Positive', $this);
115
116 if ($context == 'activitySelector') {
117 $backUrl = CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$cid}&selectedChild=activity");
118 $backUrlTitle = ts('Back to Activities');
119 }
120 elseif ($context == 'activity') {
121 $atype = CRM_Utils_Request::retrieve('atype', 'Positive', $this);
122 $aid = CRM_Utils_Request::retrieve('aid', 'Positive', $this);
123
124 $backUrl = CRM_Utils_System::url('civicrm/activity/view',
125 "atype={$atype}&action=view&reset=1&id={$aid}&cid={$cid}&context=activity"
126 );
127 $backUrlTitle = ts('Back to Activity');
128 }
b99698e5
KJ
129 elseif ($context == 'mailing') {
130 $backUrl = CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$cid}&selectedChild=mailing");
131 $backUrlTitle = ts('Back to Mailing');
132 }
6a488035
TO
133 else {
134 $backUrl = CRM_Utils_System::url('civicrm/mailing', 'reset=1');
135 $backUrlTitle = ts('Back to CiviMail');
136 }
137 $this->assign('backUrl', $backUrl);
138 $this->assign('backUrlTitle', $backUrlTitle);
139
140 $this->assign('report', $report);
141 CRM_Utils_System::setTitle(ts('CiviMail Report: %1',
353ffa53
TO
142 array(1 => $report['mailing']['name'])
143 ));
7535623a 144 $this->assign('public_url', CRM_Mailing_BAO_Mailing::getPublicViewUrl($this->_mailing_id));
6a488035 145
6ce3caf7 146 return CRM_Core_Page::run();
6a488035 147 }
96025800 148
6a488035 149}