summaryrefslogtreecommitdiff
path: root/installer/index.php
diff options
context:
space:
mode:
Diffstat (limited to 'installer/index.php')
-rw-r--r--installer/index.php149
1 files changed, 82 insertions, 67 deletions
diff --git a/installer/index.php b/installer/index.php
index a0e9235..c16ec38 100644
--- a/installer/index.php
+++ b/installer/index.php
@@ -1,18 +1,30 @@
<?php
-$BASE = dirname(dirname(__FILE__));
+define('BASEPATH', dirname(dirname(__FILE__)));
+
+// Decide where to look for things
+define('LIBPATH', BASEPATH.'/src/lib'.PATH_SEPARATOR.BASEPATH.'/src/ext');
+define('MODELPATH', BASEPATH.'/src/models');
+define('VIEWPATH', BASEPATH.'/src/views');// views are not objects
+define('CONTROLLERPATH', BASEPATH.'/src/controllers');
+define('PLUGINPATH', BASEPATH.'/src/plugins');
+
+// Modify our include path to catch our class files.
set_include_path(get_include_path()
- .PATH_SEPARATOR. "$BASE/src/lib"
- .PATH_SEPARATOR. "$BASE/src/ext"
+ .PATH_SEPARATOR.LIBPATH
+ .PATH_SEPARATOR.MODELPATH
+ .PATH_SEPARATOR.CONTROLLERPATH
+ .PATH_SEPARATOR.PLUGINPATH
);
+
$uri = $_SERVER['REQUEST_URI'];
require_once('include.php');
-$conf_file = "$BASE/conf.php";
+$conf_file = BASEPATH.'/conf.php';
if (!mm_isSqlConfigured($conf_file)) {
- require_once('Template.class.php');
- $t = new Template($BASE);
+ require_once(VIEWPATH.'/Template.class.php');
+ $t = new Template('../');
$t->header('Message Manager: Installer');
@@ -34,11 +46,11 @@ if (!mm_isSqlConfigured($conf_file)) {
$t->openFieldset("MySQL Authentication", $mysql);
$t->inputText('db_host', 'Hostname', '',
- getParam('db_host','localhost'), $mysql);
+ mm_getParam('db_host','localhost'), $mysql);
$t->inputText('db_user', 'Username', '',
- getParam('db_user'), $mysql);
+ mm_getParam('db_user'), $mysql);
$t->inputPassword('db_password', 'Password', '',
- getParam('db_password'), $mysql);
+ mm_getParam('db_password'), $mysql);
if ($try && !$mysql) {
$t->inputP("Could not authenticate: ".mysql_error(), true);
}
@@ -58,7 +70,7 @@ if (!mm_isSqlConfigured($conf_file)) {
$db_message = '';
if ($charset) {
$t->setRet(true);
- $db = mm_mysql_db($mysql, $_POST['db_name'], $db_message);
+ $db = mm_mysql_create_db($mysql, $_POST['db_name'], $db_message);
$t->setRet(false);
}
@@ -66,47 +78,42 @@ if (!mm_isSqlConfigured($conf_file)) {
$table = false;
if ($db) {
- $table_exists = mm_mysql_table_exists($mysql,$db_prefix.'auth');
- if (!$table_exists) {
- $query = '';
- $query.='CREATE TABLE '.$db_prefix."auth (\n".
- " uid INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,\n".
- " name VARCHAR(255),\n".
- " hash CHAR(60)\n".
- " status INT\n".
- ");";
- $query.='CREATE TABLE '.$db_prefix."users (\n".
- " uid INT UNSIGNED,\n".
- " k VARCHAR(255),\n".
- " v TEXT\n".
- ");";
- $query.='CREATE TABLE '.$db_prefix."conf (\n".
- " k VARCHAR(255),\n".
- " v VARCHAR(255)\n".
- ");";
- $query.='CREATE TABLE '.$db_prefix."plugins (\n".
- " plugin VARCHAR(255),\n".
- " k VARCHAR(255),\n".
- " v VARCHAR(255)\n".
- ");";
- $table = mysql_query($query);
- if (!$table) {
- $table_error = mysql_error($mysql);
- }
- } else {
- $table = true;
- }
+ $table_auth =
+ mm_mysql_create_table($mysql,$db_prefix.'auth',
+ array('uid INT UNSIGNED '.
+ 'AUTO_INCREMENT PRIMARY KEY',
+ 'name VARCHAR(255)',
+ 'hash CHAR(60)',
+ 'status INT'));
+ $table_users =
+ mm_mysql_create_table($mysql,$db_prefix.'users',
+ array('uid INT UNSIGNED',
+ 'k VARCHAR(255)',
+ 'v TEXT'));
+ $table_conf =
+ mm_mysql_create_table($mysql,$db_prefix.'conf',
+ array('k VARCHAR(255)',
+ 'v VARCHAR(255)'));
+ $table_plugins =
+ mm_mysql_create_table($mysql,$db_prefix.'plugins',
+ array('plugin VARCHAR(255)',
+ 'k VARCHAR(255)',
+ 'v VARCHAR(255)'));
+ $tables_ok=(!is_string($table_auth))
+ && (!is_string($table_users))
+ && (!is_string($table_conf))
+ && (!is_string($table_plugins));
}
////////////////////////////////////////////////////////////////////////
- $t->openFieldset("MySQL Settings", $table);
+ $t->openFieldset("MySQL Settings", $tables_ok);
$t->inputText('db_charset', 'Charset',
"I've heard that you may need to change this if ".
"you use an old version of MySQL. 'utf8' is ".
"generally a good option, though.",
- getParam('db_charset','utf8'), $table);
+ mm_getParam('db_charset','utf8'), $tables_ok);
if ($mysql) {
$str = $_POST['db_charset'];
if ($charset) {
@@ -118,26 +125,34 @@ if (!mm_isSqlConfigured($conf_file)) {
}
$t->inputText('db_name', 'Database name', '',
- getParam('db_name', 'messagemanager'), $table);
+ mm_getParam('db_name', 'messagemanager'), $tables_ok);
echo $db_message;
$t->inputText('db_prefix', 'Table prefix',
'Just use simple characters, like [A-Za-z0-9_], '.
'and keep it short.',
- getParam('db_prefix','mm_'), $table);
+ mm_getParam('db_prefix','mm_'), $tables_ok);
if ($db) {
- $db_name = '<q>'.$db_prefix.'auth</q>';
- if ($table) {
- if ($table_exists) {
- $msg="Table $db_name already exists.";
+ $tables = array($db_prefix.'auth'=>$table_auth,
+ $db_prefix.'users'=>$table_users,
+ $db_prefix.'conf'=>$table_conf,
+ $db_prefix.'plugins'=>$table_plugins);
+ foreach ($tables as $name => $table) {
+ $htmlname = '<q>'.htmlentities($name).'</q>';
+ if (is_string($table)) {
+ $msg = "Could not create table $htmlname: ".
+ $table;
} else {
- $msg="Created table $db_name.";
+ switch ($table) {
+ case 0: $msg = "Table $htmlname already exists.";
+ break;
+ case 1: $msg = "Created table $htmlname.";
+ break;
+ }
}
- } else {
- $msg="Could not create table $db_name: ".$table_error;
+ $t->inputP($msg, is_string($table));
}
- $t->inputP($msg, !$table);
}
$t->closeFieldset();
@@ -145,24 +160,24 @@ if (!mm_isSqlConfigured($conf_file)) {
////////////////////////////////////////////////////////////////////////
$fh = false;
- if ($table) {
- $fh = fopen('conf.php', 'w');
- if ($fh === FALSE) {
+ if ($tables_ok) {
+ $fh = fopen($conf_file, 'w');
+ if ($fh === false) {
$msg="Could not open file <q>conf.php</q> for writing.";
- $template->paragraph($msg, true);
+ $t->paragraph($msg, array('class'=>'error'));
} else {
fwrite($fh, '<?php global $db_config;'."\n");
- fwrite($fh, configStr('host'));
- fwrite($fh, configStr('user'));
- fwrite($fh, configStr('password'));
+ fwrite($fh, mm_configStr('host'));
+ fwrite($fh, mm_configStr('user'));
+ fwrite($fh, mm_configStr('password'));
fwrite($fh, "\n");
- fwrite($fh, configStr('charset'));
- fwrite($fh, configStr('name'));
- fwrite($fh, configStr('prefix'));
+ fwrite($fh, mm_configStr('charset'));
+ fwrite($fh, mm_configStr('name'));
+ fwrite($fh, mm_configStr('prefix'));
fclose($fh);
}
}
- if ($fh) {
+ if ($fh!==false) {
$t->closeTag('form');
$t->openTag('form', array('action'=>$uri));
$t->tag('input', array('type'=>'submit',
@@ -205,7 +220,7 @@ if (!mm_isSqlConfigured($conf_file)) {
$uid = $db->addUser($user, $password);
$admin = $db->setStatus($uid, 2);
if (!$admin) {
- $admin_error = mysql_error($mysql);
+ $admin_error = $db->mysql_error();
}
}
@@ -214,9 +229,9 @@ if (!mm_isSqlConfigured($conf_file)) {
$t->openFieldset("First Account (administrator)",$admin);
$t->inputText('mm_user', 'Username',
"Must be <= 255 characters.",
- getParam('mm_user','root'), $admin);
+ mm_getParam('mm_user','root'), $admin);
$t->inputNewPassword('mm_password', 'Password',
- ($pw?getParam('mm_password'):''),
+ ($pw?mm_getParam('mm_password'):''),
$admin);
if ($try && !$pw) {
$msg="Passwords don't match.";
@@ -244,7 +259,7 @@ if (!mm_isSqlConfigured($conf_file)) {
} else {
$t->paragraph("File conf.php already exists, and there ".
"is at least one user. Return to the ".
- "<a href='index.php'>main page</a>.");
+ "<a href='..'>main page</a>.");
}
$t->footer();
}