<link rel="stylesheet" href="./media/install.css" type="text/css" >
<title><?php ptrans ('SYP wizard')?></title>
<script type="text/javascript">
+ var sypStrings = {
+ emptyPasswordError: "<?php ptrans('Password cannot be empty')?>"
+ };
+
function init () {
if (document.getElementById('db_host')) {
document.getElementById('db_host').focus();
document.getElementById('admin_pass').select();
}
}
+
+ function checkpwd () {
+ var pass = document.getElementById('admin_pass').value;
+ if (!pass) {
+ document.getElementById('empty_pass_error').innerHTML = sypStrings.emptyPasswordError;
+ document.getElementById('empty_pass_error').style.display = "block";
+ document.getElementById('admin_pass').focus();
+ return false;
+ }
+ return true;
+ }
</script>
</head>
<body onload="init()">
function create_install_form () {
if (isset ($_POST ["db_form_submit"])) {
+ $type = $_POST ["db_type"];
$host = $_POST ["db_host"];
$name = $_POST ["db_name"];
$user = $_POST ["db_user"];
$prefix = $_POST ["db_prefix"];
$title = $_POST ["site_title"];
} else {
+ $type = "mysql";
$host = "localhost";
$user = "syp";
$name = "syp";
print '<form method="post" action="' . $_SERVER ["REQUEST_URI"] . '"><fieldset>' . "\n";
print '<legend>' . trans ("SYP configuration") . '</legend>' . "\n";
+ $drivers = array();
+ $handle = opendir("./inc/db");
+ if (!$handle) {
+ par_error_and_leave (trans ('Could not list <code>inc/db</code> directory'));
+ }
+ while (false !== ($file = readdir($handle))) {
+ if ($file == "." or $file == "..") {
+ continue;
+ }
+ $driver_name = substr($file,0,strrpos($file,'.'));
+ if ($driver_name == "anydb") {
+ continue;
+ }
+ array_push ($drivers, $driver_name);
+ }
+ closedir($handle);
+
+
+ print '<div><label for="db_type" title="' .
+ trans ("You can specify a database backend. Mysql is the most available for standard web hosting services.") .
+ '">' . trans ("database backend:") . '</label>' . "\n" .
+ '<select id="db_type" name="db_type">'. "\n";
+ foreach ($drivers as $driver) {
+ if ($driver == $type) {
+ print '<option name="' . $driver . '" selected="true">' . $driver . '</option>' . "\n";
+ } else {
+ print '<option name="' . $driver . '">' . $driver . '</option>' . "\n";
+ }
+ }
+ print "</select>" . "\n";
+
print '<div><label for="db_host" title="' .
trans ("address of the database server (example: localhost, db.myhost.com or 192.168.0.15).") .
'">' . trans ("database server hostname:") . '</label>' . "\n" .
}
}
+ define (DBTYPE, _unquote ($_POST ["db_type"]));
define (DBHOST, _unquote ($_POST ["db_host"]));
define (DBNAME, _unquote ($_POST ["db_name"]));
define (DBUSER, _unquote ($_POST ["db_user"]));
leave ();
}
- require_once ("./inc/db/mysql.php");
+ if (!include_once ("./inc/db/" . DBTYPE . ".php")) {
+ par_error_and_leave (trans("Unkown backend: ", DBTYPE));
+ }
require_once ("./inc/utils.php");
try {
if ($handle) {
while (!feof ($handle)) {
$line = fgets ($handle, 4096);
- foreach (array ("DBHOST", "DBNAME", "DBUSER", "DBPWD", "DBPREFIX", "SITETITLE") as $value) {
+ foreach (array ("DBTYPE", "DBHOST", "DBNAME", "DBUSER", "DBPWD", "DBPREFIX", "SITETITLE") as $value) {
$pattern = "(define\s+\(\s*\"$value\"\s*,\s*\")[^\"]*(\"\s*\)\s*;)";
if (preg_match( "/$pattern/", $line, $match )) {
$line = $match[1] . addslashes (constant ($value)) . $match[2];
if ($users_table_exists) {
par_success (trans ('Found user table.'));
} else {
- if (isset($_POST ["admin_pass"])) {
+ $empty_pass = (isset ($_POST ["admin_pass"]) && (strlen ($_POST ["admin_pass"]) == 0));
+ if ($_POST ["admin_pass"]) {
try {
$connection->create_users_table (true);
} catch (Exception $e) {
par_success (trans ('Admin password initialized.'));
} else {
- print ('<form class="center" method="post" action="">
+ print ('<form class="center" method="post" action="" onsubmit="return checkpwd()">
<label for="admin_pass">' . trans ("choose admin password") . '</label>
- <input id="admin_pass" name="admin_pass" type="password">
- <input type="submit">
- </form>');
+ <input id="admin_pass" name="admin_pass" type="password">');
+ if ($empty_pass) {
+ print ('<p class="error" id="empty_pass_error">' . trans('Password cannot be empty') . '</p>');
+ } else {
+ print ('<p class="error" style="display: none" id="empty_pass_error"></p>');
+ }
+ print ('<br><input type="submit"></form>');
leave ();
}
}