3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.4 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
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-2013
37 * This class handle case related functions
40 class CRM_Case_Page_Tab
extends CRM_Core_Page
{
43 * The action links that we need to display for the browse screen
48 static $_links = NULL;
49 public $_permission = NULL;
50 public $_contactId = NULL;
52 function preProcess() {
53 $this->_action
= CRM_Utils_Request
::retrieve('action', 'String', $this, FALSE, 'browse');
54 $this->_contactId
= CRM_Utils_Request
::retrieve('cid', 'Positive', $this);
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']) {
65 $this->_id
= CRM_Utils_Request
::retrieve('id', 'Positive', $this);
66 $this->_context
= CRM_Utils_Request
::retrieve('context', 'String', $this);
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();
75 $userCases = CRM_Case_BAO_Case
::getCases(FALSE, $session->get('userID'));
76 if (!array_key_exists($this->_id
, $userCases)) {
77 CRM_Core_Error
::fatal(ts('You are not authorized to access this page.'));
82 CRM_Contact_Page_View
::checkUserPermission($this);
86 CRM_Contact_Page_View
::setTitle($this->_contactId
);
89 if ($this->_action
& CRM_Core_Action
::VIEW
) {
90 CRM_Core_Error
::fatal('Contact Id is required for view action.');
94 $activityTypes = CRM_Case_PseudoConstant
::caseActivityType();
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']);
103 * View details of a case
109 $controller = new CRM_Core_Controller_Simple(
110 'CRM_Case_Form_CaseView',
117 $controller->setEmbedded(TRUE);
118 $controller->set('id', $this->_id
);
119 $controller->set('cid', $this->_contactId
);
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');
126 new CRM_Core_Selector_Controller(
128 $this->get(CRM_Utils_Pager
::PAGE_ID
),
130 CRM_Core_Action
::VIEW
,
138 $controller->setEmbedded(TRUE);
141 $controller->moveFromSessionToTemplate();
143 $this->assign('context', 'case');
147 * This function is called when action is browse
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();
163 if ($this->_contactId
) {
164 $displayName = CRM_Contact_BAO_Contact
::displayName($this->_contactId
);
165 $this->assign('displayName', $displayName);
170 * This function is called when action is update or new
176 $config = CRM_Core_Config
::singleton();
178 $controller = new CRM_Core_Controller_Simple(
179 'CRM_Case_Form_Case',
184 $controller->setEmbedded(TRUE);
186 return $controller->run();
190 * This function is the main function that is called when the page loads,
191 * it decides the which action has to be taken for the page.
197 $contactID = CRM_Utils_Request
::retrieve('cid', 'Positive', CRM_Core_DAO
::$_nullArray);
198 $context = CRM_Utils_Request
::retrieve('context', 'String', $this);
200 if ($context == 'standalone' && !$contactID) {
201 $this->_action
= CRM_Core_Action
::ADD
;
204 // we need to call parent preprocess only when we are viewing / editing / adding participant record
208 $this->assign('action', $this->_action
);
212 if ($this->_action
& CRM_Core_Action
::VIEW
) {
215 elseif (($this->_action
&
216 (CRM_Core_Action
::UPDATE | CRM_Core_Action
::ADD |
217 CRM_Core_Action
::DELETE | CRM_Core_Action
::RENEW
224 elseif ($this->_contactId
) {
228 return parent
::run();
234 * @return array (reference) of action links
239 $config = CRM_Core_Config
::singleton();
241 if (!(self
::$_links)) {
242 $deleteExtra = ts('Are you sure you want to delete this case?');
243 self
::$_links = array(
244 CRM_Core_Action
::VIEW
=> array(
245 'name' => ts('Manage'),
246 'url' => 'civicrm/contact/view/case',
247 'qs' => 'action=view&reset=1&cid=%%cid%%&id=%%id%%',
248 'title' => ts('Manage Case'),
250 CRM_Core_Action
::DELETE
=> array(
251 'name' => ts('Delete'),
252 'url' => 'civicrm/contact/view/case',
253 'qs' => 'action=delete&reset=1&cid=%%cid%%&id=%%id%%',
254 'title' => ts('Delete Case'),
258 return self
::$_links;
261 function setContext() {
262 $context = $this->get('context');
265 $qfKey = CRM_Utils_Request
::retrieve('key', 'String', $this);
267 if (!CRM_Utils_Rule
::qfKey($qfKey)) {
273 if ($this->_contactId
) {
274 $url = CRM_Utils_System
::url('civicrm/contact/view',
275 "reset=1&force=1&cid={$this->_contactId}&selectedChild=activity"
281 $url = CRM_Utils_System
::url('civicrm/case', "reset=1");
285 $urlParams = 'force=1';
287 $urlParams .= "&qfKey=$qfKey";
290 $url = CRM_Utils_System
::url('civicrm/case/search', $urlParams);
294 case 'dashletFullscreen':
297 $url = CRM_Utils_System
::url('civicrm/dashboard', 'reset=1');
301 $action = CRM_Utils_Request
::retrieve('action', 'String', $this);
302 $urlParams = 'force=1';
303 $urlString = 'civicrm/contact/search/custom';
304 if ($action == CRM_Core_Action
::RENEW
) {
305 if ($this->_contactId
) {
306 $urlParams .= '&cid=' . $this->_contactId
;
308 $urlParams .= '&context=fulltext&action=view';
309 $urlString = 'civicrm/contact/view/case';
312 $urlParams .= "&qfKey=$qfKey";
314 $url = CRM_Utils_System
::url($urlString, $urlParams);
318 if ($this->_contactId
) {
319 $url = CRM_Utils_System
::url('civicrm/contact/view',
320 "reset=1&force=1&cid={$this->_contactId}&selectedChild=case"
327 $session = CRM_Core_Session
::singleton();
328 $session->pushUserContext($url);