Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
39de6fd5 | 4 | | CiviCRM version 4.6 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
06b69b18 | 6 | | Copyright CiviCRM LLC (c) 2004-2014 | |
6a488035 TO |
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 | |
06b69b18 | 31 | * @copyright CiviCRM LLC (c) 2004-2014 |
6a488035 TO |
32 | * $Id$ |
33 | * | |
34 | */ | |
35 | ||
36 | /** | |
37 | * This class handle case related functions | |
38 | * | |
39 | */ | |
40 | class CRM_Case_Page_Tab extends CRM_Core_Page { | |
41 | ||
42 | /** | |
43 | * The action links that we need to display for the browse screen | |
44 | * | |
45 | * @var array | |
6a488035 TO |
46 | */ |
47 | static $_links = NULL; | |
48 | public $_permission = NULL; | |
430ae6dd TO |
49 | public $_contactId = NULL; |
50 | ||
00be9182 | 51 | public function preProcess() { |
6a488035 TO |
52 | $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'browse'); |
53 | $this->_contactId = CRM_Utils_Request::retrieve('cid', 'Positive', $this); | |
54 | ||
55 | //validate case configuration. | |
56 | $configured = CRM_Case_BAO_Case::isCaseConfigured($this->_contactId); | |
57 | $this->assign('notConfigured', !$configured['configured']); | |
58 | $this->assign('allowToAddNewCase', $configured['allowToAddNewCase']); | |
59 | $this->assign('redirectToCaseAdmin', $configured['redirectToCaseAdmin']); | |
60 | if (!$configured['configured'] || $configured['redirectToCaseAdmin']) { | |
61 | return; | |
62 | } | |
63 | ||
64 | $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this); | |
65 | $this->_context = CRM_Utils_Request::retrieve('context', 'String', $this); | |
66 | ||
67 | if ($this->_contactId) { | |
68 | $this->assign('contactId', $this->_contactId); | |
69 | // check logged in user permission | |
70 | if ($this->_id && ($this->_action & CRM_Core_Action::VIEW)) { | |
71 | //user might have special permissions to view this case, CRM-5666 | |
72 | if (!CRM_Core_Permission::check('access all cases and activities')) { | |
73 | $session = CRM_Core_Session::singleton(); | |
90319720 | 74 | $userCases = CRM_Case_BAO_Case::getCases(FALSE, $session->get('userID'), 'any'); |
6a488035 TO |
75 | if (!array_key_exists($this->_id, $userCases)) { |
76 | CRM_Core_Error::fatal(ts('You are not authorized to access this page.')); | |
77 | } | |
78 | } | |
79 | } | |
80 | else { | |
81 | CRM_Contact_Page_View::checkUserPermission($this); | |
82 | } | |
6a488035 TO |
83 | } |
84 | else { | |
85 | if ($this->_action & CRM_Core_Action::VIEW) { | |
86 | CRM_Core_Error::fatal('Contact Id is required for view action.'); | |
87 | } | |
88 | } | |
89 | ||
90 | $activityTypes = CRM_Case_PseudoConstant::caseActivityType(); | |
91 | ||
92 | $this->assign('openCaseId', $activityTypes['Open Case']['id']); | |
93 | $this->assign('changeCaseTypeId', $activityTypes['Change Case Type']['id']); | |
94 | $this->assign('changeCaseStatusId', $activityTypes['Change Case Status']['id']); | |
95 | $this->assign('changeCaseStartDateId', $activityTypes['Change Case Start Date']['id']); | |
96 | } | |
97 | ||
98 | /** | |
99 | * View details of a case | |
100 | * | |
101 | * @return void | |
6a488035 | 102 | */ |
00be9182 | 103 | public function view() { |
6a488035 TO |
104 | $controller = new CRM_Core_Controller_Simple( |
105 | 'CRM_Case_Form_CaseView', | |
106 | 'View Case', | |
107 | $this->_action, | |
108 | FALSE, | |
109 | FALSE, | |
110 | TRUE | |
111 | ); | |
112 | $controller->setEmbedded(TRUE); | |
113 | $controller->set('id', $this->_id); | |
114 | $controller->set('cid', $this->_contactId); | |
115 | $controller->run(); | |
116 | ||
117 | $this->assign('caseId', $this->_id); | |
353ffa53 TO |
118 | $output = CRM_Core_Selector_Controller::SESSION; |
119 | $selector = new CRM_Activity_Selector_Activity($this->_contactId, $this->_permission, FALSE, 'case'); | |
28a04ea9 | 120 | $controller = new CRM_Core_Selector_Controller( |
6a488035 TO |
121 | $selector, |
122 | $this->get(CRM_Utils_Pager::PAGE_ID), | |
123 | NULL, | |
124 | CRM_Core_Action::VIEW, | |
125 | $this, | |
126 | $output, | |
127 | NULL, | |
128 | $this->_id | |
129 | ); | |
130 | ||
6a488035 TO |
131 | $controller->setEmbedded(TRUE); |
132 | ||
133 | $controller->run(); | |
134 | $controller->moveFromSessionToTemplate(); | |
135 | ||
136 | $this->assign('context', 'case'); | |
137 | } | |
138 | ||
139 | /** | |
dc195289 | 140 | * called when action is browse |
6a488035 | 141 | * |
28a04ea9 | 142 | * @return void |
6a488035 | 143 | */ |
00be9182 | 144 | public function browse() { |
6a488035 TO |
145 | |
146 | $controller = new CRM_Core_Controller_Simple('CRM_Case_Form_Search', ts('Case'), NULL); | |
147 | $controller->setEmbedded(TRUE); | |
148 | $controller->reset(); | |
149 | $controller->set('limit', 20); | |
150 | $controller->set('force', 1); | |
151 | $controller->set('context', 'case'); | |
152 | $controller->process(); | |
153 | $controller->run(); | |
154 | ||
155 | if ($this->_contactId) { | |
156 | $displayName = CRM_Contact_BAO_Contact::displayName($this->_contactId); | |
157 | $this->assign('displayName', $displayName); | |
4e8065a9 | 158 | $this->ajaxResponse['tabCount'] = CRM_Contact_BAO_Contact::getCountComponent('case', $this->_contactId); |
6a488035 TO |
159 | } |
160 | } | |
161 | ||
162 | /** | |
dc195289 | 163 | * called when action is update or new |
6a488035 | 164 | * |
76e7a76c | 165 | * @return null |
6a488035 | 166 | */ |
00be9182 | 167 | public function edit() { |
6a488035 TO |
168 | $config = CRM_Core_Config::singleton(); |
169 | ||
170 | $controller = new CRM_Core_Controller_Simple( | |
171 | 'CRM_Case_Form_Case', | |
172 | 'Open Case', | |
173 | $this->_action | |
174 | ); | |
175 | ||
176 | $controller->setEmbedded(TRUE); | |
177 | ||
178 | return $controller->run(); | |
179 | } | |
180 | ||
181 | /** | |
dc195289 | 182 | * the main function that is called when the page loads, |
6a488035 TO |
183 | * it decides the which action has to be taken for the page. |
184 | * | |
76e7a76c | 185 | * @return null |
6a488035 | 186 | */ |
00be9182 | 187 | public function run() { |
6a488035 TO |
188 | $contactID = CRM_Utils_Request::retrieve('cid', 'Positive', CRM_Core_DAO::$_nullArray); |
189 | $context = CRM_Utils_Request::retrieve('context', 'String', $this); | |
190 | ||
191 | if ($context == 'standalone' && !$contactID) { | |
192 | $this->_action = CRM_Core_Action::ADD; | |
193 | } | |
194 | else { | |
195 | // we need to call parent preprocess only when we are viewing / editing / adding participant record | |
196 | $this->preProcess(); | |
197 | } | |
198 | ||
199 | $this->assign('action', $this->_action); | |
200 | ||
201 | $this->setContext(); | |
202 | ||
203 | if ($this->_action & CRM_Core_Action::VIEW) { | |
204 | $this->view(); | |
205 | } | |
e547f744 | 206 | elseif (($this->_action & (CRM_Core_Action::UPDATE | CRM_Core_Action::ADD | |
6a488035 TO |
207 | CRM_Core_Action::DELETE | CRM_Core_Action::RENEW |
208 | ) | |
209 | ) || | |
210 | !empty($_POST) | |
211 | ) { | |
212 | $this->edit(); | |
213 | } | |
214 | elseif ($this->_contactId) { | |
215 | $this->browse(); | |
216 | } | |
217 | ||
218 | return parent::run(); | |
219 | } | |
220 | ||
221 | /** | |
222 | * Get action links | |
223 | * | |
a6c01b45 CW |
224 | * @return array |
225 | * (reference) of action links | |
6a488035 | 226 | */ |
28a04ea9 | 227 | static public function &links() { |
6a488035 TO |
228 | $config = CRM_Core_Config::singleton(); |
229 | ||
230 | if (!(self::$_links)) { | |
231 | $deleteExtra = ts('Are you sure you want to delete this case?'); | |
232 | self::$_links = array( | |
233 | CRM_Core_Action::VIEW => array( | |
234 | 'name' => ts('Manage'), | |
235 | 'url' => 'civicrm/contact/view/case', | |
236 | 'qs' => 'action=view&reset=1&cid=%%cid%%&id=%%id%%', | |
47f03411 | 237 | 'class' => 'no-popup', |
6a488035 TO |
238 | 'title' => ts('Manage Case'), |
239 | ), | |
240 | CRM_Core_Action::DELETE => array( | |
241 | 'name' => ts('Delete'), | |
242 | 'url' => 'civicrm/contact/view/case', | |
243 | 'qs' => 'action=delete&reset=1&cid=%%cid%%&id=%%id%%', | |
244 | 'title' => ts('Delete Case'), | |
245 | ), | |
246 | ); | |
247 | } | |
248 | return self::$_links; | |
249 | } | |
250 | ||
00be9182 | 251 | public function setContext() { |
6a488035 TO |
252 | $context = $this->get('context'); |
253 | $url = NULL; | |
254 | ||
255 | $qfKey = CRM_Utils_Request::retrieve('key', 'String', $this); | |
256 | //validate the qfKey | |
257 | if (!CRM_Utils_Rule::qfKey($qfKey)) { | |
258 | $qfKey = NULL; | |
259 | } | |
260 | ||
261 | switch ($context) { | |
262 | case 'activity': | |
263 | if ($this->_contactId) { | |
264 | $url = CRM_Utils_System::url('civicrm/contact/view', | |
265 | "reset=1&force=1&cid={$this->_contactId}&selectedChild=activity" | |
266 | ); | |
267 | } | |
268 | break; | |
269 | ||
270 | case 'dashboard': | |
271 | $url = CRM_Utils_System::url('civicrm/case', "reset=1"); | |
272 | break; | |
273 | ||
274 | case 'search': | |
275 | $urlParams = 'force=1'; | |
276 | if ($qfKey) { | |
277 | $urlParams .= "&qfKey=$qfKey"; | |
278 | } | |
279 | ||
280 | $url = CRM_Utils_System::url('civicrm/case/search', $urlParams); | |
281 | break; | |
282 | ||
283 | case 'dashlet': | |
284 | case 'dashletFullscreen': | |
285 | case 'home': | |
286 | case 'standalone': | |
287 | $url = CRM_Utils_System::url('civicrm/dashboard', 'reset=1'); | |
288 | break; | |
289 | ||
290 | case 'fulltext': | |
353ffa53 | 291 | $action = CRM_Utils_Request::retrieve('action', 'String', $this); |
6a488035 TO |
292 | $urlParams = 'force=1'; |
293 | $urlString = 'civicrm/contact/search/custom'; | |
294 | if ($action == CRM_Core_Action::RENEW) { | |
295 | if ($this->_contactId) { | |
296 | $urlParams .= '&cid=' . $this->_contactId; | |
297 | } | |
298 | $urlParams .= '&context=fulltext&action=view'; | |
299 | $urlString = 'civicrm/contact/view/case'; | |
300 | } | |
301 | if ($qfKey) { | |
302 | $urlParams .= "&qfKey=$qfKey"; | |
303 | } | |
304 | $url = CRM_Utils_System::url($urlString, $urlParams); | |
305 | break; | |
306 | ||
307 | default: | |
308 | if ($this->_contactId) { | |
309 | $url = CRM_Utils_System::url('civicrm/contact/view', | |
310 | "reset=1&force=1&cid={$this->_contactId}&selectedChild=case" | |
311 | ); | |
312 | } | |
313 | break; | |
314 | } | |
315 | ||
316 | if ($url) { | |
317 | $session = CRM_Core_Session::singleton(); | |
318 | $session->pushUserContext($url); | |
319 | } | |
320 | } | |
321 | } |