PageRenderTime 41ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/interface/super/edit_globals.php

https://bitbucket.org/astawiarski/openemr
PHP | 439 lines | 372 code | 46 blank | 21 comment | 145 complexity | 5057d53aba71a326aeb7d70745cf5c78 MD5 | raw file
Possible License(s): LGPL-2.1, AGPL-1.0, GPL-2.0, MPL-2.0
  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.
  8. require_once("../globals.php");
  9. require_once("$srcdir/acl.inc");
  10. require_once("$srcdir/formdata.inc.php");
  11. require_once("$srcdir/globals.inc.php");
  12. require_once("$srcdir/user.inc");
  13. require_once("$srcdir/classes/CouchDB.class.php");
  14. if ($_GET['mode'] != "user") {
  15. // Check authorization.
  16. $thisauth = acl_check('admin', 'super');
  17. if (!$thisauth) die(xl('Not authorized'));
  18. }
  19. function checkCreateCDB(){
  20. $globalsres = sqlStatement("SELECT gl_name, gl_index, gl_value FROM globals WHERE gl_name IN
  21. ('couchdb_host','couchdb_user','couchdb_pass','couchdb_port','couchdb_dbase','document_storage_method')");
  22. $options = array();
  23. while($globalsrow = sqlFetchArray($globalsres)){
  24. $GLOBALS[$globalsrow['gl_name']] = $globalsrow['gl_value'];
  25. }
  26. $directory_created = false;
  27. if($GLOBALS['document_storage_method'] != 0){
  28. // /documents/temp/ folder is required for CouchDB
  29. if(!is_dir($GLOBALS['OE_SITE_DIR'] . '/documents/temp/')){
  30. $directory_created = mkdir($GLOBALS['OE_SITE_DIR'] . '/documents/temp/',0777,true);
  31. if(!$directory_created){
  32. echo htmlspecialchars( xl("Failed to create temporary folder. CouchDB will not work."),ENT_NOQUOTES);
  33. }
  34. }
  35. $couch = new CouchDB();
  36. if(!$couch->check_connection()) {
  37. echo "<script type='text/javascript'>alert('".addslashes(xl("CouchDB Connection Failed."))."');</script>";
  38. return;
  39. }
  40. if($GLOBALS['couchdb_host'] || $GLOBALS['couchdb_port'] || $GLOBALS['couchdb_dbase']){
  41. $couch->createDB($GLOBALS['couchdb_dbase']);
  42. $couch->createView($GLOBALS['couchdb_dbase']);
  43. }
  44. }
  45. return true;
  46. }
  47. ?>
  48. <html>
  49. <head>
  50. <?php
  51. html_header_show();
  52. // If we are saving user_specific globals.
  53. //
  54. if ($_POST['form_save'] && $_GET['mode'] == "user") {
  55. $i = 0;
  56. foreach ($GLOBALS_METADATA as $grpname => $grparr) {
  57. if (in_array($grpname, $USER_SPECIFIC_TABS)) {
  58. foreach ($grparr as $fldid => $fldarr) {
  59. if (in_array($fldid, $USER_SPECIFIC_GLOBALS)) {
  60. list($fldname, $fldtype, $flddef, $flddesc) = $fldarr;
  61. $label = "global:".$fldid;
  62. $fldvalue = trim(strip_escape_custom($_POST["form_$i"]));
  63. setUserSetting($label,$fldvalue,$_SESSION['authId'],FALSE);
  64. if ( $_POST["toggle_$i"] == "YES" ) {
  65. removeUserSetting($label);
  66. }
  67. ++$i;
  68. }
  69. }
  70. }
  71. }
  72. echo "<script type='text/javascript'>";
  73. echo "parent.left_nav.location.reload();";
  74. echo "parent.Title.location.reload();";
  75. echo "if(self.name=='RTop'){";
  76. echo "parent.RBot.location.reload();";
  77. echo "}else{";
  78. echo "parent.RTop.location.reload();";
  79. echo "}";
  80. echo "self.location.href='edit_globals.php?mode=user&unique=yes';";
  81. echo "</script>";
  82. }
  83. // If we are saving main globals.
  84. //
  85. if ($_POST['form_save'] && $_GET['mode'] != "user") {
  86. $i = 0;
  87. foreach ($GLOBALS_METADATA as $grpname => $grparr) {
  88. foreach ($grparr as $fldid => $fldarr) {
  89. list($fldname, $fldtype, $flddef, $flddesc) = $fldarr;
  90. if($fldtype == 'pwd'){
  91. $pass = sqlQuery("SELECT gl_value FROM globals WHERE gl_name = '$fldid'");
  92. $fldvalueold = $pass['gl_value'];
  93. }
  94. sqlStatement("DELETE FROM globals WHERE gl_name = '$fldid'");
  95. if (substr($fldtype, 0, 2) == 'm_') {
  96. if (isset($_POST["form_$i"])) {
  97. $fldindex = 0;
  98. foreach ($_POST["form_$i"] as $fldvalue) {
  99. $fldvalue = formDataCore($fldvalue, true);
  100. sqlStatement("INSERT INTO globals ( gl_name, gl_index, gl_value ) " .
  101. "VALUES ( '$fldid', '$fldindex', '$fldvalue' )");
  102. ++$fldindex;
  103. }
  104. }
  105. }
  106. else {
  107. if (isset($_POST["form_$i"])) {
  108. $fldvalue = formData("form_$i", "P", true);
  109. }
  110. else {
  111. $fldvalue = "";
  112. }
  113. if($fldtype=='pwd')
  114. $fldvalue = $fldvalue ? SHA1($fldvalue) : $fldvalueold;
  115. if(fldvalue){
  116. sqlStatement("INSERT INTO globals ( gl_name, gl_index, gl_value ) " .
  117. "VALUES ( '$fldid', '0', '$fldvalue' )");
  118. }
  119. }
  120. ++$i;
  121. }
  122. }
  123. checkCreateCDB();
  124. echo "<script type='text/javascript'>";
  125. echo "parent.left_nav.location.reload();";
  126. echo "parent.Title.location.reload();";
  127. echo "if(self.name=='RTop'){";
  128. echo "parent.RBot.location.reload();";
  129. echo "}else{";
  130. echo "parent.RTop.location.reload();";
  131. echo "}";
  132. echo "self.location.href='edit_globals.php?unique=yes';";
  133. echo "</script>";
  134. }
  135. ?>
  136. <!-- supporting javascript code -->
  137. <script type="text/javascript" src="../../library/dialog.js"></script>
  138. <script type="text/javascript" src="../../library/js/jquery.1.3.2.js"></script>
  139. <script type="text/javascript" src="../../library/js/common.js"></script>
  140. <script type="text/javascript" src="../../library/js/fancybox/jquery.fancybox-1.2.6.js"></script>
  141. <link rel="stylesheet" type="text/css" href="../../library/js/fancybox/jquery.fancybox-1.2.6.css" media="screen" />
  142. <link rel="stylesheet" href='<?php echo $css_header ?>' type='text/css'>
  143. <?php if ($_GET['mode'] == "user") { ?>
  144. <title><?php xl('User Settings','e'); ?></title>
  145. <?php } else { ?>
  146. <title><?php xl('Global Settings','e'); ?></title>
  147. <?php } ?>
  148. <style>
  149. tr.head { font-size:10pt; background-color:#cccccc; text-align:center; }
  150. tr.detail { font-size:10pt; }
  151. td { font-size:10pt; }
  152. input { font-size:10pt; }
  153. </style>
  154. </head>
  155. <body class="body_top">
  156. <?php if ($_GET['mode'] == "user") { ?>
  157. <form method='post' name='theform' id='theform' action='edit_globals.php?mode=user' onsubmit='return top.restoreSession()'>
  158. <?php } else { ?>
  159. <form method='post' name='theform' id='theform' action='edit_globals.php' onsubmit='return top.restoreSession()'>
  160. <?php } ?>
  161. <?php if ($_GET['mode'] == "user") { ?>
  162. <p><b><?php xl('Edit User Settings','e'); ?></b>
  163. <?php } else { ?>
  164. <p><b><?php xl('Edit Global Settings','e'); ?></b>
  165. <?php } ?>
  166. <ul class="tabNav">
  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 " <li" . ($i ? "" : " class='current'") .
  172. "><a href='/play/javascript-tabbed-navigation/'>" .
  173. xl($grpname) . "</a></li>\n";
  174. ++$i;
  175. }
  176. }
  177. ?>
  178. </ul>
  179. <div class="tabContainer">
  180. <?php
  181. $i = 0;
  182. foreach ($GLOBALS_METADATA as $grpname => $grparr) {
  183. if ( $_GET['mode'] != "user" || ($_GET['mode'] == "user" && in_array($grpname, $USER_SPECIFIC_TABS)) ) {
  184. echo " <div class='tab" . ($i ? "" : " current") .
  185. "' style='height:auto;width:97%;'>\n";
  186. echo " <table>";
  187. if ($_GET['mode'] == "user") {
  188. echo "<tr>";
  189. echo "<th>&nbsp</th>";
  190. echo "<th>" . htmlspecialchars( xl('User Specific Setting'), ENT_NOQUOTES) . "</th>";
  191. echo "<th>" . htmlspecialchars( xl('Default Setting'), ENT_NOQUOTES) . "</th>";
  192. echo "<th>&nbsp</th>";
  193. echo "<th>" . htmlspecialchars( xl('Set to Default'), ENT_NOQUOTES) . "</th>";
  194. echo "</tr>";
  195. }
  196. foreach ($grparr as $fldid => $fldarr) {
  197. if ( $_GET['mode'] != "user" || ($_GET['mode'] == "user" && in_array($fldid, $USER_SPECIFIC_GLOBALS)) ) {
  198. list($fldname, $fldtype, $flddef, $flddesc) = $fldarr;
  199. // Most parameters will have a single value, but some will be arrays.
  200. // Here we cater to both possibilities.
  201. $glres = sqlStatement("SELECT gl_index, gl_value FROM globals WHERE " .
  202. "gl_name = '$fldid' ORDER BY gl_index");
  203. $glarr = array();
  204. while ($glrow = sqlFetchArray($glres)) $glarr[] = $glrow;
  205. // $fldvalue is meaningful only for the single-value cases.
  206. $fldvalue = count($glarr) ? $glarr[0]['gl_value'] : $flddef;
  207. // Collect user specific setting if mode set to user
  208. $userSetting = "";
  209. $settingDefault = "checked='checked'";
  210. if ($_GET['mode'] == "user") {
  211. $userSettingArray = sqlQuery("SELECT * FROM user_settings WHERE setting_user=? AND setting_label=?",array($_SESSION['authId'],"global:".$fldid));
  212. $userSetting = $userSettingArray['setting_value'];
  213. $globalValue = $fldvalue;
  214. if (!empty($userSettingArray)) {
  215. $fldvalue = $userSetting;
  216. $settingDefault = "";
  217. }
  218. }
  219. echo " <tr title='$flddesc'><td valign='top'><b>$fldname </b></td><td valign='top'>\n";
  220. if (is_array($fldtype)) {
  221. echo " <select name='form_$i' id='form_$i'>\n";
  222. foreach ($fldtype as $key => $value) {
  223. if ($_GET['mode'] == "user") {
  224. if ($globalValue == $key) $globalTitle = $value;
  225. }
  226. echo " <option value='$key'";
  227. if ($key == $fldvalue) echo " selected";
  228. echo ">";
  229. echo $value;
  230. echo "</option>\n";
  231. }
  232. echo " </select>\n";
  233. }
  234. else if ($fldtype == 'bool') {
  235. if ($_GET['mode'] == "user") {
  236. if ($globalValue == 1) {
  237. $globalTitle = htmlspecialchars( xl('Checked'), ENT_NOQUOTES);
  238. }
  239. else {
  240. $globalTitle = htmlspecialchars( xl('Not Checked'), ENT_NOQUOTES);
  241. }
  242. }
  243. echo " <input type='checkbox' name='form_$i' id='form_$i' value='1'";
  244. if ($fldvalue) echo " checked";
  245. echo " />\n";
  246. }
  247. else if ($fldtype == 'num') {
  248. if ($_GET['mode'] == "user") {
  249. $globalTitle = $globalValue;
  250. }
  251. echo " <input type='text' name='form_$i' id='form_$i' " .
  252. "size='6' maxlength='15' value='$fldvalue' />\n";
  253. }
  254. else if ($fldtype == 'text') {
  255. if ($_GET['mode'] == "user") {
  256. $globalTitle = $globalValue;
  257. }
  258. echo " <input type='text' name='form_$i' id='form_$i' " .
  259. "size='50' maxlength='255' value='$fldvalue' />\n";
  260. }
  261. else if ($fldtype == 'pwd') {
  262. if ($_GET['mode'] == "user") {
  263. $globalTitle = $globalValue;
  264. }
  265. echo " <input type='password' name='form_$i' " .
  266. "size='50' maxlength='255' value='' />\n";
  267. }
  268. else if ($fldtype == 'pass') {
  269. if ($_GET['mode'] == "user") {
  270. $globalTitle = $globalValue;
  271. }
  272. echo " <input type='password' name='form_$i' " .
  273. "size='50' maxlength='255' value='$fldvalue' />\n";
  274. }
  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";
  284. }
  285. echo " </select>\n";
  286. }
  287. else if ($fldtype == 'm_lang') {
  288. $res = sqlStatement("SELECT * FROM lang_languages ORDER BY lang_description");
  289. echo " <select multiple name='form_{$i}[]' id='form_{$i}[]' size='3'>\n";
  290. while ($row = sqlFetchArray($res)) {
  291. echo " <option value='" . $row['lang_description'] . "'";
  292. foreach ($glarr as $glrow) {
  293. if ($glrow['gl_value'] == $row['lang_description']) {
  294. echo " selected";
  295. break;
  296. }
  297. }
  298. echo ">";
  299. echo xl($row['lang_description']);
  300. echo "</option>\n";
  301. }
  302. echo " </select>\n";
  303. }
  304. else if ($fldtype == 'css') {
  305. if ($_GET['mode'] == "user") {
  306. $globalTitle = $globalValue;
  307. }
  308. $themedir = "$webserver_root/interface/themes";
  309. $dh = opendir($themedir);
  310. if ($dh) {
  311. echo " <select name='form_$i' id='form_$i'>\n";
  312. while (false !== ($tfname = readdir($dh))) {
  313. // Only show files that contain style_ as options
  314. // Skip style_blue.css since this is used for
  315. // lone scripts such as setup.php
  316. // Also skip style_pdf.css which is for PDFs and not screen output
  317. if (!preg_match("/^style_.*\.css$/", $tfname) ||
  318. $tfname == 'style_blue.css' || $tfname == 'style_pdf.css')
  319. continue;
  320. echo "<option value='$tfname'";
  321. if ($tfname == $fldvalue) echo " selected";
  322. echo ">";
  323. echo $tfname;
  324. echo "</option>\n";
  325. }
  326. closedir($dh);
  327. echo " </select>\n";
  328. }
  329. }
  330. else if ($fldtype == 'hour') {
  331. if ($_GET['mode'] == "user") {
  332. $globalTitle = $globalValue;
  333. }
  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";
  344. }
  345. echo " </select>\n";
  346. }
  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";
  354. }
  355. else {
  356. echo " </td></tr>\n";
  357. }
  358. ++$i;
  359. }
  360. }
  361. echo " </table>\n";
  362. echo " </div>\n";
  363. }
  364. }
  365. ?>
  366. </div>
  367. <p>
  368. <input type='submit' name='form_save' value='<?php xl('Save','e'); ?>' />
  369. </p>
  370. </center>
  371. </form>
  372. </body>
  373. <script language="JavaScript">
  374. $(document).ready(function(){
  375. tabbify();
  376. enable_modals();
  377. // Use the counter ($i) to make the form user friendly for user-specific globals use
  378. <?php if ($_GET['mode'] == "user") { ?>
  379. <?php for ($j = 0; $j <= $i; $j++) { ?>
  380. $("#form_<?php echo $j ?>").change(function() {
  381. $("#toggle_<?php echo $j ?>").attr('checked',false);
  382. });
  383. $("#toggle_<?php echo $j ?>").change(function() {
  384. if ($('#toggle_<?php echo $j ?>').attr('checked')) {
  385. var defaultGlobal = $("#globaldefault_<?php echo $j ?>").val();
  386. $("#form_<?php echo $j ?>").val(defaultGlobal);
  387. }
  388. });
  389. <?php } ?>
  390. <?php } ?>
  391. });
  392. </script>
  393. </html>