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##", htmlspecialchars($_POST['servername'], ENT_QUOTES), $config);
$db->setSetting($mysqli,"name",htmlspecialchars($_POST['servername'], ENT_QUOTES));
//$config = str_replace("##title##", htmlspecialchars($_POST['title'], ENT_QUOTES), $config);
$db->setSetting($mysqli,"title",htmlspecialchars($_POST['title'], ENT_QUOTES));
//$config = str_replace("##url##", $_POST['url'], $config);
$db->setSetting($mysqli,"url",$_POST['url']);
//$config = str_replace("##mailer##", htmlspecialchars($_POST['mailer'], ENT_QUOTES), $config);
$db->setSetting($mysqli,"mailer",htmlspecialchars($_POST['mailer'], ENT_QUOTES));
//$config = str_replace("##mailer_email##", htmlspecialchars($_POST['mailer_email'], ENT_QUOTES), $config);
$db->setSetting($mysqli,"mailer_email",htmlspecialchars($_POST['mailer_email'], ENT_QUOTES));
$config = str_replace("##server##", htmlspecialchars($_POST['server'], ENT_QUOTES), $config);
$config = str_replace("##database##", htmlspecialchars($_POST['database'], ENT_QUOTES), $config);
$config = str_replace("##user##", htmlspecialchars($_POST['dbuser'], ENT_QUOTES), $config);
$config = str_replace("##password##", htmlspecialchars($_POST['dbpassword'], ENT_QUOTES), $config);
// Duplicate of lines 122-123 //$config = str_replace("##name##", htmlspecialchars($_POST['servername'], ENT_QUOTES), $config);
$config = str_replace("##policy_name##", htmlspecialchars($_POST['policy_name'], ENT_QUOTES), $config);
$config = str_replace("##address##", htmlspecialchars($_POST['address'], ENT_QUOTES), $config);
$config = str_replace("##policy_mail##", htmlspecialchars($_POST['policy_mail'], ENT_QUOTES), $config);
$config = str_replace("##policy_phone##", htmlspecialchars($_POST['policy_phone'], ENT_QUOTES),$config);
$config = str_replace("##who_we_are##", htmlspecialchars($_POST['who_we_are'], ENT_QUOTES), $config);
$policy_url_conf = ( ! empty($_POST['policy_url']) ) ? htmlspecialchars($_POST['policy_url'], ENT_QUOTES) : $_POST['url']."/policy.php";
$config = str_replace("##policy_url##", $policy_url_conf, $config);
file_put_contents("config.php", $config);
include_once "create-server-config.php";
$db->setSetting($mysqli,"dbConfigVersion","Version2Beta6");
$db->setSetting($mysqli,"notifyUpdates","no");
unlink("create-server-config.php");
unlink("config.php.template");
unlink("install.sql");
unlink(__FILE__);
header("Location: ".WEB_URL);
}
}
Template::render_header(_("Install"));
?>