diff --git a/website/public/API/deletePost.php b/website/public/API/deletePost.php new file mode 100644 index 0000000..fffadf5 --- /dev/null +++ b/website/public/API/deletePost.php @@ -0,0 +1,20 @@ +fetchColumn(); - $group_count = countSomeGroups($search)->fetchColumn(); - $filter = "all"; if (isset($_POST['filter'])) { $filter = test_input($_POST['filter']); } + if ($filter == "all") { + $user_count = countSomeUsers($search)->fetchColumn(); + $group_count = countSomeGroups($search)->fetchColumn(); + } else { + $user_count = countSomeFriends($search); + $group_count = countSomeOwnGroups($search); + } + + $option = "user"; if (isset($_POST['option'])) { $option = test_input($_POST['option']); } - include("../../views/searchPageNumber.php"); + include ("../../views/searchPageNumber.php"); } else { header('HTTP/1.0 403 Forbidden'); -} \ No newline at end of file +} diff --git a/website/public/API/sendMessage.php b/website/public/API/sendMessage.php index 2d0b092..c6e3231 100644 --- a/website/public/API/sendMessage.php +++ b/website/public/API/sendMessage.php @@ -6,12 +6,15 @@ require_once("../../queries/private_message.php"); require_once("../../queries/checkInput.php"); require_once("../../queries/user.php"); +// Check if the user is allowed to send a message. if (isset($_SESSION["userID"]) && getRoleByID($_SESSION["userID"]) != 'frozen' && getRoleByID($_SESSION["userID"]) != 'banned') { if (!empty(test_input($_POST["destination"])) && !empty(test_input($_POST["content"])) ) { + // Send the message. + // Returns false when it didn't succeed sending the message. if (sendMessage(test_input($_POST["destination"]), test_input($_POST["content"]))) { echo 1; } else { diff --git a/website/public/bits/friend-item.php b/website/public/bits/friend-item.php index 40bc8a8..6a0c868 100644 --- a/website/public/bits/friend-item.php +++ b/website/public/bits/friend-item.php @@ -4,6 +4,7 @@ session_start(); include_once ("../../queries/friendship.php"); +// Initialize variables to given or default values. if (isset($_POST["action"])) { $action = $_POST["action"]; } else { @@ -18,6 +19,8 @@ if (isset($_POST["actionType"])) { $friends = json_decode($_POST["friends"]); + +// Foreach friend, return them as list item. foreach($friends as $i => $friend) { $friendshipStatus = getFriendshipStatus($friend->userID); ?> @@ -38,7 +41,7 @@ foreach($friends as $i => $friend) { fullname ?>
username)) { - echo $friend->username; + echo $friend->usernameshort; } else if (isset($friend->content)) { echo $friend->content; } @@ -48,6 +51,7 @@ foreach($friends as $i => $friend) { 1) { if ($friendshipStatus == 2) { $denyName = "Annuleer"; diff --git a/website/public/bits/group-item.php b/website/public/bits/group-item.php index 92eccfc..dbe799d 100644 --- a/website/public/bits/group-item.php +++ b/website/public/bits/group-item.php @@ -6,6 +6,7 @@ include_once ("../../queries/group_member.php"); $groups = json_decode($_POST["groups"]); +// Add each group as list item. foreach($groups as $i => $group) { ?>
  • diff --git a/website/public/js/chat.js b/website/public/js/chat.js index 6a027c8..3f28c81 100644 --- a/website/public/js/chat.js +++ b/website/public/js/chat.js @@ -9,13 +9,17 @@ $(document).ready(function() { $(".chat-field").hide(); }); +// This function loads the new messages and runs the addMessages function to show them. function loadMessages() { + // If the function is not running elsewhere, run it here. if (!gettingMessages) { gettingMessages = true; + // Get the messages. $.post( "API/loadMessages.php", $("#lastIDForm").serialize() ).done(function (data) { + // Post the messages in the chat. if (data && data != "[]") { messages = JSON.parse(data); addMessages(messages); @@ -28,7 +32,7 @@ function loadMessages() { } } - +// Send a message to a friend of the user. function sendMessage() { $.post( "API/sendMessage.php", @@ -37,42 +41,54 @@ function sendMessage() { if (response == "frozen") { alert("Je account is bevroren, dus je kan niet chat berichten versturen. Contacteer een admin als je denkt dat dit onjuist is."); } + // Load messages if the message has been send, so it shows in the chat. + loadMessages(); }); $("#newContent").val(""); - loadMessages(); } +// Add messages to the chat. function addMessages(messages) { var messagesText = ""; + + // Loop over all the messages. for(var i in messages) { - // Initialize message variables + // Initialize message variables. var thisDate = new Date(messages[i].creationdate.replace(/ /,"T")); var thisTime = thisDate.getHours() + ":" + thisDate.getMinutes(); var type; thisDate.setHours(0,0,0,0); + // See where the message has been send from, so it shows on the right side. if (messages[i].destination == $(".destinationID").val()) { type = "chat-message-self"; } else { type = "chat-message-other"; } + + // If it is the first message, open the message box and maybe add a year. if (i == 0) { + if (thisDate.getTime() > previousDate.getTime()) { + messagesText += '\ +
    \ +
    \ + ' + days[thisDate.getDay()] + " " + thisDate.getDate() + " " + months[thisDate.getMonth()] + " " + thisDate.getFullYear() + '\ +
    \ +
    '; + } previousDate = thisDate; - messagesText += '\ -
    \ -
    \ - ' + days[thisDate.getDay()] + " " + thisDate.getDate() + " " + months[thisDate.getMonth()] + " " + thisDate.getFullYear() + '\ -
    \ -
    '; messagesText += '
    '; + // If it is not the first message, and has a different date/time/type then the previous message, } else if (type != previousType || thisTime != previousTime || thisDate.getTime() > previousDate.getTime()) { + // Close the previous message. messagesText += '
    \ ' + thisTime + '\
    '; previousTime = thisTime; previousType = type; + // If the date is different, add a new date. if (thisDate > previousDate) { previousDate = thisDate; messagesText += '\ @@ -83,8 +99,11 @@ function addMessages(messages) { '; } + // Open the new message. messagesText += '
    '; } + + // Add the content of the message in the new box. messagesText += fancyText(messages[i].content) + "
    "; } @@ -93,11 +112,14 @@ function addMessages(messages) { ' + thisTime + '\
    '; + // Add all the new created messaged to the chat. $("#chat-history").append(messagesText); + // Scroll down, so the user can see the new messages. $("#chat-history").scrollTop($("#chat-history")[0].scrollHeight - $('#chat-history')[0].clientHeight); } +// Switch to a different user. function switchUser(userID) { previousDate = new Date("1970-01-01 00:00:00"); $(".chat-field").show(); @@ -108,6 +130,7 @@ function switchUser(userID) { $("#friend-item-" + userID).addClass("active-friend-chat"); } +// Insert a message in the chat, this is used when it is empty. function sayEmpty() { $("#chat-history").html("Probeer ook eens foto's en video's te sturen"); } \ No newline at end of file diff --git a/website/public/js/header.js b/website/public/js/header.js index 4feea40..e4408cc 100644 --- a/website/public/js/header.js +++ b/website/public/js/header.js @@ -11,7 +11,8 @@ $(document).ready(function() { // Add cookie so the menu stays open on other pages if (window.innerWidth > 1080) { - $("#chat-history").width("calc(100% - 587px)"); + $("#chat-history").css("margin-right", "266px"); + $("#chat-history").css("width", "calc(100% - 512px - 75px)"); document.cookie = "menu=open; path=/"; } else { document.cookie = "menu=closed; path=/"; @@ -22,7 +23,8 @@ $(document).ready(function() { $("#notification-center").css("display", "none"); if (window.innerWidth > 1080) { - $("#chat-history").width("calc(100% - 331px)"); + $("#chat-history").css("margin-right", "10px"); + $("#chat-history").css("width", "calc(100% - 256px - 85px)"); } else { // Make the menu invisible and move the content to the right. $("#contact-menu").css("display", "none"); @@ -43,6 +45,7 @@ $(document).ready(function() { // Add cookie so the menu stays open on other pages if (window.innerWidth > 1080) { + $("#chat-history").css("margin-right", "266px"); $("#chat-history").width("calc(100% - 587px)"); document.cookie = "menu=open; path=/"; } else { diff --git a/website/public/js/main.js b/website/public/js/main.js index a5f17de..b6ab703 100644 --- a/website/public/js/main.js +++ b/website/public/js/main.js @@ -14,14 +14,14 @@ function fancyText(text) { return ""; + ""; } // Add ogg video's else if (link.match(/(https?:\/\/.[^ ]*\.(?:ogg))/ig)) { return ""; + ""; } // Add youtube video's else if (link.match(/(https?:\/\/.(www.)?youtube|youtu.be)*watch/ig)) { @@ -38,6 +38,8 @@ function fancyText(text) { return text; } +// This function gets the value of a cookie when given a key. +// If didn“t find any compatible cookie, it returns false. function getCookie(key) { cookies = document.cookie.split("; "); for (var i in cookies) { @@ -49,6 +51,7 @@ function getCookie(key) { return false; } +// Edit the friendship status of two users. function editFriendship(userID, value) { $.post("API/editFriendship.php", { usr: userID, action: value }) .done(function() { @@ -57,6 +60,8 @@ function editFriendship(userID, value) { }); } +// Show the given friends in the given list. +// The friends are giving in JSON, and the list is giving with a hashtag. function showFriends(friends, list) { if(friends && friends != "[]") { $(list).load("bits/friend-item.php", { @@ -69,6 +74,8 @@ function showFriends(friends, list) { } } +// Show the given friends in the given list. +// This function supports more options given as parameters. This adds extra functionality. function showFriendsPlus(friends, list, limit, action, actionType) { if(friends && friends != "[]") { $(list).load("bits/friend-item.php", { @@ -84,6 +91,7 @@ function showFriendsPlus(friends, list, limit, action, actionType) { } } +// Show the given groups in the given list. function showGroups(groups, list) { if(groups && groups != "[]") { $(list).load("bits/group-item.php", { @@ -94,14 +102,4 @@ function showGroups(groups, list) { } else { return false; } -} - -$(document).ready(function() { - $("body").delegate("textarea[maxlength]", "keydown", function() { - if ($(this).val().length / .9 >= $(this).attr("maxlength")) { - $(this).next().text($(this).val().length + "/" + $(this).attr("maxlength")); - } else { - $(this).next().text(""); - } - }); -}); \ No newline at end of file +} \ No newline at end of file diff --git a/website/public/js/masonry.js b/website/public/js/masonry.js index 4c40aad..190a26f 100644 --- a/website/public/js/masonry.js +++ b/website/public/js/masonry.js @@ -61,19 +61,9 @@ $(document).ready(function () { }); $(window).on("load", function() { - $(".modal-close").click(function () { - $(".modal").hide(); - scrollbarMargin(0, 'auto'); - $('#modal-response').hide(); - $('.modal-default').show(); - }); + $(".modal-close").click(function (){closeModal()}); // http://stackoverflow.com/questions/9439725/javascript-how-to-detect-if-browser-window-is-scrolled-to-bottom - // $(window).on("scroll", function () { - // if ((window.innerHeight + window.pageYOffset) >= document.body.offsetHeight) { - // loadMorePosts(userID, groupID, postAmount, postLimit); - // } - // }); window.onscroll = function(ev) { if($(window).scrollTop() + $(window).height() == $(document).height() ) { loadMorePosts(userID, groupID, postAmount, postLimit); @@ -81,6 +71,13 @@ $(window).on("load", function() { }; }); +function closeModal() { + $(".modal").hide(); + scrollbarMargin(0, 'auto'); + $('#modal-response').hide(); + $('.modal-default').show(); +} + $(window).resize(function() { clearTimeout(window.resizedFinished); window.resizeFinished = setTimeout(function() { @@ -123,7 +120,7 @@ function masonry(mode) { $form.append($("")); $form.append($("")); - $form.append($("")); + $form.append($("")); columns[0][1].append($postInput); columns[0][0] = $postInput.height() + margin; diff --git a/website/public/js/menu.js b/website/public/js/menu.js index 5ca9c97..c575ecd 100644 --- a/website/public/js/menu.js +++ b/website/public/js/menu.js @@ -6,11 +6,7 @@ var updatingMenus = 0; // On document load, load menus and loops loading menus every 10 seconds. $(document).ready(function() { - updatingMenus = 4; - loadMenuFriends(5); - loadNotificationFriends(); - loadUnreadMessages(); - loadMenuGroups(); + updateMenus(); setInterval(updateMenus, 10000); }); @@ -18,7 +14,6 @@ $(document).ready(function() { // Update the menu and notification items. function updateMenus() { if (updatingMenus <= 0) { - updatingMenus = 4; loadMenuFriends(5); loadNotificationFriends(); loadUnreadMessages(); @@ -27,76 +22,105 @@ function updateMenus() { } -// Get, every 3 seconds, the friends and insert them in the menu. +// Get the friends and insert them in the menu. function loadMenuFriends(limit) { + updatingMenus ++; $.post( "API/loadFriends.php", { limit: 5 } ).done(function(data) { + if (data == "" || data == "[]") { + $("#friends-menu-section").hide(); + } else { + $("#friends-menu-section").show(); + } if (menuFriendsData != data) { menuFriendsData = data; - if (showFriends(data, "#menu-friends-list", 5, "profile.php", "GET", limit)) { - $("#friends-menu-section").show(); - } else { + if (!showFriends(data, "#menu-friends-list", 5, "profile.php", "GET", limit)) { $("#friends-menu-section").hide(); } } + }).fail(function() { + $("#friends-menu-section").hide(); + }).always(function() { updatingMenus --; }); } -// Get, every 3 seconds, the groups and insert them in the menu. +// Get the groups and insert them in the menu. function loadMenuGroups() { + updatingMenus ++; $.post( "API/loadGroups.php", { limit: 5 } ).done(function(data) { + + if (data == "" || data == "[]") { + $("#groups-menu-section").hide(); + } else { + $("#groups-menu-section").show(); + } if (menuGroupsData != data) { menuGroupsData = data; - if (showGroups(data, "#menu-groups-list")) { - $("#groups-menu-section").show(); - } else { + if (!showGroups(data, "#menu-groups-list")) { $("#groups-menu-section").hide(); } } + }).fail(function() { + $("#groups-menu-section").hide(); + }).always(function() { updatingMenus --; }); } -// Get, every 3 seconds, the friends requests and insert them in the notification center. +// Get the friends requests and insert them in the notification center. function loadNotificationFriends() { + updatingMenus ++; $.post( "API/loadFriendRequest.php" ).done(function(data) { + if (data == "" || data == "[]") { + $("#friend-request-section").hide(); + } else { + $("#friend-request-section").show(); + } if (notificationRequestsData != data) { notificationRequestsData = data; - if (showFriendsPlus(data, "#friend-requests-list", 5, "profile.php", "GET")) { - $("#friend-request-section").show(); - } else { + if (!showFriendsPlus(data, "#friend-requests-list", 5, "profile.php", "GET")) { $("#friend-request-section").hide(); } } + }).fail(function() { + $("#friend-request-section").hide(); + }).always(function() { updatingMenus --; }); } -// Get, every 3 seconds, the unread messages and insert them in the notification center. +// Get the unread messages and insert them in the notification center. function loadUnreadMessages() { + updatingMenus ++; $.post( "API/loadChatNotifications.php" ).done(function(data) { + if (data == "" || data == "[]") { + $("#unread-messages-section").hide(); + } else { + $("#unread-messages-section").show(); + } if (notificationMessagesData != data) { notificationMessagesData = data; - if (showFriendsPlus(data, "#unread-chat-list", 5, "chat.php", "GET")) { - $("#unread-messages-section").show(); - } else { + if (!showFriendsPlus(data, "#unread-chat-list", 5, "chat.php", "GET")) { $("#unread-messages-section").hide(); } } + }).fail(function() { + $("#unread-messages-section").hide(); + }).always(function() { updatingMenus --; }); } \ No newline at end of file diff --git a/website/public/js/post.js b/website/public/js/post.js index 27bc34e..4009023 100644 --- a/website/public/js/post.js +++ b/website/public/js/post.js @@ -1,3 +1,4 @@ + function postComment(buttonValue) { formData = $("#newcommentform").serializeArray(); formData.push({name: "button", value: buttonValue}); @@ -19,4 +20,18 @@ function postComment(buttonValue) { ).done(function (data) { $('#modal-response').html(fancyText(data)); }); +} + +function deletePost(postID) { + var formData = [{name: "postID", value: postID}]; + $.post( + "API/deletePost.php", + formData + ).done(function (response) { + if (response == "frozen") { + alert("Je account is bevroren, dus je kan geen posts verwijderen. Contacteer een admin als je denkt dat dit onjuist is."); + } + }); + closeModal(); + masonry(masonryMode); } \ No newline at end of file diff --git a/website/public/js/search.js b/website/public/js/search.js index f7c4bbe..affe758 100644 --- a/website/public/js/search.js +++ b/website/public/js/search.js @@ -2,6 +2,7 @@ $(window).on('load', function () { pageNumber(); }); +// Search for the users and put them in the user list. function searchUsers() { $.post( "API/searchUsers.php", @@ -13,6 +14,7 @@ function searchUsers() { }); } +// Search for the groups and put them in the group list. function searchGroups() { $.post( "API/searchGroups.php", @@ -24,6 +26,7 @@ function searchGroups() { }); } +// Get the page numbers and return them in the select. function pageNumber() { var input = input2 = $('#search-form').serialize(); $.post( diff --git a/website/public/styles/adminpanel.css b/website/public/styles/adminpanel.css index 0648118..39d823f 100644 --- a/website/public/styles/adminpanel.css +++ b/website/public/styles/adminpanel.css @@ -56,5 +56,5 @@ } .bancommentform input[type="text"] { - width: 100%; + width: 80%; } \ No newline at end of file diff --git a/website/public/styles/main.css b/website/public/styles/main.css index 94fdea9..650a30f 100644 --- a/website/public/styles/main.css +++ b/website/public/styles/main.css @@ -102,7 +102,6 @@ p { .group-picture { border-radius: 5px; - border: none; } .item-box, .item-box-full-width { @@ -117,7 +116,7 @@ p { @media only screen and (max-width: 1400px) { .item-box { - width: calc(100% - 50px); + width: calc(100% - 50px)!important; } } @@ -291,19 +290,6 @@ div[data-title]:hover:after { vertical-align: middle; } -::-webkit-scrollbar { - width: 5px; - height: 5px; -} -::-webkit-scrollbar-track { - background: none; -} -::-webkit-scrollbar-thumb { - -webkit-border-radius: 20px; - border-radius: 20px; - background: #4CAF50; -} - @media only screen and (max-width: 1080px) { body { font-size: 28px!important; diff --git a/website/public/styles/post-popup.css b/website/public/styles/post-popup.css index 67d7880..3f37ffd 100644 --- a/website/public/styles/post-popup.css +++ b/website/public/styles/post-popup.css @@ -83,4 +83,21 @@ vertical-align: middle; height: 24px; width: 24px; +} + +.deleteButton { + background-color: firebrick; + +} + +.deleteButton i { + display: inline-block; +} + +.deleteButton:hover span { + display: inline-block; +} + +.deleteButton span { + display: none; } \ No newline at end of file diff --git a/website/public/styles/profile.css b/website/public/styles/profile.css index 1bacafa..146a4fa 100644 --- a/website/public/styles/profile.css +++ b/website/public/styles/profile.css @@ -11,7 +11,7 @@ display: inline-block; } -.friend-button-container { +.friend-button-container, .group-button-container { position: relative; float: right; width: 200px; @@ -62,7 +62,6 @@ .group-picture { border: none; - margin-bottom: 0; margin-right: 15px; } @@ -108,7 +107,7 @@ div.posts .post form input, div.posts .post form textarea { width: calc(100% - 15px); } -div.posts .post form input[type="submit"] { +div.posts .post form input[type="submit"], .post button{ width: 100%; } diff --git a/website/public/styles/settings.css b/website/public/styles/settings.css index 933e7fd..6a2c2f2 100644 --- a/website/public/styles/settings.css +++ b/website/public/styles/settings.css @@ -32,6 +32,11 @@ text-align: right; } +.settings-password, .settings-email { + width: calc(50% - 60px); + display: inline-flex; +} + .settings-password label, .settings-email label { text-align: left; } diff --git a/website/queries/friendship.php b/website/queries/friendship.php index a16d859..7edada9 100644 --- a/website/queries/friendship.php +++ b/website/queries/friendship.php @@ -10,8 +10,9 @@ function selectLimitedFriends($userID, $limit) { $stmt = prepareQuery(" SELECT `userID`, + LEFT(`username`, 12) as `usernameshort`, `username`, - LEFT(CONCAT(`user`.`fname`, ' ', `user`.`lname`), 15) as `fullname`, + LEFT(CONCAT(`user`.`fname`, ' ', `user`.`lname`), 12) as `fullname`, IFNULL( `profilepicture`, '../img/avatar-standard.png' @@ -50,8 +51,9 @@ function selectAllFriends($userID) { $stmt = prepareQuery(" SELECT `userID`, + LEFT(`username`, 12) as `usernameshort`, `username`, - LEFT(CONCAT(`user`.`fname`, ' ', `user`.`lname`), 15) as `fullname`, + LEFT(CONCAT(`user`.`fname`, ' ', `user`.`lname`), 12) as `fullname`, IFNULL( `profilepicture`, '../img/avatar-standard.png' @@ -85,8 +87,9 @@ function selectAllFriendRequests() { $stmt = prepareQuery(" SELECT `userID`, + LEFT(`username`, 12) as `usernameshort`, `username`, - LEFT(CONCAT(`user`.`fname`, ' ', `user`.`lname`), 15) as `fullname`, + LEFT(CONCAT(`user`.`fname`, ' ', `user`.`lname`), 12) as `fullname`, IFNULL( `profilepicture`, '../img/avatar-standard.png' @@ -235,8 +238,9 @@ function searchSomeFriends($n, $m, $search) { $stmt = prepareQuery(" SELECT `userID`, + LEFT(`username`, 12) as `usernameshort`, `username`, - LEFT(CONCAT(`user`.`fname`, ' ', `user`.`lname`), 15) as `fullname`, + LEFT(CONCAT(`user`.`fname`, ' ', `user`.`lname`), 12) as `fullname`, IFNULL( `profilepicture`, '../img/avatar-standard.png' @@ -275,4 +279,35 @@ function searchSomeFriends($n, $m, $search) { $stmt->bindParam(':m', $m, PDO::PARAM_INT); $stmt->execute(); return json_encode($stmt->fetchAll()); +} + +function countSomeFriends($search) { + $stmt = prepareQuery(" + SELECT + COUNT(*) + FROM + `user` + INNER JOIN + `friendship` + WHERE + ((`friendship`.`user1ID` = :userID AND + `friendship`.`user2ID` = `user`.`userID` OR + `friendship`.`user2ID` = :userID AND + `friendship`.`user1ID` = `user`.`userID`) AND + `user`.`role` != 'banned' AND + `friendship`.`status` = 'confirmed') AND + (`username` LIKE :keyword OR + `fname` LIKE :keyword OR + `lname` LIKE :keyword) + ORDER BY + `fname`, + `lname`, + `username` + "); + + $search = "%$search%"; + $stmt->bindParam(':keyword', $search); + $stmt->bindParam(':userID', $_SESSION["userID"], PDO::PARAM_INT); + $stmt->execute(); + return $stmt->fetchColumn(); } \ No newline at end of file diff --git a/website/queries/group_member.php b/website/queries/group_member.php index 50e6117..7844235 100644 --- a/website/queries/group_member.php +++ b/website/queries/group_member.php @@ -55,6 +55,29 @@ function searchSomeOwnGroups($n, $m, $search) { return json_encode($stmt->fetchAll()); } +function countSomeOwnGroups($search) { + $stmt = prepareQuery(" + SELECT + COUNT(*) + FROM + `group_page` + INNER JOIN + `group_member` + WHERE + `group_member`.`userID` = :userID AND + `group_member`.`groupID` = `group_page`.`groupID` AND + `group_page`.`status` != 'hidden' AND + `name` LIKE :keyword + "); + + $search = "%$search%"; + $stmt->bindParam(':keyword', $search); + $stmt->bindParam(':userID', $_SESSION["userID"], PDO::PARAM_INT); + $stmt->execute(); + + return $stmt->fetchColumn(); +} + function addMember($groupID, $userID, $role) { $stmt = prepareQuery(" INSERT INTO diff --git a/website/queries/group_page.php b/website/queries/group_page.php index b66ca54..f2f028f 100644 --- a/website/queries/group_page.php +++ b/website/queries/group_page.php @@ -196,7 +196,9 @@ function search20GroupsFromNByStatus($n, $keyword, $status) { return $q; } -function searchSomeGroupsByStatus($n, $m, $keyword, $status) { +function searchSomeGroupsByStatus($n, $m, $search, $status) { +// parentheses not needed in where clause, for clarity as +// role search should override status filter. $q = prepareQuery(" SELECT `groupID`, @@ -206,16 +208,18 @@ function searchSomeGroupsByStatus($n, $m, $keyword, $status) { FROM `group_page` WHERE - `name` LIKE :keyword AND - FIND_IN_SET (`status`, :statuses) + (`name` LIKE :keyword AND + FIND_IN_SET (`status`, :statuses)) OR + `status` = :search ORDER BY `name` LIMIT :n, :m "); - $keyword = "%$keyword%"; + $keyword = "%$search%"; $q->bindParam(':keyword', $keyword); + $q->bindParam(':search', $search); $q->bindParam(':n', $n, PDO::PARAM_INT); $q->bindParam(':m', $m, PDO::PARAM_INT); $statuses = implode(',', $status); @@ -224,21 +228,23 @@ function searchSomeGroupsByStatus($n, $m, $keyword, $status) { return $q; } -function countSomeGroupsByStatus($keyword, $status) { +function countSomeGroupsByStatus($search, $status) { $q = prepareQuery(" SELECT COUNT(*) FROM `group_page` WHERE - `name` LIKE :keyword AND - FIND_IN_SET (`status`, :statuses) + (`name` LIKE :keyword AND + FIND_IN_SET (`status`, :statuses)) OR + `status` = :search ORDER BY `name` "); - $keyword = "%$keyword%"; + $keyword = "%$search%"; $q->bindParam(':keyword', $keyword); + $q->bindParam(':search', $search); $statuses = implode(',', $status); $q->bindParam(':statuses', $statuses); $q->execute(); diff --git a/website/queries/post.php b/website/queries/post.php index db81892..ecc5c48 100644 --- a/website/queries/post.php +++ b/website/queries/post.php @@ -243,3 +243,56 @@ function deleteNietSlecht(int $postID, int $userID) { $stmt->execute(); return $stmt->rowCount(); } + +function deletePost(int $postID, int $userID) { + if (checkPermissionOnPost($postID, $userID)) { + $stmt = prepareQuery(" + DELETE FROM + `post` + WHERE + `postID` = :postID + "); + $stmt->bindParam(":postID", $postID); + $stmt->execute(); + } +} + +function checkPermissionOnPost(int $postID, int $userID) : bool { + $getGroupID = prepareQuery(" + SELECT + `author`, + `groupID` + FROM + `post` + WHERE + `postID` = :postID + "); + $getGroupID->bindParam(":postID", $postID); + $getGroupID->execute(); + $postinfo = $getGroupID->fetch(); + + if ($postinfo["groupID"] == null) { + // User post + return ($userID == $postinfo["author"]); + } else { + // Group post + $roleInGroup = getRoleInGroup($userID, $postinfo["groupID"]); + return ($roleInGroup == "mod" or $roleInGroup == "admin"); + } +} + +function getRoleInGroup(int $userID, int $groupID) { + $stmt = prepareQuery(" + SELECT + `role` + FROM + `group_member` + WHERE + `userID` = :userID AND + `groupID` = :groupID + "); + $stmt->bindParam(":userID", $userID); + $stmt->bindParam(":groupID", $groupID); + $stmt->execute(); + return $stmt->fetch()["role"]; +} diff --git a/website/queries/private_message.php b/website/queries/private_message.php index 4ac04a7..3b88563 100644 --- a/website/queries/private_message.php +++ b/website/queries/private_message.php @@ -95,7 +95,7 @@ function getNewChatMessages($lastID, $destination) { function selectAllUnreadChat() { $stmt = prepareQuery(" SELECT - LEFT(CONCAT(`user`.`fname`, ' ', `user`.`lname`), 15) AS `fullname`, + LEFT(CONCAT(`user`.`fname`, ' ', `user`.`lname`), 12) as `fullname`, `user`.`userID`, IFNULL( `profilepicture`, diff --git a/website/queries/settings.php b/website/queries/settings.php index 03f794f..dfd65a0 100644 --- a/website/queries/settings.php +++ b/website/queries/settings.php @@ -18,7 +18,8 @@ function getSettings() { `bio`, `profilepicture`, `showBday`, - `showEmail` + `showEmail`, + `showProfile` FROM `user` WHERE @@ -64,7 +65,8 @@ function updateSettings() { `birthdate` = :bday, `bio` = :bio, `showEmail` = :showEmail, - `showBday` = :showBday + `showBday` = :showBday, + `showProfile` = :showProfile WHERE `userID` = :userID "); @@ -79,6 +81,7 @@ function updateSettings() { $stmt->bindValue(":bio", test_input($_POST["bio"])); $stmt->bindValue(":showEmail", (array_key_exists("showEmail", $_POST) ? "1" : "0")); $stmt->bindValue(":showBday", (array_key_exists("showBday", $_POST) ? "1" : "0")); + $stmt->bindValue(":showProfile", (array_key_exists("showProfile", $_POST) ? "1" : "0")); $stmt->bindValue(":userID", $_SESSION["userID"]); $stmt->execute(); diff --git a/website/queries/user.php b/website/queries/user.php index 74b0aa1..972937d 100644 --- a/website/queries/user.php +++ b/website/queries/user.php @@ -52,6 +52,10 @@ function selectUser($me, $other) { `username`, `birthdate`, `location`, + `showBday`, + `showEmail`, + `showProfile`, + `email`, IFNULL( `profilepicture`, '../img/avatar-standard.png' @@ -209,7 +213,9 @@ function search20UsersFromNByStatus($n, $keyword, $status) { return $q; } -function searchSomeUsersByStatus($n, $m, $keyword, $status) { +function searchSomeUsersByStatus($n, $m, $search, $status) { +// parentheses not needed in where clause, for clarity as +// role search should override status filter. $q = prepareQuery(" SELECT `userID`, @@ -223,8 +229,9 @@ function searchSomeUsersByStatus($n, $m, $keyword, $status) { FROM `user` WHERE - `username` LIKE :keyword AND - FIND_IN_SET (`role`, :statuses) + (`username` LIKE :keyword AND + FIND_IN_SET (`role`, :statuses)) OR + `role` = :search ORDER BY `role`, `username` @@ -232,8 +239,9 @@ function searchSomeUsersByStatus($n, $m, $keyword, $status) { :n, :m "); - $keyword = "%$keyword%"; + $keyword = "%$search%"; $q->bindParam(':keyword', $keyword); + $q->bindParam(':search', $search); $q->bindParam(':n', $n, PDO::PARAM_INT); $q->bindParam(':m', $m, PDO::PARAM_INT); $statuses = implode(',', $status); @@ -242,22 +250,24 @@ function searchSomeUsersByStatus($n, $m, $keyword, $status) { return $q; } -function countSomeUsersByStatus($keyword, $status) { +function countSomeUsersByStatus($search, $status) { $q = prepareQuery(" SELECT COUNT(*) FROM `user` WHERE - `username` LIKE :keyword AND - FIND_IN_SET (`role`, :statuses) + (`username` LIKE :keyword AND + FIND_IN_SET (`role`, :statuses)) OR + `role` = :search ORDER BY `role`, `username` "); - $keyword = "%$keyword%"; + $keyword = "%$search%"; $q->bindParam(':keyword', $keyword); + $q->bindParam(':search', $search); $statuses = implode(',', $status); $q->bindParam(':statuses', $statuses); $q->execute(); @@ -349,12 +359,13 @@ function searchSomeUsers($n, $m, $search) { $stmt = prepareQuery(" SELECT `userID`, + LEFT(`username`, 12) as `usernameshort`, `username`, IFNULL( `profilepicture`, '../img/avatar-standard.png' ) AS profilepicture, - LEFT(CONCAT(`user`.`fname`, ' ', `user`.`lname`), 15) as `fullname`, + LEFT(CONCAT(`user`.`fname`, ' ', `user`.`lname`), 12) as `fullname`, CASE `lastactivity` >= DATE_SUB(NOW(),INTERVAL 15 MINUTE) WHEN TRUE THEN 'online' WHEN FALSE THEN 'offline' diff --git a/website/views/group.php b/website/views/group.php index aaec353..b27f18c 100644 --- a/website/views/group.php +++ b/website/views/group.php @@ -1,12 +1,17 @@
    -
    - -
    -

    -

    - +
    + ">
    +
    +
    + +
    +
    +
    +

    + +
    +
    -

    Leden ()

    diff --git a/website/views/head.php b/website/views/head.php index 284abb4..c4d13a5 100644 --- a/website/views/head.php +++ b/website/views/head.php @@ -1,4 +1,8 @@ - + + + + + MyHyvesbook+ diff --git a/website/views/notification-center.php b/website/views/notification-center.php index 7bd03ea..f6f4a03 100644 --- a/website/views/notification-center.php +++ b/website/views/notification-center.php @@ -14,7 +14,7 @@ echo ""; } ?> - +

    diff --git a/website/views/post-view.php b/website/views/post-view.php index 11a985a..f8fe902 100644 --- a/website/views/post-view.php +++ b/website/views/post-view.php @@ -2,11 +2,17 @@ $postID = $_GET['postID']; $post = selectPostById($postID)->fetch(PDO::FETCH_ASSOC); $fullname = $post['fname'] . " " . $post['lname'] . " (" . $post['username'] . ")"; -session_start(); ?>

    -
    verwijder post
    + +
    +

      +
    • Leeftijd: jaar
    • + + +
    • Email:
    • +
    • Locatie:
    • Lid sinds:
    diff --git a/website/views/search-view.php b/website/views/search-view.php index e42f985..f00fd3c 100644 --- a/website/views/search-view.php +++ b/website/views/search-view.php @@ -48,7 +48,12 @@ $group_n = ($group_currentpage - 1) * $group_perpage; - diff --git a/website/views/settings-view.php b/website/views/settings-view.php index e3cfd36..cf5317f 100644 --- a/website/views/settings-view.php +++ b/website/views/settings-view.php @@ -17,6 +17,7 @@ $settings = getSettings(); " @@ -27,6 +28,7 @@ $settings = getSettings(); " > @@ -36,6 +38,7 @@ $settings = getSettings(); " > @@ -96,6 +99,14 @@ $settings = getSettings(); >
  • +
  • + + + > +