3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
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 |
9 +--------------------------------------------------------------------+
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
19 * This class handle case related functions.
21 class CRM_Case_Page_Tab
extends CRM_Core_Page
{
24 * The action links that we need to display for the browse screen.
28 public static $_links = NULL;
29 public $_permission = NULL;
30 public $_contactId = NULL;
32 public function preProcess() {
33 $this->_action
= CRM_Utils_Request
::retrieve('action', 'String', $this, FALSE, 'browse');
34 $this->_contactId
= CRM_Utils_Request
::retrieve('cid', 'Positive', $this);
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']) {
45 $this->_id
= CRM_Utils_Request
::retrieve('id', 'Positive', $this);
46 $this->_context
= CRM_Utils_Request
::retrieve('context', 'Alphanumeric', $this);
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')) {
54 $userCases = CRM_Case_BAO_Case
::getCases(FALSE, ['type' => 'any']);
55 if (!array_key_exists($this->_id
, $userCases)) {
56 CRM_Core_Error
::statusBounce(ts('You are not authorized to access this page.'));
61 CRM_Contact_Page_View
::checkUserPermission($this);
65 if ($this->_action
& CRM_Core_Action
::VIEW
) {
66 CRM_Core_Error
::statusBounce(ts('Contact Id is required for view action.'));
70 $activityTypes = CRM_Case_PseudoConstant
::caseActivityType();
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']);
79 * View details of a case.
81 public function view() {
82 $controller = new CRM_Core_Controller_Simple(
83 'CRM_Case_Form_CaseView',
90 $controller->setEmbedded(TRUE);
91 $controller->set('id', $this->_id
);
92 $controller->set('cid', $this->_contactId
);
95 $this->assign('caseId', $this->_id
);
96 $output = CRM_Core_Selector_Controller
::SESSION
;
97 $selector = new CRM_Activity_Selector_Activity($this->_contactId
, $this->_permission
, FALSE, 'case');
98 $controller = new CRM_Core_Selector_Controller(
100 $this->get(CRM_Utils_Pager
::PAGE_ID
),
102 CRM_Core_Action
::VIEW
,
109 $controller->setEmbedded(TRUE);
112 $controller->moveFromSessionToTemplate();
114 $this->assign('context', 'case');
118 * Called when action is browse.
120 public function browse() {
122 $controller = new CRM_Core_Controller_Simple('CRM_Case_Form_Search', ts('Case'), CRM_Core_Action
::BROWSE
);
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();
131 if ($this->_contactId
) {
132 $displayName = CRM_Contact_BAO_Contact
::displayName($this->_contactId
);
133 $this->assign('displayName', $displayName);
134 $this->ajaxResponse
['tabCount'] = CRM_Contact_BAO_Contact
::getCountComponent('case', $this->_contactId
);
139 * called when action is update or new.
143 public function edit() {
144 $config = CRM_Core_Config
::singleton();
146 $controller = new CRM_Core_Controller_Simple(
147 'CRM_Case_Form_Case',
152 $controller->setEmbedded(TRUE);
154 return $controller->run();
158 * the main function that is called when the page loads,
159 * it decides the which action has to be taken for the page.
163 public function run() {
164 $contactID = CRM_Utils_Request
::retrieve('cid', 'Positive', CRM_Core_DAO
::$_nullArray);
165 $context = CRM_Utils_Request
::retrieve('context', 'Alphanumeric', $this);
167 if ($context == 'standalone' && !$contactID) {
168 $this->_action
= CRM_Core_Action
::ADD
;
171 // we need to call parent preprocess only when we are viewing / editing / adding participant record
175 $this->assign('action', $this->_action
);
177 self
::setContext($this);
179 if ($this->_action
& CRM_Core_Action
::VIEW
) {
182 elseif (($this->_action
& (CRM_Core_Action
::UPDATE | CRM_Core_Action
::ADD |
183 CRM_Core_Action
::DELETE | CRM_Core_Action
::RENEW
190 elseif ($this->_contactId
) {
194 return parent
::run();
201 * (reference) of action links
203 public static function &links() {
204 $config = CRM_Core_Config
::singleton();
206 if (!(self
::$_links)) {
207 $deleteExtra = ts('Are you sure you want to delete this case?');
209 CRM_Core_Action
::VIEW
=> [
210 'name' => ts('Manage'),
211 'url' => 'civicrm/contact/view/case',
212 'qs' => 'action=view&reset=1&cid=%%cid%%&id=%%id%%',
213 'class' => 'no-popup',
214 'title' => ts('Manage Case'),
216 CRM_Core_Action
::DELETE
=> [
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'),
224 return self
::$_links;
228 * @param CRM_Core_Form $form
230 public static function setContext(&$form) {
231 $context = $form->get('context');
234 $qfKey = CRM_Utils_Request
::retrieve('key', 'String', $form);
236 if (!CRM_Utils_Rule
::qfKey($qfKey)) {
242 if ($form->_contactId
) {
243 $url = CRM_Utils_System
::url('civicrm/contact/view',
244 "reset=1&force=1&cid={$form->_contactId}&selectedChild=activity"
250 $url = CRM_Utils_System
::url('civicrm/case', "reset=1");
254 $urlParams = 'force=1';
256 $urlParams .= "&qfKey=$qfKey";
259 $url = CRM_Utils_System
::url('civicrm/case/search', $urlParams);
263 case 'dashletFullscreen':
266 $url = CRM_Utils_System
::url('civicrm/dashboard', 'reset=1');
270 $action = CRM_Utils_Request
::retrieve('action', 'String', $form);
271 $urlParams = 'force=1';
272 $urlString = 'civicrm/contact/search/custom';
273 if ($action == CRM_Core_Action
::RENEW
) {
274 if ($form->_contactId
) {
275 $urlParams .= '&cid=' . $form->_contactId
;
277 $urlParams .= '&context=fulltext&action=view';
278 $urlString = 'civicrm/contact/view/case';
281 $urlParams .= "&qfKey=$qfKey";
283 $url = CRM_Utils_System
::url($urlString, $urlParams);
287 if ($form->_contactId
) {
288 $url = CRM_Utils_System
::url('civicrm/contact/view',
289 "reset=1&force=1&cid={$form->_contactId}&selectedChild=case"
296 $session = CRM_Core_Session
::singleton();
297 $session->pushUserContext($url);