random patient generator updates and ccda import php8 and other misc stuff (#4495)
[openemr.git] / interface / globals.php
blob4e0dc47e69335e105483e47afe860f739dd5b6ac
1 <?php
3 /**
4 * Default values for optional variables that are allowed to be set by callers.
6 * @package OpenEMR
7 * @link http://www.open-emr.org
8 * @author Brady Miller <brady.g.miller@gmail.com>
9 * @author Rod Roark <rod@sunsetsystems.com>
10 * @copyright Copyright (c) 2018-2019 Brady Miller <brady.g.miller@gmail.com>
11 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
14 // Checks if the server's PHP version is compatible with OpenEMR:
15 require_once(__DIR__ . "/../src/Common/Compatibility/Checker.php");
16 $response = OpenEMR\Common\Compatibility\Checker::checkPhpVersion();
17 if ($response !== true) {
18 die(htmlspecialchars($response));
21 use OpenEMR\Core\Kernel;
22 use OpenEMR\Core\ModulesApplication;
23 use Dotenv\Dotenv;
25 // Throw error if the php openssl module is not installed.
26 if (!(extension_loaded('openssl'))) {
27 error_log("OPENEMR ERROR: OpenEMR is not working since the php openssl module is not installed.", 0);
28 die("OpenEMR Error : OpenEMR is not working since the php openssl module is not installed.");
30 // Throw error if the openssl aes-256-cbc cipher is not available.
31 if (!(in_array('aes-256-cbc', openssl_get_cipher_methods()))) {
32 error_log("OPENEMR ERROR: OpenEMR is not working since the openssl aes-256-cbc cipher is not available.", 0);
33 die("OpenEMR Error : OpenEMR is not working since the openssl aes-256-cbc cipher is not available.");
37 //This is to help debug the ssl mysql connection. This will send messages to php log to show if mysql connections have a cipher set up.
38 $GLOBALS['debug_ssl_mysql_connection'] = false;
40 // Unless specified explicitly, apply Auth functions
41 if (!isset($ignoreAuth)) {
42 $ignoreAuth = false;
45 // Same for onsite
46 if (!isset($ignoreAuth_onsite_portal)) {
47 $ignoreAuth_onsite_portal = false;
50 // Is this windows or non-windows? Create a boolean definition.
51 if (!defined('IS_WINDOWS')) {
52 define('IS_WINDOWS', (stripos(PHP_OS, 'WIN') === 0));
55 // The webserver_root and web_root are now automatically collected.
56 // If not working, can set manually below.
57 // Auto collect the full absolute directory path for openemr.
58 $webserver_root = dirname(__FILE__, 2);
59 if (IS_WINDOWS) {
60 //convert windows path separators
61 $webserver_root = str_replace("\\", "/", $webserver_root);
64 // Collect the apache server document root (and convert to windows slashes, if needed)
65 $server_document_root = realpath($_SERVER['DOCUMENT_ROOT']);
66 if (IS_WINDOWS) {
67 //convert windows path separators
68 $server_document_root = str_replace("\\", "/", $server_document_root);
71 // Auto collect the relative html path, i.e. what you would type into the web
72 // browser after the server address to get to OpenEMR.
73 // This removes the leading portion of $webserver_root that it has in common with the web server's document
74 // root and assigns the result to $web_root. In addition to the common case where $webserver_root is
75 // /var/www/openemr and document root is /var/www, this also handles the case where document root is
76 // /var/www/html and there is an Apache "Alias" command that directs /openemr to /var/www/openemr.
77 $web_root = substr($webserver_root, strspn($webserver_root ^ $server_document_root, "\0"));
78 // Ensure web_root starts with a path separator
79 if (preg_match("/^[^\/]/", $web_root)) {
80 $web_root = "/" . $web_root;
83 // The webserver_root and web_root are now automatically collected in
84 // real time per above code. If above is not working, can uncomment and
85 // set manually here:
86 // $webserver_root = "/var/www/openemr";
87 // $web_root = "/openemr";
89 // Debug function. Can expand for longer trace or file info.
90 function GetCallingScriptName()
92 $e = new Exception();
93 return $e->getTrace()[1]['file'];
96 // This is the directory that contains site-specific data. Change this
97 // only if you have some reason to.
98 $GLOBALS['OE_SITES_BASE'] = "$webserver_root/sites";
101 * If a session does not yet exist, then will start the core OpenEMR session.
102 * If a session already exists, then this means portal or oauth2 or api is being used, which
103 * has already created a portal session/cookie, so will bypass setting of
104 * the core OpenEMR session/cookie.
105 * $sessionAllowWrite = 1 | true | string then normal operation
106 * $sessionAllowWrite = undefined | null | 0 session start for read only then auto
107 * immediate session_write_close.
108 * Unless $sessionAllowWrite is true, ensure no session writes are used within the calling
109 * scope of this globals instance. Goal is to unlock session file as quickly as possible
110 * instead of waiting for calling script to complete before releasing flock.
112 $read_only = empty($sessionAllowWrite);
113 if (session_status() === PHP_SESSION_NONE) {
114 //error_log("1. LOCK ".GetCallingScriptName()); // debug start lock
115 require_once(__DIR__ . "/../src/Common/Session/SessionUtil.php");
116 OpenEMR\Common\Session\SessionUtil::coreSessionStart($web_root, $read_only);
117 //error_log("2. FREE ".GetCallingScriptName()); // debug unlocked
120 // Set the site ID if required. This must be done before any database
121 // access is attempted.
122 if (empty($_SESSION['site_id']) || !empty($_GET['site'])) {
123 if (!empty($_GET['site'])) {
124 $tmp = $_GET['site'];
125 } else {
126 if (empty($ignoreAuth) && empty($ignoreAuth_onsite_portal)) {
127 // mdsupport - Don't die if logout menu link is called from expired session.
128 // Eliminate this code when close method is available for session management.
129 if ((isset($_GET['auth'])) && ($_GET['auth'] == "logout")) {
130 $GLOBALS['login_screen'] = "login_screen.php";
131 $srcdir = "../library";
132 require_once("$srcdir/auth.inc");
134 die("Site ID is missing from session data!");
137 $tmp = $_SERVER['HTTP_HOST'];
138 if (!is_dir($GLOBALS['OE_SITES_BASE'] . "/$tmp")) {
139 $tmp = "default";
143 // for both REST API and browser access we can't proceed unless we have a valid site id.
144 // since this is user provided content we need to escape the value but we use htmlspecialchars instead
145 // of text() as our helper functions are loaded in later on in this file.
146 if (empty($tmp) || preg_match('/[^A-Za-z0-9\\-.]/', $tmp)) {
147 echo "Invalid URL";
148 error_log("Request with site id '" . htmlspecialchars($tmp, ENT_QUOTES) . "' contains invalid characters.");
149 die();
152 if (isset($_SESSION['site_id']) && ($_SESSION['site_id'] != $tmp)) {
153 // This is to prevent using session to penetrate other OpenEMR instances within same multisite module
154 session_unset(); // clear session, clean logout
155 if (isset($landingpage) && !empty($landingpage)) {
156 // OpenEMR Patient Portal use
157 header('Location: index.php?site=' . urlencode($tmp));
158 } else {
159 // Main OpenEMR use
160 header('Location: ../login/login.php?site=' . urlencode($tmp)); // Assuming in the interface/main directory
163 exit;
166 if (!isset($_SESSION['site_id']) || $_SESSION['site_id'] != $tmp) {
167 $_SESSION['site_id'] = $tmp;
168 // error_log("Session site ID has been set to '$tmp'"); // debugging
172 // Set the site-specific directory path.
173 $GLOBALS['OE_SITE_DIR'] = $GLOBALS['OE_SITES_BASE'] . "/" . $_SESSION['site_id'];
175 // Set a site-specific uri root path.
176 $GLOBALS['OE_SITE_WEBROOT'] = $web_root . "/sites/" . $_SESSION['site_id'];
178 // Collecting the utf8 disable flag from the sqlconf.php file in order
179 // to set the correct html encoding. utf8 vs iso-8859-1. If flag is set
180 // then set to iso-8859-1.
181 require_once(__DIR__ . "/../library/sqlconf.php");
182 if (!$disable_utf8_flag) {
183 ini_set('default_charset', 'utf-8');
184 $HTML_CHARSET = "UTF-8";
185 mb_internal_encoding('UTF-8');
186 } else {
187 ini_set('default_charset', 'iso-8859-1');
188 $HTML_CHARSET = "ISO-8859-1";
189 mb_internal_encoding('ISO-8859-1');
192 // Root directory, relative to the webserver root:
193 $GLOBALS['rootdir'] = "$web_root/interface";
194 $rootdir = $GLOBALS['rootdir'];
195 // Absolute path to the source code include and headers file directory (Full path):
196 $GLOBALS['srcdir'] = "$webserver_root/library";
197 // Absolute path to the location of documentroot directory for use with include statements:
198 $GLOBALS['fileroot'] = "$webserver_root";
199 // Absolute path to the location of interface directory for use with include statements:
200 $include_root = "$webserver_root/interface";
201 // Absolute path to the location of documentroot directory for use with include statements:
202 $GLOBALS['webroot'] = $web_root;
204 // Static assets directory, relative to the webserver root.
205 // (it is very likely that this path will be changed in the future))
206 $GLOBALS['assets_static_relative'] = "$web_root/public/assets";
208 // Relative themes directory, relative to the webserver root.
209 $GLOBALS['themes_static_relative'] = "$web_root/public/themes";
211 // Relative images directory, relative to the webserver root.
212 $GLOBALS['images_static_relative'] = "$web_root/public/images";
214 // Static images directory, absolute to the webserver root.
215 $GLOBALS['images_static_absolute'] = "$webserver_root/public/images";
217 //Composer vendor directory, absolute to the webserver root.
218 $GLOBALS['vendor_dir'] = "$webserver_root/vendor";
219 $GLOBALS['fonts_dir'] = "{$web_root}/public/fonts";
220 $GLOBALS['template_dir'] = $GLOBALS['fileroot'] . "/templates/";
221 $GLOBALS['incdir'] = $include_root;
222 // Location of the login screen file
223 $GLOBALS['login_screen'] = $GLOBALS['rootdir'] . "/login_screen.php";
225 // Variable set for Eligibility Verification [EDI-271] path
226 $GLOBALS['edi_271_file_path'] = $GLOBALS['OE_SITE_DIR'] . "/documents/edi/";
228 // Check necessary writable paths (add them if do not exist)
229 if (! is_dir($GLOBALS['OE_SITE_DIR'] . '/documents/smarty/gacl')) {
230 mkdir($GLOBALS['OE_SITE_DIR'] . '/documents/smarty/gacl', 0755, true);
232 if (! is_dir($GLOBALS['OE_SITE_DIR'] . '/documents/smarty/main')) {
233 mkdir($GLOBALS['OE_SITE_DIR'] . '/documents/smarty/main', 0755, true);
236 // Set and check that necessary writeable path exist for mPDF tool
237 $GLOBALS['MPDF_WRITE_DIR'] = $GLOBALS['OE_SITE_DIR'] . '/documents/mpdf/pdf_tmp';
238 if (! is_dir($GLOBALS['MPDF_WRITE_DIR'])) {
239 mkdir($GLOBALS['MPDF_WRITE_DIR'], 0755, true);
242 // Includes composer autoload
243 // Note this also brings in following library files:
244 // library/htmlspecialchars.inc.php - Include convenience functions with shorter names than "htmlspecialchars" (for security)
245 // library/formdata.inc.php - Include sanitization/checking functions (for security)
246 // library/sanitize.inc.php - Include sanitization/checking functions (for security)
247 // library/formatting.inc.php - Includes functions for date/time internationalization and formatting
248 // library/date_functions.php - Includes functions for date internationalization
249 // library/validation/validate_core.php - Includes functions for page validation
250 // library/translation.inc.php - Includes translation functions
251 require_once $GLOBALS['vendor_dir'] . "/autoload.php";
254 * @var Dotenv Allow a `.env` file to be read in and applied as $_SERVER variables.
256 * This allows to define a "development" environment which can then load up
257 * different variables and reporting/debugging functionality. Should be used in
258 * development only, not for production
260 * @link http://open-emr.org/wiki/index.php/Dotenv_Usage
262 if (file_exists("{$webserver_root}/.env")) {
263 $dotenv = Dotenv::createImmutable($webserver_root);
264 $dotenv->load();
267 // This will open the openemr mysql connection.
268 require_once(__DIR__ . "/../library/sql.inc");
270 // Include the version file
271 require_once(__DIR__ . "/../version.php");
273 // The logging level for common/logging/logger.php
274 // Value can be TRACE, DEBUG, INFO, WARN, ERROR, or OFF:
275 // - DEBUG/INFO are great for development
276 // - INFO/WARN/ERROR are great for production
277 // - TRACE is useful when debugging hard to spot bugs
278 $GLOBALS["log_level"] = "OFF";
280 try {
281 /** @var Kernel */
282 $GLOBALS["kernel"] = new Kernel();
283 } catch (\Exception $e) {
284 error_log(errorLogEscape($e->getMessage()));
285 die();
288 // Defaults for specific applications.
289 $GLOBALS['weight_loss_clinic'] = false;
290 $GLOBALS['ippf_specific'] = false;
292 // Defaults for drugs and products.
293 $GLOBALS['inhouse_pharmacy'] = false;
294 $GLOBALS['sell_non_drug_products'] = 0;
296 $glrow = sqlQueryNoLog("SHOW TABLES LIKE 'globals'");
297 if (!empty($glrow)) {
298 // Collect user specific settings from user_settings table.
300 $gl_user = array();
301 // Collect the user id first
302 $temp_authuserid = '';
303 if (!empty($_SESSION['authUserID'])) {
304 //Set the user id from the session variable
305 $temp_authuserid = $_SESSION['authUserID'];
306 } else {
307 if (!empty($_POST['authUser'])) {
308 $temp_sql_ret = sqlQueryNoLog("SELECT `id` FROM `users` WHERE BINARY `username` = ?", array($_POST['authUser']));
309 if (!empty($temp_sql_ret['id'])) {
310 //Set the user id from the login variable
311 $temp_authuserid = $temp_sql_ret['id'];
316 if (!empty($temp_authuserid)) {
317 $glres_user = sqlStatementNoLog(
318 "SELECT `setting_label`, `setting_value` " .
319 "FROM `user_settings` " .
320 "WHERE `setting_user` = ? " .
321 "AND `setting_label` LIKE 'global:%'",
322 array($temp_authuserid)
324 for ($iter = 0; $row = sqlFetchArray($glres_user); $iter++) {
325 //remove global_ prefix from label
326 $row['setting_label'] = substr($row['setting_label'], 7);
327 $gl_user[$iter] = $row;
331 // Set global parameters from the database globals table.
332 // Some parameters require custom handling.
334 $GLOBALS['language_menu_show'] = array();
335 $glres = sqlStatementNoLog(
336 "SELECT gl_name, gl_index, gl_value FROM globals " .
337 "ORDER BY gl_name, gl_index"
339 while ($glrow = sqlFetchArray($glres)) {
340 $gl_name = $glrow['gl_name'];
341 $gl_value = $glrow['gl_value'];
342 // Adjust for user specific settings
343 if (!empty($gl_user)) {
344 foreach ($gl_user as $setting) {
345 if ($gl_name == $setting['setting_label']) {
346 $gl_value = $setting['setting_value'];
351 if ($gl_name == 'language_menu_other') {
352 $GLOBALS['language_menu_show'][] = $gl_value;
353 } elseif ($gl_name == 'css_header') {
354 //Escape css file name using 'attr' for security (prevent XSS).
355 $GLOBALS[$gl_name] = $web_root . '/public/themes/' . attr($gl_value) . '?v=' . $v_js_includes;
356 $GLOBALS['compact_header'] = $web_root . '/public/themes/compact_' . attr($gl_value) . '?v=' . $v_js_includes;
357 $compact_header = $GLOBALS['compact_header'];
358 $css_header = $GLOBALS[$gl_name];
359 $temp_css_theme_name = $gl_value;
360 } elseif ($gl_name == 'weekend_days') {
361 $GLOBALS[$gl_name] = explode(',', $gl_value);
362 } elseif ($gl_name == 'specific_application') {
363 if ($gl_value == '2') {
364 $GLOBALS['ippf_specific'] = true;
365 } elseif ($gl_value == '3') {
366 $GLOBALS['weight_loss_clinic'] = true;
368 } elseif ($gl_name == 'inhouse_pharmacy') {
369 if ($gl_value) {
370 $GLOBALS['inhouse_pharmacy'] = true;
373 if ($gl_value == '2') {
374 $GLOBALS['sell_non_drug_products'] = 1;
375 } elseif ($gl_value == '3') {
376 $GLOBALS['sell_non_drug_products'] = 2;
378 } elseif ($gl_name == 'gbl_time_zone') {
379 // The default PHP time zone is set here if it was specified, and is used
380 // as source data for the MySQL time zone here and in some other places
381 // where MySQL connections are opened.
382 if ($gl_value) {
383 date_default_timezone_set($gl_value);
386 // Synchronize MySQL time zone with PHP time zone.
387 sqlStatementNoLog("SET time_zone = ?", array((new DateTime())->format("P")));
388 } else {
389 $GLOBALS[$gl_name] = $gl_value;
393 // Language cleanup stuff.
394 $GLOBALS['language_menu_login'] = false;
395 if ((count($GLOBALS['language_menu_show']) > 1) || $GLOBALS['language_menu_showall']) {
396 $GLOBALS['language_menu_login'] = true;
399 // Added this $GLOBALS['concurrent_layout'] set to 3 in order to support legacy forms
400 // that may use this; note this global has been removed from the standard codebase.
401 $GLOBALS['concurrent_layout'] = 3;
403 // Additional logic to override theme name.
404 // For RTL languages we substitute the theme name with the name of RTL-adapted CSS file.
405 $rtl_override = false;
406 if (isset($_SESSION['language_direction'])) {
407 if (
408 $_SESSION['language_direction'] == 'rtl' &&
409 !strpos($GLOBALS['css_header'], 'rtl')
411 // the $css_header_value is set above
412 $rtl_override = true;
414 } elseif (isset($_SESSION['language_choice'])) {
415 //this will support the onsite patient portal which will have a language choice but not yet a set language direction
416 $_SESSION['language_direction'] = getLanguageDir($_SESSION['language_choice']);
417 if (
418 $_SESSION['language_direction'] == 'rtl' &&
419 !strpos($GLOBALS['css_header'], 'rtl')
421 // the $css_header_value is set above
422 $rtl_override = true;
424 } else {
425 //$_SESSION['language_direction'] is not set, so will use the default language
426 $default_lang_id = sqlQueryNoLog('SELECT lang_id FROM lang_languages WHERE lang_description = ?', array($GLOBALS['language_default']));
428 if (getLanguageDir($default_lang_id['lang_id']) === 'rtl' && !strpos($GLOBALS['css_header'], 'rtl')) {
429 // @todo eliminate 1 SQL query
430 $rtl_override = true;
435 // change theme name, if the override file exists.
436 if ($rtl_override) {
437 // the $css_header_value is set above
438 $new_theme = 'rtl_' . $temp_css_theme_name;
440 // Check file existance
441 if (file_exists($webserver_root . '/public/themes/' . $new_theme)) {
442 //Escape css file name using 'attr' for security (prevent XSS).
443 $GLOBALS['css_header'] = $web_root . '/public/themes/' . attr($new_theme) . '?v=' . $v_js_includes;
444 $css_header = $GLOBALS['css_header'];
445 $GLOBALS['compact_header'] = $web_root . '/public/themes/rtl_compact_' . attr($temp_css_theme_name) . '?v=' . $v_js_includes;
446 $compact_header = $GLOBALS['compact_header'];
447 } else {
448 // throw a warning if rtl'ed file does not exist.
449 error_log("Missing theme file " . errorLogEscape($webserver_root) . '/public/themes/' . errorLogEscape($new_theme));
453 unset($temp_css_theme_name, $new_theme, $rtl_override);
454 // end of RTL section
457 // End of globals table processing.
458 } else {
459 // Temporary stuff to handle the case where the globals table does not
460 // exist yet. This will happen in sql_upgrade.php on upgrading to the
461 // first release containing this table.
462 $GLOBALS['language_menu_login'] = true;
463 $GLOBALS['language_menu_showall'] = true;
464 $GLOBALS['language_menu_show'] = array('English (Standard)','Swedish');
465 $GLOBALS['language_default'] = "English (Standard)";
466 $GLOBALS['translate_layout'] = true;
467 $GLOBALS['translate_lists'] = true;
468 $GLOBALS['translate_gacl_groups'] = true;
469 $GLOBALS['translate_form_titles'] = true;
470 $GLOBALS['translate_document_categories'] = true;
471 $GLOBALS['translate_appt_categories'] = true;
472 $GLOBALS['timeout'] = 7200;
473 $openemr_name = 'OpenEMR';
474 $css_header = "$web_root/public/themes/style_default.css";
475 $GLOBALS['css_header'] = $css_header;
476 $compact_header = "$web_root/public/themes/style_default.css";
477 $GLOBALS['compact_header'] = $compact_header;
478 $GLOBALS['schedule_start'] = 8;
479 $GLOBALS['schedule_end'] = 17;
480 $GLOBALS['calendar_interval'] = 15;
481 $GLOBALS['phone_country_code'] = '1';
482 $GLOBALS['disable_non_default_groups'] = true;
483 $GLOBALS['ippf_specific'] = false;
486 // Migrated this to populate after the standard globals in order to support globals that require
487 // more security.
488 require_once($GLOBALS['OE_SITE_DIR'] . "/config.php");
490 // Need to utilize a session since library/sql.inc is established before there are any globals established yet.
491 // This means that the first time, it will be skipped even if the global is turned on. However,
492 // after that it will then be turned on via the session.
493 // Also important to note that changes to this global setting will not take effect during the same
494 // session (ie. user needs to logout) since not worth it to use resources to open session and write to it
495 // for every call to interface/globals.php .
496 $_SESSION["enable_database_connection_pooling"] = $GLOBALS["enable_database_connection_pooling"];
498 // If >0 this will enforce a separate PHP session for each top-level
499 // browser window. You must log in separately for each. This is not
500 // thoroughly tested yet and some browsers might have trouble with it,
501 // so make it 0 if you must. Alternatively, you can set it to 2 to be
502 // notified when the session ID changes.
503 $GLOBALS['restore_sessions'] = 1; // 0=no, 1=yes, 2=yes+debug
505 // Theme definition. All this stuff should be moved to CSS.
507 $top_bg_line = ' bgcolor="#dddddd" ';
508 $GLOBALS['style']['BGCOLOR2'] = "#dddddd";
509 $logocode = "<img class='img-responsive' src='" . $GLOBALS['OE_SITE_WEBROOT'] . "/images/login_logo.gif' />";
510 // optimal size for the tiny logo is height 43 width 86 px
511 // inside the open emr they will be auto reduced
512 $tinylogocode1 = "<img class='img-responsive d-block mx-auto' src='" . $GLOBALS['OE_SITE_WEBROOT'] . "/images/logo_1.png'>";
513 $tinylogocode2 = "<img class='img-responsive d-block mx-auto' src='" . $GLOBALS['OE_SITE_WEBROOT'] . "/images/logo_2.png'>";
515 $GLOBALS['style']['BGCOLOR1'] = "#cccccc";
516 // The height in pixels of the Title bar:
517 $GLOBALS['titleBarHeight'] = 50;
519 // The assistant word, MORE printed next to titles that can be clicked:
520 // Note this label gets translated here via the xl function
521 // -if you don't want it translated, then strip the xl function away
522 $tmore = xl('(More)');
523 // The assistant word, BACK printed next to titles that return to previous screens:
524 // Note this label gets translated here via the xl function
525 // -if you don't want it translated, then strip the xl function away
526 $tback = xl('(Back)');
528 $versionService = new \OpenEMR\Services\VersionService();
529 $version = $versionService->fetch();
531 if (!empty($version)) {
532 //Version tag
533 $patch_appending = "";
534 //Collected below function call to a variable, since unable to directly include
535 // function calls within empty() in php versions < 5.5 .
536 $version_getrealpatch = $version['v_realpatch'];
537 if (($version['v_realpatch'] != '0') && (!(empty($version_getrealpatch)))) {
538 $patch_appending = " (" . $version['v_realpatch'] . ")";
541 $openemr_version = $version['v_major'] . "." . $version['v_minor'] . "." . $version['v_patch'];
542 $openemr_version .= $version['v_tag'] . $patch_appending;
543 } else {
544 $openemr_version = xl('Unknown version');
546 $GLOBALS['openemr_version'] = $openemr_version;
548 $srcdir = $GLOBALS['srcdir'];
549 $login_screen = $GLOBALS['login_screen'];
550 $GLOBALS['backpic'] = $backpic ?? '';
552 // 1 = send email message to given id for Emergency Login user activation,
553 // else 0.
554 $GLOBALS['Emergency_Login_email'] = empty($GLOBALS['Emergency_Login_email_id']) ? 0 : 1;
556 //set include_de_identification to enable De-identification (currently de-identification works fine only with linux machines)
557 //Run de_identification_upgrade.php script to upgrade OpenEMR database to include procedures,
558 //functions, tables for de-identification(Mysql root user and password is required for successful
559 //execution of the de-identification upgrade script)
560 $GLOBALS['include_de_identification'] = 0;
561 // Include the authentication module code here, but the rule is
562 // if the file has the word "login" in the source code file name,
563 // don't include the authentication module - we do this to avoid
564 // include loops.
566 if (($ignoreAuth_onsite_portal === true) && ($GLOBALS['portal_onsite_two_enable'] == 1)) {
567 $ignoreAuth = true;
570 if (!$ignoreAuth) {
571 require_once("$srcdir/auth.inc");
574 // This is the background color to apply to form fields that are searchable.
575 // Currently it is applicable only to the "Search or Add Patient" form.
576 $GLOBALS['layout_search_color'] = '#ff9919';
578 // EMAIL SETTINGS
579 $SMTP_Auth = !empty($GLOBALS['SMTP_USER']);
581 // module configurations
582 // upgrade fails for versions prior to 4.2.0 since no modules table
583 // so perform this check to avoid sql error
584 if (!file_exists($webserver_root . "/interface/modules/")) {
585 error_log("The modules directory does not exist thus not loading modules.");
586 } else {
587 $GLOBALS['baseModDir'] = "interface/modules/"; //default path of modules
588 $GLOBALS['customModDir'] = "custom_modules"; //non zend modules
589 $GLOBALS['zendModDir'] = "zend_modules"; //zend modules
591 try {
592 // load up the modules system and bootstrap them.
593 // This has to be fast, so any modules that tie into the bootstrap must be kept lightweight
594 // registering event listeners, etc.
595 // TODO: why do we have 3 different directories we need to pass in for the zend dir path. shouldn't zendModDir already have all the paths set up?
596 /** @var ModulesApplication */
597 $GLOBALS['modules_application'] = new ModulesApplication(
598 $GLOBALS["kernel"],
599 $GLOBALS['fileroot'],
600 $GLOBALS['baseModDir'],
601 $GLOBALS['zendModDir']
603 } catch (\Exception $ex) {
604 error_log(errorLogEscape($ex->getMessage() . $ex->getTraceAsString()));
605 die();
609 // Don't change anything below this line. ////////////////////////////
611 $encounter = empty($_SESSION['encounter']) ? 0 : $_SESSION['encounter'];
613 if (!empty($_GET['pid']) && empty($_SESSION['pid'])) {
614 OpenEMR\Common\Session\SessionUtil::setSession('pid', $_GET['pid']);
615 } elseif (!empty($_POST['pid']) && empty($_SESSION['pid'])) {
616 OpenEMR\Common\Session\SessionUtil::setSession('pid', $_POST['pid']);
619 $pid = empty($_SESSION['pid']) ? 0 : $_SESSION['pid'];
620 $userauthorized = empty($_SESSION['userauthorized']) ? 0 : $_SESSION['userauthorized'];
621 $groupname = empty($_SESSION['authProvider']) ? 0 : $_SESSION['authProvider'];
623 //This is crucial for therapy groups and patients mechanisms to work together properly
624 $attendant_type = (empty($pid) && isset($_SESSION['therapy_group'])) ? 'gid' : 'pid';
625 $therapy_group = (empty($pid) && isset($_SESSION['therapy_group'])) ? $_SESSION['therapy_group'] : 0;
627 // global interface function to format text length using ellipses
628 function strterm($string, $length)
630 if (strlen($string) >= ($length - 3)) {
631 return substr($string, 0, $length - 3) . "...";
632 } else {
633 return $string;
637 // Helper function to generate an image URL that defeats browser/proxy caching when needed.
638 function UrlIfImageExists($filename, $append = true)
640 global $webserver_root, $web_root;
641 $path = "sites/" . $_SESSION['site_id'] . "/images/$filename";
642 // @ in next line because a missing file is not an error.
643 if ($stat = @stat("$webserver_root/$path")) {
644 if ($append) {
645 return "$web_root/$path?v=" . $stat['mtime'];
646 } else {
647 return "$web_root/$path";
650 return '';
653 // Override temporary_files_dir
654 $GLOBALS['temporary_files_dir'] = rtrim(sys_get_temp_dir(), '/');
656 error_reporting(error_reporting() & ~E_USER_DEPRECATED & ~E_USER_WARNING);
657 // user debug mode
658 if ((int) $GLOBALS['user_debug'] > 1) {
659 error_reporting(error_reporting() & ~E_WARNING & ~E_NOTICE & ~E_USER_WARNING & ~E_USER_DEPRECATED);
660 ini_set('display_errors', 1);