3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2014
39 * @copyright CiviCRM LLC (c) 2004-2014
43 class CRM_ACL_Form_ACL
extends CRM_Admin_Form
{
46 * Set default values for the form.
51 public function setDefaultValues() {
52 $defaults = parent
::setDefaultValues();
54 if ($this->_action
& CRM_Core_Action
::ADD
) {
55 $defaults['object_type'] = 1;
58 $showHide = new CRM_Core_ShowHideBlocks();
60 if (isset($defaults['object_table'])) {
61 switch ($defaults['object_table']) {
62 case 'civicrm_saved_search':
63 $defaults['group_id'] = $defaults['object_id'];
64 $defaults['object_type'] = 1;
65 $showHide->addShow("id-group-acl");
66 $showHide->addHide("id-profile-acl");
67 $showHide->addHide("id-custom-acl");
68 $showHide->addHide("id-event-acl");
71 case 'civicrm_uf_group':
72 $defaults['uf_group_id'] = $defaults['object_id'];
73 $defaults['object_type'] = 2;
74 $showHide->addHide("id-group-acl");
75 $showHide->addShow("id-profile-acl");
76 $showHide->addHide("id-custom-acl");
77 $showHide->addHide("id-event-acl");
80 case 'civicrm_custom_group':
81 $defaults['custom_group_id'] = $defaults['object_id'];
82 $defaults['object_type'] = 3;
83 $showHide->addHide("id-group-acl");
84 $showHide->addHide("id-profile-acl");
85 $showHide->addShow("id-custom-acl");
86 $showHide->addHide("id-event-acl");
90 $defaults['event_id'] = $defaults['object_id'];
91 $defaults['object_type'] = 4;
92 $showHide->addHide("id-group-acl");
93 $showHide->addHide("id-profile-acl");
94 $showHide->addHide("id-custom-acl");
95 $showHide->addShow("id-event-acl");
100 $showHide->addHide("id-group-acl");
101 $showHide->addHide("id-profile-acl");
102 $showHide->addHide("id-custom-acl");
103 $showHide->addHide("id-event-acl");
106 // Don't assign showHide elements to template in DELETE mode (fields to be shown and hidden don't exist)
107 if (!($this->_action
& CRM_Core_Action
::DELETE
)) {
108 $showHide->addToTemplate();
115 * Build the form object.
119 public function buildQuickForm() {
120 parent
::buildQuickForm();
122 $this->setPageTitle(ts('ACL'));
124 if ($this->_action
& CRM_Core_Action
::DELETE
) {
128 $attributes = CRM_Core_DAO
::getAttribute('CRM_ACL_DAO_ACL');
130 $this->add('text', 'name', ts('Description'), CRM_Core_DAO
::getAttribute('CRM_ACL_DAO_ACL', 'name'), TRUE);
132 $operations = array('' => ts('- select -')) + CRM_ACL_BAO_ACL
::operation();
140 '1' => ts('A group of contacts'),
141 '2' => ts('A profile'),
142 '3' => ts('A set of custom data fields'),
145 if (CRM_Core_Permission
::access('CiviEvent')) {
146 $objTypes['4'] = ts('Events');
149 $extra = array('onclick' => "showObjectSelect();");
150 $this->addRadio('object_type',
159 '-1' => ts('- select role -'),
160 '0' => ts('Everyone'),
161 ) + CRM_Core_OptionGroup
::values('acl_role');
162 $this->add('select', 'entity_id', $label, $role, TRUE);
165 '-1' => ts('- select -'),
166 '0' => ts('All Groups'),
167 ) + CRM_Core_PseudoConstant
::group();
169 $customGroup = array(
170 '-1' => ts('- select -'),
171 '0' => ts('All Custom Groups'),
172 ) + CRM_Core_PseudoConstant
::get('CRM_Core_DAO_CustomField', 'custom_group_id');
175 '-1' => ts('- select -'),
176 '0' => ts('All Profiles'),
177 ) + CRM_Core_PseudoConstant
::get('CRM_Core_DAO_UFField', 'uf_group_id');
180 '-1' => ts('- select -'),
181 '0' => ts('All Events'),
182 ) + CRM_Event_PseudoConstant
::event(NULL, FALSE, "( is_template IS NULL OR is_template != 1 )");
184 $this->add('select', 'group_id', ts('Group'), $group);
185 $this->add('select', 'custom_group_id', ts('Custom Data'), $customGroup);
186 $this->add('select', 'uf_group_id', ts('Profile'), $ufGroup);
187 $this->add('select', 'event_id', ts('Event'), $event);
189 $this->add('checkbox', 'is_active', ts('Enabled?'));
191 $this->addFormRule(array('CRM_ACL_Form_ACL', 'formRule'));
195 * @param array $params
199 public static function formRule($params) {
200 $showHide = new CRM_Core_ShowHideBlocks();
202 // Make sure role is not -1
203 if ($params['entity_id'] == -1) {
204 $errors['entity_id'] = ts('Please assign this permission to a Role.');
207 $validOperations = array('View', 'Edit');
208 $operationMessage = ts("Only 'View' and 'Edit' operations are valid for this type of data");
210 // Figure out which type of object we're permissioning on and make sure user has selected a value.
211 switch ($params['object_type']) {
213 if ($params['group_id'] == -1) {
214 $errors['group_id'] = ts('Please select a Group (or ALL Groups).');
215 $showHide->addShow("id-group-acl");
216 $showHide->addHide("id-profile-acl");
217 $showHide->addHide("id-custom-acl");
218 $showHide->addHide("id-event-acl");
220 if (!in_array($params['operation'], $validOperations)) {
221 $errors['operation'] = $operationMessage;
226 if ($params['uf_group_id'] == -1) {
227 $errors['uf_group_id'] = ts('Please select a Profile (or ALL Profiles).');
228 $showHide->addShow("id-profile-acl");
229 $showHide->addHide("id-group-acl");
230 $showHide->addHide("id-custom-acl");
231 $showHide->addHide("id-event-acl");
236 if ($params['custom_group_id'] == -1) {
237 $errors['custom_group_id'] = ts('Please select a set of Custom Data (or ALL Custom Data).');
238 $showHide->addShow("id-custom-acl");
239 $showHide->addHide("id-group-acl");
240 $showHide->addHide("id-profile-acl");
241 $showHide->addHide("id-event-acl");
243 if (!in_array($params['operation'], $validOperations)) {
244 $errors['operation'] = $operationMessage;
249 if ($params['event_id'] == -1) {
250 $errors['event_id'] = ts('Please select an Event (or ALL Events).');
251 $showHide->addShow("id-event-acl");
252 $showHide->addHide("id-custom-acl");
253 $showHide->addHide("id-group-acl");
254 $showHide->addHide("id-profile-acl");
256 if (!in_array($params['operation'], $validOperations)) {
257 $errors['operation'] = $operationMessage;
262 $showHide->addToTemplate();
264 return empty($errors) ?
TRUE : $errors;
268 * Process the form submission.
273 public function postProcess() {
274 // note this also resets any ACL cache
275 CRM_Core_BAO_Cache
::deleteGroup('contact fields');
277 if ($this->_action
& CRM_Core_Action
::DELETE
) {
278 CRM_ACL_BAO_ACL
::del($this->_id
);
279 CRM_Core_Session
::setStatus(ts('Selected ACL has been deleted.'), ts('Record Deleted'), 'success');
282 $params = $this->controller
->exportValues($this->_name
);
283 $params['is_active'] = CRM_Utils_Array
::value('is_active', $params, FALSE);
285 $params['entity_table'] = 'civicrm_acl_role';
287 // Figure out which type of object we're permissioning on and set object_table and object_id.
288 switch ($params['object_type']) {
290 $params['object_table'] = 'civicrm_saved_search';
291 $params['object_id'] = $params['group_id'];
295 $params['object_table'] = 'civicrm_uf_group';
296 $params['object_id'] = $params['uf_group_id'];
300 $params['object_table'] = 'civicrm_custom_group';
301 $params['object_id'] = $params['custom_group_id'];
305 $params['object_table'] = 'civicrm_event';
306 $params['object_id'] = $params['event_id'];
311 $params['id'] = $this->_id
;
314 CRM_ACL_BAO_ACL
::create($params);