3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
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-2015
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.
47 static $_links = NULL;
48 public $_permission = NULL;
49 public $_contactId = NULL;
51 public function preProcess() {
52 $this->_action
= CRM_Utils_Request
::retrieve('action', 'String', $this, FALSE, 'browse');
53 $this->_contactId
= CRM_Utils_Request
::retrieve('cid', 'Positive', $this);
55 //validate case configuration.
56 $configured = CRM_Case_BAO_Case
::isCaseConfigured($this->_contactId
);
57 $this->assign('notConfigured', !$configured['configured']);
58 $this->assign('allowToAddNewCase', $configured['allowToAddNewCase']);
59 $this->assign('redirectToCaseAdmin', $configured['redirectToCaseAdmin']);
60 if (!$configured['configured'] ||
$configured['redirectToCaseAdmin']) {
64 $this->_id
= CRM_Utils_Request
::retrieve('id', 'Positive', $this);
65 $this->_context
= CRM_Utils_Request
::retrieve('context', 'String', $this);
67 if ($this->_contactId
) {
68 $this->assign('contactId', $this->_contactId
);
69 // check logged in user permission
70 if ($this->_id
&& ($this->_action
& CRM_Core_Action
::VIEW
)) {
71 //user might have special permissions to view this case, CRM-5666
72 if (!CRM_Core_Permission
::check('access all cases and activities')) {
73 $session = CRM_Core_Session
::singleton();
74 $userCases = CRM_Case_BAO_Case
::getCases(FALSE, $session->get('userID'), 'any');
75 if (!array_key_exists($this->_id
, $userCases)) {
76 CRM_Core_Error
::fatal(ts('You are not authorized to access this page.'));
81 CRM_Contact_Page_View
::checkUserPermission($this);
85 if ($this->_action
& CRM_Core_Action
::VIEW
) {
86 CRM_Core_Error
::fatal('Contact Id is required for view action.');
90 $activityTypes = CRM_Case_PseudoConstant
::caseActivityType();
92 $this->assign('openCaseId', $activityTypes['Open Case']['id']);
93 $this->assign('changeCaseTypeId', $activityTypes['Change Case Type']['id']);
94 $this->assign('changeCaseStatusId', $activityTypes['Change Case Status']['id']);
95 $this->assign('changeCaseStartDateId', $activityTypes['Change Case Start Date']['id']);
99 * View details of a case.
103 public function view() {
104 $controller = new CRM_Core_Controller_Simple(
105 'CRM_Case_Form_CaseView',
112 $controller->setEmbedded(TRUE);
113 $controller->set('id', $this->_id
);
114 $controller->set('cid', $this->_contactId
);
117 $this->assign('caseId', $this->_id
);
118 $output = CRM_Core_Selector_Controller
::SESSION
;
119 $selector = new CRM_Activity_Selector_Activity($this->_contactId
, $this->_permission
, FALSE, 'case');
120 $controller = new CRM_Core_Selector_Controller(
122 $this->get(CRM_Utils_Pager
::PAGE_ID
),
124 CRM_Core_Action
::VIEW
,
131 $controller->setEmbedded(TRUE);
134 $controller->moveFromSessionToTemplate();
136 $this->assign('context', 'case');
140 * called when action is browse.
144 public function browse() {
146 $controller = new CRM_Core_Controller_Simple('CRM_Case_Form_Search', ts('Case'), NULL);
147 $controller->setEmbedded(TRUE);
148 $controller->reset();
149 $controller->set('limit', 20);
150 $controller->set('force', 1);
151 $controller->set('context', 'case');
152 $controller->process();
155 if ($this->_contactId
) {
156 $displayName = CRM_Contact_BAO_Contact
::displayName($this->_contactId
);
157 $this->assign('displayName', $displayName);
158 $this->ajaxResponse
['tabCount'] = CRM_Contact_BAO_Contact
::getCountComponent('case', $this->_contactId
);
163 * called when action is update or new.
167 public function edit() {
168 $config = CRM_Core_Config
::singleton();
170 $controller = new CRM_Core_Controller_Simple(
171 'CRM_Case_Form_Case',
176 $controller->setEmbedded(TRUE);
178 return $controller->run();
182 * the main function that is called when the page loads,
183 * it decides the which action has to be taken for the page.
187 public function run() {
188 $contactID = CRM_Utils_Request
::retrieve('cid', 'Positive', CRM_Core_DAO
::$_nullArray);
189 $context = CRM_Utils_Request
::retrieve('context', 'String', $this);
191 if ($context == 'standalone' && !$contactID) {
192 $this->_action
= CRM_Core_Action
::ADD
;
195 // we need to call parent preprocess only when we are viewing / editing / adding participant record
199 $this->assign('action', $this->_action
);
203 if ($this->_action
& CRM_Core_Action
::VIEW
) {
206 elseif (($this->_action
& (CRM_Core_Action
::UPDATE | CRM_Core_Action
::ADD |
207 CRM_Core_Action
::DELETE | CRM_Core_Action
::RENEW
214 elseif ($this->_contactId
) {
218 return parent
::run();
225 * (reference) of action links
227 static public function &links() {
228 $config = CRM_Core_Config
::singleton();
230 if (!(self
::$_links)) {
231 $deleteExtra = ts('Are you sure you want to delete this case?');
232 self
::$_links = array(
233 CRM_Core_Action
::VIEW
=> array(
234 'name' => ts('Manage'),
235 'url' => 'civicrm/contact/view/case',
236 'qs' => 'action=view&reset=1&cid=%%cid%%&id=%%id%%',
237 'class' => 'no-popup',
238 'title' => ts('Manage Case'),
240 CRM_Core_Action
::DELETE
=> array(
241 'name' => ts('Delete'),
242 'url' => 'civicrm/contact/view/case',
243 'qs' => 'action=delete&reset=1&cid=%%cid%%&id=%%id%%',
244 'title' => ts('Delete Case'),
248 return self
::$_links;
251 public function setContext() {
252 $context = $this->get('context');
255 $qfKey = CRM_Utils_Request
::retrieve('key', 'String', $this);
257 if (!CRM_Utils_Rule
::qfKey($qfKey)) {
263 if ($this->_contactId
) {
264 $url = CRM_Utils_System
::url('civicrm/contact/view',
265 "reset=1&force=1&cid={$this->_contactId}&selectedChild=activity"
271 $url = CRM_Utils_System
::url('civicrm/case', "reset=1");
275 $urlParams = 'force=1';
277 $urlParams .= "&qfKey=$qfKey";
280 $url = CRM_Utils_System
::url('civicrm/case/search', $urlParams);
284 case 'dashletFullscreen':
287 $url = CRM_Utils_System
::url('civicrm/dashboard', 'reset=1');
291 $action = CRM_Utils_Request
::retrieve('action', 'String', $this);
292 $urlParams = 'force=1';
293 $urlString = 'civicrm/contact/search/custom';
294 if ($action == CRM_Core_Action
::RENEW
) {
295 if ($this->_contactId
) {
296 $urlParams .= '&cid=' . $this->_contactId
;
298 $urlParams .= '&context=fulltext&action=view';
299 $urlString = 'civicrm/contact/view/case';
302 $urlParams .= "&qfKey=$qfKey";
304 $url = CRM_Utils_System
::url($urlString, $urlParams);
308 if ($this->_contactId
) {
309 $url = CRM_Utils_System
::url('civicrm/contact/view',
310 "reset=1&force=1&cid={$this->_contactId}&selectedChild=case"
317 $session = CRM_Core_Session
::singleton();
318 $session->pushUserContext($url);