Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
6a488035 TO |
2 | /* |
3 | +--------------------------------------------------------------------+ | |
fee14197 | 4 | | CiviCRM version 5 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
f299f7db | 6 | | Copyright CiviCRM LLC (c) 2004-2020 | |
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 | |
ca5cec67 | 31 | * @copyright CiviCRM LLC https://civicrm.org/licensing |
6a488035 TO |
32 | */ |
33 | class CRM_ACL_Page_ACL extends CRM_Core_Page_Basic { | |
34 | ||
96f50de2 CW |
35 | public $useLivePageJS = TRUE; |
36 | ||
6a488035 | 37 | /** |
d2e5d2ce | 38 | * The action links that we need to display for the browse screen. |
6a488035 TO |
39 | * |
40 | * @var array | |
6a488035 | 41 | */ |
683bf891 | 42 | public static $_links = NULL; |
6a488035 TO |
43 | |
44 | /** | |
d2e5d2ce | 45 | * Get BAO Name. |
6a488035 | 46 | * |
a6c01b45 CW |
47 | * @return string |
48 | * Classname of BAO. | |
6a488035 | 49 | */ |
00be9182 | 50 | public function getBAOName() { |
6a488035 TO |
51 | return 'CRM_ACL_BAO_ACL'; |
52 | } | |
53 | ||
54 | /** | |
d2e5d2ce | 55 | * Get action Links. |
6a488035 | 56 | * |
a6c01b45 CW |
57 | * @return array |
58 | * (reference) of action links | |
6a488035 | 59 | */ |
00be9182 | 60 | public function &links() { |
6a488035 | 61 | if (!(self::$_links)) { |
cf0d1c08 | 62 | self::$_links = [ |
63 | CRM_Core_Action::UPDATE => [ | |
6a488035 TO |
64 | 'name' => ts('Edit'), |
65 | 'url' => 'civicrm/acl', | |
66 | 'qs' => 'reset=1&action=update&id=%%id%%', | |
67 | 'title' => ts('Edit ACL'), | |
cf0d1c08 | 68 | ], |
69 | CRM_Core_Action::DISABLE => [ | |
6a488035 | 70 | 'name' => ts('Disable'), |
1fe97a01 | 71 | 'ref' => 'crm-enable-disable', |
6a488035 | 72 | 'title' => ts('Disable ACL'), |
cf0d1c08 | 73 | ], |
74 | CRM_Core_Action::ENABLE => [ | |
6a488035 | 75 | 'name' => ts('Enable'), |
1fe97a01 | 76 | 'ref' => 'crm-enable-disable', |
6a488035 | 77 | 'title' => ts('Enable ACL'), |
cf0d1c08 | 78 | ], |
79 | CRM_Core_Action::DELETE => [ | |
6a488035 TO |
80 | 'name' => ts('Delete'), |
81 | 'url' => 'civicrm/acl', | |
82 | 'qs' => 'reset=1&action=delete&id=%%id%%', | |
83 | 'title' => ts('Delete ACL'), | |
cf0d1c08 | 84 | ], |
85 | ]; | |
6a488035 TO |
86 | } |
87 | return self::$_links; | |
88 | } | |
89 | ||
90 | /** | |
91 | * Run the page. | |
92 | * | |
5d6d0104 | 93 | * Set the breadcrumb before beginning the standard page run. |
6a488035 | 94 | */ |
00be9182 | 95 | public function run() { |
6a488035 | 96 | // set breadcrumb to append to admin/access |
cf0d1c08 | 97 | $breadCrumb = [ |
98 | [ | |
353ffa53 | 99 | 'title' => ts('Access Control'), |
cf0d1c08 | 100 | 'url' => CRM_Utils_System::url('civicrm/admin/access', 'reset=1'), |
101 | ], | |
102 | ]; | |
6a488035 | 103 | CRM_Utils_System::appendBreadCrumb($breadCrumb); |
6a488035 TO |
104 | |
105 | // parent run | |
106 | return parent::run(); | |
107 | } | |
108 | ||
109 | /** | |
d2e5d2ce | 110 | * Browse all acls. |
6a488035 | 111 | */ |
00be9182 | 112 | public function browse() { |
6a488035 | 113 | // get all acl's sorted by weight |
cf0d1c08 | 114 | $acl = []; |
6a488035 TO |
115 | $query = " |
116 | SELECT * | |
117 | FROM civicrm_acl | |
118 | WHERE ( object_table IN ( 'civicrm_saved_search', 'civicrm_uf_group', 'civicrm_custom_group', 'civicrm_event' ) ) | |
119 | ORDER BY entity_id | |
120 | "; | |
33621c4f | 121 | $dao = CRM_Core_DAO::executeQuery($query); |
6a488035 TO |
122 | |
123 | $roles = CRM_Core_OptionGroup::values('acl_role'); | |
124 | ||
cf0d1c08 | 125 | $group = [ |
0d48f1cc TO |
126 | '-1' => ts('- select -'), |
127 | '0' => ts('All Groups'), | |
128 | ] + CRM_Core_PseudoConstant::group(); | |
cf0d1c08 | 129 | $customGroup = [ |
0d48f1cc TO |
130 | '-1' => ts('- select -'), |
131 | '0' => ts('All Custom Groups'), | |
132 | ] + CRM_Core_PseudoConstant::get('CRM_Core_DAO_CustomField', 'custom_group_id'); | |
cf0d1c08 | 133 | $ufGroup = [ |
0d48f1cc TO |
134 | '-1' => ts('- select -'), |
135 | '0' => ts('All Profiles'), | |
136 | ] + CRM_Core_PseudoConstant::get('CRM_Core_DAO_UFField', 'uf_group_id'); | |
6a488035 | 137 | |
cf0d1c08 | 138 | $event = [ |
0d48f1cc TO |
139 | '-1' => ts('- select -'), |
140 | '0' => ts('All Events'), | |
141 | ] + CRM_Event_PseudoConstant::event(); | |
6a488035 TO |
142 | |
143 | while ($dao->fetch()) { | |
cf0d1c08 | 144 | $acl[$dao->id] = []; |
6a488035 TO |
145 | $acl[$dao->id]['name'] = $dao->name; |
146 | $acl[$dao->id]['operation'] = $dao->operation; | |
147 | $acl[$dao->id]['entity_id'] = $dao->entity_id; | |
148 | $acl[$dao->id]['entity_table'] = $dao->entity_table; | |
149 | $acl[$dao->id]['object_table'] = $dao->object_table; | |
150 | $acl[$dao->id]['object_id'] = $dao->object_id; | |
151 | $acl[$dao->id]['is_active'] = $dao->is_active; | |
152 | ||
6a488035 | 153 | if ($acl[$dao->id]['entity_id']) { |
34939410 | 154 | $acl[$dao->id]['entity'] = CRM_Utils_Array::value($acl[$dao->id]['entity_id'], $roles); |
6a488035 TO |
155 | } |
156 | else { | |
157 | $acl[$dao->id]['entity'] = ts('Everyone'); | |
158 | } | |
159 | ||
160 | switch ($acl[$dao->id]['object_table']) { | |
161 | case 'civicrm_saved_search': | |
5d6d0104 | 162 | $acl[$dao->id]['object'] = CRM_Utils_Array::value($acl[$dao->id]['object_id'], $group); |
6a488035 TO |
163 | $acl[$dao->id]['object_name'] = ts('Group'); |
164 | break; | |
165 | ||
166 | case 'civicrm_uf_group': | |
5d6d0104 | 167 | $acl[$dao->id]['object'] = CRM_Utils_Array::value($acl[$dao->id]['object_id'], $ufGroup); |
6a488035 TO |
168 | $acl[$dao->id]['object_name'] = ts('Profile'); |
169 | break; | |
170 | ||
171 | case 'civicrm_custom_group': | |
5d6d0104 | 172 | $acl[$dao->id]['object'] = CRM_Utils_Array::value($acl[$dao->id]['object_id'], $customGroup); |
6a488035 TO |
173 | $acl[$dao->id]['object_name'] = ts('Custom Group'); |
174 | break; | |
175 | ||
176 | case 'civicrm_event': | |
5d6d0104 | 177 | $acl[$dao->id]['object'] = CRM_Utils_Array::value($acl[$dao->id]['object_id'], $event); |
6a488035 TO |
178 | $acl[$dao->id]['object_name'] = ts('Event'); |
179 | break; | |
180 | } | |
181 | ||
182 | // form all action links | |
183 | $action = array_sum(array_keys($this->links())); | |
184 | ||
185 | if ($dao->is_active) { | |
186 | $action -= CRM_Core_Action::ENABLE; | |
187 | } | |
188 | else { | |
189 | $action -= CRM_Core_Action::DISABLE; | |
190 | } | |
191 | ||
87dab4a4 AH |
192 | $acl[$dao->id]['action'] = CRM_Core_Action::formLink( |
193 | self::links(), | |
194 | $action, | |
cf0d1c08 | 195 | ['id' => $dao->id], |
87dab4a4 AH |
196 | ts('more'), |
197 | FALSE, | |
198 | 'ACL.manage.action', | |
199 | 'ACL', | |
200 | $dao->id | |
6a488035 TO |
201 | ); |
202 | } | |
203 | $this->assign('rows', $acl); | |
204 | } | |
205 | ||
206 | /** | |
d2e5d2ce | 207 | * Get name of edit form. |
6a488035 | 208 | * |
a6c01b45 CW |
209 | * @return string |
210 | * Classname of edit form. | |
6a488035 | 211 | */ |
00be9182 | 212 | public function editForm() { |
6a488035 TO |
213 | return 'CRM_ACL_Form_ACL'; |
214 | } | |
215 | ||
216 | /** | |
d2e5d2ce | 217 | * Get edit form name. |
6a488035 | 218 | * |
a6c01b45 CW |
219 | * @return string |
220 | * name of this page. | |
6a488035 | 221 | */ |
00be9182 | 222 | public function editName() { |
6a488035 TO |
223 | return 'ACL'; |
224 | } | |
225 | ||
226 | /** | |
227 | * Get user context. | |
228 | * | |
77b97be7 EM |
229 | * @param null $mode |
230 | * | |
a6c01b45 CW |
231 | * @return string |
232 | * user context. | |
6a488035 | 233 | */ |
00be9182 | 234 | public function userContext($mode = NULL) { |
6a488035 TO |
235 | return 'civicrm/acl'; |
236 | } | |
96025800 | 237 | |
5d6d0104 AH |
238 | /** |
239 | * Edit an ACL. | |
240 | * | |
241 | * @param int $mode | |
242 | * What mode for the form ?. | |
243 | * @param int $id | |
244 | * Id of the entity (for update, view operations). | |
245 | * @param bool $imageUpload | |
246 | * Not used in this case, but extended from CRM_Core_Page_Basic. | |
247 | * @param bool $pushUserContext | |
248 | * Not used in this case, but extended from CRM_Core_Page_Basic. | |
249 | */ | |
250 | public function edit($mode, $id = NULL, $imageUpload = FALSE, $pushUserContext = TRUE) { | |
251 | if ($mode & (CRM_Core_Action::UPDATE)) { | |
252 | if (isset($id)) { | |
253 | $aclName = CRM_Core_DAO::getFieldValue('CRM_ACL_DAO_ACL', $id); | |
cf0d1c08 | 254 | CRM_Utils_System::setTitle(ts('Edit ACL – %1', [1 => $aclName])); |
5d6d0104 AH |
255 | } |
256 | } | |
257 | parent::edit($mode, $id, $imageUpload, $pushUserContext); | |
258 | } | |
259 | ||
6a488035 | 260 | } |