prepare("SELECT * FROM praticien WHERE id = ?"); $stmt->execute([$id]); $praticien = $stmt->fetch(); if (!$praticien) { die(htmlspecialchars($translations['praticien_introuvable'] ?? 'Introuvable.')); } // ==== Traitement POST avant tout output ==== if ($_SERVER['REQUEST_METHOD'] === 'POST') { $titre = trim($_POST['titre'] ?? ''); $nom = trim($_POST['nom'] ?? ''); $prenom = trim($_POST['prenom'] ?? ''); $telephone = trim($_POST['telephone'] ?? ''); $specialite = trim($_POST['specialite'] ?? ''); $adresse = trim($_POST['adresse'] ?? ''); $ville = trim($_POST['ville'] ?? ''); $code_postal = trim($_POST['code_postal'] ?? ''); $presentation = trim($_POST['presentation'] ?? ''); $duree_rdv = (int)($_POST['duree_rdv'] ?? 60); $disponibilite = trim($_POST['disponibilite'] ?? ''); $photo = $praticien['photo'] ?? null; // --- BLOC UPLOAD SÉCURISÉ --- if (!empty($_FILES['photo']['tmp_name'])) { $file = $_FILES['photo']; $maxSize = 5 * 1024 * 1024; // 5 Mo // 1. Vérification de la taille if ($file['size'] > $maxSize) { die("Erreur : Le fichier est trop volumineux (max 5 Mo)."); } // 2. Vérification du type réel (MIME) pour bloquer les faux fichiers $finfo = new finfo(FILEINFO_MIME_TYPE); $mimeType = $finfo->file($file['tmp_name']); $allowedMimeTypes = ['image/jpeg', 'image/png', 'image/gif', 'image/webp']; if (!in_array($mimeType, $allowedMimeTypes)) { die("Erreur : Type de fichier non autorisé (Seuls JPG, PNG, GIF et WEBP sont acceptés)."); } // 3. Préparation du nom et du chemin $nom_nettoye = strtolower(preg_replace('/[^A-Za-z0-9]/', '', $nom)); $prenom_nettoye = strtolower(preg_replace('/[^A-Za-z0-9]/', '', $prenom)); $nouveau_nom_fichier = $nom_nettoye . '_' . $prenom_nettoye . '_' . time() . '.png'; $chemin_destination = __DIR__ . '/../uploads/' . $nouveau_nom_fichier; // 4. Traitement de l'image (Conversion & Redimensionnement) $image_source = @imagecreatefromstring(file_get_contents($file['tmp_name'])); if ($image_source) { list($largeur_orig, $hauteur_orig) = getimagesize($file['tmp_name']); $largeur_max = 800; if ($largeur_orig > $largeur_max) { $ratio = $largeur_max / $largeur_orig; $nouvelle_largeur = $largeur_max; $nouvelle_hauteur = (int)($hauteur_orig * $ratio); } else { $nouvelle_largeur = $largeur_orig; $nouvelle_hauteur = $hauteur_orig; } $image_dest = imagecreatetruecolor($nouvelle_largeur, $nouvelle_hauteur); imagealphablending($image_dest, false); imagesavealpha($image_dest, true); imagecopyresampled($image_dest, $image_source, 0, 0, 0, 0, $nouvelle_largeur, $nouvelle_hauteur, $largeur_orig, $hauteur_orig); // Sauvegarde effective if (imagepng($image_dest, $chemin_destination, 7)) { // Suppression de l'ancienne photo si elle existe if (!empty($praticien['photo'])) { $ancien_chemin = __DIR__ . '/../uploads/' . $praticien['photo']; if (file_exists($ancien_chemin)) { unlink($ancien_chemin); } } $photo = $nouveau_nom_fichier; } imagedestroy($image_source); imagedestroy($image_dest); } else { die("Erreur : Le fichier image semble corrompu."); } } // SIRET - normalisation + vérifs $siret = preg_replace('/\D/', '', $_POST['siret'] ?? ''); if (strlen($siret) !== 14) { die(htmlspecialchars($translations['siret_format_invalide'] ?? 'SIRET invalide (14 chiffres).')); } // Luhn $luhnOk = (function($num){ $sum=0; $alt=false; for ($i=strlen($num)-1; $i>=0; $i--){ $n=(int)$num[$i]; if($alt){ $n*=2; if($n>9)$n-=9; } $sum+=$n; $alt=!$alt; } return $sum%10===0; })($siret); if (!$luhnOk) { die(htmlspecialchars($translations['siret_format_invalide'] ?? 'SIRET invalide (Luhn).')); } // Unicité SIRET (exclure l'utilisateur courant) $chk = $pdo->prepare("SELECT id FROM praticien WHERE siret = :s AND id <> :id LIMIT 1"); $chk->execute(['s' => $siret, 'id' => $id]); if ($chk->fetch()) { die(htmlspecialchars($translations['err_siret_deja_utilise'] ?? 'Ce SIRET est déjà utilisé.')); } // Mise à jour $stmt = $pdo->prepare(" UPDATE praticien SET titre = :titre, nom = :nom, prenom = :prenom, telephone = :telephone, specialite = :specialite, adresse = :adresse, ville = :ville, code_postal = :code_postal, presentation = :presentation, photo = :photo, disponibilite = :disponibilite, duree_rdv = :duree_rdv, siret = :siret WHERE id = :id "); $stmt->execute([ 'titre' => $titre, 'nom' => $nom, 'prenom' => $prenom, 'telephone' => $telephone, 'specialite' => $specialite, 'adresse' => $adresse, 'ville' => $ville, 'code_postal' => $code_postal, 'presentation' => $presentation, 'photo' => $photo, 'disponibilite' => $disponibilite, 'duree_rdv' => $duree_rdv, 'siret' => $siret, 'id' => $id, ]); // Redirection ABSOLUE (ou "informations.php" si même dossier) header('Location: /public/praticien/informations.php'); exit; } $PAGE_TITLE = $translations['modifier_infos_title']; $HEAD_EXTRA = << .message-erreur { color: red; font-size: 0.9em; display: none; margin-bottom: 10px; } HTML; // ==== À partir d’ici, on peut afficher ==== require_once __DIR__ . '/../includes/header.php'; ?>