PageRenderTime 52ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/interface/globals.php

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