dev/core#1622 Fix unsubscribe when loading the unsubscribe form on a different locale...
[civicrm-core.git] / CRM / ACL / Page / ACLBasic.php
CommitLineData
6a488035 1<?php
6a488035
TO
2/*
3 +--------------------------------------------------------------------+
bc77d7c0 4 | Copyright CiviCRM LLC. All rights reserved. |
6a488035 5 | |
bc77d7c0
TO
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
6a488035 9 +--------------------------------------------------------------------+
d25dd0ee 10 */
6a488035
TO
11
12/**
13 *
14 * @package CRM
ca5cec67 15 * @copyright CiviCRM LLC https://civicrm.org/licensing
6a488035
TO
16 */
17class CRM_ACL_Page_ACLBasic extends CRM_Core_Page_Basic {
18
19 /**
d2e5d2ce 20 * The action links that we need to display for the browse screen.
6a488035
TO
21 *
22 * @var array
6a488035 23 */
683bf891 24 public static $_links = NULL;
6a488035
TO
25
26 /**
d2e5d2ce 27 * Get BAO Name.
6a488035 28 *
a6c01b45
CW
29 * @return string
30 * Classname of BAO.
6a488035 31 */
00be9182 32 public function getBAOName() {
6a488035
TO
33 return 'CRM_ACL_BAO_ACL';
34 }
35
36 /**
d2e5d2ce 37 * Get action Links.
6a488035 38 *
a6c01b45
CW
39 * @return array
40 * (reference) of action links
6a488035 41 */
00be9182 42 public function &links() {
6a488035 43 if (!(self::$_links)) {
cf0d1c08 44 self::$_links = [
45 CRM_Core_Action::UPDATE => [
6a488035
TO
46 'name' => ts('Edit'),
47 'url' => 'civicrm/acl/basic',
48 'qs' => 'reset=1&action=update&id=%%id%%',
49 'title' => ts('Edit ACL'),
cf0d1c08 50 ],
51 CRM_Core_Action::DELETE => [
6a488035
TO
52 'name' => ts('Delete'),
53 'url' => 'civicrm/acl/basic',
54 'qs' => 'reset=1&action=delete&id=%%id%%',
55 'title' => ts('Delete ACL'),
cf0d1c08 56 ],
57 ];
6a488035
TO
58 }
59 return self::$_links;
60 }
61
62 /**
63 * Run the page.
64 *
65 * This method is called after the page is created. It checks for the
66 * type of action and executes that action.
67 * Finally it calls the parent's run method.
6a488035 68 */
00be9182 69 public function run() {
5d6d0104 70 $id = $this->getIdAndAction();
6a488035
TO
71
72 // set breadcrumb to append to admin/access
cf0d1c08 73 $breadCrumb = [
74 [
353ffa53 75 'title' => ts('Access Control'),
6a488035 76 'url' => CRM_Utils_System::url('civicrm/admin/access', 'reset=1'),
cf0d1c08 77 ],
78 ];
6a488035
TO
79 CRM_Utils_System::appendBreadCrumb($breadCrumb);
80
81 // what action to take ?
5d6d0104
AH
82 if ($this->_action & (CRM_Core_Action::UPDATE | CRM_Core_Action::ADD | CRM_Core_Action::DELETE)) {
83 $this->edit($this->_action, $id);
6a488035
TO
84 }
85
86 // finally browse the acl's
87 $this->browse();
88
5d6d0104
AH
89 // This replaces parent run, but do parent's parent run
90 return CRM_Core_Page::run();
6a488035
TO
91 }
92
93 /**
d2e5d2ce 94 * Browse all acls.
6a488035 95 */
00be9182 96 public function browse() {
6a488035
TO
97
98 // get all acl's sorted by weight
cf0d1c08 99 $acl = [];
6a488035
TO
100 $query = "
101 SELECT *
102 FROM civicrm_acl
103 WHERE ( object_table NOT IN ( 'civicrm_saved_search', 'civicrm_uf_group', 'civicrm_custom_group' ) )
104ORDER BY entity_id
105";
33621c4f 106 $dao = CRM_Core_DAO::executeQuery($query);
6a488035
TO
107
108 $roles = CRM_Core_OptionGroup::values('acl_role');
109
110 $permissions = CRM_Core_Permission::basicPermissions();
111 while ($dao->fetch()) {
112 if (!array_key_exists($dao->entity_id, $acl)) {
cf0d1c08 113 $acl[$dao->entity_id] = [];
6a488035
TO
114 $acl[$dao->entity_id]['name'] = $dao->name;
115 $acl[$dao->entity_id]['entity_id'] = $dao->entity_id;
116 $acl[$dao->entity_id]['entity_table'] = $dao->entity_table;
117 $acl[$dao->entity_id]['object_table'] = CRM_Utils_Array::value($dao->object_table, $permissions);
118 $acl[$dao->entity_id]['is_active'] = 1;
119
120 if ($acl[$dao->entity_id]['entity_id']) {
121 $acl[$dao->entity_id]['entity'] = $roles[$acl[$dao->entity_id]['entity_id']];
122 }
123 else {
124 $acl[$dao->entity_id]['entity'] = ts('Any Role');
125 }
126
127 // form all action links
128 $action = array_sum(array_keys($this->links()));
129
87dab4a4
AH
130 $acl[$dao->entity_id]['action'] = CRM_Core_Action::formLink(
131 self::links(),
132 $action,
cf0d1c08 133 ['id' => $dao->entity_id],
87dab4a4
AH
134 ts('more'),
135 FALSE,
136 'aclRole.manage.action',
137 'ACLRole',
138 $dao->entity_id
6a488035
TO
139 );
140 }
a7488080 141 elseif (!empty($permissions[$dao->object_table])) {
6a488035
TO
142 $acl[$dao->entity_id]['object_table'] .= ", {$permissions[$dao->object_table]}";
143 }
144 }
145 $this->assign('rows', $acl);
146 }
147
148 /**
d2e5d2ce 149 * Get name of edit form.
6a488035 150 *
a6c01b45
CW
151 * @return string
152 * Classname of edit form.
6a488035 153 */
00be9182 154 public function editForm() {
6a488035
TO
155 return 'CRM_ACL_Form_ACLBasic';
156 }
157
158 /**
d2e5d2ce 159 * Get edit form name.
6a488035 160 *
a6c01b45
CW
161 * @return string
162 * name of this page.
6a488035 163 */
00be9182 164 public function editName() {
6a488035
TO
165 return 'Core ACLs';
166 }
167
168 /**
169 * Get user context.
170 *
77b97be7
EM
171 * @param null $mode
172 *
a6c01b45
CW
173 * @return string
174 * user context.
6a488035 175 */
00be9182 176 public function userContext($mode = NULL) {
6a488035
TO
177 return 'civicrm/acl/basic';
178 }
96025800 179
6a488035 180}