Merge pull request #4896 from totten/master-movedep
[civicrm-core.git] / CRM / Mailing / Page / Report.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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 +--------------------------------------------------------------------+
26 */
27
28 /**
29 *
30 * @package CRM
31 * @copyright CiviCRM LLC (c) 2004-2014
32 * $Id$
33 *
34 */
35
36 /**
37 * Page to display / edit the header / footer of a mailing
38 *
39 */
40 class CRM_Mailing_Page_Report extends CRM_Core_Page_Basic {
41 public $_mailing_id;
42
43 /**
44 * Get BAO Name
45 *
46 * @return string
47 * Classname of BAO
48 */
49 public function getBAOName() {
50 return 'CRM_Mailing_BAO_Mailing';
51 }
52
53 /**
54 * @return null
55 */
56 public function &links() {
57 return CRM_Core_DAO::$_nullObject;
58 }
59
60 /**
61 * @return null
62 */
63 public function editForm() {
64 return NULL;
65 }
66
67 /**
68 * @return string
69 */
70 public function editName() {
71 return 'CiviMail Report';
72 }
73
74 /**
75 * Get user context.
76 *
77 * @param null $mode
78 *
79 * @return string
80 * user context.
81 */
82 public function userContext($mode = NULL) {
83 return 'civicrm/mailing/report';
84 }
85
86 /**
87 * @param null $mode
88 *
89 * @return string
90 */
91 public function userContextParams($mode = NULL) {
92 return 'reset=1&mid=' . $this->_mailing_id;
93 }
94
95 /**
96 * @return string
97 */
98 public function run() {
99 $this->_mailing_id = CRM_Utils_Request::retrieve('mid', 'Positive', $this);
100
101 // check that the user has permission to access mailing id
102 CRM_Mailing_BAO_Mailing::checkPermission($this->_mailing_id);
103
104 $report = CRM_Mailing_BAO_Mailing::report($this->_mailing_id);
105
106 //get contents of mailing
107 CRM_Mailing_BAO_Mailing::getMailingContent($report, $this);
108
109 //assign backurl
110 $context = CRM_Utils_Request::retrieve('context', 'String', $this);
111 $cid = CRM_Utils_Request::retrieve('cid', 'Positive', $this);
112
113 if ($context == 'activitySelector') {
114 $backUrl = CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$cid}&selectedChild=activity");
115 $backUrlTitle = ts('Back to Activities');
116 }
117 elseif ($context == 'activity') {
118 $atype = CRM_Utils_Request::retrieve('atype', 'Positive', $this);
119 $aid = CRM_Utils_Request::retrieve('aid', 'Positive', $this);
120
121 $backUrl = CRM_Utils_System::url('civicrm/activity/view',
122 "atype={$atype}&action=view&reset=1&id={$aid}&cid={$cid}&context=activity"
123 );
124 $backUrlTitle = ts('Back to Activity');
125 }
126 elseif ($context == 'mailing') {
127 $backUrl = CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$cid}&selectedChild=mailing");
128 $backUrlTitle = ts('Back to Mailing');
129 }
130 else {
131 $backUrl = CRM_Utils_System::url('civicrm/mailing', 'reset=1');
132 $backUrlTitle = ts('Back to CiviMail');
133 }
134 $this->assign('backUrl', $backUrl);
135 $this->assign('backUrlTitle', $backUrlTitle);
136
137 $this->assign('report', $report);
138 CRM_Utils_System::setTitle(ts('CiviMail Report: %1',
139 array(1 => $report['mailing']['name'])
140 ));
141
142 return CRM_Core_Page::run();
143 }
144 }