file_get_contents and file_put_contents seems to not be available on your PHP installation. You should enable them first.";
$block_form = true;
}
if(!is_writable('data/')) {
$error = "The script seems to be unable to write to data/ folder (to write the data/config.php configuration file). You should give write access during install and disable them after (chmod 777 -R data/ to install and chmod 755 -R data/ after installation for example).";
$block_form = true;
}
if(!empty($_POST['mysql_host']) && !empty($_POST['mysql_login']) && !empty($_POST['mysql_db']) && !empty($_POST['admin_login']) && !empty($_POST['admin_password']) && !empty($_POST['currency']) && !empty($_POST['instance_title']) && !empty($_POST['base_url']) && !empty($_POST['timezone']) && !empty($_POST['email_webmaster']) && check_token(600, 'install')) {
$mysql_host = $_POST['mysql_host'];
$mysql_login = $_POST['mysql_login'];
$mysql_db = $_POST['mysql_db'];
$mysql_password = $_POST['mysql_password'];
$mysql_prefix = (!empty($_POST['mysql_prefix'])) ? $_POST['mysql_prefix'] : '';
$instance_title = (!empty($_POST['instance_title'])) ? $_POST['instance_title'] : 'Bouffe@Ulm';
try {
$db = new PDO('mysql:host='.$mysql_host.';dbname='.$mysql_db, $mysql_login, $mysql_password);
//Create table "Users"
$db->query('CREATE TABLE IF NOT EXISTS '.$mysql_prefix.'Users (id INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY, login VARCHAR(255), display_name VARCHAR(255), password VARCHAR(130), admin TINYINT(1)) DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci');
$count_users = $db->query('SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = "'.$mysql_db.'" AND table_name = "'.$mysql_prefix.'"Users');
$count_users = $count_users->fetch();
if($count_users[0] > 0) {
$warning = 'Table '.$mysql_prefix.'Users already exists. Not doing anything on this table. Please check manually that this table is correct.
';
}
//Create table "Invoices"
$db->query('CREATE TABLE IF NOT EXISTS '.$mysql_prefix.'Invoices (id INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY, date INT(11), users_in VARCHAR(255), buyer INT(11), amount FLOAT, what TEXT) DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci');
$count_invoices = $db->query('SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = "'.$mysql_db.'" AND table_name = "'.$mysql_prefix.'"Invoices');
$count_invoices = $count_users->fetch();
if($count_invoices[0] > 0) {
$warning .= 'Table '.$mysql_prefix.'Users already exists. Not doing anything on this table. Please check manually that this table is correct.
';
}
//Create table "Users_in_invoices"
$db->query('CREATE TABLE IF NOT EXISTS '.$mysql_prefix.'Users_in_invoices (invoice_id INT(11) NOT NULL, KEY invoice_id (invoice_id), user_id INT(11), KEY user_id (user_id), guests INT(11)) DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci');
$count_users_in_invoices = $db->query('SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = "'.$mysql_db.'" AND table_name = "'.$mysql_prefix.'"Users_in_invoices');
$count_users_in_invoices = $count_users_in_invoices->fetch();
if($count_users_in_invoices[0] > 0) {
$warning .= 'Table '.$mysql_prefix.'Users_in_invoices already exists. Not doing anything on this table. Please check manually that this table is correct.
';
}
//Create table "Payback" - TODO
} catch (PDOException $e) {
$error = 'Unable to connect to database and create database, check your credentials and config.
Error message : '.$e->getMessage().'.';
}
if(!filter_var($_POST['email_webmaster'], FILTER_VALIDATE_EMAIL)) {
$email = 'Webmaster\'s e-mail address is invalid.';
}
if(empty($error)) {
if(function_exists('mcrypt_create_iv')) {
$salt = strtr(base64_encode(mcrypt_create_iv(16, MCRYPT_DEV_URANDOM)), '+', '.');
}
else {
mt_srand(microtime(true)*100000 + memory_get_usage(true));
$salt = md5(uniqid(mt_rand(), true));
}
$salt = sprintf("$2a$%02d$", 10) . $salt; //prefix for blowfish
$config = "setLogin($_POST['admin_login']);
$admin->setDisplayName($_POST['admin_display_name']);
$admin->setPassword($admin->encrypt($_POST['admin_password']));
$admin->setAdmin(true);
$admin->save();
if(empty($warning)) {
header('location: index.php');
exit();
}
else {
echo '
'.$warning.'Go to your instance.
'; } } catch (Exception $e) { $erreur = 'An error occurred when inserting user in the database.This small form will guide you through the installation of Bouffe@Ulm. You must fill in all the fields.