load();
}
// @TODO This needs to be broken out to it's own function, but for time's sake
// @TODO putting it here until we land on a good place. RD 2017-05-02
$twigOptions = [
'debug' => false,
];
$twigLoader = new Twig_Loader_Filesystem();
$twigEnv = new Twig_Environment($twigLoader, $twigOptions);
if (array_key_exists('debug', $twigOptions) && $twigOptions['debug'] == true) {
$twigEnv->addExtension(new Twig_Extension_Debug());
}
$twigEnv->addGlobal('assets_dir', $GLOBALS['assets_static_relative']);
$twigEnv->addGlobal('srcdir', $GLOBALS['srcdir']);
$twigEnv->addGlobal('rootdir', $GLOBALS['rootdir']);
$twigEnv->addFilter(new Twig_SimpleFilter('translate', function ($string) {
return xl($string);
}));
/** Twig_Loader */
$GLOBALS['twigLoader'] = $twigLoader;
/** Twig_Environment */
$GLOBALS['twig'] = $twigEnv;
// This will open the openemr mysql connection.
require_once (dirname(__FILE__) . "/../library/sql.inc");
// Include the version file
require_once (dirname(__FILE__) . "/../version.php");
// The logging level for common/logging/logger.php
// Value can be TRACE, DEBUG, INFO, WARN, ERROR, or OFF:
// - DEBUG/INFO are great for development
// - INFO/WARN/ERROR are great for production
// - TRACE is useful when debugging hard to spot bugs
$GLOBALS["log_level"] = "OFF";
// Should Doctrine make use of connection pooling? Database connection pooling is a method
// used to keep database connections open so they can be reused by others. (The only reason
// to not use connection pooling is if your server has limited resources.)
$GLOBALS["doctrine_connection_pooling"] = true;
// Defaults for specific applications.
$GLOBALS['weight_loss_clinic'] = false;
$GLOBALS['ippf_specific'] = false;
// Defaults for drugs and products.
$GLOBALS['inhouse_pharmacy'] = false;
$GLOBALS['sell_non_drug_products'] = 0;
$glrow = sqlQuery("SHOW TABLES LIKE 'globals'");
if (!empty($glrow)) {
// Collect user specific settings from user_settings table.
//
$gl_user = array();
// Collect the user id first
$temp_authuserid = '';
if (!empty($_SESSION['authUserID'])) {
//Set the user id from the session variable
$temp_authuserid = $_SESSION['authUserID'];
} else {
if (!empty($_POST['authUser'])) {
$temp_sql_ret = sqlQuery("SELECT `id` FROM `users` WHERE `username` = ?", array($_POST['authUser']));
if (!empty($temp_sql_ret['id'])) {
//Set the user id from the login variable
$temp_authuserid = $temp_sql_ret['id'];
}
}
}
if (!empty($temp_authuserid)) {
$glres_user = sqlStatement(
"SELECT `setting_label`, `setting_value` " .
"FROM `user_settings` " .
"WHERE `setting_user` = ? " .
"AND `setting_label` LIKE 'global:%'",
array($temp_authuserid)
);
for ($iter=0; $row=sqlFetchArray($glres_user); $iter++) {
//remove global_ prefix from label
$row['setting_label'] = substr($row['setting_label'], 7);
$gl_user[$iter]=$row;
}
}
// Set global parameters from the database globals table.
// Some parameters require custom handling.
//
$GLOBALS['language_menu_show'] = array();
$glres = sqlStatement(
"SELECT gl_name, gl_index, gl_value FROM globals " .
"ORDER BY gl_name, gl_index"
);
while ($glrow = sqlFetchArray($glres)) {
$gl_name = $glrow['gl_name'];
$gl_value = $glrow['gl_value'];
// Adjust for user specific settings
if (!empty($gl_user)) {
foreach ($gl_user as $setting) {
if ($gl_name == $setting['setting_label']) {
$gl_value = $setting['setting_value'];
}
}
}
if ($gl_name == 'language_menu_other') {
$GLOBALS['language_menu_show'][] = $gl_value;
} elseif ($gl_name == 'css_header') {
$GLOBALS[$gl_name] = $rootdir.'/themes/'.$gl_value.'?v='.$v_js_includes;
$temp_css_theme_name = $gl_value;
} elseif ($gl_name == 'weekend_days') {
$GLOBALS[$gl_name] = explode(',', $gl_value);
} elseif ($gl_name == 'specific_application') {
if ($gl_value == '2') {
$GLOBALS['ippf_specific'] = true;
} elseif ($gl_value == '3') {
$GLOBALS['weight_loss_clinic'] = true;
}
} elseif ($gl_name == 'inhouse_pharmacy') {
if ($gl_value) {
$GLOBALS['inhouse_pharmacy'] = true;
}
if ($gl_value == '2') {
$GLOBALS['sell_non_drug_products'] = 1;
} elseif ($gl_value == '3') {
$GLOBALS['sell_non_drug_products'] = 2;
}
} elseif ($gl_name == 'gbl_time_zone') {
// The default PHP time zone is set here if it was specified, and is used
// as source data for the MySQL time zone here and in some other places
// where MySQL connections are opened.
if ($gl_value) {
date_default_timezone_set($gl_value);
}
// Synchronize MySQL time zone with PHP time zone.
sqlStatement("SET time_zone = ?", array((new DateTime())->format("P")));
} else {
$GLOBALS[$gl_name] = $gl_value;
}
}
// Language cleanup stuff.
$GLOBALS['language_menu_login'] = false;
if ((count($GLOBALS['language_menu_show']) >= 1) || $GLOBALS['language_menu_showall']) {
$GLOBALS['language_menu_login'] = true;
}
// Added this $GLOBALS['concurrent_layout'] set to 3 in order to support legacy forms
// that may use this; note this global has been removed from the standard codebase.
$GLOBALS['concurrent_layout'] = 3;
// Additional logic to override theme name.
// For RTL languages we substitute the theme name with the name of RTL-adapted CSS file.
$rtl_override = false;
if (isset( $_SESSION['language_direction'] )) {
if ($_SESSION['language_direction'] == 'rtl' &&
!strpos($GLOBALS['css_header'], 'rtl') ) {
// the $css_header_value is set above
$rtl_override = true;
}
} elseif (isset( $_SESSION['language_choice'] )) {
//this will support the onsite patient portal which will have a language choice but not yet a set language direction
$_SESSION['language_direction'] = getLanguageDir($_SESSION['language_choice']);
if ($_SESSION['language_direction'] == 'rtl' &&
!strpos($GLOBALS['css_header'], 'rtl')) {
// the $css_header_value is set above
$rtl_override = true;
}
} else {
//$_SESSION['language_direction'] is not set, so will use the default language
$default_lang_id = sqlQuery('SELECT lang_id FROM lang_languages WHERE lang_description = ?', array($GLOBALS['language_default']));
if (getLanguageDir($default_lang_id['lang_id']) === 'rtl' && !strpos($GLOBALS['css_header'], 'rtl')) {
// @todo eliminate 1 SQL query
$rtl_override = true;
}
}
// change theme name, if the override file exists.
if ($rtl_override) {
// the $css_header_value is set above
$new_theme = 'rtl_' . $temp_css_theme_name;
// Check file existance
if (file_exists($include_root.'/themes/'.$new_theme)) {
$GLOBALS['css_header'] = $rootdir.'/themes/'.$new_theme.'?v='.$v_js_includes;
} else {
// throw a warning if rtl'ed file does not exist.
error_log("Missing theme file ".text($include_root).'/themes/'.text($new_theme));
}
}
unset( $temp_css_theme_name, $new_theme,$rtl_override);
// end of RTL section
//
// End of globals table processing.
} else {
// Temporary stuff to handle the case where the globals table does not
// exist yet. This will happen in sql_upgrade.php on upgrading to the
// first release containing this table.
$GLOBALS['language_menu_login'] = true;
$GLOBALS['language_menu_showall'] = true;
$GLOBALS['language_menu_show'] = array('English (Standard)','Swedish');
$GLOBALS['language_default'] = "English (Standard)";
$GLOBALS['translate_layout'] = true;
$GLOBALS['translate_lists'] = true;
$GLOBALS['translate_gacl_groups'] = true;
$GLOBALS['translate_form_titles'] = true;
$GLOBALS['translate_document_categories'] = true;
$GLOBALS['translate_appt_categories'] = true;
$timeout = 7200;
$openemr_name = 'OpenEMR';
$css_header = "$rootdir/themes/style_default.css";
$GLOBALS['css_header'] = $css_header;
$GLOBALS['schedule_start'] = 8;
$GLOBALS['schedule_end'] = 17;
$GLOBALS['calendar_interval'] = 15;
$GLOBALS['phone_country_code'] = '1';
$GLOBALS['disable_non_default_groups'] = true;
$GLOBALS['ippf_specific'] = false;
}
// If >0 this will enforce a separate PHP session for each top-level
// browser window. You must log in separately for each. This is not
// thoroughly tested yet and some browsers might have trouble with it,
// so make it 0 if you must. Alternatively, you can set it to 2 to be
// notified when the session ID changes.
$GLOBALS['restore_sessions'] = 1; // 0=no, 1=yes, 2=yes+debug
// Theme definition. All this stuff should be moved to CSS.
//
$top_bg_line = ' bgcolor="#dddddd" ';
$GLOBALS['style']['BGCOLOR2'] = "#dddddd";
$bottom_bg_line = $top_bg_line;
$title_bg_line = ' bgcolor="#bbbbbb" ';
$nav_bg_line = ' bgcolor="#94d6e7" ';
$login_filler_line = ' bgcolor="#f7f0d5" ';
$logocode = "";
// optimal size for the tiny logo is height 43 width 86 px
// inside the open emr they will be auto reduced
$tinylogocode1 = "";
$tinylogocode2 = "";
$linepic = "$rootdir/pic/repeat_vline9.gif";
$table_bg = ' bgcolor="#cccccc" ';
$GLOBALS['style']['BGCOLOR1'] = "#cccccc";
$GLOBALS['style']['TEXTCOLOR11'] = "#222222";
$GLOBALS['style']['HIGHLIGHTCOLOR'] = "#dddddd";
$GLOBALS['style']['BOTTOM_BG_LINE'] = $bottom_bg_line;
// The height in pixels of the Logo bar at the top of the login page:
$GLOBALS['logoBarHeight'] = 110;
// The height in pixels of the Navigation bar:
$GLOBALS['navBarHeight'] = 22;
// The height in pixels of the Title bar:
$GLOBALS['titleBarHeight'] = 40;
// The assistant word, MORE printed next to titles that can be clicked:
// Note this label gets translated here via the xl function
// -if you don't want it translated, then strip the xl function away
$tmore = xl('(More)');
// The assistant word, BACK printed next to titles that return to previous screens:
// Note this label gets translated here via the xl function
// -if you don't want it translated, then strip the xl function away
$tback = xl('(Back)');
// This is the idle logout function:
// if a page has not been refreshed within this many seconds, the interface
// will return to the login page
if (!empty($special_timeout)) {
$timeout = intval($special_timeout);
}
$versionService = new \services\VersionService();
$version = $versionService->fetch();
if (!empty($version)) {
//Version tag
$patch_appending = "";
//Collected below function call to a variable, since unable to directly include
// function calls within empty() in php versions < 5.5 .
$version_getrealpatch = $version->getRealPatch();
if (($version->getRealPatch() != '0') && (!(empty($version_getrealpatch)))) {
$patch_appending = " (".$version->getRealPatch().")";
}
$openemr_version = $version->getMajor() . "." . $version->getMinor() . "." . $version->getPatch();
$openemr_version .= $version->getTag() . $patch_appending;
} else {
$openemr_version = xl('Unknown version');
}
$srcdir = $GLOBALS['srcdir'];
$login_screen = $GLOBALS['login_screen'];
$GLOBALS['css_header'] = $css_header;
$GLOBALS['backpic'] = $backpic;
// 1 = send email message to given id for Emergency Login user activation,
// else 0.
$GLOBALS['Emergency_Login_email'] = empty($GLOBALS['Emergency_Login_email_id']) ? 0 : 1;
//set include_de_identification to enable De-identification (currently de-identification works fine only with linux machines)
//Run de_identification_upgrade.php script to upgrade OpenEMR database to include procedures,
//functions, tables for de-identification(Mysql root user and password is required for successful
//execution of the de-identification upgrade script)
$GLOBALS['include_de_identification']=0;
// Include the authentication module code here, but the rule is
// if the file has the word "login" in the source code file name,
// don't include the authentication module - we do this to avoid
// include loops.
if (($ignoreAuth_offsite_portal === true) && ($GLOBALS['portal_offsite_enable'] == 1)) {
$ignoreAuth = true;
} elseif (($ignoreAuth_onsite_portal_two === true) && ($GLOBALS['portal_onsite_two_enable'] == 1)) {
$ignoreAuth = true;
}
if (!$ignoreAuth) {
include_once("$srcdir/auth.inc");
}
// This is the background color to apply to form fields that are searchable.
// Currently it is applicable only to the "Search or Add Patient" form.
$GLOBALS['layout_search_color'] = '#ffff55';
//EMAIL SETTINGS
$SMTP_Auth = !empty($GLOBALS['SMTP_USER']);
//module configurations
$GLOBALS['baseModDir'] = "interface/modules/"; //default path of modules
$GLOBALS['customModDir'] = "custom_modules"; //non zend modules
$GLOBALS['zendModDir'] = "zend_modules"; //zend modules
// Don't change anything below this line. ////////////////////////////
$encounter = empty($_SESSION['encounter']) ? 0 : $_SESSION['encounter'];
if (!empty($_GET['pid']) && empty($_SESSION['pid'])) {
$_SESSION['pid'] = $_GET['pid'];
} elseif (!empty($_POST['pid']) && empty($_SESSION['pid'])) {
$_SESSION['pid'] = $_POST['pid'];
}
$pid = empty($_SESSION['pid']) ? 0 : $_SESSION['pid'];
$userauthorized = empty($_SESSION['userauthorized']) ? 0 : $_SESSION['userauthorized'];
$groupname = empty($_SESSION['authProvider']) ? 0 : $_SESSION['authProvider'];
//This is crucial for therapy groups and patients mechanisms to work together properly
$attendant_type = (empty($pid) && isset($_SESSION['therapy_group'])) ? 'gid' : 'pid';
$therapy_group = (empty($pid) && isset($_SESSION['therapy_group'])) ? $_SESSION['therapy_group'] : 0;
// global interface function to format text length using ellipses
function strterm($string, $length)
{
if (strlen($string) >= ($length-3)) {
return substr($string, 0, $length-3) . "...";
} else {
return $string;
}
}
// Override temporary_files_dir if PHP >= 5.2.1.
if (version_compare(phpversion(), "5.2.1", ">=")) {
$GLOBALS['temporary_files_dir'] = rtrim(sys_get_temp_dir(), '/');
}
// turn off PHP compatibility warnings
ini_set("session.bug_compat_warn", "off");