single start
This commit is contained in:
parent
d699e85c2b
commit
ef50f1aca2
9 changed files with 96 additions and 47 deletions
|
@ -18,7 +18,7 @@ include $_SERVER["DOCUMENT_ROOT"] . "/php/pages.php";
|
|||
<main>
|
||||
<h2>Wybierz typ quizu</h2>
|
||||
<article>
|
||||
<div onclick="window.location.href = '/single/'">
|
||||
<div onclick="window.location.href = '/test/single/'">
|
||||
<h3>Jedno Pytanie</h3>
|
||||
<p>Wyświetl jedno pytanie z bazy quizu oraz natychmiastowo dostań na nie odpowiedź</p>
|
||||
</div>
|
||||
|
|
|
@ -1,8 +0,0 @@
|
|||
//msg
|
||||
export function msg(message) {
|
||||
const output = document.getElementById("info");
|
||||
output.innerHTML = result.msg;
|
||||
output.style.display = "block";
|
||||
}
|
||||
|
||||
//password show
|
|
@ -1,24 +0,0 @@
|
|||
<?php
|
||||
include $_SERVER["DOCUMENT_ROOT"] . "/php/pages.php";
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="pl-PL">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Pytanie - quiz.czem.eu</title>
|
||||
<link rel="stylesheet" href="/styles/main.css">
|
||||
<link rel="stylesheet" href="/styles/quiz.css">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>Pojedyńcze pytanie - quiz PHP</h1>
|
||||
<div class="wrap">
|
||||
<main>
|
||||
|
||||
</main>
|
||||
</div>
|
||||
</body>
|
||||
|
||||
</html>
|
|
@ -30,14 +30,13 @@ include $_SERVER["DOCUMENT_ROOT"] . "/php/pages.php";
|
|||
if (!isset($_SESSION["username"]))
|
||||
echo "<p id='info' style='display: block;'>Nie jesteś zalogowany,<br>więc żaden postęp nie zostanie zapisany!</p><script>const logged = false;</script>";
|
||||
else
|
||||
echo "<p id='info'></p><script>const logged = true;</script>"
|
||||
?>
|
||||
</form>
|
||||
<h4>Jednak nie chcesz zacząć?</h4>
|
||||
<p><a href="/">Powrót do strony głównej</a></p>
|
||||
</main>
|
||||
</div>
|
||||
<!-- <h1></h1> -->
|
||||
</body>
|
||||
echo "<p id='info'></p><script>const logged = true;</script>";
|
||||
?>
|
||||
</form>
|
||||
<h4>Jednak nie chcesz zacząć?</h4>
|
||||
<p><a href="/">Powrót do strony głównej</a></p>
|
||||
</main>
|
||||
</div>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
</html>
|
41
test/single/index.php
Normal file
41
test/single/index.php
Normal file
|
@ -0,0 +1,41 @@
|
|||
<?php
|
||||
include $_SERVER["DOCUMENT_ROOT"] . "/php/pages.php";
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="pl-PL">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Test - quiz.czem.eu</title>
|
||||
<link rel="stylesheet" href="/styles/main.css">
|
||||
<link rel="stylesheet" href="/styles/quiz.css">
|
||||
<script src="single.js"></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>Pojedyńcze pytanie - quiz PHP</h1>
|
||||
<div class="wrap">
|
||||
<main id="content">
|
||||
<form id="startForm">
|
||||
Wyświetlania pytań:
|
||||
<p style="text-align: left;">
|
||||
<input type="radio" name="random" value="true" checked> Losowo<br>
|
||||
<input type="radio" name="random" value="false" id="byQID"> Wg nr pytania w bazie<br>
|
||||
<span id="QIDnum" style="visibility: hidden;"> Nr: <input type="number" name="QID" min="0" max="9999" value="1"></span>
|
||||
</p>
|
||||
<p><input type="submit" value="Znajdź pytanie"></p>
|
||||
<?php
|
||||
if (!isset($_SESSION["username"]))
|
||||
echo "<p id='info' style='display: block;'>Nie jesteś zalogowany,<br>więc żaden postęp nie zostanie zapisany!</p><script>const logged = false;</script>";
|
||||
else
|
||||
echo "<p id='info'></p><script>const logged = true;</script>";
|
||||
?>
|
||||
</form>
|
||||
<h4>Jednak nie chcesz zacząć?</h4>
|
||||
<p><a href="/">Powrót do strony głównej</a></p>
|
||||
</main>
|
||||
</div>
|
||||
</body>
|
||||
|
||||
</html>
|
31
test/single/single.js
Normal file
31
test/single/single.js
Normal file
|
@ -0,0 +1,31 @@
|
|||
document.addEventListener("DOMContentLoaded", function () {
|
||||
async function generateQuestion(formE) {
|
||||
formE.preventDefault();
|
||||
let formData = new FormData(formE.target);
|
||||
formData.append("generateQuestion", "true")
|
||||
const response = await fetch("single.php", {
|
||||
method: "POST",
|
||||
body: formData,
|
||||
credentials: "include",
|
||||
headers: {
|
||||
'X-Requested-With': 'XMLHttpRequest'
|
||||
}
|
||||
});
|
||||
const result = await response.json();
|
||||
output.innerHTML = result.msg;
|
||||
output.style.display = "block";
|
||||
}
|
||||
const output = document.getElementById("info");
|
||||
const mainContent = document.getElementById("content");
|
||||
const randomRadio = document.querySelectorAll("input[name='random']");
|
||||
randomRadio.forEach(function (inputRadio) {
|
||||
inputRadio.addEventListener("change", function (QIDnum) {
|
||||
if (document.getElementById("byQID").checked) {
|
||||
QIDnum.style.visibility = "visible";
|
||||
} else {
|
||||
QIDnum.style.visibility = "hidden";
|
||||
}
|
||||
});
|
||||
});
|
||||
document.getElementById("startForm").addEventListener("submit", generateQuestion);
|
||||
});
|
12
test/single/single.php
Normal file
12
test/single/single.php
Normal file
|
@ -0,0 +1,12 @@
|
|||
<?php
|
||||
include $_SERVER["DOCUMENT_ROOT"] . "/php/scripts.php";
|
||||
if (!checkLogin()) {
|
||||
jsonMsg("Nie jesteś zalogowany");
|
||||
exit();
|
||||
}
|
||||
if ($_SERVER['REQUEST_METHOD'] == "POST" && isset($_POST["generateQuestion"])) {
|
||||
|
||||
} else if ($_SERVER['REQUEST_METHOD'] == "POST" && isset($_POST["checkQuestion"])) {
|
||||
|
||||
} else
|
||||
jsonMsg("Nieprawidłowy request");
|
|
@ -70,9 +70,7 @@ document.addEventListener("DOMContentLoaded", function () {
|
|||
const result = await response.json();
|
||||
if (result.status == "OK") {
|
||||
window.scrollTo({ top: 0, behavior: 'smooth' });
|
||||
console.log(result.answers); // DEBUG
|
||||
Object.entries(result.answers).forEach(function ([key, arr]) {
|
||||
console.log(key, arr);
|
||||
if (!arr.correct && arr.answeredChar != "-") {
|
||||
document.getElementById(`q${key}`).innerHTML = `Nieprawidłowa odpowiedź, odpowiedziałeś ${arr.answeredChar}, prawidłowa odpowiedź to ${arr.correctChar}`;
|
||||
document.getElementById(`q${key}`).style.color = "red";
|
||||
|
|
|
@ -5,8 +5,8 @@ if (!checkLogin()) {
|
|||
exit();
|
||||
}
|
||||
if ($_SERVER['REQUEST_METHOD'] == "POST" && isset($_POST["testStart"])) {
|
||||
if ($_POST["testLength"] > 100 || $_POST["testLength"] < 2)
|
||||
jsonMsg("Test nie może być dłuższy niż 100 pytań ani krótszy niż 2");
|
||||
if ($_POST["testLength"] > 100 || $_POST["testLength"] < 1)
|
||||
jsonMsg("Test nie może być dłuższy niż 100 pytań ani krótszy niż 1");
|
||||
$conn = connectDB();
|
||||
$stmt = $conn->prepare("SELECT QID FROM questions");
|
||||
$stmt->execute();
|
||||
|
|
Loading…
Add table
Reference in a new issue