Merge pull request #8790 from totten/master-php7-syntax
[civicrm-core.git] / CRM / Mailing / Page / Report.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
7e9e8871 4 | CiviCRM version 4.7 |
6a488035 5 +--------------------------------------------------------------------+
fa938177 6 | Copyright CiviCRM LLC (c) 2004-2016 |
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
fa938177 31 * @copyright CiviCRM LLC (c) 2004-2016
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
EM
50 /**
51 * @return null
52 */
00be9182 53 public function &links() {
6a488035
TO
54 return CRM_Core_DAO::$_nullObject;
55 }
56
e0ef6999
EM
57 /**
58 * @return null
59 */
00be9182 60 public function editForm() {
6a488035
TO
61 return NULL;
62 }
63
e0ef6999
EM
64 /**
65 * @return string
66 */
00be9182 67 public function editName() {
6a488035
TO
68 return 'CiviMail Report';
69 }
70
71 /**
72 * Get user context.
73 *
6c8f6e67
EM
74 * @param null $mode
75 *
a6c01b45
CW
76 * @return string
77 * user context.
6a488035 78 */
00be9182 79 public function userContext($mode = NULL) {
6a488035
TO
80 return 'civicrm/mailing/report';
81 }
82
e0ef6999
EM
83 /**
84 * @param null $mode
85 *
86 * @return string
87 */
00be9182 88 public function userContextParams($mode = NULL) {
6a488035
TO
89 return 'reset=1&mid=' . $this->_mailing_id;
90 }
91
e0ef6999
EM
92 /**
93 * @return string
94 */
00be9182 95 public function run() {
6a488035 96 $this->_mailing_id = CRM_Utils_Request::retrieve('mid', 'Positive', $this);
e81bac46 97 //CRM-15979 - check if abtest exist for mailing then redirect accordingly
98 $abtest = CRM_Mailing_BAO_MailingAB::getABTest($this->_mailing_id);
99 if (!empty($abtest) && !empty($abtest->id)) {
100 CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/a/', NULL, TRUE, '/abtest/' . $abtest->id));
101 }
6a488035
TO
102 // check that the user has permission to access mailing id
103 CRM_Mailing_BAO_Mailing::checkPermission($this->_mailing_id);
104
105 $report = CRM_Mailing_BAO_Mailing::report($this->_mailing_id);
106
25606795 107 // get contents of mailing
6a488035
TO
108 CRM_Mailing_BAO_Mailing::getMailingContent($report, $this);
109
25606795 110 // assign backurl
6a488035
TO
111 $context = CRM_Utils_Request::retrieve('context', 'String', $this);
112 $cid = CRM_Utils_Request::retrieve('cid', 'Positive', $this);
113
114 if ($context == 'activitySelector') {
115 $backUrl = CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$cid}&selectedChild=activity");
116 $backUrlTitle = ts('Back to Activities');
117 }
118 elseif ($context == 'activity') {
119 $atype = CRM_Utils_Request::retrieve('atype', 'Positive', $this);
120 $aid = CRM_Utils_Request::retrieve('aid', 'Positive', $this);
121
122 $backUrl = CRM_Utils_System::url('civicrm/activity/view',
123 "atype={$atype}&action=view&reset=1&id={$aid}&cid={$cid}&context=activity"
124 );
125 $backUrlTitle = ts('Back to Activity');
126 }
b99698e5
KJ
127 elseif ($context == 'mailing') {
128 $backUrl = CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$cid}&selectedChild=mailing");
129 $backUrlTitle = ts('Back to Mailing');
130 }
6a488035
TO
131 else {
132 $backUrl = CRM_Utils_System::url('civicrm/mailing', 'reset=1');
133 $backUrlTitle = ts('Back to CiviMail');
134 }
135 $this->assign('backUrl', $backUrl);
136 $this->assign('backUrlTitle', $backUrlTitle);
137
138 $this->assign('report', $report);
139 CRM_Utils_System::setTitle(ts('CiviMail Report: %1',
353ffa53
TO
140 array(1 => $report['mailing']['name'])
141 ));
6a488035 142
6ce3caf7 143 return CRM_Core_Page::run();
6a488035 144 }
96025800 145
6a488035 146}