-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
94 lines (92 loc) · 4.24 KB
/
index.php
File metadata and controls
94 lines (92 loc) · 4.24 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<?php
include 'serverScripts/sessionManagement.php';
if (!file_exists(DB_FILENAME)) {
$setupKey = generateRandomString();
$db = getDB();
$db->exec("INSERT INTO Settings (\"Key\", \"Value\") VALUES ('setup_key', '$setupKey');");
createSession();
http_response_code(303);
header('Location: /psychologistMode.php?action=changePassword&setup_key='.$setupKey); die();
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'/>
<title>Психологическое тестирование</title>
<link rel="stylesheet" type="text/css" href="/styles/main.css"/>
<script src="clientScripts/jquery.js"></script>
<script>
$(function(){ // Data Integrity Verification
$("#submit").click(function(e){
errors = "";
if ($("#lastname").val().length <= 0) errors += "Не введена фамилия.\n";
if ($("#firstname").val().length <= 0) errors += "Не введено имя.\n";
if ($("#group").val().length <= 0) errors += "Не введена группа.\n";
else if (!(/[А-Яа-я]?[А-Яа-я]?[А-Яа-я]-\d?\d\d/.exec($("#group").val()))) errors += "Неверный формат группы.\n";
if (typeof $("input[name=test]:checked", "#test").val() === typeof undefined) errors += "Не выбран тест.\n";
if (errors !== "") {
e.preventDefault();
$("#error").show();
$("#error").html(errors.replace(/(?:\r\n|\r|\n)/g, '<br>'));
}
});
$("#error").hide();
});
</script>
</head>
<body>
<div class="bg"></div>
<a class="button" href="psychologistMode.php" style="position: fixed">Режим психолога</a>
<form action="/test.php" id="test" method="post" class="centerADiv">
<div class="glass"/>
<table>
<!--tr><td colspan="2"><h1>Платформа психологического тестирования Satori</h1></td></tr-->
<?php
$testingEnabled = false;
try {
$db = getDB();
$testingEnabled = (intval($db->querySingle("select \"Value\" from Settings where \"Key\" = 'testing_enabled'")) == 1);
}
catch (SQLite3Exception $e) {
echo "<b>Ошибка базы данных:</b> ".$e->getMessage();
die();
}
if ($testingEnabled) {
echo " <tr><td colspan=\"2\"><h3>Введите свои данные для начала тестирования.</h3></td></tr>
<tr><td colspan=\"2\" class='error' id='error'></td></tr>
<tr><td><label for=\"lastname\">Фамилия</label></td><td><input class=\"textbox\" type=\"text\" id=\"lastname\" name=\"lastname\"/></td></tr>
<tr><td><label for=\"firstname\">Имя</label></td><td><input class=\"textbox\" type=\"text\" id=\"firstname\" name=\"firstname\"/></td></tr>
<tr><td><label for=\"group\">Группа</label></td><td><input class=\"textbox\" type=\"text\" id=\"group\" name=\"group\"/></td></tr>";
$i = 0;
/*$dir = "./tests";
define("LOADTYPE", "index");
if (is_dir($dir)) {
if ($dh = opendir($dir)) {
while (($file = readdir($dh)) !== false) {
if (!is_dir($file)) {
if (pathinfo($file, PATHINFO_EXTENSION) === 'php') {
$readableName = NULL; include 'tests/'.$file;
if ($readableName != NULL){
echo "<tr><td colspan=\"2\"><input id=\"module".$i."\" type=\"radio\" name=\"testmodule\" value=\"".$file."\"/>";
echo "<label for=\"module".$i++."\">".$readableName."</label></td></tr>";
}
}
}
} echo "<tr><td colspan=\"2\"><input class=\"button\" type=\"submit\" id=\"submit\" value=\"Начать\"/></td></tr>";
closedir($dh);
}
} else echo "<tr><td colspan=\"2\"><b>Ошибка:</b> Папки с тестами не существует.</td></tr>";*/
$testQuery = $db->query("SELECT ID, ReadableName FROM Tests WHERE TestEnabled = 1");
while ($row = $testQuery->fetchArray()) {
echo "<tr><td colspan=\"2\"><input id=\"test".$row[0]."\" type=\"radio\" name=\"test\" value=\"".$row[0]."\"/>";
echo "<label for=\"test".$row[0]."\">".$row[1]."</label></td></tr>";
$i++;
} if ($i != 0) echo "<tr><td colspan=\"2\"><input class=\"button\" type=\"submit\" id=\"submit\" value=\"Начать\"/></td></tr>";
} else echo "<tr><td colspan=\"2\"><h3>Тестирование отключено.</h3></td></tr>";
$db->close();
?>
</table>
</form>
</body>
</html>