PageRenderTime 55ms CodeModel.GetById 27ms RepoModel.GetById 1ms app.codeStats 0ms

/htdocs/after.inc.php

https://bitbucket.org/speedealing/speedealing
PHP | 119 lines | 65 code | 10 blank | 44 comment | 29 complexity | 6267a5ab77d4e54bd51a7b28ae875ec6 MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.1, GPL-3.0, MIT
  1. <?PHP
  2. /* Copyright (C) 2002-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2003 Xavier Dutoit <doli@sydesy.com>
  4. * Copyright (C) 2004-2012 Laurent Destailleur <eldy@users.sourceforge.net>
  5. * Copyright (C) 2004 Sebastien Di Cintio <sdicintio@ressource-toi.org>
  6. * Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be>
  7. * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com>
  8. * Copyright (C) 2005 Simon Tosser <simon@kornog-computing.com>
  9. * Copyright (C) 2006 Andre Cianfarani <andre.cianfarani@acdeveloppement.net>
  10. * Copyright (C) 2010 Juanjo Menent <jmenent@2byte.es>
  11. * Copyright (C) 2011 Philippe Grand <philippe.grand@atoo-net.com>
  12. * Copyright (C) 2012 Herve Prot <herve.prot@symeos.com>
  13. *
  14. * This program is free software; you can redistribute it and/or modify
  15. * it under the terms of the GNU General Public License as published by
  16. * the Free Software Foundation; either version 3 of the License, or
  17. * (at your option) any later version.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU General Public License
  25. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  26. */
  27. /*
  28. * Load object $conf
  29. * After this, all parameters conf->global->CONSTANTS are loaded
  30. */
  31. if (!defined('NOREQUIREDB')) {
  32. // Here we read database (llx_const table) and define $conf->global->XXX var.
  33. // if no db specified, using default database form user profile (entity)
  34. // Just after login : we choose the default entity
  35. $conf->useDatabase("system");
  36. $conf->setValues();
  37. $database = (!empty($conf->Couchdb->name)?$conf->Couchdb->name:$user->entity); // for avoid error
  38. $couch->useDatabase($database); //Refresh default dababase if needed
  39. }
  40. // Overwrite database value
  41. if (!empty($conf->file->mailing_limit_sendbyweb)) {
  42. $conf->global->MAILING_LIMIT_SENDBYWEB = $conf->file->mailing_limit_sendbyweb;
  43. }
  44. // If software has been locked. Only login $conf->global->MAIN_ONLY_LOGIN_ALLOWED is allowed.
  45. if (!empty($conf->global->MAIN_ONLY_LOGIN_ALLOWED)) {
  46. $ok = 0;
  47. if ((!session_id() || !isset($_SESSION["dol_login"])) && !isset($_POST["username"]) && !empty($_SERVER["GATEWAY_INTERFACE"]))
  48. $ok = 1; // We let working pages if not logged and inside a web browser (login form, to allow login by admin)
  49. elseif (isset($_POST["username"]) && $_POST["username"] == $conf->global->MAIN_ONLY_LOGIN_ALLOWED)
  50. $ok = 1; // We let working pages that is a login submission (login submit, to allow login by admin)
  51. elseif (defined('NOREQUIREDB'))
  52. $ok = 1; // We let working pages that don't need database access (xxx.css.php)
  53. elseif (defined('EVEN_IF_ONLY_LOGIN_ALLOWED'))
  54. $ok = 1; // We let working pages that ask to work even if only login enabled (logout.php)
  55. elseif (session_id() && isset($_SESSION["dol_login"]) && $_SESSION["dol_login"] == $conf->global->MAIN_ONLY_LOGIN_ALLOWED)
  56. $ok = 1; // We let working if user is allowed admin
  57. if (!$ok) {
  58. if (session_id() && isset($_SESSION["dol_login"]) && $_SESSION["dol_login"] != $conf->global->MAIN_ONLY_LOGIN_ALLOWED) {
  59. print 'Sorry, your application is offline.' . "\n";
  60. print 'You are logged with user "' . $_SESSION["dol_login"] . '" and only administrator user "' . $conf->global->MAIN_ONLY_LOGIN_ALLOWED . '" is allowed to connect for the moment.' . "\n";
  61. $nexturl = DOL_URL_ROOT . '/user/logout.php';
  62. print 'Please try later or <a href="' . $nexturl . '">click here to disconnect and change login user</a>...' . "\n";
  63. } else {
  64. print 'Sorry, your application is offline. Only administrator user "' . $conf->global->MAIN_ONLY_LOGIN_ALLOWED . '" is allowed to connect for the moment.' . "\n";
  65. $nexturl = DOL_URL_ROOT . '/';
  66. print 'Please try later or <a href="' . $nexturl . '">click here to change login user</a>...' . "\n";
  67. }
  68. exit;
  69. }
  70. }
  71. // Set default language (must be after the setValues of $conf)
  72. if (!defined('NOREQUIRETRAN')) {
  73. if (!class_exists('Translate'))
  74. require DOL_DOCUMENT_ROOT . '/core/class/translate.class.php';
  75. $langs = new Translate(); // Use database translation
  76. $langs->setDefaultLang($conf->global->MAIN_LANG_DEFAULT);
  77. }
  78. /*
  79. * Create object $mysoc (A thirdparty object that contains properties of companies managed by Speedealing.
  80. */
  81. if (!defined('NOREQUIREDB') && !defined('NOREQUIRESOC')) {
  82. require_once(DOL_DOCUMENT_ROOT . "/societe/class/societe.class.php");
  83. $mysoc = new Societe($db);
  84. if ($_SERVER["PHP_SELF"] != '/admin/company.php')
  85. try {
  86. $mysoc->load("societe:mysoc", true);
  87. } catch (Exception $e) {
  88. // First install
  89. if ($conf->urlrewrite) {
  90. $tmp_db = $conf->Couchdb->name; // First connecte using $user->entity for default
  91. Header("Location: /" . $tmp_db . '/admin/company.php?action=edit');
  92. exit;
  93. } else {
  94. Header("Location: /admin/company.php?action=edit");
  95. exit;
  96. }
  97. }
  98. // For some countries, we need to invert our address with customer address
  99. // TODO move this specific settings in database
  100. if ($mysoc->country_id == 'DE' && !isset($conf->global->MAIN_INVERT_SENDER_RECIPIENT))
  101. $conf->global->MAIN_INVERT_SENDER_RECIPIENT = 1;
  102. }
  103. /**
  104. * Initialise messages notifications
  105. */
  106. dol_setcache("errors", array());
  107. dol_setcache("warnings", array());
  108. dol_setcache("mesgs", array());
  109. ?>