require_once('install_functions.php');
+// Start by destroying session to avoid wrong logins from previous installations
+// cookie part
+$cookiedir = '';
+if (dirname($_SERVER['SCRIPT_NAME'])!='/') {
+ $cookiedir = dirname($_SERVER["SCRIPT_NAME"]).'/';
+}
+
+if (isset($_SERVER['HTTP_COOKIE'])) {
+ $cookies = explode(';', $_SERVER['HTTP_COOKIE']);
+ foreach($cookies as $cookie) {
+ $parts = explode('=', $cookie);
+ $name = trim($parts[0]);
+ setcookie($name, '', time()-1000);
+ setcookie($name, '', time()-1000, $cookiedir);
+ }
+}
+// session part
+if (isset($_SESSION['poche_user'])) {
+ unset($_SESSION['poche_user']);
+}
+
if (isset($_GET['clean'])) {
if (is_dir('install')){
delTree('install', true);
$errors[] = 'Impossible to create the SQLite database file. Please check your file permissions.';
}
else {
- $db_path = 'sqlite:' . realpath('') . '/db/poche.sqlite';
- $handle = new PDO($db_path);
- $handle->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
- $sql_structure = "";
+ try {
+ $db_path = 'sqlite:' . realpath('') . '/db/poche.sqlite';
+ $handle = new PDO($db_path);
+ $handle->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
+ $sql_structure = "";
+ } catch (PDOException $e) {
+ $errors[] = "SQLite has encountered an issue : " . $e->getMessage();
+ }
}
} else {
// MySQL and Postgre
$sql_structure = file_get_contents('install/postgres.sql');
}
// create database structure
- $query = $handle->exec($sql_structure);
-
- $usertest = executeQuery($handle,"SELECT * from users WHERE username = ?", array($username));
- if (!empty($usertest)) {
- $continue = false;
- $errors[] = "An user already exists with this username in database.";
- }
+ if (!$handle) {
+ $continue = false;
+ $errors[] = "Couldn't connect to your database server. Please check credentials.";
+ } else {
+ $query = $handle->exec($sql_structure);
+
+ $usertest = executeQuery($handle,"SELECT * from users WHERE username = ?", array($username));
+ if (!empty($usertest)) {
+ $continue = false;
+ $errors[] = "An user already exists with this username in database.";
+ }
+ }
} catch (PDOException $e) {
- $errors[] = $e->getMessage();
+ /* Error codes :
+ / 7 : PostgreSQL issues
+ / 1045 : Access denied to the user : user doesn't exists
+ / 1044 : Access denied to the user : user doesn't have the rights to connect to this database
+ / 2005 : Unknown database server
+ */
+ switch ($e->getCode()) {
+ case 7:
+ $errors[] = "PostgreSQL has encountered an issue : " . $e->getMessage();
+ break;
+ case 1045:
+ $errors[] = "The password for this user is incorrect, or this user doesn't exist.";
+ break;
+ case 1044:
+ $errors[] = "The user isn't allowed to use this database.";
+ break;
+ case 2005:
+ $errors[] = "The server can't be reached.";
+ break;
+ default:
+ $errors[] = "A error happened while connecting to your database : " . $e->getMessage();
+ break;
+ }
$continue = false;
}
}
<link rel="apple-touch-icon-precomposed" sizes="144x144" href="themes/baggy/img/apple-touch-icon-144x144-precomposed.png">
<link rel="apple-touch-icon-precomposed" sizes="72x72" href="themes/baggy/img/apple-touch-icon-72x72-precomposed.png">
<link rel="apple-touch-icon-precomposed" href="themes/baggy/img/apple-touch-icon-precomposed.png">
- <link href='//fonts.googleapis.com/css?family=PT+Sans:700' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="themes/baggy/css/ratatouille.css" media="all">
<link rel="stylesheet" href="themes/baggy/css/font.css" media="all">
<link rel="stylesheet" href="themes/baggy/css/main.css" media="all">