5 * Functions wrapping php-GACL's functionality, to create a generic OpenEMR access control system.
7 * LICENSE: This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 3
10 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see
17 * http://www.gnu.org/licenses/licenses.html#GPL .
20 * @license http://www.gnu.org/licenses/licenses.html#GPL GNU GPL V3+
21 * @author Brady Miller <brady.g.miller@gmail.com>
22 * @author Rod Roark <rod@sunsetsystems.com>
23 * @link http://www.open-emr.org
26 // php-GACL access controls are included in OpenEMR. The below
27 // function will automatically create the path where gacl.class.php
28 // can be found. Note that this path can be manually set below
29 // for users who are using an external version of php-GACL.
30 // Also note that php-GACL access controls can be turned off
33 $phpgacl_location = dirname(__FILE__).'/../gacl';
35 // If using an external version of phpGACL, then uncomment the following
36 // line and manually place the path below. IN THIS CASE YOU MUST ALSO
37 // COMMENT OUT ABOVE $phpgacl_location ASSIGNMENT ABOVE, OR BACKUPS WILL
38 // NOT RESTORE PROPERLY!
40 //$phpgacl_location = "/var/www/gacl";
42 // If you want to turn off php-GACL, then uncomment the following line.
43 // IN THIS CASE YOU MUST ALSO COMMENT OUT ABOVE $phpgacl_location ASSIGNMENT(S)
44 // ABOVE, OR BACKUPS WILL NOT RESTORE PROPERLY!
46 //unset($phpgacl_location);
49 // The following Access Control Objects (ACO) are currently supported.
50 // These are the "things to be protected":
52 // Section "admin" (Administration):
53 // super Superuser - can delete patients, encounters, issues
54 // calendar Calendar Settings
55 // database Database Reporting
56 // forms Forms Administration
57 // practice Practice Settings
58 // superbill Superbill Codes Administration
59 // users Users/Groups/Logs Administration
60 // batchcom Batch Communication Tool
61 // language Language Interface Tool
62 // drugs Pharmacy Dispensary
63 // acl ACL Administration
64 // multipledb Multipledb
67 // Section "acct" (Accounting):
68 // bill Billing (write optional)
69 // disc Allowed to discount prices (in Fee Sheet or Checkout form)
71 // rep Financial Reporting - my encounters
72 // rep_a Financial Reporting - anything
74 // Section "patients" (Patient Information):
75 // appt Appointments (write,wsome optional)
76 // demo Demographics (write,addonly optional)
77 // med Medical Records and History (write,addonly optional)
78 // trans Transactions, e.g. referrals (write optional)
79 // docs Documents (write,addonly optional)
80 // docs_rm Documents Delete
81 // notes Patient Notes (write,addonly optional)
82 // sign Sign Lab Results (write,addonly optional)
83 // reminder Patient Reminders (write,addonly optional)
84 // alert Clinical Reminders/Alerts (write,addonly optional)
85 // disclosure Disclosures (write,addonly optional)
86 // rx Prescriptions (write,addonly optional)
87 // amendment Amendments (write,addonly optional)
88 // lab Lab Results (write,addonly optional)
90 // Section "encounters" (Encounter Information):
91 // auth Authorize - my encounters
92 // auth_a Authorize - any encounters
93 // coding Coding - my encounters (write,wsome optional)
94 // coding_a Coding - any encounters (write,wsome optional)
95 // notes Notes - my encounters (write,addonly optional)
96 // notes_a Notes - any encounters (write,addonly optional)
97 // date_a Fix encounter dates - any encounters
98 // relaxed Less-private information (write,addonly optional)
99 // (e.g. the Sports Fitness encounter form)
101 // Section "squads" applies to sports team use only:
102 // acos in this section define the user-specified list of squads
104 // Section "sensitivities" (Sensitivities):
108 // Section "lists" (Lists):
109 // default Default List (write,addonly optional)
110 // state State List (write,addonly optional)
111 // country Country List (write,addonly optional)
112 // language Language List (write,addonly optional)
113 // ethrace Ethnicity-Race List (write,addonly optional)
115 // Section "placeholder" (Placeholder):
116 // filler Placeholder (Maintains empty ACLs)
118 // Section "nationnotes" (Nation Notes):
119 // nn_configure Nation Notes
121 // Section "patientportal" (Patient Portal):
122 // portal Patient Portal
124 // Section "menus" (Menus):
127 // Section "groups" (Groups):
128 // gadd View/Add/Update groups
129 // gcalendar View/Create/Update groups appointment in calendar
130 // glog Group encounter log
131 // gdlog Group detailed log of appointment in patient record
132 // gm Send message from the permanent group therapist to the personal therapist
134 if (isset($phpgacl_location)) {
135 $GLOBALS['phpgacl_location_global'] = $phpgacl_location;
136 require_once("$phpgacl_location/gacl.class.php");
137 $gacl_object = new gacl();
138 //DO NOT CHANGE BELOW VARIABLE
139 $section_aro_value = 'users';
140 $GLOBALS['section_aro_value_global'] = $section_aro_value;
144 * Check if a user has a given type or types of access to an access control object.
146 * Globals that can use are:
147 * $GLOBALS['phpgacl_location_global']
148 * $GLOBALS['section_aro_value_global']
150 * This function will check for access to the given ACO.
151 * view - The user may view but not add or modify entries
152 * write - The user may add or modify the ACO
153 * wsome - The user has limited add/modify access to the ACO
154 * addonly - The user may view and add but not modify entries
156 * @param string $section Category of ACO
157 * @param string $value Subcategory of ACO
158 * @param string $user Optional user being checked for access.
159 * @param string|array $return_value Type or types of access being requested.
160 * @return bool|array FALSE if access is denied, TRUE if allowed. An
161 * array() of bools is returned if $return_value is an
162 * array, representing results for each type of access
165 function acl_check($section, $value, $user = '', $return_value = '')
168 $user = $_SESSION['authUser'];
171 // Superuser always gets access to everything.
172 if (($section != 'admin' || $value != 'super') && acl_check('admin', 'super', $user)) {
176 if ($GLOBALS['phpgacl_location_global']) {
177 // This will return all pertinent ACL's (including return_values and whether allow/deny)
178 // Walk through them to assess for access
180 $acl_results = $gacl_object->acl_query($section, $value, $GLOBALS['section_aro_value_global'], $user, null, null, null, null, null, true);
181 if (empty($acl_results)) {
182 return false; //deny access
184 $access=false; //flag
186 foreach ($acl_results as $acl_result) {
187 if (empty($acl_result['acl_id'])) {
188 return false; //deny access, since this happens if no pertinent ACL's are returned
190 if (is_array($return_value)) {
191 foreach ($return_value as $single_return_value) {
192 if (empty($single_return_value)) {
193 // deal with case if not looking for specific return value
194 if ($acl_result['allow']) {
199 } else { //!empty($single_return_value)
200 // deal with case if looking for specific return value
201 if ($acl_result['return_value'] == $single_return_value) {
202 if ($acl_result['allow']) {
210 } else { // $return_value is not an array (either empty or with one value)
211 if (empty($return_value)) {
212 // deal with case if not looking for specific return value
213 if ($acl_result['allow']) {
218 } else { //!empty($return_value)
219 // deal with case if looking for specific return value
220 if ($acl_result['return_value'] == $return_value) {
221 if ($acl_result['allow']) {
231 // Now decide whether user has access
232 // (Note a denial takes precedence)
233 if (!$deny && $access) {
239 // If no phpgacl, then apply the old static rules whereby "authorized"
240 // users (providers) can do anything, and other users can do most things.
241 // If you want custom access control but don't want to mess with phpGACL,
242 // then you could customize the code below instead.
244 if ($user == 'admin') {
247 if ($section == 'admin' && $value == 'super') {
250 if ($_SESSION['userauthorized']) {
254 if ($section == 'patients') {
255 if ($value == 'med') {
259 } else if ($section == 'encounters') {
260 if (strpos($value, 'coding') === 0) {
263 if (strpos($value, 'notes') === 0) {
266 if ($value == 'relaxed') {
269 } else if ($section != 'admin') {
276 // Get the ACO name/value pairs for a designated section. Each value
277 // is an array (section_value, value, order_value, name, hidden).
279 function acl_get_section_acos($section)
281 global $phpgacl_location;
282 if ($phpgacl_location) {
283 include_once("$phpgacl_location/gacl_api.class.php");
284 $gacl = new gacl_api();
285 $arr1 = $gacl->get_objects($section, 1, 'ACO');
287 if (!empty($arr1[$section])) {
288 foreach ($arr1[$section] as $value) {
289 $odata = $gacl->get_object_data($gacl->get_object_id($section, $value, 'ACO'), 'ACO');
290 $arr[$value] = $odata[0];
298 // Sort squads by their order value. Used only by acl_get_squads().
299 function _acl_squad_compare($a, $b)
301 if ($a[2] == $b[2]) {
302 // If order value is the same, sort by squad name.
303 if ($a[3] == $b[3]) {
306 return ($a[3] < $b[3]) ? -1 : 1;
308 return ($a[2] < $b[2]) ? -1 : 1;
311 // Return an array keyed on squad ACO names.
312 // This is only applicable for sports team use.
314 function acl_get_squads()
316 $squads = acl_get_section_acos('squads');
317 uasort($squads, "_acl_squad_compare");
321 // Return an array keyed on encounter sensitivity level ACO names.
322 // Sensitivities are useful when some encounter notes are not
323 // medically sensitive (e.g. a physical fitness test), and/or if
324 // some will be "for doctor's eyes only" (e.g. STD treatment).
326 // When a non-blank sensitivity value exists in the new encounter
327 // form, it names an additional ACO required for access to all forms
328 // in the encounter. If you want some encounters to be non-sensitive,
329 // then you also need some default nonblank sensitivity for normal
330 // encounters, as well as greater encounter notes permissions for
331 // those allowed to view non-sensitive encounters.
333 function acl_get_sensitivities()
335 return acl_get_section_acos('sensitivities');
339 // Returns true if aco exist
340 // Returns false if aco doesn't exist
341 // $section_name = name of section (string)
342 // $aco_name = name of aco (string)
344 function aco_exist($section_name, $aco_name)
346 global $phpgacl_location;
347 if (isset($phpgacl_location)) {
348 include_once("$phpgacl_location/gacl_api.class.php");
349 $gacl = new gacl_api();
350 $aco_id = $gacl->get_object_id($section_name, $aco_name, 'ACO');
359 // Returns a sorted array of all available Group Titles.
361 function acl_get_group_title_list()
363 global $phpgacl_location;
364 if (isset($phpgacl_location)) {
365 include_once("$phpgacl_location/gacl_api.class.php");
366 $gacl = new gacl_api();
367 $parent_id = $gacl->get_root_group_id();
368 $arr_group_ids = $gacl->get_group_children($parent_id, 'ARO', 'RECURSE');
369 $arr_group_titles = array();
370 foreach ($arr_group_ids as $value) {
371 $arr_group_data = $gacl->get_group_data($value, 'ARO');
372 $arr_group_titles[$value] = $arr_group_data[3];
374 sort($arr_group_titles);
375 return $arr_group_titles;
381 // Returns a sorted array of group Titles that a user belongs to.
382 // Returns 0 if does not belong to any group yet.
383 // $user_name = Username, which is login name.
385 function acl_get_group_titles($user_name)
387 global $phpgacl_location, $section_aro_value;
388 if (isset($phpgacl_location)) {
389 include_once("$phpgacl_location/gacl_api.class.php");
390 $gacl = new gacl_api();
391 $user_aro_id = $gacl->get_object_id($section_aro_value, $user_name, 'ARO');
393 $arr_group_id = $gacl->get_object_groups($user_aro_id, 'ARO', 'NO_RECURSE');
395 foreach ($arr_group_id as $key => $value) {
396 $arr_group_data = $gacl->get_group_data($value, 'ARO');
397 $arr_group_titles[$key] = $arr_group_data[3];
399 sort($arr_group_titles);
400 return $arr_group_titles;
408 // This will place the user aro object into selected group(s)
409 // It uses the set_user_aro() function
410 // $username = username (string)
411 // $group = title of group(s) (string or array)
413 function add_user_aros($username, $group)
415 $current_user_groups = acl_get_group_titles($username);
416 if (!$current_user_groups) {
417 $current_user_groups = array();
419 if (is_array($group)) {
420 foreach ($group as $value) {
421 if (!in_array($value, $current_user_groups)) {
422 array_push($current_user_groups, $value);
426 if (!in_array($group, $current_user_groups)) {
427 array_push($current_user_groups, $group);
430 $user_data = sqlFetchArray(sqlStatement("select * from users where username='" .
433 $current_user_groups,
443 // This will remove the user aro object from the selected group(s)
444 // It uses the set_user_aro() function
445 // $username = username (string)
446 // $group = title of group(s) (string or array)
448 function remove_user_aros($username, $group)
450 $current_user_groups = acl_get_group_titles($username);
451 $new_user_groups = array();
452 if (is_array($group)) {
453 foreach ($current_user_groups as $value) {
454 if (!in_array($value, $group)) {
455 array_push($new_user_groups, $value);
459 foreach ($current_user_groups as $value) {
460 if ($value != $group) {
461 array_push($new_user_groups, $value);
465 $user_data = sqlFetchArray(sqlStatement("select * from users where username='" .
478 // This will either create or edit a user aro object, and then place it
479 // in the requested groups. It will not allow removal of the 'admin'
480 // user or gacl_protected users from the 'admin' group.
481 // $arr_group_titles = titles of the groups that user will be added to.
482 // $user_name = username, which is login name.
483 // $first_name = first name
484 // $middle_name = middle name
485 // $last_name = last name
487 function set_user_aro($arr_group_titles, $user_name, $first_name, $middle_name, $last_name)
489 global $phpgacl_location, $section_aro_value;
491 if (isset($phpgacl_location)) {
492 include_once("$phpgacl_location/gacl_api.class.php");
493 $gacl = new gacl_api();
495 //see if this user is gacl protected (ie. do not allow
496 //removal from the Administrators group)
497 require_once(dirname(__FILE__).'/user.inc');
498 require_once(dirname(__FILE__).'/calendar.inc');
499 $userNametoID = getIDfromUser($user_name);
500 if (checkUserSetting("gacl_protect", "1", $userNametoID) || $user_name == "admin") {
501 $gacl_protect = true;
503 $gacl_protect = false;
506 //get array of all available group ID numbers
507 $parent_id = $gacl->get_root_group_id();
508 $arr_all_group_ids = $gacl->get_group_children($parent_id, 'ARO', 'RECURSE');
510 //Cycle through ID array to find and process each selected group
511 //Create a counter since processing of first hit is unique
513 foreach ($arr_all_group_ids as $value) {
514 $arr_group_data = $gacl->get_group_data($value, 'ARO');
515 if ((empty($arr_group_titles)) ||
516 (in_array($arr_group_data[3], $arr_group_titles))) {
517 //We have a hit, so need to add group and increment counter
518 // because processing of first hit is unique
519 //This will also deal with an empty $arr_group_titles array
520 // removing user from all groups unless 'admin'
521 $counter = $counter + 1;
522 //create user full name field
524 $full_name = $first_name . " " . $middle_name . " " . $last_name;
527 $full_name = $first_name . " " . $last_name;
529 $full_name = $first_name;
533 //If this is not the first group to be added, then will skip below
534 // and will be added. If this is the first group, then need to
535 // go thru several steps before adding the group.
537 //get ID of user ARO object, if it exist
538 $user_aro_id = $gacl->get_object_id($section_aro_value, $user_name, 'ARO');
540 //user ARO object already exist, so will edit it
541 $gacl->edit_object($user_aro_id, $section_aro_value, $full_name, $user_name, 10, 0, 'ARO');
543 //remove all current user ARO object group associations
544 $arr_remove_group_ids = $gacl->get_object_groups($user_aro_id, 'ARO', 'NO_RECURSE');
545 foreach ($arr_remove_group_ids as $value2) {
546 $gacl->del_group_object($value2, $section_aro_value, $user_name, 'ARO');
549 //user ARO object does not exist, so will create it
550 $gacl->add_object($section_aro_value, $full_name, $user_name, 10, 0, 'ARO');
554 //place the user ARO object in the selected group (if group(s) is selected)
555 if (!empty($arr_group_titles)) {
556 $gacl->add_group_object($value, $section_aro_value, $user_name, 'ARO');
560 //Below will not allow 'admin' or gacl_protected user to be removed from 'admin' group
564 $admin_id = $gacl->get_object_id($section_aro_value, $user_name, 'ARO');
565 $arr_admin = $gacl->get_object_groups($admin_id, 'ARO', 'NO_RECURSE');
566 foreach ($arr_admin as $value3) {
567 $arr_admin_data = $gacl->get_group_data($value3, 'ARO');
568 if (strcmp($arr_admin_data[2], 'admin') == 0) {
572 if (!$boolean_admin) {
573 foreach ($arr_all_group_ids as $value4) {
574 $arr_temp = $gacl->get_group_data($value4, 'ARO');
575 if ($arr_temp[2] == 'admin') {
576 $gacl->add_group_object($value4, $section_aro_value, $user_name, 'ARO');
582 //if array of groups was empty, then we are done, and can break from loop
583 if (empty($arr_group_titles)) {
593 // Returns true if acl exist
594 // Returns false if acl doesn't exist
595 // EITHER $title or $name is required(send FALSE in variable
596 // not being used). If both are sent, then only $title will be
598 // $return_value is required
599 // $title = title of acl (string)
600 // $name = name of acl (string)
601 // $return_value = return value of acl (string)
603 function acl_exist($title, $name, $return_value)
605 global $phpgacl_location;
606 if (isset($phpgacl_location)) {
607 include_once("$phpgacl_location/gacl_api.class.php");
608 $gacl = new gacl_api();
610 $acl = $gacl->search_acl(false, false, false, false, $title, false, false, false, $return_value);
611 } else if (!$title) {
612 $group_id = $gacl->get_group_id($name, null, 'ARO');
614 $group_data = $gacl->get_group_data($group_id, 'ARO');
615 $acl = $gacl->search_acl(false, false, false, false, $group_data[3], false, false, false, $return_value);
620 $acl = $gacl->search_acl(false, false, false, false, $title, false, false, false, $return_value);
631 // This will add a new acl and group(if group doesn't yet exist)
632 // with one aco in it.
633 // $acl_title = title of acl (string)
634 // $acl_name = name of acl (string)
635 // $return_value = return value of acl (string)
636 // $note = description of acl (array)
638 function acl_add($acl_title, $acl_name, $return_value, $note)
640 global $phpgacl_location;
641 if (isset($phpgacl_location)) {
642 include_once("$phpgacl_location/gacl_api.class.php");
643 $gacl = new gacl_api();
644 $group_id = $gacl->get_group_id($acl_name, $acl_title, 'ARO');
646 //group already exist, so just create acl
648 array("placeholder"=>array("filler")),
659 //create group, then create acl
660 $parent_id = $gacl->get_root_group_id();
661 $aro_id = $gacl->add_group($acl_name, $acl_title, $parent_id, 'ARO');
663 array("placeholder"=>array("filler")),
680 // This will remove acl. It will also remove group(if the group
681 // is no longer associated with any acl's).
682 // $acl_title = title of acl (string)
683 // $acl_name = name of acl (string)
684 // $return_value = return value of acl (string)
685 // $note = description of acl (array)
687 function acl_remove($acl_title, $return_value)
689 global $phpgacl_location;
690 if (isset($phpgacl_location)) {
691 include_once("$phpgacl_location/gacl_api.class.php");
692 $gacl = new gacl_api();
693 //First, delete the acl
694 $acl_id=$gacl->search_acl(false, false, false, false, $acl_title, false, false, false, $return_value);
695 $gacl->del_acl($acl_id[0]);
696 //Then, remove the group(if no more acl's are remaining)
697 $acl_search=$gacl->search_acl(false, false, false, false, $acl_title, false, false, false, false);
698 if (empty($acl_search)) {
699 $group_id=$gacl-> get_group_id(null, $acl_title, 'ARO');
700 $gacl->del_group($group_id, true, 'ARO');
708 // This will place the aco(s) into the selected acl
709 // $acl_title = title of acl (string)
710 // $return_value = return value of acl (string)
711 // $aco_id = id of aco (array)
713 function acl_add_acos($acl_title, $return_value, $aco_id)
715 global $phpgacl_location;
716 if (isset($phpgacl_location)) {
717 include_once("$phpgacl_location/gacl_api.class.php");
718 $gacl = new gacl_api();
719 $acl_id = $gacl->search_acl(false, false, false, false, $acl_title, false, false, false, $return_value);
720 foreach ($aco_id as $value) {
721 $aco_data = $gacl->get_object_data($value, 'ACO');
722 $aco_section = $aco_data[0][0];
723 $aco_name = $aco_data[0][1];
724 $gacl->append_acl($acl_id[0], null, null, null, null, array($aco_section=>array($aco_name)));
732 // This will remove the aco(s) from the selected acl
733 // Note if all aco's are removed, then will place the filler-placeholder
734 // into the acl to avoid complete removal of the acl.
735 // $acl_title = title of acl (string)
736 // $return_value = return value of acl (string)
737 // $aco_id = id of aco (array)
739 function acl_remove_acos($acl_title, $return_value, $aco_id)
741 global $phpgacl_location;
742 if (isset($phpgacl_location)) {
743 include_once("$phpgacl_location/gacl_api.class.php");
744 $gacl = new gacl_api();
745 $acl_id = $gacl->search_acl(false, false, false, false, $acl_title, false, false, false, $return_value);
747 // Check to see if removing all acos. If removing all acos then will
748 // ensure the filler-placeholder aco in acl to avoid complete
749 // removal of the acl.
750 if (count($aco_id) == acl_count_acos($acl_title, $return_value)) {
751 //1-get the filler-placeholder aco id
752 $filler_aco_id = $gacl->get_object_id('placeholder', 'filler', 'ACO');
753 //2-add filler-placeholder aco
754 acl_add_acos($acl_title, $return_value, array($filler_aco_id));
755 //3-ensure filler-placeholder aco is not to be deleted
756 $safeListaco = remove_element($_POST["selection"], $filler_aco_id);
757 //4-prepare to safely delete the acos
758 $aco_id = $safeListaco;
761 foreach ($aco_id as $value) {
762 $aco_data = $gacl->get_object_data($value, 'ACO');
763 $aco_section = $aco_data[0][0];
764 $aco_name = $aco_data[0][1];
765 $gacl->shift_acl($acl_id[0], null, null, null, null, array($aco_section=>array($aco_name)));
773 // This will return the number of aco objects
774 // in a specified acl.
775 // $acl_title = title of acl (string)
776 // $return_value = return value of acl (string)
778 function acl_count_acos($acl_title, $return_value)
780 global $phpgacl_location;
781 if (isset($phpgacl_location)) {
782 include_once("$phpgacl_location/gacl_api.class.php");
783 $gacl = new gacl_api();
784 $acl_id = $gacl->search_acl(false, false, false, false, $acl_title, false, false, false, $return_value);
785 $acl_data = $gacl->get_acl($acl_id[0]);
787 foreach ($acl_data['aco'] as $key => $value) {
788 $aco_count = $aco_count + count($acl_data['aco'][$key]);
796 // Function to remove an element from an array
798 function remove_element($arr, $val)
801 foreach ($arr as $value) {
802 if ($value != $val) {
803 array_push($arr2, $value);
811 * Same Functionality in the Zend Module
812 * for ACL Check in Zend
813 * Path openemr/interface/modules/zend_modules/module/Application/src/Application/Model/ApplicationTable
814 * Function Name zAclCheck
816 * @param String $user_id Auth user Id
817 * $param String $section_identifier ACL Section id
820 function zh_acl_check($user_id, $section_identifier)
822 $sql_user_acl = " SELECT
823 COUNT(allowed) AS count
825 module_acl_user_settings AS usr_settings
826 LEFT JOIN module_acl_sections AS acl_sections
827 ON usr_settings.section_id = acl_sections.`section_id`
829 acl_sections.section_identifier = ? AND usr_settings.user_id = ? AND usr_settings.allowed = ?";
830 $sql_user_group = " SELECT
834 LEFT JOIN `gacl_groups_aro_map` AS gamp
835 ON garo.id = gamp.aro_id
836 LEFT JOIN `gacl_aro_groups` AS gagp
837 ON gagp.id = gamp.group_id
838 RIGHT JOIN `users_secure` usr
839 ON usr. username = garo.value
841 garo.section_value = ? AND usr. id = ?";
842 $res_groups = sqlStatement($sql_user_group, array('users',$user_id));
844 // Prepare the group queries with the placemakers and binding array for the IN part
845 $groups_sql_param = array();
846 $groupPlacemakers = "";
848 while ($row = sqlFetchArray($res_groups)) {
849 array_push($groups_sql_param, $row['group_id']);
851 $groupPlacemakers = "?";
854 $groupPlacemakers .= ",?";
857 $sql_group_acl_base = " SELECT
858 COUNT(allowed) AS count
860 module_acl_group_settings AS group_settings
861 LEFT JOIN module_acl_sections AS acl_sections
862 ON group_settings.section_id = acl_sections.section_id
864 group_settings.group_id IN (".$groupPlacemakers.") AND acl_sections.`section_identifier` = ? ";
866 $sql_group_acl_allowed = $sql_group_acl_base . " AND group_settings.allowed = '1'";
868 // Complete the group queries sql binding array
869 array_push($groups_sql_param, $section_identifier);
871 $count_group_allowed = 0;
872 $count_user_allowed = 0;
874 $res_user_allowed = sqlQuery($sql_user_acl, array($section_identifier,$user_id,1));
875 $count_user_allowed = $res_user_allowed['count'];
877 $res_group_allowed = sqlQuery($sql_group_acl_allowed, $groups_sql_param);
878 $count_group_allowed = $res_group_allowed['count'];
880 if ($count_user_allowed > 0) {
882 } elseif ($count_group_allowed > 0) {
889 // This generates an HTML options list for all ACOs.
890 // The caller inserts this between <select> and </select> tags.
892 function gen_aco_html_options($default = '')
894 $acoArray = gen_aco_array();
896 foreach ($acoArray as $section => $acos_array) {
897 $s .= "<optgroup label='" . xla($section) . "'>\n";
898 foreach ($acos_array as $aco_array) {
899 $s .= "<option value='" . attr($aco_array['value']) . "'";
900 if ($aco_array['value'] == $default) {
903 $s .= ">" . xlt($aco_array['name']) . "</option>";
911 // Returns array of all ACOs
912 function gen_aco_array()
914 global $phpgacl_location;
915 require_once("$phpgacl_location/gacl_api.class.php");
917 $gacl = new gacl_api();
918 // collect and sort all aco objects
919 $list_aco_objects = $gacl->get_objects(null, 0, 'ACO');
920 ksort($list_aco_objects);
921 foreach ($list_aco_objects as $seckey => $dummy) {
925 asort($list_aco_objects[$seckey]);
926 $aco_section_data = $gacl->get_section_data($seckey, 'ACO');
927 $aco_section_title = $aco_section_data[3];
928 foreach ($list_aco_objects[$seckey] as $acokey) {
929 $aco_id = $gacl->get_object_id($seckey, $acokey, 'ACO');
930 $aco_data = $gacl->get_object_data($aco_id, 'ACO');
931 $aco_title = $aco_data[0][3];
932 $optkey = "$seckey|$acokey";
933 $acoArray[$aco_section_title][$aco_id]['name'] = $aco_title;
934 $acoArray[$aco_section_title][$aco_id]['value'] = $optkey;
941 // Permissions check for an ACO in "section|aco" format.
942 // Note $return_value may be an array of return values.
944 function acl_check_aco_spec($aco_spec, $user = '', $return_value = '')
946 if (empty($aco_spec)) {
949 $tmp = explode('|', $aco_spec);
950 if (!is_array($return_value)) {
951 $return_value = array($return_value);
953 foreach ($return_value as $rv) {
954 if (acl_check($tmp[0], $tmp[1], $user, $rv)) {
961 // Permissions check for a specified encounter form type.
962 // Note $return_value may be an array of return values.
964 function acl_check_form($formdir, $user = '', $return_value = '')
966 require_once(dirname(__FILE__) . '/registry.inc');
967 $tmp = getRegistryEntryByDirectory($formdir, 'aco_spec');
968 return acl_check_aco_spec($tmp['aco_spec'], $user, $return_value);
971 // Permissions check for a specified issue type.
972 // Note $return_value may be an array of return values.
974 function acl_check_issue($type, $user = '', $return_value = '')
976 require_once(dirname(__FILE__) . '/lists.inc');
978 if (empty($ISSUE_TYPES[$type][5])) {
981 return acl_check_aco_spec($ISSUE_TYPES[$type][5], $user, $return_value);
984 // Permissions check for a specified document category name.
985 // Note $return_value may be an array of return values.
987 function acl_check_cat_name($catname, $user = '', $return_value = '')
990 "SELECT aco_spec FROM categories WHERE name = ? ORDER BY id LIMIT 1",
993 if (empty($tmp['aco_spec'])) {
996 return acl_check_aco_spec($tmp['aco_spec'], $user, $return_value);
999 //Fetches aco for given postcalendar category
1000 function fetchPostCalendarCategoryACO($pc_catid)
1003 "SELECT aco_spec FROM openemr_postcalendar_categories WHERE pc_catid = ? LIMIT 1",
1006 return $aco['aco_spec'];