site-accueil-insa/admin/ville.php

182 lines
6.5 KiB
PHP
Raw Normal View History

2022-07-24 19:54:06 +02:00
<?php
include "script.php";
if($user['perm'] < 1) {
header('Location: deco.php');
}
2022-07-30 23:20:40 +02:00
if(isset($_POST['start1'])) {
$req = $db->prepare("UPDATE ville SET state = ?, time_begin = ? WHERE session = 1");
$req->execute(array(1, time()));
header('Refresh: 0');
}
if(isset($_POST['start2'])) {
$req = $db->prepare("UPDATE ville SET state = ?, time_begin = ? WHERE session = 2");
$req->execute(array(1, time()));
header('Refresh: 0');
}
if(isset($_POST['stop1'])) {
$req = $db->query("UPDATE ville SET state = 2 WHERE session = 1");
header('Refresh: 0');
}
if(isset($_POST['stop2'])) {
$req = $db->query("UPDATE ville SET state = 2 WHERE session = 2");
header('Refresh: 0');
}
if(isset($_POST['reset1'])) {
if(htmlspecialchars($_POST['code']) == "anti-missclick") {
$req = $db->query("UPDATE ville SET state = 0, time_begin = 0 WHERE session = 1");
$req = $db->query("UPDATE ville_equipe SET temps = NULL WHERE id < 17");
header('Refresh: 0');
}
}
if(isset($_POST['reset2'])) {
if(htmlspecialchars($_POST['code']) == "anti-missclick") {
$req = $db->query("UPDATE ville SET state = 0, time_begin = 0 WHERE session = 2");
$req = $db->query("UPDATE ville_equipe SET temps = NULL WHERE id > 16");
header('Refresh: 0');
}
}
2022-07-24 19:54:06 +02:00
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Admin / Com'ville</title>
</head>
<body>
<main>
2022-07-30 23:20:40 +02:00
<?php
if(isset($_GET['session']) AND !empty($_GET['session']))
{
$session = (int) htmlspecialchars($_GET['session']);
if($session == 1) {
?>
<a href="ville.php?session=1" class="href_session_selected">Session matin</a>
<a href="ville.php?session=2" class="href_session">Session aprem</a>
<br>
<?php
$req = $db->query("SELECT state FROM ville WHERE session = 1");
$r = $req -> fetchAll(PDO::FETCH_ASSOC);
if($r[0]['state'] == 0) {
?>
<font color="green">Session non demarré, </font>
<form method="POST">
<input type="submit" name="start1" value="Démarrer la session" class="submit_ville"></form>
</form>
<?php
} elseif($r[0]['state'] == 1) {
?>
<font color="orange">Session en cours, </font>
<form method="POST">
<input type="submit" name="stop1" value="Stopper la session" class="submit_ville"></form>
</form>
<?php
} elseif($r[0]['state'] == 2) {
?>
<font color="red">Session terminé, </font>
<form method="POST">
<input type="text" name="code" placeholder="anti-missclick" class="input_ville">
<input type="submit" name="reset1" value="Reset la session" class="submit_ville"></form>
</form>
<?php
}
?>
<?php
$reqint = $db->query('SELECT id, nom FROM ville_equipe WHERE id < 17');
while($equipe = $reqint->fetch()) {
?>
<?php
}
?>
<?php
} elseif($session == 2) {
?>
<a href="ville.php?session=1" class="href_session">Session matin</a>
<a href="ville.php?session=2" class="href_session_selected">Session aprem</a>
<br>
<?php
$req = $db->query("SELECT state FROM ville WHERE session = 2");
$r = $req -> fetchAll(PDO::FETCH_ASSOC);
if($r[0]['state'] == 0) {
?>
<font color="green">Session non demarré, </font>
<form method="POST">
<input type="submit" name="start2" value="Démarrer la session" class="submit_ville"></form>
</form>
<?php
} elseif($r[0]['state'] == 1) {
?>
<font color="orange">Session en cours, </font>
<form method="POST">
<input type="submit" name="stop2" value="Stopper la session" class="submit_ville"></form>
</form>
<?php
} elseif($r[0]['state'] == 2) {
?>
<font color="red">Session terminé, </font>
<form method="POST">
<input type="text" name="code" placeholder="anti-missclick" class="input_ville">
<input type="submit" name="reset2" value="Reset la session" class="submit_ville"></form>
</form>
<?php
}
?>
<?php
} else {
heade('Location: ../error.php');
}
} else {
?>
<a href="ville.php?session=1" class="href_session">Session matin</a>
<a href="ville.php?session=2" class="href_session">Session aprem</a>
<table class="acces">
2022-07-24 23:12:31 +02:00
<tr>
2022-07-30 23:20:40 +02:00
<th width="10%">ID (db)</td>
<th width="70%">Indice</td>
<th width="10%">reponse</td>
<th width="10%">photos</td>
2022-07-24 23:12:31 +02:00
</tr>
2022-07-30 23:20:40 +02:00
<?php
$req = $db->query('SELECT id, indice, reponse, photo FROM ville_epreuve');
while($epreuve = $req->fetch()) {
?>
<tr>
<td><?= $epreuve['id'] ?></td>
<td><?= $epreuve['indice'] ?></td>
<td><?= $epreuve['reponse'] ?></td>
<td><?php if(isset($epreuve['photo'])) { ?><img src="../assets/img/com_ville/<?= $epreuve['photo'] ?>" style="height: 100px;"><?php } else { echo "<font color='red'>no photos</font>"; }?></td>
</tr>
<?php } ?>
</table>
<?php } ?>
2022-07-24 19:54:06 +02:00
</main>
</body>
</html>