use a container div for padding + handle_db_errors function

This commit is contained in:
Daku 2016-05-19 16:29:55 +01:00
parent d17de45965
commit b161bbcf1b

View File

@ -37,6 +37,9 @@ date_default_timezone_set('UTC');
border: 1px solid black; border: 1px solid black;
border-radius: 16px; border-radius: 16px;
} }
#installer > .container {
padding: 5px;
}
#installer A { #installer A {
text-decoration: none; text-decoration: none;
} }
@ -65,12 +68,14 @@ date_default_timezone_set('UTC');
<?php if(false) { ?> <?php if(false) { ?>
<div id="installer"> <div id="installer">
<h1>Install Error</h1> <h1>Install Error</h1>
<p>Shimmie needs to be run via a web server with PHP support -- you <div class="container">
appear to be either opening the file from your hard disk, or your <p>Shimmie needs to be run via a web server with PHP support -- you
web server is mis-configured and doesn't know how to handle PHP files.</p> appear to be either opening the file from your hard disk, or your
<p>If you've installed a web server on your desktop PC, you probably web server is mis-configured and doesn't know how to handle PHP files.</p>
want to visit <a href="http://localhost/">the local web server</a>.<br/><br/> <p>If you've installed a web server on your desktop PC, you probably
</p> want to visit <a href="http://localhost/">the local web server</a>.<br/><br/>
</p>
</div>
</div> </div>
<div style="display: none;"> <div style="display: none;">
<PLAINTEXT> <PLAINTEXT>
@ -207,67 +212,68 @@ function ask_questions() { // {{{
<div id="installer"> <div id="installer">
<h1>Shimmie Installer</h1> <h1>Shimmie Installer</h1>
$warn_msg <div class="container">
$err_msg $warn_msg
$err_msg
<h3>Database Install</h3> <h3>Database Install</h3>
<form action="install.php" method="POST"> <form action="install.php" method="POST">
<center> <center>
<table class='form'> <table class='form'>
<tr> <tr>
<th>Type:</th> <th>Type:</th>
<td><select name="database_type" id="database_type" onchange="update_qs();"> <td><select name="database_type" id="database_type" onchange="update_qs();">
$db_m $db_m
$db_p $db_p
$db_s $db_s
</select></td> </select></td>
</tr> </tr>
<tr class="dbconf mysql pgsql"> <tr class="dbconf mysql pgsql">
<th>Host:</th> <th>Host:</th>
<td><input type="text" name="database_host" size="40" value="localhost"></td> <td><input type="text" name="database_host" size="40" value="localhost"></td>
</tr> </tr>
<tr class="dbconf mysql pgsql"> <tr class="dbconf mysql pgsql">
<th>Username:</th> <th>Username:</th>
<td><input type="text" name="database_user" size="40"></td> <td><input type="text" name="database_user" size="40"></td>
</tr> </tr>
<tr class="dbconf mysql pgsql"> <tr class="dbconf mysql pgsql">
<th>Password:</th> <th>Password:</th>
<td><input type="password" name="database_password" size="40"></td> <td><input type="password" name="database_password" size="40"></td>
</tr> </tr>
<tr class="dbconf mysql pgsql sqlite"> <tr class="dbconf mysql pgsql sqlite">
<th>DB&nbsp;Name:</th> <th>DB&nbsp;Name:</th>
<td><input type="text" name="database_name" size="40" value="shimmie"></td> <td><input type="text" name="database_name" size="40" value="shimmie"></td>
</tr> </tr>
<tr><td colspan="2"><input type="submit" value="Go!"></td></tr> <tr><td colspan="2"><input type="submit" value="Go!"></td></tr>
</table> </table>
</center> </center>
<script> <script>
$(function() { $(function() {
update_qs(); update_qs();
}); });
function update_qs() { function update_qs() {
$(".dbconf").hide(); $(".dbconf").hide();
var seldb = $("#database_type").val() || "none"; var seldb = $("#database_type").val() || "none";
$("."+seldb).show(); $("."+seldb).show();
} }
</script> </script>
</form> </form>
<h3>Help</h3> <h3>Help</h3>
<p class="dbconf mysql pgsql">
Please make sure the database you have chosen exists and is empty.<br>
The username provided must have access to create tables within the database.
</p>
<p class="dbconf sqlite">
For SQLite the database name will be a filename on disk, relative to
where shimmie was installed.
</p>
<p class="dbconf none">
Drivers can generally be downloaded with your OS package manager;
for Debian / Ubuntu you want php5-pgsql, php5-mysql, or php5-sqlite.
</p>
<p class="dbconf mysql pgsql">
Please make sure the database you have chosen exists and is empty.<br>
The username provided must have access to create tables within the database.
</p>
<p class="dbconf sqlite">
For SQLite the database name will be a filename on disk, relative to
where shimmie was installed.
</p>
<p class="dbconf none">
Drivers can generally be downloaded with your OS package manager;
for Debian / Ubuntu you want php5-pgsql, php5-mysql, or php5-sqlite.
</p>
</div>
</div> </div>
EOD; EOD;
} // }}} } // }}}
@ -290,10 +296,12 @@ function create_tables() { // {{{
print <<<EOD print <<<EOD
<div id="installer"> <div id="installer">
<h1>Shimmie Installer</h1> <h1>Shimmie Installer</h1>
<h3>Warning: The Database schema is not empty!</h3> <div class="container">
<p>Please ensure that the database you are installing Shimmie with is empty before continuing.</p> <h3>Warning: The Database schema is not empty!</h3>
<p>Once you have emptied the database of any tables, please hit 'refresh' to continue.</p> <p>Please ensure that the database you are installing Shimmie with is empty before continuing.</p>
<br/><br/> <p>Once you have emptied the database of any tables, please hit 'refresh' to continue.</p>
<br/><br/>
</div>
</div> </div>
EOD; EOD;
exit(2); exit(2);
@ -362,28 +370,9 @@ EOD;
$db->commit(); $db->commit();
} }
catch(PDOException $e) { catch(PDOException $e) {
print <<<EOD handle_db_errors(TRUE, "An error occurred while trying to create the database tables necessary for Shimmie.", $e->getMessage(), 3);
<div id="installer"> } catch (Exception $e) {
<h1>Shimmie Installer</h1> handle_db_errors(FALSE, "An unknown error occurred while trying to insert data into the database.", $e->getMessage(), 4);
<h3>Database Error:</h3>
<p>An error occured while trying to create the database tables necessary for Shimmie.</p>
<p>Please check and ensure that the database configuration options are all correct.</p>
<p>{$e->getMessage()}</p>
</div>
EOD;
exit(3);
}
catch (Exception $e) {
print <<<EOD
<div id="installer">
<h1>Shimmie Installer</h1>
<h3>Unknown Error:</h3>
<p>An unknown error occured while trying to create the database tables necessary for Shimmie.</p>
<p>Please check the server log files for more information.</p>
<p>{$e->getMessage()}</p>
</div>
EOD;
exit(4);
} }
} // }}} } // }}}
@ -399,31 +388,11 @@ function insert_defaults() { // {{{
} }
$db->commit(); $db->commit();
} }
catch(PDOException $e) catch(PDOException $e) {
{ handle_db_errors(TRUE, "An error occurred while trying to insert data into the database.", $e->getMessage(), 5);
print <<<EOD
<div id="installer">
<h1>Shimmie Installer</h1>
<h3>Database Error:</h3>
<p>An error occured while trying to insert data into the database.</p>
<p>Please check and ensure that the database configuration options are all correct.</p>
<p>{$e->getMessage()}</p>
</div>
EOD;
exit(5);
} }
catch (Exception $e) catch (Exception $e) {
{ handle_db_errors(FALSE, "An unknown error occurred while trying to insert data into the database.", $e->getMessage(), 6);
print <<<EOD
<div id="installer">
<h1>Shimmie Installer</h1>
<h3>Unknown Error:</h3>
<p>An unknown error occured while trying to insert data into the database.</p>
<p>Please check the server log files for more information.</p>
<p>{$e->getMessage()}</p>
</div>
EOD;
exit(6);
} }
} // }}} } // }}}
@ -498,6 +467,22 @@ EOD;
} }
echo "\n"; echo "\n";
} // }}} } // }}}
function handle_db_errors(/*bool*/ $isPDO, /*str*/ $errorMessage1, /*str*/ $errorMessage2, /*int*/ $exitCode) {
$errorMessage1Extra = ($isPDO ? "Please check and ensure that the database configuration options are all correct." : "Please check the server log files for more information.");
print <<<EOD
<div id="installer">
<h1>Shimmie Installer</h1>
<div class="container">
<h3>Unknown Error:</h3>
<p>{$errorMessage1}</p>
<p>{$errorMessage1Extra}</p>
<p>{$errorMessage2}</p>
</div>
</div>
EOD;
exit($exitCode);
}
?> ?>
</body> </body>
</html> </html>