_action); $controller->setEmbedded(TRUE); $controller->reset(); $controller->set('cid', $this->_contactId); $controller->set('context', 'grant'); $controller->process(); $controller->run(); if ($this->_contactId) { $displayName = CRM_Contact_BAO_Contact::displayName($this->_contactId); $this->assign('displayName', $displayName); $this->ajaxResponse['tabCount'] = CRM_Contact_BAO_Contact::getCountComponent('grant', $this->_contactId); } } /** * This function is called when action is view * * return null * @access public */ function view() { $controller = new CRM_Core_Controller_Simple('CRM_Grant_Form_GrantView', 'View Grant', $this->_action); $controller->setEmbedded(TRUE); $controller->set('id', $this->_id); $controller->set('cid', $this->_contactId); return $controller->run(); } /** * This function is called when action is update or new * * return null * @access public */ function edit() { $controller = new CRM_Core_Controller_Simple('CRM_Grant_Form_Grant', 'Create grant', $this->_action); $controller->setEmbedded(TRUE); $controller->set('id', $this->_id); $controller->set('cid', $this->_contactId); return $controller->run(); } /** * Build all the data structures needed to build the form * * @return void * @access public */ function preProcess() { $context = CRM_Utils_Request::retrieve('context', 'String', $this); $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'browse'); $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this); if ($context == 'standalone') { $this->_action = CRM_Core_Action::ADD; } else { $this->_contactId = CRM_Utils_Request::retrieve('cid', 'Positive', $this, TRUE); $displayName = CRM_Contact_BAO_Contact::displayName($this->_contactId); $this->assign('contactId', $this->_contactId); $this->assign('displayName', $displayName); // check logged in url permission CRM_Contact_Page_View::checkUserPermission($this); } $this->assign('action', $this->_action); if ($this->_permission == CRM_Core_Permission::EDIT && !CRM_Core_Permission::check('edit grants')) { // demote to view since user does not have edit grant rights $this->_permission = CRM_Core_Permission::VIEW; $this->assign('permission', 'view'); } } /** * This function is the main function that is called when the page loads, * it decides the which action has to be taken for the page. * * return null * @access public */ function run() { $this->preProcess(); $this->setContext(); if ($this->_action & CRM_Core_Action::VIEW) { $this->view(); } elseif ($this->_action & (CRM_Core_Action::UPDATE | CRM_Core_Action::ADD | CRM_Core_Action::DELETE)) { $this->edit(); } else { $this->browse(); } return parent::run(); } function setContext() { $context = CRM_Utils_Request::retrieve('context', 'String', $this); $this->_id = CRM_Utils_Request::retrieve('id', 'Integer', $this); $session = CRM_Core_Session::singleton(); $qfKey = CRM_Utils_Request::retrieve('key', 'String', $this); //validate the qfKey if (!CRM_Utils_Rule::qfKey($qfKey)) { $qfKey = NULL; } switch ($context) { case 'search': $urlParams = 'force=1'; if ($qfKey) { $urlParams .= "&qfKey=$qfKey"; } $this->assign('searchKey', $qfKey); $url = CRM_Utils_System::url('civicrm/grant/search', $urlParams); break; case 'dashboard': $url = CRM_Utils_System::url('civicrm/grant', 'reset=1'); break; case 'edit': $url = CRM_utils_System::url('civicrm/contact/view/grant', 'reset=1&id=' . $this->_id . '&cid=' . $this->_contactId . '&action=view&context=grant&selectedChild=grant'); break; case 'grant': $url = CRM_Utils_System::url('civicrm/contact/view', 'action=browse&selectedChild=grant&cid=' . $this->_contactId); break; case 'standalone': $url = CRM_Utils_System::url('civicrm/dashboard', 'reset=1'); break; default: $cid = NULL; if ($this->_contactId) { $cid = '&cid=' . $this->_contactId; } $url = CRM_Utils_System::url('civicrm/grant/search', 'reset=1&force=1' . $cid); break; } $session->pushUserContext($url); if (CRM_Utils_Request::retrieve('confirmed', 'Boolean', CRM_Core_DAO::$_nullObject )) { CRM_Grant_BAO_Grant::del($this->_id); CRM_Utils_System::redirect($url); } } }