Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
6a488035 TO |
2 | /* |
3 | +--------------------------------------------------------------------+ | |
232624b1 | 4 | | CiviCRM version 4.4 | |
6a488035 TO |
5 | +--------------------------------------------------------------------+ |
6 | | Copyright CiviCRM LLC (c) 2004-2013 | | |
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 | |
31 | * @copyright CiviCRM LLC (c) 2004-2013 | |
32 | * $Id$ | |
33 | * | |
34 | */ | |
35 | ||
36 | /** | |
37 | * | |
38 | * @package CRM | |
39 | * @copyright CiviCRM LLC (c) 2004-2013 | |
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 | * | |
50 | * @return None | |
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 | * | |
80 | * @return None | |
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 | ||
113 | static function formRule($params) { | |
114 | if ($params['entity_id'] == -1) { | |
115 | $errors = array('entity_id' => ts('Role is a required field')); | |
116 | return $errors; | |
117 | } | |
118 | ||
119 | return TRUE; | |
120 | } | |
121 | ||
122 | /** | |
123 | * Function to process the form | |
124 | * | |
125 | * @access public | |
126 | * | |
127 | * @return None | |
128 | */ | |
129 | public function postProcess() { | |
130 | CRM_ACL_BAO_Cache::resetCache(); | |
131 | ||
132 | $params = $this->controller->exportValues($this->_name); | |
133 | if ($this->_id || | |
134 | $this->_id === '0' | |
135 | ) { | |
136 | $query = " | |
137 | DELETE | |
138 | FROM civicrm_acl | |
139 | WHERE entity_id = %1 | |
140 | AND ( object_table NOT IN ( 'civicrm_saved_search', 'civicrm_uf_group', 'civicrm_custom_group' ) ) | |
141 | "; | |
142 | $deleteParams = array(1 => array($this->_id, 'Integer')); | |
143 | $dao = CRM_Core_DAO::executeQuery($query, $deleteParams); | |
144 | ||
145 | if ($this->_action & CRM_Core_Action::DELETE) { | |
146 | CRM_Core_Session::setStatus(ts('Selected ACL has been deleted.'), ts('Record Deleted'), 'success'); | |
147 | return; | |
148 | } | |
149 | } | |
150 | ||
151 | $params['operation'] = 'All'; | |
152 | $params['deny'] = 0; | |
153 | $params['is_active'] = 1; | |
154 | $params['entity_table'] = 'civicrm_acl_role'; | |
155 | $params['name'] = 'Core ACL'; | |
156 | ||
157 | foreach ($params['object_table'] as $object_table => $value) { | |
158 | if ($value) { | |
159 | $newParams = $params; | |
160 | unset($newParams['object_table']); | |
161 | $newParams['object_table'] = $object_table; | |
162 | CRM_ACL_BAO_ACL::create($newParams); | |
163 | } | |
164 | } | |
165 | } | |
166 | } | |
167 |