forked from rebillar/site-accueil-insa
83 lines
No EOL
2.6 KiB
PHP
83 lines
No EOL
2.6 KiB
PHP
<?php
|
|
ob_start(); // Start reading html
|
|
|
|
include "script/db.php";
|
|
include "assets/scripts/globals.php"
|
|
|
|
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 == $TEAM1) {
|
|
$team = 0;
|
|
} elseif($team == $TEAM2) {
|
|
$team = 1;
|
|
} else {
|
|
header('Refresh: 0');
|
|
}
|
|
|
|
|
|
if($ans == $reponse[0]['answer']) {
|
|
$req = $db->prepare("INSERT INTO scores(texte, points, team, id_staff) VALUES(?, ?, ?, ?)");
|
|
$req->execute(array("enigme de la plaquette", $reponse[0]['point'], $team, 0));
|
|
|
|
$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 ;)";
|
|
}
|
|
}
|
|
?>
|
|
|
|
<div class="zone_txt">
|
|
<?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">
|
|
<input type="text" placeholder="Réponse à l'énigme" name="answer" class="input">
|
|
<select name="team" class="input">
|
|
<option value="">Choisissez votre équipe</option>
|
|
<?php
|
|
echo"<option value=".$TEAM1.">".$TEAM1."</option>"
|
|
echo"<option value=".$TEAM2.">".$TEAM2."</option>"
|
|
?>
|
|
</select>
|
|
<input type="submit" name="send" value="Valider votre réponse" class="submit">
|
|
</form>
|
|
<?php
|
|
} else {
|
|
if($reponse[0]['team'] == 0) {
|
|
echo "La réponse de l'énigme de la plaquette à déja été trouvé par ".$TEAM1." !";
|
|
} else {
|
|
echo "La réponse de l'énigme de la plaquette à déja été trouvé ".$TEAM2." !";
|
|
}
|
|
}
|
|
|
|
if(isset($error)) {
|
|
echo $error;
|
|
}
|
|
?>
|
|
</div>
|
|
|
|
<?php
|
|
$infopage = ["", "Enigma", ob_get_clean(), "", "enigma","Enigme de la plaquette"]; //relativepath, pagetitle, pagecontent, pagescript, pagename | cf structure/template.php ligne 2 à 6
|
|
include("structure/template.php");
|
|
?>
|