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