1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
|
<?php
//On récupère la valeur de la variable action
$action = (isset($_GET['action']))?htmlspecialchars($_GET['action']):'';
// Si le membre n'est pas connecté, il est arrivé ici par erreur
if ($id==0) erreur(ERR_IS_CO);
?>
<?php
switch($action) {
case "nouveautopic":
if (!verif_auth($data['auth_annonce']) AND isset($_POST['mess'])) {
exit('</div></body></html>');
}
$message = $_POST['message'];
$mess = $_POST['mess'];
$titre = $_POST['titre'];
//ici seulement, maintenant qu'on est sur qu'elle existe, on récupère la valeur de la variable f
$forum = (int) $_GET['f'];
$temps = time();
if (empty($message) OR empty($titre)) {
echo'<p>Votre message ou votre titre est vide, cliquez <a href="poster.php?action=nouveautopic&f='.$forum.'">ici</a> pour recommencer</p>';
}
else { //Si jamais le message n'est pas vide, on entre le topic dans la base de donnée en laissant le champ topic_last_post à 0
$query=$db->prepare('INSERT INTO forum_topic (forum_id, topic_titre, topic_createur, topic_vu, topic_time, topic_genre)
VALUES(:forum, :titre, :id, 1, :temps, :mess)');
$query->bindValue(':forum', $forum, PDO::PARAM_INT);
$query->bindValue(':titre', $titre, PDO::PARAM_STR);
$query->bindValue(':id', $id, PDO::PARAM_INT);
$query->bindValue(':temps', $temps, PDO::PARAM_INT);
$query->bindValue(':mess', $mess, PDO::PARAM_STR);
$query->execute();
$nouveautopic = $db->lastInsertId(); //Notre fameuse fonction !
$query->CloseCursor();
//Puis on entre le message
$query=$db->prepare('INSERT INTO forum_post (post_createur, post_texte, post_time, topic_id, post_forum_id)
VALUES (:id, :mess, :temps, :nouveautopic, :forum)');
$query->bindValue(':id', $id, PDO::PARAM_INT);
$query->bindValue(':mess', $message, PDO::PARAM_STR);
$query->bindValue(':temps', $temps,PDO::PARAM_INT);
$query->bindValue(':nouveautopic', (int) $nouveautopic, PDO::PARAM_INT);
$query->bindValue(':forum', $forum, PDO::PARAM_INT);
$query->execute();
$nouveaupost = $db->lastInsertId(); //Encore notre fameuse fonction !
$query->CloseCursor();
//Ici on update comme prévu la valeur de topic_last_post et de topic_first_post
$query=$db->prepare('UPDATE forum_topic SET topic_last_post = :nouveaupost, topic_first_post = :nouveaupost
WHERE topic_id = :nouveautopic');
$query->bindValue(':nouveaupost', (int) $nouveaupost, PDO::PARAM_INT);
$query->bindValue(':nouveautopic', (int) $nouveautopic, PDO::PARAM_INT);
$query->execute();
$query->CloseCursor();
//Enfin on met à jour les tables forum_forum et forum_membres
$query=$db->prepare('UPDATE forum_forum SET forum_post = forum_post + 1 ,forum_topic = forum_topic + 1, forum_last_post_id = :nouveaupost
WHERE forum_id = :forum');
$query->bindValue(':nouveaupost', (int) $nouveaupost, PDO::PARAM_INT);
$query->bindValue(':forum', (int) $forum, PDO::PARAM_INT);
$query->execute();
$query->CloseCursor();
$query=$db->prepare('UPDATE forum_membres SET membre_post = membre_post + 1 WHERE membre_id = :id');
$query->bindValue(':id', $id, PDO::PARAM_INT);
$query->execute();
$query->CloseCursor();
//Et un petit message
echo'<p>Votre message a bien été ajouté ! Cliquez <a href="voirtopic.php?t='.$nouveautopic.'">ici</a> pour le voir<br />
Cliquez <a href="index.php">ici</a> pour revenir à l\'index du forum</p>';
}
break;
?> |
Partager