fix for pharmacy dispensory to work with correct Pharmacy Dispensary aco
[openemr.git] / interface / globals.php
blobdc8182b4dd565798c2c9c32a1b9c4e14760098ae
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 // Auto collect the relative html path, i.e. what you would type into the web
64 // browser after the server address to get to OpenEMR.
65 $web_root = substr($webserver_root, strlen($_SERVER['DOCUMENT_ROOT']));
66 // Ensure web_root starts with a path separator
67 if (preg_match("/^[^\/]/",$web_root)) {
68 $web_root = "/".$web_root;
70 // The webserver_root and web_root are now automatically collected in
71 // real time per above code. If above is not working, can uncomment and
72 // set manually here:
73 // $webserver_root = "/var/www/openemr";
74 // $web_root = "/openemr";
77 // This is the directory that contains site-specific data. Change this
78 // only if you have some reason to.
79 $GLOBALS['OE_SITES_BASE'] = "$webserver_root/sites";
81 // The session name names a cookie stored in the browser.
82 // If you modify session_name, then need to place the identical name in
83 // the phpmyadmin file here: openemr/phpmyadmin/libraries/session.inc.php
84 // at line 71. This was required after embedded new phpmyadmin version on
85 // 05-12-2009 by Brady. Hopefully will figure out a more appropriate fix.
86 // Now that restore_session() is implemented in javaScript, session IDs are
87 // effectively saved in the top level browser window and there is no longer
88 // any need to change the session name for different OpenEMR instances.
89 session_name("OpenEMR");
91 session_start();
93 // Set the site ID if required. This must be done before any database
94 // access is attempted.
95 if (empty($_SESSION['site_id']) || !empty($_GET['site'])) {
96 if (!empty($_GET['site'])) {
97 $tmp = $_GET['site'];
99 else {
100 if (!$ignoreAuth) die("Site ID is missing from session data!");
101 $tmp = $_SERVER['HTTP_HOST'];
102 if (!is_dir($GLOBALS['OE_SITES_BASE'] . "/$tmp")) $tmp = "default";
104 if (empty($tmp) || preg_match('/[^A-Za-z0-9\\-.]/', $tmp))
105 die("Site ID '". htmlspecialchars($tmp,ENT_NOQUOTES) . "' contains invalid characters.");
106 if (isset($_SESSION['site_id']) && ($_SESSION['site_id'] != $tmp)) {
107 // This is to prevent using session to penetrate other OpenEMR instances within same multisite module
108 session_unset(); // clear session, clean logout
109 if (isset($landingpage) && !empty($landingpage)) {
110 // OpenEMR Patient Portal use
111 header('Location: index.php?site='.$tmp);
113 else {
114 // Main OpenEMR use
115 header('Location: ../login/login_frame.php?site='.$tmp); // Assuming in the interface/main directory
117 exit;
119 if (!isset($_SESSION['site_id']) || $_SESSION['site_id'] != $tmp) {
120 $_SESSION['site_id'] = $tmp;
121 //error_log("Session site ID has been set to '$tmp'"); // debugging
125 // Set the site-specific directory path.
126 $GLOBALS['OE_SITE_DIR'] = $GLOBALS['OE_SITES_BASE'] . "/" . $_SESSION['site_id'];
128 require_once($GLOBALS['OE_SITE_DIR'] . "/config.php");
130 // Collecting the utf8 disable flag from the sqlconf.php file in order
131 // to set the correct html encoding. utf8 vs iso-8859-1. If flag is set
132 // then set to iso-8859-1.
133 require_once(dirname(__FILE__) . "/../library/sqlconf.php");
134 if (!$disable_utf8_flag) {
135 ini_set('default_charset', 'utf-8');
136 $HTML_CHARSET = "UTF-8";
138 else {
139 ini_set('default_charset', 'iso-8859-1');
140 $HTML_CHARSET = "ISO-8859-1";
143 // Root directory, relative to the webserver root:
144 $GLOBALS['rootdir'] = "$web_root/interface";
145 $rootdir = $GLOBALS['rootdir'];
146 // Absolute path to the source code include and headers file directory (Full path):
147 $GLOBALS['srcdir'] = "$webserver_root/library";
148 // Absolute path to the location of documentroot directory for use with include statements:
149 $GLOBALS['fileroot'] = "$webserver_root";
150 // Absolute path to the location of interface directory for use with include statements:
151 $include_root = "$webserver_root/interface";
152 // Absolute path to the location of documentroot directory for use with include statements:
153 $GLOBALS['webroot'] = $web_root;
155 $GLOBALS['template_dir'] = $GLOBALS['fileroot'] . "/templates/";
156 $GLOBALS['incdir'] = $include_root;
157 // Location of the login screen file
158 $GLOBALS['login_screen'] = $GLOBALS['rootdir'] . "/login_screen.php";
160 // Variable set for Eligibility Verification [EDI-271] path
161 $GLOBALS['edi_271_file_path'] = $GLOBALS['OE_SITE_DIR'] . "/edi/";
163 // Include the translation engine. This will also call sql.inc to
164 // open the openemr mysql connection.
165 include_once (dirname(__FILE__) . "/../library/translation.inc.php");
167 // Include convenience functions with shorter names than "htmlspecialchars" (for security)
168 require_once (dirname(__FILE__) . "/../library/htmlspecialchars.inc.php");
170 // Include sanitization/checking functions (for security)
171 require_once (dirname(__FILE__) . "/../library/formdata.inc.php");
173 // Include sanitization/checking function (for security)
174 require_once (dirname(__FILE__) . "/../library/sanitize.inc.php");
176 // Includes functions for date internationalization
177 include_once (dirname(__FILE__) . "/../library/date_functions.php");
179 // Defaults for specific applications.
180 $GLOBALS['athletic_team'] = false;
181 $GLOBALS['weight_loss_clinic'] = false;
182 $GLOBALS['ippf_specific'] = false;
183 $GLOBALS['cene_specific'] = false;
185 // Defaults for drugs and products.
186 $GLOBALS['inhouse_pharmacy'] = false;
187 $GLOBALS['sell_non_drug_products'] = 0;
189 $glrow = sqlQuery("SHOW TABLES LIKE 'globals'");
190 if (!empty($glrow)) {
191 // Collect user specific settings from user_settings table.
193 $gl_user = array();
194 if (!empty($_SESSION['authUserID'])) {
195 $glres_user = sqlStatement("SELECT `setting_label`, `setting_value` " .
196 "FROM `user_settings` " .
197 "WHERE `setting_user` = ? " .
198 "AND `setting_label` LIKE 'global:%'", array($_SESSION['authUserID']) );
199 for($iter=0; $row=sqlFetchArray($glres_user); $iter++) {
200 //remove global_ prefix from label
201 $row['setting_label'] = substr($row['setting_label'],7);
202 $gl_user[$iter]=$row;
205 // Set global parameters from the database globals table.
206 // Some parameters require custom handling.
208 $GLOBALS['language_menu_show'] = array();
209 $glres = sqlStatement("SELECT gl_name, gl_index, gl_value FROM globals " .
210 "ORDER BY gl_name, gl_index");
211 while ($glrow = sqlFetchArray($glres)) {
212 $gl_name = $glrow['gl_name'];
213 $gl_value = $glrow['gl_value'];
214 // Adjust for user specific settings
215 if (!empty($gl_user)) {
216 foreach ($gl_user as $setting) {
217 if ($gl_name == $setting['setting_label']) {
218 $gl_value = $setting['setting_value'];
222 if ($gl_name == 'language_menu_other') {
223 $GLOBALS['language_menu_show'][] = $gl_value;
225 else if ($gl_name == 'css_header') {
226 $GLOBALS[$gl_name] = "$rootdir/themes/" . $gl_value;
228 else if ($gl_name == 'specific_application') {
229 if ($gl_value == '1') $GLOBALS['athletic_team'] = true;
230 else if ($gl_value == '2') $GLOBALS['ippf_specific'] = true;
231 else if ($gl_value == '3') $GLOBALS['weight_loss_clinic'] = true;
233 else if ($gl_name == 'inhouse_pharmacy') {
234 if ($gl_value) $GLOBALS['inhouse_pharmacy'] = true;
235 if ($gl_value == '2') $GLOBALS['sell_non_drug_products'] = 1;
236 else if ($gl_value == '3') $GLOBALS['sell_non_drug_products'] = 2;
238 else {
239 $GLOBALS[$gl_name] = $gl_value;
242 // Language cleanup stuff.
243 $GLOBALS['language_menu_login'] = false;
244 if ((count($GLOBALS['language_menu_show']) >= 1) || $GLOBALS['language_menu_showall']) {
245 $GLOBALS['language_menu_login'] = true;
248 // End of globals table processing.
250 else {
251 // Temporary stuff to handle the case where the globals table does not
252 // exist yet. This will happen in sql_upgrade.php on upgrading to the
253 // first release containing this table.
254 $GLOBALS['language_menu_login'] = true;
255 $GLOBALS['language_menu_showall'] = true;
256 $GLOBALS['language_menu_show'] = array('English (Standard)','Swedish');
257 $GLOBALS['language_default'] = "English (Standard)";
258 $GLOBALS['translate_layout'] = true;
259 $GLOBALS['translate_lists'] = true;
260 $GLOBALS['translate_gacl_groups'] = true;
261 $GLOBALS['translate_form_titles'] = true;
262 $GLOBALS['translate_document_categories'] = true;
263 $GLOBALS['translate_appt_categories'] = true;
264 $GLOBALS['concurrent_layout'] = 2;
265 $timeout = 7200;
266 $openemr_name = 'OpenEMR';
267 $css_header = "$rootdir/themes/style_default.css";
268 $GLOBALS['css_header'] = $css_header;
269 $GLOBALS['schedule_start'] = 8;
270 $GLOBALS['schedule_end'] = 17;
271 $GLOBALS['calendar_interval'] = 15;
272 $GLOBALS['phone_country_code'] = '1';
273 $GLOBALS['disable_non_default_groups'] = true;
274 $GLOBALS['ippf_specific'] = false;
277 // If >0 this will enforce a separate PHP session for each top-level
278 // browser window. You must log in separately for each. This is not
279 // thoroughly tested yet and some browsers might have trouble with it,
280 // so make it 0 if you must. Alternatively, you can set it to 2 to be
281 // notified when the session ID changes.
282 $GLOBALS['restore_sessions'] = 1; // 0=no, 1=yes, 2=yes+debug
284 // Theme definition. All this stuff should be moved to CSS.
286 if ($GLOBALS['concurrent_layout']) {
287 $top_bg_line = ' bgcolor="#dddddd" ';
288 $GLOBALS['style']['BGCOLOR2'] = "#dddddd";
289 $bottom_bg_line = $top_bg_line;
290 $title_bg_line = ' bgcolor="#bbbbbb" ';
291 $nav_bg_line = ' bgcolor="#94d6e7" ';
292 } else {
293 $top_bg_line = ' bgcolor="#94d6e7" ';
294 $GLOBALS['style']['BGCOLOR2'] = "#94d6e7";
295 $bottom_bg_line = ' background="'.$rootdir.'/pic/aquabg.gif" ';
296 $title_bg_line = ' bgcolor="#aaffff" ';
297 $nav_bg_line = ' bgcolor="#94d6e7" ';
299 $login_filler_line = ' bgcolor="#f7f0d5" ';
300 $logocode = "<img src='$web_root/sites/" . $_SESSION['site_id'] . "/images/login_logo.gif'>";
301 $linepic = "$rootdir/pic/repeat_vline9.gif";
302 $table_bg = ' bgcolor="#cccccc" ';
303 $GLOBALS['style']['BGCOLOR1'] = "#cccccc";
304 $GLOBALS['style']['TEXTCOLOR11'] = "#222222";
305 $GLOBALS['style']['HIGHLIGHTCOLOR'] = "#dddddd";
306 $GLOBALS['style']['BOTTOM_BG_LINE'] = $bottom_bg_line;
307 // The height in pixels of the Logo bar at the top of the login page:
308 $GLOBALS['logoBarHeight'] = 110;
309 // The height in pixels of the Navigation bar:
310 $GLOBALS['navBarHeight'] = 22;
311 // The height in pixels of the Title bar:
312 $GLOBALS['titleBarHeight'] = 40;
314 // The assistant word, MORE printed next to titles that can be clicked:
315 // Note this label gets translated here via the xl function
316 // -if you don't want it translated, then strip the xl function away
317 $tmore = xl('(More)');
318 // The assistant word, BACK printed next to titles that return to previous screens:
319 // Note this label gets translated here via the xl function
320 // -if you don't want it translated, then strip the xl function away
321 $tback = xl('(Back)');
323 // This is the idle logout function:
324 // if a page has not been refreshed within this many seconds, the interface
325 // will return to the login page
326 if (!empty($special_timeout)) {
327 $timeout = intval($special_timeout);
330 //Version tag
331 require_once(dirname(__FILE__) . "/../version.php");
332 $patch_appending = "";
333 if ( ($v_realpatch != '0') && (!(empty($v_realpatch))) ) {
334 $patch_appending = " (".$v_realpatch.")";
336 $openemr_version = "$v_major.$v_minor.$v_patch".$v_tag.$patch_appending;
338 $srcdir = $GLOBALS['srcdir'];
339 $login_screen = $GLOBALS['login_screen'];
340 $GLOBALS['css_header'] = $css_header;
341 $GLOBALS['backpic'] = $backpic;
343 // 1 = send email message to given id for Emergency Login user activation,
344 // else 0.
345 $GLOBALS['Emergency_Login_email'] = $GLOBALS['Emergency_Login_email_id'] ? 1 : 0;
347 //set include_de_identification to enable De-identification (currently de-identification works fine only with linux machines)
348 //Run de_identification_upgrade.php script to upgrade OpenEMR database to include procedures,
349 //functions, tables for de-identification(Mysql root user and password is required for successful
350 //execution of the de-identification upgrade script)
351 $GLOBALS['include_de_identification']=0;
352 // Include the authentication module code here, but the rule is
353 // if the file has the word "login" in the source code file name,
354 // don't include the authentication module - we do this to avoid
355 // include loops.
357 if (!isset($ignoreAuth) || !$ignoreAuth) {
358 include_once("$srcdir/auth.inc");
361 // If you do not want your accounting system to have a customer added to it
362 // for each insurance company, then set this to true. SQL-Ledger currently
363 // (2005-03-21) does nothing useful with insurance companies as customers.
364 $GLOBALS['insurance_companies_are_not_customers'] = true;
366 // This is the background color to apply to form fields that are searchable.
367 // Currently it is applicable only to the "Search or Add Patient" form.
368 $GLOBALS['layout_search_color'] = '#ffff55';
370 //EMAIL SETTINGS
371 $SMTP_Auth = !empty($GLOBALS['SMTP_USER']);
373 // Customize these if you are using SQL-Ledger with OpenEMR, or if you are
374 // going to run sl_convert.php to convert from SQL-Ledger.
376 $sl_cash_acc = '1060'; // sql-ledger account number for checking account
377 $sl_ar_acc = '1200'; // sql-ledger account number for accounts receivable
378 $sl_income_acc = '4320'; // sql-ledger account number for medical services income
379 $sl_services_id = 'MS'; // sql-ledger parts table id for medical services
380 $sl_dbname = 'sql-ledger'; // sql-ledger database name
381 $sl_dbuser = 'sql-ledger'; // sql-ledger database login name
382 $sl_dbpass = 'secret'; // sql-ledger database login password
383 //////////////////////////////////////////////////////////////////
385 // Don't change anything below this line. ////////////////////////////
387 $encounter = empty($_SESSION['encounter']) ? 0 : $_SESSION['encounter'];
389 if (!empty($_GET['pid']) && empty($_SESSION['pid'])) {
390 $_SESSION['pid'] = $_GET['pid'];
392 elseif (!empty($_POST['pid']) && empty($_SESSION['pid'])) {
393 $_SESSION['pid'] = $_POST['pid'];
395 $pid = empty($_SESSION['pid']) ? 0 : $_SESSION['pid'];
396 $userauthorized = empty($_SESSION['userauthorized']) ? 0 : $_SESSION['userauthorized'];
397 $groupname = empty($_SESSION['authProvider']) ? 0 : $_SESSION['authProvider'];
399 // global interface function to format text length using ellipses
400 function strterm($string,$length) {
401 if (strlen($string) >= ($length-3)) {
402 return substr($string,0,$length-3) . "...";
403 } else {
404 return $string;
408 // Override temporary_files_dir if PHP >= 5.2.1.
409 if (version_compare(phpversion(), "5.2.1", ">=")) {
410 $GLOBALS['temporary_files_dir'] = rtrim(sys_get_temp_dir(),'/');
413 // turn off PHP compatibility warnings
414 ini_set("session.bug_compat_warn","off");
416 //////////////////////////////////////////////////////////////////