Support for multiple submissions added. Need to work on /* */ processing for multibo...
[openemr.git] / acl_upgrade.php
blob0053b0c5e7c73534ed4f42831af856f64cf1df80
1 <?php
2 // This program is free software; you can redistribute it and/or
3 // modify it under the terms of the GNU General Public License
4 // as published by the Free Software Foundation; either version 2
5 // of the License, or (at your option) any later version.
6 //
7 // This script will update the phpGACL database, which include
8 // Access Control Objects(ACO), Groups(ARO), and Access Control
9 // Lists(ACL) created by the the acl_setup.php(2.8.1 onward)
10 // program, to the most recent version.
11 // (this assumes phpGACL has been previously installed)
12 // It will display whether each update already exist
13 // or if it was updated succesfully.
15 // Updates included:
16 // 2.8.2
17 // Section "sensitivities" (Sensitivities):
18 // normal Normal (Administrators, Physicians, Clinicians(addonly))
19 // high High (Administrators, Physicians)
20 // Section "admin" (Administration):
21 // super Superuser (Adminstrators)
22 // 2.8.4
23 // Section "admin" (Administration):
24 // drugs Pharmacy Dispensary (Administrators, Physicians, Clinicians(write))
27 //Ensure that phpGACL has been installed
28 include_once('library/acl.inc');
29 if (isset ($phpgacl_location)) {
30 include_once("$phpgacl_location/gacl_api.class.php");
31 $gacl = new gacl_api();
33 else {
34 die("You must first set up library/acl.inc to use phpGACL!");
38 //Collect the ACL ID numbers.
39 echo "<B>Checking to ensure all the proper ACL(access control list) are present:</B></BR>";
40 //Get Administrator ACL ID number
41 $admin_write = getAclIdNumber('Administrators', 'write');
42 //Get Doctor ACL ID Number
43 $doc_write = getAclIdNumber('Physicians', 'write');
44 //Get Clinician ACL with write access ID number
45 $clin_write = getAclIdNumber('Clinicians', 'write');
46 //Get Clinician ACL with addonly access ID number
47 $clin_addonly = getAclIdNumber('Clinicians', 'addonly');
48 //Get Receptionist ACL ID number
49 $front_write = getAclIdNumber('Front Office', 'write');
50 //Get Accountant ACL ID number
51 $back_write = getAclIdNumber('Accounting', 'write');
54 //Add new object Sections
55 echo "<BR/><B>Adding new object sections</B><BR/>";
56 //Add 'Sensitivities' object section (added in 2.8.2)
57 addObjectSectionAcl('sensitivities', 'Sensitivities');
60 //Add new Objects
61 echo "<BR/><B>Adding new objects</B><BR/>";
62 //Add 'Normal' sensitivity object (added in 2.8.2)
63 addObjectAcl('sensitivities', 'Sensitivities', 'normal', 'Normal');
64 //Add 'High' sensitivity object (added in 2.8.2)
65 addObjectAcl('sensitivities', 'Sensitivities', 'high', 'High');
66 //Add 'Pharmacy Dispensary' object (added in 2.8.4)
67 addObjectAcl('admin', 'Administration', 'drugs', 'Pharmacy Dispensary');
70 //Add new User Defined Groups (ARO) here
71 //(placemarker, since no new user defined groups since 2.8.1 have been added)
74 //Update the ACLs
75 echo "<BR/><B>Updating the ACLs(Access Control Lists)</B><BR/>";
76 //Insert the 'super' object from the 'admin' section into the Administrators group write ACL (added in 2.8.2)
77 updateAcl($admin_write, 'Administrators', 'admin', 'Administration', 'super', 'Superuser', 'write');
78 //Insert the 'high' object from the 'sensitivities' section into the Administrators group write ACL (added in 2.8.2)
79 updateAcl($admin_write, 'Administrators', 'sensitivities', 'Sensitivities', 'high', 'High', 'write');
80 //Insert the 'normal' object from the 'sensitivities' section into the Administrators group write ACL (added in 2.8.2)
81 updateAcl($admin_write, 'Administrators', 'sensitivities', 'Sensitivities', 'normal', 'Normal', 'write');
82 //Insert the 'high' object from the 'sensitivities' section into the Physicians group write ACL (added in 2.8.2)
83 updateAcl($doc_write, 'Physicians', 'sensitivities', 'Sensitivities', 'high', 'High', 'write');
84 //Insert the 'normal' object from the 'sensitivities' section into the Physicians group write ACL (added in 2.8.2)
85 updateAcl($doc_write, 'Physicians', 'sensitivities', 'Sensitivities', 'normal', 'Normal', 'write');
86 //Insert the 'normal' object from the 'sensitivities' section into the Clinicians group addonly ACL (added in 2.8.2)
87 updateAcl($clin_addonly, 'Clinicians', 'sensitivities', 'Sensitivities', 'normal', 'Normal', 'addonly');
88 //Insert the 'drugs' object from the 'admin' section into the Administrators group write ACL (added in 2.8.4)
89 updateAcl($admin_write, 'Administrators', 'admin', 'Administration', 'drugs', 'Pharmacy Dispensary', 'write');
90 //Insert the 'drugs' object from the 'admin' section into the Physicians group write ACL (added in 2.8.4)
91 updateAcl($doc_write, 'Physicians', 'admin', 'Administration', 'drugs', 'Pharmacy Dispensary', 'write');
92 //Insert the 'drugs' object from the 'admin' section into the Clinicians group write ACL (added in 2.8.4)
93 updateAcl($clin_write, 'Clinicians', 'admin', 'Administration', 'drugs', 'Pharmacy Dispensary', 'write');
96 //Function will return an array that contains the ACL ID number.
97 //It will also check to ensure the ACL exist and is not duplicated.
98 // $title = Title(string) of group.
99 // $return_value = What the acl returns (string), usually 'write' or 'addonly'
100 function getAclIdNumber($title, $return_value) {
101 global $gacl;
102 $temp_acl_id_array = $gacl->search_acl(FALSE, FALSE, FALSE, FALSE, $title, FALSE, FALSE, FALSE, $return_value);
103 switch (count($temp_acl_id_array)) {
104 case 0:
105 echo "<B>ERROR</B>, '$title' group '$return_value' ACL does not exist.</BR>";
106 break;
107 case 1:
108 echo "'$title' group '$return_value' ACL is present.</BR>";
109 break;
110 default:
111 echo "<B>ERROR</B>, Multiple '$title' group '$return_value' ACLs are present.</BR>";
112 break;
114 return $temp_acl_id_array;
118 //Function to add a group.
119 //This is just a placeholder function at this point, since have not added another group yet.
120 // $name = Identifier(string) of group
121 // $title = Title(string) of group
122 function addGroupAcl($name, $title) {
123 global $gacl;
124 //if add a group, then will need to add logic here
125 return;
129 //Function to add an object section.
130 //It will check to ensure the object section doesn't already exist.
131 // $name = Identifier(string) of section
132 // $title = Title(string) of object
133 function addObjectSectionAcl($name, $title) {
134 global $gacl;
135 if ($gacl->get_object_section_section_id($title, $name, 'ACO')) {
136 echo "The '$title' object section already exist.</BR>";
138 else {
139 $tmp_boolean = $gacl->add_object_section($title , $name, 10, 0, 'ACO');
140 if ($tmp_boolean) {
141 echo "The '$title' object section has been successfully added.</BR>";
143 else {
144 echo "<B>ERROR</B>,unable to create the '$title' object section.</BR>";
147 return;
151 //Function to add an object.
152 //It will check to ensure the object doesn't already exist.
153 // $section_name = Identifier(string) of section
154 // $section_title = Title(string) of section
155 // $object_name = Identifier(string) of object
156 // $object_title = Title(string) of object
157 function addObjectAcl($section_name, $section_title, $object_name, $object_title) {
158 global $gacl;
159 if ($gacl->get_object_id($section_name, $object_name, 'ACO')) {
160 echo "The '$object_title' object in the '$section_title' section already exist.</BR>";
162 else {
163 $tmp_boolean = $gacl->add_object($section_name, $object_title, $object_name, 10, 0, 'ACO');
164 if ($tmp_boolean) {
165 echo "The '$object_title' object in the '$section_title' section has been successfully added.</BR>";
167 else {
168 echo "<B>ERROR</B>,unable to create the '$object_title' object in the '$section_title' section.</BR>";
171 return;
175 //Update the ACL
176 //It will check to ensure the ACL hasn't already been updated.
177 // $array_acl_id_number = array containing hopefully one element, which is an integer, and is identifier of acl to be updated.
178 // $group_title = Title(string) of group.
179 // $object_section_name = Identifier(string) of section
180 // $object_section_title = Title(string) of section
181 // $object_name = Identifier(string) of object
182 // $object_title = Title(string) of object
183 // $acl_return_value = What the acl returns (string), usually 'write' or 'addonly'
184 function updateAcl($array_acl_id_number, $group_title, $section_name, $section_title, $object_name, $object_title, $return_value) {
185 global $gacl;
186 $tmp_array = $gacl->search_acl($section_name, $object_name, FALSE, FALSE, $group_title, FALSE, FALSE, FALSE, $return_value);
187 switch (count($tmp_array)) {
188 case 0:
189 $tmp_boolean = @$gacl->append_acl($array_acl_id_number[0], NULL, NULL, NULL, NULL, array($section_name=>array($object_name)));
190 if ($tmp_boolean){
191 echo "Successfully placed the '$object_title' object of the '$section_title' section into the '$group_title' group '$return_value' ACL.</BR>";
193 else {
194 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>";
196 break;
197 case 1:
198 echo "The '$object_title' object of the '$section_title' section is already found in the '$group_title' group '$return_value' ACL.</BR>";
199 break;
200 default:
201 echo "<B>ERROR</B>, Multiple '$group_title' group '$return_value' ACLs with the '$object_title' object of the '$section_title' section are present.</BR>";
202 break;
204 return;
207 //All done
208 echo "</BR><B>ALL DONE</B>";