Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
6a488035 TO |
2 | /* |
3 | +--------------------------------------------------------------------+ | |
fee14197 | 4 | | CiviCRM version 5 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
6b83d5bd | 6 | | Copyright CiviCRM LLC (c) 2004-2019 | |
6a488035 TO |
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 | +--------------------------------------------------------------------+ | |
d25dd0ee | 26 | */ |
6a488035 TO |
27 | |
28 | /** | |
29 | * | |
30 | * @package CRM | |
6b83d5bd | 31 | * @copyright CiviCRM LLC (c) 2004-2019 |
6a488035 | 32 | */ |
6a488035 TO |
33 | class CRM_ACL_Form_ACLBasic extends CRM_Admin_Form { |
34 | ||
35 | /** | |
c490a46a | 36 | * Set default values for the form. |
6a488035 | 37 | */ |
00be9182 | 38 | public function setDefaultValues() { |
6a488035 TO |
39 | $defaults = array(); |
40 | ||
41 | if ($this->_id || | |
42 | $this->_id === '0' | |
43 | ) { | |
44 | $defaults['entity_id'] = $this->_id; | |
45 | ||
46 | $query = " | |
47 | SELECT object_table | |
48 | FROM civicrm_acl | |
49 | WHERE entity_id = %1 | |
50 | AND ( object_table NOT IN ( 'civicrm_saved_search', 'civicrm_uf_group', 'civicrm_custom_group' ) ) | |
51 | "; | |
52 | $params = array(1 => array($this->_id, 'Integer')); | |
53 | $dao = CRM_Core_DAO::executeQuery($query, $params); | |
54 | $defaults['object_table'] = array(); | |
55 | while ($dao->fetch()) { | |
56 | $defaults['object_table'][$dao->object_table] = 1; | |
57 | } | |
58 | } | |
59 | ||
60 | return $defaults; | |
61 | } | |
62 | ||
63 | /** | |
d2e5d2ce | 64 | * Build the form object. |
6a488035 TO |
65 | */ |
66 | public function buildQuickForm() { | |
67 | parent::buildQuickForm(); | |
68 | ||
69 | if ($this->_action & CRM_Core_Action::DELETE) { | |
70 | return; | |
71 | } | |
72 | ||
73 | $permissions = array_flip(CRM_Core_Permission::basicPermissions()); | |
74 | $this->addCheckBox('object_table', | |
75 | ts('ACL Type'), | |
76 | $permissions, | |
77 | NULL, NULL, TRUE, NULL, | |
78 | array('</td><td>', '</td></tr><tr><td>') | |
79 | ); | |
80 | ||
6a488035 | 81 | $label = ts('Role'); |
100b0ec6 | 82 | $role = array( |
28a04ea9 | 83 | '-1' => ts('- select role -'), |
84 | '0' => ts('Everyone'), | |
85 | ) + CRM_Core_OptionGroup::values('acl_role'); | |
6a488035 TO |
86 | $entityID = &$this->add('select', 'entity_id', $label, $role, TRUE); |
87 | ||
88 | if ($this->_id) { | |
89 | $entityID->freeze(); | |
90 | } | |
91 | $this->add('checkbox', 'is_active', ts('Enabled?')); | |
92 | ||
93 | $this->addFormRule(array('CRM_ACL_Form_ACLBasic', 'formRule')); | |
94 | } | |
95 | ||
28518c90 | 96 | /** |
c490a46a | 97 | * @param array $params |
28518c90 EM |
98 | * |
99 | * @return array|bool | |
100 | */ | |
00be9182 | 101 | public static function formRule($params) { |
6a488035 TO |
102 | if ($params['entity_id'] == -1) { |
103 | $errors = array('entity_id' => ts('Role is a required field')); | |
104 | return $errors; | |
105 | } | |
106 | ||
107 | return TRUE; | |
108 | } | |
109 | ||
110 | /** | |
d2e5d2ce | 111 | * Process the form submission. |
6a488035 TO |
112 | */ |
113 | public function postProcess() { | |
114 | CRM_ACL_BAO_Cache::resetCache(); | |
115 | ||
116 | $params = $this->controller->exportValues($this->_name); | |
117 | if ($this->_id || | |
118 | $this->_id === '0' | |
119 | ) { | |
120 | $query = " | |
121 | DELETE | |
122 | FROM civicrm_acl | |
123 | WHERE entity_id = %1 | |
124 | AND ( object_table NOT IN ( 'civicrm_saved_search', 'civicrm_uf_group', 'civicrm_custom_group' ) ) | |
125 | "; | |
126 | $deleteParams = array(1 => array($this->_id, 'Integer')); | |
7e1f3142 | 127 | CRM_Core_DAO::executeQuery($query, $deleteParams); |
6a488035 TO |
128 | |
129 | if ($this->_action & CRM_Core_Action::DELETE) { | |
130 | CRM_Core_Session::setStatus(ts('Selected ACL has been deleted.'), ts('Record Deleted'), 'success'); | |
131 | return; | |
132 | } | |
133 | } | |
134 | ||
135 | $params['operation'] = 'All'; | |
136 | $params['deny'] = 0; | |
137 | $params['is_active'] = 1; | |
138 | $params['entity_table'] = 'civicrm_acl_role'; | |
139 | $params['name'] = 'Core ACL'; | |
140 | ||
141 | foreach ($params['object_table'] as $object_table => $value) { | |
142 | if ($value) { | |
143 | $newParams = $params; | |
144 | unset($newParams['object_table']); | |
145 | $newParams['object_table'] = $object_table; | |
146 | CRM_ACL_BAO_ACL::create($newParams); | |
147 | } | |
148 | } | |
149 | } | |
96025800 | 150 | |
6a488035 | 151 | } |