MedEx Updates
[openemr.git] / interface / super / edit_globals.php
blob5da3ae02a316650c436921540e7ede1573de8f40
1 <?php
2 /**
3 * Script for the globals editor.
5 * @package OpenEMR
6 * @link http://www.open-emr.org
7 * @author Rod Roark <rod@sunsetsystems.com>
8 * @author Brady Miller <brady.g.miller@gmail.com>
9 * @copyright Copyright (c) 2010 Rod Roark <rod@sunsetsystems.com>
10 * @copyright Copyright (c) 2016-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("../../custom/code_types.inc.php");
17 require_once("$srcdir/acl.inc");
18 require_once("$srcdir/globals.inc.php");
19 require_once("$srcdir/user.inc");
20 require_once("$srcdir/log.inc");
21 require_once(dirname(__FILE__)."/../../myportal/soap_service/portal_connectivity.php");
23 use OpenEMR\Core\Header;
25 $userMode = (array_key_exists('mode', $_GET) && $_GET['mode'] == 'user');
27 if (!$userMode) {
28 // Check authorization.
29 $thisauth = acl_check('admin', 'super');
30 if (!$thisauth) {
31 die(xlt('Not authorized'));
35 function checkCreateCDB()
37 $globalsres = sqlStatement("SELECT gl_name, gl_index, gl_value FROM globals WHERE gl_name IN
38 ('couchdb_host','couchdb_user','couchdb_pass','couchdb_port','couchdb_dbase','document_storage_method')");
39 $options = array();
40 while ($globalsrow = sqlFetchArray($globalsres)) {
41 $GLOBALS[$globalsrow['gl_name']] = $globalsrow['gl_value'];
44 $directory_created = false;
45 if (!empty($GLOBALS['document_storage_method'])) {
46 // /documents/temp/ folder is required for CouchDB
47 if (!is_dir($GLOBALS['OE_SITE_DIR'] . '/documents/temp/')) {
48 $directory_created = mkdir($GLOBALS['OE_SITE_DIR'] . '/documents/temp/', 0777, true);
49 if (!$directory_created) {
50 echo xlt("Failed to create temporary folder. CouchDB will not work.");
54 $couch = new CouchDB();
55 if (!$couch->check_connection()) {
56 echo "<script type='text/javascript'>alert('".addslashes(xl("CouchDB Connection Failed."))."');</script>";
57 return false;
60 if ($GLOBALS['couchdb_host'] || $GLOBALS['couchdb_port'] || $GLOBALS['couchdb_dbase']) {
61 $couch->createDB($GLOBALS['couchdb_dbase']);
62 $couch->createView($GLOBALS['couchdb_dbase']);
66 return true;
69 /**
70 * Update background_services table for a specific service following globals save.
71 * @author EMR Direct
73 function updateBackgroundService($name, $active, $interval)
75 //order important here: next_run change dependent on _old_ value of execute_interval so it comes first
76 $sql = 'UPDATE background_services SET active=?, '
77 . 'next_run = next_run + INTERVAL (? - execute_interval) MINUTE, execute_interval=? WHERE name=?';
78 return sqlStatement($sql, array($active,$interval,$interval,$name));
81 /**
82 * Make any necessary changes to background_services table when globals are saved.
83 * To prevent an unexpected service call during startup or shutdown, follow these rules:
84 * 1. Any "startup" operations should occur _before_ the updateBackgroundService() call.
85 * 2. Any "shutdown" operations should occur _after_ the updateBackgroundService() call. If these operations
86 * would cause errors in a running service call, it would be best to make the shutdown function itself is
87 * a background service that is activated here, does nothing if active=1 or running=1 for the
88 * parent service. Then it deactivates itself by setting active=0 when it is done shutting the parent service
89 * down. This will prevent non-responsiveness to the user by waiting for a service to finish.
90 * 3. If any "previous" values for globals are required for startup/shutdown logic, they need to be
91 * copied to a temp variable before the while($globalsrow...) loop.
92 * @author EMR Direct
94 function checkBackgroundServices()
96 //load up any necessary globals
97 $bgservices = sqlStatement("SELECT gl_name, gl_index, gl_value FROM globals WHERE gl_name IN
98 ('phimail_enable','phimail_interval')");
99 while ($globalsrow = sqlFetchArray($bgservices)) {
100 $GLOBALS[$globalsrow['gl_name']] = $globalsrow['gl_value'];
103 //Set up phimail service
104 $phimail_active = empty($GLOBALS['phimail_enable']) ? '0' : '1';
105 $phimail_interval = max(0, (int) $GLOBALS['phimail_interval']);
106 updateBackgroundService('phimail', $phimail_active, $phimail_interval);
110 <html>
112 <head>
113 <?php
115 // If we are saving user_specific globals.
117 if (array_key_exists('form_save', $_POST) && $_POST['form_save'] && $userMode) {
118 $i = 0;
119 foreach ($GLOBALS_METADATA as $grpname => $grparr) {
120 if (in_array($grpname, $USER_SPECIFIC_TABS)) {
121 foreach ($grparr as $fldid => $fldarr) {
122 if (in_array($fldid, $USER_SPECIFIC_GLOBALS)) {
123 list($fldname, $fldtype, $flddef, $flddesc) = $fldarr;
124 $label = "global:".$fldid;
125 $fldvalue = trim($_POST["form_$i"]);
126 setUserSetting($label, $fldvalue, $_SESSION['authId'], false);
127 if ($_POST["toggle_$i"] == "YES") {
128 removeUserSetting($label);
131 ++$i;
137 echo "<script type='text/javascript'>";
138 echo "if (parent.left_nav.location) {";
139 echo " parent.left_nav.location.reload();";
140 echo " parent.Title.location.reload();";
141 echo " if(self.name=='RTop'){";
142 echo " parent.RBot.location.reload();";
143 echo " }else{";
144 echo " parent.RTop.location.reload();";
145 echo " }";
146 echo "}";
147 echo "self.location.href='edit_globals.php?mode=user&unique=yes';";
148 echo "</script>";
151 if (array_key_exists('form_download', $_POST) && $_POST['form_download']) {
152 $client = portal_connection();
153 try {
154 $response = $client->getPortalConnectionFiles($credentials);
155 } catch (SoapFault $e) {
156 error_log('SoapFault Error');
157 error_log(var_dump(get_object_vars($e)));
158 } catch (Exception $e) {
159 error_log('Exception Error');
160 error_log(var_dump(get_object_vars($e)));
163 if (array_key_exists('status', $response) && $response['status'] == "1") {//WEBSERVICE RETURNED VALUE SUCCESSFULLY
164 $tmpfilename = realpath(sys_get_temp_dir())."/".date('YmdHis').".zip";
165 $fp = fopen($tmpfilename, "wb");
166 fwrite($fp, base64_decode($response['value']));
167 fclose($fp);
168 $practice_filename = $response['file_name'];//practicename.zip
169 ob_clean();
170 // Set headers
171 header("Cache-Control: public");
172 header("Content-Description: File Transfer");
173 header("Content-Disposition: attachment; filename=".$practice_filename);
174 header("Content-Type: application/zip");
175 header("Content-Transfer-Encoding: binary");
176 // Read the file from disk
177 readfile($tmpfilename);
178 unlink($tmpfilename);
179 exit;
180 } else {//WEBSERVICE CALL FAILED AND RETURNED AN ERROR MESSAGE
181 ob_end_clean();
183 <script type="text/javascript">
184 alert('<?php echo xls('Offsite Portal web Service Failed').":\\n".text($response['value']);?>');
185 </script>
186 <?php
191 <?php
193 // If we are saving main globals.
195 if (array_key_exists('form_save', $_POST) && $_POST['form_save'] && !$userMode) {
196 $force_off_enable_auditlog_encryption = true;
197 // Need to force enable_auditlog_encryption off if the php openssl module
198 // is not installed or the AES-256-CBC cipher is not available.
199 if (extension_loaded('openssl') && in_array('AES-256-CBC', openssl_get_cipher_methods())) {
200 $force_off_enable_auditlog_encryption = false;
203 // Aug 22, 2014: Ensoftek: For Auditable events and tamper-resistance (MU2)
204 // Check the current status of Audit Logging
205 $auditLogStatusFieldOld = $GLOBALS['enable_auditlog'];
208 * Compare form values with old database values.
209 * Only save if values differ. Improves speed.
212 // Get all the globals from DB
213 $old_globals = sqlGetAssoc('SELECT gl_name, gl_index, gl_value FROM `globals` ORDER BY gl_name, gl_index', false, true);
215 $i = 0;
216 foreach ($GLOBALS_METADATA as $grpname => $grparr) {
217 foreach ($grparr as $fldid => $fldarr) {
218 list($fldname, $fldtype, $flddef, $flddesc) = $fldarr;
219 if ($fldtype == 'pwd') {
220 $pass = sqlQuery("SELECT gl_value FROM globals WHERE gl_name = ?", array($fldid));
221 $fldvalueold = $pass['gl_value'];
224 /* Multiple choice fields - do not compare , overwrite */
225 if (!is_array($fldtype) && substr($fldtype, 0, 2) == 'm_') {
226 if (isset($_POST["form_$i"])) {
227 $fldindex = 0;
229 sqlStatement("DELETE FROM globals WHERE gl_name = ?", array( $fldid ));
231 foreach ($_POST["form_$i"] as $fldvalue) {
232 $fldvalue = trim($fldvalue);
233 sqlStatement('INSERT INTO `globals` ( gl_name, gl_index, gl_value ) VALUES ( ?,?,?)', array( $fldid, $fldindex, $fldvalue ));
234 ++$fldindex;
237 } else {
238 /* check value of single field. Don't update if the database holds the same value */
239 if (isset($_POST["form_$i"])) {
240 $fldvalue = trim($_POST["form_$i"]);
241 } else {
242 $fldvalue = "";
245 if ($fldtype=='pwd') {
246 $fldvalue = $fldvalue ? SHA1($fldvalue) : $fldvalueold; // TODO: salted passwords?
249 // We rely on the fact that set of keys in globals.inc === set of keys in `globals` table!
251 if (!isset($old_globals[$fldid]) // if the key not found in database - update database
253 ( isset($old_globals[$fldid]) && $old_globals[ $fldid ]['gl_value'] !== $fldvalue ) // if the value in database is different
255 // Need to force enable_auditlog_encryption off if the php openssl module
256 // is not installed or the AES-256-CBC cipher is not available.
257 if ($force_off_enable_auditlog_encryption && ($fldid == "enable_auditlog_encryption")) {
258 error_log("OPENEMR ERROR: UNABLE to support auditlog encryption since the php openssl module is not installed or the AES-256-CBC cipher is not available", 0);
259 $fldvalue=0;
261 if (!$force_off_enable_auditlog_encryption && ($fldid == "enable_auditlog_encryption") && ($fldvalue==1)) {
262 // Run below function to set up the encryption key
263 aes256PrepKey();
266 // special treatment for some vars
267 switch ($fldid) {
268 case 'first_day_week':
269 // update PostCalendar config as well
270 sqlStatement("UPDATE openemr_module_vars SET pn_value = ? WHERE pn_name = 'pcFirstDayOfWeek'", array($fldvalue));
271 break;
274 // Replace old values
275 sqlStatement('DELETE FROM `globals` WHERE gl_name = ?', array( $fldid ));
276 sqlStatement('INSERT INTO `globals` ( gl_name, gl_index, gl_value ) VALUES ( ?, ?, ? )', array( $fldid, 0, $fldvalue ));
277 } else {
278 //error_log("No need to update $fldid");
282 ++$i;
286 checkCreateCDB();
287 checkBackgroundServices();
289 // July 1, 2014: Ensoftek: For Auditable events and tamper-resistance (MU2)
290 // If Audit Logging status has changed, log it.
291 $auditLogStatusNew = sqlQuery("SELECT gl_value FROM globals WHERE gl_name = 'enable_auditlog'");
292 $auditLogStatusFieldNew = $auditLogStatusNew['gl_value'];
293 if ($auditLogStatusFieldOld != $auditLogStatusFieldNew) {
294 auditSQLAuditTamper($auditLogStatusFieldNew);
297 echo "<script type='text/javascript'>";
298 echo "if (parent.left_nav.location) {";
299 echo " parent.left_nav.location.reload();";
300 echo " parent.Title.location.reload();";
301 echo " if(self.name=='RTop'){";
302 echo " parent.RBot.location.reload();";
303 echo " }else{";
304 echo " parent.RTop.location.reload();";
305 echo " }";
306 echo "}";
307 echo "self.location.href='edit_globals.php?unique=yes';";
308 echo "</script>";
312 <?php if ($userMode) { ?>
313 <title><?php echo xlt('User Settings'); ?></title>
314 <?php } else { ?>
315 <title><?php echo xlt('Global Settings'); ?></title>
316 <?php } ?>
318 <?php Header::setupHeader(['common','jscolor']); ?>
320 <script type="text/javascript">
321 function validate_file(){
322 $.ajax({
323 type: "POST",
324 url: "<?php echo $GLOBALS['webroot']?>/library/ajax/offsite_portal_ajax.php",
325 data: {
326 action: 'check_file'
328 cache: false,
329 success: function( message )
331 if(message == 'OK'){
332 document.getElementById('form_download').value = 1;
333 document.getElementById('file_error_message').innerHTML = '';
334 document.forms[0].submit();
336 else{
337 document.getElementById('form_download').value = 0;
338 document.getElementById('file_error_message').innerHTML = message;
339 return false;
344 </script>
345 </head>
347 <?php if ($userMode) { ?>
348 <body class="body_top" style="min-width: 700px;">
349 <?php } else { ?>
350 <div class="body_top">
351 <?php } ?>
353 <?php if ($userMode) { ?>
354 <form method='post' name='theform' id='theform' class='form-horizontal' action='edit_globals.php?mode=user' onsubmit='return top.restoreSession()'>
355 <?php } else { ?>
356 <form method='post' name='theform' id='theform' class='form-horizontal' action='edit_globals.php' onsubmit='return top.restoreSession()'>
357 <?php } ?>
359 <div class="container">
360 <div class="row">
361 <div class="col-xs-12">
362 <div class="form-group">
363 <?php if ($userMode) { ?>
364 <h3><?php echo xlt('Edit User Settings'); ?></h3>
365 <?php } else { ?>
366 <h3><?php echo xlt('Edit Global Settings'); ?></h3>
367 <?php } ?>
368 </div>
369 </div>
370 </div>
371 <div class="row">
372 <div class="col-xs-12">
373 <div class="form-group">
374 <button type='submit' class='btn btn-default btn-save' name='form_save' value='<?php echo xla('Save'); ?>'><?php echo xlt('Save'); ?></button>
375 <div class="form-inline pull-right">
376 <?php // mdsupport - Optional server based searching mechanism for large number of fields on this screen. ?>
377 <button type='submit' class='btn btn-default btn-search' id='globals_form_search' name='form_search'><?php echo xlt('Search'); ?></button>
378 <input name='srch_desc' class='form-control' type='text' value='<?php echo (!empty($_POST['srch_desc']) ? attr($_POST['srch_desc']) : '') ?>' />
379 </div>
380 </div>
381 </div>
382 </div>
383 </div>
385 <ul class="tabNav">
386 <?php
387 $i = 0;
388 foreach ($GLOBALS_METADATA as $grpname => $grparr) {
389 if (!$userMode || in_array($grpname, $USER_SPECIFIC_TABS)) {
390 echo " <li" . ($i ? "" : " class='current'") .
391 "><a href='#'>" .
392 xlt($grpname) . "</a></li>\n";
393 ++$i;
397 </ul>
399 <div class="tabContainer">
400 <?php
401 $i = 0;
402 foreach ($GLOBALS_METADATA as $grpname => $grparr) {
403 if (!$userMode || in_array($grpname, $USER_SPECIFIC_TABS)) {
404 echo " <div class='tab" . ($i ? "" : " current") .
405 "' style='height:auto;width:97%;'>\n";
407 echo "<div class='container'>";
409 if ($userMode) {
410 echo "<div class='row'>";
411 echo "<div class='col-xs-5'>&nbsp</div>";
412 echo "<div class='col-xs-4'><b>" . xlt('User Specific Setting') . "</b></div>";
413 echo "<div class='col-xs-2'><b>" . xlt('Default Setting') . "</b></div>";
414 echo "<div class='col-xs-1'><b>" . xlt('Default') . "</b></div>";
415 echo "</div>";
418 foreach ($grparr as $fldid => $fldarr) {
419 if (!$userMode || in_array($fldid, $USER_SPECIFIC_GLOBALS)) {
420 list($fldname, $fldtype, $flddef, $flddesc) = $fldarr;
421 // mdsupport - Check for matches
422 $srch_cl = '';
423 if (!empty($_POST['srch_desc']) && (stristr(($fldname.$flddesc), $_POST['srch_desc']) !== false)) {
424 $srch_cl = ' srch';
427 // Most parameters will have a single value, but some will be arrays.
428 // Here we cater to both possibilities.
429 $glres = sqlStatement("SELECT gl_index, gl_value FROM globals WHERE " .
430 "gl_name = ? ORDER BY gl_index", array($fldid));
431 $glarr = array();
432 while ($glrow = sqlFetchArray($glres)) {
433 $glarr[] = $glrow;
436 // $fldvalue is meaningful only for the single-value cases.
437 $fldvalue = count($glarr) ? $glarr[0]['gl_value'] : $flddef;
439 // Collect user specific setting if mode set to user
440 $userSetting = "";
441 $settingDefault = "checked='checked'";
442 if ($userMode) {
443 $userSettingArray = sqlQuery("SELECT * FROM user_settings WHERE setting_user=? AND setting_label=?", array($_SESSION['authId'],"global:".$fldid));
444 $userSetting = $userSettingArray['setting_value'];
445 $globalValue = $fldvalue;
446 if (!empty($userSettingArray)) {
447 $fldvalue = $userSetting;
448 $settingDefault = "";
452 if ($userMode) {
453 echo " <div class='row" . $srch_cl . "' title='" . attr($flddesc) . "'><div class='col-xs-5 control-label'><b>" . text($fldname) . "</b></div><div class='col-xs-4'>\n";
454 } else {
455 echo " <div class='row" . $srch_cl . "' title='" . attr($flddesc) . "'><div class='col-sm-5 control-label'><b>" . text($fldname) . "</b></div><div class='col-sm-6'>\n";
458 if (is_array($fldtype)) {
459 echo " <select class='form-control' name='form_$i' id='form_$i'>\n";
460 foreach ($fldtype as $key => $value) {
461 if ($userMode) {
462 if ($globalValue == $key) {
463 $globalTitle = $value;
467 echo " <option value='" . attr($key) . "'";
469 //Casting value to string so the comparison will be always the same type and the only thing that will check is the value
470 //Tried to use === but it will fail in already existing variables
471 if ((string)$key == (string)$fldvalue) {
472 echo " selected";
475 echo ">";
476 echo text($value);
477 echo "</option>\n";
480 echo " </select>\n";
481 } else if ($fldtype == 'bool') {
482 if ($userMode) {
483 if ($globalValue == 1) {
484 $globalTitle = xlt('Checked');
485 } else {
486 $globalTitle = xlt('Not Checked');
490 echo " <input type='checkbox' class='checkbox' name='form_$i' id='form_$i' value='1'";
491 if ($fldvalue) {
492 echo " checked";
495 echo " />\n";
496 } else if ($fldtype == 'num') {
497 if ($userMode) {
498 $globalTitle = $globalValue;
501 echo " <input type='text' class='form-control' name='form_$i' id='form_$i' " .
502 "maxlength='15' value='" . attr($fldvalue) . "' />\n";
503 } else if ($fldtype == 'text') {
504 if ($userMode) {
505 $globalTitle = $globalValue;
508 echo " <input type='text' class='form-control' name='form_$i' id='form_$i' " .
509 "maxlength='255' value='" . attr($fldvalue) . "' />\n";
510 } else if ($fldtype == 'pwd') {
511 if ($userMode) {
512 $globalTitle = $globalValue;
515 echo " <input type='password' class='form-control' name='form_$i' " .
516 "maxlength='255' value='' />\n";
517 } else if ($fldtype == 'pass') {
518 if ($userMode) {
519 $globalTitle = $globalValue;
522 echo " <input type='password' class='form-control' name='form_$i' " .
523 "maxlength='255' value='" . attr($fldvalue) . "' />\n";
524 } else if ($fldtype == 'lang') {
525 $res = sqlStatement("SELECT * FROM lang_languages ORDER BY lang_description");
526 echo " <select class='form-control' name='form_$i' id='form_$i'>\n";
527 while ($row = sqlFetchArray($res)) {
528 echo " <option value='" . attr($row['lang_description']) . "'";
529 if ($row['lang_description'] == $fldvalue) {
530 echo " selected";
533 echo ">";
534 echo xlt($row['lang_description']);
535 echo "</option>\n";
538 echo " </select>\n";
539 } else if ($fldtype == 'all_code_types') {
540 global $code_types;
541 echo " <select class='form-control' name='form_$i' id='form_$i'>\n";
542 foreach (array_keys($code_types) as $code_key) {
543 echo " <option value='" . attr($code_key) . "'";
544 if ($code_key == $fldvalue) {
545 echo " selected";
548 echo ">";
549 echo xlt($code_types[$code_key]['label']);
550 echo "</option>\n";
553 echo " </select>\n";
554 } else if ($fldtype == 'm_lang') {
555 $res = sqlStatement("SELECT * FROM lang_languages ORDER BY lang_description");
556 echo " <select multiple class='form-control' name='form_{$i}[]' id='form_{$i}[]' size='3'>\n";
557 while ($row = sqlFetchArray($res)) {
558 echo " <option value='" . attr($row['lang_description']) . "'";
559 foreach ($glarr as $glrow) {
560 if ($glrow['gl_value'] == $row['lang_description']) {
561 echo " selected";
562 break;
566 echo ">";
567 echo xlt($row['lang_description']);
568 echo "</option>\n";
571 echo " </select>\n";
572 } else if ($fldtype == 'color_code') {
573 if ($userMode) {
574 $globalTitle = $globalValue;
577 echo " <input type='text' class='form-control jscolor {hash:true}' name='form_$i' id='form_$i' " .
578 "maxlength='15' value='" . attr($fldvalue) . "' />" .
579 "<input type='button' value='" . xla('Default'). "' onclick=\"document.forms[0].form_$i.jscolor.fromString('" . attr($flddef) . "')\">\n";
580 } else if ($fldtype == 'default_visit_category') {
581 $sql = "SELECT pc_catid, pc_catname, pc_cattype
582 FROM openemr_postcalendar_categories
583 WHERE pc_active = 1 ORDER BY pc_seq";
584 $result = sqlStatement($sql);
585 echo "<select class='form-control' name='form_{$i}' id='form_{$i}'>\n";
586 echo "<option value='_blank'>" . xlt('None') . "</option>";
587 while ($row = sqlFetchArray($result)) {
588 $catId = $row['pc_catid'];
589 $name = $row['pc_catname'];
590 if ($catId < 9 && $catId != "5") {
591 continue;
594 if ($row['pc_cattype'] == 3 && !$GLOBALS['enable_group_therapy']) {
595 continue;
598 $optionStr = '<option value="%pc_catid%"%selected%>%pc_catname%</option>';
599 $optionStr = str_replace("%pc_catid%", attr($catId), $optionStr);
600 $optionStr = str_replace("%pc_catname%", text(xl_appt_category($name)), $optionStr);
601 $selected = ($fldvalue == $catId) ? " selected" : "";
602 $optionStr = str_replace("%selected%", $selected, $optionStr);
603 echo $optionStr;
606 echo "</select>";
607 } else if ($fldtype == 'css' || $fldtype == 'tabs_css') {
608 if ($userMode) {
609 $globalTitle = $globalValue;
611 $themedir = "$webserver_root/interface/themes";
612 $dh = opendir($themedir);
613 if ($dh) {
614 // Collect styles
615 $styleArray = array();
616 while (false !== ($tfname = readdir($dh))) {
617 // Only show files that contain tabs_style_ or style_ as options
618 if ($fldtype == 'tabs_css') {
619 $patternStyle = 'tabs_style_';
620 } else { // $fldtype == 'css'
621 $patternStyle = 'style_';
623 if ($tfname == 'style_blue.css' ||
624 $tfname == 'style_pdf.css' ||
625 !preg_match("/^" . $patternStyle . ".*\.css$/", $tfname)) {
626 continue;
629 if ($fldtype == 'tabs_css') {
630 // Drop the "tabs_style_" part and any replace any underscores with spaces
631 $styleDisplayName = str_replace("_", " ", substr($tfname, 11));
632 } else { // $fldtype == 'css'
633 // Drop the "style_" part and any replace any underscores with spaces
634 $styleDisplayName = str_replace("_", " ", substr($tfname, 6));
636 // Strip the ".css" and uppercase the first character
637 $styleDisplayName = ucfirst(str_replace(".css", "", $styleDisplayName));
639 $styleArray[$tfname] = $styleDisplayName;
641 // Alphabetize styles
642 asort($styleArray);
643 // Generate style selector
644 echo "<select class='form-control' name='form_$i' id='form_$i'>\n";
645 foreach ($styleArray as $styleKey => $styleValue) {
646 echo "<option value='" . attr($styleKey) . "'";
647 if ($styleKey == $fldvalue) {
648 echo " selected";
650 echo ">";
651 echo text($styleValue);
652 echo "</option>\n";
654 echo "</select>\n";
656 closedir($dh);
657 } else if ($fldtype == 'hour') {
658 if ($userMode) {
659 $globalTitle = $globalValue;
662 echo " <select class='form-control' name='form_$i' id='form_$i'>\n";
663 for ($h = 0; $h < 24; ++$h) {
664 echo "<option value='$h'";
665 if ($h == $fldvalue) {
666 echo " selected";
669 echo ">";
670 if ($h == 0) {
671 echo "12 AM";
672 } else if ($h < 12) {
673 echo "$h AM";
674 } else if ($h == 12) {
675 echo "12 PM";
676 } else {
677 echo ($h - 12) . " PM";
680 echo "</option>\n";
683 echo " </select>\n";
686 if ($userMode) {
687 echo " </div>\n";
688 echo "<div class='col-xs-2' style='color:red;'>" . attr($globalTitle) . "</div>\n";
689 echo "<div class='col-xs-1'><input type='checkbox' value='YES' name='toggle_" . $i . "' id='toggle_" . $i . "' " . attr($settingDefault) . "/></div>\n";
690 echo "<input type='hidden' id='globaldefault_" . $i . "' value='" . attr($globalValue) . "'>\n";
691 echo "</div>\n";
692 } else {
693 echo " </div></div>\n";
696 ++$i;
699 if (trim(strtolower($fldid)) == 'portal_offsite_address_patient_link' && !empty($GLOBALS['portal_offsite_enable']) && !empty($GLOBALS['portal_offsite_providerid'])) {
700 echo "<div class='row'>";
701 echo "<div class='col-xs-12'>";
702 echo "<input type='hidden' name='form_download' id='form_download'>";
703 echo "<button onclick=\"return validate_file()\" type='button'>" . xla('Download Offsite Portal Connection Files') . "</button>";
704 echo "<div id='file_error_message' class='alert alert-error'></div>";
705 echo "</div>";
706 echo "</div>";
710 echo " </div>\n";
711 echo " </div>\n";
715 </div>
717 </form>
719 </div>
720 </body>
722 <script language="JavaScript">
724 $(document).ready(function(){
725 tabbify();
727 <?php // mdsupport - Highlight search results ?>
728 $('.srch div').wrapInner("<mark></mark>");
729 $('.tab .row.srch :first-child').closest('.tab').each(function() {
730 $('.tabNav li:nth-child('+($(this).index()+1)+') a').wrapInner("<mark></mark>");
732 // Use the counter ($i) to make the form user friendly for user-specific globals use
733 <?php if ($userMode) { ?>
734 <?php for ($j = 0; $j <= $i; $j++) { ?>
735 $("#form_<?php echo $j ?>").change(function() {
736 $("#toggle_<?php echo $j ?>").prop('checked',false);
738 $("#toggle_<?php echo $j ?>").change(function() {
739 if ($('#toggle_<?php echo $j ?>').prop('checked')) {
740 var defaultGlobal = $("#globaldefault_<?php echo $j ?>").val();
741 $("#form_<?php echo $j ?>").val(defaultGlobal);
744 <?php } ?>
745 <?php } ?>
749 </script>
751 </html>