added bootstrap 2.1.1; fixed paths to match edoko (img->pics)
[e-DoKo.git] / index.php
index d1d2926f15271ab80566a4d252ee86c20317ac36..00014088760a01c0fdd4ace5ca7c80e642631d52 100644 (file)
--- a/index.php
+++ b/index.php
@@ -1,6 +1,32 @@
 <?php
+/* Copyright 2006, 2007, 2008, 2009, 2010, 2011, 2012 Arun Persaud <arun@nubati.net>
+ *
+ *   This file is part of e-DoKo.
+ *
+ *   e-DoKo is free software: you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation, either version 3 of the License, or
+ *   (at your option) any later version.
+ *
+ *   e-DoKo is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with e-DoKo.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
 error_reporting(E_ALL);
 
+/* start a session, if it is not already running.
+ * This way people don't have to log in all the times.
+ * The session variables can also be read out from different
+ * php scripts, so that the code can be easily split up across several files
+ */
+session_start();
+
 include_once("config.php");                /* needs to be first in list, since other includes use this */
 include_once("./include/output.php");      /* html output only */
 include_once("./include/db.php");          /* database only */
@@ -10,21 +36,48 @@ include_once("./include/functions.php");   /* the rest */
 config_check();
 
 /* open the database */
-if(DB_open()<0)
+$DBopen = DB_open();
+if($DBopen<0)
   {
     output_header();
-    echo "Database error, can't connect... Please wait a while and try again. ".
-      "If the problem doesn't go away feel free to contact $ADMIN_NAME at $ADMIN_EMAIL.";
+
+    if($DBopen == -1)
+      echo "Database error, can't connect... Please wait a while and try again. ".
+       "If the problem doesn't go away feel free to contact $ADMIN_NAME at $ADMIN_EMAIL.";
+    else if ($DBopen == -2)
+      echo 'Wrong database version, please update your database using the update.php script.';
+
     output_footer();
     exit();
   }
 
-/* start a session, if it is not already running.
- * This way people don't have to log in all the times. 
- * The session variables can also be read out from different
- * php scripts, so that the code can be easily split up across several files
+/* localization */
+/* needs to be in front of output_header, but we don't know the users preferences at this time,
+ * so we go by the session variable or if language is set
  */
-session_start();
+if(myisset('language') || isset($_SESSION['language']))
+  {
+    $language = 'en';
+
+    if(myisset('language'))
+      $language = $_REQUEST['language'];
+    else if(isset($_SESSION['language']))
+      $language = $_SESSION['language'];
+
+    switch($language)
+      {
+      case 'de':
+       putenv("LC_ALL=de_DE");
+       setlocale(LC_ALL, "de_DE");
+       // Specify location of translation tables
+       bindtextdomain("edoko", "./locale");
+       // Choose domain
+       textdomain("edoko");
+       break;
+      default:
+       /* do nothing */
+      }
+  }
 
 /* done major error checking, output header of HTML page */
 output_header();
@@ -50,19 +103,31 @@ switch($action)
     require './include/reminder.php';
     break;
   case 'logout':
-    require './include/logout.php'; 
+    require './include/logout.php';
     require './include/welcome.php';
     break;
   case 'login':
-    require './include/login.php'; 
+    require './include/login.php';
     require './include/user.php';
     break;
   case 'register':
     require './include/register.php';
     break;
+  case 'prefs':
+    require './include/preferences.php';
+    break;
   case 'game':
     require './include/game.php';
     break;
+  case 'about':
+    require './include/about.php';
+    break;
+  case 'stats':
+    if(isset($_SESSION["name"]))
+      require './include/stats.php';
+    else
+      require './include/welcome.php';
+    break;
   default:
     if(isset($_SESSION["name"]))
       require './include/user.php';
@@ -70,6 +135,11 @@ switch($action)
       require './include/welcome.php';
   }
 
+/* ask for login or display login info, needs to go at the end, so that we have the
+ * session-variable already set.
+ */
+output_status();
+
 output_footer();
 
 DB_close();
@@ -81,5 +151,3 @@ DB_close();
  *End:
  */
 ?>
-
-