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