-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathclean.php
48 lines (41 loc) · 1.33 KB
/
clean.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php
use Brus\Session;
use AstroQuiz\ConfigureFile;
use AstroQuiz\DatabaseFile;
require_once __DIR__.'/vendor/autoload.php';
$loader = new Twig_Loader_Filesystem(__DIR__.'/templates');
$twig = new Twig_Environment($loader);
$loadDataError = NULL;
$displayLoginForm = NULL;
$formPassword = $_POST['admin_password'];
try {
$configureFile = new ConfigureFile("astroquiz.cfg");
$password = $configureFile->getPassword();
$databaseFile = new DatabaseFile("database/database");
} catch (AstroQuiz\Exception\WrongConfiguration $err) {
$loadDataError = $err->getMessage();
} catch (Brus\Exception\NoFileException $err) {
$loadDataError = $err->getMessage();
} catch (Brus\Exception\NoFileAccessException $err) {
$loadDataError = $err->getMessage();
}
if (isset($password) && ($password != $formPassword)) {
$loadDataError = NULL;
$displayLoginForm = TRUE;
echo $twig->render('clean.html.twig', array(
'loadDataError' => $loadDataError,
'displayLoginForm' => $displayLoginForm
));
exit;
}
if ($loadDataError == NULL) {
try {
$databaseFile->clean();
} catch (AstroQuiz\FailureCleanDataException $err) {
$loadDataError = $err->getMessage();
}
}
echo $twig->render('clean.html.twig', array(
'loadDataError' => $loadDataError,
'displayLoginForm' => $displayLoginForm
));