Dofus
This commit is contained in:
+51
-4
@@ -3,6 +3,9 @@
|
||||
session_start();
|
||||
// On ajoute la DB
|
||||
require_once('../functions/databaseConnection.php');
|
||||
// On ajoute les logs Discord
|
||||
require_once('../functions/sendLogs.php');
|
||||
require_once('../functions/pdfUpload.php');
|
||||
|
||||
// Si l'utilisateur n'est pas admin il ne peut pas executer le reste du script
|
||||
if (!isset($_SESSION['role']) || $_SESSION['role'] !== 'admin') {
|
||||
@@ -10,6 +13,12 @@ if (!isset($_SESSION['role']) || $_SESSION['role'] !== 'admin') {
|
||||
exit;
|
||||
}
|
||||
|
||||
// Le fichier envoyé dépasse post_max_size : $_POST/$_FILES sont vides, on le détecte
|
||||
// tout de suite (sinon le script redirige silencieusement vers admin.php sans explication)
|
||||
if (postDepasseLimite()) {
|
||||
die(messageDepassementPost());
|
||||
}
|
||||
|
||||
// Si le formulaire à un champ vide
|
||||
if (
|
||||
!isset($_POST['id']) || !is_numeric($_POST['id']) ||
|
||||
@@ -26,29 +35,67 @@ if (
|
||||
//On récupère les données pour les mettres en variables locales
|
||||
$id = (int) $_POST['id'];
|
||||
$title = trim($_POST['title']);
|
||||
$status = trim($_POST['status'] ?? '');
|
||||
$xptype = trim($_POST['xptype']);
|
||||
$tags = trim($_POST['tags'] ?? '');
|
||||
$description = trim($_POST['description']);
|
||||
$duration = trim($_POST['duration']);
|
||||
$imageurl = trim($_POST['imageurl']);
|
||||
$markdown = trim($_POST['markdown'] ?? '');
|
||||
$link_url = trim($_POST['linkurl'] ?? '');
|
||||
|
||||
// Lecture et validation du PDF envoyé (optionnel)
|
||||
$pdfResultat = lireUploadPdf('pdf');
|
||||
if (is_string($pdfResultat)) {
|
||||
echo $pdfResultat;
|
||||
exit;
|
||||
}
|
||||
|
||||
// Le PDF n'est mis à jour que si un nouveau fichier est envoyé OU si la case
|
||||
// "Supprimer ce PDF" est cochée. Sinon on garde le PDF actuel intact.
|
||||
$updatePdf = false;
|
||||
$pdfData = null;
|
||||
$pdfFilename = null;
|
||||
if (is_array($pdfResultat)) {
|
||||
$updatePdf = true;
|
||||
$pdfData = $pdfResultat['data'];
|
||||
$pdfFilename = $pdfResultat['filename'];
|
||||
} elseif (isset($_POST['remove_pdf'])) {
|
||||
$updatePdf = true;
|
||||
}
|
||||
|
||||
try { // On essaie d'executer une requête qui est préparée
|
||||
$stmt = $dbh->prepare('
|
||||
$sql = '
|
||||
UPDATE experiences
|
||||
SET title = :title, xptype = :xptype, tags = :tags, description = :description, duration = :duration, image_url = :image_url
|
||||
WHERE id = :id
|
||||
');
|
||||
SET title = :title, status = :status, xptype = :xptype, tags = :tags, description = :description, duration = :duration, image_url = :image_url, markdown = :markdown, link_url = :link_url';
|
||||
if ($updatePdf) {
|
||||
$sql .= ', pdf_data = :pdf_data, pdf_filename = :pdf_filename';
|
||||
}
|
||||
$sql .= ' WHERE id = :id';
|
||||
|
||||
$stmt = $dbh->prepare($sql);
|
||||
$stmt->bindValue(':title', $title, PDO::PARAM_STR);
|
||||
$stmt->bindValue(':status', $status, PDO::PARAM_STR);
|
||||
$stmt->bindValue(':xptype', $xptype, PDO::PARAM_STR);
|
||||
$stmt->bindValue(':tags', $tags, PDO::PARAM_STR);
|
||||
$stmt->bindValue(':description', $description, PDO::PARAM_STR);
|
||||
$stmt->bindValue(':duration', $duration, PDO::PARAM_STR);
|
||||
$stmt->bindValue(':image_url', $imageurl, PDO::PARAM_STR);
|
||||
$stmt->bindValue(':markdown', $markdown, PDO::PARAM_STR);
|
||||
$stmt->bindValue(':link_url', $link_url, PDO::PARAM_STR);
|
||||
if ($updatePdf) {
|
||||
$stmt->bindValue(':pdf_data', $pdfData, $pdfData === null ? PDO::PARAM_NULL : PDO::PARAM_LOB);
|
||||
$stmt->bindValue(':pdf_filename', $pdfFilename, $pdfFilename === null ? PDO::PARAM_NULL : PDO::PARAM_STR);
|
||||
}
|
||||
$stmt->bindValue(':id', $id, PDO::PARAM_INT);
|
||||
$stmt->execute(); // Sinon on renvoie l'erreur
|
||||
} catch (PDOException $e) {
|
||||
die("Erreur lors de la modification de l experience :" . $e->getMessage());
|
||||
}
|
||||
|
||||
// Log Discord
|
||||
sendLog("Modification de l'expérience : " . $title . " (id " . $id . ")");
|
||||
|
||||
// On renvoie l'utilisateur sur admin.php
|
||||
header('Location: ../pages/admin.php');
|
||||
exit;
|
||||
Reference in New Issue
Block a user