Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
7e9e8871 | 4 | | CiviCRM version 4.7 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
e7112fa7 | 6 | | Copyright CiviCRM LLC (c) 2004-2015 | |
6a488035 TO |
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 | +--------------------------------------------------------------------+ | |
d25dd0ee | 26 | */ |
6a488035 TO |
27 | |
28 | /** | |
29 | * | |
30 | * @package CRM | |
e7112fa7 | 31 | * @copyright CiviCRM LLC (c) 2004-2015 |
6a488035 TO |
32 | * $Id$ |
33 | * | |
34 | */ | |
35 | ||
36 | /** | |
37 | * This class handle grant related functions | |
38 | * | |
39 | */ | |
40 | class CRM_Grant_Page_Tab extends CRM_Contact_Page_View { | |
41 | ||
42 | /** | |
fe482240 | 43 | * The action links that we need to display for the browse screen. |
6a488035 TO |
44 | * |
45 | * @var array | |
6a488035 TO |
46 | */ |
47 | static $_links = NULL; | |
48 | public $_permission = NULL; | |
49 | public $_contactId = NULL; | |
50 | ||
51 | /** | |
fe482240 | 52 | * called when action is browse. |
6a488035 | 53 | * |
95ea96be | 54 | */ |
79d7553f | 55 | public function browse() { |
6a488035 TO |
56 | $controller = new CRM_Core_Controller_Simple('CRM_Grant_Form_Search', ts('Grants'), $this->_action); |
57 | $controller->setEmbedded(TRUE); | |
58 | $controller->reset(); | |
59 | $controller->set('cid', $this->_contactId); | |
60 | $controller->set('context', 'grant'); | |
61 | $controller->process(); | |
62 | $controller->run(); | |
63 | ||
64 | if ($this->_contactId) { | |
65 | $displayName = CRM_Contact_BAO_Contact::displayName($this->_contactId); | |
66 | $this->assign('displayName', $displayName); | |
4e8065a9 | 67 | $this->ajaxResponse['tabCount'] = CRM_Contact_BAO_Contact::getCountComponent('grant', $this->_contactId); |
6a488035 TO |
68 | } |
69 | } | |
70 | ||
71 | /** | |
fe482240 | 72 | * called when action is view. |
6a488035 | 73 | * |
76e7a76c | 74 | * @return null |
6a488035 | 75 | */ |
00be9182 | 76 | public function view() { |
6a488035 TO |
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); | |
81 | ||
82 | return $controller->run(); | |
83 | } | |
84 | ||
85 | /** | |
fe482240 | 86 | * called when action is update or new. |
6a488035 | 87 | * |
76e7a76c | 88 | * @return null |
6a488035 | 89 | */ |
00be9182 | 90 | public function edit() { |
6a488035 TO |
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); | |
95 | ||
96 | return $controller->run(); | |
97 | } | |
98 | ||
99 | /** | |
fe482240 | 100 | * Build all the data structures needed to build the form. |
6a488035 TO |
101 | * |
102 | * @return void | |
6a488035 | 103 | */ |
00be9182 | 104 | public function preProcess() { |
353ffa53 | 105 | $context = CRM_Utils_Request::retrieve('context', 'String', $this); |
6a488035 | 106 | $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'browse'); |
353ffa53 | 107 | $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this); |
6a488035 TO |
108 | |
109 | if ($context == 'standalone') { | |
110 | $this->_action = CRM_Core_Action::ADD; | |
111 | } | |
112 | else { | |
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); | |
117 | ||
118 | // check logged in url permission | |
119 | CRM_Contact_Page_View::checkUserPermission($this); | |
6a488035 TO |
120 | } |
121 | $this->assign('action', $this->_action); | |
122 | ||
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'); | |
127 | } | |
128 | } | |
129 | ||
130 | /** | |
dc195289 | 131 | * the main function that is called when the page loads, |
6a488035 TO |
132 | * it decides the which action has to be taken for the page. |
133 | * | |
76e7a76c | 134 | * @return null |
6a488035 | 135 | */ |
00be9182 | 136 | public function run() { |
6a488035 TO |
137 | $this->preProcess(); |
138 | ||
139 | $this->setContext(); | |
140 | ||
141 | if ($this->_action & CRM_Core_Action::VIEW) { | |
142 | $this->view(); | |
143 | } | |
144 | elseif ($this->_action & (CRM_Core_Action::UPDATE | CRM_Core_Action::ADD | CRM_Core_Action::DELETE)) { | |
145 | $this->edit(); | |
146 | } | |
147 | else { | |
148 | $this->browse(); | |
149 | } | |
150 | return parent::run(); | |
151 | } | |
152 | ||
00be9182 | 153 | public function setContext() { |
353ffa53 | 154 | $context = CRM_Utils_Request::retrieve('context', 'String', $this); |
6a488035 | 155 | $this->_id = CRM_Utils_Request::retrieve('id', 'Integer', $this); |
353ffa53 | 156 | $session = CRM_Core_Session::singleton(); |
6a488035 TO |
157 | |
158 | $qfKey = CRM_Utils_Request::retrieve('key', 'String', $this); | |
159 | //validate the qfKey | |
160 | if (!CRM_Utils_Rule::qfKey($qfKey)) { | |
161 | $qfKey = NULL; | |
162 | } | |
163 | ||
164 | switch ($context) { | |
165 | case 'search': | |
166 | $urlParams = 'force=1'; | |
167 | if ($qfKey) { | |
168 | $urlParams .= "&qfKey=$qfKey"; | |
169 | } | |
170 | $this->assign('searchKey', $qfKey); | |
171 | ||
172 | $url = CRM_Utils_System::url('civicrm/grant/search', $urlParams); | |
173 | break; | |
174 | ||
175 | case 'dashboard': | |
176 | $url = CRM_Utils_System::url('civicrm/grant', 'reset=1'); | |
177 | break; | |
178 | ||
179 | case 'edit': | |
180 | $url = CRM_utils_System::url('civicrm/contact/view/grant', 'reset=1&id=' . $this->_id . '&cid=' . $this->_contactId . '&action=view&context=grant&selectedChild=grant'); | |
181 | break; | |
182 | ||
183 | case 'grant': | |
184 | $url = CRM_Utils_System::url('civicrm/contact/view', 'action=browse&selectedChild=grant&cid=' . $this->_contactId); | |
185 | break; | |
186 | ||
187 | case 'standalone': | |
188 | $url = CRM_Utils_System::url('civicrm/dashboard', 'reset=1'); | |
189 | break; | |
190 | ||
191 | default: | |
192 | $cid = NULL; | |
193 | if ($this->_contactId) { | |
194 | $cid = '&cid=' . $this->_contactId; | |
195 | } | |
196 | $url = CRM_Utils_System::url('civicrm/grant/search', 'reset=1&force=1' . $cid); | |
197 | break; | |
198 | } | |
199 | $session->pushUserContext($url); | |
200 | ||
201 | if (CRM_Utils_Request::retrieve('confirmed', 'Boolean', | |
353ffa53 TO |
202 | CRM_Core_DAO::$_nullObject |
203 | ) | |
204 | ) { | |
6a488035 TO |
205 | CRM_Grant_BAO_Grant::del($this->_id); |
206 | CRM_Utils_System::redirect($url); | |
207 | } | |
208 | } | |
96025800 | 209 | |
6a488035 | 210 | } |