public function majPost($smarty, $tpl, $params, $DB) { $this->Test_session(); if (isset($_POST['majPost'])) { $post = new Home($DB); $id = $_GET['id']; $read = $post->readPost($id); if (empty($_POST['newTitle']) || empty($_POST['newText']) || empty($_POST['list'])) { if ($read['etatPosts'] == 1) { $titre = substr($read['titrePosts'], 9); } else { $titre = $read['titrePosts']; } // Récupération des infos du post $smarty->assign('id', $read['idPosts']); $smarty->assign('titre', html_entity_decode($titre)); $smarty->assign('date', $read['datePosts']); $smarty->assign('texte', html_entity_decode($read['textePosts'])); $smarty->assign('auteur', $read['membres_pseudoMbr']); $smarty->assign('categorie', $read['catPosts_nomCatPosts']); $smarty->assign('newTitle', html_entity_decode($_POST['newTitle'])); $smarty->assign('newText', html_entity_decode($_POST['newText'])); $smarty->assign('errMaj', "Attention, vous devez renseigner tous les champs !"); $this->setCat($smarty, $tpl, $params, $DB); $smarty->display('modify.tpl'); } else { $compte = new Account($DB); $id = $_GET['id']; if ($read['etatPosts'] == 1) { $titre = trim(htmlentities("[RESOLU] " . $_POST['newTitle'], ENT_QUOTES)); } else { $titre = trim(htmlentities($_POST['newTitle'], ENT_QUOTES)); } $text = trim(htmlentities($_POST['newText'], ENT_QUOTES)); $categorie = $_POST['list']; $maj = $compte->majPost($id, $titre, $text, $categorie); $myPosts = $compte->myPosts($_SESSION['pseudoMbr']); if ($myPosts) { foreach ($myPosts as $key => $value) { if (!isset($tabPosts[$myPosts[$key]['idPosts']])) { $tabPosts[$myPosts[$key]['idPosts']] = array(); } // Ajout des posts dans le tableau créé array_push($tabPosts[$myPosts[$key]['idPosts']], html_entity_decode($myPosts[$key]['titrePosts']), $myPosts[$key]['datePosts'], $myPosts[$key]['etatPosts'], $myPosts[$key]['catPosts_nomCatPosts']); } $smarty->assign('myPosts', $tabPosts); } $smarty->assign('okMaj', "Votre post a bien été modifié !"); $smarty->display('account.tpl'); } } }
public function sendRep($smarty, $tpl, $params, $DB) { $this->Test_session(); $rep = new Home($DB); $id = $_GET['id']; // Vérif champs if (isset($_POST['repSend'])) { if (isset($_POST['repPost']) && $_POST['repPost'] != '') { $texte = trim(htmlentities($_POST['repPost'], ENT_QUOTES)); $today = getdate(); $jour = $today['mday']; $annee = $today['year']; $heures = $today['hours']; $minutes = $today['minutes']; if (strlen($minutes) == 1) { $minutes = "0" . $today['minutes']; } switch ($today['month']) { case "January": $mois = "Janvier"; break; case "February": $mois = "Février"; break; case "March": $mois = "Mars"; break; case "April": $mois = "Avril"; break; case "May": $mois = "Mai"; break; case "June": $mois = "Juin"; break; case "July": $mois = "Juillet"; break; case "August": $mois = "Août"; break; case "September": $mois = "Septembre"; break; case "October": $mois = "Octobre"; break; case "November": $mois = "Novembre"; break; case "December": $mois = "Décembre"; break; } $date = $jour . " " . $mois . " " . $annee . " à " . $heures . "h" . $minutes; $auteur = trim(htmlentities($_SESSION['pseudoMbr'])); // Ajout dans la BDD $send = $rep->addRep($texte, $date, $auteur, $id); // Lecture du post $post = new Home($DB); $read = $post->readPost($id); // Récupération des infos du post $smarty->assign('idd', $read['idPosts']); $smarty->assign('titre', $read['titrePosts']); $smarty->assign('date', $read['datePosts']); $smarty->assign('texte', $read['textePosts']); $smarty->assign('etat', $read['etatPosts']); $smarty->assign('auteur', $read['membres_pseudoMbr']); $smarty->assign('categorie', $read['catPosts_nomCatPosts']); // (Ré)affichage du post $rep = new Home($DB); $reps = $rep->repPost($id); $tabReps = array(); if ($reps) { foreach ($reps as $key => $value) { if (!isset($tabReps[$reps[$key]['idMsg']])) { $tabReps[$reps[$key]['idMsg']] = array(); } array_push($tabReps[$reps[$key]['idMsg']], html_entity_decode($reps[$key]['texteMsg']), $reps[$key]['dateMsg'], $reps[$key]['membres_pseudoMbr']); } } $smarty->assign('reps', $tabReps); $this->Test_admin($smarty, $tpl, $params, $DB); $this->init($smarty, $tpl, $params, $DB); header('Location:index.php?c=home&f=readPost&id=' . $read['idPosts']); } else { $post = new Home($DB); $read = $post->readPost($id); // Récupération des infos du post $smarty->assign('idd', $read['idPosts']); $smarty->assign('titre', $read['titrePosts']); $smarty->assign('date', $read['datePosts']); $smarty->assign('texte', $read['textePosts']); $smarty->assign('etat', $read['etatPosts']); $smarty->assign('auteur', $read['membres_pseudoMbr']); $smarty->assign('categorie', $read['catPosts_nomCatPosts']); $smarty->assign('errRep', "Veuillez saisir une réponse."); $rep = new Home($DB); $reps = $rep->repPost($id); $tabReps = array(); if ($reps) { foreach ($reps as $key => $value) { if (!isset($tabReps[$reps[$key]['idMsg']])) { $tabReps[$reps[$key]['idMsg']] = array(); } array_push($tabReps[$reps[$key]['idMsg']], html_entity_decode($reps[$key]['texteMsg']), $reps[$key]['dateMsg'], $reps[$key]['membres_pseudoMbr']); } } $smarty->assign('reps', $tabReps); $this->Test_admin($smarty, $tpl, $params, $DB); $smarty->display('readPost.tpl'); } } }