8293da89173495415b75e3d7652213ff1fd39c7f
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
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 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.
47 static $_links = NULL;
48 public $_permission = NULL;
49 public $_contactId = NULL;
52 * called when action is browse.
55 public function browse() {
56 $controller = new CRM_Core_Controller_Simple('CRM_Grant_Form_Search', ts('Grants'), $this->_action
);
57 $controller->setEmbedded(TRUE);
59 $controller->set('cid', $this->_contactId
);
60 $controller->set('context', 'grant');
61 $controller->process();
64 if ($this->_contactId
) {
65 $displayName = CRM_Contact_BAO_Contact
::displayName($this->_contactId
);
66 $this->assign('displayName', $displayName);
67 $this->ajaxResponse
['tabCount'] = CRM_Contact_BAO_Contact
::getCountComponent('grant', $this->_contactId
);
72 * called when action is view.
76 public function view() {
77 $controller = new CRM_Core_Controller_Simple('CRM_Grant_Form_GrantView', 'View Grant', $this->_action
);
78 $controller->setEmbedded(TRUE);
79 $controller->set('id', $this->_id
);
80 $controller->set('cid', $this->_contactId
);
82 return $controller->run();
86 * called when action is update or new.
90 public function edit() {
91 $controller = new CRM_Core_Controller_Simple('CRM_Grant_Form_Grant', 'Create grant', $this->_action
);
92 $controller->setEmbedded(TRUE);
93 $controller->set('id', $this->_id
);
94 $controller->set('cid', $this->_contactId
);
96 return $controller->run();
100 * Build all the data structures needed to build the form.
104 public function preProcess() {
105 $context = CRM_Utils_Request
::retrieve('context', 'String', $this);
106 $this->_action
= CRM_Utils_Request
::retrieve('action', 'String', $this, FALSE, 'browse');
107 $this->_id
= CRM_Utils_Request
::retrieve('id', 'Positive', $this);
109 if ($context == 'standalone') {
110 $this->_action
= CRM_Core_Action
::ADD
;
113 $this->_contactId
= CRM_Utils_Request
::retrieve('cid', 'Positive', $this, TRUE);
114 $displayName = CRM_Contact_BAO_Contact
::displayName($this->_contactId
);
115 $this->assign('contactId', $this->_contactId
);
116 $this->assign('displayName', $displayName);
118 // check logged in url permission
119 CRM_Contact_Page_View
::checkUserPermission($this);
121 $this->assign('action', $this->_action
);
123 if ($this->_permission
== CRM_Core_Permission
::EDIT
&& !CRM_Core_Permission
::check('edit grants')) {
124 // demote to view since user does not have edit grant rights
125 $this->_permission
= CRM_Core_Permission
::VIEW
;
126 $this->assign('permission', 'view');
131 * the main function that is called when the page loads,
132 * it decides the which action has to be taken for the page.
136 public function run() {
141 if ($this->_action
& CRM_Core_Action
::VIEW
) {
144 elseif ($this->_action
& (CRM_Core_Action
::UPDATE | CRM_Core_Action
::ADD | CRM_Core_Action
::DELETE
)) {
150 return parent
::run();
153 public function setContext() {
154 $context = CRM_Utils_Request
::retrieve('context', 'String', $this);
155 $this->_id
= CRM_Utils_Request
::retrieve('id', 'Integer', $this);
156 $session = CRM_Core_Session
::singleton();
158 $qfKey = CRM_Utils_Request
::retrieve('key', 'String', $this);
160 if (!CRM_Utils_Rule
::qfKey($qfKey)) {
166 $urlParams = 'force=1';
168 $urlParams .= "&qfKey=$qfKey";
170 $this->assign('searchKey', $qfKey);
172 $url = CRM_Utils_System
::url('civicrm/grant/search', $urlParams);
176 $url = CRM_Utils_System
::url('civicrm/grant', 'reset=1');
180 $url = CRM_utils_System
::url('civicrm/contact/view/grant', 'reset=1&id=' . $this->_id
. '&cid=' . $this->_contactId
. '&action=view&context=grant&selectedChild=grant');
184 $url = CRM_Utils_System
::url('civicrm/contact/view', 'action=browse&selectedChild=grant&cid=' . $this->_contactId
);
188 $url = CRM_Utils_System
::url('civicrm/dashboard', 'reset=1');
193 if ($this->_contactId
) {
194 $cid = '&cid=' . $this->_contactId
;
196 $url = CRM_Utils_System
::url('civicrm/grant/search', 'reset=1&force=1' . $cid);
199 $session->pushUserContext($url);
201 if (CRM_Utils_Request
::retrieve('confirmed', 'Boolean',
202 CRM_Core_DAO
::$_nullObject
205 CRM_Grant_BAO_Grant
::del($this->_id
);
206 CRM_Utils_System
::redirect($url);