Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
06b69b18 | 4 | | CiviCRM version 4.5 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
06b69b18 | 6 | | Copyright CiviCRM LLC (c) 2004-2014 | |
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 | +--------------------------------------------------------------------+ | |
26 | */ | |
27 | ||
28 | /** | |
29 | * | |
30 | * @package CRM | |
06b69b18 | 31 | * @copyright CiviCRM LLC (c) 2004-2014 |
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 | /** | |
43 | * The action links that we need to display for the browse screen | |
44 | * | |
45 | * @var array | |
46 | * @static | |
47 | */ | |
48 | static $_links = NULL; | |
49 | public $_permission = NULL; | |
50 | public $_contactId = NULL; | |
51 | ||
52 | /** | |
53 | * This function is called when action is browse | |
54 | * | |
55 | * return null | |
56 | * @access public | |
57 | */ function browse() { | |
58 | $controller = new CRM_Core_Controller_Simple('CRM_Grant_Form_Search', ts('Grants'), $this->_action); | |
59 | $controller->setEmbedded(TRUE); | |
60 | $controller->reset(); | |
61 | $controller->set('cid', $this->_contactId); | |
62 | $controller->set('context', 'grant'); | |
63 | $controller->process(); | |
64 | $controller->run(); | |
65 | ||
66 | if ($this->_contactId) { | |
67 | $displayName = CRM_Contact_BAO_Contact::displayName($this->_contactId); | |
68 | $this->assign('displayName', $displayName); | |
4e8065a9 | 69 | $this->ajaxResponse['tabCount'] = CRM_Contact_BAO_Contact::getCountComponent('grant', $this->_contactId); |
6a488035 TO |
70 | } |
71 | } | |
72 | ||
73 | /** | |
74 | * This function is called when action is view | |
75 | * | |
76 | * return null | |
77 | * @access public | |
78 | */ | |
79 | function 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); | |
84 | ||
85 | return $controller->run(); | |
86 | } | |
87 | ||
88 | /** | |
89 | * This function is called when action is update or new | |
90 | * | |
91 | * return null | |
92 | * @access public | |
93 | */ | |
94 | function edit() { | |
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); | |
99 | ||
100 | return $controller->run(); | |
101 | } | |
102 | ||
103 | /** | |
104 | * build all the data structures needed to build the form | |
105 | * | |
106 | * @return void | |
107 | * @access public | |
108 | */ | |
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); | |
113 | ||
114 | if ($context == 'standalone') { | |
115 | $this->_action = CRM_Core_Action::ADD; | |
116 | } | |
117 | else { | |
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); | |
122 | ||
123 | // check logged in url permission | |
124 | CRM_Contact_Page_View::checkUserPermission($this); | |
125 | ||
126 | // set page title | |
f08f6e94 | 127 | CRM_Utils_System::setTitle(ts('Grant by') . ' ' . $displayName); |
6a488035 TO |
128 | } |
129 | $this->assign('action', $this->_action); | |
130 | ||
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'); | |
135 | } | |
136 | } | |
137 | ||
138 | /** | |
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. | |
141 | * | |
142 | * return null | |
143 | * @access public | |
144 | */ | |
145 | function run() { | |
146 | $this->preProcess(); | |
147 | ||
148 | $this->setContext(); | |
149 | ||
150 | if ($this->_action & CRM_Core_Action::VIEW) { | |
151 | $this->view(); | |
152 | } | |
153 | elseif ($this->_action & (CRM_Core_Action::UPDATE | CRM_Core_Action::ADD | CRM_Core_Action::DELETE)) { | |
154 | $this->edit(); | |
155 | } | |
156 | else { | |
157 | $this->browse(); | |
158 | } | |
159 | return parent::run(); | |
160 | } | |
161 | ||
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(); | |
166 | ||
167 | $qfKey = CRM_Utils_Request::retrieve('key', 'String', $this); | |
168 | //validate the qfKey | |
169 | if (!CRM_Utils_Rule::qfKey($qfKey)) { | |
170 | $qfKey = NULL; | |
171 | } | |
172 | ||
173 | switch ($context) { | |
174 | case 'search': | |
175 | $urlParams = 'force=1'; | |
176 | if ($qfKey) { | |
177 | $urlParams .= "&qfKey=$qfKey"; | |
178 | } | |
179 | $this->assign('searchKey', $qfKey); | |
180 | ||
181 | $url = CRM_Utils_System::url('civicrm/grant/search', $urlParams); | |
182 | break; | |
183 | ||
184 | case 'dashboard': | |
185 | $url = CRM_Utils_System::url('civicrm/grant', 'reset=1'); | |
186 | break; | |
187 | ||
188 | case 'edit': | |
189 | $url = CRM_utils_System::url('civicrm/contact/view/grant', 'reset=1&id=' . $this->_id . '&cid=' . $this->_contactId . '&action=view&context=grant&selectedChild=grant'); | |
190 | break; | |
191 | ||
192 | case 'grant': | |
193 | $url = CRM_Utils_System::url('civicrm/contact/view', 'action=browse&selectedChild=grant&cid=' . $this->_contactId); | |
194 | break; | |
195 | ||
196 | case 'standalone': | |
197 | $url = CRM_Utils_System::url('civicrm/dashboard', 'reset=1'); | |
198 | break; | |
199 | ||
200 | default: | |
201 | $cid = NULL; | |
202 | if ($this->_contactId) { | |
203 | $cid = '&cid=' . $this->_contactId; | |
204 | } | |
205 | $url = CRM_Utils_System::url('civicrm/grant/search', 'reset=1&force=1' . $cid); | |
206 | break; | |
207 | } | |
208 | $session->pushUserContext($url); | |
209 | ||
210 | if (CRM_Utils_Request::retrieve('confirmed', 'Boolean', | |
211 | CRM_Core_DAO::$_nullObject | |
212 | )) { | |
213 | CRM_Grant_BAO_Grant::del($this->_id); | |
214 | CRM_Utils_System::redirect($url); | |
215 | } | |
216 | } | |
217 | } | |
218 |