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