diff --git a/website/public/API/nietSlecht.php b/website/public/API/nietSlecht.php new file mode 100644 index 0000000..e37c8e0 --- /dev/null +++ b/website/public/API/nietSlecht.php @@ -0,0 +1,41 @@ +prepare(" + SELECT + `userID` + FROM + `niet_slecht` + WHERE + `postID` = :postID + "); + $stmt->bindParam(":postID", $postID); + $stmt->execute(); + return $stmt->rowCount(); +} + +function getNietSlechtUsersForPost(int $postID) { + $stmt = $GLOBALS["db"]->prepare(" + SELECT + `fname`, + `lname`, + CONCAT(`user`.`fname`, ' ', `user`.`lname`) as `fullname` + FROM + `user` + INNER JOIN + `niet_slecht` + WHERE + `user`.`userID` = `niet_slecht`.`userID` AND + `niet_slecht`.`postID` = :postID + "); + $stmt->bindParam(":postID", $postID); + $stmt->execute(); + $rows = $stmt->fetchAll(); + foreach ($rows as $row) { + print($row["fullname"]); + } +} \ No newline at end of file diff --git a/website/public/API/postComment.php b/website/public/API/postComment.php index b840e0b..30c02eb 100644 --- a/website/public/API/postComment.php +++ b/website/public/API/postComment.php @@ -5,14 +5,25 @@ session_start(); require("../../queries/post.php"); require("../../queries/connect.php"); require("../../queries/checkInput.php"); -if (empty($_POST['newcomment-content'])) { - echo 0; -} else { - if(makeComment($_POST['postID'], - $_SESSION['userID'], - test_input($_POST['newcomment-content']))) { +print_r($_POST); +if ($_POST['button'] == 'reaction') { + if (empty($_POST['newcomment-content'])) { + echo 0; + } else { + if (makeComment($_POST['postID'], + $_SESSION['userID'], + test_input($_POST['newcomment-content']))) { + echo 1; + } else { + echo 0; + } + } +} else if ($_POST['button'] == 'nietslecht') { + if (makeNietSlecht($_POST["postID"], $_SESSION["userID"])) { echo 1; } else { echo 0; } +} else { + echo 0; } \ No newline at end of file diff --git a/website/public/js/post.js b/website/public/js/post.js index 62ace68..1906428 100644 --- a/website/public/js/post.js +++ b/website/public/js/post.js @@ -1,7 +1,9 @@ -function postComment() { +function postComment(buttonValue) { + formData = $("#newcommentform").serializeArray(); + formData.push({name: "button", value: buttonValue}); $.post( "API/postComment.php", - $("#newcommentform").serialize() + formData ); $("#newcomment").val(""); @@ -13,6 +15,4 @@ function postComment() { ).done(function (data) { $('#modal-response').html(data); }); -} - - +} \ No newline at end of file diff --git a/website/public/profile.php b/website/public/profile.php index a79ad4c..95c5b86 100644 --- a/website/public/profile.php +++ b/website/public/profile.php @@ -8,6 +8,7 @@ diff --git a/website/public/styles/post-popup.css b/website/public/styles/post-popup.css index 11fe03b..c6e96c1 100644 --- a/website/public/styles/post-popup.css +++ b/website/public/styles/post-popup.css @@ -69,4 +69,9 @@ .commentcontent { margin: 5px auto; width: 95%; +} + +.nietslecht { + font-family: Impact, Anton, sans-serif; + text-shadow: -1.5px 0 1px black, 0 1.5px 1px black, 1px 0 1.5px black, 0 -1.5px 1px black; } \ No newline at end of file diff --git a/website/queries/post.php b/website/queries/post.php index 5940267..df1e227 100644 --- a/website/queries/post.php +++ b/website/queries/post.php @@ -75,7 +75,7 @@ function makePost($userID, $groupID, $title, $content) { $stmt->execute(); } -function makeComment($postID, $userID, $content) { +function makeComment($postID, $userID, $content) : int { $stmt = $GLOBALS["db"]->prepare(" INSERT INTO `comment` ( @@ -94,4 +94,55 @@ function makeComment($postID, $userID, $content) { $stmt->bindParam(':userID', $userID); $stmt->bindParam(':content', $content); $stmt->execute(); -} \ No newline at end of file + return $stmt->rowCount(); +} + +function makeNietSlecht(int $postID, int $userID) : int { + if (checkNietSlecht($postID, $userID)) { + return deleteNietSlecht($postID, $userID); + } else { + return addNietSlecht($postID, $userID); + } +} + +function checkNietSlecht(int $postID, int $userID) { + $stmt = $GLOBALS["db"]->prepare(" + SELECT + * + FROM + `niet_slecht` + WHERE + `userID` = :userID AND + `postID` = :postID + "); + $stmt->bindParam(":userID", $userID); + $stmt->bindParam(":postID", $postID); + $stmt->execute(); + return $stmt->rowCount(); +} + +function addNietSlecht(int $postID, int $userID) { + $stmt = $GLOBALS["db"]->prepare(" + INSERT INTO + `niet_slecht` (`userID`, `postID`) + VALUES (:userID, :postID) + "); + $stmt->bindParam(":userID", $userID); + $stmt->bindParam(":postID", $postID); + $stmt->execute(); + return $stmt->rowCount(); +} + +function deleteNietSlecht(int $postID, int $userID) { + $stmt = $GLOBALS["db"]->prepare(" + DELETE FROM + `niet_slecht` + WHERE + `userID` = :userID AND + `postID` = :postID + "); + $stmt->bindParam(":userID", $userID); + $stmt->bindParam(":postID", $postID); + $stmt->execute(); + return $stmt->rowCount(); +} diff --git a/website/views/post-view.php b/website/views/post-view.php index 61e0e05..4e0ddb1 100644 --- a/website/views/post-view.php +++ b/website/views/post-view.php @@ -2,6 +2,7 @@ $postID = $_GET['postID']; $post = selectPostById($postID)->fetch(PDO::FETCH_ASSOC); $fullname = $post['fname'] . " " . $post['lname'] . " (" . $post['username'] . ")"; +session_start(); echo("
@@ -21,10 +22,20 @@ echo("
-
+
- + + +