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