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