prepare("UPDATE users SET profile_picture = :user_pp WHERE ID = :user_id"); $req->bindParam(":user_pp", $webPath); $req->bindParam(":user_id", $_SESSION['userid']); if($req->execute()) { $status = "PP mise à jour"; } else { $status = "Erreur SQL"; } } else { $status = "Le fichier doit être au format PNG ou JPG"; } } if (isset($_FILES['banner']) && $_FILES['banner']['error'] == 0) { // Chemins et noms de fichiers $tempPath = $_FILES['banner']['tmp_name']; $path = '/src/banner/'. $_SESSION['userid'] .'.png'; $rootPath = $wwwroot . "/html" . $path; $webPath = $root . $path; // Redimensionnement de l'image list($width, $height) = getimagesize($tempPath); $imageInfo = getimagesize($tempPath); if ($imageInfo[2] === IMAGETYPE_PNG || $imageInfo[2] === IMAGETYPE_JPEG) { $newWidth = 800; $newHeight = ($height / $width) * $newWidth; $imageResized = imagecreatetruecolor($newWidth, $newHeight); imagealphablending($imageResized, false); imagesavealpha($imageResized, true); $imageOriginal = imagecreatefromstring(file_get_contents($tempPath)); imagecopyresampled($imageResized, $imageOriginal, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height); // Enregistrement de l'image redimensionnée imagepng($imageResized, $rootPath); // Nettoyage imagedestroy($imageOriginal); imagedestroy($imageResized); $bdd = connect($dbhost, $dbname, $dbuser, $dbpass); $req = $bdd->prepare("UPDATE users SET banner = :user_banner WHERE ID = :user_id"); $req->bindParam(":user_banner", $webPath); $req->bindParam(":user_id", $_SESSION['userid']); if($req->execute()) { $status = "Banière mise à jour"; } else { $status = "Erreur SQL"; } } else { $status = "Le fichier doit être un PNG ou JPG"; } } if(isset($_POST['user_display_name']) && isset($_POST['user_name']) && isset($_POST['user_bio'])) { $bdd = connect($dbhost, $dbname, $dbuser, $dbpass); $req = $bdd->prepare("SELECT ID FROM users WHERE username = :user_name AND NOT ID = :user_id"); $req->bindParam(":user_name", htmlspecialchars($_POST['user_name'])); $req->bindParam(":user_id", $_SESSION['userid'], PDO::PARAM_INT); $req->execute(); $resultat = $req->fetchAll(PDO::FETCH_ASSOC); if($resultat) { $status = "Erreur, le nom d'utilisateur existe déjà."; } else { $bdd = connect($dbhost, $dbname, $dbuser, $dbpass); $req = $bdd->prepare("UPDATE users SET username = :user_name, display_name = :user_display_name, bio = :user_bio WHERE ID = :user_id"); $req->bindParam(":user_name", htmlspecialchars($_POST['user_name'])); $req->bindParam(":user_display_name", htmlspecialchars($_POST['user_display_name'])); $req->bindParam(":user_bio", htmlspecialchars($_POST['user_bio'])); $req->bindParam(":user_id", $_SESSION['userid']); if($req->execute()) { $status = "Informations mises à jour"; $_SESSION['username'] = htmlspecialchars($_POST['user_name']); $_SESSION['display_name'] = htmlspecialchars($_POST['user_display_name']); } else { $status = "Erreur, les informations n'ont pas pu être mises à jour."; } } } $bdd = connect($dbhost, $dbname, $dbuser, $dbpass); $req = $bdd->prepare("SELECT ID, username, creation_date, display_name, role, profile_picture, banner, bio FROM users WHERE ID = :user_id"); $req->bindParam(":user_id", $_SESSION['userid']); $req->execute(); $resultat = $req->fetchAll(PDO::FETCH_ASSOC); if($resultat) { $user_id = $resultat[0]['ID']; $user_name = $resultat[0]['username']; $user_creation_date = $resultat[0]['creation_date']; $user_display_name = $resultat[0]['display_name']; $user_role = $resultat[0]['role']; $user_pp = $resultat[0]['profile_picture'] == NULL ? "https://abs.twimg.com/sticky/default_profile_images/default_profile_400x400.png" : $resultat[0]['profile_picture']; $user_pp_url = $resultat[0]['profile_picture']; $user_banner = $resultat[0]['banner'] = NULL ? "./src/img/empty.jpg" : $resultat[0]['banner']; $user_bio = $resultat[0]['bio']; } else { die("Erreur, utilisateur introuvable"); } ?> <?=$title?>
prepare("SELECT ID, titre, date, image, resume FROM articles WHERE (titre LIKE :search OR ID LIKE :search OR auteur LIKE :search) AND classification <= :accreditation AND auteur = :user_id ORDER BY date DESC"); $req->bindParam(":search", $search); $req->bindParam(":accreditation", $_SESSION['accreditation']); $req->bindParam(":user_id", $user_id); $req->execute(); $resultat = $req->fetchAll(PDO::FETCH_ASSOC); echo "

Editer un article

"; echo "
"; if ($resultat) { foreach($resultat as $row) { $date = strtotime($row['date']); echo '
'; echo '
'; echo ''; echo '
'; echo '
'; echo '
n° ' . $row['ID'] . ' | ' . date('d/m/Y', $date) . '
'; echo ''; echo '
' . $row['titre'] . '
'; echo '
'; echo '
' . $row['resume'] . '
'; echo '
'; echo '
'; } } else { echo "Vous n'avez publié aucun article..."; } ?>