Merge branch 'master' into joey-testing
This commit is contained in:
20
website/public/API/deletePost.php
Normal file
20
website/public/API/deletePost.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
session_start();
|
||||
|
||||
require_once "../../queries/post.php";
|
||||
require_once "../../queries/user.php";
|
||||
|
||||
if (isset($_SESSION["userID"]) and
|
||||
getRoleByID($_SESSION["userID"]) != 'frozen' and
|
||||
getRoleByID($_SESSION["userID"]) != 'banned') {
|
||||
|
||||
if (empty($_POST["postID"]) or empty($_SESSION["userID"])) {
|
||||
header('HTTP/1.1 500 Non enough arguments');
|
||||
}
|
||||
|
||||
deletePost($_POST["postID"], $_SESSION["userID"]);
|
||||
return;
|
||||
|
||||
} else {
|
||||
echo "frozen";
|
||||
}
|
||||
@@ -1,8 +1,13 @@
|
||||
<?php
|
||||
|
||||
if(empty($_POST["usr"]) and empty($_POST["grp"])) {
|
||||
header('HTTP/1.1 500 Non enough arguments');
|
||||
if(!isset($_POST["offset"]) or !isset($_POST["limit"])) {
|
||||
header('HTTP/1.1 500 Not enough arguments');
|
||||
}
|
||||
if(!isset($_POST["usr"]) and !isset($_POST["grp"])) {
|
||||
header('HTTP/1.1 500 Not enough arguments');
|
||||
}
|
||||
|
||||
session_start();
|
||||
|
||||
require_once ("../../queries/post.php");
|
||||
require_once ("../../queries/nicetime.php");
|
||||
@@ -10,24 +15,23 @@ require_once("../../queries/user.php");
|
||||
|
||||
if (isset($_SESSION["userID"]) &&
|
||||
getRoleByID($_SESSION["userID"]) != 'banned') {
|
||||
|
||||
if (empty($_POST["usr"])) {
|
||||
$posts = selectAllPosts(0, $_POST["grp"]);
|
||||
if(empty($_POST["usr"])) {
|
||||
$posts = selectSomePosts(0, $_POST["grp"], $_POST["offset"], $_POST["limit"]);
|
||||
} else {
|
||||
$posts = selectAllPosts($_POST["usr"], 0);
|
||||
$posts = selectSomePosts($_POST["usr"], 0, $_POST["offset"], $_POST["limit"]);
|
||||
}
|
||||
|
||||
if (!$posts) {
|
||||
header('HTTP/1.1 500 Query failed');
|
||||
if(!$posts) {
|
||||
echo false;
|
||||
} else {
|
||||
$results = $posts->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
for($i = 0; $i < sizeof($results); $i++) {
|
||||
$results[$i]["nicetime"] = nicetime($results[$i]["creationdate"]);
|
||||
}
|
||||
|
||||
echo json_encode($results);
|
||||
}
|
||||
|
||||
$results = $posts->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
for ($i = 0; $i < sizeof($results); $i++) {
|
||||
$results[$i]["nicetime"] = nicetime($results[$i]["creationdate"]);
|
||||
}
|
||||
|
||||
echo json_encode($results);
|
||||
} else {
|
||||
header('HTTP/1.0 403 Forbidden');
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
session_start();
|
||||
|
||||
require_once("../../queries/connect.php");
|
||||
require_once("../../queries/post.php");
|
||||
require_once("../../queries/checkInput.php");
|
||||
|
||||
BIN
website/public/img/nietslecht_small.png
Normal file
BIN
website/public/img/nietslecht_small.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 25 KiB |
@@ -17,12 +17,10 @@ $(window).on("load", function () {
|
||||
because serialize doesn't take submit values. */
|
||||
$('#admin-batchform > button').click(function () {
|
||||
$('#batchinput').prop('value', $(this).prop('value'));
|
||||
console.log($('#batchinput').prop('value'));
|
||||
});
|
||||
|
||||
$('#admin-groupbatchform > button').click(function () {
|
||||
$('#groupbatchinput').prop('value', $(this).prop('value'));
|
||||
console.log($('#batchinput').prop('value'));
|
||||
});
|
||||
});
|
||||
|
||||
@@ -67,7 +65,6 @@ function searchFromOne() {
|
||||
}
|
||||
|
||||
function adminSearch() {
|
||||
console.log($("#admin-searchform").serialize());
|
||||
$.post(
|
||||
"API/adminSearchUsers.php",
|
||||
$("#admin-searchform").serialize()
|
||||
|
||||
@@ -49,7 +49,6 @@ function addMessages(messages) {
|
||||
// Initialize message variables
|
||||
var thisDate = new Date(messages[i].creationdate.replace(/ /,"T"));
|
||||
var thisTime = thisDate.getHours() + ":" + thisDate.getMinutes();
|
||||
console.log(thisDate);
|
||||
var type;
|
||||
thisDate.setHours(0,0,0,0);
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@ function placeGroupButtons() {
|
||||
.done(function() {
|
||||
$buttonContainer.children().remove();
|
||||
placeGroupButtons();
|
||||
updateMenus();
|
||||
}).fail(function() {
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,40 +1,55 @@
|
||||
$(document).ready(function() {
|
||||
// Toggle menu
|
||||
$("#own-profile-picture, #open-notifications").click(function() {
|
||||
if ($("#notification-center").css('display') == "none") {
|
||||
// Make the menu visible and move the content to the left.
|
||||
$(".modal").width("calc(100% - 512px)");
|
||||
$(".content").css("margin-right", "256px");
|
||||
$("#notification-center").css("right", "0px");
|
||||
$("#notification-center").css("display", "block");
|
||||
$("#contact-menu").css("display", "block");
|
||||
if ($("#notification-center").css('display') == "none") {
|
||||
// Make the menu visible and move the content to the left.
|
||||
$(".modal").width("calc(100% - 512px)");
|
||||
$(".content").css("margin-right", "256px");
|
||||
$("#notification-center").css("right", "0px");
|
||||
$("#notification-center").css("display", "block");
|
||||
$("#contact-menu").css("display", "block");
|
||||
|
||||
// Add cookie so the menu stays open on other pages
|
||||
if (window.innerWidth > 1080) {
|
||||
$("#chat-history").width("calc(100% - 587px)");
|
||||
document.cookie = "menu=open; path=/";
|
||||
} else {
|
||||
document.cookie = "menu=closed; path=/";
|
||||
}
|
||||
// Add cookie so the menu stays open on other pages
|
||||
if (window.innerWidth > 1080) {
|
||||
$("#chat-history").css("margin-right", "266px");
|
||||
$("#chat-history").css("width", "calc(100% - 512px - 75px)");
|
||||
document.cookie = "menu=open; path=/";
|
||||
} else {
|
||||
$(".modal").width("calc(100% - 256px)");
|
||||
$(".content").css("margin-right", "0px");
|
||||
$("#notification-center").css("display", "none");
|
||||
|
||||
if (window.innerWidth > 1080) {
|
||||
$("#chat-history").width("calc(100% - 331px)");
|
||||
} else {
|
||||
// Make the menu invisible and move the content to the right.
|
||||
$("#contact-menu").css("display", "none");
|
||||
}
|
||||
|
||||
// Change menu cookie to close
|
||||
document.cookie = "menu=closed; path=/";
|
||||
|
||||
}
|
||||
} else {
|
||||
$(".modal").width("calc(100% - 256px)");
|
||||
$(".content").css("margin-right", "0px");
|
||||
$("#notification-center").css("display", "none");
|
||||
|
||||
if (window.innerWidth > 1080) {
|
||||
$("#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");
|
||||
}
|
||||
|
||||
// Change menu cookie to close
|
||||
document.cookie = "menu=closed; path=/";
|
||||
}
|
||||
});
|
||||
|
||||
if (getCookie("menu") == "open") {
|
||||
$("#own-profile-picture").click();
|
||||
// Make the menu visible and move the content to the left.
|
||||
$(".modal").width("calc(100% - 512px)");
|
||||
$(".content").css("margin-right", "256px");
|
||||
$("#notification-center").css("right", "0px");
|
||||
$("#notification-center").css("display", "block");
|
||||
$("#contact-menu").css("display", "block");
|
||||
|
||||
// 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 {
|
||||
document.cookie = "menu=closed; path=/";
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -53,6 +53,7 @@ function editFriendship(userID, value) {
|
||||
$.post("API/editFriendship.php", { usr: userID, action: value })
|
||||
.done(function() {
|
||||
placeFriendButtons();
|
||||
updateMenus();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -94,13 +95,3 @@ function showGroups(groups, list) {
|
||||
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("");
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -45,24 +45,49 @@ function postPost() {
|
||||
|
||||
}
|
||||
|
||||
$(window).on("load", function() {
|
||||
$(".modal-close").click(function () {
|
||||
$(".modal").hide();
|
||||
scrollbarMargin(0, 'auto');
|
||||
$('#modal-response').hide();
|
||||
$('.modal-default').show();
|
||||
});
|
||||
var masonryMode = 0;
|
||||
var windowWidth;
|
||||
var columnCount;
|
||||
var columns;
|
||||
var postLimit;
|
||||
var postAmount = 0;
|
||||
var noposts = false;
|
||||
|
||||
$(document).ready(function () {
|
||||
windowWidth = $(window).width();
|
||||
columnCount = Math.floor($(".posts").width() / 250);
|
||||
columns = new Array(columnCount);
|
||||
postLimit = columnCount * 7;
|
||||
});
|
||||
|
||||
var masonryMode = 0;
|
||||
var windowWidth = $(window).width();
|
||||
$(window).on("load", function() {
|
||||
$(".modal-close").click(function (){closeModal()});
|
||||
|
||||
// http://stackoverflow.com/questions/9439725/javascript-how-to-detect-if-browser-window-is-scrolled-to-bottom
|
||||
window.onscroll = function(ev) {
|
||||
if($(window).scrollTop() + $(window).height() == $(document).height() ) {
|
||||
loadMorePosts(userID, groupID, postAmount, postLimit);
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
function closeModal() {
|
||||
$(".modal").hide();
|
||||
scrollbarMargin(0, 'auto');
|
||||
$('#modal-response').hide();
|
||||
$('.modal-default').show();
|
||||
}
|
||||
|
||||
$(window).resize(function() {
|
||||
clearTimeout(window.resizedFinished);
|
||||
window.resizeFinished = setTimeout(function() {
|
||||
if ($(window).width() != windowWidth) {
|
||||
windowWidth = $(window).width();
|
||||
masonry(masonryMode);
|
||||
|
||||
if (columnCount != Math.floor($(".posts").width() / 250)) {
|
||||
columnCount = Math.floor($(".posts").width() / 250);
|
||||
masonry(masonryMode);
|
||||
}
|
||||
}
|
||||
}, 250);
|
||||
});
|
||||
@@ -72,12 +97,10 @@ var $container = $(".posts");
|
||||
function masonry(mode) {
|
||||
masonryMode = mode;
|
||||
$container.children().remove();
|
||||
columnCount = Math.floor($(".posts").width() / 250);
|
||||
|
||||
/*
|
||||
* Initialise columns.
|
||||
*/
|
||||
var columns = new Array(columnCount);
|
||||
|
||||
for (i = 0; i < columnCount; i++) {
|
||||
$column = $("<div class=\"column\">");
|
||||
@@ -106,38 +129,61 @@ function masonry(mode) {
|
||||
/*
|
||||
* Function will find the column with the shortest height.
|
||||
*/
|
||||
function getShortestColumn(columns) {
|
||||
column = columns[0];
|
||||
|
||||
for (i = 1; i < columnCount; i++) {
|
||||
if (column[0] > columns[i][0]) {
|
||||
column = columns[i];
|
||||
}
|
||||
}
|
||||
return column;
|
||||
}
|
||||
|
||||
/*
|
||||
* Get the posts from the server.
|
||||
*/
|
||||
$.post("API/getPosts.php", { usr : userID, grp : groupID })
|
||||
.done(function(data) {
|
||||
posts = JSON.parse(data);
|
||||
|
||||
/*
|
||||
* Rearange the objects.
|
||||
*/
|
||||
$.each(posts, function() {
|
||||
$post = $("<div class=\"post platform\" onclick=\"requestPost(\'"+this['postID']+"\')\">");
|
||||
$post.append($("<h2>").html(this["title"]));
|
||||
$post.append($("<p>").html(fancyText(this["content"])));
|
||||
$post.append($("<p class=\"subscript\">").text(this["nicetime"]));
|
||||
$post.append($("<p class=\"subscript\">").text("comments: " + this["comments"] + ", niet slechts: " + this["niet_slechts"]));
|
||||
|
||||
shortestColumn = getShortestColumn(columns);
|
||||
shortestColumn[1].append($post);
|
||||
shortestColumn[0] = shortestColumn[0] + $post.height() + margin;
|
||||
});
|
||||
});
|
||||
loadMorePosts(userID, groupID, 0, postLimit);
|
||||
}
|
||||
|
||||
function getShortestColumn(columns) {
|
||||
column = columns[0];
|
||||
|
||||
for (i = 1; i < columnCount; i++) {
|
||||
if (column[0] > columns[i][0]) {
|
||||
column = columns[i];
|
||||
}
|
||||
}
|
||||
return column;
|
||||
}
|
||||
|
||||
function loadMorePosts(uID, gID, offset, limit) {
|
||||
if (noposts) {
|
||||
return;
|
||||
}
|
||||
|
||||
console.log(uID, gID, offset, limit);
|
||||
|
||||
|
||||
$.post("API/getPosts.php", { usr : uID,
|
||||
grp : gID,
|
||||
offset : offset,
|
||||
limit : limit})
|
||||
.done(function(data) {
|
||||
if (!data) {
|
||||
$('.noposts').show();
|
||||
noposts = true;
|
||||
return;
|
||||
}
|
||||
|
||||
posts = JSON.parse(data);
|
||||
|
||||
/*
|
||||
* Rearange the objects.
|
||||
*/
|
||||
$.each(posts, function() {
|
||||
$post = $("<div class=\"post platform\" onclick=\"requestPost(\'"+this['postID']+"\')\">");
|
||||
$post.append($("<h2>").html(this["title"]));
|
||||
$post.append($("<p>").html(fancyText(this["content"])));
|
||||
$post.append($("<p class=\"subscript\">").text(this["nicetime"]));
|
||||
$post.append($("<p class=\"subscript\">").text("comments: " + this["comments"] + ", niet slechts: " + this["niet_slechts"]));
|
||||
|
||||
shortestColumn = getShortestColumn(columns);
|
||||
shortestColumn[1].append($post);
|
||||
shortestColumn[0] = shortestColumn[0] + $post.height() + margin;
|
||||
});
|
||||
});
|
||||
|
||||
postAmount += limit;
|
||||
}
|
||||
@@ -2,92 +2,125 @@ var menuFriendsData;
|
||||
var menuGroupsData;
|
||||
var notificationMessagesData;
|
||||
var notificationRequestsData;
|
||||
var updatingMenus = 0;
|
||||
|
||||
|
||||
// On document load, load menus and loops loading menus every 10 seconds.
|
||||
$(document).ready(function() {
|
||||
loadMenuFriends(5);
|
||||
loadNotificationFriends();
|
||||
loadUnreadMessages();
|
||||
loadMenuGroups();
|
||||
setInterval(updateMenus, 3000);
|
||||
updateMenus();
|
||||
setInterval(updateMenus, 10000);
|
||||
});
|
||||
|
||||
|
||||
// Update the menu and notification items.
|
||||
function updateMenus() {
|
||||
loadMenuFriends(5);
|
||||
loadNotificationFriends();
|
||||
loadUnreadMessages();
|
||||
loadMenuGroups();
|
||||
if (updatingMenus <= 0) {
|
||||
loadMenuFriends(5);
|
||||
loadNotificationFriends();
|
||||
loadUnreadMessages();
|
||||
loadMenuGroups();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 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 --;
|
||||
});
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
|
||||
function postComment(buttonValue) {
|
||||
formData = $("#newcommentform").serializeArray();
|
||||
formData.push({name: "button", value: buttonValue});
|
||||
@@ -20,3 +21,17 @@ function postComment(buttonValue) {
|
||||
$('#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);
|
||||
}
|
||||
@@ -56,5 +56,5 @@
|
||||
}
|
||||
|
||||
.bancommentform input[type="text"] {
|
||||
width: 100%;
|
||||
width: 80%;
|
||||
}
|
||||
@@ -14,7 +14,7 @@
|
||||
|
||||
/* Modal Content/Box */
|
||||
.modal-content {
|
||||
margin: 5% auto;
|
||||
margin: 50px auto;
|
||||
width: 70%; /* Could be more or less, depending on screen size */
|
||||
overflow-y: auto;
|
||||
}
|
||||
@@ -84,3 +84,20 @@
|
||||
height: 24px;
|
||||
width: 24px;
|
||||
}
|
||||
|
||||
.deleteButton {
|
||||
background-color: firebrick;
|
||||
|
||||
}
|
||||
|
||||
.deleteButton i {
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
.deleteButton:hover span {
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
.deleteButton span {
|
||||
display: none;
|
||||
}
|
||||
@@ -123,6 +123,11 @@ div.posts .post form textarea.newpost {
|
||||
font-size: 0.8em;
|
||||
}
|
||||
|
||||
.noposts {
|
||||
display: none;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
@media only screen and (max-width: 1500px) {
|
||||
.post-box {
|
||||
width: calc(50% - 68px);
|
||||
|
||||
@@ -193,7 +193,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`,
|
||||
@@ -203,16 +205,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);
|
||||
@@ -221,21 +225,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();
|
||||
|
||||
@@ -46,6 +46,57 @@ function selectAllPosts($userID, $groupID) {
|
||||
|
||||
}
|
||||
|
||||
function selectSomePosts($userID, $groupID, $offset, $limit) {
|
||||
$stmt = prepareQuery("
|
||||
SELECT
|
||||
`post`.`postID`,
|
||||
`post`.`author`,
|
||||
`title`,
|
||||
CASE LENGTH(`post`.`content`) >= 150 AND `post`.`content` NOT LIKE '<img%'
|
||||
WHEN TRUE THEN
|
||||
CONCAT(LEFT(`post`.`content`, 150), '...')
|
||||
WHEN FALSE THEN
|
||||
`post`.`content`
|
||||
END
|
||||
AS `content`,
|
||||
`post`.`creationdate`,
|
||||
COUNT(DISTINCT `commentID`) AS `comments`,
|
||||
COUNT(DISTINCT `niet_slecht`.`postID`) AS `niet_slechts`
|
||||
FROM
|
||||
`post`
|
||||
LEFT JOIN
|
||||
`niet_slecht`
|
||||
ON
|
||||
`post`.`postID` = `niet_slecht`.`postID`
|
||||
LEFT JOIN
|
||||
`comment`
|
||||
ON
|
||||
`post`.`postID` = `comment`.`postID`
|
||||
WHERE
|
||||
`post`.`author` = :userID AND
|
||||
`groupID` IS NULL OR
|
||||
`groupID` = :groupID
|
||||
GROUP BY
|
||||
`post`.`postID`
|
||||
ORDER BY
|
||||
`post`.`creationdate` DESC
|
||||
LIMIT
|
||||
:offset, :limit
|
||||
");
|
||||
$stmt->bindParam(':userID', $userID, PDO::PARAM_INT);
|
||||
$stmt->bindParam(':groupID', $groupID , PDO::PARAM_INT);
|
||||
$stmt->bindParam(':offset', intval($offset), PDO::PARAM_INT);
|
||||
$stmt->bindParam(':limit', intval($limit), PDO::PARAM_INT);
|
||||
if(!$stmt->execute()) {
|
||||
return False;
|
||||
}
|
||||
if($stmt->rowCount() == 0) {
|
||||
return False;
|
||||
}
|
||||
return $stmt;
|
||||
|
||||
}
|
||||
|
||||
function selectPostById($postID) {
|
||||
$stmt = prepareQuery("
|
||||
SELECT
|
||||
@@ -192,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"];
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -205,7 +205,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`,
|
||||
@@ -219,8 +221,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`
|
||||
@@ -228,8 +231,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);
|
||||
@@ -238,22 +242,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();
|
||||
|
||||
@@ -2,23 +2,28 @@
|
||||
$postID = $_GET['postID'];
|
||||
$post = selectPostById($postID)->fetch(PDO::FETCH_ASSOC);
|
||||
$fullname = $post['fname'] . " " . $post['lname'] . " (" . $post['username'] . ")";
|
||||
session_start();
|
||||
|
||||
echo("
|
||||
?>
|
||||
<div class='post-header header'>
|
||||
<h4>" . $post['title'] . "</h4>
|
||||
<h4><?=$post['title']?></h4>
|
||||
<?php if (checkPermissionOnPost($postID, $_SESSION["userID"])) {?>
|
||||
<button class="deleteButton"
|
||||
onclick="deletePost('<?=$postID?>')"
|
||||
type="submit">
|
||||
<i class="fa fa-trash"></i>
|
||||
<span>Verwijder post</span>
|
||||
</button><br />
|
||||
<?php } ?>
|
||||
<span class='postinfo'>
|
||||
gepost door $fullname,
|
||||
<span class='posttime' title='" . $post['creationdate'] . "'>
|
||||
" . nicetime($post['creationdate']) . "
|
||||
gepost door <?=$fullname?>,
|
||||
<span class='posttime' title='<?=$post['creationdate']?>'>
|
||||
<?=nicetime($post['creationdate'])?>
|
||||
</span>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div class='post-content'>
|
||||
<p>" . $post['content'] . "</p>
|
||||
<p><?=$post['content']?></p>
|
||||
</div>
|
||||
"); ?>
|
||||
|
||||
<div class='post-comments'>
|
||||
<div class="commentfield">
|
||||
|
||||
@@ -71,6 +71,10 @@
|
||||
|
||||
</div>
|
||||
|
||||
<div class="noposts platform">
|
||||
<p>Geen posts meer!</p>
|
||||
</div>
|
||||
|
||||
<div class="modal">
|
||||
<div class="modal-content platform">
|
||||
<div class="modal-close">
|
||||
|
||||
@@ -96,6 +96,14 @@ $settings = getSettings();
|
||||
<?=($settings["showEmail"] ? "checked" : "")?>
|
||||
>
|
||||
</li>
|
||||
<li>
|
||||
<label for="showProfile">Publiek profiel</label>
|
||||
<input type="checkbox"
|
||||
name="showProfile"
|
||||
id="showProfile"
|
||||
<?=($settings["showProfile"] ? "checked" : "")?>
|
||||
>
|
||||
</li>
|
||||
<li>
|
||||
<label for="bio">Bio</label>
|
||||
<textarea name="bio"
|
||||
|
||||
Reference in New Issue
Block a user