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