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