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 * This function sets the 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 * Function to build the form
121 public function buildQuickForm() {
122 parent
::buildQuickForm();
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();
139 $objTypes = array('1' => ts('A group of contacts'),
140 '2' => ts('A profile'),
141 '3' => ts('A set of custom data fields'),
144 if (CRM_Core_Permission
::access('CiviEvent')) {
145 $objTypes['4'] = ts('Events');
148 $extra = array('onclick' => "showObjectSelect();");
149 $this->addRadio('object_type',
158 $role = array('-1' => ts('- select role -'),
159 '0' => ts('Everyone'),
160 ) + CRM_Core_OptionGroup
::values('acl_role');
161 $this->add('select', 'entity_id', $label, $role, TRUE);
163 $group = array('-1' => ts('- select -'),
164 '0' => ts('All Groups'),
165 ) + CRM_Core_PseudoConstant
::group();
167 $customGroup = array('-1' => ts('- select -'),
168 '0' => ts('All Custom Groups'),
169 ) + CRM_Core_PseudoConstant
::get('CRM_Core_DAO_CustomField', 'custom_group_id');
171 $ufGroup = array('-1' => ts('- select -'),
172 '0' => ts('All Profiles'),
173 ) + CRM_Core_PseudoConstant
::get('CRM_Core_DAO_UFField', 'uf_group_id');
175 $event = array('-1' => ts('- select -'),
176 '0' => ts('All Events'),
177 ) + CRM_Event_PseudoConstant
::event(NULL, FALSE, "( is_template IS NULL OR is_template != 1 )");
179 $this->add('select', 'group_id', ts('Group'), $group);
180 $this->add('select', 'custom_group_id', ts('Custom Data'), $customGroup);
181 $this->add('select', 'uf_group_id', ts('Profile'), $ufGroup);
182 $this->add('select', 'event_id', ts('Event'), $event);
184 $this->add('checkbox', 'is_active', ts('Enabled?'));
186 $this->addFormRule(array('CRM_ACL_Form_ACL', 'formRule'));
189 static function formRule($params) {
190 $showHide = new CRM_Core_ShowHideBlocks();
192 // Make sure role is not -1
193 if ($params['entity_id'] == -1) {
194 $errors['entity_id'] = ts('Please assign this permission to a Role.');
197 $validOperations = array('View', 'Edit');
198 $operationMessage = ts("Only 'View' and 'Edit' operations are valid for this type of data");
200 // Figure out which type of object we're permissioning on and make sure user has selected a value.
201 switch ($params['object_type']) {
203 if ($params['group_id'] == -1) {
204 $errors['group_id'] = ts('Please select a Group (or ALL Groups).');
205 $showHide->addShow("id-group-acl");
206 $showHide->addHide("id-profile-acl");
207 $showHide->addHide("id-custom-acl");
208 $showHide->addHide("id-event-acl");
210 if (!in_array($params['operation'], $validOperations)) {
211 $errors['operation'] = $operationMessage;
216 if ($params['uf_group_id'] == -1) {
217 $errors['uf_group_id'] = ts('Please select a Profile (or ALL Profiles).');
218 $showHide->addShow("id-profile-acl");
219 $showHide->addHide("id-group-acl");
220 $showHide->addHide("id-custom-acl");
221 $showHide->addHide("id-event-acl");
226 if ($params['custom_group_id'] == -1) {
227 $errors['custom_group_id'] = ts('Please select a set of Custom Data (or ALL Custom Data).');
228 $showHide->addShow("id-custom-acl");
229 $showHide->addHide("id-group-acl");
230 $showHide->addHide("id-profile-acl");
231 $showHide->addHide("id-event-acl");
233 if (!in_array($params['operation'], $validOperations)) {
234 $errors['operation'] = $operationMessage;
239 if ($params['event_id'] == -1) {
240 $errors['event_id'] = ts('Please select an Event (or ALL Events).');
241 $showHide->addShow("id-event-acl");
242 $showHide->addHide("id-custom-acl");
243 $showHide->addHide("id-group-acl");
244 $showHide->addHide("id-profile-acl");
246 if (!in_array($params['operation'], $validOperations)) {
247 $errors['operation'] = $operationMessage;
252 $showHide->addToTemplate();
254 return empty($errors) ?
TRUE : $errors;
258 * Function to process the form
264 public function postProcess() {
265 // note this also resets any ACL cache
266 CRM_Core_BAO_Cache
::deleteGroup('contact fields');
269 if ($this->_action
& CRM_Core_Action
::DELETE
) {
270 CRM_ACL_BAO_ACL
::del($this->_id
);
271 CRM_Core_Session
::setStatus(ts('Selected ACL has been deleted.'), ts('Record Deleted'), 'success');
274 $params = $this->controller
->exportValues($this->_name
);
275 $params['is_active'] = CRM_Utils_Array
::value('is_active', $params, FALSE);
277 $params['entity_table'] = 'civicrm_acl_role';
279 // Figure out which type of object we're permissioning on and set object_table and object_id.
280 switch ($params['object_type']) {
282 $params['object_table'] = 'civicrm_saved_search';
283 $params['object_id'] = $params['group_id'];
287 $params['object_table'] = 'civicrm_uf_group';
288 $params['object_id'] = $params['uf_group_id'];
292 $params['object_table'] = 'civicrm_custom_group';
293 $params['object_id'] = $params['custom_group_id'];
297 $params['object_table'] = 'civicrm_event';
298 $params['object_id'] = $params['event_id'];
303 $params['id'] = $this->_id
;
306 CRM_ACL_BAO_ACL
::create($params);