Added email address
[openemr.git] / interface / globals.php
blob026bcf5e68ed934b1cdbf62c86a51117630bc4f6
1 <?php
2 /* $Id$ */
3 // ------------------------------------------------------------------------ //
4 // OpenEMR Electronic Medical Records System //
5 // Copyright (c) 2005-2010 oemr.org //
6 // <http://www.oemr.org/> //
7 // ------------------------------------------------------------------------ //
8 // This program is free software; you can redistribute it and/or modify //
9 // it under the terms of the GNU General Public License as published by //
10 // the Free Software Foundation; either version 2 of the License, or //
11 // (at your option) any later version. //
12 // //
13 // You may not change or alter any portion of this comment or credits //
14 // of supporting developers from this source code or any supporting //
15 // source code which is considered copyrighted (c) material of the //
16 // original comment or credit authors. //
17 // //
18 // This program is distributed in the hope that it will be useful, //
19 // but WITHOUT ANY WARRANTY; without even the implied warranty of //
20 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
21 // GNU General Public License for more details. //
22 // //
23 // You should have received a copy of the GNU General Public License //
24 // along with this program; if not, write to the Free Software //
25 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA //
26 // ------------------------------------------------------------------------ //
28 // Is this windows or non-windows? Create a boolean definition.
29 if (!defined('IS_WINDOWS'))
30 define('IS_WINDOWS', (stripos(PHP_OS,'WIN') === 0));
32 // Some important php.ini overrides. Defaults for these values are often
33 // too small. You might choose to adjust them further.
35 ini_set('memory_limit', '64M');
36 ini_set('session.gc_maxlifetime', '14400');
38 /* If the includer didn't specify, assume they want us to "fake" register_globals. */
39 if (!isset($fake_register_globals)) {
40 $fake_register_globals = TRUE;
43 /* Pages with "myadmin" in the URL don't need register_globals. */
44 $fake_register_globals =
45 $fake_register_globals && (strpos($_SERVER['REQUEST_URI'],"myadmin") === FALSE);
47 // Emulates register_globals = On. Moved to here from the bottom of this file
48 // to address security issues. Need to change everything requiring this!
49 if ($fake_register_globals) {
50 extract($_GET);
51 extract($_POST);
54 // This is for sanitization of all escapes.
55 // (ie. reversing magic quotes if it's set)
56 if ($sanitize_all_escapes) {
57 if (get_magic_quotes_gpc()) {
58 function undoMagicQuotes($array, $topLevel=true) {
59 $newArray = array();
60 foreach($array as $key => $value) {
61 if (!$topLevel) {
62 $key = stripslashes($key);
64 if (is_array($value)) {
65 $newArray[$key] = undoMagicQuotes($value, false);
67 else {
68 $newArray[$key] = stripslashes($value);
71 return $newArray;
73 $_GET = undoMagicQuotes($_GET);
74 $_POST = undoMagicQuotes($_POST);
75 $_COOKIE = undoMagicQuotes($_COOKIE);
76 $_REQUEST = undoMagicQuotes($_REQUEST);
81 // The webserver_root and web_root are now automatically collected.
82 // If not working, can set manually below.
83 // Auto collect the full absolute directory path for openemr.
84 $webserver_root = dirname(dirname(__FILE__));
85 if (IS_WINDOWS) {
86 //convert windows path separators
87 $webserver_root = str_replace("\\","/",$webserver_root);
90 // Auto collect the relative html path, i.e. what you would type into the web
91 // browser after the server address to get to OpenEMR.
93 // wh25aug11 - adapted from http://stackoverflow.com/questions/176712/how-can-i-find-an-applications-base-url
94 // works better than trimming if there's a symlink or a ~user directory involved
95 $tempPath1 = explode('/', str_replace('\\', '/', dirname(dirname($_SERVER['SCRIPT_FILENAME']))));
96 $tempPath2 = explode('/', substr($webserver_root, 0, -1));
97 $tempPath3 = explode('/', str_replace('\\', '/', dirname(dirname($_SERVER['PHP_SELF']))));
99 for ($i = count($tempPath2); $i < count($tempPath1); $i++)
100 array_pop ($tempPath3);
102 $web_root = implode('/', $tempPath3);
103 // Ensure web_root starts with a path separator
104 if (preg_match("/^[^\/]/",$web_root)) {
105 $web_root = "/".$web_root;
107 unset($tempPath1, $tempPath2, $tempPath3);
108 // wh25aug11 / end
110 // The webserver_root and web_root are now automatically collected in
111 // real time per above code. If above is not working, can uncomment and
112 // set manually here:
113 // $webserver_root = "/var/www/openemr";
114 // $web_root = "/openemr";
117 // This is the directory that contains site-specific data. Change this
118 // only if you have some reason to.
119 $GLOBALS['OE_SITES_BASE'] = "$webserver_root/sites";
121 // The session name names a cookie stored in the browser.
122 // If you modify session_name, then need to place the identical name in
123 // the phpmyadmin file here: openemr/phpmyadmin/libraries/session.inc.php
124 // at line 71. This was required after embedded new phpmyadmin version on
125 // 05-12-2009 by Brady. Hopefully will figure out a more appropriate fix.
126 // Now that restore_session() is implemented in javaScript, session IDs are
127 // effectively saved in the top level browser window and there is no longer
128 // any need to change the session name for different OpenEMR instances.
129 session_name("OpenEMR");
131 session_start();
133 // Set the site ID if required. This must be done before any database
134 // access is attempted.
135 if (empty($_SESSION['site_id']) || !empty($_GET['site'])) {
136 if (!empty($_GET['site'])) {
137 $tmp = $_GET['site'];
139 else {
140 if (!$ignoreAuth) die("Site ID is missing from session data!");
141 $tmp = $_SERVER['HTTP_HOST'];
142 if (!is_dir($GLOBALS['OE_SITES_BASE'] . "/$tmp")) $tmp = "default";
144 if (empty($tmp) || preg_match('/[^A-Za-z0-9\\-.]/', $tmp))
145 die("Site ID '$tmp' contains invalid characters.");
146 if (!isset($_SESSION['site_id']) || $_SESSION['site_id'] != $tmp) {
147 $_SESSION['site_id'] = $tmp;
148 error_log("Session site ID has been set to '$tmp'"); // debugging
152 // Set the site-specific directory path.
153 $GLOBALS['OE_SITE_DIR'] = $GLOBALS['OE_SITES_BASE'] . "/" . $_SESSION['site_id'];
155 require_once($GLOBALS['OE_SITE_DIR'] . "/config.php");
157 // Collecting the utf8 disable flag from the sqlconf.php file in order
158 // to set the correct html encoding. utf8 vs iso-8859-1. If flag is set
159 // then set to iso-8859-1.
160 require_once(dirname(__FILE__) . "/../library/sqlconf.php");
161 if (!$disable_utf8_flag) {
162 ini_set('default_charset', 'utf-8');
163 $HTML_CHARSET = "UTF-8";
165 else {
166 ini_set('default_charset', 'iso-8859-1');
167 $HTML_CHARSET = "ISO-8859-1";
170 // Root directory, relative to the webserver root:
171 $GLOBALS['rootdir'] = "$web_root/interface";
172 $rootdir = $GLOBALS['rootdir'];
173 // Absolute path to the source code include and headers file directory (Full path):
174 $GLOBALS['srcdir'] = "$webserver_root/library";
175 // Absolute path to the location of documentroot directory for use with include statements:
176 $GLOBALS['fileroot'] = "$webserver_root";
177 // Absolute path to the location of interface directory for use with include statements:
178 $include_root = "$webserver_root/interface";
179 // Absolute path to the location of documentroot directory for use with include statements:
180 $GLOBALS['webroot'] = $web_root;
182 $GLOBALS['template_dir'] = $GLOBALS['fileroot'] . "/templates/";
183 $GLOBALS['incdir'] = $include_root;
184 // Location of the login screen file
185 $GLOBALS['login_screen'] = $GLOBALS['rootdir'] . "/login_screen.php";
187 // Variable set for Eligibility Verification [EDI-271] path
188 $GLOBALS['edi_271_file_path'] = $GLOBALS['OE_SITE_DIR'] . "/edi/";
190 // Include the translation engine. This will also call sql.inc to
191 // open the openemr mysql connection.
192 include_once (dirname(__FILE__) . "/../library/translation.inc.php");
194 // Include convenience functions with shorter names than "htmlspecialchars"
195 include_once (dirname(__FILE__) . "/../library/htmlspecialchars.inc.php");
197 // Includes functions for date internationalization
198 include_once (dirname(__FILE__) . "/../library/date_functions.php");
200 // Defaults for specific applications.
201 $GLOBALS['athletic_team'] = false;
202 $GLOBALS['weight_loss_clinic'] = false;
203 $GLOBALS['ippf_specific'] = false;
204 $GLOBALS['cene_specific'] = false;
206 // Defaults for drugs and products.
207 $GLOBALS['inhouse_pharmacy'] = false;
208 $GLOBALS['sell_non_drug_products'] = 0;
210 $glrow = sqlQuery("SHOW TABLES LIKE 'globals'");
211 if (!empty($glrow)) {
212 // Collect user specific settings from user_settings table.
214 $gl_user = array();
215 if (!empty($_SESSION['authUserID'])) {
216 $glres_user = sqlStatement("SELECT `setting_label`, `setting_value` " .
217 "FROM `user_settings` " .
218 "WHERE `setting_user` = ? " .
219 "AND `setting_label` LIKE 'global:%'", array($_SESSION['authUserID']) );
220 for($iter=0; $row=sqlFetchArray($glres_user); $iter++) {
221 //remove global_ prefix from label
222 $row['setting_label'] = substr($row['setting_label'],7);
223 $gl_user[$iter]=$row;
226 // Set global parameters from the database globals table.
227 // Some parameters require custom handling.
229 $GLOBALS['language_menu_show'] = array();
230 $glres = sqlStatement("SELECT gl_name, gl_index, gl_value FROM globals " .
231 "ORDER BY gl_name, gl_index");
232 while ($glrow = sqlFetchArray($glres)) {
233 $gl_name = $glrow['gl_name'];
234 $gl_value = $glrow['gl_value'];
235 // Adjust for user specific settings
236 if (!empty($gl_user)) {
237 foreach ($gl_user as $setting) {
238 if ($gl_name == $setting['setting_label']) {
239 $gl_value = $setting['setting_value'];
243 if ($gl_name == 'language_menu_other') {
244 $GLOBALS['language_menu_show'][] = $gl_value;
246 else if ($gl_name == 'css_header') {
247 $GLOBALS[$gl_name] = "$rootdir/themes/" . $gl_value;
249 else if ($gl_name == 'specific_application') {
250 if ($gl_value == '1') $GLOBALS['athletic_team'] = true;
251 else if ($gl_value == '2') $GLOBALS['ippf_specific'] = true;
252 else if ($gl_value == '3') $GLOBALS['weight_loss_clinic'] = true;
254 else if ($gl_name == 'inhouse_pharmacy') {
255 if ($gl_value) $GLOBALS['inhouse_pharmacy'] = true;
256 if ($gl_value == '2') $GLOBALS['sell_non_drug_products'] = 1;
257 else if ($gl_value == '3') $GLOBALS['sell_non_drug_products'] = 2;
259 else {
260 $GLOBALS[$gl_name] = $gl_value;
263 // Language cleanup stuff.
264 $GLOBALS['language_menu_login'] = false;
265 if ((count($GLOBALS['language_menu_show']) >= 1) || $GLOBALS['language_menu_showall']) {
266 $GLOBALS['language_menu_login'] = true;
269 // End of globals table processing.
271 else {
272 // Temporary stuff to handle the case where the globals table does not
273 // exist yet. This will happen in sql_upgrade.php on upgrading to the
274 // first release containing this table.
275 $GLOBALS['language_menu_login'] = true;
276 $GLOBALS['language_menu_showall'] = true;
277 $GLOBALS['language_menu_show'] = array('English (Standard)','Swedish');
278 $GLOBALS['language_default'] = "English (Standard)";
279 $GLOBALS['translate_layout'] = true;
280 $GLOBALS['translate_lists'] = true;
281 $GLOBALS['translate_gacl_groups'] = true;
282 $GLOBALS['translate_form_titles'] = true;
283 $GLOBALS['translate_document_categories'] = true;
284 $GLOBALS['translate_appt_categories'] = true;
285 $GLOBALS['concurrent_layout'] = 2;
286 $timeout = 7200;
287 $openemr_name = 'OpenEMR';
288 $css_header = "$rootdir/themes/style_default.css";
289 $GLOBALS['css_header'] = $css_header;
290 $GLOBALS['schedule_start'] = 8;
291 $GLOBALS['schedule_end'] = 17;
292 $GLOBALS['calendar_interval'] = 15;
293 $GLOBALS['phone_country_code'] = '1';
294 $GLOBALS['disable_non_default_groups'] = true;
295 $GLOBALS['ippf_specific'] = false;
298 // If >0 this will enforce a separate PHP session for each top-level
299 // browser window. You must log in separately for each. This is not
300 // thoroughly tested yet and some browsers might have trouble with it,
301 // so make it 0 if you must. Alternatively, you can set it to 2 to be
302 // notified when the session ID changes.
303 $GLOBALS['restore_sessions'] = 1; // 0=no, 1=yes, 2=yes+debug
305 // Theme definition. All this stuff should be moved to CSS.
307 if ($GLOBALS['concurrent_layout']) {
308 $top_bg_line = ' bgcolor="#dddddd" ';
309 $GLOBALS['style']['BGCOLOR2'] = "#dddddd";
310 $bottom_bg_line = $top_bg_line;
311 $title_bg_line = ' bgcolor="#bbbbbb" ';
312 $nav_bg_line = ' bgcolor="#94d6e7" ';
313 } else {
314 $top_bg_line = ' bgcolor="#94d6e7" ';
315 $GLOBALS['style']['BGCOLOR2'] = "#94d6e7";
316 $bottom_bg_line = ' background="'.$rootdir.'/pic/aquabg.gif" ';
317 $title_bg_line = ' bgcolor="#aaffff" ';
318 $nav_bg_line = ' bgcolor="#94d6e7" ';
320 $login_filler_line = ' bgcolor="#f7f0d5" ';
321 $login_body_line = ' background="'.$rootdir.'/pic/aquabg.gif" ';
322 $logocode = "<img src='$web_root/sites/" . $_SESSION['site_id'] . "/images/login_logo.gif'>";
323 $linepic = "$rootdir/pic/repeat_vline9.gif";
324 $table_bg = ' bgcolor="#cccccc" ';
325 $GLOBALS['style']['BGCOLOR1'] = "#cccccc";
326 $GLOBALS['style']['TEXTCOLOR11'] = "#222222";
327 $GLOBALS['style']['HIGHLIGHTCOLOR'] = "#dddddd";
328 $GLOBALS['style']['BOTTOM_BG_LINE'] = $bottom_bg_line;
329 // The height in pixels of the Logo bar at the top of the login page:
330 $GLOBALS['logoBarHeight'] = 110;
331 // The height in pixels of the Navigation bar:
332 $GLOBALS['navBarHeight'] = 22;
333 // The height in pixels of the Title bar:
334 $GLOBALS['titleBarHeight'] = 40;
336 // The assistant word, MORE printed next to titles that can be clicked:
337 // Note this label gets translated here via the xl function
338 // -if you don't want it translated, then strip the xl function away
339 $tmore = xl('(More)');
340 // The assistant word, BACK printed next to titles that return to previous screens:
341 // Note this label gets translated here via the xl function
342 // -if you don't want it translated, then strip the xl function away
343 $tback = xl('(Back)');
345 // This is the idle logout function:
346 // if a page has not been refreshed within this many seconds, the interface
347 // will return to the login page
348 if (!empty($special_timeout)) {
349 $timeout = intval($special_timeout);
352 //Version tags
353 require_once(dirname(__FILE__) . "/../version.php");
354 $openemr_version = "$v_major.$v_minor.$v_patch".$v_tag; // Version tag used by program
356 $srcdir = $GLOBALS['srcdir'];
357 $login_screen = $GLOBALS['login_screen'];
358 $GLOBALS['css_header'] = $css_header;
359 $GLOBALS['backpic'] = $backpic;
361 // 1 = send email message to given id for Emergency Login user activation,
362 // else 0.
363 $GLOBALS['Emergency_Login_email'] = $GLOBALS['Emergency_Login_email_id'] ? 1 : 0;
365 //set include_de_identification to enable De-identification (currently de-identification works fine only with linux machines)
366 //Run de_identification_upgrade.php script to upgrade OpenEMR database to include procedures,
367 //functions, tables for de-identification(Mysql root user and password is required for successful
368 //execution of the de-identification upgrade script)
369 $GLOBALS['include_de_identification']=0;
370 // Include the authentication module code here, but the rule is
371 // if the file has the word "login" in the source code file name,
372 // don't include the authentication module - we do this to avoid
373 // include loops.
375 if (!$ignoreAuth) {
376 include_once("$srcdir/auth.inc");
379 // If you do not want your accounting system to have a customer added to it
380 // for each insurance company, then set this to true. SQL-Ledger currently
381 // (2005-03-21) does nothing useful with insurance companies as customers.
382 $GLOBALS['insurance_companies_are_not_customers'] = true;
384 // This is the background color to apply to form fields that are searchable.
385 // Currently it is applicable only to the "Search or Add Patient" form.
386 $GLOBALS['layout_search_color'] = '#ffff55';
388 //EMAIL SETTINGS
389 $SMTP_Auth = !empty($GLOBALS['SMTP_USER']);
391 // Customize these if you are using SQL-Ledger with OpenEMR, or if you are
392 // going to run sl_convert.php to convert from SQL-Ledger.
394 $sl_cash_acc = '1060'; // sql-ledger account number for checking account
395 $sl_ar_acc = '1200'; // sql-ledger account number for accounts receivable
396 $sl_income_acc = '4320'; // sql-ledger account number for medical services income
397 $sl_services_id = 'MS'; // sql-ledger parts table id for medical services
398 $sl_dbname = 'sql-ledger'; // sql-ledger database name
399 $sl_dbuser = 'sql-ledger'; // sql-ledger database login name
400 $sl_dbpass = 'secret'; // sql-ledger database login password
401 //////////////////////////////////////////////////////////////////
403 // Don't change anything below this line. ////////////////////////////
405 $encounter = empty($_SESSION['encounter']) ? 0 : $_SESSION['encounter'];
407 if (!empty($_GET['pid']) && empty($_SESSION['pid'])) {
408 $_SESSION['pid'] = $_GET['pid'];
410 elseif (!empty($_POST['pid']) && empty($_SESSION['pid'])) {
411 $_SESSION['pid'] = $_POST['pid'];
413 $pid = empty($_SESSION['pid']) ? 0 : $_SESSION['pid'];
414 $userauthorized = empty($_SESSION['userauthorized']) ? 0 : $_SESSION['userauthorized'];
415 $groupname = empty($_SESSION['authProvider']) ? 0 : $_SESSION['authProvider'];
417 // global interface function to format text length using ellipses
418 function strterm($string,$length) {
419 if (strlen($string) >= ($length-3)) {
420 return substr($string,0,$length-3) . "...";
421 } else {
422 return $string;
426 // Override temporary_files_dir if PHP >= 5.2.1.
427 if (version_compare(phpversion(), "5.2.1", ">=")) {
428 $GLOBALS['temporary_files_dir'] = rtrim(sys_get_temp_dir(),'/');
431 // turn off PHP compatibility warnings
432 ini_set("session.bug_compat_warn","off");
434 //////////////////////////////////////////////////////////////////