3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2018 |
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-2018
33 class CRM_ACL_Form_ACL
extends CRM_Admin_Form
{
36 * Set default values for the form.
38 public function setDefaultValues() {
39 $defaults = parent
::setDefaultValues();
41 if ($this->_action
& CRM_Core_Action
::ADD
) {
42 $defaults['object_type'] = 1;
45 $showHide = new CRM_Core_ShowHideBlocks();
47 if (isset($defaults['object_table'])) {
48 switch ($defaults['object_table']) {
49 case 'civicrm_saved_search':
50 $defaults['group_id'] = $defaults['object_id'];
51 $defaults['object_type'] = 1;
52 $showHide->addShow("id-group-acl");
53 $showHide->addHide("id-profile-acl");
54 $showHide->addHide("id-custom-acl");
55 $showHide->addHide("id-event-acl");
58 case 'civicrm_uf_group':
59 $defaults['uf_group_id'] = $defaults['object_id'];
60 $defaults['object_type'] = 2;
61 $showHide->addHide("id-group-acl");
62 $showHide->addShow("id-profile-acl");
63 $showHide->addHide("id-custom-acl");
64 $showHide->addHide("id-event-acl");
67 case 'civicrm_custom_group':
68 $defaults['custom_group_id'] = $defaults['object_id'];
69 $defaults['object_type'] = 3;
70 $showHide->addHide("id-group-acl");
71 $showHide->addHide("id-profile-acl");
72 $showHide->addShow("id-custom-acl");
73 $showHide->addHide("id-event-acl");
77 $defaults['event_id'] = $defaults['object_id'];
78 $defaults['object_type'] = 4;
79 $showHide->addHide("id-group-acl");
80 $showHide->addHide("id-profile-acl");
81 $showHide->addHide("id-custom-acl");
82 $showHide->addShow("id-event-acl");
87 $showHide->addHide("id-group-acl");
88 $showHide->addHide("id-profile-acl");
89 $showHide->addHide("id-custom-acl");
90 $showHide->addHide("id-event-acl");
93 // Don't assign showHide elements to template in DELETE mode (fields to be shown and hidden don't exist)
94 if (!($this->_action
& CRM_Core_Action
::DELETE
)) {
95 $showHide->addToTemplate();
102 * Build the form object.
104 public function buildQuickForm() {
105 parent
::buildQuickForm();
107 $this->setPageTitle(ts('ACL'));
109 if ($this->_action
& CRM_Core_Action
::DELETE
) {
113 $attributes = CRM_Core_DAO
::getAttribute('CRM_ACL_DAO_ACL');
115 $this->add('text', 'name', ts('Description'), CRM_Core_DAO
::getAttribute('CRM_ACL_DAO_ACL', 'name'), TRUE);
117 $operations = array('' => ts('- select -')) + CRM_ACL_BAO_ACL
::operation();
125 '1' => ts('A group of contacts'),
126 '2' => ts('A profile'),
127 '3' => ts('A set of custom data fields'),
130 if (CRM_Core_Permission
::access('CiviEvent')) {
131 $objTypes['4'] = ts('Events');
134 $extra = array('onclick' => "showObjectSelect();");
135 $this->addRadio('object_type',
144 '-1' => ts('- select role -'),
145 '0' => ts('Everyone'),
146 ) + CRM_Core_OptionGroup
::values('acl_role');
147 $this->add('select', 'entity_id', $label, $role, TRUE);
150 '-1' => ts('- select -'),
151 '0' => ts('All Groups'),
152 ) + CRM_Core_PseudoConstant
::group();
154 $customGroup = array(
155 '-1' => ts('- select -'),
156 '0' => ts('All Custom Groups'),
157 ) + CRM_Core_PseudoConstant
::get('CRM_Core_DAO_CustomField', 'custom_group_id');
160 '-1' => ts('- select -'),
161 '0' => ts('All Profiles'),
162 ) + CRM_Core_PseudoConstant
::get('CRM_Core_DAO_UFField', 'uf_group_id');
165 '-1' => ts('- select -'),
166 '0' => ts('All Events'),
167 ) + CRM_Event_PseudoConstant
::event(NULL, FALSE, "( is_template IS NULL OR is_template != 1 )");
169 $this->add('select', 'group_id', ts('Group'), $group);
170 $this->add('select', 'custom_group_id', ts('Custom Data'), $customGroup);
171 $this->add('select', 'uf_group_id', ts('Profile'), $ufGroup);
172 $this->add('select', 'event_id', ts('Event'), $event);
174 $this->add('checkbox', 'is_active', ts('Enabled?'));
176 $this->addFormRule(array('CRM_ACL_Form_ACL', 'formRule'));
180 * @param array $params
184 public static function formRule($params) {
185 $showHide = new CRM_Core_ShowHideBlocks();
187 // Make sure role is not -1
188 if ($params['entity_id'] == -1) {
189 $errors['entity_id'] = ts('Please assign this permission to a Role.');
192 $validOperations = array('View', 'Edit');
193 $operationMessage = ts("Only 'View' and 'Edit' operations are valid for this type of data");
195 // Figure out which type of object we're permissioning on and make sure user has selected a value.
196 switch ($params['object_type']) {
198 if ($params['group_id'] == -1) {
199 $errors['group_id'] = ts('Please select a Group (or ALL Groups).');
200 $showHide->addShow("id-group-acl");
201 $showHide->addHide("id-profile-acl");
202 $showHide->addHide("id-custom-acl");
203 $showHide->addHide("id-event-acl");
205 if (!in_array($params['operation'], $validOperations)) {
206 $errors['operation'] = $operationMessage;
211 if ($params['uf_group_id'] == -1) {
212 $errors['uf_group_id'] = ts('Please select a Profile (or ALL Profiles).');
213 $showHide->addShow("id-profile-acl");
214 $showHide->addHide("id-group-acl");
215 $showHide->addHide("id-custom-acl");
216 $showHide->addHide("id-event-acl");
221 if ($params['custom_group_id'] == -1) {
222 $errors['custom_group_id'] = ts('Please select a set of Custom Data (or ALL Custom Data).');
223 $showHide->addShow("id-custom-acl");
224 $showHide->addHide("id-group-acl");
225 $showHide->addHide("id-profile-acl");
226 $showHide->addHide("id-event-acl");
228 if (!in_array($params['operation'], $validOperations)) {
229 $errors['operation'] = $operationMessage;
234 if ($params['event_id'] == -1) {
235 $errors['event_id'] = ts('Please select an Event (or ALL Events).');
236 $showHide->addShow("id-event-acl");
237 $showHide->addHide("id-custom-acl");
238 $showHide->addHide("id-group-acl");
239 $showHide->addHide("id-profile-acl");
241 if (!in_array($params['operation'], $validOperations)) {
242 $errors['operation'] = $operationMessage;
247 $showHide->addToTemplate();
249 return empty($errors) ?
TRUE : $errors;
253 * Process the form submission.
255 public function postProcess() {
256 // note this also resets any ACL cache
257 CRM_Core_BAO_Cache
::deleteGroup('contact fields');
259 if ($this->_action
& CRM_Core_Action
::DELETE
) {
260 CRM_ACL_BAO_ACL
::del($this->_id
);
261 CRM_Core_Session
::setStatus(ts('Selected ACL has been deleted.'), ts('Record Deleted'), 'success');
264 $params = $this->controller
->exportValues($this->_name
);
265 $params['is_active'] = CRM_Utils_Array
::value('is_active', $params, FALSE);
267 $params['entity_table'] = 'civicrm_acl_role';
269 // Figure out which type of object we're permissioning on and set object_table and object_id.
270 switch ($params['object_type']) {
272 $params['object_table'] = 'civicrm_saved_search';
273 $params['object_id'] = $params['group_id'];
277 $params['object_table'] = 'civicrm_uf_group';
278 $params['object_id'] = $params['uf_group_id'];
282 $params['object_table'] = 'civicrm_custom_group';
283 $params['object_id'] = $params['custom_group_id'];
287 $params['object_table'] = 'civicrm_event';
288 $params['object_id'] = $params['event_id'];
293 $params['id'] = $this->_id
;
296 CRM_ACL_BAO_ACL
::create($params);