3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2017 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2017
35 * This class handle case related functions.
37 class CRM_Case_Page_Tab
extends CRM_Core_Page
{
40 * The action links that we need to display for the browse screen.
44 static $_links = NULL;
45 public $_permission = NULL;
46 public $_contactId = NULL;
48 public function preProcess() {
49 $this->_action
= CRM_Utils_Request
::retrieve('action', 'String', $this, FALSE, 'browse');
50 $this->_contactId
= CRM_Utils_Request
::retrieve('cid', 'Positive', $this);
52 //validate case configuration.
53 $configured = CRM_Case_BAO_Case
::isCaseConfigured($this->_contactId
);
54 $this->assign('notConfigured', !$configured['configured']);
55 $this->assign('allowToAddNewCase', $configured['allowToAddNewCase']);
56 $this->assign('redirectToCaseAdmin', $configured['redirectToCaseAdmin']);
57 if (!$configured['configured'] ||
$configured['redirectToCaseAdmin']) {
61 $this->_id
= CRM_Utils_Request
::retrieve('id', 'Positive', $this);
62 $this->_context
= CRM_Utils_Request
::retrieve('context', 'String', $this);
64 if ($this->_contactId
) {
65 $this->assign('contactId', $this->_contactId
);
66 // check logged in user permission
67 if ($this->_id
&& ($this->_action
& CRM_Core_Action
::VIEW
)) {
68 //user might have special permissions to view this case, CRM-5666
69 if (!CRM_Core_Permission
::check('access all cases and activities')) {
70 $session = CRM_Core_Session
::singleton();
71 $userCases = CRM_Case_BAO_Case
::getCases(FALSE, $session->get('userID'), 'any');
72 if (!array_key_exists($this->_id
, $userCases)) {
73 CRM_Core_Error
::fatal(ts('You are not authorized to access this page.'));
78 CRM_Contact_Page_View
::checkUserPermission($this);
82 if ($this->_action
& CRM_Core_Action
::VIEW
) {
83 CRM_Core_Error
::fatal('Contact Id is required for view action.');
87 $activityTypes = CRM_Case_PseudoConstant
::caseActivityType();
89 $this->assign('openCaseId', $activityTypes['Open Case']['id']);
90 $this->assign('changeCaseTypeId', $activityTypes['Change Case Type']['id']);
91 $this->assign('changeCaseStatusId', $activityTypes['Change Case Status']['id']);
92 $this->assign('changeCaseStartDateId', $activityTypes['Change Case Start Date']['id']);
96 * View details of a case.
98 public function view() {
99 $controller = new CRM_Core_Controller_Simple(
100 'CRM_Case_Form_CaseView',
107 $controller->setEmbedded(TRUE);
108 $controller->set('id', $this->_id
);
109 $controller->set('cid', $this->_contactId
);
112 $this->assign('caseId', $this->_id
);
113 $output = CRM_Core_Selector_Controller
::SESSION
;
114 $selector = new CRM_Activity_Selector_Activity($this->_contactId
, $this->_permission
, FALSE, 'case');
115 $controller = new CRM_Core_Selector_Controller(
117 $this->get(CRM_Utils_Pager
::PAGE_ID
),
119 CRM_Core_Action
::VIEW
,
126 $controller->setEmbedded(TRUE);
129 $controller->moveFromSessionToTemplate();
131 $this->assign('context', 'case');
135 * Called when action is browse.
137 public function browse() {
139 $controller = new CRM_Core_Controller_Simple('CRM_Case_Form_Search', ts('Case'), CRM_Core_Action
::BROWSE
);
140 $controller->setEmbedded(TRUE);
141 $controller->reset();
142 $controller->set('limit', 20);
143 $controller->set('force', 1);
144 $controller->set('context', 'case');
145 $controller->process();
148 if ($this->_contactId
) {
149 $displayName = CRM_Contact_BAO_Contact
::displayName($this->_contactId
);
150 $this->assign('displayName', $displayName);
151 $this->ajaxResponse
['tabCount'] = CRM_Contact_BAO_Contact
::getCountComponent('case', $this->_contactId
);
156 * called when action is update or new.
160 public function edit() {
161 $config = CRM_Core_Config
::singleton();
163 $controller = new CRM_Core_Controller_Simple(
164 'CRM_Case_Form_Case',
169 $controller->setEmbedded(TRUE);
171 return $controller->run();
175 * the main function that is called when the page loads,
176 * it decides the which action has to be taken for the page.
180 public function run() {
181 $contactID = CRM_Utils_Request
::retrieve('cid', 'Positive', CRM_Core_DAO
::$_nullArray);
182 $context = CRM_Utils_Request
::retrieve('context', 'String', $this);
184 if ($context == 'standalone' && !$contactID) {
185 $this->_action
= CRM_Core_Action
::ADD
;
188 // we need to call parent preprocess only when we are viewing / editing / adding participant record
192 $this->assign('action', $this->_action
);
194 self
::setContext($this);
196 if ($this->_action
& CRM_Core_Action
::VIEW
) {
199 elseif (($this->_action
& (CRM_Core_Action
::UPDATE | CRM_Core_Action
::ADD |
200 CRM_Core_Action
::DELETE | CRM_Core_Action
::RENEW
207 elseif ($this->_contactId
) {
211 return parent
::run();
218 * (reference) of action links
220 static public function &links() {
221 $config = CRM_Core_Config
::singleton();
223 if (!(self
::$_links)) {
224 $deleteExtra = ts('Are you sure you want to delete this case?');
225 self
::$_links = array(
226 CRM_Core_Action
::VIEW
=> array(
227 'name' => ts('Manage'),
228 'url' => 'civicrm/contact/view/case',
229 'qs' => 'action=view&reset=1&cid=%%cid%%&id=%%id%%',
230 'class' => 'no-popup',
231 'title' => ts('Manage Case'),
233 CRM_Core_Action
::DELETE
=> array(
234 'name' => ts('Delete'),
235 'url' => 'civicrm/contact/view/case',
236 'qs' => 'action=delete&reset=1&cid=%%cid%%&id=%%id%%',
237 'title' => ts('Delete Case'),
241 return self
::$_links;
245 * @param CRM_Core_Form $form
247 public static function setContext(&$form) {
248 $context = $form->get('context');
251 $qfKey = CRM_Utils_Request
::retrieve('key', 'String', $form);
253 if (!CRM_Utils_Rule
::qfKey($qfKey)) {
259 if ($form->_contactId
) {
260 $url = CRM_Utils_System
::url('civicrm/contact/view',
261 "reset=1&force=1&cid={$form->_contactId}&selectedChild=activity"
267 $url = CRM_Utils_System
::url('civicrm/case', "reset=1");
271 $urlParams = 'force=1';
273 $urlParams .= "&qfKey=$qfKey";
276 $url = CRM_Utils_System
::url('civicrm/case/search', $urlParams);
280 case 'dashletFullscreen':
283 $url = CRM_Utils_System
::url('civicrm/dashboard', 'reset=1');
287 $action = CRM_Utils_Request
::retrieve('action', 'String', $form);
288 $urlParams = 'force=1';
289 $urlString = 'civicrm/contact/search/custom';
290 if ($action == CRM_Core_Action
::RENEW
) {
291 if ($form->_contactId
) {
292 $urlParams .= '&cid=' . $form->_contactId
;
294 $urlParams .= '&context=fulltext&action=view';
295 $urlString = 'civicrm/contact/view/case';
298 $urlParams .= "&qfKey=$qfKey";
300 $url = CRM_Utils_System
::url($urlString, $urlParams);
304 if ($form->_contactId
) {
305 $url = CRM_Utils_System
::url('civicrm/contact/view',
306 "reset=1&force=1&cid={$form->_contactId}&selectedChild=case"
313 $session = CRM_Core_Session
::singleton();
314 $session->pushUserContext($url);