site-accueil-insa/admin/planning.php

179 lines
5.6 KiB
PHP
Raw Normal View History

2022-06-14 23:36:26 +02:00
<?php
include "script.php";
if($user['perm'] < 1) {
header('Location: deco.php');
}
2022-06-16 22:52:20 +02:00
$req = $db->query('SELECT * FROM planning_insa');
if(isset($_GET['del']) AND !empty($_GET['del']))
{
if($user['perm'] >= 1) {
$del = (int) htmlspecialchars($_GET['del']);
$req = $db->prepare('DELETE FROM planning_insa WHERE id =?');
$req->execute(array($del));
header('Location: planning.php');
}
}
if(isset($_GET['select']) AND !empty($_GET['select']))
{
$select = (int) htmlspecialchars($_GET['select']);
$req = $db->prepare('SELECT * FROM planning_insa WHERE num_planning = ?');
$req->execute(array($select));
}
$req2 = $db->query('SELECT num_planning FROM planning_insa');
$tab = [];
$length = 0;
while($h = $req2->fetch()) {
array_push($tab, $h['num_planning']);
$length++;
}
$tab = array_unique($tab); //supprimer les doublons
if(isset($_POST['send'])) {
if($user['perm'] >= 1) {
2022-06-18 13:21:04 +02:00
if(isset($_POST['day']) AND !empty($_POST['day']) AND isset($_POST['title']) AND !empty($_POST['title']) AND isset($_POST['description']) AND !empty($_POST['description']) AND isset($_POST['color']) AND !empty($_POST['color']) AND isset($_POST['order_start']) AND !empty($_POST['order_start']) AND isset($_POST['length']) AND !empty($_POST['length']) AND isset($_POST['num_planning']) AND !empty($_POST['num_planning']) AND isset($_POST['opacity'])) {
2022-06-16 22:52:20 +02:00
$day = (int) htmlspecialchars($_POST['day']);
$title = htmlspecialchars($_POST['title']);
$desc = htmlspecialchars($_POST['description']);
$color = htmlspecialchars($_POST['color']);
2022-06-17 15:08:08 +02:00
$opacity = (float) htmlspecialchars($_POST['opacity']);
2022-06-16 22:52:20 +02:00
$order_start = (int) htmlspecialchars($_POST['order_start']);
2022-06-19 17:19:07 +02:00
$len = (float) (4.1)*htmlspecialchars($_POST['length']);
2022-06-16 22:52:20 +02:00
$num_planning = (int) htmlspecialchars($_POST['num_planning']);
2022-06-18 12:19:38 +02:00
if (isset($_POST['colorhex']) AND !empty($_POST['colorhex'])) {
$color = htmlspecialchars($_POST['colorhex']);
} else {
2022-06-18 13:21:04 +02:00
if($opacity <= 100 AND $opacity >= 0) {
2022-06-18 13:29:00 +02:00
if($opacity == 0) {
2022-06-18 13:21:04 +02:00
$color = "transparent";
} else {
$color = $color.dechex($opacity*2.55);
}
} else {
$error = "l'opacité doit être en %";
}
2022-06-17 15:08:08 +02:00
}
2022-06-18 13:21:04 +02:00
$req = $db->prepare("INSERT INTO planning_insa(day, title, description, color, order_start, length, num_planning) VALUES(?, ?, ?, ?, ?, ?, ?)");
$req->execute(array($day, $title, $desc, $color, $order_start, $len, $num_planning));
header('refresh:0');
2022-06-17 15:08:08 +02:00
2022-06-16 22:52:20 +02:00
} else {
$error = "Tout les champs doivent être complétés";
}
}
}
2022-06-15 17:35:34 +02:00
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Admin / Planning</title>
</head>
<body>
<main>
2022-06-16 22:52:20 +02:00
<form method="POST">
<select name="day" class="input_inline">
<option value="1">Lundi</option>
<option value="2">Mardi</option>
<option value="3">Mercredi</option>
<option value="4">Jeudi</option>
<option value="5">Vendredi</option>
<option value="6">Samedi</option>
<option value="7">Dimanche</option>
</select>
<input type="text" class="input_inline" name="title" placeholder="titre">
<input type="text" class="input_inline" name="description" placeholder="description">
<input type="color" name="color">
2022-06-18 12:19:38 +02:00
<input type="text" name="colorhex" placeholder="couleur hexa (pas obligatoire)" class="input_inline">
2022-06-17 15:08:08 +02:00
<input type="float" class="input_inline" name="opacity" placeholder="Opacité (%)" value="100">
2022-06-16 22:52:20 +02:00
<input type="number" class="input_inline" name="order_start" placeholder="Ordre d'apparition">
2022-06-18 11:53:13 +02:00
<input type="number" step="0.01" class="input_inline" name="length" placeholder="Taille (en heure)">
2022-06-16 22:52:20 +02:00
<select name="num_planning" class="input_inline">
<option value="1">Planning 1</option>
<option value="2">Planning 2</option>
<option value="3">Planning 3</option>
<option value="4">Planning 4</option>
<option value="5">Planning 5</option>
</select>
<input type="submit" value="Ajouter" name="send" class="submit_inline">
</form><br><br>
2022-06-17 14:35:05 +02:00
2022-06-16 22:52:20 +02:00
<?php
if(isset($error)) {
2022-06-17 14:35:05 +02:00
echo "<font color='red'>".$error."</font>";
2022-06-16 22:52:20 +02:00
}
2022-06-17 14:35:05 +02:00
?>
<a href="planning.php"><input type="submit" value="All" class="submit_inline"></a>
<?php
2022-06-16 22:52:20 +02:00
for($i=0; $i<$length; $i++) {
if(isset($tab[$i])) {
echo '<a href="?select='.$tab[$i].'"><input type="submit" value="Planning '.$tab[$i].'" class="submit_inline"></a>';
}
}
?>
<br><br>
<table class="acces">
<tr>
<th width="5%">ID (db)</th>
<th width="10%">Jour</th>
<th width="20%">Titre</th>
<th width="30%">Description</th>
<th width="5%">Couleur</th>
<th width="5%">Ordre d'apparition</th>
2022-06-17 15:22:24 +02:00
<th width="5%">taille</th>
2022-06-16 22:52:20 +02:00
<th width="10%">Planning </th>
<th width="10%">Action</th>
</tr>
<?php
while($r = $req->fetch()) {
?>
<tr>
<td><?= $r['id'] ?></td>
<td><?php
switch ($r['day']) {
case 1:
echo "Lundi";
break;
case 2:
echo "Mardi";
break;
case 3:
echo "Mercredi";
break;
case 4:
echo "Jeudi";
break;
case 5:
echo "Vendredi";
break;
case 6:
echo "Samedi";
break;
case 7:
echo "Dimanche";
break;
}
?></td>
<td><?= $r['title'] ?></td>
<td><?= $r['description'] ?></td>
2022-06-18 12:19:38 +02:00
<td style="background-color: <?= $r['color'] ?>;"><?= $r['color'] ?></td>
2022-06-16 22:52:20 +02:00
<td><?= $r['order_start'] ?></td>
<td><?= $r['length'] ?>%</td>
<td><?= $r['num_planning'] ?></td>
<td><a href="?del=<?= $r['id'] ?>" class="cross">X</a></td>
</tr>
<?php } ?>
</table>
2022-06-15 17:35:34 +02:00
</main>
</body>
</html>