Commit | Line | Data |
---|---|---|
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 | */ | |
43 | class CRM_ACL_Page_EntityRole 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_EntityRole'; | |
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/entityrole', | |
73 | 'qs' => 'action=update&id=%%id%%', | |
74 | 'title' => ts('Edit ACL Role Assignment'), | |
75 | ), | |
76 | CRM_Core_Action::DISABLE => array( | |
77 | 'name' => ts('Disable'), | |
663072a5 | 78 | 'ref' => 'crm-enable-disable', |
6a488035 TO |
79 | 'title' => ts('Disable ACL Role Assignment'), |
80 | ), | |
81 | CRM_Core_Action::ENABLE => array( | |
82 | 'name' => ts('Enable'), | |
663072a5 | 83 | 'ref' => 'crm-enable-disable', |
6a488035 TO |
84 | 'title' => ts('Enable ACL Role Assignment'), |
85 | ), | |
86 | CRM_Core_Action::DELETE => array( | |
87 | 'name' => ts('Delete'), | |
88 | 'url' => 'civicrm/acl/entityrole', | |
89 | 'qs' => 'action=delete&id=%%id%%', | |
90 | 'title' => ts('Delete ACL Role Assignment'), | |
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 | CRM_Utils_System::setTitle(ts('Assign Users to Roles')); | |
129 | ||
130 | // what action to take ? | |
131 | if ($action & (CRM_Core_Action::UPDATE | CRM_Core_Action::ADD | CRM_Core_Action::DELETE)) { | |
132 | $this->edit($action, $id); | |
133 | } | |
134 | ||
135 | // reset cache if enabled/disabled | |
136 | if ($action & (CRM_Core_Action::DISABLE | CRM_Core_Action::ENABLE)) { | |
137 | CRM_ACL_BAO_Cache::resetCache(); | |
138 | } | |
139 | ||
140 | // finally browse the acl's | |
141 | if ($action & CRM_Core_Action::BROWSE) { | |
f1cf499b CW |
142 | if (CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'ajax_popups_enabled', NULL, TRUE)) { |
143 | CRM_Core_Resources::singleton()->addScriptFile('civicrm', 'js/crm.livePage.js'); | |
144 | } | |
6a488035 TO |
145 | } |
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() { | |
f1cf499b CW |
159 | if (CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'ajax_popups_enabled', NULL, TRUE)) { |
160 | CRM_Core_Resources::singleton()->addScriptFile('civicrm', 'js/crm.livePage.js'); | |
161 | } | |
6a488035 TO |
162 | |
163 | // get all acl's sorted by weight | |
164 | $entityRoles = array(); | |
165 | $dao = new CRM_ACL_DAO_EntityRole(); | |
166 | $dao->find(); | |
167 | ||
168 | $aclRoles = CRM_Core_OptionGroup::values('acl_role'); | |
169 | $groups = CRM_Core_PseudoConstant::staticGroup(); | |
170 | ||
171 | while ($dao->fetch()) { | |
172 | $entityRoles[$dao->id] = array(); | |
173 | CRM_Core_DAO::storeValues($dao, $entityRoles[$dao->id]); | |
174 | ||
175 | $entityRoles[$dao->id]['acl_role'] = $aclRoles[$dao->acl_role_id]; | |
176 | $entityRoles[$dao->id]['entity'] = $groups[$dao->entity_id]; | |
177 | ||
178 | // form all action links | |
179 | $action = array_sum(array_keys($this->links())); | |
180 | if ($dao->is_active) { | |
181 | $action -= CRM_Core_Action::ENABLE; | |
182 | } | |
183 | else { | |
184 | $action -= CRM_Core_Action::DISABLE; | |
185 | } | |
186 | ||
87dab4a4 AH |
187 | $entityRoles[$dao->id]['action'] = CRM_Core_Action::formLink( |
188 | self::links(), | |
189 | $action, | |
190 | array('id' => $dao->id), | |
191 | ts('more'), | |
192 | FALSE, | |
193 | 'entityRole.manage.action', | |
194 | 'EntityRole', | |
195 | $dao->id | |
6a488035 TO |
196 | ); |
197 | } | |
198 | $this->assign('rows', $entityRoles); | |
199 | } | |
200 | ||
201 | /** | |
202 | * Get name of edit form | |
203 | * | |
204 | * @return string Classname of edit form. | |
205 | */ | |
206 | function editForm() { | |
207 | return 'CRM_ACL_Form_EntityRole'; | |
208 | } | |
209 | ||
210 | /** | |
211 | * Get edit form name | |
212 | * | |
213 | * @return string name of this page. | |
214 | */ | |
215 | function editName() { | |
216 | return 'ACL EntityRole'; | |
217 | } | |
218 | ||
219 | /** | |
220 | * Get user context. | |
221 | * | |
222 | * @return string user context. | |
223 | */ | |
224 | function userContext($mode = NULL) { | |
225 | return 'civicrm/acl/entityrole'; | |
226 | } | |
227 | } | |
228 |