negotiate($override);
$_SESSION['locale'] = $best_match;
setlocale(LC_ALL, $_SESSION['locale'].".UTF-8");
bindtextdomain("server-status", __DIR__ . "/locale/");
bind_textdomain_codeset($_SESSION['locale'], "utf-8");
textdomain("server-status");
}
if (isset($_POST['server']))
{
$mysqli = new mysqli($_POST['server'],$_POST['dbuser'],$_POST['dbpassword'],$_POST['database']);
if ($mysqli->connect_errno) {
$message .= sprintf(_("Connection failed: %s\n"), $mysqli->connect_error);
}
if (isset($_POST['url']) && filter_var($_POST['url'], FILTER_VALIDATE_URL) === false)
{
$message .= _("Please set valid url!");
}
//Ostatnà má checky existence ve funkci pro pridani
if (0 == strlen(trim($_POST['servername']))){
$messages[] = _("Server name");
}
if (0 == strlen(trim($_POST['url']))){
$messages[] = _("Url");
}
if (0 == strlen(trim($_POST['mailer']))){
$messages[] = _("Mailer name");
}
if (0 == strlen(trim($_POST['title']))){
$messages[] = _("Title");
}
if (0 == strlen(trim($_POST['mailer_email']))){
$messages[] = _("Mailer email");
}
if (0 == strlen(trim($_POST['server']))){
$messages[] = _("Database server");
}
if (0 == strlen(trim($_POST['database']))){
$messages[] = _("Database name");
}
if (0 == strlen(trim($_POST['dbuser']))){
$messages[] = _("Database user");
}
if (0 == strlen(trim($_POST['dbpassword'])))
{
$messages[] = _("Database password");
}
if (isset($messages))
{
$message .= _("Please enter");
$message .= implode(", ", $messages);
}
}
if(isset($_POST['server']) && empty($message))
{
define("MAILER_NAME", $_POST['mailer']);
define("MAILER_ADDRESS", $_POST['mailer_email']);
define("INSTALL_OVERRIDE", true);
//No need to include config, as we have connection from testing it... :)
//There may be better way to do this...
$sql = file_get_contents("install.sql");
$array = explode(";", $sql);
foreach ($array as $value) {
$val = trim($value);
if (empty($val))
{
continue;
}
$q_res = $mysqli->query($value);
if ($q_res === false)
{
$message = sprintf(_("Error while creating database. Please check permission for your account or MYSQL version.
Error: %s"), $mysqli->error);
break;
}
}
if (empty($message))
{
require_once("classes/constellation.php");
User::add();
}
if (empty($message))
{
//Create config
$config = file_get_contents("config.php.template");
$config = str_replace("##name##", $_POST['servername'], $config);
$config = str_replace("##title##", $_POST['title'], $config);
$config = str_replace("##url##", $_POST['url'], $config);
$config = str_replace("##mailer##", $_POST['mailer'], $config);
$config = str_replace("##mailer_email##", $_POST['mailer_email'], $config);
$config = str_replace("##server##", $_POST['server'], $config);
$config = str_replace("##database##", $_POST['database'], $config);
$config = str_replace("##user##", $_POST['dbuser'], $config);
$config = str_replace("##password##", $_POST['dbpassword'], $config);
$config = str_replace("##name##", $_POST['servername'], $config);
$config = str_replace("##policy_name##", $_POST['policy_name'], $config);
$config = str_replace("##address##", $_POST['address'], $config);
$config = str_replace("##policy_mail##", $_POST['policy_mail'], $config);
$config = str_replace("##policy_phone##", $_POST['policy_phone'],$config);
$config = str_replace("##who_we_are##", $_POST['who_we_are'], $config);
file_put_contents("config.php", $config);
unlink("config.php.template");
unlink("install.sql");
unlink(__FILE__);
header("Location: ".WEB_URL);
}
}
Template::render_header(_("Install"));
?>