3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
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 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);
73 * This function is called when action is view
79 $controller = new CRM_Core_Controller_Simple('CRM_Grant_Form_GrantView', 'View Grant', $this->_action
);
80 $controller->setEmbedded(TRUE);
81 $controller->set('id', $this->_id
);
82 $controller->set('cid', $this->_contactId
);
84 return $controller->run();
88 * This function is called when action is update or new
94 $controller = new CRM_Core_Controller_Simple('CRM_Grant_Form_Grant', 'Create grant', $this->_action
);
95 $controller->setEmbedded(TRUE);
96 $controller->set('id', $this->_id
);
97 $controller->set('cid', $this->_contactId
);
99 return $controller->run();
103 * build all the data structures needed to build the form
108 function preProcess() {
109 $context = CRM_Utils_Request
::retrieve('context', 'String', $this);
110 $this->_action
= CRM_Utils_Request
::retrieve('action', 'String', $this, FALSE, 'browse');
111 $this->_id
= CRM_Utils_Request
::retrieve('id', 'Positive', $this);
113 if ($context == 'standalone') {
114 $this->_action
= CRM_Core_Action
::ADD
;
117 $this->_contactId
= CRM_Utils_Request
::retrieve('cid', 'Positive', $this, TRUE);
118 $displayName = CRM_Contact_BAO_Contact
::displayName($this->_contactId
);
119 $this->assign('contactId', $this->_contactId
);
120 $this->assign('displayName', $displayName);
122 // check logged in url permission
123 CRM_Contact_Page_View
::checkUserPermission($this);
126 CRM_Utils_System
::setTitle(ts('Grant by') . ' ' . $displayName);
128 $this->assign('action', $this->_action
);
130 if ($this->_permission
== CRM_Core_Permission
::EDIT
&& !CRM_Core_Permission
::check('edit grants')) {
131 // demote to view since user does not have edit grant rights
132 $this->_permission
= CRM_Core_Permission
::VIEW
;
133 $this->assign('permission', 'view');
138 * This function is the main function that is called when the page loads,
139 * it decides the which action has to be taken for the page.
149 if ($this->_action
& CRM_Core_Action
::VIEW
) {
152 elseif ($this->_action
& (CRM_Core_Action
::UPDATE | CRM_Core_Action
::ADD | CRM_Core_Action
::DELETE
)) {
158 return parent
::run();
161 function setContext() {
162 $context = CRM_Utils_Request
::retrieve('context', 'String', $this);
163 $this->_id
= CRM_Utils_Request
::retrieve('id', 'Integer', $this);
164 $session = CRM_Core_Session
::singleton();
166 $qfKey = CRM_Utils_Request
::retrieve('key', 'String', $this);
168 if (!CRM_Utils_Rule
::qfKey($qfKey)) {
174 $urlParams = 'force=1';
176 $urlParams .= "&qfKey=$qfKey";
178 $this->assign('searchKey', $qfKey);
180 $url = CRM_Utils_System
::url('civicrm/grant/search', $urlParams);
184 $url = CRM_Utils_System
::url('civicrm/grant', 'reset=1');
188 $url = CRM_utils_System
::url('civicrm/contact/view/grant', 'reset=1&id=' . $this->_id
. '&cid=' . $this->_contactId
. '&action=view&context=grant&selectedChild=grant');
192 $url = CRM_Utils_System
::url('civicrm/contact/view', 'action=browse&selectedChild=grant&cid=' . $this->_contactId
);
196 $url = CRM_Utils_System
::url('civicrm/dashboard', 'reset=1');
201 if ($this->_contactId
) {
202 $cid = '&cid=' . $this->_contactId
;
204 $url = CRM_Utils_System
::url('civicrm/grant/search', 'reset=1&force=1' . $cid);
207 $session->pushUserContext($url);
209 if (CRM_Utils_Request
::retrieve('confirmed', 'Boolean',
210 CRM_Core_DAO
::$_nullObject
212 CRM_Grant_BAO_Grant
::del($this->_id
);
213 CRM_Utils_System
::redirect($url);