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