minor improvement to tabs style
[openemr.git] / library / acl_upgrade_fx.php
blob21bd9bf110f193806f0750b57445a43fb8601c58
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 // Making global to be accessed in subsequent function scopes
27 global $versionService;
28 $versionService = new \services\VersionService();
30 /**
31 * Returns the current access control version.
33 * @return integer The current access control version.
35 function get_acl_version() {
36 global $versionService;
37 $version = $versionService->fetch();
38 return $version->getAcl();
41 /**
42 * Records the access control version.
44 * @param integer $acl_version access control version
46 function set_acl_version($acl_version) {
47 global $versionService;
48 $version = $versionService->fetch();
49 $version->setAcl($acl_version);
50 $response = $versionService->update($version);
51 return $response;
54 /**
55 * Function will return an array that contains the ACL ID number. It will also check to ensure
56 * the ACL exist and is not duplicated.
58 * @param string $title Title of group.
59 * @param string $return_value What the acl returns), usually 'write' or 'addonly'
60 * @return array An array that contains the ACL ID number.
62 function getAclIdNumber($title, $return_value) {
63 global $gacl;
64 $temp_acl_id_array = $gacl->search_acl(FALSE, FALSE, FALSE, FALSE, $title, FALSE, FALSE, FALSE, $return_value);
65 switch (count($temp_acl_id_array)) {
66 case 0:
67 echo "<B>ERROR</B>, '$title' group '$return_value' ACL does not exist.</BR>";
68 break;
69 case 1:
70 echo "'$title' group '$return_value' ACL is present.</BR>";
71 break;
72 default:
73 echo "<B>ERROR</B>, Multiple '$title' group '$return_value' ACLs are present.</BR>";
74 break;
76 return $temp_acl_id_array;
79 /**
80 * Function will add an ACL (if doesn't already exist).
81 * It will also place the acl in the group, or will CREATE a new group.
82 * It will return the ID number of the acl (created or old)
84 * @param string $title Title of group.
85 * @param string $name name of acl
86 * @param string $return_value What the acl returns, usually 'write' or 'addonly'
87 * @param string $note description of acl
88 * @return array ID number of the acl (created or old)
90 function addNewACL($title, $name, $return_value, $note) {
91 global $gacl;
92 $temp_acl_id_array = $gacl->search_acl(FALSE, FALSE, FALSE, FALSE, $title, FALSE, FALSE, FALSE, $return_value);
93 switch (count($temp_acl_id_array)) {
94 case 0:
95 $group_id = $gacl->get_group_id($name, $title, 'ARO');
96 if ($group_id) {
97 //group already exist, so just create acl
98 $temp_acl_id = $gacl->add_acl(array("placeholder"=>array("filler")), NULL, array($group_id), NULL, NULL, 1, 1, $return_value, $note);
99 if ($temp_acl_id) {
100 echo "The '$title' group already exist.</BR>";
101 echo "The '$title' group '$return_value' ACL has been successfully added.</BR>";
102 $temp_acl_id_array = array($temp_acl_id);
104 else {
105 echo "The '$title' group already exist.</BR>";
106 echo "<B>ERROR</B>, Unable to create the '$title' group '$return_value' ACL.</BR>";
109 else {
110 //create group, then create acl
111 $parent_id = $gacl->get_root_group_id();
112 $aro_id = $gacl->add_group($name, $title, $parent_id, 'ARO');
113 $temp_acl_id = $gacl->add_acl(array("placeholder"=>array("filler")), NULL, array($aro_id), NULL, NULL, 1, 1, $return_value, $note);
114 if ($aro_id ) {
115 echo "The '$title' group has been successfully added.</BR>";
117 else {
118 echo "<B>ERROR</B>, Unable to create the '$title' group.</BR>";
120 if ($temp_acl_id) {
121 echo "The '$title' group '$return_value' ACL has been successfully added.</BR>";
122 $temp_acl_id_array = array($temp_acl_id);
124 else {
125 echo "<B>ERROR</B>, Unable to create the '$title' group '$return_value' ACL.</BR>";
128 break;
129 case 1:
130 echo "'$title' group '$return_value' ACL already exist.</BR>";
131 break;
133 default:
134 echo "<B>ERROR</B>, Multiple '$title' group '$return_value' ACLs are present.</BR>";
135 break;
137 return $temp_acl_id_array;
141 * Function to add an object section.
142 * It will check to ensure the object section doesn't already exist.
144 * @param string $name identifier of section
145 * @param string $title Title o object.
147 function addObjectSectionAcl($name, $title) {
148 global $gacl;
149 if ($gacl->get_object_section_section_id($title, $name, 'ACO')) {
150 echo "The '$title' object section already exist.</BR>";
152 else {
153 $tmp_boolean = $gacl->add_object_section($title , $name, 10, 0, 'ACO');
154 if ($tmp_boolean) {
155 echo "The '$title' object section has been successfully added.</BR>";
157 else {
158 echo "<B>ERROR</B>,unable to create the '$title' object section.</BR>";
161 return;
166 * Function to add an object.
167 * It will check to ensure the object doesn't already exist.
169 * @param string $section_name Identifier of section
170 * @param string $section_title Title of section
171 * @param string $object_name Identifier of object
172 * @param string $object_title Title of object
174 function addObjectAcl($section_name, $section_title, $object_name, $object_title) {
175 global $gacl;
176 if ($gacl->get_object_id($section_name, $object_name, 'ACO')) {
177 echo "The '$object_title' object in the '$section_title' section already exist.</BR>";
179 else {
180 $tmp_boolean = $gacl->add_object($section_name, $object_title, $object_name, 10, 0, 'ACO');
181 if ($tmp_boolean) {
182 echo "The '$object_title' object in the '$section_title' section has been successfully added.</BR>";
184 else {
185 echo "<B>ERROR</B>,unable to create the '$object_title' object in the '$section_title' section.</BR>";
188 return;
192 * Function to add an object and set the 'order' variable.
193 * It will check to ensure the object doesn't already exist.
195 * @param string $section_name Identifier of section
196 * @param string $section_title Title of section
197 * @param string $object_name Identifier of object
198 * @param string $object_title Title of object
199 * @param string $order_number number to determine order in list. used in sensitivities to order the choices in openemr
201 function addObjectAclWithOrder($section_name, $section_title, $object_name, $object_title, $order_number) {
202 global $gacl;
203 if ($gacl->get_object_id($section_name, $object_name, 'ACO')) {
204 echo "The '$object_title' object in the '$section_title' section already exist.</BR>";
206 else {
207 $tmp_boolean = $gacl->add_object($section_name, $object_title, $object_name, $order_number, 0, 'ACO');
208 if ($tmp_boolean) {
209 echo "The '$object_title' object in the '$section_title' section has been successfully added.</BR>";
211 else {
212 echo "<B>ERROR</B>,unable to create the '$object_title' object in the '$section_title' section.</BR>";
215 return;
219 * Function to edit an object and set the 'order' variable.
220 * It will check to ensure the object doesn't already exist, and hasn't been upgraded yet.
222 * @param string $section_name Identifier of section
223 * @param string $section_title Title of section
224 * @param string $object_name Identifier of object
225 * @param string $object_title Title of object
226 * @param string $order_number number to determine order in list. used in sensitivities to order the choices in openemr
228 function editObjectAcl($section_name, $section_title, $object_name, $object_title, $order_number) {
229 global $gacl;
230 $tmp_objectID = $gacl->get_object_id($section_name, $object_name, 'ACO');
231 if ($tmp_objectID) {
232 $tmp_object = $gacl->get_object_data($tmp_objectID, 'ACO');
233 if ($tmp_object[0][2] == $order_number &&
234 $tmp_object[0][0] == $section_name &&
235 $tmp_object[0][1] == $object_name &&
236 $tmp_object[0][3] == $object_title) {
237 echo "The '$object_title' object in the '$section_title' section has already been updated.</BR>";
239 else {
240 $tmp_boolean = $gacl->edit_object($tmp_objectID, $section_name, $object_title, $object_name, $order_number, 0, 'ACO');
241 if ($tmp_boolean) {
242 echo "The '$object_title' object in the '$section_title' section has been successfully updated.</BR>";
244 else {
245 echo "<B>ERROR</B>,unable to update the '$object_title' object in the '$section_title' section.</BR>";
249 else {
250 echo "<B>ERROR</B>, the '$object_title' object in the '$section_title' section does not exist.</BR>";
252 return;
256 * Update the ACL.
257 * It will check to ensure the ACL hasn't already been updated.
259 * @param array $array_acl_id_number Array containing hopefully one element, which is an integer, and is identifier of acl to be updated.
260 * @param string $group_title Title of group.
261 * @param string $object_section_name Identifier of section
262 * @param string $object_section_title Title of section
263 * @param string $object_name Identifier of object
264 * @param string $object_title Title of object
265 * @param string $acl_return_value What the acl returns (string), usually 'write', 'addonly', 'wsome' or 'view'
267 function updateAcl($array_acl_id_number, $group_title, $section_name, $section_title, $object_name, $object_title, $return_value) {
268 global $gacl;
269 $tmp_array = $gacl->search_acl($section_name, $object_name, FALSE, FALSE, $group_title, FALSE, FALSE, FALSE, $return_value);
270 switch (count($tmp_array)) {
271 case 0:
272 $tmp_boolean = @$gacl->append_acl($array_acl_id_number[0], NULL, NULL, NULL, NULL, array($section_name=>array($object_name)));
273 if ($tmp_boolean){
274 echo "Successfully placed the '$object_title' object of the '$section_title' section into the '$group_title' group '$return_value' ACL.</BR>";
276 else {
277 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>";
279 break;
280 case 1:
281 echo "The '$object_title' object of the '$section_title' section is already found in the '$group_title' group '$return_value' ACL.</BR>";
282 break;
283 default:
284 echo "<B>ERROR</B>, Multiple '$group_title' group '$return_value' ACLs with the '$object_title' object of the '$section_title' section are present.</BR>";
285 break;
287 return;