2021-11-12 15:23:48 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* index.php
|
|
|
|
*
|
|
|
|
* @author Jay Trees <github.jay@grandel.anonaddy.me>
|
|
|
|
*/
|
|
|
|
|
2021-11-12 16:01:04 +00:00
|
|
|
use wishthis\{Page, Database};
|
2021-11-12 15:23:48 +00:00
|
|
|
|
|
|
|
$page = new page(__FILE__, 'Home');
|
|
|
|
$page->header();
|
|
|
|
|
2021-11-14 08:12:49 +00:00
|
|
|
$step = isset($_POST['step']) ? $_POST['step'] : 1;
|
|
|
|
|
|
|
|
switch ($step) {
|
|
|
|
case 1:
|
|
|
|
?>
|
|
|
|
<main>
|
|
|
|
<section>
|
|
|
|
<h1>Install</h1>
|
2021-11-15 08:45:36 +00:00
|
|
|
<h2>Step <?= $step ?></h2>
|
2021-11-14 08:12:49 +00:00
|
|
|
<p>Welcome to the wishthis installer.</p>
|
|
|
|
<p>wishthis needs a database to function properly. Please enter your credentials.</p>
|
|
|
|
|
2021-11-15 08:45:36 +00:00
|
|
|
<form action="?page=install" method="post">
|
2021-11-14 08:12:49 +00:00
|
|
|
<input type="hidden" name="step" value="<?= $step + 1; ?>" />
|
|
|
|
|
|
|
|
<fieldset>
|
|
|
|
<label>Host</label>
|
|
|
|
<input type="text" name="DATABASE_HOST" placeholder="localhost" value="localhost" />
|
|
|
|
</fieldset>
|
|
|
|
|
|
|
|
<fieldset>
|
|
|
|
<label>Name</label>
|
2021-11-15 08:45:36 +00:00
|
|
|
<input type="text" name="DATABASE_NAME" placeholder="wishthis" value="wishthis" />
|
2021-11-14 08:12:49 +00:00
|
|
|
</fieldset>
|
|
|
|
|
|
|
|
<fieldset>
|
|
|
|
<label>Username</label>
|
|
|
|
<input type="text" name="DATABASE_USER" placeholder="root" value="root" />
|
|
|
|
</fieldset>
|
|
|
|
|
|
|
|
<fieldset>
|
|
|
|
<label>Password</label>
|
|
|
|
<input type="text" name="DATABASE_PASSWORD" />
|
|
|
|
</fieldset>
|
|
|
|
|
2021-11-15 08:45:36 +00:00
|
|
|
<input type="submit" value="Continue" />
|
2021-11-14 08:12:49 +00:00
|
|
|
</form>
|
|
|
|
</section>
|
|
|
|
</main>
|
|
|
|
<?php
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
$configDirectory = 'includes/config';
|
|
|
|
$configPath = $configDirectory . '/config.php';
|
|
|
|
$configSamplePath = $configDirectory . '/config-sample.php';
|
|
|
|
$configContents = file_get_contents($configSamplePath);
|
|
|
|
|
|
|
|
foreach ($_POST as $key => $value) {
|
|
|
|
if ('DATABASE' === substr($key, 0, 8)) {
|
|
|
|
$configContents = preg_replace('/(' . $key . '.+?\').*?(\')/', '$1' . $value . '$2', $configContents);
|
|
|
|
}
|
2021-11-12 16:01:04 +00:00
|
|
|
}
|
2021-11-14 08:12:49 +00:00
|
|
|
|
|
|
|
file_put_contents($configPath, $configContents);
|
2021-11-15 08:45:36 +00:00
|
|
|
?>
|
|
|
|
<main>
|
|
|
|
<section>
|
|
|
|
<h1>Install</h1>
|
|
|
|
<h2>Step <?= $step ?></h2>
|
|
|
|
<p>Klick Continue to test the database connection.</p>
|
2021-11-14 08:12:49 +00:00
|
|
|
|
2021-11-15 08:45:36 +00:00
|
|
|
<form action="?page=install" method="post">
|
|
|
|
<input type="hidden" name="step" value="<?= $step + 1; ?>" />
|
|
|
|
|
|
|
|
<input type="submit" value="Continue" />
|
|
|
|
</form>
|
|
|
|
</section>
|
|
|
|
</main>
|
|
|
|
<?php
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 3:
|
|
|
|
$database->query('CREATE TABLE IF NOT EXISTS `users` (
|
|
|
|
`id` int AUTO_INCREMENT,
|
|
|
|
`email` varchar(64),
|
|
|
|
`password` varchar(128),
|
|
|
|
PRIMARY KEY (id)
|
|
|
|
);');
|
2021-11-14 08:12:49 +00:00
|
|
|
?>
|
|
|
|
<main>
|
|
|
|
<section>
|
|
|
|
<h1>Success</h1>
|
2021-11-15 08:45:36 +00:00
|
|
|
<a href="?page=login">Login</a>
|
2021-11-14 08:12:49 +00:00
|
|
|
</section>
|
|
|
|
</main>
|
|
|
|
<?php
|
|
|
|
break;
|
2021-11-12 15:23:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$page->footer();
|