3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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-2014
37 * This class handle grant related functions
40 class CRM_Grant_Page_Tab
extends CRM_Contact_Page_View
{
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;
53 * This function is called when action is browse
57 */ function browse() {
58 $controller = new CRM_Core_Controller_Simple('CRM_Grant_Form_Search', ts('Grants'), $this->_action
);
59 $controller->setEmbedded(TRUE);
61 $controller->set('cid', $this->_contactId
);
62 $controller->set('context', 'grant');
63 $controller->process();
66 if ($this->_contactId
) {
67 $displayName = CRM_Contact_BAO_Contact
::displayName($this->_contactId
);
68 $this->assign('displayName', $displayName);
69 $this->ajaxResponse
['tabCount'] = CRM_Contact_BAO_Contact
::getCountComponent('grant', $this->_contactId
);
74 * This function is called when action is view
80 $controller = new CRM_Core_Controller_Simple('CRM_Grant_Form_GrantView', 'View Grant', $this->_action
);
81 $controller->setEmbedded(TRUE);
82 $controller->set('id', $this->_id
);
83 $controller->set('cid', $this->_contactId
);
85 return $controller->run();
89 * This function is called when action is update or new
95 $controller = new CRM_Core_Controller_Simple('CRM_Grant_Form_Grant', 'Create grant', $this->_action
);
96 $controller->setEmbedded(TRUE);
97 $controller->set('id', $this->_id
);
98 $controller->set('cid', $this->_contactId
);
100 return $controller->run();
104 * build all the data structures needed to build the form
109 function preProcess() {
110 $context = CRM_Utils_Request
::retrieve('context', 'String', $this);
111 $this->_action
= CRM_Utils_Request
::retrieve('action', 'String', $this, FALSE, 'browse');
112 $this->_id
= CRM_Utils_Request
::retrieve('id', 'Positive', $this);
114 if ($context == 'standalone') {
115 $this->_action
= CRM_Core_Action
::ADD
;
118 $this->_contactId
= CRM_Utils_Request
::retrieve('cid', 'Positive', $this, TRUE);
119 $displayName = CRM_Contact_BAO_Contact
::displayName($this->_contactId
);
120 $this->assign('contactId', $this->_contactId
);
121 $this->assign('displayName', $displayName);
123 // check logged in url permission
124 CRM_Contact_Page_View
::checkUserPermission($this);
127 CRM_Utils_System
::setTitle(ts('Grant by') . ' ' . $displayName);
129 $this->assign('action', $this->_action
);
131 if ($this->_permission
== CRM_Core_Permission
::EDIT
&& !CRM_Core_Permission
::check('edit grants')) {
132 // demote to view since user does not have edit grant rights
133 $this->_permission
= CRM_Core_Permission
::VIEW
;
134 $this->assign('permission', 'view');
139 * This function is the main function that is called when the page loads,
140 * it decides the which action has to be taken for the page.
150 if ($this->_action
& CRM_Core_Action
::VIEW
) {
153 elseif ($this->_action
& (CRM_Core_Action
::UPDATE | CRM_Core_Action
::ADD | CRM_Core_Action
::DELETE
)) {
159 return parent
::run();
162 function setContext() {
163 $context = CRM_Utils_Request
::retrieve('context', 'String', $this);
164 $this->_id
= CRM_Utils_Request
::retrieve('id', 'Integer', $this);
165 $session = CRM_Core_Session
::singleton();
167 $qfKey = CRM_Utils_Request
::retrieve('key', 'String', $this);
169 if (!CRM_Utils_Rule
::qfKey($qfKey)) {
175 $urlParams = 'force=1';
177 $urlParams .= "&qfKey=$qfKey";
179 $this->assign('searchKey', $qfKey);
181 $url = CRM_Utils_System
::url('civicrm/grant/search', $urlParams);
185 $url = CRM_Utils_System
::url('civicrm/grant', 'reset=1');
189 $url = CRM_utils_System
::url('civicrm/contact/view/grant', 'reset=1&id=' . $this->_id
. '&cid=' . $this->_contactId
. '&action=view&context=grant&selectedChild=grant');
193 $url = CRM_Utils_System
::url('civicrm/contact/view', 'action=browse&selectedChild=grant&cid=' . $this->_contactId
);
197 $url = CRM_Utils_System
::url('civicrm/dashboard', 'reset=1');
202 if ($this->_contactId
) {
203 $cid = '&cid=' . $this->_contactId
;
205 $url = CRM_Utils_System
::url('civicrm/grant/search', 'reset=1&force=1' . $cid);
208 $session->pushUserContext($url);
210 if (CRM_Utils_Request
::retrieve('confirmed', 'Boolean',
211 CRM_Core_DAO
::$_nullObject
213 CRM_Grant_BAO_Grant
::del($this->_id
);
214 CRM_Utils_System
::redirect($url);