forked from rebillar/site-accueil-insa
109 lines
No EOL
2.7 KiB
PHP
109 lines
No EOL
2.7 KiB
PHP
<?php
|
|
include "script.php";
|
|
|
|
include "../assets/scripts/globals.php";
|
|
|
|
if($user['perm'] < 3) {
|
|
header('Location: deco.php');
|
|
}
|
|
|
|
$req = $db->query("SELECT * FROM enigma WHERE id = 1");
|
|
$r = $req -> fetchAll(PDO::FETCH_ASSOC);
|
|
|
|
|
|
/*
|
|
Le principe est qu'une seule énigme est émise en même temps,
|
|
il s'agit de la même pour les deux équipes.
|
|
D'où le fait que l'id de l'entrée est hardcode à 1.
|
|
|
|
La série de if est faite pour n'avoir qu'a remplir la/les colonne(s) dans l'interface
|
|
que l'on souhaite modifier dans la BDD.
|
|
*/
|
|
|
|
if(isset($_POST['send'])) {
|
|
|
|
// on vérifie les privilèges de l'utilisateur
|
|
if($user['perm'] >= 3) {
|
|
|
|
|
|
if(isset($_POST['answer']) AND !empty($_POST['answer'])) {
|
|
$ans = htmlspecialchars($_POST['answer']);
|
|
$req = $db->prepare("UPDATE enigma SET answer = ? WHERE id = 1");
|
|
$req->execute(array($ans));
|
|
}
|
|
|
|
if(isset($_POST['points']) AND !empty($_POST['points'])) {
|
|
$point = (int) htmlspecialchars($_POST['points']);
|
|
$req = $db->prepare("UPDATE enigma SET point = ? WHERE id = 1");
|
|
$req->execute(array($point));
|
|
}
|
|
|
|
if(isset($_POST['team']) AND !empty($_POST['team'])) {
|
|
switch (htmlspecialchars($_POST['team'])) {
|
|
|
|
// le cas "t" est lorsque aucune équipe n'a encore trouvé
|
|
case "t":
|
|
$t_int = NULL;
|
|
break;
|
|
case "t0":
|
|
$t_int = 0;
|
|
break;
|
|
case "t1":
|
|
$t_int = 1;
|
|
break;
|
|
}
|
|
$req = $db->prepare("UPDATE enigma SET team = ? WHERE id = 1");
|
|
$req->execute(array($t_int));
|
|
}
|
|
header('Refresh:0');
|
|
}
|
|
}
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
<title>Admin / Enigma</title>
|
|
</head>
|
|
<body>
|
|
<main>
|
|
<form method="POST">
|
|
<input type="texte" name="answer" placeholder="answer" class="input_inline">
|
|
<input type="number" name ="points" placeholder="points" class="input_inline">
|
|
<select name="team" class="input_inline" id="team">
|
|
<option value="t">AUCUNE EQUIPE</option>
|
|
<option value="t0"><?=$TEAM1?></option>
|
|
<option value="t1"><?=$TEAM2?></option>
|
|
</select>
|
|
|
|
<label for="team">Equipe ayant trouvé l'énigme.</label>
|
|
<input type="submit" name="send" value="Mettre à jour" class="submit_inline">
|
|
</form>
|
|
<table class="acces">
|
|
<tr>
|
|
<th width="10%">ID (db)</td>
|
|
<th width="40%">Answer</td>
|
|
<th width="20%">Points</td>
|
|
<th width="10%">Team</td>
|
|
</tr>
|
|
<tr>
|
|
<td><?= $r[0]['id'] ?></td>
|
|
<td><?= $r[0]['answer'] ?></td>
|
|
<td><?= $r[0]['point'] ?></td>
|
|
<td>
|
|
<?php
|
|
switch ($r[0]['team']) {
|
|
case "0":
|
|
echo $TEAM1;
|
|
break;
|
|
case "1":
|
|
echo $TEAM2;
|
|
break;
|
|
}
|
|
?></td>
|
|
</tr>
|
|
</table>
|
|
</main>
|
|
</body>
|
|
</html>
|