Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
bc77d7c0 | 4 | | Copyright CiviCRM LLC. All rights reserved. | |
6a488035 | 5 | | | |
bc77d7c0 TO |
6 | | This work is published under the GNU AGPLv3 license with some | |
7 | | permitted exceptions and without any warranty. For full license | | |
8 | | and copyright information, see https://civicrm.org/licensing | | |
6a488035 | 9 | +--------------------------------------------------------------------+ |
d25dd0ee | 10 | */ |
6a488035 TO |
11 | |
12 | /** | |
13 | * | |
14 | * @package CRM | |
ca5cec67 | 15 | * @copyright CiviCRM LLC https://civicrm.org/licensing |
6a488035 TO |
16 | * $Id$ |
17 | * | |
18 | */ | |
19 | ||
20 | /** | |
21 | * This class handle grant related functions | |
22 | * | |
23 | */ | |
24 | class CRM_Grant_Page_Tab extends CRM_Contact_Page_View { | |
25 | ||
26 | /** | |
fe482240 | 27 | * The action links that we need to display for the browse screen. |
6a488035 TO |
28 | * |
29 | * @var array | |
6a488035 | 30 | */ |
7e8c8317 | 31 | public static $_links = NULL; |
6a488035 TO |
32 | public $_permission = NULL; |
33 | public $_contactId = NULL; | |
34 | ||
35 | /** | |
fe482240 | 36 | * called when action is browse. |
6a488035 | 37 | * |
95ea96be | 38 | */ |
79d7553f | 39 | public function browse() { |
6a488035 TO |
40 | $controller = new CRM_Core_Controller_Simple('CRM_Grant_Form_Search', ts('Grants'), $this->_action); |
41 | $controller->setEmbedded(TRUE); | |
42 | $controller->reset(); | |
43 | $controller->set('cid', $this->_contactId); | |
44 | $controller->set('context', 'grant'); | |
45 | $controller->process(); | |
46 | $controller->run(); | |
47 | ||
48 | if ($this->_contactId) { | |
49 | $displayName = CRM_Contact_BAO_Contact::displayName($this->_contactId); | |
50 | $this->assign('displayName', $displayName); | |
4e8065a9 | 51 | $this->ajaxResponse['tabCount'] = CRM_Contact_BAO_Contact::getCountComponent('grant', $this->_contactId); |
6a488035 TO |
52 | } |
53 | } | |
54 | ||
55 | /** | |
fe482240 | 56 | * called when action is view. |
6a488035 | 57 | * |
76e7a76c | 58 | * @return null |
6a488035 | 59 | */ |
00be9182 | 60 | public function view() { |
6a488035 TO |
61 | $controller = new CRM_Core_Controller_Simple('CRM_Grant_Form_GrantView', 'View Grant', $this->_action); |
62 | $controller->setEmbedded(TRUE); | |
63 | $controller->set('id', $this->_id); | |
64 | $controller->set('cid', $this->_contactId); | |
65 | ||
66 | return $controller->run(); | |
67 | } | |
68 | ||
69 | /** | |
fe482240 | 70 | * called when action is update or new. |
6a488035 | 71 | * |
76e7a76c | 72 | * @return null |
6a488035 | 73 | */ |
00be9182 | 74 | public function edit() { |
6a488035 TO |
75 | $controller = new CRM_Core_Controller_Simple('CRM_Grant_Form_Grant', 'Create grant', $this->_action); |
76 | $controller->setEmbedded(TRUE); | |
77 | $controller->set('id', $this->_id); | |
78 | $controller->set('cid', $this->_contactId); | |
79 | ||
80 | return $controller->run(); | |
81 | } | |
82 | ||
83 | /** | |
fe482240 | 84 | * Build all the data structures needed to build the form. |
6a488035 TO |
85 | * |
86 | * @return void | |
6a488035 | 87 | */ |
00be9182 | 88 | public function preProcess() { |
edc80cda | 89 | $context = CRM_Utils_Request::retrieve('context', 'Alphanumeric', $this); |
6a488035 | 90 | $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'browse'); |
353ffa53 | 91 | $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this); |
6a488035 TO |
92 | |
93 | if ($context == 'standalone') { | |
94 | $this->_action = CRM_Core_Action::ADD; | |
95 | } | |
96 | else { | |
97 | $this->_contactId = CRM_Utils_Request::retrieve('cid', 'Positive', $this, TRUE); | |
98 | $displayName = CRM_Contact_BAO_Contact::displayName($this->_contactId); | |
99 | $this->assign('contactId', $this->_contactId); | |
100 | $this->assign('displayName', $displayName); | |
101 | ||
102 | // check logged in url permission | |
103 | CRM_Contact_Page_View::checkUserPermission($this); | |
6a488035 TO |
104 | } |
105 | $this->assign('action', $this->_action); | |
106 | ||
107 | if ($this->_permission == CRM_Core_Permission::EDIT && !CRM_Core_Permission::check('edit grants')) { | |
108 | // demote to view since user does not have edit grant rights | |
109 | $this->_permission = CRM_Core_Permission::VIEW; | |
110 | $this->assign('permission', 'view'); | |
111 | } | |
112 | } | |
113 | ||
114 | /** | |
dc195289 | 115 | * the main function that is called when the page loads, |
6a488035 TO |
116 | * it decides the which action has to be taken for the page. |
117 | * | |
76e7a76c | 118 | * @return null |
6a488035 | 119 | */ |
00be9182 | 120 | public function run() { |
6a488035 TO |
121 | $this->preProcess(); |
122 | ||
123 | $this->setContext(); | |
124 | ||
125 | if ($this->_action & CRM_Core_Action::VIEW) { | |
126 | $this->view(); | |
127 | } | |
128 | elseif ($this->_action & (CRM_Core_Action::UPDATE | CRM_Core_Action::ADD | CRM_Core_Action::DELETE)) { | |
129 | $this->edit(); | |
130 | } | |
131 | else { | |
132 | $this->browse(); | |
133 | } | |
134 | return parent::run(); | |
135 | } | |
136 | ||
00be9182 | 137 | public function setContext() { |
edc80cda | 138 | $context = CRM_Utils_Request::retrieve('context', 'Alphanumeric', $this); |
6a488035 | 139 | $this->_id = CRM_Utils_Request::retrieve('id', 'Integer', $this); |
353ffa53 | 140 | $session = CRM_Core_Session::singleton(); |
6a488035 TO |
141 | |
142 | $qfKey = CRM_Utils_Request::retrieve('key', 'String', $this); | |
143 | //validate the qfKey | |
144 | if (!CRM_Utils_Rule::qfKey($qfKey)) { | |
145 | $qfKey = NULL; | |
146 | } | |
147 | ||
148 | switch ($context) { | |
149 | case 'search': | |
150 | $urlParams = 'force=1'; | |
151 | if ($qfKey) { | |
152 | $urlParams .= "&qfKey=$qfKey"; | |
153 | } | |
154 | $this->assign('searchKey', $qfKey); | |
155 | ||
156 | $url = CRM_Utils_System::url('civicrm/grant/search', $urlParams); | |
157 | break; | |
158 | ||
159 | case 'dashboard': | |
160 | $url = CRM_Utils_System::url('civicrm/grant', 'reset=1'); | |
161 | break; | |
162 | ||
163 | case 'edit': | |
c33f1df1 | 164 | $url = CRM_Utils_System::url('civicrm/contact/view/grant', 'reset=1&id=' . $this->_id . '&cid=' . $this->_contactId . '&action=view&context=grant&selectedChild=grant'); |
6a488035 TO |
165 | break; |
166 | ||
167 | case 'grant': | |
168 | $url = CRM_Utils_System::url('civicrm/contact/view', 'action=browse&selectedChild=grant&cid=' . $this->_contactId); | |
169 | break; | |
170 | ||
171 | case 'standalone': | |
172 | $url = CRM_Utils_System::url('civicrm/dashboard', 'reset=1'); | |
173 | break; | |
174 | ||
175 | default: | |
176 | $cid = NULL; | |
177 | if ($this->_contactId) { | |
178 | $cid = '&cid=' . $this->_contactId; | |
179 | } | |
180 | $url = CRM_Utils_System::url('civicrm/grant/search', 'reset=1&force=1' . $cid); | |
181 | break; | |
182 | } | |
183 | $session->pushUserContext($url); | |
184 | ||
1273d77c | 185 | if (CRM_Utils_Request::retrieve('confirmed', 'Boolean')) { |
6a488035 TO |
186 | CRM_Grant_BAO_Grant::del($this->_id); |
187 | CRM_Utils_System::redirect($url); | |
188 | } | |
189 | } | |
96025800 | 190 | |
6a488035 | 191 | } |