From ddbc3e12d28249b1235a37afd76eeead12626624 Mon Sep 17 00:00:00 2001 From: drapeau Date: Sat, 20 Mar 2021 09:31:47 +0100 Subject: [PATCH] [IMP] now in AJAX PHP file, it is not needed anymore to use DB IDs hard coded; Use the session dsn --- index.php | 73 +++++++++++++++++++++++++-------------------- modules/ClassDB.php | 13 ++++++++ 2 files changed, 54 insertions(+), 32 deletions(-) create mode 100644 modules/ClassDB.php diff --git a/index.php b/index.php index 146e230..c9d28ae 100644 --- a/index.php +++ b/index.php @@ -30,6 +30,7 @@ require_once './modules/InterfacePostgreSQL.php'; require_once './modules/InterfaceTranslation.php'; require_once './modules/InterfaceEmail.php'; +require_once './modules/ClassDB.php'; require_once './modules/ClassConfig.php'; require_once './modules/ClassTranslation.php'; require_once './modules/ClassController.php'; @@ -42,6 +43,7 @@ require_once './modules/ClassUser.php'; require_once './modules/ClassEmail.php'; require_once './modules/ClassForm.php'; +$oDB = new ClassDB(); $oConf = new ClassConfig(); $oTrans = new ClassTranslation(); $oController = new ClassController($_REQUEST); @@ -70,48 +72,55 @@ if(file_exists($oConf->getPathCustom("modules.php"))){ // Load configuration in _SESSION //unset($_SESSION['config']); //uncomment this line, even for test, creates a bug for translations for logged users - if (!isset($_SESSION['config'])) { - $_SESSION['config'] = $oConf->getConfig(); + $_SESSION['config'] = $oConf->getConfig(); - ////// - //// The code below creates a bug in Chromium "Too many redirections - //$find_lang = "/[a-zA-Z][a-zA-Z]-[a-zA-Z][a-zA-Z]/"; - //preg_match($find_lang, $_SERVER['HTTP_ACCEPT_LANGUAGE'], $lang); - //$lang = str_replace('-', '_', strtolower($lang[0])); - //$langs = $oLang->listLanguages(); - // - //foreach ($langs as $k=>$v) { - // if ($langs[$k]['code'] == $lang) { - // $_SESSION['config']['default_lang_code'] = $lang; - // } - //} - - $_SESSION['translations'] = $oTrans->listTranslations($_SESSION['config']['default_lang_code']); - $_SESSION['countries'] = $oCountry->listCountries('priority ASC, name ASC'); - $_SESSION['activeCountries'] = $oCountry->listActiveCountries('priority ASC, name ASC'); - $_SESSION['currencies'] = $oCurrency->listCurrencies('priority ASC, name ASC'); - $_SESSION['languages'] = $oLang->listLanguages(); - $_SESSION['activeLanguages'] = $oLang->listActiveLanguages(); + ////// + //// The code below creates a bug in Chromium "Too many redirections + //$find_lang = "/[a-zA-Z][a-zA-Z]-[a-zA-Z][a-zA-Z]/"; + //preg_match($find_lang, $_SERVER['HTTP_ACCEPT_LANGUAGE'], $lang); + //$lang = str_replace('-', '_', strtolower($lang[0])); + //$langs = $oLang->listLanguages(); + // + //foreach ($langs as $k=>$v) { + // if ($langs[$k]['code'] == $lang) { + // $_SESSION['config']['default_lang_code'] = $lang; + // } + //} + + $_SESSION['translations'] = $oTrans->listTranslations($_SESSION['config']['default_lang_code']); + $_SESSION['countries'] = $oCountry->listCountries('priority ASC, name ASC'); + $_SESSION['activeCountries'] = $oCountry->listActiveCountries('priority ASC, name ASC'); + $_SESSION['currencies'] = $oCurrency->listCurrencies('priority ASC, name ASC'); + $_SESSION['languages'] = $oLang->listLanguages(); + $_SESSION['activeLanguages'] = $oLang->listActiveLanguages(); + //$_SESSION['dsn'] = $oPDOLink; } + +$_SESSION['dsn'] = ['host'=>$oDB->_host, 'port'=>$oDB->_port, 'dbname'=>$oDB->_dbname, 'user'=>$oDB->_user, 'password'=>$oDB->_password]; + + + + + if(!isset($_SESSION['translations'])){ - $_SESSION['translations'] = $oTrans->listTranslations('fr_fr'); + $_SESSION['translations'] = $oTrans->listTranslations('fr_fr'); } if(!isset($_SESSION['countries'])){ - $_SESSION['countries'] = $oCountry->listCountries('priority ASC, name ASC'); + $_SESSION['countries'] = $oCountry->listCountries('priority ASC, name ASC'); } if(!isset($_SESSION['activeCountries'])){ - $_SESSION['activeCountries'] = $oCountry->listActiveCountries('priority ASC, name ASC'); + $_SESSION['activeCountries'] = $oCountry->listActiveCountries('priority ASC, name ASC'); } if(!isset($_SESSION['currencies'])){ - $_SESSION['currencies'] = $oCurrency->listCurrencies('priority ASC, name ASC'); + $_SESSION['currencies'] = $oCurrency->listCurrencies('priority ASC, name ASC'); } if(!isset($_SESSION['languages'])){ - $_SESSION['languages'] = $oLang->listLanguages(); + $_SESSION['languages'] = $oLang->listLanguages(); } if(!isset($_SESSION['activeLanguages'])){ - $_SESSION['activeLanguages'] = $oLang->listActiveLanguages(); + $_SESSION['activeLanguages'] = $oLang->listActiveLanguages(); } //$data_updated = array(); @@ -137,11 +146,11 @@ if (!isset($_REQUEST['page'])) header("Location: ".$oConf->getURLRoot($oFeatTran // Get features for menu //unset($_SESSION['features']); if (!isset($_SESSION['features'])) { - if(isset($_SESSION['user']['id'])) { - $_SESSION['features'] = $oFeat->getFeaturesOfUser($_SESSION['user']['id']); - } else { - $_SESSION['features'] = $oFeat->getFeatures($_SESSION['config']['default_lang_code']); - } + if(isset($_SESSION['user']['id'])) { + $_SESSION['features'] = $oFeat->getFeaturesOfUser($_SESSION['user']['id']); + } else { + $_SESSION['features'] = $oFeat->getFeatures($_SESSION['config']['default_lang_code']); + } } if(file_exists($oConf->getPathCustom("themes/".$_SESSION['config']['theme']."/index.php"))){ diff --git a/modules/ClassDB.php b/modules/ClassDB.php new file mode 100644 index 0000000..da9d6a8 --- /dev/null +++ b/modules/ClassDB.php @@ -0,0 +1,13 @@ +_host = InterfacePostgreSQL::PG_SERVER; + $this->_port = InterfacePostgreSQL::PG_PORT; + $this->_dbname = InterfacePostgreSQL::PG_DBNAME; + $this->_user = InterfacePostgreSQL::PG_USER; + $this->_password = InterfacePostgreSQL::PG_PASSWORD; + } + public function __desctruct(){} + + public static function databaseConnect(){} +} \ No newline at end of file