fixed sql date comparison to be pre-4.1 compatible
[openemr.git] / phpgacl_upgrade_1.php
blob9db98f68d7ca262aa68bcece7797052bd473630f
1 <?php
2 //Upgrade OpenEMR phpgacl ACLs from 2.8.1 to 2.8.2/2.8.3
3 //author: Brady Miller
4 //email: brady@sparmy.com
5 //version 1
6 //Use at your own risk.
9 //Ensure that phpGACL has been installed
10 include_once('library/acl.inc');
11 if (isset ($phpgacl_location)) {
12 include_once("$phpgacl_location/gacl_api.class.php");
13 $gacl = new gacl_api();
15 else {
16 die("You must first set up library/acl.inc to use phpGACL!");
20 //Collect the ACL ID numbers.
21 echo "<B>Checking to ensure all the proper ACL(access control list) are present:</B></BR>";
22 //Get Administrator ACL ID number
23 $admin_write = getAclIdNumber('Administrators', 'write');
24 //Get Doctor ACL ID Number
25 $doc_write = getAclIdNumber('Physicians', 'write');
26 //Get Clinician ACL with write access ID number
27 $clin_write = getAclIdNumber('Clinicians', 'write');
28 //Get Clinician ACL with addonly access ID number
29 $clin_addonly = getAclIdNumber('Clinicians', 'addonly');
30 //Get Receptionist ACL ID number
31 $front_write = getAclIdNumber('Front Office', 'write');
32 //Get Accountant ACL ID number
33 $back_write = getAclIdNumber('Accounting', 'write');
36 //Add new User Defined Groups here(placemarker, since no new user defined groups since 2.8.1 have been added)
39 //Add new object Sections
40 echo "<BR/><B>Adding new object sections</B><BR/>";
41 //Add 'Sensitivities' object section (added in 2.8.2)
42 addObjectSectionAcl('sensitivities', 'Sensitivities');
45 //Add new Objects
46 echo "<BR/><B>Adding new objects</B><BR/>";
47 //Add 'Normal' sensitivity object (added in 2.8.2)
48 addObjectAcl('sensitivities', 'Sensitivities', 'normal', 'Normal');
49 //Add 'High' sensitivity object (added in 2.8.2)
50 addObjectAcl('sensitivities', 'Sensitivities', 'high', 'High');
51 //Add 'Pharmacy Dispensary' object (added in 2.8.4)
52 addObjectAcl('admin', 'Administration', 'drugs', 'Pharmacy Dispensary');
55 //Update the ACLs
56 echo "<BR/><B>Updating the ACLs(Access Control Lists)</B><BR/>";
57 //Insert the 'super' object from the 'admin' section into the Administrators group write ACL (added in 2.8.2)
58 updateAcl($admin_write, 'Administrators', 'admin', 'Administration', 'super', 'Superuser', 'write');
59 //Insert the 'high' object from the 'sensitivities' section into the Administrators group write ACL (added in 2.8.2)
60 updateAcl($admin_write, 'Administrators', 'sensitivities', 'Sensitivities', 'high', 'High', 'write');
61 //Insert the 'normal' object from the 'sensitivities' section into the Administrators group write ACL (added in 2.8.2)
62 updateAcl($admin_write, 'Administrators', 'sensitivities', 'Sensitivities', 'normal', 'Normal', 'write');
63 //Insert the 'high' object from the 'sensitivities' section into the Physicians group write ACL (added in 2.8.2)
64 updateAcl($doc_write, 'Physicians', 'sensitivities', 'Sensitivities', 'high', 'High', 'write');
65 //Insert the 'normal' object from the 'sensitivities' section into the Physicians group write ACL (added in 2.8.2)
66 updateAcl($doc_write, 'Physicians', 'sensitivities', 'Sensitivities', 'normal', 'Normal', 'write');
67 //Insert the 'normal' object from the 'sensitivities' section into the Clinicians group addonly ACL (added in 2.8.2)
68 updateAcl($clin_addonly, 'Clinicians', 'sensitivities', 'Sensitivities', 'normal', 'Normal', 'addonly');
69 //Insert the 'drugs' object from the 'admin' section into the Administrators group write ACL (added in 2.8.4)
70 updateAcl($admin_write, 'Administrators', 'admin', 'Administration', 'drugs', 'Pharmacy Dispensary', 'write');
71 //Insert the 'drugs' object from the 'admin' section into the Physicians group write ACL (added in 2.8.4)
72 updateAcl($doc_write, 'Physicians', 'admin', 'Administration', 'drugs', 'Pharmacy Dispensary', 'write');
73 //Insert the 'drugs' object from the 'admin' section into the Clinicians group write ACL (added in 2.8.4)
74 updateAcl($clin_write, 'Clinicians', 'admin', 'Administration', 'drugs', 'Pharmacy Dispensary', 'write');
77 //Function will return an array that contains the ACL ID number.
78 //It will also check to ensure the ACL exist and is not duplicated.
79 // $title = Title(string) of group.
80 // $return_value = What the acl returns (string), usually 'write' or 'addonly'
81 function getAclIdNumber($title, $return_value) {
82 global $gacl;
83 $temp_acl_id_array = $gacl->search_acl(FALSE, FALSE, FALSE, FALSE, $title, FALSE, FALSE, FALSE, $return_value);
84 switch (count($temp_acl_id_array)) {
85 case 0:
86 echo "<B>ERROR</B>, '$title' group '$return_value' ACL does not exist.</BR>";
87 break;
88 case 1:
89 echo "'$title' group '$return_value' ACL is present.</BR>";
90 break;
91 default:
92 echo "<B>ERROR</B>, Multiple '$title' group '$return_value' ACLs are present.</BR>";
93 break;
95 return $temp_acl_id_array;
99 //Function to add a group.
100 //This is just a placeholder function at this point, since have not added another group yet.
101 // $name = Identifier(string) of group
102 // $title = Title(string) of group
103 function addGroupAcl($name, $title) {
104 global $gacl;
105 return;
109 //Function to add an object section.
110 //It will check to ensure the object section doesn't already exist.
111 // $name = Identifier(string) of section
112 // $title = Title(string) of object
113 function addObjectSectionAcl($name, $title) {
114 global $gacl;
115 if ($gacl->get_object_section_section_id($title, $name, 'ACO')) {
116 echo "The '$title' object section already exist.</BR>";
118 else {
119 $tmp_boolean = $gacl->add_object_section($title , $name, 10, 0, 'ACO');
120 if ($tmp_boolean) {
121 echo "The '$title' object section has been successfully added.</BR>";
123 else {
124 echo "<B>ERROR</B>,unable to create the '$title' object section.</BR>";
127 return;
131 //Function to add an object.
132 //It will check to ensure the object doesn't already exist.
133 // $section_name = Identifier(string) of section
134 // $section_title = Title(string) of section
135 // $object_name = Identifier(string) of object
136 // $object_title = Title(string) of object
137 function addObjectAcl($section_name, $section_title, $object_name, $object_title) {
138 global $gacl;
139 if ($gacl->get_object_id($section_name, $object_name, 'ACO')) {
140 echo "The '$object_title' object in the '$section_title' section already exist.</BR>";
142 else {
143 $tmp_boolean = $gacl->add_object($section_name, $object_title, $object_name, 10, 0, 'ACO');
144 if ($tmp_boolean) {
145 echo "The '$object_title' object in the '$section_title' section has been successfully added.</BR>";
147 else {
148 echo "<B>ERROR</B>,unable to create the '$object_title' object in the '$section_title' section.</BR>";
151 return;
155 //Update the ACL
156 //It will check to ensure the ACL hasn't already been updated.
157 // $array_acl_id_number = array containing hopefully one element, which is an integer, and is identifier of acl to be updated.
158 // $group_title = Title(string) of group.
159 // $object_section_name = Identifier(string) of section
160 // $object_section_title = Title(string) of section
161 // $object_name = Identifier(string) of object
162 // $object_title = Title(string) of object
163 // $acl_return_value = What the acl returns (string), usually 'write' or 'addonly'
164 function updateAcl($array_acl_id_number, $group_title, $section_name, $section_title, $object_name, $object_title, $return_value) {
165 global $gacl;
166 $tmp_array = $gacl->search_acl($section_name, $object_name, FALSE, FALSE, $group_title, FALSE, FALSE, FALSE, $return_value);
167 switch (count($tmp_array)) {
168 case 0:
169 $tmp_boolean = @$gacl->append_acl($array_acl_id_number[0], NULL, NULL, NULL, NULL, array($section_name=>array($object_name)));
170 if ($tmp_boolean){
171 echo "Successfully placed the '$object_title' object of the '$section_title' section into the '$group_title' group '$return_value' ACL.</BR>";
173 else {
174 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>";
176 break;
177 case 1:
178 echo "The '$object_title' object of the '$section_title' section is already found in the '$group_title' group '$return_value' ACL.</BR>";
179 break;
180 default:
181 echo "<B>ERROR</B>, Multiple '$group_title' group '$return_value' ACLs with the '$object_title' object of the '$section_title' section are present.</BR>";
182 break;
184 return;
187 //All done
188 echo "</BR><B>ALL DONE</B>";