Merge pull request #15365 from samuelsov/userdashboard
[civicrm-core.git] / CRM / Activity / Page / Tab.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2019 |
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-2019
32 */
33
34 /**
35 * Main page for viewing activities,
36 */
37 class CRM_Activity_Page_Tab extends CRM_Core_Page {
38
39 /**
40 * Browse all activities for a particular contact.
41 */
42 public function browse() {
43 $this->assign('admin', FALSE);
44 $this->assign('context', 'activity');
45
46 // also create the form element for the activity filter box
47 $controller = new CRM_Core_Controller_Simple(
48 'CRM_Activity_Form_ActivityFilter',
49 ts('Activity Filter'),
50 NULL,
51 FALSE, FALSE, TRUE
52 );
53 $controller->set('contactId', $this->_contactId);
54 $controller->setEmbedded(TRUE);
55 $controller->run();
56 $this->ajaxResponse['tabCount'] = CRM_Contact_BAO_Contact::getCountComponent('activity', $this->_contactId);
57 }
58
59 /**
60 * Edit tab.
61 *
62 * @return mixed
63 */
64 public function edit() {
65 // used for ajax tabs
66 $context = CRM_Utils_Request::retrieve('context', 'Alphanumeric', $this);
67 $this->assign('context', $context);
68
69 $this->_id = CRM_Utils_Request::retrieve('id', 'Integer', $this);
70
71 $this->_caseId = CRM_Utils_Request::retrieve('caseid', 'Integer', $this);
72
73 $activityTypeId = CRM_Utils_Request::retrieve('atype', 'Positive', $this);
74
75 // Email and Create Letter activities use a different form class
76 $emailTypeValue = CRM_Core_PseudoConstant::getKey('CRM_Activity_BAO_Activity',
77 'activity_type_id',
78 'Email'
79 );
80
81 $letterTypeValue = CRM_Core_PseudoConstant::getKey('CRM_Activity_BAO_Activity',
82 'activity_type_id',
83 'Print PDF Letter'
84 );
85
86 switch ($activityTypeId) {
87 case $emailTypeValue:
88 $wrapper = new CRM_Utils_Wrapper();
89 $arguments = ['attachUpload' => 1];
90 return $wrapper->run('CRM_Contact_Form_Task_Email', ts('Email a Contact'), $arguments);
91
92 case $letterTypeValue:
93 $wrapper = new CRM_Utils_Wrapper();
94 $arguments = ['attachUpload' => 1];
95 return $wrapper->run('CRM_Contact_Form_Task_PDF', ts('Create PDF Letter'), $arguments);
96
97 default:
98 $controller = new CRM_Core_Controller_Simple('CRM_Activity_Form_Activity',
99 ts('Contact Activities'),
100 $this->_action,
101 FALSE, FALSE, FALSE, TRUE
102 );
103 }
104
105 $controller->setEmbedded(TRUE);
106
107 $controller->set('contactId', $this->_contactId);
108 $controller->set('atype', $activityTypeId);
109 $controller->set('id', $this->_id);
110 $controller->set('pid', $this->get('pid'));
111 $controller->set('action', $this->_action);
112 $controller->set('context', $context);
113
114 $controller->process();
115 $controller->run();
116 }
117
118 /**
119 * Heart of the viewing process.
120 *
121 * The runner gets all the meta data for the contact and calls the appropriate type of page to view.
122 */
123 public function preProcess() {
124 $this->_contactId = CRM_Utils_Request::retrieve('cid', 'Positive', $this, TRUE);
125 $this->assign('contactId', $this->_contactId);
126 // FIXME: need to fix this conflict
127 $this->assign('contactID', $this->_contactId);
128
129 // check logged in url permission
130 CRM_Contact_Page_View::checkUserPermission($this);
131
132 $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'browse');
133 $this->assign('action', $this->_action);
134 $this->assign('allow_edit_inbound_emails', CRM_Activity_BAO_Activity::checkEditInboundEmailsPermissions());
135
136 // also create the form element for the activity links box
137 $controller = new CRM_Core_Controller_Simple(
138 'CRM_Activity_Form_ActivityLinks',
139 ts('Activity Links'),
140 NULL,
141 FALSE, FALSE, TRUE
142 );
143 $controller->setEmbedded(TRUE);
144 $controller->run();
145 }
146
147 public function delete() {
148 $controller = new CRM_Core_Controller_Simple(
149 'CRM_Activity_Form_Activity',
150 ts('Activity Record'),
151 $this->_action
152 );
153 $controller->set('id', $this->_id);
154 $controller->setEmbedded(TRUE);
155 $controller->process();
156 $controller->run();
157 }
158
159 /**
160 * Perform actions and display for activities.
161 */
162 public function run() {
163 $context = CRM_Utils_Request::retrieve('context', 'Alphanumeric', $this);
164 $contactId = CRM_Utils_Request::retrieve('cid', 'Positive', $this);
165 $action = CRM_Utils_Request::retrieve('action', 'String', $this);
166 $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this);
167
168 // Do check for view/edit operation.
169 if ($this->_id &&
170 in_array($action, [CRM_Core_Action::UPDATE, CRM_Core_Action::VIEW])
171 ) {
172 if (!CRM_Activity_BAO_Activity::checkPermission($this->_id, $action)) {
173 CRM_Core_Error::fatal(ts('You are not authorized to access this page.'));
174 }
175 }
176
177 if ($context == 'standalone' || (!$contactId && ($action != CRM_Core_Action::DELETE) && !$this->_id)) {
178 $this->_action = CRM_Core_Action::ADD;
179 $this->assign('action', $this->_action);
180 }
181 else {
182 // we should call contact view, preprocess only for activity in contact summary
183 $this->preProcess();
184 }
185
186 // route behaviour of contact/view/activity based on action defined
187 if ($this->_action & (CRM_Core_Action::UPDATE | CRM_Core_Action::ADD | CRM_Core_Action::VIEW)
188 ) {
189 $this->edit();
190 $activityTypeId = CRM_Utils_Request::retrieve('atype', 'Positive', $this);
191
192 // Email and Create Letter activities use a different form class
193 $emailTypeValue = CRM_Core_PseudoConstant::getKey('CRM_Activity_BAO_Activity',
194 'activity_type_id',
195 'Email'
196 );
197
198 $letterTypeValue = CRM_Core_PseudoConstant::getKey('CRM_Activity_BAO_Activity',
199 'activity_type_id',
200 'Print PDF Letter'
201 );
202
203 if (in_array($activityTypeId, [
204 $emailTypeValue,
205 $letterTypeValue,
206 ])) {
207 return;
208 }
209 }
210 elseif ($this->_action & (CRM_Core_Action::DELETE | CRM_Core_Action::DETACH)) {
211 $this->delete();
212 }
213 else {
214 $this->browse();
215 }
216
217 return parent::run();
218 }
219
220 }