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