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