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