Secure SOAP APIs to support third party patient portals. Contributed
[openemr.git] / interface / super / edit_globals.php
blob5a82d5a54fb467156e1d9b9ef7ae9ac6f94a5cc9
1 <?php
2 // Copyright (C) 2010 Rod Roark <rod@sunsetsystems.com>
3 //
4 // This program is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU General Public License
6 // as published by the Free Software Foundation; either version 2
7 // of the License, or (at your option) any later version.
9 require_once("../globals.php");
10 require_once("$srcdir/acl.inc");
11 require_once("$srcdir/formdata.inc.php");
12 require_once("$srcdir/globals.inc.php");
13 require_once("$srcdir/user.inc");
15 if ($_GET['mode'] != "user") {
16 // Check authorization.
17 $thisauth = acl_check('admin', 'super');
18 if (!$thisauth) die(xl('Not authorized'));
21 // If we are saving user_specific globals.
23 if ($_POST['form_save'] && $_GET['mode'] == "user") {
24 $i = 0;
25 foreach ($GLOBALS_METADATA as $grpname => $grparr) {
26 if (in_array($grpname, $USER_SPECIFIC_TABS)) {
27 foreach ($grparr as $fldid => $fldarr) {
28 if (in_array($fldid, $USER_SPECIFIC_GLOBALS)) {
29 list($fldname, $fldtype, $flddef, $flddesc) = $fldarr;
30 $label = "global:".$fldid;
31 if (isset($_POST["form_$i"])) {
32 $fldvalue = trim(strip_escape_custom($_POST["form_$i"]));
33 setUserSetting($label,$fldvalue,$_SESSION['authId'],FALSE);
35 if ( $_POST["toggle_$i"] == "YES" ) {
36 removeUserSetting($label);
38 ++$i;
43 echo "<script type='text/javascript'>";
44 echo "parent.left_nav.location.reload();";
45 echo "parent.Title.location.reload();";
46 echo "if(self.name=='RTop'){";
47 echo "parent.RTop.location.href='edit_globals.php?mode=user';";
48 echo "parent.RBot.location.reload();";
49 echo "}else{";
50 echo "parent.RBot.location.href='edit_globals.php?mode=user';";
51 echo "parent.RTop.location.reload();";
52 echo "}</script>";
55 // If we are saving main globals.
57 if ($_POST['form_save'] && $_GET['mode'] != "user") {
59 $i = 0;
60 foreach ($GLOBALS_METADATA as $grpname => $grparr) {
61 foreach ($grparr as $fldid => $fldarr) {
62 list($fldname, $fldtype, $flddef, $flddesc) = $fldarr;
63 if($fldtype == 'pwd'){
64 $pass = sqlQuery("SELECT gl_value FROM globals WHERE gl_name = '$fldid'");
65 $fldvalueold = $pass['gl_value'];
67 sqlStatement("DELETE FROM globals WHERE gl_name = '$fldid'");
69 if (substr($fldtype, 0, 2) == 'm_') {
70 if (isset($_POST["form_$i"])) {
71 $fldindex = 0;
72 foreach ($_POST["form_$i"] as $fldvalue) {
73 $fldvalue = formDataCore($fldvalue, true);
74 sqlStatement("INSERT INTO globals ( gl_name, gl_index, gl_value ) " .
75 "VALUES ( '$fldid', '$fldindex', '$fldvalue' )");
76 ++$fldindex;
80 else {
81 if (isset($_POST["form_$i"])) {
82 $fldvalue = formData("form_$i", "P", true);
84 else {
85 $fldvalue = "";
87 if($fldtype=='pwd')
88 $fldvalue = $fldvalue ? SHA1($fldvalue) : $fldvalueold;
89 if(fldvalue){
90 sqlStatement("INSERT INTO globals ( gl_name, gl_index, gl_value ) " .
91 "VALUES ( '$fldid', '0', '$fldvalue' )");
95 ++$i;
98 echo "<script type='text/javascript'>";
99 echo "parent.left_nav.location.reload();";
100 echo "parent.Title.location.reload();";
101 echo "if(self.name=='RTop'){";
102 echo "parent.RTop.location.href='edit_globals.php';";
103 echo "parent.RBot.location.reload();";
104 echo "}else{";
105 echo "parent.RBot.location.href='edit_globals.php';";
106 echo "parent.RTop.location.reload();";
107 echo "}</script>";
110 <html>
112 <head>
113 <?php html_header_show();?>
115 <!-- supporting javascript code -->
116 <script type="text/javascript" src="../../library/dialog.js"></script>
117 <script type="text/javascript" src="../../library/js/jquery.1.3.2.js"></script>
118 <script type="text/javascript" src="../../library/js/common.js"></script>
119 <script type="text/javascript" src="../../library/js/fancybox/jquery.fancybox-1.2.6.js"></script>
120 <link rel="stylesheet" type="text/css" href="../../library/js/fancybox/jquery.fancybox-1.2.6.css" media="screen" />
122 <link rel="stylesheet" href='<?php echo $css_header ?>' type='text/css'>
123 <?php if ($_GET['mode'] == "user") { ?>
124 <title><?php xl('User Settings','e'); ?></title>
125 <?php } else { ?>
126 <title><?php xl('Global Settings','e'); ?></title>
127 <?php } ?>
129 <style>
130 tr.head { font-size:10pt; background-color:#cccccc; text-align:center; }
131 tr.detail { font-size:10pt; }
132 td { font-size:10pt; }
133 input { font-size:10pt; }
134 </style>
136 </head>
138 <body class="body_top">
140 <?php if ($_GET['mode'] == "user") { ?>
141 <form method='post' name='theform' id='theform' action='edit_globals.php?mode=user' onsubmit='return top.restoreSession()'>
142 <?php } else { ?>
143 <form method='post' name='theform' id='theform' action='edit_globals.php' onsubmit='return top.restoreSession()'>
144 <?php } ?>
146 <?php if ($_GET['mode'] == "user") { ?>
147 <p><b><?php xl('Edit User Settings','e'); ?></b>
148 <?php } else { ?>
149 <p><b><?php xl('Edit Global Settings','e'); ?></b>
150 <?php } ?>
152 <ul class="tabNav">
153 <?php
154 $i = 0;
155 foreach ($GLOBALS_METADATA as $grpname => $grparr) {
156 if ( $_GET['mode'] != "user" || ($_GET['mode'] == "user" && in_array($grpname, $USER_SPECIFIC_TABS)) ) {
157 echo " <li" . ($i ? "" : " class='current'") .
158 "><a href='/play/javascript-tabbed-navigation/'>" .
159 xl($grpname) . "</a></li>\n";
160 ++$i;
164 </ul>
166 <div class="tabContainer">
167 <?php
168 $i = 0;
169 foreach ($GLOBALS_METADATA as $grpname => $grparr) {
170 if ( $_GET['mode'] != "user" || ($_GET['mode'] == "user" && in_array($grpname, $USER_SPECIFIC_TABS)) ) {
171 echo " <div class='tab" . ($i ? "" : " current") .
172 "' style='height:auto;width:97%;'>\n";
174 echo " <table>";
176 if ($_GET['mode'] == "user") {
177 echo "<tr>";
178 echo "<th>&nbsp</th>";
179 echo "<th>" . htmlspecialchars( xl('User Specific Setting'), ENT_NOQUOTES) . "</th>";
180 echo "<th>" . htmlspecialchars( xl('Default Setting'), ENT_NOQUOTES) . "</th>";
181 echo "<th>&nbsp</th>";
182 echo "<th>" . htmlspecialchars( xl('Set to Default'), ENT_NOQUOTES) . "</th>";
183 echo "</tr>";
186 foreach ($grparr as $fldid => $fldarr) {
187 if ( $_GET['mode'] != "user" || ($_GET['mode'] == "user" && in_array($fldid, $USER_SPECIFIC_GLOBALS)) ) {
188 list($fldname, $fldtype, $flddef, $flddesc) = $fldarr;
190 // Most parameters will have a single value, but some will be arrays.
191 // Here we cater to both possibilities.
192 $glres = sqlStatement("SELECT gl_index, gl_value FROM globals WHERE " .
193 "gl_name = '$fldid' ORDER BY gl_index");
194 $glarr = array();
195 while ($glrow = sqlFetchArray($glres)) $glarr[] = $glrow;
197 // $fldvalue is meaningful only for the single-value cases.
198 $fldvalue = count($glarr) ? $glarr[0]['gl_value'] : $flddef;
200 // Collect user specific setting if mode set to user
201 $userSetting = "";
202 $settingDefault = "checked='checked'";
203 if ($_GET['mode'] == "user") {
204 $userSettingArray = sqlQuery("SELECT * FROM user_settings WHERE setting_user=? AND setting_label=?",array($_SESSION['authId'],"global:".$fldid));
205 $userSetting = $userSettingArray['setting_value'];
206 $globalValue = $fldvalue;
207 if (!empty($userSetting) || $userSetting === "0" ) {
208 $fldvalue = $userSetting;
209 $settingDefault = "";
213 echo " <tr title='$flddesc'><td valign='top'><b>$fldname </b></td><td valign='top'>\n";
215 if (is_array($fldtype)) {
216 echo " <select name='form_$i' id='form_$i'>\n";
217 foreach ($fldtype as $key => $value) {
218 if ($_GET['mode'] == "user") {
219 if ($globalValue == $key) $globalTitle = $value;
221 echo " <option value='$key'";
222 if ($key == $fldvalue) echo " selected";
223 echo ">";
224 echo $value;
225 echo "</option>\n";
227 echo " </select>\n";
230 else if ($fldtype == 'bool') {
231 if ($_GET['mode'] == "user") {
232 if ($globalValue == 1) {
233 $globalTitle = htmlspecialchars( xl('Checked'), ENT_NOQUOTES);
235 else {
236 $globalTitle = htmlspecialchars( xl('Not Checked'), ENT_NOQUOTES);
239 echo " <input type='checkbox' name='form_$i' id='form_$i' value='1'";
240 if ($fldvalue) echo " checked";
241 echo " />\n";
244 else if ($fldtype == 'num') {
245 if ($_GET['mode'] == "user") {
246 $globalTitle = $globalValue;
248 echo " <input type='text' name='form_$i' id='form_$i' " .
249 "size='6' maxlength='15' value='$fldvalue' />\n";
252 else if ($fldtype == 'text') {
253 if ($_GET['mode'] == "user") {
254 $globalTitle = $globalValue;
256 echo " <input type='text' name='form_$i' id='form_$i' " .
257 "size='50' maxlength='255' value='$fldvalue' />\n";
259 else if ($fldtype == 'pwd') {
260 if ($_GET['mode'] == "user") {
261 $globalTitle = $globalValue;
263 echo " <input type='password' name='form_$i' " .
264 "size='50' maxlength='255' value='' />\n";
267 else if ($fldtype == 'pass') {
268 if ($_GET['mode'] == "user") {
269 $globalTitle = $globalValue;
271 echo " <input type='password' name='form_$i' " .
272 "size='50' maxlength='255' value='$fldvalue' />\n";
275 else if ($fldtype == 'lang') {
276 $res = sqlStatement("SELECT * FROM lang_languages ORDER BY lang_description");
277 echo " <select name='form_$i' id='form_$i'>\n";
278 while ($row = sqlFetchArray($res)) {
279 echo " <option value='" . $row['lang_description'] . "'";
280 if ($row['lang_description'] == $fldvalue) echo " selected";
281 echo ">";
282 echo xl($row['lang_description']);
283 echo "</option>\n";
285 echo " </select>\n";
288 else if ($fldtype == 'm_lang') {
289 $res = sqlStatement("SELECT * FROM lang_languages ORDER BY lang_description");
290 echo " <select multiple name='form_{$i}[]' id='form_{$i}[]' size='3'>\n";
291 while ($row = sqlFetchArray($res)) {
292 echo " <option value='" . $row['lang_description'] . "'";
293 foreach ($glarr as $glrow) {
294 if ($glrow['gl_value'] == $row['lang_description']) {
295 echo " selected";
296 break;
299 echo ">";
300 echo xl($row['lang_description']);
301 echo "</option>\n";
303 echo " </select>\n";
306 else if ($fldtype == 'css') {
307 if ($_GET['mode'] == "user") {
308 $globalTitle = $globalValue;
310 $themedir = "$webserver_root/interface/themes";
311 $dh = opendir($themedir);
312 if ($dh) {
313 echo " <select name='form_$i' id='form_$i'>\n";
314 while (false !== ($tfname = readdir($dh))) {
315 // Only show files that contain style_ as options
316 // Skip style_blue.css since this is used for
317 // lone scripts such as setup.php
318 if (!preg_match("/^style_.*\.css$/", $tfname) || $tfname == 'style_blue.css') { continue; }
319 echo "<option value='$tfname'";
320 if ($tfname == $fldvalue) echo " selected";
321 echo ">";
322 echo $tfname;
323 echo "</option>\n";
325 closedir($dh);
326 echo " </select>\n";
330 else if ($fldtype == 'hour') {
331 if ($_GET['mode'] == "user") {
332 $globalTitle = $globalValue;
334 echo " <select name='form_$i' id='form_$i'>\n";
335 for ($h = 0; $h < 24; ++$h) {
336 echo "<option value='$h'";
337 if ($h == $fldvalue) echo " selected";
338 echo ">";
339 if ($h == 0) echo "12 AM";
340 else if ($h < 12) echo "$h AM";
341 else if ($h == 12) echo "12 PM";
342 else echo ($h - 12) . " PM";
343 echo "</option>\n";
345 echo " </select>\n";
347 if ($_GET['mode'] == "user") {
348 echo " </td>\n";
349 echo "<td align='center' style='color:red;'>" . $globalTitle . "</td>\n";
350 echo "<td>&nbsp</td>";
351 echo "<td align='center'><input type='checkbox' value='YES' name='toggle_" . $i . "' id='toggle_" . $i . "' " . $settingDefault . "/></td>\n";
352 echo "<input type='hidden' id='globaldefault_" . $i . "' value='" . $globalValue . "'>\n";
353 echo "</tr>\n";
355 else {
356 echo " </td></tr>\n";
358 ++$i;
361 echo " </table>\n";
362 echo " </div>\n";
366 </div>
369 <input type='submit' name='form_save' value='<?php xl('Save','e'); ?>' />
370 </p>
371 </center>
373 </form>
375 </body>
377 <script language="JavaScript">
379 $(document).ready(function(){
380 tabbify();
381 enable_modals();
383 // Use the counter ($i) to make the form user friendly for user-specific globals use
384 <?php if ($_GET['mode'] == "user") { ?>
385 <?php for ($j = 0; $j <= $i; $j++) { ?>
386 $("#form_<?php echo $j ?>").change(function() {
387 $("#toggle_<?php echo $j ?>").attr('checked',false);
389 $("#toggle_<?php echo $j ?>").change(function() {
390 if ($('#toggle_<?php echo $j ?>').attr('checked')) {
391 var defaultGlobal = $("#globaldefault_<?php echo $j ?>").val();
392 $("#form_<?php echo $j ?>").val(defaultGlobal);
395 <?php } ?>
396 <?php } ?>
400 </script>
402 </html>