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