Updated gui for user facility settings (#1327)
[openemr.git] / interface / usergroup / facility_user.php
blob122eb3ef082f474b15646eef47fcee69e11b0e3a
1 <?php
2 /**
3 * Facility user-specific settings.
5 * @package OpenEMR
6 * @link http://www.open-emr.org
7 * @author Scott Wakefield <scott@npclinics.com.au>
8 * @author Brady Miller <brady.g.miller@gmail.com>
9 * @copyright Copyright (c) 2012 NP Clinics <info@npclinics.com.au>
10 * @copyright Copyright (c) 2017 Brady Miller <brady.g.miller@gmail.com>
11 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
15 require_once("../globals.php");
16 require_once("$srcdir/options.inc.php");
17 require_once("$srcdir/acl.inc");
19 use OpenEMR\Core\Header;
21 // Ensure authorized
22 if (!acl_check('admin', 'users')) {
23 die(xlt("Unauthorized"));
26 $alertmsg = '';
28 if (isset($_POST["mode"]) && $_POST["mode"] == "facility_user_id" && isset($_POST["user_id"]) && isset($_POST["fac_id"])) {
29 // Inserting/Updating new facility specific user information
30 $fres = sqlStatement("SELECT * FROM `layout_options` " .
31 "WHERE `form_id` = 'FACUSR' AND `uor` > 0 AND `field_id` != '' " .
32 "ORDER BY `group_id`, `seq`");
33 while ($frow = sqlFetchArray($fres)) {
34 $value = get_layout_form_value($frow);
35 $entry_id = sqlQuery("SELECT `id` FROM `facility_user_ids` WHERE `uid` = ? AND `facility_id` = ? AND `field_id` =?", array($_POST["user_id"],$_POST["fac_id"],$frow['field_id']));
36 if (empty($entry_id)) {
37 // Insert new entry
38 sqlInsert("INSERT INTO `facility_user_ids` (`uid`, `facility_id`, `field_id`, `field_value`) VALUES (?,?,?,?)", array($_POST["user_id"],$_POST["fac_id"],$frow['field_id'], $value));
39 } else {
40 // Update existing entry
41 sqlStatement("UPDATE `facility_user_ids` SET `field_value` = ? WHERE `id` = ?", array($value,$entry_id['id']));
47 <html>
48 <head>
50 <title><?php echo xlt("Facility Specific User Information"); ?></title>
52 <?php Header::setupHeader(['common','jquery-ui']); ?>
54 <script type="text/javascript">
55 function refreshme() {
56 top.restoreSession();
57 document.location.reload();
60 $(document).ready(function(){
61 $(".small_modal").on('click', function(e) {
62 e.preventDefault();e.stopPropagation();
63 dlgopen('', '', 500, 200, '', '', {
64 //onClosed: 'refreshme',
65 sizeHeight: 'auto',
66 allowResize: true,
67 allowDrag: true,
68 dialogId: '',
69 type: 'iframe',
70 url: $(this).attr('href')
71 });
72 });
73 });
74 </script>
75 </head>
76 <body class="body_top">
77 <?php
78 // Collect all users
79 $u_res = sqlStatement("select * from `users` WHERE `username` != '' AND `active` = 1 order by `username`");
81 // Collect all facilities and store them in an array
82 $f_res = sqlStatement("select * from `facility` order by `name`");
83 $f_arr = array();
84 for ($i=0; $row=sqlFetchArray($f_res); $i++) {
85 $f_arr[$i]=$row;
88 // Collect layout information and store them in an array
89 $l_res = sqlStatement("SELECT * FROM layout_options " .
90 "WHERE form_id = 'FACUSR' AND uor > 0 AND field_id != '' " .
91 "ORDER BY group_id, seq");
92 $l_arr = array();
93 for ($i=0; $row=sqlFetchArray($l_res); $i++) {
94 $l_arr[$i]=$row;
98 <div class="container">
99 <div class="row">
100 <div class="col-xs-12">
101 <div class="page-title">
102 <h2><?php echo xlt('Facility Specific User Information'); ?></h2>
103 </div>
104 </div>
105 </div>
106 <div class="row">
107 <div class="col-xs-12">
108 <div class="btn-group">
109 <a href="usergroup_admin.php" class="btn btn-default btn-back" onclick="top.restoreSession()"><?php echo xlt('Back to Users'); ?></a>
110 </div>
111 </div>
112 </div>
113 <div class="row">
114 <div class="table-responsive">
115 <table class="table table-striped">
116 <thead>
117 <tr>
118 <th><b><?php echo xlt('Username'); ?></b></th>
119 <th><b><?php echo xlt('Full Name'); ?></b></th>
120 <th><b><span class="bold"><?php echo xlt('Facility'); ?></span></b></th>
121 <?php
122 foreach ($l_arr as $layout_entry) {
123 echo "<th>" . text(xl_layout_label($layout_entry['title'])) . "&nbsp;</th>";
126 </tr>
127 </thead>
128 <tbody>
129 <?php
130 while ($user = sqlFetchArray($u_res)) {
131 foreach ($f_arr as $facility) { ?>
132 <tr>
133 <td><a href="facility_user_admin.php?user_id=<?php echo attr($user['id']);?>&fac_id=<?php echo attr($facility['id']);?>" class="small_modal" onclick="top.restoreSession()"><b><?php echo text($user['username']);?></b></a>&nbsp;</td>
134 <td><?php echo text($user['fname'] . " " . $user['lname']);?></td>
135 <td><?php echo text($facility['name']);?>&nbsp;</td>
136 <?php
137 foreach ($l_arr as $layout_entry) {
138 $entry_data = sqlQuery("SELECT `field_value` FROM `facility_user_ids` " .
139 "WHERE `uid` = ? AND `facility_id` = ? AND `field_id` = ?", array($user['id'],$facility['id'],$layout_entry['field_id']));
140 echo "<td>" . generate_display_field($layout_entry, $entry_data['field_value']) . "&nbsp;</td>";
143 </tr>
144 <?php
148 </tbody>
149 </table>
150 </div>
151 </div>
152 </div>
153 </body>
154 </html>