PageRenderTime 24ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/drupal/sites/all/modules/civicrm/CRM/Case/Page/Tab.php

https://github.com/michaelmcandrew/vaw
PHP | 319 lines | 193 code | 47 blank | 79 comment | 31 complexity | d52305985e71c9b8f3212c9bfbc6fff2 MD5 | raw file
  1. <?php
  2. /*
  3. +--------------------------------------------------------------------+
  4. | CiviCRM version 3.4 |
  5. +--------------------------------------------------------------------+
  6. | Copyright CiviCRM LLC (c) 2004-2011 |
  7. +--------------------------------------------------------------------+
  8. | This file is a part of CiviCRM. |
  9. | |
  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. |
  13. | |
  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. |
  18. | |
  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. +--------------------------------------------------------------------+
  26. */
  27. /**
  28. *
  29. * @package CRM
  30. * @copyright CiviCRM LLC (c) 2004-2011
  31. * $Id$
  32. *
  33. */
  34. require_once 'CRM/Core/Page.php';
  35. require_once 'CRM/Case/BAO/Case.php';
  36. /**
  37. * This class handle case related functions
  38. *
  39. */
  40. class CRM_Case_Page_Tab extends CRM_Core_Page
  41. {
  42. /**
  43. * The action links that we need to display for the browse screen
  44. *
  45. * @var array
  46. * @static
  47. */
  48. static $_links = null;
  49. public $_permission = null;
  50. public $_contactId = null;
  51. function preProcess( )
  52. {
  53. $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, false, 'browse');
  54. $this->_contactId = CRM_Utils_Request::retrieve( 'cid', 'Positive', $this );
  55. //validate case configuration.
  56. require_once 'CRM/Case/BAO/Case.php';
  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'] ) {
  62. return;
  63. }
  64. $this->_id = CRM_Utils_Request::retrieve( 'id' , 'Positive', $this );
  65. $this->_context = CRM_Utils_Request::retrieve( 'context', 'String', $this );
  66. if ( $this->_contactId ) {
  67. $this->assign( 'contactId', $this->_contactId );
  68. // check logged in user permission
  69. require_once 'CRM/Contact/Page/View.php';
  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') );
  75. if ( !array_key_exists( $this->_id, $userCases ) ) {
  76. CRM_Core_Error::fatal( ts( 'You are not authorized to access this page.' ) );
  77. }
  78. }
  79. } else {
  80. CRM_Contact_Page_View::checkUserPermission( $this );
  81. }
  82. // set page title
  83. CRM_Contact_Page_View::setTitle( $this->_contactId );
  84. } else {
  85. if ( $this->_action & CRM_Core_Action::VIEW ) {
  86. CRM_Core_Error::fatal('Contact Id is required for view action.');
  87. }
  88. }
  89. $activityTypes = CRM_Case_PseudoConstant::activityType( );
  90. $this->assign( 'openCaseId' ,$activityTypes['Open Case']['id']);
  91. $this->assign( 'changeCaseTypeId' ,$activityTypes['Change Case Type']['id']);
  92. $this->assign( 'changeCaseStatusId',$activityTypes['Change Case Status']['id']);
  93. $this->assign( 'changeCaseStartDateId',$activityTypes['Change Case Start Date']['id']);
  94. }
  95. /**
  96. * View details of a case
  97. *
  98. * @return void
  99. * @access public
  100. */
  101. function view( )
  102. {
  103. $controller = new CRM_Core_Controller_Simple( 'CRM_Case_Form_CaseView',
  104. 'View Case',
  105. $this->_action );
  106. $controller->setEmbedded( true );
  107. $controller->set( 'id' , $this->_id );
  108. $controller->set( 'cid', $this->_contactId );
  109. $controller->run();
  110. $this->assign( 'caseId',$this->_id);
  111. require_once 'CRM/Activity/Selector/Activity.php' ;
  112. require_once 'CRM/Core/Selector/Controller.php';
  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($selector, $this->get(CRM_Utils_Pager::PAGE_ID),
  116. null, CRM_Core_Action::VIEW, $this, $output, null, $this->_id);
  117. $controller->setEmbedded(true);
  118. $controller->run();
  119. $controller->moveFromSessionToTemplate( );
  120. $this->assign( 'context', 'case');
  121. }
  122. /**
  123. * This function is called when action is browse
  124. *
  125. * return null
  126. * @access public
  127. */
  128. function browse( ) {
  129. $controller = new CRM_Core_Controller_Simple( 'CRM_Case_Form_Search', ts('Case'), null );
  130. $controller->setEmbedded( true );
  131. $controller->reset( );
  132. $controller->set( 'limit', 20 );
  133. $controller->set( 'force', 1 );
  134. $controller->set( 'context', 'case' );
  135. $controller->process( );
  136. $controller->run( );
  137. if ( $this->_contactId ) {
  138. require_once 'CRM/Contact/BAO/Contact.php';
  139. $displayName = CRM_Contact_BAO_Contact::displayName( $this->_contactId );
  140. $this->assign( 'displayName', $displayName );
  141. }
  142. }
  143. /**
  144. * This function is called when action is update or new
  145. *
  146. * return null
  147. * @access public
  148. */
  149. function edit( )
  150. {
  151. $config = CRM_Core_Config::singleton( );
  152. $controller = new CRM_Core_Controller_Simple( 'CRM_Case_Form_Case',
  153. 'Open Case',
  154. $this->_action );
  155. $controller->setEmbedded( true );
  156. return $controller->run( );
  157. }
  158. /**
  159. * This function is the main function that is called when the page loads,
  160. * it decides the which action has to be taken for the page.
  161. *
  162. * return null
  163. * @access public
  164. */
  165. function run( )
  166. {
  167. $contactID = CRM_Utils_Request::retrieve('cid', 'Positive', CRM_Core_DAO::$_nullArray );
  168. $context = CRM_Utils_Request::retrieve('context', 'String', $this );
  169. if ( $context == 'standalone' && !$contactID ) {
  170. $this->_action = CRM_Core_Action::ADD;
  171. } else {
  172. // we need to call parent preprocess only when we are viewing / editing / adding participant record
  173. $this->preProcess( );
  174. }
  175. $this->assign( 'action', $this->_action);
  176. $this->setContext( );
  177. if ( $this->_action & CRM_Core_Action::VIEW ) {
  178. $this->view( );
  179. } else if ( ( $this->_action &
  180. ( CRM_Core_Action::UPDATE | CRM_Core_Action::ADD |
  181. CRM_Core_Action::DELETE | CRM_Core_Action::RENEW ) ) ||
  182. ! empty( $_POST ) ) {
  183. $this->edit( );
  184. } else if ( $this->_contactId ) {
  185. $this->browse( );
  186. }
  187. return parent::run( );
  188. }
  189. /**
  190. * Get action links
  191. *
  192. * @return array (reference) of action links
  193. * @static
  194. */
  195. static function &links()
  196. {
  197. $config = CRM_Core_Config::singleton( );
  198. if (!(self::$_links)) {
  199. $deleteExtra = ts('Are you sure you want to delete this case?');
  200. self::$_links = array(
  201. CRM_Core_Action::VIEW => array(
  202. 'name' => ts('Manage'),
  203. 'url' => 'civicrm/contact/view/case',
  204. 'qs' => 'action=view&reset=1&cid=%%cid%%&id=%%id%%',
  205. 'title' => ts('Manage Case')
  206. ),
  207. CRM_Core_Action::DELETE => array(
  208. 'name' => ts('Delete'),
  209. 'url' => 'civicrm/contact/view/case',
  210. 'qs' => 'action=delete&reset=1&cid=%%cid%%&id=%%id%%',
  211. 'title' => ts('Delete Case')
  212. ),
  213. );
  214. }
  215. return self::$_links;
  216. }
  217. function setContext( )
  218. {
  219. $context = $this->get('context');
  220. $url = null;
  221. $qfKey = CRM_Utils_Request::retrieve( 'key', 'String', $this );
  222. //validate the qfKey
  223. require_once 'CRM/Utils/Rule.php';
  224. if ( !CRM_Utils_Rule::qfKey( $qfKey ) ) $qfKey = null;
  225. switch ( $context ) {
  226. case 'activity':
  227. if ( $this->_contactId ) {
  228. $url = CRM_Utils_System::url( 'civicrm/contact/view',
  229. "reset=1&force=1&cid={$this->_contactId}&selectedChild=activity" );
  230. }
  231. break;
  232. case 'dashboard':
  233. $url = CRM_Utils_System::url( 'civicrm/case', "reset=1" );
  234. break;
  235. case 'search':
  236. $urlParams = 'force=1';
  237. if ( $qfKey ) $urlParams .= "&qfKey=$qfKey";
  238. $url = CRM_Utils_System::url( 'civicrm/case/search', $urlParams );
  239. break;
  240. case 'dashlet':
  241. case 'dashletFullscreen':
  242. case 'home':
  243. case 'standalone':
  244. $url = CRM_Utils_System::url( 'civicrm/dashboard', 'reset=1' );
  245. break;
  246. case 'fulltext':
  247. $action = CRM_Utils_Request::retrieve('action', 'String', $this);
  248. $urlParams = 'force=1';
  249. $urlString = 'civicrm/contact/search/custom';
  250. if ( $action == CRM_Core_Action::RENEW ) {
  251. if ( $this->_contactId ) {
  252. $urlParams .= '&cid=' . $this->_contactId;
  253. }
  254. $urlParams .= '&context=fulltext&action=view';
  255. $urlString = 'civicrm/contact/view/case';
  256. }
  257. if ( $qfKey ) $urlParams .= "&qfKey=$qfKey";
  258. $url = CRM_Utils_System::url( $urlString, $urlParams );
  259. break;
  260. default:
  261. if ( $this->_contactId ) {
  262. $url = CRM_Utils_System::url( 'civicrm/contact/view',
  263. "reset=1&force=1&cid={$this->_contactId}&selectedChild=case" );
  264. }
  265. break;
  266. }
  267. if ( $url ) {
  268. $session = CRM_Core_Session::singleton( );
  269. $session->pushUserContext( $url );
  270. }
  271. }
  272. }