Skip to content
Browse files

Improved database installer to give useful output

  • Loading branch information...
1 parent 4a1123d commit 4616eefd562d907ead6800dd232cf06d69f1b75c @b-turchyn committed May 26, 2011
Showing with 63 additions and 11 deletions.
  1. +63 −11 src/install/index.php
View
74 src/install/index.php
@@ -18,41 +18,93 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
************************************************************************/
-error_reporting(E_ALL);
-ini_set('display_errors','On');
+error_reporting(0);
+ini_set('display_errors','Off');
require_once 'classes/sqli.php';
+function bufferflush (){
+ echo(str_repeat(' ',256));
+ // check that buffer is actually set before flushing
+ if (ob_get_length()){
+ @ob_flush();
+ @flush();
+ @ob_end_flush();
+ }
+ @ob_start();
+}
+?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
+
+ <title>CoC Chargen Installer</title>
+ <style type='text/css'>
+ body {background:#8CA2D5;font-family: Verdana;font-size:10px;margin: 0;padding: 0;}
+ .header {width: 100%; margin: 0; padding: 0;border: 0; background: #5D75AB;}
+ .header h1 {text-align:right;margin: 0 0 25px 0;padding:25px;}
+ .container {margin: auto; width: 400px;padding: 10px;background:#A0B0D5;position:relative;}
+ .label {width: 200px;text-align: right;float:left;height:20px;vertical-align:bottom;padding-top:5px;}
+ .input {width: 200px;text-align: left; float:left;height:25px;}
+ .status {text-align:center;font-size: 12px;}
+ .success {color: green;}
+ .failure {color: red;}
+ </style>
+
+</head>
+
+<body>
+ <div class="header"><h1>CoC Chargen Installer</h1></div>
+ <div class="container">
+<?php
+
if(isset($_POST['coc_install'])) {
$sql = new SQLiInstall($_POST['coc_host'], $_POST['coc_user'], $_POST['coc_password'], $_POST['coc_database'], $_POST['coc_prefix']);
- echo $sql->host_info . "<br />";
+ echo "Successfully connected to " . $sql->host_info . "<br />";
+
+ $failed = false;
// Get the SQL files
$dir = 'tabledata';
$files = scandir($dir, 0);
// Iterate through each file
foreach($files as $key => $value) {
if(preg_match("/.sql$/", $value)) {
- $res = $sql->runQueryFromFile($value);
echo preg_replace("/.sql$/", "", $value) . " ==> ";
- if(is_array($res) && $res[0] == 0) {
+ bufferflush();
+
+ $res = $sql->runQueryFromFile($value);
+
+ if($res == null) {
echo "<span style=\"color: green\">Passed</span><br />\n";
} else {
echo "<span style=\"color: red\">FAILED</span><br />\n";
+ $failed = true;
}
}
}
+ if(!$failed) {
+ echo "<p class='status success'>Completed successfully!</p>";
+ } else {
+ echo "<p class='status failed'>One or more install queries failed. Your installation of CoC Chargen may not function properly!</p>";
+ }
+
} else {
?>
<form method='POST'>
- <label for='coc_host'>Database host:</label> <input type="text" name="coc_host" /><br />
- <label for='coc_user'>Database username:</label> <input type="text" name="coc_user" /><br />
- <label for='coc_password'>Database password:</label> <input type="text" name="coc_password" /><br />
- <label for='coc_database'>Database name:</label> <input type="text" name="coc_database" /><br />
- <label for='coc_prefix'>Table prefix:</label> <input type="text" name="coc_prefix" /><br />
- <input type="submit" name="coc_install" value="Install Database" />
+ <div class='label'><label for='coc_host'>Database host:</label></div> <div class='input'><input type="text" name="coc_host" /></div>
+ <div class='label'><label for='coc_user'>Database username:</label></div> <div class='input'><input type="text" name="coc_user" /></div>
+ <div class='label'><label for='coc_password'>Database password:</label></div> <div class='input'><input type="text" name="coc_password" /></div>
+ <div class='label'><label for='coc_database'>Database name:</label></div> <div class='input'><input type="text" name="coc_database" /></div>
+ <div class='label'><label for='coc_prefix'>Table prefix:</label></div> <div class='input'><input type="text" name="coc_prefix" /></div>
+ <div style='text-align:center'><input type="submit" name="coc_install" value="Install Database" /></div>
</form>
<?php
}
?>
+ </div>
+</body>
+</html>

0 comments on commit 4616eef

Please sign in to comment.
Something went wrong with that request. Please try again.