Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
6a488035 TO |
2 | /* |
3 | +--------------------------------------------------------------------+ | |
39de6fd5 | 4 | | CiviCRM version 4.6 | |
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 | * | |
38 | * @package CRM | |
06b69b18 | 39 | * @copyright CiviCRM LLC (c) 2004-2014 |
6a488035 TO |
40 | * $Id$ |
41 | * | |
42 | */ | |
43 | class CRM_ACL_Page_ACL extends CRM_Core_Page_Basic { | |
44 | ||
96f50de2 CW |
45 | public $useLivePageJS = TRUE; |
46 | ||
6a488035 TO |
47 | /** |
48 | * The action links that we need to display for the browse screen | |
49 | * | |
50 | * @var array | |
51 | * @static | |
52 | */ | |
53 | static $_links = NULL; | |
54 | ||
55 | /** | |
56 | * Get BAO Name | |
57 | * | |
a6c01b45 CW |
58 | * @return string |
59 | * Classname of BAO. | |
6a488035 | 60 | */ |
00be9182 | 61 | public function getBAOName() { |
6a488035 TO |
62 | return 'CRM_ACL_BAO_ACL'; |
63 | } | |
64 | ||
65 | /** | |
66 | * Get action Links | |
67 | * | |
a6c01b45 CW |
68 | * @return array |
69 | * (reference) of action links | |
6a488035 | 70 | */ |
00be9182 | 71 | public function &links() { |
6a488035 TO |
72 | if (!(self::$_links)) { |
73 | self::$_links = array( | |
74 | CRM_Core_Action::UPDATE => array( | |
75 | 'name' => ts('Edit'), | |
76 | 'url' => 'civicrm/acl', | |
77 | 'qs' => 'reset=1&action=update&id=%%id%%', | |
78 | 'title' => ts('Edit ACL'), | |
79 | ), | |
80 | CRM_Core_Action::DISABLE => array( | |
81 | 'name' => ts('Disable'), | |
1fe97a01 | 82 | 'ref' => 'crm-enable-disable', |
6a488035 TO |
83 | 'title' => ts('Disable ACL'), |
84 | ), | |
85 | CRM_Core_Action::ENABLE => array( | |
86 | 'name' => ts('Enable'), | |
1fe97a01 | 87 | 'ref' => 'crm-enable-disable', |
6a488035 TO |
88 | 'title' => ts('Enable ACL'), |
89 | ), | |
90 | CRM_Core_Action::DELETE => array( | |
91 | 'name' => ts('Delete'), | |
92 | 'url' => 'civicrm/acl', | |
93 | 'qs' => 'reset=1&action=delete&id=%%id%%', | |
94 | 'title' => ts('Delete ACL'), | |
95 | ), | |
96 | ); | |
97 | } | |
98 | return self::$_links; | |
99 | } | |
100 | ||
101 | /** | |
102 | * Run the page. | |
103 | * | |
104 | * This method is called after the page is created. It checks for the | |
105 | * type of action and executes that action. | |
106 | * Finally it calls the parent's run method. | |
107 | * | |
108 | * @return void | |
6a488035 | 109 | */ |
00be9182 | 110 | public function run() { |
6a488035 TO |
111 | // get the requested action |
112 | $action = CRM_Utils_Request::retrieve('action', 'String', | |
113 | // default to 'browse' | |
114 | $this, FALSE, 'browse' | |
115 | ); | |
116 | ||
117 | // assign vars to templates | |
118 | $this->assign('action', $action); | |
119 | $id = CRM_Utils_Request::retrieve('id', 'Positive', | |
120 | $this, FALSE, 0 | |
121 | ); | |
122 | ||
123 | // set breadcrumb to append to admin/access | |
353ffa53 TO |
124 | $breadCrumb = array( |
125 | array( | |
126 | 'title' => ts('Access Control'), | |
6a488035 TO |
127 | 'url' => CRM_Utils_System::url('civicrm/admin/access', |
128 | 'reset=1' | |
129 | ), | |
353ffa53 TO |
130 | ) |
131 | ); | |
6a488035 TO |
132 | CRM_Utils_System::appendBreadCrumb($breadCrumb); |
133 | // what action to take ? | |
134 | if ($action & (CRM_Core_Action::ADD | CRM_Core_Action::DELETE)) { | |
135 | $this->edit($action, $id); | |
136 | } | |
137 | ||
138 | if ($action & (CRM_Core_Action::UPDATE)) { | |
139 | $this->edit($action, $id); | |
140 | ||
141 | if (isset($id)) { | |
142 | $aclName = CRM_Core_DAO::getFieldValue('CRM_ACL_DAO_ACL', $id); | |
143 | CRM_Utils_System::setTitle(ts('Edit ACL - %1', array(1 => $aclName))); | |
144 | } | |
145 | } | |
146 | ||
6a488035 | 147 | // finally browse the acl's |
dd384531 | 148 | if ($action & CRM_Core_Action::BROWSE) { |
dd384531 CW |
149 | $this->browse(); |
150 | } | |
6a488035 TO |
151 | |
152 | // parent run | |
153 | return parent::run(); | |
154 | } | |
155 | ||
156 | /** | |
157 | * Browse all acls | |
158 | * | |
159 | * @return void | |
6a488035 TO |
160 | * @static |
161 | */ | |
00be9182 | 162 | public function browse() { |
6a488035 TO |
163 | // get all acl's sorted by weight |
164 | $acl = array(); | |
165 | $query = " | |
166 | SELECT * | |
167 | FROM civicrm_acl | |
168 | WHERE ( object_table IN ( 'civicrm_saved_search', 'civicrm_uf_group', 'civicrm_custom_group', 'civicrm_event' ) ) | |
169 | ORDER BY entity_id | |
170 | "; | |
171 | $dao = CRM_Core_DAO::executeQuery($query, | |
172 | CRM_Core_DAO::$_nullArray | |
173 | ); | |
174 | ||
175 | $roles = CRM_Core_OptionGroup::values('acl_role'); | |
176 | ||
100b0ec6 | 177 | $group = array( |
353ffa53 TO |
178 | '-1' => ts('- select -'), |
179 | '0' => ts('All Groups'), | |
180 | ) + CRM_Core_PseudoConstant::group(); | |
100b0ec6 | 181 | $customGroup = array( |
353ffa53 TO |
182 | '-1' => ts('- select -'), |
183 | '0' => ts('All Custom Groups'), | |
184 | ) + CRM_Core_PseudoConstant::get('CRM_Core_DAO_CustomField', 'custom_group_id'); | |
100b0ec6 | 185 | $ufGroup = array( |
353ffa53 TO |
186 | '-1' => ts('- select -'), |
187 | '0' => ts('All Profiles'), | |
188 | ) + CRM_Core_PseudoConstant::get('CRM_Core_DAO_UFField', 'uf_group_id'); | |
6a488035 | 189 | |
100b0ec6 | 190 | $event = array( |
353ffa53 TO |
191 | '-1' => ts('- select -'), |
192 | '0' => ts('All Events'), | |
193 | ) + CRM_Event_PseudoConstant::event(); | |
6a488035 TO |
194 | |
195 | while ($dao->fetch()) { | |
196 | $acl[$dao->id] = array(); | |
197 | $acl[$dao->id]['name'] = $dao->name; | |
198 | $acl[$dao->id]['operation'] = $dao->operation; | |
199 | $acl[$dao->id]['entity_id'] = $dao->entity_id; | |
200 | $acl[$dao->id]['entity_table'] = $dao->entity_table; | |
201 | $acl[$dao->id]['object_table'] = $dao->object_table; | |
202 | $acl[$dao->id]['object_id'] = $dao->object_id; | |
203 | $acl[$dao->id]['is_active'] = $dao->is_active; | |
204 | ||
6a488035 TO |
205 | if ($acl[$dao->id]['entity_id']) { |
206 | $acl[$dao->id]['entity'] = $roles[$acl[$dao->id]['entity_id']]; | |
207 | } | |
208 | else { | |
209 | $acl[$dao->id]['entity'] = ts('Everyone'); | |
210 | } | |
211 | ||
212 | switch ($acl[$dao->id]['object_table']) { | |
213 | case 'civicrm_saved_search': | |
214 | $acl[$dao->id]['object'] = $group[$acl[$dao->id]['object_id']]; | |
215 | $acl[$dao->id]['object_name'] = ts('Group'); | |
216 | break; | |
217 | ||
218 | case 'civicrm_uf_group': | |
219 | $acl[$dao->id]['object'] = $ufGroup[$acl[$dao->id]['object_id']]; | |
220 | $acl[$dao->id]['object_name'] = ts('Profile'); | |
221 | break; | |
222 | ||
223 | case 'civicrm_custom_group': | |
224 | $acl[$dao->id]['object'] = $customGroup[$acl[$dao->id]['object_id']]; | |
225 | $acl[$dao->id]['object_name'] = ts('Custom Group'); | |
226 | break; | |
227 | ||
228 | case 'civicrm_event': | |
229 | $acl[$dao->id]['object'] = $event[$acl[$dao->id]['object_id']]; | |
230 | $acl[$dao->id]['object_name'] = ts('Event'); | |
231 | break; | |
232 | } | |
233 | ||
234 | // form all action links | |
235 | $action = array_sum(array_keys($this->links())); | |
236 | ||
237 | if ($dao->is_active) { | |
238 | $action -= CRM_Core_Action::ENABLE; | |
239 | } | |
240 | else { | |
241 | $action -= CRM_Core_Action::DISABLE; | |
242 | } | |
243 | ||
87dab4a4 AH |
244 | $acl[$dao->id]['action'] = CRM_Core_Action::formLink( |
245 | self::links(), | |
246 | $action, | |
247 | array('id' => $dao->id), | |
248 | ts('more'), | |
249 | FALSE, | |
250 | 'ACL.manage.action', | |
251 | 'ACL', | |
252 | $dao->id | |
6a488035 TO |
253 | ); |
254 | } | |
255 | $this->assign('rows', $acl); | |
256 | } | |
257 | ||
258 | /** | |
259 | * Get name of edit form | |
260 | * | |
a6c01b45 CW |
261 | * @return string |
262 | * Classname of edit form. | |
6a488035 | 263 | */ |
00be9182 | 264 | public function editForm() { |
6a488035 TO |
265 | return 'CRM_ACL_Form_ACL'; |
266 | } | |
267 | ||
268 | /** | |
269 | * Get edit form name | |
270 | * | |
a6c01b45 CW |
271 | * @return string |
272 | * name of this page. | |
6a488035 | 273 | */ |
00be9182 | 274 | public function editName() { |
6a488035 TO |
275 | return 'ACL'; |
276 | } | |
277 | ||
278 | /** | |
279 | * Get user context. | |
280 | * | |
77b97be7 EM |
281 | * @param null $mode |
282 | * | |
a6c01b45 CW |
283 | * @return string |
284 | * user context. | |
6a488035 | 285 | */ |
00be9182 | 286 | public function userContext($mode = NULL) { |
6a488035 TO |
287 | return 'civicrm/acl'; |
288 | } | |
289 | } |