site-accueil-insa/enigma.php

89 lines
2.8 KiB
PHP
Raw Normal View History

2021-07-28 22:03:33 +02:00
<?php
2022-01-19 22:26:58 +01:00
ob_start(); // Start reading html
2022-06-12 13:49:12 +02:00
include "script/db.php";
2022-06-12 13:49:12 +02:00
if(isset($_POST['send'])) {
if(!empty($_POST['answer']) AND !empty($_POST['team'])) {
$ans = htmlspecialchars($_POST['answer']);
$team = htmlspecialchars($_POST['team']);
$req = $db->query('SELECT answer, point, team FROM enigma WHERE id = 1'); //id = 1 est la ligne correspondant à l'énigme de la plaquette
$reponse = $req -> fetchAll(PDO::FETCH_ASSOC);
if($reponse[0]['team'] == NULL) {
//le "if" ici c'est parce que le 0 => $team = NULL du coup on doit genre faire une conversion relou
if($team == "pkpeach") {
$team = 0;
} elseif($team == "boomario") {
$team = 1;
} else {
header('Refresh: 0');
}
if($ans == $reponse[0]['answer']) {
2022-06-15 22:58:37 +02:00
$req = $db->prepare("INSERT INTO scores(texte, points, team, id_staff) VALUES(?, ?, ?, ?)");
$req->execute(array("enigme de la plaquette", $reponse[0]['point'], $team, 0));
2022-06-12 13:49:12 +02:00
$req = $db->prepare("UPDATE enigma SET team = ? WHERE id = 1");
$req->execute(array($team));
?><script type="text/javascript">alert("Félicitation, vous avez fait gagner <?= $reponse[0]['point'] ?>points à votre équipe");</script><?php
} else {
$error = "Mauvaise réponse, try again !";
}
} else {
$error = "petit malin, la réponse à déjà été trouvé";
}
} else {
$error = "Il faut remplir tout les champs ;)";
}
}
2021-07-28 22:03:33 +02:00
?>
2022-06-12 13:49:12 +02:00
<div class="box-jaune">
<span class="corners corners-top"></span>
<span class="corners corners-bottom"></span>
<div class="title">Enigme de la plaquette</div>
<span class="circles circles-top"></span>
<span class="circles circles-bottom"></span>
</div>
<section>
<?php
$req = $db->query('SELECT team FROM enigma WHERE id = 1'); //id = 1 est la ligne correspondant à l'énigme de la plaquette
$reponse = $req -> fetchAll(PDO::FETCH_ASSOC);
//var_dump($reponse);
if($reponse[0]['team'] == NULL) {
?>
<form method="POST">
2022-06-13 18:41:47 +02:00
<input type="text" placeholder="Réponse à l'énigme" name="answer" class="input">
<select name="team" class="input">
2022-06-12 13:49:12 +02:00
<option value="">Choisissez votre équipe</option>
<option value="pkpeach">PKpeach</option>
<option value="boomario">Boomario</option>
</select>
2022-06-13 18:41:47 +02:00
<input type="submit" name="send" value="Valider votre réponse" class="submit">
2022-06-12 13:49:12 +02:00
</form>
<?php
} else {
if($reponse[0]['team'] == 0) {
echo "La réponse de l'énigme de la plaquette à déja été trouvé par PKpeach !";
} else {
echo "La réponse de l'énigme de la plaquette à déja été trouvé Boomario !";
}
2022-06-12 13:49:12 +02:00
}
if(isset($error)) {
echo $error;
}
?>
</section>
2021-07-28 22:03:33 +02:00
<?php
2022-01-19 22:26:58 +01:00
$infopage = ["", "Enigma", ob_get_clean(), "", "enigma"]; //relativepath, pagetitle, pagecontent, pagescript, pagename | cf structure/template.php ligne 2 à 6
include("structure/template.php");
2021-07-28 22:03:33 +02:00
?>