Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $serverName = 'localhost'; //Variables to access the database
- $username = 'root';
- $password = '';
- $database = 'snake_database';
- $moderator = 0;
- $conn = mysqli_connect($serverName, $username, $password, $database); //Connect to the database
- if (!empty($_SESSION["loggedUser"])) //If someone is logged in
- {
- $moderator = $_SESSION["loggedUser"][2]; //Check if they are a moderator
- }
- if(!$conn) //If the database failed to connect
- {
- die("Database failed to connect: " .mysqli_connect_error()); //Display an error message
- }
- $sql = "SELECT * FROM posts ORDER BY `posts`.`date` DESC"; //Select all posts, latest first
- $stmt = $conn->prepare($sql);
- $stmt->execute(); //Execute the query
- $result = $stmt->get_result();
- $count = mysqli_num_rows($result);
- if ($count > 0) //If there is more than one post
- {
- while($row = $result->fetch_assoc()) //For every post, display each one
- { ?>
- <div class="post">
- <div class="post-header">
- <h3><?php echo $row["username"]; ?></h3> <!-- Display their username -->
- </div>
- <form action="functions/directProfile.php" method="get" accept-charset="utf-8"> <!-- Display their profile picture as a link to their profile page -->
- <input type="hidden" name="user" value="<?php echo htmlspecialchars($row["username"]); ?>" >
- <input type="submit" value="" class="post-image" class="submit-button" style="background-image: url('graphics/buttons/profile.png');">
- </form>
- <textarea class="post-message" readonly="readonly"><?php echo $row["post"] . " - " . $row["date"] . " Likes: " . $row["votes_up"] . " Dislikes: " . $row["votes_down"]; ?></textarea>
- <?php
- $postId = $row["post_id"]; //Get the post_id and user_id
- $userId = $row["user_id"];
- if ($moderator == 1) //Show these buttons only if they
- { ?>
- <form action="functions/muteUser.php" method="post" accept-charset="utf-8"> <!-- Form for the mute/ unmute user button -->
- <input type="hidden" name="postId" value="<?php echo htmlspecialchars($postId); ?>" > <!-- Make a hidden input with the posts id so i can retrieve it in muteUser.php -->
- <?php
- $sqlM = "SELECT * FROM `users` WHERE user_id = ?"; //Get the users info who posted this post
- $stmtM = $conn->prepare($sqlM);
- $stmtM->bind_param("i", $userId); //bind user id as an integer
- $stmtM->execute(); //Execute the query
- $resultM = $stmtM->get_result(); //Get the results
- $rowM = $resultM->fetch_assoc();
- if ($rowM["muted"] == 1) //If the user is already muted, display a muted button
- { ?>
- <input type="submit" value="" class="post-buttons" style="background-image: url('graphics/buttons/muteon.png');"><?php
- } else //If not, display a button to show they arnt muted
- { ?>
- <input type="submit" value="" class="post-buttons" style="background-image: url('graphics/buttons/muteoff.png');"><?php
- } ?>
- </form>
- <form action="functions/deletePost.php" method="post" accept-charset="utf-8"> <!-- Button to delete post -->
- <input type="hidden" name="postId" value="<?php echo htmlspecialchars($postId); ?>" >
- <input type="submit" value="" class="post-buttons" style="background-image: url('graphics/buttons/delete.png');">
- </form><?php
- } ?>
- <form action="functions/voteUp.php" method="post" accept-charset="utf-8"> <!-- Button to up vote this post -->
- <input type="hidden" name="postId" value="<?php echo htmlspecialchars($postId); ?>" >
- <input type="submit" value="" class="post-buttons" style="background-image: url('graphics/buttons/voteupoff.png');">
- </form>
- <form action="functions/voteDown.php" method="post" accept-charset="utf-8"> <!-- Button to down vote this post -->
- <input type="hidden" name="postId" value="<?php echo htmlspecialchars($postId); ?>" >
- <input type="submit" value="" class="post-buttons" style="background-image: url('graphics/buttons/votedownoff.png');">
- </form>
- </div><?php
- }
- }
- $stmt->close(); //Close the statment and connection
- $conn->close();
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement