2022-07-24 19:54:06 +02:00
|
|
|
<?php
|
|
|
|
include "script.php";
|
|
|
|
|
2022-08-03 14:19:19 +02:00
|
|
|
$refresh_rate = 15; //refresh rate en seconde (en gros on refresh la page toute les 15sec)
|
|
|
|
|
2022-07-24 19:54:06 +02:00
|
|
|
if($user['perm'] < 1) {
|
|
|
|
header('Location: deco.php');
|
|
|
|
}
|
2022-07-30 23:20:40 +02:00
|
|
|
|
|
|
|
|
2023-05-11 21:46:36 +02:00
|
|
|
|
2023-05-10 20:54:11 +02:00
|
|
|
|
|
|
|
// ajout d'une epreuve
|
2023-09-03 12:38:03 +02:00
|
|
|
if(isset($_POST['add_epreuve'])){
|
|
|
|
|
|
|
|
//$upload_state prend plusieurs valeurs :
|
|
|
|
// 1 si tout est valide et l'image n'existe pas déjà
|
|
|
|
// 0 si une verification a invalidé le fichier
|
|
|
|
// 2 si l'image existe déjà mais l'upload est valide, on va alors utiliser le nom pour la bdd
|
2023-09-03 12:50:26 +02:00
|
|
|
$file_name = "";
|
2023-09-03 12:46:19 +02:00
|
|
|
if(true){
|
2023-09-03 12:38:03 +02:00
|
|
|
$EXT_WHITELIST = array("gif","jpg","jpeg","raw","png","svg");
|
2023-09-03 12:45:06 +02:00
|
|
|
echo "passe";
|
2023-09-03 12:38:03 +02:00
|
|
|
/* gestion des uploads d'images indices */
|
|
|
|
$target_dir = "../assets/img/com_ville/";
|
|
|
|
$target_file = $target_dir . basename($_FILES["photo"]["name"]);
|
2023-06-27 15:01:01 +02:00
|
|
|
$upload_state = 1;
|
2023-09-03 12:38:03 +02:00
|
|
|
$imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));
|
|
|
|
// Check if image file is a actual image or fake image
|
|
|
|
$check = $_FILES["photo"]["size"] > pow(2,2);;
|
|
|
|
if($check !== false) {
|
|
|
|
$upload_state = 1;
|
|
|
|
} else {
|
|
|
|
$upload_state = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (file_exists($target_file)) {
|
|
|
|
$upload_state = 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
// limite de taille
|
|
|
|
if ($_FILES["photo"]["size"] > pow(2,40)) {
|
|
|
|
$upload_state = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// check le type de fichier
|
|
|
|
if (!in_array($imageFileType,$EXT_WHITELIST)){
|
|
|
|
$upload_state = 0;
|
|
|
|
}
|
2023-09-03 12:34:52 +02:00
|
|
|
|
2023-09-03 12:38:03 +02:00
|
|
|
|
|
|
|
$file_name = "";
|
|
|
|
switch($upload_state){
|
|
|
|
case 1:
|
|
|
|
|
|
|
|
move_uploaded_file($_FILES["photo"]["tmp_name"],$target_file);
|
|
|
|
$file_name = htmlspecialchars($_FILES["photo"]["name"]);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
move_uploaded_file($_FILES["photo"]["tmp_name"],$target_file);
|
|
|
|
$file_name = htmlspecialchars($_FILES["photo"]["name"]);
|
|
|
|
break;
|
|
|
|
case 0:
|
|
|
|
?> <script>
|
|
|
|
alert("L'image envoyée n'a pas passées tout les tests de vérifications.");
|
|
|
|
</script>
|
|
|
|
<?php
|
|
|
|
break;
|
|
|
|
}
|
2023-06-27 15:01:01 +02:00
|
|
|
}
|
2023-09-03 12:38:03 +02:00
|
|
|
|
2023-06-27 15:01:01 +02:00
|
|
|
|
2023-07-02 20:16:34 +02:00
|
|
|
$_POST['est_finale'] = $_POST['est_finale'] == 'on' ? 1 : 0;
|
2023-06-01 17:51:06 +02:00
|
|
|
|
|
|
|
$req = $db->prepare("INSERT INTO ville_epreuve(indice,reponse,photo,id_equipe,est_finale,ordre,est_trouvee) VALUES(?,?,?,?,?,?,?)");
|
|
|
|
$req->execute(array(htmlspecialchars($_POST['indice']),
|
|
|
|
htmlspecialchars($_POST['reponse']),
|
2023-06-27 15:01:01 +02:00
|
|
|
$file_name,
|
2023-06-01 17:51:06 +02:00
|
|
|
(int)htmlspecialchars($_POST['id_equipe']),
|
2023-07-02 20:11:42 +02:00
|
|
|
(int)htmlspecialchars($_POST['est_finale']),
|
2023-06-01 17:51:06 +02:00
|
|
|
(int)htmlspecialchars($_POST['ordre']),
|
2023-07-02 20:11:42 +02:00
|
|
|
0
|
2023-06-01 17:51:06 +02:00
|
|
|
|
|
|
|
));
|
2023-06-27 15:01:01 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
2023-09-03 12:38:03 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2023-05-10 20:54:11 +02:00
|
|
|
//ajout d'une equipe
|
|
|
|
if(isset($_POST['add_equipe'])){
|
2023-06-01 17:51:06 +02:00
|
|
|
$req = $db->prepare("INSERT INTO ville_equipe(nom,temps) VALUES(?,?)");
|
|
|
|
$req->execute(array(htmlspecialchars($_POST['nom']),NULL));
|
2023-05-10 20:54:11 +02:00
|
|
|
}
|
|
|
|
|
2023-06-04 21:22:36 +02:00
|
|
|
// suppression d'une équipe
|
|
|
|
if(isset($_POST['del_equipe'])){
|
|
|
|
$req = $db->prepare("DELETE FROM ville_equipe WHERE id=?");
|
|
|
|
$req->execute(array(htmlspecialchars((int)$_POST['id_ekip'])));
|
|
|
|
}
|
|
|
|
|
|
|
|
//suppression d'une épreuve
|
|
|
|
|
|
|
|
if(isset($_POST['del_epreuve'])){
|
|
|
|
$req = $db->prepare("DELETE FROM ville_epreuve WHERE id=?");
|
|
|
|
$req->execute(array((int)$_POST['id_epreuve']));
|
|
|
|
}
|
2023-05-10 20:54:11 +02:00
|
|
|
|
2022-07-30 23:20:40 +02:00
|
|
|
|
2023-06-27 15:01:01 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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>
|
2022-08-03 14:19:19 +02:00
|
|
|
<link rel="stylesheet" type="text/css" href="com_ville.css" />
|
2022-07-24 19:54:06 +02:00
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<main>
|
2023-05-04 14:50:55 +02:00
|
|
|
|
2023-06-27 15:01:01 +02:00
|
|
|
<form method="POST" enctype="multipart/form-data">
|
2023-05-11 21:46:36 +02:00
|
|
|
<input type="text" name="indice" placeholder="indice" class="input_inline">
|
|
|
|
<input type="text" name="reponse" placeholder="réponse" class="input_inline">
|
2023-06-27 15:01:01 +02:00
|
|
|
<input type="file" name="photo" placeholder="image.png" id="photo" class="input_inline">
|
2023-06-01 17:51:06 +02:00
|
|
|
<input type="number" name="id_equipe" id="id_equipe" class="input_inline" value="<?= isset($_GET["ekip"]) ? (int)$_GET["ekip"]:1;?>">
|
|
|
|
<label for="id_equipe">id de l'équipe</label>
|
2023-06-27 15:01:01 +02:00
|
|
|
<br>
|
2023-06-01 17:51:06 +02:00
|
|
|
<input type="radio" name="est_finale" id="est_finale" class="input_inline">
|
|
|
|
<label for="est_finale">ultime épreuve</label>
|
|
|
|
<input type="number" name="ordre" id="ordre" class="input_inline">
|
|
|
|
<label for="ordre">ordre de l'épreuve</label>
|
2023-05-11 21:46:36 +02:00
|
|
|
<input type="submit" name="add_epreuve" value="Ajouter l'épreuve" class="submit_inline">
|
|
|
|
</form>
|
|
|
|
|
2023-06-01 17:51:06 +02:00
|
|
|
<hr>
|
2023-05-11 21:46:36 +02:00
|
|
|
<form method="POST">
|
|
|
|
<input type="text" name="nom" placeholder="nom de l'équipe" class="input_inline">
|
|
|
|
<input type="submit" name="add_equipe" value="Ajouter l'équipe" class="submit_inline">
|
|
|
|
</form>
|
2023-05-04 14:50:55 +02:00
|
|
|
|
2023-06-01 17:51:06 +02:00
|
|
|
<h4>Equipes déjà enregistrées :</h4>
|
|
|
|
<table class="acces">
|
2022-07-30 23:20:40 +02:00
|
|
|
<?php
|
2023-06-01 17:51:06 +02:00
|
|
|
$req = $db->query('SELECT * FROM ville_equipe');
|
|
|
|
while($equipe = $req->fetch()) {
|
|
|
|
|
|
|
|
echo "<th><a href=\"?ekip=".$equipe['id']."\">".htmlspecialchars($equipe['nom'])."(".$equipe['id'].")"."<a></th><wbr>";
|
2022-07-30 23:20:40 +02:00
|
|
|
}
|
2023-06-01 17:51:06 +02:00
|
|
|
|
2022-07-30 23:20:40 +02:00
|
|
|
?>
|
2023-06-01 17:51:06 +02:00
|
|
|
</table>
|
|
|
|
<hr>
|
|
|
|
<?php
|
|
|
|
$ekip = isset($_GET["ekip"]) ? (int)$_GET["ekip"]:1;
|
|
|
|
$req = $db->prepare('SELECT * FROM ville_epreuve WHERE id_equipe=?');
|
|
|
|
$req->execute(array($ekip));
|
|
|
|
?>
|
|
|
|
<form method="GET">
|
|
|
|
<input type="number" name="ekip" id="ekip" placeholder="numéro de l'équipe" class="input_inline">
|
|
|
|
<label for="ekip">Numéro de l'équipe dont tu veux voir le tableau</label>
|
|
|
|
<input type="submit" name="aff_equipe" value="Afficher le tableau de l'équipe" class="submit_inline">
|
|
|
|
</form>
|
2022-07-30 23:20:40 +02:00
|
|
|
|
|
|
|
<table class="acces">
|
2022-07-24 23:12:31 +02:00
|
|
|
<tr>
|
2023-06-01 17:51:06 +02:00
|
|
|
<th width="10%">ID (db)</th>
|
|
|
|
<th width="70%">Indice</th>
|
2023-06-04 21:22:36 +02:00
|
|
|
<th width="10%">Reponse</th>
|
|
|
|
<th width="10%">Photos</th>
|
|
|
|
<th width="10%">Id_equipe</th>
|
|
|
|
<th width="10%">Est finale</th>
|
|
|
|
<th width="10%">Ordre</th>
|
|
|
|
<th width="10%">Est trouvée</th>
|
|
|
|
<th width="10%">Action</th>
|
|
|
|
|
2022-07-24 23:12:31 +02:00
|
|
|
</tr>
|
2022-07-30 23:20:40 +02:00
|
|
|
<?php
|
2023-06-01 17:51:06 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
2022-07-30 23:20:40 +02:00
|
|
|
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>
|
2023-06-01 17:51:06 +02:00
|
|
|
<td><?= $epreuve['id_equipe'] ?></td>
|
|
|
|
<td><?= $epreuve['est_finale'] == 0 ? "non":"oui" ?></td>
|
|
|
|
<td><?= $epreuve['ordre'] ?></td>
|
|
|
|
<td><?= $epreuve['est_trouvee'] == 0 ? "non":"oui" ?></td>
|
2023-06-04 21:22:36 +02:00
|
|
|
<td>
|
|
|
|
<form method="POST">
|
|
|
|
<input type="text" name="del_epreuve" value="del_epreuve" hidden>
|
|
|
|
<input type="number" value="<?=$epreuve['id']?>" name="id_epreuve" hidden>
|
|
|
|
<input type="submit" value="supprimer">
|
|
|
|
</form>
|
|
|
|
</td>
|
|
|
|
|
2022-07-30 23:20:40 +02:00
|
|
|
</tr>
|
|
|
|
<?php } ?>
|
|
|
|
</table>
|
|
|
|
|
2023-06-01 17:51:06 +02:00
|
|
|
<?php ?>
|
2022-07-24 19:54:06 +02:00
|
|
|
</main>
|
|
|
|
</body>
|
|
|
|
</html>
|