some cleanup - several user interface improvements
[openemr.git] / library / acl_upgrade_fx.php
blob995589a39fe2278bc0b0852cdd0ad1c67d74535f
1 <?php
2 /**
3 * Upgrading functions of access controls.
5 * Functions to allow safe access control modifications
6 * during upgrading.
8 * Copyright (C) 2012 Brady Miller <brady.g.miller@gmail.com>
10 * LICENSE: This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://opensource.org/licenses/gpl-license.php>.
21 * @package OpenEMR
22 * @author Brady Miller <brady.g.miller@gmail.com>
23 * @link http://www.open-emr.org
26 use OpenEMR\Services\VersionService;
28 // Making global to be accessed in subsequent function scopes
29 global $versionService;
30 $versionService = new VersionService();
32 /**
33 * Returns the current access control version.
35 * @return integer The current access control version.
37 function get_acl_version()
39 global $versionService;
40 $version = $versionService->fetch();
41 return $version->getAcl();
44 /**
45 * Records the access control version.
47 * @param integer $acl_version access control version
49 function set_acl_version($acl_version)
51 global $versionService;
52 $version = $versionService->fetch();
53 $version->setAcl($acl_version);
54 $response = $versionService->update($version);
55 return $response;
58 /**
59 * Function will return an array that contains the ACL ID number. It will also check to ensure
60 * the ACL exist and is not duplicated.
62 * @param string $title Title of group.
63 * @param string $return_value What the acl returns), usually 'write' or 'addonly'
64 * @return array An array that contains the ACL ID number.
66 function getAclIdNumber($title, $return_value)
68 global $gacl;
69 $temp_acl_id_array = $gacl->search_acl(false, false, false, false, $title, false, false, false, $return_value);
70 switch (count($temp_acl_id_array)) {
71 case 0:
72 echo "<B>ERROR</B>, '$title' group '$return_value' ACL does not exist.</BR>";
73 break;
74 case 1:
75 echo "'$title' group '$return_value' ACL is present.</BR>";
76 break;
77 default:
78 echo "<B>ERROR</B>, Multiple '$title' group '$return_value' ACLs are present.</BR>";
79 break;
82 return $temp_acl_id_array;
85 /**
86 * Function will add an ACL (if doesn't already exist).
87 * It will also place the acl in the group, or will CREATE a new group.
88 * It will return the ID number of the acl (created or old)
90 * @param string $title Title of group.
91 * @param string $name name of acl
92 * @param string $return_value What the acl returns, usually 'write' or 'addonly'
93 * @param string $note description of acl
94 * @return array ID number of the acl (created or old)
96 function addNewACL($title, $name, $return_value, $note)
98 global $gacl;
99 $temp_acl_id_array = $gacl->search_acl(false, false, false, false, $title, false, false, false, $return_value);
100 switch (count($temp_acl_id_array)) {
101 case 0:
102 $group_id = $gacl->get_group_id($name, $title, 'ARO');
103 if ($group_id) {
104 //group already exist, so just create acl
105 $temp_acl_id = $gacl->add_acl(array("placeholder"=>array("filler")), null, array($group_id), null, null, 1, 1, $return_value, $note);
106 if ($temp_acl_id) {
107 echo "The '$title' group already exist.</BR>";
108 echo "The '$title' group '$return_value' ACL has been successfully added.</BR>";
109 $temp_acl_id_array = array($temp_acl_id);
110 } else {
111 echo "The '$title' group already exist.</BR>";
112 echo "<B>ERROR</B>, Unable to create the '$title' group '$return_value' ACL.</BR>";
114 } else {
115 //create group, then create acl
116 $parent_id = $gacl->get_root_group_id();
117 $aro_id = $gacl->add_group($name, $title, $parent_id, 'ARO');
118 $temp_acl_id = $gacl->add_acl(array("placeholder"=>array("filler")), null, array($aro_id), null, null, 1, 1, $return_value, $note);
119 if ($aro_id) {
120 echo "The '$title' group has been successfully added.</BR>";
121 } else {
122 echo "<B>ERROR</B>, Unable to create the '$title' group.</BR>";
125 if ($temp_acl_id) {
126 echo "The '$title' group '$return_value' ACL has been successfully added.</BR>";
127 $temp_acl_id_array = array($temp_acl_id);
128 } else {
129 echo "<B>ERROR</B>, Unable to create the '$title' group '$return_value' ACL.</BR>";
132 break;
133 case 1:
134 echo "'$title' group '$return_value' ACL already exist.</BR>";
135 break;
137 default:
138 echo "<B>ERROR</B>, Multiple '$title' group '$return_value' ACLs are present.</BR>";
139 break;
142 return $temp_acl_id_array;
146 * Function to add an object section.
147 * It will check to ensure the object section doesn't already exist.
149 * @param string $name identifier of section
150 * @param string $title Title o object.
152 function addObjectSectionAcl($name, $title)
154 global $gacl;
155 if ($gacl->get_object_section_section_id($title, $name, 'ACO')) {
156 echo "The '$title' object section already exist.</BR>";
157 } else {
158 $tmp_boolean = $gacl->add_object_section($title, $name, 10, 0, 'ACO');
159 if ($tmp_boolean) {
160 echo "The '$title' object section has been successfully added.</BR>";
161 } else {
162 echo "<B>ERROR</B>,unable to create the '$title' object section.</BR>";
166 return;
171 * Function to add an object.
172 * It will check to ensure the object doesn't already exist.
174 * @param string $section_name Identifier of section
175 * @param string $section_title Title of section
176 * @param string $object_name Identifier of object
177 * @param string $object_title Title of object
179 function addObjectAcl($section_name, $section_title, $object_name, $object_title)
181 global $gacl;
182 if ($gacl->get_object_id($section_name, $object_name, 'ACO')) {
183 echo "The '$object_title' object in the '$section_title' section already exist.</BR>";
184 } else {
185 $tmp_boolean = $gacl->add_object($section_name, $object_title, $object_name, 10, 0, 'ACO');
186 if ($tmp_boolean) {
187 echo "The '$object_title' object in the '$section_title' section has been successfully added.</BR>";
188 } else {
189 echo "<B>ERROR</B>,unable to create the '$object_title' object in the '$section_title' section.</BR>";
193 return;
197 * Function to add an object and set the 'order' variable.
198 * It will check to ensure the object doesn't already exist.
200 * @param string $section_name Identifier of section
201 * @param string $section_title Title of section
202 * @param string $object_name Identifier of object
203 * @param string $object_title Title of object
204 * @param string $order_number number to determine order in list. used in sensitivities to order the choices in openemr
206 function addObjectAclWithOrder($section_name, $section_title, $object_name, $object_title, $order_number)
208 global $gacl;
209 if ($gacl->get_object_id($section_name, $object_name, 'ACO')) {
210 echo "The '$object_title' object in the '$section_title' section already exist.</BR>";
211 } else {
212 $tmp_boolean = $gacl->add_object($section_name, $object_title, $object_name, $order_number, 0, 'ACO');
213 if ($tmp_boolean) {
214 echo "The '$object_title' object in the '$section_title' section has been successfully added.</BR>";
215 } else {
216 echo "<B>ERROR</B>,unable to create the '$object_title' object in the '$section_title' section.</BR>";
220 return;
224 * Function to edit an object and set the 'order' variable.
225 * It will check to ensure the object doesn't already exist, and hasn't been upgraded yet.
227 * @param string $section_name Identifier of section
228 * @param string $section_title Title of section
229 * @param string $object_name Identifier of object
230 * @param string $object_title Title of object
231 * @param string $order_number number to determine order in list. used in sensitivities to order the choices in openemr
233 function editObjectAcl($section_name, $section_title, $object_name, $object_title, $order_number)
235 global $gacl;
236 $tmp_objectID = $gacl->get_object_id($section_name, $object_name, 'ACO');
237 if ($tmp_objectID) {
238 $tmp_object = $gacl->get_object_data($tmp_objectID, 'ACO');
239 if ($tmp_object[0][2] == $order_number &&
240 $tmp_object[0][0] == $section_name &&
241 $tmp_object[0][1] == $object_name &&
242 $tmp_object[0][3] == $object_title) {
243 echo "The '$object_title' object in the '$section_title' section has already been updated.</BR>";
244 } else {
245 $tmp_boolean = $gacl->edit_object($tmp_objectID, $section_name, $object_title, $object_name, $order_number, 0, 'ACO');
246 if ($tmp_boolean) {
247 echo "The '$object_title' object in the '$section_title' section has been successfully updated.</BR>";
248 } else {
249 echo "<B>ERROR</B>,unable to update the '$object_title' object in the '$section_title' section.</BR>";
252 } else {
253 echo "<B>ERROR</B>, the '$object_title' object in the '$section_title' section does not exist.</BR>";
256 return;
260 * Update the ACL.
261 * It will check to ensure the ACL hasn't already been updated.
263 * @param array $array_acl_id_number Array containing hopefully one element, which is an integer, and is identifier of acl to be updated.
264 * @param string $group_title Title of group.
265 * @param string $object_section_name Identifier of section
266 * @param string $object_section_title Title of section
267 * @param string $object_name Identifier of object
268 * @param string $object_title Title of object
269 * @param string $acl_return_value What the acl returns (string), usually 'write', 'addonly', 'wsome' or 'view'
271 function updateAcl($array_acl_id_number, $group_title, $section_name, $section_title, $object_name, $object_title, $return_value)
273 global $gacl;
274 $tmp_array = $gacl->search_acl($section_name, $object_name, false, false, $group_title, false, false, false, $return_value);
275 switch (count($tmp_array)) {
276 case 0:
277 $tmp_boolean = @$gacl->append_acl($array_acl_id_number[0], null, null, null, null, array($section_name=>array($object_name)));
278 if ($tmp_boolean) {
279 echo "Successfully placed the '$object_title' object of the '$section_title' section into the '$group_title' group '$return_value' ACL.</BR>";
280 } else {
281 echo "<B>ERROR</B>,unable to place the '$object_title' object of the '$section_title' section into the '$group_title' group '$return_value' ACL.</BR>";
283 break;
284 case 1:
285 echo "The '$object_title' object of the '$section_title' section is already found in the '$group_title' group '$return_value' ACL.</BR>";
286 break;
287 default:
288 echo "<B>ERROR</B>, Multiple '$group_title' group '$return_value' ACLs with the '$object_title' object of the '$section_title' section are present.</BR>";
289 break;
292 return;