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