OpenEMR minimum web technologies requirements (#443)
[openemr.git] / interface / globals.php
blob19b58c84668ce9e0394da554ede92db13cfa2a31
1 <?php
3 // Checks if the server's PHP version is compatible with OpenEMR:
4 require_once(dirname(__FILE__) . "/../common/compatibility/checker.php");
6 $response = Checker::checkPhpVersion();
7 if ($response !== true) {
8 die($response);
11 // Default values for optional variables that are allowed to be set by callers.
13 // Unless specified explicitly, apply Auth functions
14 if (!isset($ignoreAuth)) $ignoreAuth = false;
15 // Unless specified explicitly, caller is not offsite_portal and Auth is required
16 if (!isset($ignoreAuth_offsite_portal)) $ignoreAuth_offsite_portal = false;
17 // Unless specified explicitly, do not reverse magic quotes
18 if (!isset($sanitize_all_escapes)) $sanitize_all_escapes = false;
19 // Unless specified explicitly, "fake" register_globals.
20 if (!isset($fake_register_globals)) $fake_register_globals = true;
22 // Is this windows or non-windows? Create a boolean definition.
23 if (!defined('IS_WINDOWS'))
24 define('IS_WINDOWS', (stripos(PHP_OS,'WIN') === 0));
26 // Some important php.ini overrides. Defaults for these values are often
27 // too small. You might choose to adjust them further.
29 ini_set('session.gc_maxlifetime', '14400');
31 // This is for sanitization of all escapes.
32 // (ie. reversing magic quotes if it's set)
33 if ($sanitize_all_escapes) {
34 if (get_magic_quotes_gpc()) {
35 function undoMagicQuotes($array, $topLevel=true) {
36 $newArray = array();
37 foreach($array as $key => $value) {
38 if (!$topLevel) {
39 $key = stripslashes($key);
41 if (is_array($value)) {
42 $newArray[$key] = undoMagicQuotes($value, false);
44 else {
45 $newArray[$key] = stripslashes($value);
48 return $newArray;
50 $_GET = undoMagicQuotes($_GET);
51 $_POST = undoMagicQuotes($_POST);
52 $_COOKIE = undoMagicQuotes($_COOKIE);
53 $_REQUEST = undoMagicQuotes($_REQUEST);
58 // The webserver_root and web_root are now automatically collected.
59 // If not working, can set manually below.
60 // Auto collect the full absolute directory path for openemr.
61 $webserver_root = dirname(dirname(__FILE__));
62 if (IS_WINDOWS) {
63 //convert windows path separators
64 $webserver_root = str_replace("\\","/",$webserver_root);
66 // Collect the apache server document root (and convert to windows slashes, if needed)
67 $server_document_root = realpath($_SERVER['DOCUMENT_ROOT']);
68 if (IS_WINDOWS) {
69 //convert windows path separators
70 $server_document_root = str_replace("\\","/",$server_document_root);
72 // Auto collect the relative html path, i.e. what you would type into the web
73 // browser after the server address to get to OpenEMR.
74 // This removes the leading portion of $webserver_root that it has in common with the web server's document
75 // root and assigns the result to $web_root. In addition to the common case where $webserver_root is
76 // /var/www/openemr and document root is /var/www, this also handles the case where document root is
77 // /var/www/html and there is an Apache "Alias" command that directs /openemr to /var/www/openemr.
78 $web_root = substr($webserver_root, strspn($webserver_root ^ $server_document_root, "\0"));
79 // Ensure web_root starts with a path separator
80 if (preg_match("/^[^\/]/",$web_root)) {
81 $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";
90 // This is the directory that contains site-specific data. Change this
91 // only if you have some reason to.
92 $GLOBALS['OE_SITES_BASE'] = "$webserver_root/sites";
94 // The session name names a cookie stored in the browser.
95 // Now that restore_session() is implemented in javaScript, session IDs are
96 // effectively saved in the top level browser window and there is no longer
97 // any need to change the session name for different OpenEMR instances.
98 session_name("OpenEMR");
100 session_start();
102 // Set the site ID if required. This must be done before any database
103 // access is attempted.
104 if (empty($_SESSION['site_id']) || !empty($_GET['site'])) {
105 if (!empty($_GET['site'])) {
106 $tmp = $_GET['site'];
108 else {
109 if (empty($ignoreAuth)) die("Site ID is missing from session data!");
110 $tmp = $_SERVER['HTTP_HOST'];
111 if (!is_dir($GLOBALS['OE_SITES_BASE'] . "/$tmp")) $tmp = "default";
113 if (empty($tmp) || preg_match('/[^A-Za-z0-9\\-.]/', $tmp))
114 die("Site ID '". htmlspecialchars($tmp,ENT_NOQUOTES) . "' contains invalid characters.");
115 if (isset($_SESSION['site_id']) && ($_SESSION['site_id'] != $tmp)) {
116 // This is to prevent using session to penetrate other OpenEMR instances within same multisite module
117 session_unset(); // clear session, clean logout
118 if (isset($landingpage) && !empty($landingpage)) {
119 // OpenEMR Patient Portal use
120 header('Location: index.php?site='.$tmp);
122 else {
123 // Main OpenEMR use
124 header('Location: ../login/login.php?site='.$tmp); // Assuming in the interface/main directory
126 exit;
128 if (!isset($_SESSION['site_id']) || $_SESSION['site_id'] != $tmp) {
129 $_SESSION['site_id'] = $tmp;
130 //error_log("Session site ID has been set to '$tmp'"); // debugging
134 // Set the site-specific directory path.
135 $GLOBALS['OE_SITE_DIR'] = $GLOBALS['OE_SITES_BASE'] . "/" . $_SESSION['site_id'];
137 require_once($GLOBALS['OE_SITE_DIR'] . "/config.php");
139 // Collecting the utf8 disable flag from the sqlconf.php file in order
140 // to set the correct html encoding. utf8 vs iso-8859-1. If flag is set
141 // then set to iso-8859-1.
142 require_once(dirname(__FILE__) . "/../library/sqlconf.php");
143 if (!$disable_utf8_flag) {
144 ini_set('default_charset', 'utf-8');
145 $HTML_CHARSET = "UTF-8";
146 mb_internal_encoding('UTF-8');
148 else {
149 ini_set('default_charset', 'iso-8859-1');
150 $HTML_CHARSET = "ISO-8859-1";
151 mb_internal_encoding('ISO-8859-1');
154 // Root directory, relative to the webserver root:
155 $GLOBALS['rootdir'] = "$web_root/interface";
156 $rootdir = $GLOBALS['rootdir'];
157 // Absolute path to the source code include and headers file directory (Full path):
158 $GLOBALS['srcdir'] = "$webserver_root/library";
159 // Absolute path to the location of documentroot directory for use with include statements:
160 $GLOBALS['fileroot'] = "$webserver_root";
161 // Absolute path to the location of interface directory for use with include statements:
162 $include_root = "$webserver_root/interface";
163 // Absolute path to the location of documentroot directory for use with include statements:
164 $GLOBALS['webroot'] = $web_root;
166 // Static assets directory, relative to the webserver root.
167 // (it is very likely that this path will be changed in the future))
168 $GLOBALS['assets_static_relative'] = "$web_root/public/assets";
170 // Relative images directory, relative to the webserver root.
171 $GLOBALS['images_static_relative'] = "$web_root/public/images";
173 // Static images directory, absolute to the webserver root.
174 $GLOBALS['images_static_absolute'] = "$webserver_root/public/images";
176 //Composer vendor directory, absolute to the webserver root.
177 $GLOBALS['vendor_dir'] = "$webserver_root/vendor";
179 $GLOBALS['template_dir'] = $GLOBALS['fileroot'] . "/templates/";
180 $GLOBALS['incdir'] = $include_root;
181 // Location of the login screen file
182 $GLOBALS['login_screen'] = $GLOBALS['rootdir'] . "/login_screen.php";
184 // Variable set for Eligibility Verification [EDI-271] path
185 $GLOBALS['edi_271_file_path'] = $GLOBALS['OE_SITE_DIR'] . "/edi/";
187 // Includes composer autoload
188 // Note this also brings in following library files:
189 // library/htmlspecialchars.inc.php - Include convenience functions with shorter names than "htmlspecialchars" (for security)
190 // library/formdata.inc.php - Include sanitization/checking functions (for security)
191 // library/sanitize.inc.php - Include sanitization/checking functions (for security)
192 // library/date_functions.php - Includes functions for date internationalization
193 // library/validation/validate_core.php - Includes functions for page validation
194 // library/translation.inc.php - Includes translation functions
195 require_once $GLOBALS['vendor_dir'] ."/autoload.php";
197 // This will open the openemr mysql connection.
198 require_once (dirname(__FILE__) . "/../library/sql.inc");
200 // Include the version file
201 require_once (dirname(__FILE__) . "/../version.php");
203 // The logging level for common/logging/logger.php
204 // Value can be TRACE, DEBUG, INFO, WARN, ERROR, or OFF:
205 // - DEBUG/INFO are great for development
206 // - INFO/WARN/ERROR are great for production
207 // - TRACE is useful when debugging hard to spot bugs
208 $GLOBALS["log_level"] = "OFF";
210 // Should Doctrine make use of connection pooling? Database connection pooling is a method
211 // used to keep database connections open so they can be reused by others. (The only reason
212 // to not use connection pooling is if your server has limited resources.)
213 $GLOBALS["doctrine_connection_pooling"] = true;
215 // Defaults for specific applications.
216 $GLOBALS['weight_loss_clinic'] = false;
217 $GLOBALS['ippf_specific'] = false;
218 $GLOBALS['cene_specific'] = false;
220 // Defaults for drugs and products.
221 $GLOBALS['inhouse_pharmacy'] = false;
222 $GLOBALS['sell_non_drug_products'] = 0;
224 $glrow = sqlQuery("SHOW TABLES LIKE 'globals'");
225 if (!empty($glrow)) {
226 // Collect user specific settings from user_settings table.
228 $gl_user = array();
229 // Collect the user id first
230 $temp_authuserid = '';
231 if (!empty($_SESSION['authUserID'])) {
232 //Set the user id from the session variable
233 $temp_authuserid = $_SESSION['authUserID'];
235 else {
236 if (!empty($_POST['authUser'])) {
237 $temp_sql_ret = sqlQuery("SELECT `id` FROM `users` WHERE `username` = ?", array($_POST['authUser']) );
238 if (!empty($temp_sql_ret['id'])) {
239 //Set the user id from the login variable
240 $temp_authuserid = $temp_sql_ret['id'];
244 if (!empty($temp_authuserid)) {
245 $glres_user = sqlStatement("SELECT `setting_label`, `setting_value` " .
246 "FROM `user_settings` " .
247 "WHERE `setting_user` = ? " .
248 "AND `setting_label` LIKE 'global:%'", array($temp_authuserid) );
249 for($iter=0; $row=sqlFetchArray($glres_user); $iter++) {
250 //remove global_ prefix from label
251 $row['setting_label'] = substr($row['setting_label'],7);
252 $gl_user[$iter]=$row;
255 // Set global parameters from the database globals table.
256 // Some parameters require custom handling.
258 $GLOBALS['language_menu_show'] = array();
259 $glres = sqlStatement("SELECT gl_name, gl_index, gl_value FROM globals " .
260 "ORDER BY gl_name, gl_index");
261 while ($glrow = sqlFetchArray($glres)) {
262 $gl_name = $glrow['gl_name'];
263 $gl_value = $glrow['gl_value'];
264 // Adjust for user specific settings
265 if (!empty($gl_user)) {
266 foreach ($gl_user as $setting) {
267 if ($gl_name == $setting['setting_label']) {
268 $gl_value = $setting['setting_value'];
272 if ($gl_name == 'language_menu_other') {
273 $GLOBALS['language_menu_show'][] = $gl_value;
275 else if ($gl_name == 'css_header') {
276 $GLOBALS[$gl_name] = $rootdir.'/themes/'.$gl_value.'?v='.$v_js_includes;
277 $temp_css_theme_name = $gl_value;
279 else if ($gl_name == 'weekend_days') {
280 $GLOBALS[$gl_name] = explode(',', $gl_value);
282 else if ($gl_name == 'specific_application') {
283 if ($gl_value == '2') $GLOBALS['ippf_specific'] = true;
284 else if ($gl_value == '3') $GLOBALS['weight_loss_clinic'] = true;
286 else if ($gl_name == 'inhouse_pharmacy') {
287 if ($gl_value) $GLOBALS['inhouse_pharmacy'] = true;
288 if ($gl_value == '2') $GLOBALS['sell_non_drug_products'] = 1;
289 else if ($gl_value == '3') $GLOBALS['sell_non_drug_products'] = 2;
291 else {
292 $GLOBALS[$gl_name] = $gl_value;
295 // Language cleanup stuff.
296 $GLOBALS['language_menu_login'] = false;
297 if ((count($GLOBALS['language_menu_show']) >= 1) || $GLOBALS['language_menu_showall']) {
298 $GLOBALS['language_menu_login'] = true;
301 // Added this $GLOBALS['concurrent_layout'] set to 3 in order to support legacy forms
302 // that may use this; note this global has been removed from the standard codebase.
303 $GLOBALS['concurrent_layout'] = 3;
305 // Additional logic to override theme name.
306 // For RTL languages we substitute the theme name with the name of RTL-adapted CSS file.
307 $rtl_override = false;
308 if( isset( $_SESSION['language_direction'] )) {
309 if( $_SESSION['language_direction'] == 'rtl' &&
310 !strpos($GLOBALS['css_header'], 'rtl') ) {
312 // the $css_header_value is set above
313 $rtl_override = true;
316 else if (isset( $_SESSION['language_choice'] )) {
317 //this will support the onsite patient portal which will have a language choice but not yet a set language direction
318 $_SESSION['language_direction'] = getLanguageDir($_SESSION['language_choice']);
319 if ( $_SESSION['language_direction'] == 'rtl' &&
320 !strpos($GLOBALS['css_header'], 'rtl')) {
321 // the $css_header_value is set above
322 $rtl_override = true;
325 else {
326 //$_SESSION['language_direction'] is not set, so will use the default language
327 $default_lang_id = sqlQuery('SELECT lang_id FROM lang_languages WHERE lang_description = ?',array($GLOBALS['language_default']));
329 if ( getLanguageDir( $default_lang_id['lang_id'] ) === 'rtl' && !strpos($GLOBALS['css_header'], 'rtl')) { // @todo eliminate 1 SQL query
330 $rtl_override = true;
335 // change theme name, if the override file exists.
336 if( $rtl_override ) {
337 // the $css_header_value is set above
338 $new_theme = 'rtl_' . $temp_css_theme_name;
340 // Check file existance
341 if( file_exists( $include_root.'/themes/'.$new_theme ) ) {
342 $GLOBALS['css_header'] = $rootdir.'/themes/'.$new_theme.'?v='.$v_js_includes;
343 } else {
344 // throw a warning if rtl'ed file does not exist.
345 error_log("Missing theme file ".text($include_root).'/themes/'.text($new_theme) );
348 unset( $temp_css_theme_name, $new_theme,$rtl_override);
349 // end of RTL section
352 // End of globals table processing.
354 else {
355 // Temporary stuff to handle the case where the globals table does not
356 // exist yet. This will happen in sql_upgrade.php on upgrading to the
357 // first release containing this table.
358 $GLOBALS['language_menu_login'] = true;
359 $GLOBALS['language_menu_showall'] = true;
360 $GLOBALS['language_menu_show'] = array('English (Standard)','Swedish');
361 $GLOBALS['language_default'] = "English (Standard)";
362 $GLOBALS['translate_layout'] = true;
363 $GLOBALS['translate_lists'] = true;
364 $GLOBALS['translate_gacl_groups'] = true;
365 $GLOBALS['translate_form_titles'] = true;
366 $GLOBALS['translate_document_categories'] = true;
367 $GLOBALS['translate_appt_categories'] = true;
368 $timeout = 7200;
369 $openemr_name = 'OpenEMR';
370 $css_header = "$rootdir/themes/style_default.css";
371 $GLOBALS['css_header'] = $css_header;
372 $GLOBALS['schedule_start'] = 8;
373 $GLOBALS['schedule_end'] = 17;
374 $GLOBALS['calendar_interval'] = 15;
375 $GLOBALS['phone_country_code'] = '1';
376 $GLOBALS['disable_non_default_groups'] = true;
377 $GLOBALS['ippf_specific'] = false;
380 // If >0 this will enforce a separate PHP session for each top-level
381 // browser window. You must log in separately for each. This is not
382 // thoroughly tested yet and some browsers might have trouble with it,
383 // so make it 0 if you must. Alternatively, you can set it to 2 to be
384 // notified when the session ID changes.
385 $GLOBALS['restore_sessions'] = 1; // 0=no, 1=yes, 2=yes+debug
387 // Theme definition. All this stuff should be moved to CSS.
389 $top_bg_line = ' bgcolor="#dddddd" ';
390 $GLOBALS['style']['BGCOLOR2'] = "#dddddd";
391 $bottom_bg_line = $top_bg_line;
392 $title_bg_line = ' bgcolor="#bbbbbb" ';
393 $nav_bg_line = ' bgcolor="#94d6e7" ';
394 $login_filler_line = ' bgcolor="#f7f0d5" ';
395 $logocode = "<img class='img-responsive center-block' src='$web_root/sites/" . $_SESSION['site_id'] . "/images/login_logo.gif'>";
396 // optimal size for the tiny logo is height 43 width 86 px
397 // inside the open emr they will be auto reduced
398 $tinylogocode1 = "<img class='tinylogopng' src='$web_root/sites/" . $_SESSION['site_id'] . "/images/logo_1.png'>";
399 $tinylogocode2 = "<img class='tinylogopng' src='$web_root/sites/" . $_SESSION['site_id'] . "/images/logo_2.png'>";
401 $linepic = "$rootdir/pic/repeat_vline9.gif";
402 $table_bg = ' bgcolor="#cccccc" ';
403 $GLOBALS['style']['BGCOLOR1'] = "#cccccc";
404 $GLOBALS['style']['TEXTCOLOR11'] = "#222222";
405 $GLOBALS['style']['HIGHLIGHTCOLOR'] = "#dddddd";
406 $GLOBALS['style']['BOTTOM_BG_LINE'] = $bottom_bg_line;
407 // The height in pixels of the Logo bar at the top of the login page:
408 $GLOBALS['logoBarHeight'] = 110;
409 // The height in pixels of the Navigation bar:
410 $GLOBALS['navBarHeight'] = 22;
411 // The height in pixels of the Title bar:
412 $GLOBALS['titleBarHeight'] = 40;
414 // The assistant word, MORE printed next to titles that can be clicked:
415 // Note this label gets translated here via the xl function
416 // -if you don't want it translated, then strip the xl function away
417 $tmore = xl('(More)');
418 // The assistant word, BACK printed next to titles that return to previous screens:
419 // Note this label gets translated here via the xl function
420 // -if you don't want it translated, then strip the xl function away
421 $tback = xl('(Back)');
423 // This is the idle logout function:
424 // if a page has not been refreshed within this many seconds, the interface
425 // will return to the login page
426 if (!empty($special_timeout)) {
427 $timeout = intval($special_timeout);
430 $versionService = new \services\VersionService();
431 $version = $versionService->fetch();
433 if (!empty($version)) {
434 //Version tag
435 $patch_appending = "";
436 //Collected below function call to a variable, since unable to directly include
437 // function calls within empty() in php versions < 5.5 .
438 $version_getrealpatch = $version->getRealPatch();
439 if ( ($version->getRealPatch() != '0') && (!(empty($version_getrealpatch))) ) {
440 $patch_appending = " (".$version->getRealPatch().")";
443 $openemr_version = $version->getMajor() . "." . $version->getMinor() . "." . $version->getPatch();
444 $openemr_version .= $version->getTag() . $patch_appending;
445 } else {
446 $openemr_version = xl('Unknown version');
449 $srcdir = $GLOBALS['srcdir'];
450 $login_screen = $GLOBALS['login_screen'];
451 $GLOBALS['css_header'] = $css_header;
452 $GLOBALS['backpic'] = $backpic;
454 // 1 = send email message to given id for Emergency Login user activation,
455 // else 0.
456 $GLOBALS['Emergency_Login_email'] = empty($GLOBALS['Emergency_Login_email_id']) ? 0 : 1;
458 //set include_de_identification to enable De-identification (currently de-identification works fine only with linux machines)
459 //Run de_identification_upgrade.php script to upgrade OpenEMR database to include procedures,
460 //functions, tables for de-identification(Mysql root user and password is required for successful
461 //execution of the de-identification upgrade script)
462 $GLOBALS['include_de_identification']=0;
463 // Include the authentication module code here, but the rule is
464 // if the file has the word "login" in the source code file name,
465 // don't include the authentication module - we do this to avoid
466 // include loops.
468 if ( ($ignoreAuth_offsite_portal === true) && ($GLOBALS['portal_offsite_enable'] == 1) ) {
469 $ignoreAuth = true;
471 if (!$ignoreAuth) {
472 include_once("$srcdir/auth.inc");
476 // This is the background color to apply to form fields that are searchable.
477 // Currently it is applicable only to the "Search or Add Patient" form.
478 $GLOBALS['layout_search_color'] = '#ffff55';
480 //EMAIL SETTINGS
481 $SMTP_Auth = !empty($GLOBALS['SMTP_USER']);
484 //module configurations
485 $GLOBALS['baseModDir'] = "interface/modules/"; //default path of modules
486 $GLOBALS['customModDir']= "custom_modules"; //non zend modules
487 $GLOBALS['zendModDir'] = "zend_modules"; //zend modules
489 // Don't change anything below this line. ////////////////////////////
491 $encounter = empty($_SESSION['encounter']) ? 0 : $_SESSION['encounter'];
493 if (!empty($_GET['pid']) && empty($_SESSION['pid'])) {
494 $_SESSION['pid'] = $_GET['pid'];
496 elseif (!empty($_POST['pid']) && empty($_SESSION['pid'])) {
497 $_SESSION['pid'] = $_POST['pid'];
499 $pid = empty($_SESSION['pid']) ? 0 : $_SESSION['pid'];
500 $userauthorized = empty($_SESSION['userauthorized']) ? 0 : $_SESSION['userauthorized'];
501 $groupname = empty($_SESSION['authProvider']) ? 0 : $_SESSION['authProvider'];
503 // global interface function to format text length using ellipses
504 function strterm($string,$length) {
505 if (strlen($string) >= ($length-3)) {
506 return substr($string,0,$length-3) . "...";
507 } else {
508 return $string;
512 // Override temporary_files_dir if PHP >= 5.2.1.
513 if (version_compare(phpversion(), "5.2.1", ">=")) {
514 $GLOBALS['temporary_files_dir'] = rtrim(sys_get_temp_dir(),'/');
517 // turn off PHP compatibility warnings
518 ini_set("session.bug_compat_warn","off");
520 //////////////////////////////////////////////////////////////////
522 /* Pages with "myadmin" in the URL don't need register_globals. */
523 $fake_register_globals =
524 $fake_register_globals && (strpos($_SERVER['REQUEST_URI'],"myadmin") === FALSE);
527 // Emulates register_globals = On. Moved to the bottom of globals.php to prevent
528 // overrides of any variables used during global setup.
529 // EXTR_SKIP flag set to prevent overriding any variables defined earlier
530 if ($fake_register_globals) {
531 extract($_GET,EXTR_SKIP);
532 extract($_POST,EXTR_SKIP);