From 0ea79ac2d2d9582d3c2ceb5e5a4b99eb487b8cdc Mon Sep 17 00:00:00 2001 From: Baptiste Date: Sun, 31 Jul 2022 20:41:43 +0200 Subject: [PATCH] modif planning --- admin/planning.php | 94 ++++++++++++++++++++++++++++++++++------------ 1 file changed, 69 insertions(+), 25 deletions(-) diff --git a/admin/planning.php b/admin/planning.php index e4b0400..ca6c478 100644 --- a/admin/planning.php +++ b/admin/planning.php @@ -36,38 +36,81 @@ $tab = array_unique($tab); //supprimer les doublons if(isset($_POST['send'])) { if($user['perm'] >= 2) { - 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'])) { - $day = (int) htmlspecialchars($_POST['day']); - $title = htmlspecialchars($_POST['title']); - $desc = htmlspecialchars($_POST['description']); - $color = htmlspecialchars($_POST['color']); - $opacity = (float) htmlspecialchars($_POST['opacity']); - $order_start = (int) htmlspecialchars($_POST['order_start']); - $len = (float) (4.1)*htmlspecialchars($_POST['length']); - $num_planning = (int) htmlspecialchars($_POST['num_planning']); + if(isset($_POST['id_base']) AND !empty($_POST['id_base'])) { + $id_base = (int) htmlspecialchars($_POST['id_base']); + if(isset($_POST['day']) AND !empty($_POST['day'])) { + $day = (int) htmlspecialchars($_POST['day']); + $req = $db->prepare("UPDATE planning_insa SET day = ? WHERE id = ?"); + $req->execute(array($day, $id_base)); + } + if(isset($_POST['title']) AND !empty($_POST['title'])) { + $title = htmlspecialchars($_POST['title']); + $req = $db->prepare("UPDATE planning_insa SET title = ? WHERE id = ?"); + $req->execute(array($title, $id_base)); + } + if(isset($_POST['description']) AND !empty($_POST['description'])) { + $description = htmlspecialchars($_POST['description']); + $req = $db->prepare("UPDATE planning_insa SET description = ? WHERE id = ?"); + $req->execute(array($description, $id_base)); + } if (isset($_POST['colorhex']) AND !empty($_POST['colorhex'])) { $color = htmlspecialchars($_POST['colorhex']); - } else { - - if($opacity <= 100 AND $opacity >= 0) { - if($opacity == 0) { - $color = "transparent"; - } else { - $color = $color.dechex($opacity*2.55); - } - } else { - $error = "l'opacité doit être en %"; - } + $req = $db->prepare("UPDATE planning_insa SET color = ? WHERE id = ?"); + $req->execute(array($color, $id_base)); + } + if(isset($_POST['order_start']) AND !empty($_POST['order_start'])) { + $order_start = (int) htmlspecialchars($_POST['order_start']); + $req = $db->prepare("UPDATE planning_insa SET order_start = ? WHERE id = ?"); + $req->execute(array($order_start, $id_base)); + } + if(isset($_POST['length']) AND !empty($_POST['length'])) { + $length = (float) (4.1)*htmlspecialchars($_POST['length']); + $req = $db->prepare("UPDATE planning_insa SET length = ? WHERE id = ?"); + $req->execute(array($length, $id_base)); + } + if(isset($_POST['num_planning']) AND !empty($_POST['num_planning'])) { + $num_planning = (int) htmlspecialchars($_POST['num_planning']); + $req = $db->prepare("UPDATE planning_insa SET num_planning = ? WHERE id = ?"); + $req->execute(array($num_planning, $id_base)); } - $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'); - + header('Refresh: 0'); } else { - $error = "Tout les champs doivent être complétés"; + 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'])) { + + $day = (int) htmlspecialchars($_POST['day']); + $title = htmlspecialchars($_POST['title']); + $desc = htmlspecialchars($_POST['description']); + $color = htmlspecialchars($_POST['color']); + $opacity = (float) htmlspecialchars($_POST['opacity']); + $order_start = (int) htmlspecialchars($_POST['order_start']); + $len = (float) (4.1)*htmlspecialchars($_POST['length']); + $num_planning = (int) htmlspecialchars($_POST['num_planning']); + + + if (isset($_POST['colorhex']) AND !empty($_POST['colorhex'])) { + $color = htmlspecialchars($_POST['colorhex']); + } else { + + if($opacity <= 100 AND $opacity >= 0) { + if($opacity == 0) { + $color = "transparent"; + } else { + $color = $color.dechex($opacity*2.55); + } + } else { + $error = "l'opacité doit être en %"; + } + } + + $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'); + } else { + $error = "Tout les champs doivent être complétés"; + } } } } @@ -106,6 +149,7 @@ if(isset($_POST['send'])) { +