Adding installer step 1: database connection

This commit is contained in:
ohartl 2016-05-19 02:50:36 +02:00
parent 4c5429d647
commit e054c8627b
4 changed files with 163 additions and 7 deletions

View file

@ -12,7 +12,7 @@ hr {
}
hr.invisible {
border: none;
border-color: transparent;
}
.text-fail {
@ -88,6 +88,13 @@ hr.invisible {
color: rgba(62, 59, 59, 1);
}
#content .sub-header {
font-weight: normal;
font-size: .9em;
color: #999;
padding: 5px 0 0 5px;
}
#content a {
color: blue;
text-decoration: none;
@ -157,6 +164,27 @@ hr.invisible {
width: 70px;
}
#content .form .input input[type="checkbox"],
#content .form .input input[type="radio"] {
border: none;
box-shadow: none;
min-width: inherit;
vertical-align: middle;
margin: 6px 0 8px 5px;
cursor: pointer;
}
#content .form .input input[type="checkbox"]+label,
#content .form .input input[type="radio"]+label {
padding-left: 3px;
margin-right: 15px;
cursor: pointer;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
#content .form .input textarea {
min-height: 150px;
min-width: 400px;

View file

@ -1,5 +1,8 @@
<?php
define('INSTALLER_TYPE_CREATE', 0);
define('INSTALLER_TYPE_MAP', 1);
function installer_reset()
{
global $_SESSION;
@ -28,9 +31,9 @@ function installer_message($setMessage = null)
return $setMessage;
}
function installer_prev($thisStep)
function installer_prev($thisStep, $stepSize = 1)
{
$s = ($thisStep < 0) ? 0 : ($thisStep - 1);
$s = ($thisStep < 0) ? 0 : ($thisStep - $stepSize);
$_SESSION['installer']['lastStep'] = $thisStep;
$_SESSION['installer']['step'] = $s;
@ -38,9 +41,9 @@ function installer_prev($thisStep)
Router::redirect('/?step='.$s);
}
function installer_next($thisStep)
function installer_next($thisStep, $stepSize = 1)
{
$s = ($thisStep > 8) ? 8 : ($thisStep + 1);
$s = ($thisStep > 8) ? 8 : ($thisStep + $stepSize);
$_SESSION['installer']['lastStep'] = $thisStep;
$_SESSION['installer']['step'] = $s;
@ -53,7 +56,7 @@ if(!isset($_SESSION['installer'])){
}
?>
<h1>Installation of WebMUM</h1>
<h1>Installation of WebMUM</h1>
<?php
try{

View file

@ -86,7 +86,7 @@ if(isset($_GET['go']) && $_GET['go'] == 'next'){
<hr>
<?php if(count($requirements) === $numberOfRequirements):?>
<p>Click on Start button to continue.</p>
<p>Click on the Start button to continue.</p>
<a class="button button-primary" href="/?step=<?php echo $thisStep; ?>&go=next">Start</a>
<?php else:?>
<p class="notification notification-fail">Some requirements aren't fulfilled.</p>

125
installer/step1.php Normal file
View file

@ -0,0 +1,125 @@
<?php
$thisStep = 1;
$error = null;
/*-----------------------------------------------------------------------------*/
if(isset($_GET['go'])){
if($_GET['go'] == 'next' && $_SERVER['REQUEST_METHOD'] == 'POST'){
try{
// testing db settings
Database::init($_POST);
// saving information
$_SESSION['installer']['config']['mysql'] = array(
'host' => $_POST['host'],
'user' => $_POST['user'],
'password' => $_POST['password'],
'database' => $_POST['database'],
);
$_SESSION['installer']['type'] = (isset($_POST['install_type']) && $_POST['install_type'] == INSTALLER_TYPE_MAP)
? INSTALLER_TYPE_MAP
: INSTALLER_TYPE_CREATE;
installer_message('Database connection was successfully established.');
installer_next($thisStep, ($_SESSION['installer']['type'] === INSTALLER_TYPE_MAP) ? 2 : 1);
}
catch(InvalidArgumentException $e){
$error = 'Some fields are missing.';
}
catch(Exception $e){
$error = $e->getMessage();
}
}
elseif($_GET['go'] == 'prev'){
// reset
unset($_SESSION['installer']['config']['mysql']);
unset($_SESSION['installer']['type']);
installer_prev($thisStep);
}
}
function getAttr($name, $default = null)
{
global $_SESSION, $_POST;
if(isset($_POST[$name])){
return strip_tags($_POST[$name]);
}
elseif(isset($_SESSION['installer']['config']['mysql'][$name])){
return $_SESSION['installer']['config']['mysql'][$name];
}
elseif($name === 'install_type' && isset($_SESSION['installer']['type'])){
return $_SESSION['installer']['type'];
}
return $default;
}
?>
<?php echo installer_message(); ?>
<h2>Step 1: Database connection.</h2>
<?php if(!empty($error)): ?>
<div class="notification notification-fail"><?php echo $error; ?></div>
<?php endif; ?>
<form class="form" action="/?step=<?php echo $thisStep; ?>&go=next" method="post">
<p>Setup your MySQL database connection.</p>
<div class="input-group">
<label for="host">Database Host</label>
<div class="input">
<input type="text" name="host" value="<?php echo getAttr('host', 'localhost'); ?>" autofocus/>
</div>
</div>
<div class="input-group">
<label for="database">Database Name</label>
<div class="input">
<input type="text" name="database" value="<?php echo getAttr('database'); ?>"/>
</div>
</div>
<div class="input-group">
<label for="user">Database Username</label>
<div class="input">
<input type="text" name="user" value="<?php echo getAttr('user'); ?>"/>
</div>
</div>
<div class="input-group">
<label for="password">Database Password</label>
<div class="input">
<input type="password" name="password" value="<?php echo getAttr('password'); ?>"/>
</div>
</div>
<hr>
<div class="input-group">
<label for="install_type">Installation Type</label>
<div class="input-info">Be sure to select the correct option.</div>
<div class="input">
<input type="radio" name="install_type" id="install_type_0" value="0" <?php echo getAttr('install_type', 0) == 0 ? 'checked' : ''; ?>/>
<label for="install_type_0">Create new database schema</label>
</div>
<div class="input">
<input type="radio" name="install_type" id="install_type_1" value="1" <?php echo getAttr('install_type', 0) == 1 ? 'checked' : ''; ?>/>
<label for="install_type_1">Map existing database schema</label>
</div>
</div>
<hr class="invisible">
<div class="buttons">
<a class="button" href="/?step=<?php echo $thisStep; ?>&go=prev">Back</a>
<button class="button button-primary" type="submit">Continue</button>
</div>
</form>