From 254512c55a642fb3932350a683b30dca39c5912d Mon Sep 17 00:00:00 2001
From: Olivier PEREZ <olivier@olivierperez.fr>
Date: Thu, 3 Sep 2015 08:03:37 +0200
Subject: [PATCH] Install: Redirections between Install and Index

---
 admin/install.php                             | 18 ++---------
 app/classes/Framadate/Utils.php               |  2 +-
 app/inc/init.php                              | 30 ++++++++++++++-----
 app/inc/smarty.php                            |  2 +-
 create_classic_poll.php                       |  2 +-
 index.php                                     |  6 ++++
 ...ysql.auto.sql => install.mysql.auto.sqlXX} |  0
 7 files changed, 33 insertions(+), 27 deletions(-)
 rename install/{install.mysql.auto.sql => install.mysql.auto.sqlXX} (100%)

diff --git a/admin/install.php b/admin/install.php
index 4fbec156..21e3bcb1 100644
--- a/admin/install.php
+++ b/admin/install.php
@@ -20,23 +20,9 @@
 use Framadate\Services\InstallService;
 use Framadate\Utils;
 
-// Define values in place of config.php (that does not exists yet)
-const NOMAPPLICATION = 'Framadate';
-const DEFAULT_LANGUAGE = 'fr';
-const IMAGE_TITRE = 'images/logo-framadate.png';
-const LOG_FILE = 'admin/stdout.log';
-$ALLOWED_LANGUAGES = [
-    'fr' => 'Français',
-    'en' => 'English',
-    'es' => 'Español',
-    'de' => 'Deutsch',
-    'it' => 'Italiano',
-];
-
 require_once '../app/inc/init.php';
-define('CONF_FILENAME', ROOT_DIR . '/app/inc/config.php');
 
-if (file_exists(CONF_FILENAME)) {
+if (is_file(CONF_FILENAME)) {
     header(('Location: ' . Utils::get_server_name()));
     exit;
 }
@@ -48,7 +34,7 @@ if (!empty($_POST)) {
     $result = $installService->install($_POST, $smarty);
 
     if ($result['status'] === 'OK') {
-        header(('Location: ' . Utils::get_server_name() . '/admin/migration.php'));
+        header(('Location: ' . Utils::get_server_name() . 'admin/migration.php'));
         exit;
     } else {
         $error = __('Error', $result['code']);
diff --git a/app/classes/Framadate/Utils.php b/app/classes/Framadate/Utils.php
index 5eec8b55..aca9b9ba 100644
--- a/app/classes/Framadate/Utils.php
+++ b/app/classes/Framadate/Utils.php
@@ -75,7 +75,7 @@ class Utils {
         <script type="text/javascript" src="' . self::get_server_name() . 'js/bootstrap-datepicker.js"></script>
         <script type="text/javascript" src="' . self::get_server_name() . 'js/locales/bootstrap-datepicker.' . $locale . '.js"></script>
         <script type="text/javascript" src="' . self::get_server_name() . 'js/core.js"></script>';
-        if (file_exists($_SERVER['DOCUMENT_ROOT'] . "/nav/nav.js")) {
+        if (is_file($_SERVER['DOCUMENT_ROOT'] . "/nav/nav.js")) {
             echo '<script src="/nav/nav.js" id="nav_js" type="text/javascript" charset="utf-8"></script><!-- /Framanav -->';
         }
 
diff --git a/app/inc/init.php b/app/inc/init.php
index ef31bdf4..8879bae7 100644
--- a/app/inc/init.php
+++ b/app/inc/init.php
@@ -32,17 +32,31 @@ if (ini_get('date.timezone') == '') {
 }
 
 define('ROOT_DIR', __DIR__ . '/../../');
+define('CONF_FILENAME', ROOT_DIR . '/app/inc/config.php');
 
-require_once __DIR__ . '/constants.php';
-@include_once __DIR__ . '/config.php';
-require_once __DIR__ . '/i18n.php';
+if (is_file(CONF_FILENAME)) {
 
-// Smarty
-require_once __DIR__ . '/smarty.php';
+    require_once __DIR__ . '/constants.php';
+    @include_once __DIR__ . '/config.php';
 
-// Connection to database
-if (is_file(__DIR__ . '/config.php')) {
+    // Connection to database
     $connect = new FramaDB(DB_CONNECTION_STRING, DB_USER, DB_PASSWORD);
     RepositoryFactory::init($connect);
+    $err = 0;
+} else {
+    define('NOMAPPLICATION', 'Framadate');
+    define('DEFAULT_LANGUAGE', 'fr');
+    define('IMAGE_TITRE', 'images/logo-framadate.png');
+    define('LOG_FILE', 'admin/stdout.log');
+    $ALLOWED_LANGUAGES = [
+        'fr' => 'Français',
+        'en' => 'English',
+        'es' => 'Español',
+        'de' => 'Deutsch',
+        'it' => 'Italiano',
+    ];
 }
-$err = 0;
+
+require_once __DIR__ . '/i18n.php';
+// Smarty
+require_once __DIR__ . '/smarty.php';
\ No newline at end of file
diff --git a/app/inc/smarty.php b/app/inc/smarty.php
index 83dddedf..26be0b30 100644
--- a/app/inc/smarty.php
+++ b/app/inc/smarty.php
@@ -29,7 +29,7 @@ $smarty->assign('APPLICATION_NAME', NOMAPPLICATION);
 $smarty->assign('SERVER_URL', Utils::get_server_name());
 $smarty->assign('SCRIPT_NAME', $_SERVER['SCRIPT_NAME']);
 $smarty->assign('TITLE_IMAGE', IMAGE_TITRE);
-$smarty->assign('use_nav_js', file_exists($_SERVER['DOCUMENT_ROOT'] . '/nav/nav.js'));
+$smarty->assign('use_nav_js', is_file($_SERVER['DOCUMENT_ROOT'] . '/nav/nav.js'));
 $smarty->assign('locale', $locale);
 $smarty->assign('langs', $ALLOWED_LANGUAGES);
 $smarty->assign('date_format', $date_format);
diff --git a/create_classic_poll.php b/create_classic_poll.php
index 21c652be..1c1f213c 100644
--- a/create_classic_poll.php
+++ b/create_classic_poll.php
@@ -32,7 +32,7 @@ $pollService = new PollService($connect, $logService);
 $mailService = new MailService($config['use_smtp']);
 $purgeService = new PurgeService($connect, $logService);
 
-if (file_exists('bandeaux_local.php')) {
+if (is_file('bandeaux_local.php')) {
     include_once('bandeaux_local.php');
 } else {
     include_once('bandeaux.php');
diff --git a/index.php b/index.php
index 364c90c3..8ee6b6f9 100644
--- a/index.php
+++ b/index.php
@@ -18,9 +18,15 @@
  */
 
 use Framadate\Services\PollService;
+use Framadate\Utils;
 
 include_once __DIR__ . '/app/inc/init.php';
 
+if (!is_file(CONF_FILENAME)) {
+    header(('Location: ' . Utils::get_server_name() . 'admin/install.php'));
+    exit;
+}
+
 /* SERVICES */
 /* -------- */
 $logService = '\Framadate\Services\LogService';
diff --git a/install/install.mysql.auto.sql b/install/install.mysql.auto.sqlXX
similarity index 100%
rename from install/install.mysql.auto.sql
rename to install/install.mysql.auto.sqlXX
-- 
GitLab