Implemented the following functionality for MU2 - ยง170.314(a)(12) Image Results
[openemr.git] / interface / globals.php
blob420a0cba337f30b6218046c1f57468170093af7d
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 /* If the includer didn't specify, assume they want us to "fake" register_globals. */
13 if (!isset($fake_register_globals)) {
14 $fake_register_globals = TRUE;
17 /* Pages with "myadmin" in the URL don't need register_globals. */
18 $fake_register_globals =
19 $fake_register_globals && (strpos($_SERVER['REQUEST_URI'],"myadmin") === FALSE);
21 // Emulates register_globals = On. Moved to here from the bottom of this file
22 // to address security issues. Need to change everything requiring this!
23 if ($fake_register_globals) {
24 extract($_GET);
25 extract($_POST);
28 // This is for sanitization of all escapes.
29 // (ie. reversing magic quotes if it's set)
30 if (isset($sanitize_all_escapes) && $sanitize_all_escapes) {
31 if (get_magic_quotes_gpc()) {
32 function undoMagicQuotes($array, $topLevel=true) {
33 $newArray = array();
34 foreach($array as $key => $value) {
35 if (!$topLevel) {
36 $key = stripslashes($key);
38 if (is_array($value)) {
39 $newArray[$key] = undoMagicQuotes($value, false);
41 else {
42 $newArray[$key] = stripslashes($value);
45 return $newArray;
47 $_GET = undoMagicQuotes($_GET);
48 $_POST = undoMagicQuotes($_POST);
49 $_COOKIE = undoMagicQuotes($_COOKIE);
50 $_REQUEST = undoMagicQuotes($_REQUEST);
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(dirname(__FILE__));
59 if (IS_WINDOWS) {
60 //convert windows path separators
61 $webserver_root = str_replace("\\","/",$webserver_root);
63 // Collect the apache server document root (and convert to windows slashes, if needed)
64 $server_document_root = $_SERVER['DOCUMENT_ROOT'];
65 if (IS_WINDOWS) {
66 //convert windows path separators
67 $server_document_root = str_replace("\\","/",$server_document_root);
69 // Auto collect the relative html path, i.e. what you would type into the web
70 // browser after the server address to get to OpenEMR.
71 // This removes the leading portion of $webserver_root that it has in common with the web server's document
72 // root and assigns the result to $web_root. In addition to the common case where $webserver_root is
73 // /var/www/openemr and document root is /var/www, this also handles the case where document root is
74 // /var/www/html and there is an Apache "Alias" command that directs /openemr to /var/www/openemr.
75 $web_root = substr($webserver_root, strspn($webserver_root ^ $server_document_root, "\0"));
76 // Ensure web_root starts with a path separator
77 if (preg_match("/^[^\/]/",$web_root)) {
78 $web_root = "/".$web_root;
80 // The webserver_root and web_root are now automatically collected in
81 // real time per above code. If above is not working, can uncomment and
82 // set manually here:
83 // $webserver_root = "/var/www/openemr";
84 // $web_root = "/openemr";
87 // This is the directory that contains site-specific data. Change this
88 // only if you have some reason to.
89 $GLOBALS['OE_SITES_BASE'] = "$webserver_root/sites";
91 // The session name names a cookie stored in the browser.
92 // If you modify session_name, then need to place the identical name in
93 // the phpmyadmin file here: openemr/phpmyadmin/libraries/session.inc.php
94 // at line 71. This was required after embedded new phpmyadmin version on
95 // 05-12-2009 by Brady. Hopefully will figure out a more appropriate fix.
96 // Now that restore_session() is implemented in javaScript, session IDs are
97 // effectively saved in the top level browser window and there is no longer
98 // any need to change the session name for different OpenEMR instances.
99 session_name("OpenEMR");
101 session_start();
103 // Set the site ID if required. This must be done before any database
104 // access is attempted.
105 if (empty($_SESSION['site_id']) || !empty($_GET['site'])) {
106 if (!empty($_GET['site'])) {
107 $tmp = $_GET['site'];
109 else {
110 if (!$ignoreAuth) die("Site ID is missing from session data!");
111 $tmp = $_SERVER['HTTP_HOST'];
112 if (!is_dir($GLOBALS['OE_SITES_BASE'] . "/$tmp")) $tmp = "default";
114 if (empty($tmp) || preg_match('/[^A-Za-z0-9\\-.]/', $tmp))
115 die("Site ID '". htmlspecialchars($tmp,ENT_NOQUOTES) . "' contains invalid characters.");
116 if (isset($_SESSION['site_id']) && ($_SESSION['site_id'] != $tmp)) {
117 // This is to prevent using session to penetrate other OpenEMR instances within same multisite module
118 session_unset(); // clear session, clean logout
119 if (isset($landingpage) && !empty($landingpage)) {
120 // OpenEMR Patient Portal use
121 header('Location: index.php?site='.$tmp);
123 else {
124 // Main OpenEMR use
125 header('Location: ../login/login_frame.php?site='.$tmp); // Assuming in the interface/main directory
127 exit;
129 if (!isset($_SESSION['site_id']) || $_SESSION['site_id'] != $tmp) {
130 $_SESSION['site_id'] = $tmp;
131 //error_log("Session site ID has been set to '$tmp'"); // debugging
135 // Set the site-specific directory path.
136 $GLOBALS['OE_SITE_DIR'] = $GLOBALS['OE_SITES_BASE'] . "/" . $_SESSION['site_id'];
138 require_once($GLOBALS['OE_SITE_DIR'] . "/config.php");
140 // Collecting the utf8 disable flag from the sqlconf.php file in order
141 // to set the correct html encoding. utf8 vs iso-8859-1. If flag is set
142 // then set to iso-8859-1.
143 require_once(dirname(__FILE__) . "/../library/sqlconf.php");
144 if (!$disable_utf8_flag) {
145 ini_set('default_charset', 'utf-8');
146 $HTML_CHARSET = "UTF-8";
148 else {
149 ini_set('default_charset', 'iso-8859-1');
150 $HTML_CHARSET = "ISO-8859-1";
153 // Root directory, relative to the webserver root:
154 $GLOBALS['rootdir'] = "$web_root/interface";
155 $rootdir = $GLOBALS['rootdir'];
156 // Absolute path to the source code include and headers file directory (Full path):
157 $GLOBALS['srcdir'] = "$webserver_root/library";
158 // Absolute path to the location of documentroot directory for use with include statements:
159 $GLOBALS['fileroot'] = "$webserver_root";
160 // Absolute path to the location of interface directory for use with include statements:
161 $include_root = "$webserver_root/interface";
162 // Absolute path to the location of documentroot directory for use with include statements:
163 $GLOBALS['webroot'] = $web_root;
165 $GLOBALS['template_dir'] = $GLOBALS['fileroot'] . "/templates/";
166 $GLOBALS['incdir'] = $include_root;
167 // Location of the login screen file
168 $GLOBALS['login_screen'] = $GLOBALS['rootdir'] . "/login_screen.php";
170 // Variable set for Eligibility Verification [EDI-271] path
171 $GLOBALS['edi_271_file_path'] = $GLOBALS['OE_SITE_DIR'] . "/edi/";
173 // Include the translation engine. This will also call sql.inc to
174 // open the openemr mysql connection.
175 include_once (dirname(__FILE__) . "/../library/translation.inc.php");
177 // Include convenience functions with shorter names than "htmlspecialchars" (for security)
178 require_once (dirname(__FILE__) . "/../library/htmlspecialchars.inc.php");
180 // Include sanitization/checking functions (for security)
181 require_once (dirname(__FILE__) . "/../library/formdata.inc.php");
183 // Include sanitization/checking function (for security)
184 require_once (dirname(__FILE__) . "/../library/sanitize.inc.php");
186 // Includes functions for date internationalization
187 include_once (dirname(__FILE__) . "/../library/date_functions.php");
189 // Defaults for specific applications.
190 $GLOBALS['athletic_team'] = false;
191 $GLOBALS['weight_loss_clinic'] = false;
192 $GLOBALS['ippf_specific'] = false;
193 $GLOBALS['cene_specific'] = false;
195 // Defaults for drugs and products.
196 $GLOBALS['inhouse_pharmacy'] = false;
197 $GLOBALS['sell_non_drug_products'] = 0;
199 $glrow = sqlQuery("SHOW TABLES LIKE 'globals'");
200 if (!empty($glrow)) {
201 // Collect user specific settings from user_settings table.
203 $gl_user = array();
204 if (!empty($_SESSION['authUserID'])) {
205 $glres_user = sqlStatement("SELECT `setting_label`, `setting_value` " .
206 "FROM `user_settings` " .
207 "WHERE `setting_user` = ? " .
208 "AND `setting_label` LIKE 'global:%'", array($_SESSION['authUserID']) );
209 for($iter=0; $row=sqlFetchArray($glres_user); $iter++) {
210 //remove global_ prefix from label
211 $row['setting_label'] = substr($row['setting_label'],7);
212 $gl_user[$iter]=$row;
215 // Set global parameters from the database globals table.
216 // Some parameters require custom handling.
218 $GLOBALS['language_menu_show'] = array();
219 $glres = sqlStatement("SELECT gl_name, gl_index, gl_value FROM globals " .
220 "ORDER BY gl_name, gl_index");
221 while ($glrow = sqlFetchArray($glres)) {
222 $gl_name = $glrow['gl_name'];
223 $gl_value = $glrow['gl_value'];
224 // Adjust for user specific settings
225 if (!empty($gl_user)) {
226 foreach ($gl_user as $setting) {
227 if ($gl_name == $setting['setting_label']) {
228 $gl_value = $setting['setting_value'];
232 if ($gl_name == 'language_menu_other') {
233 $GLOBALS['language_menu_show'][] = $gl_value;
235 else if ($gl_name == 'css_header') {
236 $GLOBALS[$gl_name] = "$rootdir/themes/" . $gl_value;
238 else if ($gl_name == 'specific_application') {
239 if ($gl_value == '1') $GLOBALS['athletic_team'] = true;
240 else if ($gl_value == '2') $GLOBALS['ippf_specific'] = true;
241 else if ($gl_value == '3') $GLOBALS['weight_loss_clinic'] = true;
243 else if ($gl_name == 'inhouse_pharmacy') {
244 if ($gl_value) $GLOBALS['inhouse_pharmacy'] = true;
245 if ($gl_value == '2') $GLOBALS['sell_non_drug_products'] = 1;
246 else if ($gl_value == '3') $GLOBALS['sell_non_drug_products'] = 2;
248 else {
249 $GLOBALS[$gl_name] = $gl_value;
252 // Language cleanup stuff.
253 $GLOBALS['language_menu_login'] = false;
254 if ((count($GLOBALS['language_menu_show']) >= 1) || $GLOBALS['language_menu_showall']) {
255 $GLOBALS['language_menu_login'] = true;
258 // End of globals table processing.
260 else {
261 // Temporary stuff to handle the case where the globals table does not
262 // exist yet. This will happen in sql_upgrade.php on upgrading to the
263 // first release containing this table.
264 $GLOBALS['language_menu_login'] = true;
265 $GLOBALS['language_menu_showall'] = true;
266 $GLOBALS['language_menu_show'] = array('English (Standard)','Swedish');
267 $GLOBALS['language_default'] = "English (Standard)";
268 $GLOBALS['translate_layout'] = true;
269 $GLOBALS['translate_lists'] = true;
270 $GLOBALS['translate_gacl_groups'] = true;
271 $GLOBALS['translate_form_titles'] = true;
272 $GLOBALS['translate_document_categories'] = true;
273 $GLOBALS['translate_appt_categories'] = true;
274 $GLOBALS['concurrent_layout'] = 2;
275 $timeout = 7200;
276 $openemr_name = 'OpenEMR';
277 $css_header = "$rootdir/themes/style_default.css";
278 $GLOBALS['css_header'] = $css_header;
279 $GLOBALS['schedule_start'] = 8;
280 $GLOBALS['schedule_end'] = 17;
281 $GLOBALS['calendar_interval'] = 15;
282 $GLOBALS['phone_country_code'] = '1';
283 $GLOBALS['disable_non_default_groups'] = true;
284 $GLOBALS['ippf_specific'] = false;
287 // If >0 this will enforce a separate PHP session for each top-level
288 // browser window. You must log in separately for each. This is not
289 // thoroughly tested yet and some browsers might have trouble with it,
290 // so make it 0 if you must. Alternatively, you can set it to 2 to be
291 // notified when the session ID changes.
292 $GLOBALS['restore_sessions'] = 1; // 0=no, 1=yes, 2=yes+debug
294 // Theme definition. All this stuff should be moved to CSS.
296 if ($GLOBALS['concurrent_layout']) {
297 $top_bg_line = ' bgcolor="#dddddd" ';
298 $GLOBALS['style']['BGCOLOR2'] = "#dddddd";
299 $bottom_bg_line = $top_bg_line;
300 $title_bg_line = ' bgcolor="#bbbbbb" ';
301 $nav_bg_line = ' bgcolor="#94d6e7" ';
302 } else {
303 $top_bg_line = ' bgcolor="#94d6e7" ';
304 $GLOBALS['style']['BGCOLOR2'] = "#94d6e7";
305 $bottom_bg_line = ' background="'.$rootdir.'/pic/aquabg.gif" ';
306 $title_bg_line = ' bgcolor="#aaffff" ';
307 $nav_bg_line = ' bgcolor="#94d6e7" ';
309 $login_filler_line = ' bgcolor="#f7f0d5" ';
310 $logocode = "<img src='$web_root/sites/" . $_SESSION['site_id'] . "/images/login_logo.gif'>";
311 $linepic = "$rootdir/pic/repeat_vline9.gif";
312 $table_bg = ' bgcolor="#cccccc" ';
313 $GLOBALS['style']['BGCOLOR1'] = "#cccccc";
314 $GLOBALS['style']['TEXTCOLOR11'] = "#222222";
315 $GLOBALS['style']['HIGHLIGHTCOLOR'] = "#dddddd";
316 $GLOBALS['style']['BOTTOM_BG_LINE'] = $bottom_bg_line;
317 // The height in pixels of the Logo bar at the top of the login page:
318 $GLOBALS['logoBarHeight'] = 110;
319 // The height in pixels of the Navigation bar:
320 $GLOBALS['navBarHeight'] = 22;
321 // The height in pixels of the Title bar:
322 $GLOBALS['titleBarHeight'] = 40;
324 // The assistant word, MORE printed next to titles that can be clicked:
325 // Note this label gets translated here via the xl function
326 // -if you don't want it translated, then strip the xl function away
327 $tmore = xl('(More)');
328 // The assistant word, BACK printed next to titles that return to previous screens:
329 // Note this label gets translated here via the xl function
330 // -if you don't want it translated, then strip the xl function away
331 $tback = xl('(Back)');
333 // This is the idle logout function:
334 // if a page has not been refreshed within this many seconds, the interface
335 // will return to the login page
336 if (!empty($special_timeout)) {
337 $timeout = intval($special_timeout);
340 //Version tag
341 require_once(dirname(__FILE__) . "/../version.php");
342 $patch_appending = "";
343 if ( ($v_realpatch != '0') && (!(empty($v_realpatch))) ) {
344 $patch_appending = " (".$v_realpatch.")";
346 $openemr_version = "$v_major.$v_minor.$v_patch".$v_tag.$patch_appending;
348 $srcdir = $GLOBALS['srcdir'];
349 $login_screen = $GLOBALS['login_screen'];
350 $GLOBALS['css_header'] = $css_header;
351 $GLOBALS['backpic'] = $backpic;
353 // 1 = send email message to given id for Emergency Login user activation,
354 // else 0.
355 $GLOBALS['Emergency_Login_email'] = $GLOBALS['Emergency_Login_email_id'] ? 1 : 0;
357 //set include_de_identification to enable De-identification (currently de-identification works fine only with linux machines)
358 //Run de_identification_upgrade.php script to upgrade OpenEMR database to include procedures,
359 //functions, tables for de-identification(Mysql root user and password is required for successful
360 //execution of the de-identification upgrade script)
361 $GLOBALS['include_de_identification']=0;
362 // Include the authentication module code here, but the rule is
363 // if the file has the word "login" in the source code file name,
364 // don't include the authentication module - we do this to avoid
365 // include loops.
367 if (!isset($ignoreAuth) || !$ignoreAuth) {
368 include_once("$srcdir/auth.inc");
371 // If you do not want your accounting system to have a customer added to it
372 // for each insurance company, then set this to true. SQL-Ledger currently
373 // (2005-03-21) does nothing useful with insurance companies as customers.
374 $GLOBALS['insurance_companies_are_not_customers'] = true;
376 // This is the background color to apply to form fields that are searchable.
377 // Currently it is applicable only to the "Search or Add Patient" form.
378 $GLOBALS['layout_search_color'] = '#ffff55';
380 //EMAIL SETTINGS
381 $SMTP_Auth = !empty($GLOBALS['SMTP_USER']);
383 // Customize these if you are using SQL-Ledger with OpenEMR, or if you are
384 // going to run sl_convert.php to convert from SQL-Ledger.
386 $sl_cash_acc = '1060'; // sql-ledger account number for checking account
387 $sl_ar_acc = '1200'; // sql-ledger account number for accounts receivable
388 $sl_income_acc = '4320'; // sql-ledger account number for medical services income
389 $sl_services_id = 'MS'; // sql-ledger parts table id for medical services
390 $sl_dbname = 'sql-ledger'; // sql-ledger database name
391 $sl_dbuser = 'sql-ledger'; // sql-ledger database login name
392 $sl_dbpass = 'secret'; // sql-ledger database login password
393 //////////////////////////////////////////////////////////////////
395 //module configurations
396 $GLOBALS['baseModDir'] = "interface/modules/"; //default path of modules
397 $GLOBALS['customModDir']= "custom_modules"; //non zend modules
398 $GLOBALS['zendModDir'] = "zend_modules"; //zend modules
400 // Don't change anything below this line. ////////////////////////////
402 $encounter = empty($_SESSION['encounter']) ? 0 : $_SESSION['encounter'];
404 if (!empty($_GET['pid']) && empty($_SESSION['pid'])) {
405 $_SESSION['pid'] = $_GET['pid'];
407 elseif (!empty($_POST['pid']) && empty($_SESSION['pid'])) {
408 $_SESSION['pid'] = $_POST['pid'];
410 $pid = empty($_SESSION['pid']) ? 0 : $_SESSION['pid'];
411 $userauthorized = empty($_SESSION['userauthorized']) ? 0 : $_SESSION['userauthorized'];
412 $groupname = empty($_SESSION['authProvider']) ? 0 : $_SESSION['authProvider'];
414 // global interface function to format text length using ellipses
415 function strterm($string,$length) {
416 if (strlen($string) >= ($length-3)) {
417 return substr($string,0,$length-3) . "...";
418 } else {
419 return $string;
423 // Override temporary_files_dir if PHP >= 5.2.1.
424 if (version_compare(phpversion(), "5.2.1", ">=")) {
425 $GLOBALS['temporary_files_dir'] = rtrim(sys_get_temp_dir(),'/');
428 // turn off PHP compatibility warnings
429 ini_set("session.bug_compat_warn","off");
431 //////////////////////////////////////////////////////////////////