Show sourcecode
The following files exists in this folder. Click to view.
ramverket/exercises/fragetavling/
ovn_fragetavling3.php
ovn_fragetavling5.php
ovn_fragetavling5.php
129 lines UTF-8 Windows (CRLF)
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
<?php
// Title: Frågetävling 5
error_reporting(-1); // Report all type of errors
ini_set('display_errors', 1); // Display all errors
ini_set('output_buffering', 0); // Do not buffer outputs, write directly
$current_phase = 1;
$username = '';
$answers = [];
$cheat_sheet = ['a', 'b', 'c'];
$password = 'jail';
?>
<!DOCTYPE html>
<html lang="sv">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Frågetävling 5</title>
</head>
<body>
<?php
if (isset($_POST['password']) && $_POST['password'] !== $password && $current_phase == 1) {
echo 'Fel lösenord! Åtkomst nekad!';
return;
}
if (isset($_POST['current_phase'])) {
$current_phase = number_format($_POST['current_phase']);
} else {
$current_phase = 1;
}
if (isset($_POST['answers']) && $_POST['answers'] !== '') {
$answers = explode(',', $_POST['answers']);
} else {
$answers = [];
}
if (isset($_POST['name'])) {
$username = $_POST['name'];
} else {
$username = '';
}
if (isset($_POST['q1'])) {
array_push($answers, $_POST['q1']);
}
if (isset($_POST['q2'])) {
array_push($answers, $_POST['q2']);
}
if (isset($_POST['q3'])) {
array_push($answers, $_POST['q3']);
}
?>
<form action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']);?>" method="POST">
<?php if ($current_phase == 1) : ?>
<input type="hidden" name="current_phase" value="2">
<input type="hidden" name="answers" value="<?php echo htmlspecialchars(implode(',', $answers)); ?>">
<input type="text" name="name" required placeholder="Ditt namn">
<input type="password" name="password" required placeholder="Lösenord">
<button type="submit" value="2">Nästa</button>
<?php endif; ?>
<?php if ($current_phase == 2) : ?>
<input type="hidden" name="current_phase" value="3">
<input type="hidden" name="answers" value="<?php echo htmlspecialchars(implode(',', $answers)); ?>">
<input type="hidden" name="name" value="<?php echo htmlspecialchars($username); ?>">
<p id="q1">Vilket språk används främst för att strukturera innehåll på webbsidor?</p>
<input type="radio" name="q1" value="a" required id="q1a"><label for="q1a">HTML</label>
<input type="radio" name="q1" value="b" required id="q1b"><label for="q1b">CSS</label>
<input type="radio" name="q1" value="c" required id="q1c"><label for="q1c">JavaScript</label>
<input type="radio" name="q1" value="d" required id="q1d"><label for="q1d">PHP</label>
<button type="submit" value="3">Nästa</button>
<?php endif; ?>
<?php if ($current_phase == 3) : ?>
<input type="hidden" name="current_phase" value="4">
<input type="hidden" name="answers" value="<?php echo htmlspecialchars(implode(',', $answers)); ?>">
<input type="hidden" name="name" value="<?php echo htmlspecialchars($username); ?>">
<p id="q2">Vad används CSS huvudsakligen till?</p>
<input type="radio" name="q2" value="a" id="q2a"><label for="q2a">Att skapa serverlogik</label>
<input type="radio" name="q2" value="b" id="q2b"><label for="q2b">Att styra layout och design</label>
<input type="radio" name="q2" value="c" id="q2c"><label for="q2c">Att lagra data i databaser</label>
<input type="radio" name="q2" value="d" id="q2d"><label for="q2d">Att strukturera textinnehåll</label>
<button type="submit" value="4">Nästa</button>
<?php endif; ?>
<?php if ($current_phase == 4) : ?>
<input type="hidden" name="current_phase" value="5">
<input type="hidden" name="answers" value="<?php echo htmlspecialchars(implode(',', $answers)); ?>">
<input type="hidden" name="name" value="<?php echo htmlspecialchars($username); ?>">
<p id="q3">Vilken av följande tekniker är ett JavaScript-baserat frontend-ramverk?</p>
<input type="radio" name="q3" value="a" id="q3a"><label for="q3a">Laravel</label>
<input type="radio" name="q3" value="b" id="q3b"><label for="q3b">Django</label>
<input type="radio" name="q3" value="c" id="q3c"><label for="q3c">React</label>
<input type="radio" name="q3" value="d" id="q3d"><label for="q3d">Flask</label>
<button type="submit" value="Skicka">Skicka</button>
<?php endif; ?>
<?php if ($current_phase == 5) : ?>
<?php
$total = count($cheat_sheet);
$correct = 0;
foreach ($answers as $i => $ans) {
if ($ans === $cheat_sheet[$i]) {
$correct++;
}
}
?>
<h1>Tack för dina svar, <?php echo htmlspecialchars($username); ?>!</h1>
<p>Ditt resultat: <?php echo htmlspecialchars("$correct/$total"); ?></p>
<hr>
<p id="q1">Vilket språk används främst för att strukturera innehåll på webbsidor?</p>
<input type="radio" name="q1" value="a" required id="q1a" <?php if ($answers[0] === "a") echo "checked"; ?> disabled><label for="q1a" <?php if ($cheat_sheet[0] === "a") echo "style = \"color: green;\""; else if ($answers[0] === "a") echo "style = \"color: red;\""; ?> >HTML</label>
<input type="radio" name="q1" value="b" required id="q1b" <?php if ($answers[0] === "b") echo "checked"; ?> disabled><label for="q1b" <?php if ($cheat_sheet[0] === "b") echo "style = \"color: green;\""; else if ($answers[0] === "b") echo "style = \"color: red;\""; ?> >CSS</label>
<input type="radio" name="q1" value="c" required id="q1c" <?php if ($answers[0] === "c") echo "checked"; ?> disabled><label for="q1c" <?php if ($cheat_sheet[0] === "c") echo "style = \"color: green;\""; else if ($answers[0] === "c") echo "style = \"color: red;\""; ?> >JavaScript</label>
<input type="radio" name="q1" value="d" required id="q1d" <?php if ($answers[0] === "d") echo "checked"; ?> disabled><label for="q1d" <?php if ($cheat_sheet[0] === "d") echo "style = \"color: green;\""; else if ($answers[0] === "d") echo "style = \"color: red;\""; ?> >PHP</label>
<p id="q2">Vad används CSS huvudsakligen till?</p>
<input type="radio" name="q2" value="a" id="q2a" <?php if ($answers[1] === "a") echo "checked"; ?> disabled><label for="q2a" <?php if ($cheat_sheet[1] === "a") echo "style = \"color: green;\""; else if ($answers[1] === "a") echo "style = \"color: red;\""; ?> >Att skapa serverlogik</label>
<input type="radio" name="q2" value="b" id="q2b" <?php if ($answers[1] === "b") echo "checked"; ?> disabled><label for="q2b" <?php if ($cheat_sheet[1] === "b") echo "style = \"color: green;\""; else if ($answers[1] === "b") echo "style = \"color: red;\""; ?> >Att styra layout och design</label>
<input type="radio" name="q2" value="c" id="q2c" <?php if ($answers[1] === "c") echo "checked"; ?> disabled><label for="q2c" <?php if ($cheat_sheet[1] === "c") echo "style = \"color: green;\""; else if ($answers[1] === "c") echo "style = \"color: red;\""; ?> >Att lagra data i databaser</label>
<input type="radio" name="q2" value="d" id="q2d" <?php if ($answers[1] === "d") echo "checked"; ?> disabled><label for="q2d" <?php if ($cheat_sheet[1] === "d") echo "style = \"color: green;\""; else if ($answers[1] === "d") echo "style = \"color: red;\""; ?> >Att strukturera textinnehåll</label>
<p id="q3">Vilken av följande tekniker är ett JavaScript-baserat frontend-ramverk?</p>
<input type="radio" name="q3" value="a" id="q3a" <?php if ($answers[2] === "a") echo "checked"; ?> disabled><label for="q3a" <?php if ($cheat_sheet[2] === "a") echo "style = \"color: green;\""; else if ($answers[2] === "a") echo "style = \"color: red;\""; ?> >Laravel</label>
<input type="radio" name="q3" value="b" id="q3b" <?php if ($answers[2] === "b") echo "checked"; ?> disabled><label for="q3b" <?php if ($cheat_sheet[2] === "b") echo "style = \"color: green;\""; else if ($answers[2] === "b") echo "style = \"color: red;\""; ?> >Django</label>
<input type="radio" name="q3" value="c" id="q3c" <?php if ($answers[2] === "c") echo "checked"; ?> disabled><label for="q3c" <?php if ($cheat_sheet[2] === "c") echo "style = \"color: green;\""; else if ($answers[2] === "c") echo "style = \"color: red;\""; ?> >React</label>
<input type="radio" name="q3" value="d" id="q3d" <?php if ($answers[2] === "d") echo "checked"; ?> disabled><label for="q3d" <?php if ($cheat_sheet[2] === "d") echo "style = \"color: green;\""; else if ($answers[2] === "d") echo "style = \"color: red;\""; ?> >Flask</label>
<?php mail("pavvor23@varmdogymnasium.se", htmlspecialchars("Resultat för spelaren (uppg 5) - $username"), htmlspecialchars("$correct/$total")); ?>
<?php endif; ?>
</form>
</body>
</html>