diff --git a/Assets/functions.php b/Assets/functions.php index 0c67ed8..6b4934c 100644 --- a/Assets/functions.php +++ b/Assets/functions.php @@ -300,4 +300,13 @@ function updateActuContent($bdd, $actuId, $content){ mysqli_stmt_close($stmt); return $success; +} + +function createEvent($bdd, $titre, $date, $site){ + + $sql = "INSERT INTO evenements (date, titre, couverture, site_id) VALUES (?, ?, '', ?)"; + $req = $bdd->prepare($sql); + $req->bind_param("ssi", $date, $titre, $site); + $req->execute(); + return $bdd->insert_id; } \ No newline at end of file diff --git a/admin/modifyEvent.php b/admin/modifyEvent.php index b3f4991..19d3194 100644 --- a/admin/modifyEvent.php +++ b/admin/modifyEvent.php @@ -21,7 +21,7 @@ $eventId = $_GET['id'] ?? null; $titre = getEventName($bdd, $eventId) ?? ''; $couverture = getEventBigImage($bdd, $eventId) ?? ''; -if ($_SERVER['REQUEST_METHOD'] === 'POST' && (!$_POST['new'] ?? '')) { +if ($_SERVER['REQUEST_METHOD'] === 'POST' && empty($_POST['new'])) { if (!empty($_POST['title'])) { updateEventTitle($bdd, $eventId, trim($_POST['title'])); } @@ -55,9 +55,33 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && (!$_POST['new'] ?? '')) { header("Location: ?id=" . $eventId); exit; } -if($_POST['new'] ?? ''){ - // - die('test'); +if (!empty($_POST['new'])) { + + $uploadDir = "../Photos/INTRANET/"; + $fileTmpPath = $_FILES["couverture"]["tmp_name"]; + $fileSize = $_FILES["couverture"]["size"]; + $site = $_SESSION['site']; + + $finfo = finfo_open(FILEINFO_MIME_TYPE); + $mime = finfo_file($finfo, $fileTmpPath); + finfo_close($finfo); + + $allowedTypes = ['image/jpeg', 'image/png', 'image/gif']; + if (in_array($mime, $allowedTypes) && $fileSize <= 5 * 1024 * 1024) { + $extension = pathinfo($_FILES["couverture"]["name"], PATHINFO_EXTENSION); + $eventId = createEvent($bdd, $_POST['title'], $_POST['date'], $site); + + $newFileName = "event_" . $eventId . "_" . time() . "." . $extension; + + $destination = $uploadDir . $newFileName; + + if (move_uploaded_file($fileTmpPath, $destination)) { + updateEventImage($bdd, $eventId, $newFileName); + } + } + + header("Location: ?id=" . $eventId); + exit; } ?> @@ -160,9 +184,13 @@ if($_POST['new'] ?? ''){ class="form-control" accept="image/*"> - - - +
+ + +
+ + +