3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
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.
52 function setDefaultValues() {
53 $defaults = parent
::setDefaultValues();
55 if ($this->_action
& CRM_Core_Action
::ADD
) {
56 $defaults['object_type'] = 1;
59 $showHide = new CRM_Core_ShowHideBlocks();
61 if (isset($defaults['object_table'])) {
62 switch ($defaults['object_table']) {
63 case 'civicrm_saved_search':
64 $defaults['group_id'] = $defaults['object_id'];
65 $defaults['object_type'] = 1;
66 $showHide->addShow("id-group-acl");
67 $showHide->addHide("id-profile-acl");
68 $showHide->addHide("id-custom-acl");
69 $showHide->addHide("id-event-acl");
72 case 'civicrm_uf_group':
73 $defaults['uf_group_id'] = $defaults['object_id'];
74 $defaults['object_type'] = 2;
75 $showHide->addHide("id-group-acl");
76 $showHide->addShow("id-profile-acl");
77 $showHide->addHide("id-custom-acl");
78 $showHide->addHide("id-event-acl");
81 case 'civicrm_custom_group':
82 $defaults['custom_group_id'] = $defaults['object_id'];
83 $defaults['object_type'] = 3;
84 $showHide->addHide("id-group-acl");
85 $showHide->addHide("id-profile-acl");
86 $showHide->addShow("id-custom-acl");
87 $showHide->addHide("id-event-acl");
91 $defaults['event_id'] = $defaults['object_id'];
92 $defaults['object_type'] = 4;
93 $showHide->addHide("id-group-acl");
94 $showHide->addHide("id-profile-acl");
95 $showHide->addHide("id-custom-acl");
96 $showHide->addShow("id-event-acl");
101 $showHide->addHide("id-group-acl");
102 $showHide->addHide("id-profile-acl");
103 $showHide->addHide("id-custom-acl");
104 $showHide->addHide("id-event-acl");
107 // Don't assign showHide elements to template in DELETE mode (fields to be shown and hidden don't exist)
108 if (!($this->_action
& CRM_Core_Action
::DELETE
)) {
109 $showHide->addToTemplate();
116 * Build the form object
121 public function buildQuickForm() {
122 parent
::buildQuickForm();
124 $this->setPageTitle(ts('ACL'));
126 if ($this->_action
& CRM_Core_Action
::DELETE
) {
130 $attributes = CRM_Core_DAO
::getAttribute('CRM_ACL_DAO_ACL');
132 $this->add('text', 'name', ts('Description'), CRM_Core_DAO
::getAttribute('CRM_ACL_DAO_ACL', 'name'), TRUE);
134 $operations = array('' => ts('- select -')) + CRM_ACL_BAO_ACL
::operation();
142 '1' => ts('A group of contacts'),
143 '2' => ts('A profile'),
144 '3' => ts('A set of custom data fields'),
147 if (CRM_Core_Permission
::access('CiviEvent')) {
148 $objTypes['4'] = ts('Events');
151 $extra = array('onclick' => "showObjectSelect();");
152 $this->addRadio('object_type',
162 '-1' => ts('- select role -'),
163 '0' => ts('Everyone'),
164 ) + CRM_Core_OptionGroup
::values('acl_role');
165 $this->add('select', 'entity_id', $label, $role, TRUE);
168 '-1' => ts('- select -'),
169 '0' => ts('All Groups'),
170 ) + CRM_Core_PseudoConstant
::group();
172 $customGroup = array(
173 '-1' => ts('- select -'),
174 '0' => ts('All Custom Groups'),
175 ) + CRM_Core_PseudoConstant
::get('CRM_Core_DAO_CustomField', 'custom_group_id');
178 '-1' => ts('- select -'),
179 '0' => ts('All Profiles'),
180 ) + CRM_Core_PseudoConstant
::get('CRM_Core_DAO_UFField', 'uf_group_id');
183 '-1' => ts('- select -'),
184 '0' => ts('All Events'),
185 ) + CRM_Event_PseudoConstant
::event(NULL, FALSE, "( is_template IS NULL OR is_template != 1 )");
187 $this->add('select', 'group_id', ts('Group'), $group);
188 $this->add('select', 'custom_group_id', ts('Custom Data'), $customGroup);
189 $this->add('select', 'uf_group_id', ts('Profile'), $ufGroup);
190 $this->add('select', 'event_id', ts('Event'), $event);
192 $this->add('checkbox', 'is_active', ts('Enabled?'));
194 $this->addFormRule(array('CRM_ACL_Form_ACL', 'formRule'));
198 * @param array $params
202 static function formRule($params) {
203 $showHide = new CRM_Core_ShowHideBlocks();
205 // Make sure role is not -1
206 if ($params['entity_id'] == -1) {
207 $errors['entity_id'] = ts('Please assign this permission to a Role.');
210 $validOperations = array('View', 'Edit');
211 $operationMessage = ts("Only 'View' and 'Edit' operations are valid for this type of data");
213 // Figure out which type of object we're permissioning on and make sure user has selected a value.
214 switch ($params['object_type']) {
216 if ($params['group_id'] == -1) {
217 $errors['group_id'] = ts('Please select a Group (or ALL Groups).');
218 $showHide->addShow("id-group-acl");
219 $showHide->addHide("id-profile-acl");
220 $showHide->addHide("id-custom-acl");
221 $showHide->addHide("id-event-acl");
223 if (!in_array($params['operation'], $validOperations)) {
224 $errors['operation'] = $operationMessage;
229 if ($params['uf_group_id'] == -1) {
230 $errors['uf_group_id'] = ts('Please select a Profile (or ALL Profiles).');
231 $showHide->addShow("id-profile-acl");
232 $showHide->addHide("id-group-acl");
233 $showHide->addHide("id-custom-acl");
234 $showHide->addHide("id-event-acl");
239 if ($params['custom_group_id'] == -1) {
240 $errors['custom_group_id'] = ts('Please select a set of Custom Data (or ALL Custom Data).');
241 $showHide->addShow("id-custom-acl");
242 $showHide->addHide("id-group-acl");
243 $showHide->addHide("id-profile-acl");
244 $showHide->addHide("id-event-acl");
246 if (!in_array($params['operation'], $validOperations)) {
247 $errors['operation'] = $operationMessage;
252 if ($params['event_id'] == -1) {
253 $errors['event_id'] = ts('Please select an Event (or ALL Events).');
254 $showHide->addShow("id-event-acl");
255 $showHide->addHide("id-custom-acl");
256 $showHide->addHide("id-group-acl");
257 $showHide->addHide("id-profile-acl");
259 if (!in_array($params['operation'], $validOperations)) {
260 $errors['operation'] = $operationMessage;
265 $showHide->addToTemplate();
267 return empty($errors) ?
TRUE : $errors;
271 * Process the form submission
277 public function postProcess() {
278 // note this also resets any ACL cache
279 CRM_Core_BAO_Cache
::deleteGroup('contact fields');
282 if ($this->_action
& CRM_Core_Action
::DELETE
) {
283 CRM_ACL_BAO_ACL
::del($this->_id
);
284 CRM_Core_Session
::setStatus(ts('Selected ACL has been deleted.'), ts('Record Deleted'), 'success');
287 $params = $this->controller
->exportValues($this->_name
);
288 $params['is_active'] = CRM_Utils_Array
::value('is_active', $params, FALSE);
290 $params['entity_table'] = 'civicrm_acl_role';
292 // Figure out which type of object we're permissioning on and set object_table and object_id.
293 switch ($params['object_type']) {
295 $params['object_table'] = 'civicrm_saved_search';
296 $params['object_id'] = $params['group_id'];
300 $params['object_table'] = 'civicrm_uf_group';
301 $params['object_id'] = $params['uf_group_id'];
305 $params['object_table'] = 'civicrm_custom_group';
306 $params['object_id'] = $params['custom_group_id'];
310 $params['object_table'] = 'civicrm_event';
311 $params['object_id'] = $params['event_id'];
316 $params['id'] = $this->_id
;
319 CRM_ACL_BAO_ACL
::create($params);