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