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 // notes Patient Notes (write,addonly optional)
81 // sign Sign Lab Results (write,addonly optional)
82 // reminder Patient Reminders (write,addonly optional)
83 // alert Clinical Reminders/Alerts (write,addonly optional)
84 // disclosure Disclosures (write,addonly optional)
85 // rx Prescriptions (write,addonly optional)
86 // amendment Amendments (write,addonly optional)
87 // lab Lab Results (write,addonly optional)
89 // Section "encounters" (Encounter Information):
90 // auth Authorize - my encounters
91 // auth_a Authorize - any encounters
92 // coding Coding - my encounters (write,wsome optional)
93 // coding_a Coding - any encounters (write,wsome optional)
94 // notes Notes - my encounters (write,addonly optional)
95 // notes_a Notes - any encounters (write,addonly optional)
96 // date_a Fix encounter dates - any encounters
97 // relaxed Less-private information (write,addonly optional)
98 // (e.g. the Sports Fitness encounter form)
100 // Section "squads" applies to sports team use only:
101 // acos in this section define the user-specified list of squads
103 // Section "sensitivities" (Sensitivities):
107 // Section "lists" (Lists):
108 // default Default List (write,addonly optional)
109 // state State List (write,addonly optional)
110 // country Country List (write,addonly optional)
111 // language Language List (write,addonly optional)
112 // ethrace Ethnicity-Race List (write,addonly optional)
114 // Section "placeholder" (Placeholder):
115 // filler Placeholder (Maintains empty ACLs)
117 // Section "nationnotes" (Nation Notes):
118 // nn_configure Nation Notes
120 // Section "patientportal" (Patient Portal):
121 // portal Patient Portal
123 // Section "menus" (Menus):
126 // Section "groups" (Groups):
127 // gadd View/Add/Update groups
128 // gcalendar View/Create/Update groups appointment in calendar
129 // glog Group encounter log
130 // gdlog Group detailed log of appointment in patient record
131 // gm Send message from the permanent group therapist to the personal therapist
133 if (isset($phpgacl_location)) {
134 $GLOBALS['phpgacl_location_global'] = $phpgacl_location;
135 require_once("$phpgacl_location/gacl.class.php");
136 $gacl_object = new gacl();
137 //DO NOT CHANGE BELOW VARIABLE
138 $section_aro_value = 'users';
139 $GLOBALS['section_aro_value_global'] = $section_aro_value;
143 * Check if a user has a given type or types of access to an access control object.
145 * Globals that can use are:
146 * $GLOBALS['phpgacl_location_global']
147 * $GLOBALS['section_aro_value_global']
149 * This function will check for access to the given ACO.
150 * view - The user may view but not add or modify entries
151 * write - The user may add or modify the ACO
152 * wsome - The user has limited add/modify access to the ACO
153 * addonly - The user may view and add but not modify entries
155 * @param string $section Category of ACO
156 * @param string $value Subcategory of ACO
157 * @param string $user Optional user being checked for access.
158 * @param string|array $return_value Type or types of access being requested.
159 * @return bool|array FALSE if access is denied, TRUE if allowed. An
160 * array() of bools is returned if $return_value is an
161 * array, representing results for each type of access
164 function acl_check($section, $value, $user = '', $return_value = '')
167 $user = $_SESSION['authUser'];
170 // Superuser always gets access to everything.
171 if (($section != 'admin' || $value != 'super') && acl_check('admin', 'super', $user)) {
175 if ($GLOBALS['phpgacl_location_global']) {
176 // This will return all pertinent ACL's (including return_values and whether allow/deny)
177 // Walk through them to assess for access
179 $acl_results = $gacl_object->acl_query($section, $value, $GLOBALS['section_aro_value_global'], $user, null, null, null, null, null, true);
180 if (empty($acl_results)) {
181 return false; //deny access
183 $access=false; //flag
185 foreach ($acl_results as $acl_result) {
186 if (empty($acl_result['acl_id'])) {
187 return false; //deny access, since this happens if no pertinent ACL's are returned
189 if (is_array($return_value)) {
190 foreach ($return_value as $single_return_value) {
191 if (empty($single_return_value)) {
192 // deal with case if not looking for specific return value
193 if ($acl_result['allow']) {
198 } else { //!empty($single_return_value)
199 // deal with case if looking for specific return value
200 if ($acl_result['return_value'] == $single_return_value) {
201 if ($acl_result['allow']) {
209 } else { // $return_value is not an array (either empty or with one value)
210 if (empty($return_value)) {
211 // deal with case if not looking for specific return value
212 if ($acl_result['allow']) {
217 } else { //!empty($return_value)
218 // deal with case if looking for specific return value
219 if ($acl_result['return_value'] == $return_value) {
220 if ($acl_result['allow']) {
230 // Now decide whether user has access
231 // (Note a denial takes precedence)
232 if (!$deny && $access) {
238 // If no phpgacl, then apply the old static rules whereby "authorized"
239 // users (providers) can do anything, and other users can do most things.
240 // If you want custom access control but don't want to mess with phpGACL,
241 // then you could customize the code below instead.
243 if ($user == 'admin') {
246 if ($section == 'admin' && $value == 'super') {
249 if ($_SESSION['userauthorized']) {
253 if ($section == 'patients') {
254 if ($value == 'med') {
258 } else if ($section == 'encounters') {
259 if (strpos($value, 'coding') === 0) {
262 if (strpos($value, 'notes') === 0) {
265 if ($value == 'relaxed') {
268 } else if ($section != 'admin') {
275 // Get the ACO name/value pairs for a designated section. Each value
276 // is an array (section_value, value, order_value, name, hidden).
278 function acl_get_section_acos($section)
280 global $phpgacl_location;
281 if ($phpgacl_location) {
282 include_once("$phpgacl_location/gacl_api.class.php");
283 $gacl = new gacl_api();
284 $arr1 = $gacl->get_objects($section, 1, 'ACO');
286 if (!empty($arr1[$section])) {
287 foreach ($arr1[$section] as $value) {
288 $odata = $gacl->get_object_data($gacl->get_object_id($section, $value, 'ACO'), 'ACO');
289 $arr[$value] = $odata[0];
297 // Sort squads by their order value. Used only by acl_get_squads().
298 function _acl_squad_compare($a, $b)
300 if ($a[2] == $b[2]) {
301 // If order value is the same, sort by squad name.
302 if ($a[3] == $b[3]) {
305 return ($a[3] < $b[3]) ? -1 : 1;
307 return ($a[2] < $b[2]) ? -1 : 1;
310 // Return an array keyed on squad ACO names.
311 // This is only applicable for sports team use.
313 function acl_get_squads()
315 $squads = acl_get_section_acos('squads');
316 uasort($squads, "_acl_squad_compare");
320 // Return an array keyed on encounter sensitivity level ACO names.
321 // Sensitivities are useful when some encounter notes are not
322 // medically sensitive (e.g. a physical fitness test), and/or if
323 // some will be "for doctor's eyes only" (e.g. STD treatment).
325 // When a non-blank sensitivity value exists in the new encounter
326 // form, it names an additional ACO required for access to all forms
327 // in the encounter. If you want some encounters to be non-sensitive,
328 // then you also need some default nonblank sensitivity for normal
329 // encounters, as well as greater encounter notes permissions for
330 // those allowed to view non-sensitive encounters.
332 function acl_get_sensitivities()
334 return acl_get_section_acos('sensitivities');
338 // Returns true if aco exist
339 // Returns false if aco doesn't exist
340 // $section_name = name of section (string)
341 // $aco_name = name of aco (string)
343 function aco_exist($section_name, $aco_name)
345 global $phpgacl_location;
346 if (isset($phpgacl_location)) {
347 include_once("$phpgacl_location/gacl_api.class.php");
348 $gacl = new gacl_api();
349 $aco_id = $gacl->get_object_id($section_name, $aco_name, 'ACO');
358 // Returns a sorted array of all available Group Titles.
360 function acl_get_group_title_list()
362 global $phpgacl_location;
363 if (isset($phpgacl_location)) {
364 include_once("$phpgacl_location/gacl_api.class.php");
365 $gacl = new gacl_api();
366 $parent_id = $gacl->get_root_group_id();
367 $arr_group_ids = $gacl->get_group_children($parent_id, 'ARO', 'RECURSE');
368 $arr_group_titles = array();
369 foreach ($arr_group_ids as $value) {
370 $arr_group_data = $gacl->get_group_data($value, 'ARO');
371 $arr_group_titles[$value] = $arr_group_data[3];
373 sort($arr_group_titles);
374 return $arr_group_titles;
380 // Returns a sorted array of group Titles that a user belongs to.
381 // Returns 0 if does not belong to any group yet.
382 // $user_name = Username, which is login name.
384 function acl_get_group_titles($user_name)
386 global $phpgacl_location, $section_aro_value;
387 if (isset($phpgacl_location)) {
388 include_once("$phpgacl_location/gacl_api.class.php");
389 $gacl = new gacl_api();
390 $user_aro_id = $gacl->get_object_id($section_aro_value, $user_name, 'ARO');
392 $arr_group_id = $gacl->get_object_groups($user_aro_id, 'ARO', 'NO_RECURSE');
394 foreach ($arr_group_id as $key => $value) {
395 $arr_group_data = $gacl->get_group_data($value, 'ARO');
396 $arr_group_titles[$key] = $arr_group_data[3];
398 sort($arr_group_titles);
399 return $arr_group_titles;
407 // This will place the user aro object into selected group(s)
408 // It uses the set_user_aro() function
409 // $username = username (string)
410 // $group = title of group(s) (string or array)
412 function add_user_aros($username, $group)
414 $current_user_groups = acl_get_group_titles($username);
415 if (!$current_user_groups) {
416 $current_user_groups = array();
418 if (is_array($group)) {
419 foreach ($group as $value) {
420 if (!in_array($value, $current_user_groups)) {
421 array_push($current_user_groups, $value);
425 if (!in_array($group, $current_user_groups)) {
426 array_push($current_user_groups, $group);
429 $user_data = sqlFetchArray(sqlStatement("select * from users where username='" .
432 $current_user_groups,
442 // This will remove the user aro object from the selected group(s)
443 // It uses the set_user_aro() function
444 // $username = username (string)
445 // $group = title of group(s) (string or array)
447 function remove_user_aros($username, $group)
449 $current_user_groups = acl_get_group_titles($username);
450 $new_user_groups = array();
451 if (is_array($group)) {
452 foreach ($current_user_groups as $value) {
453 if (!in_array($value, $group)) {
454 array_push($new_user_groups, $value);
458 foreach ($current_user_groups as $value) {
459 if ($value != $group) {
460 array_push($new_user_groups, $value);
464 $user_data = sqlFetchArray(sqlStatement("select * from users where username='" .
477 // This will either create or edit a user aro object, and then place it
478 // in the requested groups. It will not allow removal of the 'admin'
479 // user or gacl_protected users from the 'admin' group.
480 // $arr_group_titles = titles of the groups that user will be added to.
481 // $user_name = username, which is login name.
482 // $first_name = first name
483 // $middle_name = middle name
484 // $last_name = last name
486 function set_user_aro($arr_group_titles, $user_name, $first_name, $middle_name, $last_name)
488 global $phpgacl_location, $section_aro_value;
490 if (isset($phpgacl_location)) {
491 include_once("$phpgacl_location/gacl_api.class.php");
492 $gacl = new gacl_api();
494 //see if this user is gacl protected (ie. do not allow
495 //removal from the Administrators group)
496 require_once(dirname(__FILE__).'/user.inc');
497 require_once(dirname(__FILE__).'/calendar.inc');
498 $userNametoID = getIDfromUser($user_name);
499 if (checkUserSetting("gacl_protect", "1", $userNametoID) || $user_name == "admin") {
500 $gacl_protect = true;
502 $gacl_protect = false;
505 //get array of all available group ID numbers
506 $parent_id = $gacl->get_root_group_id();
507 $arr_all_group_ids = $gacl->get_group_children($parent_id, 'ARO', 'RECURSE');
509 //Cycle through ID array to find and process each selected group
510 //Create a counter since processing of first hit is unique
512 foreach ($arr_all_group_ids as $value) {
513 $arr_group_data = $gacl->get_group_data($value, 'ARO');
514 if ((empty($arr_group_titles)) ||
515 (in_array($arr_group_data[3], $arr_group_titles))) {
516 //We have a hit, so need to add group and increment counter
517 // because processing of first hit is unique
518 //This will also deal with an empty $arr_group_titles array
519 // removing user from all groups unless 'admin'
520 $counter = $counter + 1;
521 //create user full name field
523 $full_name = $first_name . " " . $middle_name . " " . $last_name;
526 $full_name = $first_name . " " . $last_name;
528 $full_name = $first_name;
532 //If this is not the first group to be added, then will skip below
533 // and will be added. If this is the first group, then need to
534 // go thru several steps before adding the group.
536 //get ID of user ARO object, if it exist
537 $user_aro_id = $gacl->get_object_id($section_aro_value, $user_name, 'ARO');
539 //user ARO object already exist, so will edit it
540 $gacl->edit_object($user_aro_id, $section_aro_value, $full_name, $user_name, 10, 0, 'ARO');
542 //remove all current user ARO object group associations
543 $arr_remove_group_ids = $gacl->get_object_groups($user_aro_id, 'ARO', 'NO_RECURSE');
544 foreach ($arr_remove_group_ids as $value2) {
545 $gacl->del_group_object($value2, $section_aro_value, $user_name, 'ARO');
548 //user ARO object does not exist, so will create it
549 $gacl->add_object($section_aro_value, $full_name, $user_name, 10, 0, 'ARO');
553 //place the user ARO object in the selected group (if group(s) is selected)
554 if (!empty($arr_group_titles)) {
555 $gacl->add_group_object($value, $section_aro_value, $user_name, 'ARO');
559 //Below will not allow 'admin' or gacl_protected user to be removed from 'admin' group
563 $admin_id = $gacl->get_object_id($section_aro_value, $user_name, 'ARO');
564 $arr_admin = $gacl->get_object_groups($admin_id, 'ARO', 'NO_RECURSE');
565 foreach ($arr_admin as $value3) {
566 $arr_admin_data = $gacl->get_group_data($value3, 'ARO');
567 if (strcmp($arr_admin_data[2], 'admin') == 0) {
571 if (!$boolean_admin) {
572 foreach ($arr_all_group_ids as $value4) {
573 $arr_temp = $gacl->get_group_data($value4, 'ARO');
574 if ($arr_temp[2] == 'admin') {
575 $gacl->add_group_object($value4, $section_aro_value, $user_name, 'ARO');
581 //if array of groups was empty, then we are done, and can break from loop
582 if (empty($arr_group_titles)) {
592 // Returns true if acl exist
593 // Returns false if acl doesn't exist
594 // EITHER $title or $name is required(send FALSE in variable
595 // not being used). If both are sent, then only $title will be
597 // $return_value is required
598 // $title = title of acl (string)
599 // $name = name of acl (string)
600 // $return_value = return value of acl (string)
602 function acl_exist($title, $name, $return_value)
604 global $phpgacl_location;
605 if (isset($phpgacl_location)) {
606 include_once("$phpgacl_location/gacl_api.class.php");
607 $gacl = new gacl_api();
609 $acl = $gacl->search_acl(false, false, false, false, $title, false, false, false, $return_value);
610 } else if (!$title) {
611 $group_id = $gacl->get_group_id($name, null, 'ARO');
613 $group_data = $gacl->get_group_data($group_id, 'ARO');
614 $acl = $gacl->search_acl(false, false, false, false, $group_data[3], false, false, false, $return_value);
619 $acl = $gacl->search_acl(false, false, false, false, $title, false, false, false, $return_value);
630 // This will add a new acl and group(if group doesn't yet exist)
631 // with one aco in it.
632 // $acl_title = title of acl (string)
633 // $acl_name = name of acl (string)
634 // $return_value = return value of acl (string)
635 // $note = description of acl (array)
637 function acl_add($acl_title, $acl_name, $return_value, $note)
639 global $phpgacl_location;
640 if (isset($phpgacl_location)) {
641 include_once("$phpgacl_location/gacl_api.class.php");
642 $gacl = new gacl_api();
643 $group_id = $gacl->get_group_id($acl_name, $acl_title, 'ARO');
645 //group already exist, so just create acl
647 array("placeholder"=>array("filler")),
658 //create group, then create acl
659 $parent_id = $gacl->get_root_group_id();
660 $aro_id = $gacl->add_group($acl_name, $acl_title, $parent_id, 'ARO');
662 array("placeholder"=>array("filler")),
679 // This will remove acl. It will also remove group(if the group
680 // is no longer associated with any acl's).
681 // $acl_title = title of acl (string)
682 // $acl_name = name of acl (string)
683 // $return_value = return value of acl (string)
684 // $note = description of acl (array)
686 function acl_remove($acl_title, $return_value)
688 global $phpgacl_location;
689 if (isset($phpgacl_location)) {
690 include_once("$phpgacl_location/gacl_api.class.php");
691 $gacl = new gacl_api();
692 //First, delete the acl
693 $acl_id=$gacl->search_acl(false, false, false, false, $acl_title, false, false, false, $return_value);
694 $gacl->del_acl($acl_id[0]);
695 //Then, remove the group(if no more acl's are remaining)
696 $acl_search=$gacl->search_acl(false, false, false, false, $acl_title, false, false, false, false);
697 if (empty($acl_search)) {
698 $group_id=$gacl-> get_group_id(null, $acl_title, 'ARO');
699 $gacl->del_group($group_id, true, 'ARO');
707 // This will place the aco(s) into the selected acl
708 // $acl_title = title of acl (string)
709 // $return_value = return value of acl (string)
710 // $aco_id = id of aco (array)
712 function acl_add_acos($acl_title, $return_value, $aco_id)
714 global $phpgacl_location;
715 if (isset($phpgacl_location)) {
716 include_once("$phpgacl_location/gacl_api.class.php");
717 $gacl = new gacl_api();
718 $acl_id = $gacl->search_acl(false, false, false, false, $acl_title, false, false, false, $return_value);
719 foreach ($aco_id as $value) {
720 $aco_data = $gacl->get_object_data($value, 'ACO');
721 $aco_section = $aco_data[0][0];
722 $aco_name = $aco_data[0][1];
723 $gacl->append_acl($acl_id[0], null, null, null, null, array($aco_section=>array($aco_name)));
731 // This will remove the aco(s) from the selected acl
732 // Note if all aco's are removed, then will place the filler-placeholder
733 // into the acl to avoid complete removal of the acl.
734 // $acl_title = title of acl (string)
735 // $return_value = return value of acl (string)
736 // $aco_id = id of aco (array)
738 function acl_remove_acos($acl_title, $return_value, $aco_id)
740 global $phpgacl_location;
741 if (isset($phpgacl_location)) {
742 include_once("$phpgacl_location/gacl_api.class.php");
743 $gacl = new gacl_api();
744 $acl_id = $gacl->search_acl(false, false, false, false, $acl_title, false, false, false, $return_value);
746 // Check to see if removing all acos. If removing all acos then will
747 // ensure the filler-placeholder aco in acl to avoid complete
748 // removal of the acl.
749 if (count($aco_id) == acl_count_acos($acl_title, $return_value)) {
750 //1-get the filler-placeholder aco id
751 $filler_aco_id = $gacl->get_object_id('placeholder', 'filler', 'ACO');
752 //2-add filler-placeholder aco
753 acl_add_acos($acl_title, $return_value, array($filler_aco_id));
754 //3-ensure filler-placeholder aco is not to be deleted
755 $safeListaco = remove_element($_POST["selection"], $filler_aco_id);
756 //4-prepare to safely delete the acos
757 $aco_id = $safeListaco;
760 foreach ($aco_id as $value) {
761 $aco_data = $gacl->get_object_data($value, 'ACO');
762 $aco_section = $aco_data[0][0];
763 $aco_name = $aco_data[0][1];
764 $gacl->shift_acl($acl_id[0], null, null, null, null, array($aco_section=>array($aco_name)));
772 // This will return the number of aco objects
773 // in a specified acl.
774 // $acl_title = title of acl (string)
775 // $return_value = return value of acl (string)
777 function acl_count_acos($acl_title, $return_value)
779 global $phpgacl_location;
780 if (isset($phpgacl_location)) {
781 include_once("$phpgacl_location/gacl_api.class.php");
782 $gacl = new gacl_api();
783 $acl_id = $gacl->search_acl(false, false, false, false, $acl_title, false, false, false, $return_value);
784 $acl_data = $gacl->get_acl($acl_id[0]);
786 foreach ($acl_data['aco'] as $key => $value) {
787 $aco_count = $aco_count + count($acl_data['aco'][$key]);
795 // Function to remove an element from an array
797 function remove_element($arr, $val)
800 foreach ($arr as $value) {
801 if ($value != $val) {
802 array_push($arr2, $value);
810 * Same Functionality in the Zend Module
811 * for ACL Check in Zend
812 * Path openemr/interface/modules/zend_modules/module/Application/src/Application/Model/ApplicationTable
813 * Function Name zAclCheck
815 * @param String $user_id Auth user Id
816 * $param String $section_identifier ACL Section id
819 function zh_acl_check($user_id, $section_identifier)
821 $sql_user_acl = " SELECT
822 COUNT(allowed) AS count
824 module_acl_user_settings AS usr_settings
825 LEFT JOIN module_acl_sections AS acl_sections
826 ON usr_settings.section_id = acl_sections.`section_id`
828 acl_sections.section_identifier = ? AND usr_settings.user_id = ? AND usr_settings.allowed = ?";
829 $sql_user_group = " SELECT
833 LEFT JOIN `gacl_groups_aro_map` AS gamp
834 ON garo.id = gamp.aro_id
835 LEFT JOIN `gacl_aro_groups` AS gagp
836 ON gagp.id = gamp.group_id
837 RIGHT JOIN `users_secure` usr
838 ON usr. username = garo.value
840 garo.section_value = ? AND usr. id = ?";
841 $res_groups = sqlStatement($sql_user_group, array('users',$user_id));
843 // Prepare the group queries with the placemakers and binding array for the IN part
844 $groups_sql_param = array();
845 $groupPlacemakers = "";
847 while ($row = sqlFetchArray($res_groups)) {
848 array_push($groups_sql_param, $row['group_id']);
850 $groupPlacemakers = "?";
853 $groupPlacemakers .= ",?";
856 $sql_group_acl_base = " SELECT
857 COUNT(allowed) AS count
859 module_acl_group_settings AS group_settings
860 LEFT JOIN module_acl_sections AS acl_sections
861 ON group_settings.section_id = acl_sections.section_id
863 group_settings.group_id IN (".$groupPlacemakers.") AND acl_sections.`section_identifier` = ? ";
865 $sql_group_acl_allowed = $sql_group_acl_base . " AND group_settings.allowed = '1'";
867 // Complete the group queries sql binding array
868 array_push($groups_sql_param, $section_identifier);
870 $count_group_allowed = 0;
871 $count_user_allowed = 0;
873 $res_user_allowed = sqlQuery($sql_user_acl, array($section_identifier,$user_id,1));
874 $count_user_allowed = $res_user_allowed['count'];
876 $res_group_allowed = sqlQuery($sql_group_acl_allowed, $groups_sql_param);
877 $count_group_allowed = $res_group_allowed['count'];
879 if ($count_user_allowed > 0) {
881 } elseif ($count_group_allowed > 0) {
888 // This generates an HTML options list for all ACOs.
889 // The caller inserts this between <select> and </select> tags.
891 function gen_aco_html_options($default = '')
893 $acoArray = gen_aco_array();
895 foreach ($acoArray as $section => $acos_array) {
896 $s .= "<optgroup label='" . xla($section) . "'>\n";
897 foreach ($acos_array as $aco_array) {
898 $s .= "<option value='" . attr($aco_array['value']) . "'";
899 if ($aco_array['value'] == $default) {
902 $s .= ">" . xlt($aco_array['name']) . "</option>";
910 // Returns array of all ACOs
911 function gen_aco_array()
913 global $phpgacl_location;
914 require_once("$phpgacl_location/gacl_api.class.php");
916 $gacl = new gacl_api();
917 // collect and sort all aco objects
918 $list_aco_objects = $gacl->get_objects(null, 0, 'ACO');
919 ksort($list_aco_objects);
920 foreach ($list_aco_objects as $seckey => $dummy) {
924 asort($list_aco_objects[$seckey]);
925 $aco_section_data = $gacl->get_section_data($seckey, 'ACO');
926 $aco_section_title = $aco_section_data[3];
927 foreach ($list_aco_objects[$seckey] as $acokey) {
928 $aco_id = $gacl->get_object_id($seckey, $acokey, 'ACO');
929 $aco_data = $gacl->get_object_data($aco_id, 'ACO');
930 $aco_title = $aco_data[0][3];
931 $optkey = "$seckey|$acokey";
932 $acoArray[$aco_section_title][$aco_id]['name'] = $aco_title;
933 $acoArray[$aco_section_title][$aco_id]['value'] = $optkey;
940 // Permissions check for an ACO in "section|aco" format.
941 // Note $return_value may be an array of return values.
943 function acl_check_aco_spec($aco_spec, $user = '', $return_value = '')
945 if (empty($aco_spec)) {
948 $tmp = explode('|', $aco_spec);
949 if (!is_array($return_value)) {
950 $return_value = array($return_value);
952 foreach ($return_value as $rv) {
953 if (acl_check($tmp[0], $tmp[1], $user, $rv)) {
960 // Permissions check for a specified encounter form type.
961 // Note $return_value may be an array of return values.
963 function acl_check_form($formdir, $user = '', $return_value = '')
965 require_once(dirname(__FILE__) . '/registry.inc');
966 $tmp = getRegistryEntryByDirectory($formdir, 'aco_spec');
967 return acl_check_aco_spec($tmp['aco_spec'], $user, $return_value);
970 // Permissions check for a specified issue type.
971 // Note $return_value may be an array of return values.
973 function acl_check_issue($type, $user = '', $return_value = '')
975 require_once(dirname(__FILE__) . '/lists.inc');
977 if (empty($ISSUE_TYPES[$type][5])) {
980 return acl_check_aco_spec($ISSUE_TYPES[$type][5], $user, $return_value);
983 // Permissions check for a specified document category name.
984 // Note $return_value may be an array of return values.
986 function acl_check_cat_name($catname, $user = '', $return_value = '')
989 "SELECT aco_spec FROM categories WHERE name = ? ORDER BY id LIMIT 1",
992 if (empty($tmp['aco_spec'])) {
995 return acl_check_aco_spec($tmp['aco_spec'], $user, $return_value);
998 //Fetches aco for given postcalendar category
999 function fetchPostCalendarCategoryACO($pc_catid)
1002 "SELECT aco_spec FROM openemr_postcalendar_categories WHERE pc_catid = ? LIMIT 1",
1005 return $aco['aco_spec'];