feat: allow full swapping of insurances (#6311)
[openemr.git] / gacl / admin / group_admin.php
blob8a9e9f106175c824026275e59519ccdcb55f6964
1 <?php
2 //First make sure user has access
3 require_once("../../interface/globals.php");
5 use OpenEMR\Common\Acl\AclMain;
6 use OpenEMR\Common\Csrf\CsrfUtils;
7 use OpenEMR\Common\Twig\TwigContainer;
9 //ensure user has proper access
10 if (!AclMain::aclCheckCore('admin', 'acl')) {
11 echo (new TwigContainer(null, $GLOBALS['kernel']))->getTwig()->render('core/unauthorized.html.twig', ['pageTitle' => xl("ACL Administration")]);
12 exit;
15 require_once('gacl_admin.inc.php');
17 //GET takes precedence.
18 if ($_GET['group_type'] != '') {
19 $group_type = $_GET['group_type'];
20 } else {
21 $group_type = $_POST['group_type'];
24 switch(strtolower(trim($group_type))) {
25 case 'axo':
26 $group_type = 'axo';
27 $group_table = $gacl_api->_db_table_prefix . 'axo_groups';
28 $group_map_table = $gacl_api->_db_table_prefix . 'groups_axo_map';
29 $smarty->assign('current','axo_group');
30 break;
31 default:
32 $group_type = 'aro';
33 $group_table = $gacl_api->_db_table_prefix . 'aro_groups';
34 $group_map_table = $gacl_api->_db_table_prefix . 'groups_aro_map';
35 $smarty->assign('current','aro_group');
36 break;
39 $postAction = $_POST['action'] ?? null;
40 switch ($postAction) {
41 case 'Delete':
42 //See edit_group.php
43 break;
44 default:
45 $formatted_groups = $gacl_api->format_groups($gacl_api->sort_groups($group_type), 'HTML');
47 $query = '
48 SELECT a.id, a.name, a.value, count(b.'. $group_type .'_id)
49 FROM '. $group_table .' a
50 LEFT JOIN '. $group_map_table .' b ON b.group_id=a.id
51 GROUP BY a.id,a.name,a.value';
52 $rs = $db->Execute($query);
54 $group_data = array();
56 if(is_object($rs)) {
57 while($row = $rs->FetchRow()) {
58 $group_data[$row[0]] = array(
59 'name' => $row[1],
60 'value' => $row[2],
61 'count' => $row[3]
66 $groups = array();
68 foreach($formatted_groups as $id => $name) {
69 $groups[] = array(
70 'id' => $id,
71 // 'parent_id' => $parent_id,
72 // 'family_id' => $family_id,
73 'name' => $name,
74 'raw_name' => $group_data[$id]['name'],
75 'value' => $group_data[$id]['value'],
76 'object_count' => $group_data[$id]['count']
80 $smarty->assign('groups', $groups);
81 break;
84 $smarty->assign('group_type', $group_type);
85 $smarty->assign('return_page', $_SERVER['REQUEST_URI']);
87 $smarty->assign('current', $group_type .'_group');
88 $smarty->assign('page_title', strtoupper($group_type) .' Group Admin');
90 $smarty->assign('phpgacl_version', $gacl_api->get_version());
91 $smarty->assign('phpgacl_schema_version', $gacl_api->get_schema_version());
93 $smarty->assign("CSRF_TOKEN_FORM", CsrfUtils::collectCsrfToken());
95 $smarty->display('phpgacl/group_admin.tpl');