ad580950f034030d56df0a8079ed6219aeb24280
[civicrm-core.git] / CRM / ACL / Page / ACLBasic.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_ACLBasic 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
57 * Classname of BAO.
58 */
59 public function getBAOName() {
60 return 'CRM_ACL_BAO_ACL';
61 }
62
63 /**
64 * Get action Links
65 *
66 * @return array
67 * (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/basic',
75 'qs' => 'reset=1&action=update&id=%%id%%',
76 'title' => ts('Edit ACL'),
77 ),
78 CRM_Core_Action::DELETE => array(
79 'name' => ts('Delete'),
80 'url' => 'civicrm/acl/basic',
81 'qs' => 'reset=1&action=delete&id=%%id%%',
82 'title' => ts('Delete ACL'),
83 ),
84 );
85 }
86 return self::$_links;
87 }
88
89 /**
90 * Run the page.
91 *
92 * This method is called after the page is created. It checks for the
93 * type of action and executes that action.
94 * Finally it calls the parent's run method.
95 *
96 * @return void
97 */
98 public function run() {
99 // get the requested action
100 $action = CRM_Utils_Request::retrieve('action', 'String',
101 // default to 'browse'
102 $this, FALSE, 'browse'
103 );
104
105 // assign vars to templates
106 $this->assign('action', $action);
107 $id = CRM_Utils_Request::retrieve('id', 'Positive',
108 $this, FALSE, 0
109 );
110
111 // set breadcrumb to append to admin/access
112 $breadCrumb = array(
113 array(
114 'title' => ts('Access Control'),
115 'url' => CRM_Utils_System::url('civicrm/admin/access', 'reset=1'),
116 )
117 );
118 CRM_Utils_System::appendBreadCrumb($breadCrumb);
119
120 // what action to take ?
121 if ($action & (CRM_Core_Action::UPDATE | CRM_Core_Action::ADD | CRM_Core_Action::DELETE)) {
122 $this->edit($action, $id);
123 }
124
125 // finally browse the acl's
126 $this->browse();
127
128 // parent run
129 return parent::run();
130 }
131
132 /**
133 * Browse all acls
134 *
135 * @return void
136 * @static
137 */
138 public function browse() {
139
140 // get all acl's sorted by weight
141 $acl = array();
142 $query = "
143 SELECT *
144 FROM civicrm_acl
145 WHERE ( object_table NOT IN ( 'civicrm_saved_search', 'civicrm_uf_group', 'civicrm_custom_group' ) )
146 ORDER BY entity_id
147 ";
148 $dao = CRM_Core_DAO::executeQuery($query,
149 CRM_Core_DAO::$_nullArray
150 );
151
152 $roles = CRM_Core_OptionGroup::values('acl_role');
153
154 $permissions = CRM_Core_Permission::basicPermissions();
155 while ($dao->fetch()) {
156 if (!array_key_exists($dao->entity_id, $acl)) {
157 $acl[$dao->entity_id] = array();
158 $acl[$dao->entity_id]['name'] = $dao->name;
159 $acl[$dao->entity_id]['entity_id'] = $dao->entity_id;
160 $acl[$dao->entity_id]['entity_table'] = $dao->entity_table;
161 $acl[$dao->entity_id]['object_table'] = CRM_Utils_Array::value($dao->object_table, $permissions);
162 $acl[$dao->entity_id]['is_active'] = 1;
163
164 if ($acl[$dao->entity_id]['entity_id']) {
165 $acl[$dao->entity_id]['entity'] = $roles[$acl[$dao->entity_id]['entity_id']];
166 }
167 else {
168 $acl[$dao->entity_id]['entity'] = ts('Any Role');
169 }
170
171 // form all action links
172 $action = array_sum(array_keys($this->links()));
173
174 $acl[$dao->entity_id]['action'] = CRM_Core_Action::formLink(
175 self::links(),
176 $action,
177 array('id' => $dao->entity_id),
178 ts('more'),
179 FALSE,
180 'aclRole.manage.action',
181 'ACLRole',
182 $dao->entity_id
183 );
184 }
185 elseif (!empty($permissions[$dao->object_table])) {
186 $acl[$dao->entity_id]['object_table'] .= ", {$permissions[$dao->object_table]}";
187 }
188 }
189 $this->assign('rows', $acl);
190 }
191
192 /**
193 * Get name of edit form
194 *
195 * @return string
196 * Classname of edit form.
197 */
198 public function editForm() {
199 return 'CRM_ACL_Form_ACLBasic';
200 }
201
202 /**
203 * Get edit form name
204 *
205 * @return string
206 * name of this page.
207 */
208 public function editName() {
209 return 'Core ACLs';
210 }
211
212 /**
213 * Get user context.
214 *
215 * @param null $mode
216 *
217 * @return string
218 * user context.
219 */
220 public function userContext($mode = NULL) {
221 return 'civicrm/acl/basic';
222 }
223 }