Converted deleter.php to standard security model, take 2.
[openemr.git] / interface / globals.php
blob02f98997d0d1c5575aec60eeedf03d8a6bab1e7d
1 <?php
3 // Is this windows or non-windows? Create a boolean definition.
4 if (!defined('IS_WINDOWS'))
5 define('IS_WINDOWS', (stripos(PHP_OS,'WIN') === 0));
7 // Some important php.ini overrides. Defaults for these values are often
8 // too small. You might choose to adjust them further.
9 //
10 ini_set('session.gc_maxlifetime', '14400');
12 // This is for sanitization of all escapes.
13 // (ie. reversing magic quotes if it's set)
14 if (isset($sanitize_all_escapes) && $sanitize_all_escapes) {
15 if (get_magic_quotes_gpc()) {
16 function undoMagicQuotes($array, $topLevel=true) {
17 $newArray = array();
18 foreach($array as $key => $value) {
19 if (!$topLevel) {
20 $key = stripslashes($key);
22 if (is_array($value)) {
23 $newArray[$key] = undoMagicQuotes($value, false);
25 else {
26 $newArray[$key] = stripslashes($value);
29 return $newArray;
31 $_GET = undoMagicQuotes($_GET);
32 $_POST = undoMagicQuotes($_POST);
33 $_COOKIE = undoMagicQuotes($_COOKIE);
34 $_REQUEST = undoMagicQuotes($_REQUEST);
39 // The webserver_root and web_root are now automatically collected.
40 // If not working, can set manually below.
41 // Auto collect the full absolute directory path for openemr.
42 $webserver_root = dirname(dirname(__FILE__));
43 if (IS_WINDOWS) {
44 //convert windows path separators
45 $webserver_root = str_replace("\\","/",$webserver_root);
47 // Collect the apache server document root (and convert to windows slashes, if needed)
48 $server_document_root = realpath($_SERVER['DOCUMENT_ROOT']);
49 if (IS_WINDOWS) {
50 //convert windows path separators
51 $server_document_root = str_replace("\\","/",$server_document_root);
53 // Auto collect the relative html path, i.e. what you would type into the web
54 // browser after the server address to get to OpenEMR.
55 // This removes the leading portion of $webserver_root that it has in common with the web server's document
56 // root and assigns the result to $web_root. In addition to the common case where $webserver_root is
57 // /var/www/openemr and document root is /var/www, this also handles the case where document root is
58 // /var/www/html and there is an Apache "Alias" command that directs /openemr to /var/www/openemr.
59 $web_root = substr($webserver_root, strspn($webserver_root ^ $server_document_root, "\0"));
60 // Ensure web_root starts with a path separator
61 if (preg_match("/^[^\/]/",$web_root)) {
62 $web_root = "/".$web_root;
64 // The webserver_root and web_root are now automatically collected in
65 // real time per above code. If above is not working, can uncomment and
66 // set manually here:
67 // $webserver_root = "/var/www/openemr";
68 // $web_root = "/openemr";
71 // This is the directory that contains site-specific data. Change this
72 // only if you have some reason to.
73 $GLOBALS['OE_SITES_BASE'] = "$webserver_root/sites";
75 // The session name names a cookie stored in the browser.
76 // Now that restore_session() is implemented in javaScript, session IDs are
77 // effectively saved in the top level browser window and there is no longer
78 // any need to change the session name for different OpenEMR instances.
79 session_name("OpenEMR");
81 session_start();
83 // Set the site ID if required. This must be done before any database
84 // access is attempted.
85 if (empty($_SESSION['site_id']) || !empty($_GET['site'])) {
86 if (!empty($_GET['site'])) {
87 $tmp = $_GET['site'];
89 else {
90 if (!$ignoreAuth) die("Site ID is missing from session data!");
91 $tmp = $_SERVER['HTTP_HOST'];
92 if (!is_dir($GLOBALS['OE_SITES_BASE'] . "/$tmp")) $tmp = "default";
94 if (empty($tmp) || preg_match('/[^A-Za-z0-9\\-.]/', $tmp))
95 die("Site ID '". htmlspecialchars($tmp,ENT_NOQUOTES) . "' contains invalid characters.");
96 if (isset($_SESSION['site_id']) && ($_SESSION['site_id'] != $tmp)) {
97 // This is to prevent using session to penetrate other OpenEMR instances within same multisite module
98 session_unset(); // clear session, clean logout
99 if (isset($landingpage) && !empty($landingpage)) {
100 // OpenEMR Patient Portal use
101 header('Location: index.php?site='.$tmp);
103 else {
104 // Main OpenEMR use
105 header('Location: ../login/login_frame.php?site='.$tmp); // Assuming in the interface/main directory
107 exit;
109 if (!isset($_SESSION['site_id']) || $_SESSION['site_id'] != $tmp) {
110 $_SESSION['site_id'] = $tmp;
111 //error_log("Session site ID has been set to '$tmp'"); // debugging
115 // Set the site-specific directory path.
116 $GLOBALS['OE_SITE_DIR'] = $GLOBALS['OE_SITES_BASE'] . "/" . $_SESSION['site_id'];
118 require_once($GLOBALS['OE_SITE_DIR'] . "/config.php");
120 // Collecting the utf8 disable flag from the sqlconf.php file in order
121 // to set the correct html encoding. utf8 vs iso-8859-1. If flag is set
122 // then set to iso-8859-1.
123 require_once(dirname(__FILE__) . "/../library/sqlconf.php");
124 if (!$disable_utf8_flag) {
125 ini_set('default_charset', 'utf-8');
126 $HTML_CHARSET = "UTF-8";
127 mb_internal_encoding('UTF-8');
129 else {
130 ini_set('default_charset', 'iso-8859-1');
131 $HTML_CHARSET = "ISO-8859-1";
132 mb_internal_encoding('ISO-8859-1');
135 // Root directory, relative to the webserver root:
136 $GLOBALS['rootdir'] = "$web_root/interface";
137 $rootdir = $GLOBALS['rootdir'];
138 // Absolute path to the source code include and headers file directory (Full path):
139 $GLOBALS['srcdir'] = "$webserver_root/library";
140 // Absolute path to the location of documentroot directory for use with include statements:
141 $GLOBALS['fileroot'] = "$webserver_root";
142 // Absolute path to the location of interface directory for use with include statements:
143 $include_root = "$webserver_root/interface";
144 // Absolute path to the location of documentroot directory for use with include statements:
145 $GLOBALS['webroot'] = $web_root;
147 $GLOBALS['template_dir'] = $GLOBALS['fileroot'] . "/templates/";
148 $GLOBALS['incdir'] = $include_root;
149 // Location of the login screen file
150 $GLOBALS['login_screen'] = $GLOBALS['rootdir'] . "/login_screen.php";
152 // Variable set for Eligibility Verification [EDI-271] path
153 $GLOBALS['edi_271_file_path'] = $GLOBALS['OE_SITE_DIR'] . "/edi/";
155 // Include the translation engine. This will also call sql.inc to
156 // open the openemr mysql connection.
157 include_once (dirname(__FILE__) . "/../library/translation.inc.php");
159 // Include convenience functions with shorter names than "htmlspecialchars" (for security)
160 require_once (dirname(__FILE__) . "/../library/htmlspecialchars.inc.php");
162 // Include sanitization/checking functions (for security)
163 require_once (dirname(__FILE__) . "/../library/formdata.inc.php");
165 // Include sanitization/checking function (for security)
166 require_once (dirname(__FILE__) . "/../library/sanitize.inc.php");
168 // Includes functions for date internationalization
169 include_once (dirname(__FILE__) . "/../library/date_functions.php");
171 // Defaults for specific applications.
172 $GLOBALS['athletic_team'] = false;
173 $GLOBALS['weight_loss_clinic'] = false;
174 $GLOBALS['ippf_specific'] = false;
175 $GLOBALS['cene_specific'] = false;
177 // Defaults for drugs and products.
178 $GLOBALS['inhouse_pharmacy'] = false;
179 $GLOBALS['sell_non_drug_products'] = 0;
181 $glrow = sqlQuery("SHOW TABLES LIKE 'globals'");
182 if (!empty($glrow)) {
183 // Collect user specific settings from user_settings table.
185 $gl_user = array();
186 if (!empty($_SESSION['authUserID'])) {
187 $glres_user = sqlStatement("SELECT `setting_label`, `setting_value` " .
188 "FROM `user_settings` " .
189 "WHERE `setting_user` = ? " .
190 "AND `setting_label` LIKE 'global:%'", array($_SESSION['authUserID']) );
191 for($iter=0; $row=sqlFetchArray($glres_user); $iter++) {
192 //remove global_ prefix from label
193 $row['setting_label'] = substr($row['setting_label'],7);
194 $gl_user[$iter]=$row;
197 // Set global parameters from the database globals table.
198 // Some parameters require custom handling.
200 $GLOBALS['language_menu_show'] = array();
201 $glres = sqlStatement("SELECT gl_name, gl_index, gl_value FROM globals " .
202 "ORDER BY gl_name, gl_index");
203 while ($glrow = sqlFetchArray($glres)) {
204 $gl_name = $glrow['gl_name'];
205 $gl_value = $glrow['gl_value'];
206 // Adjust for user specific settings
207 if (!empty($gl_user)) {
208 foreach ($gl_user as $setting) {
209 if ($gl_name == $setting['setting_label']) {
210 $gl_value = $setting['setting_value'];
214 if ($gl_name == 'language_menu_other') {
215 $GLOBALS['language_menu_show'][] = $gl_value;
217 else if ($gl_name == 'css_header') {
218 $GLOBALS[$gl_name] = $rootdir.'/themes/'. $gl_value;
219 $temp_css_theme_name = $gl_value;
221 else if ($gl_name == 'specific_application') {
222 if ($gl_value == '1') $GLOBALS['athletic_team'] = true;
223 else if ($gl_value == '2') $GLOBALS['ippf_specific'] = true;
224 else if ($gl_value == '3') $GLOBALS['weight_loss_clinic'] = true;
226 else if ($gl_name == 'inhouse_pharmacy') {
227 if ($gl_value) $GLOBALS['inhouse_pharmacy'] = true;
228 if ($gl_value == '2') $GLOBALS['sell_non_drug_products'] = 1;
229 else if ($gl_value == '3') $GLOBALS['sell_non_drug_products'] = 2;
231 else {
232 $GLOBALS[$gl_name] = $gl_value;
235 // Language cleanup stuff.
236 $GLOBALS['language_menu_login'] = false;
237 if ((count($GLOBALS['language_menu_show']) >= 1) || $GLOBALS['language_menu_showall']) {
238 $GLOBALS['language_menu_login'] = true;
242 // Additional logic to override theme name.
243 // For RTL languages we substitute the theme name with the name of RTL-adapted CSS file.
244 $rtl_override = false;
245 if( isset( $_SESSION['language_direction'] )) {
246 if( $_SESSION['language_direction'] == 'rtl' &&
247 !strpos($GLOBALS['css_header'], 'rtl') ) {
249 // the $css_header_value is set above
250 $rtl_override = true;
254 else {
255 //$_SESSION['language_direction'] is not set, so will use the default language
256 $default_lang_id = sqlQuery('SELECT lang_id FROM lang_languages WHERE lang_description = ?',array($GLOBALS['language_default']));
258 if ( getLanguageDir( $default_lang_id['lang_id'] ) === 'rtl' && !strpos($GLOBALS['css_header'], 'rtl')) { // @todo eliminate 1 SQL query
259 $rtl_override = true;
264 // change theme name, if the override file exists.
265 if( $rtl_override ) {
266 // the $css_header_value is set above
267 $new_theme = 'rtl_' . $temp_css_theme_name;
269 // Check file existance
270 if( file_exists( $include_root.'/themes/'.$new_theme ) ) {
271 $GLOBALS['css_header'] = $rootdir.'/themes/'.$new_theme;
272 } else {
273 // throw a warning if rtl'ed file does not exist.
274 error_log("Missing theme file ".text($include_root).'/themes/'.text($new_theme) );
277 unset( $temp_css_theme_name, $new_theme,$rtl_override);
278 // end of RTL section
281 // End of globals table processing.
283 else {
284 // Temporary stuff to handle the case where the globals table does not
285 // exist yet. This will happen in sql_upgrade.php on upgrading to the
286 // first release containing this table.
287 $GLOBALS['language_menu_login'] = true;
288 $GLOBALS['language_menu_showall'] = true;
289 $GLOBALS['language_menu_show'] = array('English (Standard)','Swedish');
290 $GLOBALS['language_default'] = "English (Standard)";
291 $GLOBALS['translate_layout'] = true;
292 $GLOBALS['translate_lists'] = true;
293 $GLOBALS['translate_gacl_groups'] = true;
294 $GLOBALS['translate_form_titles'] = true;
295 $GLOBALS['translate_document_categories'] = true;
296 $GLOBALS['translate_appt_categories'] = true;
297 $GLOBALS['concurrent_layout'] = 2;
298 $timeout = 7200;
299 $openemr_name = 'OpenEMR';
300 $css_header = "$rootdir/themes/style_default.css";
301 $GLOBALS['css_header'] = $css_header;
302 $GLOBALS['schedule_start'] = 8;
303 $GLOBALS['schedule_end'] = 17;
304 $GLOBALS['calendar_interval'] = 15;
305 $GLOBALS['phone_country_code'] = '1';
306 $GLOBALS['disable_non_default_groups'] = true;
307 $GLOBALS['ippf_specific'] = false;
310 // If >0 this will enforce a separate PHP session for each top-level
311 // browser window. You must log in separately for each. This is not
312 // thoroughly tested yet and some browsers might have trouble with it,
313 // so make it 0 if you must. Alternatively, you can set it to 2 to be
314 // notified when the session ID changes.
315 $GLOBALS['restore_sessions'] = 1; // 0=no, 1=yes, 2=yes+debug
317 // Theme definition. All this stuff should be moved to CSS.
319 if ($GLOBALS['concurrent_layout']) {
320 $top_bg_line = ' bgcolor="#dddddd" ';
321 $GLOBALS['style']['BGCOLOR2'] = "#dddddd";
322 $bottom_bg_line = $top_bg_line;
323 $title_bg_line = ' bgcolor="#bbbbbb" ';
324 $nav_bg_line = ' bgcolor="#94d6e7" ';
325 } else {
326 $top_bg_line = ' bgcolor="#94d6e7" ';
327 $GLOBALS['style']['BGCOLOR2'] = "#94d6e7";
328 $bottom_bg_line = ' background="'.$rootdir.'/pic/aquabg.gif" ';
329 $title_bg_line = ' bgcolor="#aaffff" ';
330 $nav_bg_line = ' bgcolor="#94d6e7" ';
332 $login_filler_line = ' bgcolor="#f7f0d5" ';
333 $logocode = "<img src='$web_root/sites/" . $_SESSION['site_id'] . "/images/login_logo.gif'>";
334 $linepic = "$rootdir/pic/repeat_vline9.gif";
335 $table_bg = ' bgcolor="#cccccc" ';
336 $GLOBALS['style']['BGCOLOR1'] = "#cccccc";
337 $GLOBALS['style']['TEXTCOLOR11'] = "#222222";
338 $GLOBALS['style']['HIGHLIGHTCOLOR'] = "#dddddd";
339 $GLOBALS['style']['BOTTOM_BG_LINE'] = $bottom_bg_line;
340 // The height in pixels of the Logo bar at the top of the login page:
341 $GLOBALS['logoBarHeight'] = 110;
342 // The height in pixels of the Navigation bar:
343 $GLOBALS['navBarHeight'] = 22;
344 // The height in pixels of the Title bar:
345 $GLOBALS['titleBarHeight'] = 40;
347 // The assistant word, MORE printed next to titles that can be clicked:
348 // Note this label gets translated here via the xl function
349 // -if you don't want it translated, then strip the xl function away
350 $tmore = xl('(More)');
351 // The assistant word, BACK printed next to titles that return to previous screens:
352 // Note this label gets translated here via the xl function
353 // -if you don't want it translated, then strip the xl function away
354 $tback = xl('(Back)');
356 // This is the idle logout function:
357 // if a page has not been refreshed within this many seconds, the interface
358 // will return to the login page
359 if (!empty($special_timeout)) {
360 $timeout = intval($special_timeout);
363 //Version tag
364 require_once(dirname(__FILE__) . "/../version.php");
365 $patch_appending = "";
366 if ( ($v_realpatch != '0') && (!(empty($v_realpatch))) ) {
367 $patch_appending = " (".$v_realpatch.")";
369 $openemr_version = "$v_major.$v_minor.$v_patch".$v_tag.$patch_appending;
371 $srcdir = $GLOBALS['srcdir'];
372 $login_screen = $GLOBALS['login_screen'];
373 $GLOBALS['css_header'] = $css_header;
374 $GLOBALS['backpic'] = $backpic;
376 // 1 = send email message to given id for Emergency Login user activation,
377 // else 0.
378 $GLOBALS['Emergency_Login_email'] = $GLOBALS['Emergency_Login_email_id'] ? 1 : 0;
380 //set include_de_identification to enable De-identification (currently de-identification works fine only with linux machines)
381 //Run de_identification_upgrade.php script to upgrade OpenEMR database to include procedures,
382 //functions, tables for de-identification(Mysql root user and password is required for successful
383 //execution of the de-identification upgrade script)
384 $GLOBALS['include_de_identification']=0;
385 // Include the authentication module code here, but the rule is
386 // if the file has the word "login" in the source code file name,
387 // don't include the authentication module - we do this to avoid
388 // include loops.
390 if (!isset($ignoreAuth) || !$ignoreAuth) {
391 include_once("$srcdir/auth.inc");
395 // This is the background color to apply to form fields that are searchable.
396 // Currently it is applicable only to the "Search or Add Patient" form.
397 $GLOBALS['layout_search_color'] = '#ffff55';
399 //EMAIL SETTINGS
400 $SMTP_Auth = !empty($GLOBALS['SMTP_USER']);
403 //module configurations
404 $GLOBALS['baseModDir'] = "interface/modules/"; //default path of modules
405 $GLOBALS['customModDir']= "custom_modules"; //non zend modules
406 $GLOBALS['zendModDir'] = "zend_modules"; //zend modules
408 // Don't change anything below this line. ////////////////////////////
410 $encounter = empty($_SESSION['encounter']) ? 0 : $_SESSION['encounter'];
412 if (!empty($_GET['pid']) && empty($_SESSION['pid'])) {
413 $_SESSION['pid'] = $_GET['pid'];
415 elseif (!empty($_POST['pid']) && empty($_SESSION['pid'])) {
416 $_SESSION['pid'] = $_POST['pid'];
418 $pid = empty($_SESSION['pid']) ? 0 : $_SESSION['pid'];
419 $userauthorized = empty($_SESSION['userauthorized']) ? 0 : $_SESSION['userauthorized'];
420 $groupname = empty($_SESSION['authProvider']) ? 0 : $_SESSION['authProvider'];
422 // global interface function to format text length using ellipses
423 function strterm($string,$length) {
424 if (strlen($string) >= ($length-3)) {
425 return substr($string,0,$length-3) . "...";
426 } else {
427 return $string;
431 // Override temporary_files_dir if PHP >= 5.2.1.
432 if (version_compare(phpversion(), "5.2.1", ">=")) {
433 $GLOBALS['temporary_files_dir'] = rtrim(sys_get_temp_dir(),'/');
436 // turn off PHP compatibility warnings
437 ini_set("session.bug_compat_warn","off");
439 //////////////////////////////////////////////////////////////////
441 /* If the includer didn't specify, assume they want us to "fake" register_globals. */
442 if (!isset($fake_register_globals)) {
443 $fake_register_globals = TRUE;
446 /* Pages with "myadmin" in the URL don't need register_globals. */
447 $fake_register_globals =
448 $fake_register_globals && (strpos($_SERVER['REQUEST_URI'],"myadmin") === FALSE);
451 // Emulates register_globals = On. Moved to the bottom of globals.php to prevent
452 // overrides of any variables used during global setup.
453 // EXTR_SKIP flag set to prevent overriding any variables defined earlier
454 if ($fake_register_globals) {
455 extract($_GET,EXTR_SKIP);
456 extract($_POST,EXTR_SKIP);