Fixes for restoreSession logic. (#4378)
[openemr.git] / interface / globals.php
blobebf82b41960b7e39169762cfe9df2d6cd2bf50de
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 // Load twig support
281 $twigLoader = new Twig\Loader\FilesystemLoader($webserver_root . '/templates');
282 $twigEnv = new Twig\Environment($twigLoader, ['autoescape' => false]);
283 $twigEnv->addExtension(new OpenEMR\Core\TwigExtension());
284 $GLOBALS['twig'] = $twigEnv;
286 try {
287 /** @var Kernel */
288 $GLOBALS["kernel"] = new Kernel();
289 } catch (\Exception $e) {
290 error_log(errorLogEscape($e->getMessage()));
291 die();
294 // Defaults for specific applications.
295 $GLOBALS['weight_loss_clinic'] = false;
296 $GLOBALS['ippf_specific'] = false;
298 // Defaults for drugs and products.
299 $GLOBALS['inhouse_pharmacy'] = false;
300 $GLOBALS['sell_non_drug_products'] = 0;
302 $glrow = sqlQueryNoLog("SHOW TABLES LIKE 'globals'");
303 if (!empty($glrow)) {
304 // Collect user specific settings from user_settings table.
306 $gl_user = array();
307 // Collect the user id first
308 $temp_authuserid = '';
309 if (!empty($_SESSION['authUserID'])) {
310 //Set the user id from the session variable
311 $temp_authuserid = $_SESSION['authUserID'];
312 } else {
313 if (!empty($_POST['authUser'])) {
314 $temp_sql_ret = sqlQueryNoLog("SELECT `id` FROM `users` WHERE BINARY `username` = ?", array($_POST['authUser']));
315 if (!empty($temp_sql_ret['id'])) {
316 //Set the user id from the login variable
317 $temp_authuserid = $temp_sql_ret['id'];
322 if (!empty($temp_authuserid)) {
323 $glres_user = sqlStatementNoLog(
324 "SELECT `setting_label`, `setting_value` " .
325 "FROM `user_settings` " .
326 "WHERE `setting_user` = ? " .
327 "AND `setting_label` LIKE 'global:%'",
328 array($temp_authuserid)
330 for ($iter = 0; $row = sqlFetchArray($glres_user); $iter++) {
331 //remove global_ prefix from label
332 $row['setting_label'] = substr($row['setting_label'], 7);
333 $gl_user[$iter] = $row;
337 // Set global parameters from the database globals table.
338 // Some parameters require custom handling.
340 $GLOBALS['language_menu_show'] = array();
341 $glres = sqlStatementNoLog(
342 "SELECT gl_name, gl_index, gl_value FROM globals " .
343 "ORDER BY gl_name, gl_index"
345 while ($glrow = sqlFetchArray($glres)) {
346 $gl_name = $glrow['gl_name'];
347 $gl_value = $glrow['gl_value'];
348 // Adjust for user specific settings
349 if (!empty($gl_user)) {
350 foreach ($gl_user as $setting) {
351 if ($gl_name == $setting['setting_label']) {
352 $gl_value = $setting['setting_value'];
357 if ($gl_name == 'language_menu_other') {
358 $GLOBALS['language_menu_show'][] = $gl_value;
359 } elseif ($gl_name == 'css_header') {
360 //Escape css file name using 'attr' for security (prevent XSS).
361 $GLOBALS[$gl_name] = $web_root . '/public/themes/' . attr($gl_value) . '?v=' . $v_js_includes;
362 $GLOBALS['compact_header'] = $web_root . '/public/themes/compact_' . attr($gl_value) . '?v=' . $v_js_includes;
363 $compact_header = $GLOBALS['compact_header'];
364 $css_header = $GLOBALS[$gl_name];
365 $temp_css_theme_name = $gl_value;
366 } elseif ($gl_name == 'weekend_days') {
367 $GLOBALS[$gl_name] = explode(',', $gl_value);
368 } elseif ($gl_name == 'specific_application') {
369 if ($gl_value == '2') {
370 $GLOBALS['ippf_specific'] = true;
371 } elseif ($gl_value == '3') {
372 $GLOBALS['weight_loss_clinic'] = true;
374 } elseif ($gl_name == 'inhouse_pharmacy') {
375 if ($gl_value) {
376 $GLOBALS['inhouse_pharmacy'] = true;
379 if ($gl_value == '2') {
380 $GLOBALS['sell_non_drug_products'] = 1;
381 } elseif ($gl_value == '3') {
382 $GLOBALS['sell_non_drug_products'] = 2;
384 } elseif ($gl_name == 'gbl_time_zone') {
385 // The default PHP time zone is set here if it was specified, and is used
386 // as source data for the MySQL time zone here and in some other places
387 // where MySQL connections are opened.
388 if ($gl_value) {
389 date_default_timezone_set($gl_value);
392 // Synchronize MySQL time zone with PHP time zone.
393 sqlStatementNoLog("SET time_zone = ?", array((new DateTime())->format("P")));
394 } else {
395 $GLOBALS[$gl_name] = $gl_value;
399 // Language cleanup stuff.
400 $GLOBALS['language_menu_login'] = false;
401 if ((count($GLOBALS['language_menu_show']) > 1) || $GLOBALS['language_menu_showall']) {
402 $GLOBALS['language_menu_login'] = true;
405 // Added this $GLOBALS['concurrent_layout'] set to 3 in order to support legacy forms
406 // that may use this; note this global has been removed from the standard codebase.
407 $GLOBALS['concurrent_layout'] = 3;
409 // Additional logic to override theme name.
410 // For RTL languages we substitute the theme name with the name of RTL-adapted CSS file.
411 $rtl_override = false;
412 if (isset($_SESSION['language_direction'])) {
413 if (
414 $_SESSION['language_direction'] == 'rtl' &&
415 !strpos($GLOBALS['css_header'], 'rtl')
417 // the $css_header_value is set above
418 $rtl_override = true;
420 } elseif (isset($_SESSION['language_choice'])) {
421 //this will support the onsite patient portal which will have a language choice but not yet a set language direction
422 $_SESSION['language_direction'] = getLanguageDir($_SESSION['language_choice']);
423 if (
424 $_SESSION['language_direction'] == 'rtl' &&
425 !strpos($GLOBALS['css_header'], 'rtl')
427 // the $css_header_value is set above
428 $rtl_override = true;
430 } else {
431 //$_SESSION['language_direction'] is not set, so will use the default language
432 $default_lang_id = sqlQueryNoLog('SELECT lang_id FROM lang_languages WHERE lang_description = ?', array($GLOBALS['language_default']));
434 if (getLanguageDir($default_lang_id['lang_id']) === 'rtl' && !strpos($GLOBALS['css_header'], 'rtl')) {
435 // @todo eliminate 1 SQL query
436 $rtl_override = true;
441 // change theme name, if the override file exists.
442 if ($rtl_override) {
443 // the $css_header_value is set above
444 $new_theme = 'rtl_' . $temp_css_theme_name;
446 // Check file existance
447 if (file_exists($webserver_root . '/public/themes/' . $new_theme)) {
448 //Escape css file name using 'attr' for security (prevent XSS).
449 $GLOBALS['css_header'] = $web_root . '/public/themes/' . attr($new_theme) . '?v=' . $v_js_includes;
450 $css_header = $GLOBALS['css_header'];
451 $GLOBALS['compact_header'] = $web_root . '/public/themes/rtl_compact_' . attr($temp_css_theme_name) . '?v=' . $v_js_includes;
452 $compact_header = $GLOBALS['compact_header'];
453 } else {
454 // throw a warning if rtl'ed file does not exist.
455 error_log("Missing theme file " . errorLogEscape($webserver_root) . '/public/themes/' . errorLogEscape($new_theme));
459 unset($temp_css_theme_name, $new_theme, $rtl_override);
460 // end of RTL section
463 // End of globals table processing.
464 } else {
465 // Temporary stuff to handle the case where the globals table does not
466 // exist yet. This will happen in sql_upgrade.php on upgrading to the
467 // first release containing this table.
468 $GLOBALS['language_menu_login'] = true;
469 $GLOBALS['language_menu_showall'] = true;
470 $GLOBALS['language_menu_show'] = array('English (Standard)','Swedish');
471 $GLOBALS['language_default'] = "English (Standard)";
472 $GLOBALS['translate_layout'] = true;
473 $GLOBALS['translate_lists'] = true;
474 $GLOBALS['translate_gacl_groups'] = true;
475 $GLOBALS['translate_form_titles'] = true;
476 $GLOBALS['translate_document_categories'] = true;
477 $GLOBALS['translate_appt_categories'] = true;
478 $GLOBALS['timeout'] = 7200;
479 $openemr_name = 'OpenEMR';
480 $css_header = "$web_root/public/themes/style_default.css";
481 $GLOBALS['css_header'] = $css_header;
482 $compact_header = "$web_root/public/themes/style_default.css";
483 $GLOBALS['compact_header'] = $compact_header;
484 $GLOBALS['schedule_start'] = 8;
485 $GLOBALS['schedule_end'] = 17;
486 $GLOBALS['calendar_interval'] = 15;
487 $GLOBALS['phone_country_code'] = '1';
488 $GLOBALS['disable_non_default_groups'] = true;
489 $GLOBALS['ippf_specific'] = false;
492 // Migrated this to populate after the standard globals in order to support globals that require
493 // more security.
494 require_once($GLOBALS['OE_SITE_DIR'] . "/config.php");
496 // Need to utilize a session since library/sql.inc is established before there are any globals established yet.
497 // This means that the first time, it will be skipped even if the global is turned on. However,
498 // after that it will then be turned on via the session.
499 // Also important to note that changes to this global setting will not take effect during the same
500 // session (ie. user needs to logout) since not worth it to use resources to open session and write to it
501 // for every call to interface/globals.php .
502 $_SESSION["enable_database_connection_pooling"] = $GLOBALS["enable_database_connection_pooling"];
504 // If >0 this will enforce a separate PHP session for each top-level
505 // browser window. You must log in separately for each. This is not
506 // thoroughly tested yet and some browsers might have trouble with it,
507 // so make it 0 if you must. Alternatively, you can set it to 2 to be
508 // notified when the session ID changes.
509 $GLOBALS['restore_sessions'] = 1; // 0=no, 1=yes, 2=yes+debug
511 // Theme definition. All this stuff should be moved to CSS.
513 $top_bg_line = ' bgcolor="#dddddd" ';
514 $GLOBALS['style']['BGCOLOR2'] = "#dddddd";
515 $logocode = "<img class='img-responsive' src='" . $GLOBALS['OE_SITE_WEBROOT'] . "/images/login_logo.gif' />";
516 // optimal size for the tiny logo is height 43 width 86 px
517 // inside the open emr they will be auto reduced
518 $tinylogocode1 = "<img class='img-responsive d-block mx-auto' src='" . $GLOBALS['OE_SITE_WEBROOT'] . "/images/logo_1.png'>";
519 $tinylogocode2 = "<img class='img-responsive d-block mx-auto' src='" . $GLOBALS['OE_SITE_WEBROOT'] . "/images/logo_2.png'>";
521 $GLOBALS['style']['BGCOLOR1'] = "#cccccc";
522 // The height in pixels of the Title bar:
523 $GLOBALS['titleBarHeight'] = 50;
525 // The assistant word, MORE printed next to titles that can be clicked:
526 // Note this label gets translated here via the xl function
527 // -if you don't want it translated, then strip the xl function away
528 $tmore = xl('(More)');
529 // The assistant word, BACK printed next to titles that return to previous screens:
530 // Note this label gets translated here via the xl function
531 // -if you don't want it translated, then strip the xl function away
532 $tback = xl('(Back)');
534 $versionService = new \OpenEMR\Services\VersionService();
535 $version = $versionService->fetch();
537 if (!empty($version)) {
538 //Version tag
539 $patch_appending = "";
540 //Collected below function call to a variable, since unable to directly include
541 // function calls within empty() in php versions < 5.5 .
542 $version_getrealpatch = $version['v_realpatch'];
543 if (($version['v_realpatch'] != '0') && (!(empty($version_getrealpatch)))) {
544 $patch_appending = " (" . $version['v_realpatch'] . ")";
547 $openemr_version = $version['v_major'] . "." . $version['v_minor'] . "." . $version['v_patch'];
548 $openemr_version .= $version['v_tag'] . $patch_appending;
549 } else {
550 $openemr_version = xl('Unknown version');
552 $GLOBALS['openemr_version'] = $openemr_version;
554 $srcdir = $GLOBALS['srcdir'];
555 $login_screen = $GLOBALS['login_screen'];
556 $GLOBALS['backpic'] = $backpic ?? '';
558 // 1 = send email message to given id for Emergency Login user activation,
559 // else 0.
560 $GLOBALS['Emergency_Login_email'] = empty($GLOBALS['Emergency_Login_email_id']) ? 0 : 1;
562 //set include_de_identification to enable De-identification (currently de-identification works fine only with linux machines)
563 //Run de_identification_upgrade.php script to upgrade OpenEMR database to include procedures,
564 //functions, tables for de-identification(Mysql root user and password is required for successful
565 //execution of the de-identification upgrade script)
566 $GLOBALS['include_de_identification'] = 0;
567 // Include the authentication module code here, but the rule is
568 // if the file has the word "login" in the source code file name,
569 // don't include the authentication module - we do this to avoid
570 // include loops.
572 if (($ignoreAuth_onsite_portal === true) && ($GLOBALS['portal_onsite_two_enable'] == 1)) {
573 $ignoreAuth = true;
576 if (!$ignoreAuth) {
577 require_once("$srcdir/auth.inc");
580 // This is the background color to apply to form fields that are searchable.
581 // Currently it is applicable only to the "Search or Add Patient" form.
582 $GLOBALS['layout_search_color'] = '#ff9919';
584 // EMAIL SETTINGS
585 $SMTP_Auth = !empty($GLOBALS['SMTP_USER']);
587 // module configurations
588 // upgrade fails for versions prior to 4.2.0 since no modules table
589 // so perform this check to avoid sql error
590 if (!file_exists($webserver_root . "/interface/modules/")) {
591 error_log("The modules directory does not exist thus not loading modules.");
592 } else {
593 $GLOBALS['baseModDir'] = "interface/modules/"; //default path of modules
594 $GLOBALS['customModDir'] = "custom_modules"; //non zend modules
595 $GLOBALS['zendModDir'] = "zend_modules"; //zend modules
597 try {
598 // load up the modules system and bootstrap them.
599 // This has to be fast, so any modules that tie into the bootstrap must be kept lightweight
600 // registering event listeners, etc.
601 // 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?
602 /** @var ModulesApplication */
603 $GLOBALS['modules_application'] = new ModulesApplication(
604 $GLOBALS["kernel"],
605 $GLOBALS['fileroot'],
606 $GLOBALS['baseModDir'],
607 $GLOBALS['zendModDir']
609 } catch (\Exception $ex) {
610 error_log(errorLogEscape($ex->getMessage() . $ex->getTraceAsString()));
611 die();
615 // Don't change anything below this line. ////////////////////////////
617 $encounter = empty($_SESSION['encounter']) ? 0 : $_SESSION['encounter'];
619 if (!empty($_GET['pid']) && empty($_SESSION['pid'])) {
620 OpenEMR\Common\Session\SessionUtil::setSession('pid', $_GET['pid']);
621 } elseif (!empty($_POST['pid']) && empty($_SESSION['pid'])) {
622 OpenEMR\Common\Session\SessionUtil::setSession('pid', $_POST['pid']);
625 $pid = empty($_SESSION['pid']) ? 0 : $_SESSION['pid'];
626 $userauthorized = empty($_SESSION['userauthorized']) ? 0 : $_SESSION['userauthorized'];
627 $groupname = empty($_SESSION['authProvider']) ? 0 : $_SESSION['authProvider'];
629 //This is crucial for therapy groups and patients mechanisms to work together properly
630 $attendant_type = (empty($pid) && isset($_SESSION['therapy_group'])) ? 'gid' : 'pid';
631 $therapy_group = (empty($pid) && isset($_SESSION['therapy_group'])) ? $_SESSION['therapy_group'] : 0;
633 // global interface function to format text length using ellipses
634 function strterm($string, $length)
636 if (strlen($string) >= ($length - 3)) {
637 return substr($string, 0, $length - 3) . "...";
638 } else {
639 return $string;
643 // Helper function to generate an image URL that defeats browser/proxy caching when needed.
644 function UrlIfImageExists($filename, $append = true)
646 global $webserver_root, $web_root;
647 $path = "sites/" . $_SESSION['site_id'] . "/images/$filename";
648 // @ in next line because a missing file is not an error.
649 if ($stat = @stat("$webserver_root/$path")) {
650 if ($append) {
651 return "$web_root/$path?v=" . $stat['mtime'];
652 } else {
653 return "$web_root/$path";
656 return '';
659 // Override temporary_files_dir
660 $GLOBALS['temporary_files_dir'] = rtrim(sys_get_temp_dir(), '/');
662 // turn off PHP compatibility warnings
663 ini_set("session.bug_compat_warn", "off");
664 // user debug mode
665 if ((int) $GLOBALS['user_debug'] > 1) {
666 error_reporting(error_reporting() & ~E_WARNING & ~E_NOTICE & ~E_USER_WARNING);
667 ini_set('display_errors', 1);