diff --git a/website/public/.htaccess b/website/public/.htaccess index f08898a..5b6a2ef 100644 --- a/website/public/.htaccess +++ b/website/public/.htaccess @@ -1,7 +1,7 @@ Options +FollowSymLinks RewriteEngine On -ErrorDocument 404 /error404.jpg +ErrorDocument 404 /error/404.php RewriteCond %{SCRIPT_FILENAME} !-d RewriteCond %{SCRIPT_FILENAME} !-f diff --git a/website/public/API/adminChangeUser.php b/website/public/API/adminChangeUser.php new file mode 100644 index 0000000..6ec50c9 --- /dev/null +++ b/website/public/API/adminChangeUser.php @@ -0,0 +1,25 @@ +bindParam(":postID", $postID); + $stmt->execute(); + return $stmt->rowCount(); +} + +function getNietSlechtUsersForPost(int $postID) { + $stmt = prepareQuery(" + 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 5fd48b5..3864cc8 100644 --- a/website/public/API/postComment.php +++ b/website/public/API/postComment.php @@ -2,17 +2,36 @@ session_start(); -require("../../queries/post.php"); -require("../../queries/connect.php"); -require("../../queries/checkInput.php"); -if (empty($_POST['newcomment-content'])) { - echo 0; -} else { - if(makeComment(test_input($_POST['postID']), - $_SESSION['userID'], - test_input($_POST['newcomment-content']))) { - echo 1; +require_once("../../queries/post.php"); +require_once("../../queries/connect.php"); +require_once("../../queries/checkInput.php"); +require_once("../../queries/user.php"); + + +if (isset($_SESSION["userID"]) && + getRoleByID($_SESSION["userID"]) != 'frozen' && + getRoleByID($_SESSION["userID"]) != 'banned') { + 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; } +} else { + echo "frozen"; } \ No newline at end of file diff --git a/website/public/API/postPost.php b/website/public/API/postPost.php index b52e96b..7a33857 100644 --- a/website/public/API/postPost.php +++ b/website/public/API/postPost.php @@ -2,16 +2,53 @@ session_start(); -require("../../queries/post.php"); -require("../../queries/connect.php"); -require("../../queries/checkInput.php"); +require_once("../../queries/post.php"); +require_once("../../queries/group_page.php"); +require_once("../../queries/connect.php"); +require_once("../../queries/checkInput.php"); -if (empty($_POST['newpost-title'])) { -} else { - makePost($_SESSION['userID'], - null, - test_input($_POST['newpost-title']), - test_input($_POST['newpost-content'])); +if (empty($_POST["title"]) or + empty($_POST["content"]) or + empty($_SESSION["userID"])) { + header('HTTP/1.1 500 Non enough arguments'); } -header("Location: ../profile.php"); \ No newline at end of file +if (empty($_POST["group"])) { + // User Post + makePost( + $_SESSION["userID"], + null, + test_input($_POST["title"]), + test_input($_POST["content"]) + ); +} else { + // Group Post + + // Check if the user is an admin or mod of the group. + if(!in_array(selectGroupRole($_POST["group"]), array('mod', 'admin'))) { + header('HTTP/1.1 500 Non enough rights'); + return; + } + + makePost( + $_SESSION["userID"], + $_POST["group"], + test_input($_POST["title"]), + test_input($_POST["content"]) + ); +} + + + + + + +//if (empty($_POST['newpost-title'])) { +//} else { +// makePost($_SESSION['userID'], +// null, +// test_input($_POST['newpost-title']), +// test_input($_POST['newpost-content'])); +//} +// +//header("Location: ../profile.php"); \ No newline at end of file diff --git a/website/public/API/searchPageNumber.php b/website/public/API/searchPageNumber.php new file mode 100644 index 0000000..4a76516 --- /dev/null +++ b/website/public/API/searchPageNumber.php @@ -0,0 +1,41 @@ +fetchColumn(); +$group_count = countSomeGroups($search)->fetchColumn(); + +$filter = "all"; +if (isset($_POST['filter'])) { + $filter = test_input($_POST['filter']); +} + +$option = "user"; +if (isset($_POST['option'])) { + $option = test_input($_POST['option']); +} + +include ("../../views/searchPageNumber.php"); diff --git a/website/public/API/searchUsers.php b/website/public/API/searchUsers.php index 15b03ed..f431f88 100644 --- a/website/public/API/searchUsers.php +++ b/website/public/API/searchUsers.php @@ -8,13 +8,15 @@ require_once ("../../queries/friendship.php"); require_once ("../../queries/user.php"); $n = 0; -if (isset($_POST["n"])) { - $n = (int) test_input($_POST["n"]); -} $m = 20; -if (isset($_POST["m"])) { - $m = (int) test_input($_POST["m"]); + +$page = 1; +if (isset($_POST["user-pageselect"])) { + $page = (int) test_input($_POST['user-pageselect']); } + +$n = ($page - 1) * $m; + $search = ""; if (isset($_POST["search"])) { $search = test_input($_POST["search"]); diff --git a/website/public/API/sendMessage.php b/website/public/API/sendMessage.php index c5d47d1..2d0b092 100644 --- a/website/public/API/sendMessage.php +++ b/website/public/API/sendMessage.php @@ -4,14 +4,22 @@ session_start(); require_once("../../queries/connect.php"); require_once("../../queries/private_message.php"); require_once("../../queries/checkInput.php"); +require_once("../../queries/user.php"); -if (!empty(test_input($_POST["destination"])) && - !empty(test_input($_POST["content"]))) { - if (sendMessage(test_input($_POST["destination"]), test_input($_POST["content"]))) { - echo 1; +if (isset($_SESSION["userID"]) && + getRoleByID($_SESSION["userID"]) != 'frozen' && + getRoleByID($_SESSION["userID"]) != 'banned') { + if (!empty(test_input($_POST["destination"])) && + !empty(test_input($_POST["content"])) + ) { + if (sendMessage(test_input($_POST["destination"]), test_input($_POST["content"]))) { + echo 1; + } else { + echo 0; + } } else { echo 0; } } else { - echo 0; + echo "frozen"; } \ No newline at end of file diff --git a/website/public/admin.php b/website/public/admin.php index 5faa096..ddcbbf2 100644 --- a/website/public/admin.php +++ b/website/public/admin.php @@ -1,10 +1,14 @@ - + + $friend) { $friendshipStatus = getFriendshipStatus($friend->userID); ?> -
  • +
  • ")); - } else if(friendshipStatus == 1) { - $buttonContainer.append($("")); - } else if(friendshipStatus == 2) { - $buttonContainer.append($("")); - } else if(friendshipStatus == 3) { - $buttonContainer.append($("")); - $buttonContainer.append($("")); - } + var friendshipStatus = data; + var $buttonContainer = $("div.friend-button-container"); + $("#start-profile-chat").hide(); + $buttonContainer.html(""); + var value1 = ""; + var class1 = "empty-button"; + var icon1 = ""; + var text1 = ""; + + var value2 = ""; + var class2 = "empty-button"; + var icon2 = ""; + var text2 = ""; + + switch (friendshipStatus) { + case "0": + value1 = "request"; + class1 = "green"; + text1 = "Bevriend"; + icon1 = "fa-handshake-o"; + break; + case "1": + value1 = userID; + class1 = "green"; + text1 = "Chat"; + icon1 = "fa-comment-o"; + value2 = "delete"; + class2 = "red"; + text2 = "Verwijder"; + icon2 = "fa-times"; + break; + case "2": + value1 = "delete"; + class1 = "red"; + text1 = "Trek verzoek in"; + icon1 = "fa-cross"; + break; + case "3": + value1 = "accept"; + class1 = "green"; + text1 = "Accepteer"; + icon1 = "fa-check"; + value2 = "delete"; + class2 = "red"; + text2 = "Weiger"; + icon2 = "fa-times"; + break; + } + + $buttonContainer.append( + ""); + $buttonContainer.append( + ""); + $buttonContainer.children().click(function() { - editFriendship(userID, this.value); + if (isNaN(this.value)) + editFriendship(userID, this.value); + else if (this.value != "") + window.location.href = "chat.php?username=" + this.value; }); }); } \ No newline at end of file diff --git a/website/public/js/header.js b/website/public/js/header.js index 9889bdb..13e3e12 100644 --- a/website/public/js/header.js +++ b/website/public/js/header.js @@ -1,19 +1,40 @@ $(document).ready(function() { - // Toggle menu $("#own-profile-picture, #open-notifications").click(function() { - if ($("#notification-center").css('right') == "-256px") { - // Make the menu visible and move the content to the left. - $("#chat-history").width("calc(100% - 587px)"); - $(".modal").width("calc(100% - 512px)"); - $(".content").css("margin-right", "256px"); - $("#notification-center").css("right", "0px"); - } else { - // Make the menu invisible and move the content to the right. - $("#chat-history").width("calc(100% - 331px)"); - $(".modal").width("calc(100% - 256px)"); - $(".content").css("margin-right", "0px"); - $("#notification-center").css("right", "-256px"); - } + 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=/"; + } + } 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=/"; + + } }); + + if (getCookie("menu") == "open") { + $("#own-profile-picture").click(); + } }); diff --git a/website/public/js/main.js b/website/public/js/main.js index 8a52797..2983fdb 100644 --- a/website/public/js/main.js +++ b/website/public/js/main.js @@ -1,3 +1,54 @@ +var days = ["zondag", "maandag", "dinsdag", "woensdag", "donderdag", "vrijdag", "zaterdag"]; +var months = ["januari", "februari", "maart", "april", "mei", "juni", "juli", "augustus", "september", "oktober", "november", "december"] + +function fancyText(text) { + // Add links, images, gifs and (youtube) video's. + var regex = /(https?:\/\/.[^ <>"]*)/ig; + text = text.replace(regex, function(link) { + // Add images + if (link.match(/(https?:\/\/.[^ ]*\.(?:png|jpg|jpeg|gif))/ig)) { + return "" + link + ""; + } + // Add mp4 video's + else if (link.match(/(https?:\/\/.[^ ]*\.(?:mp4))/ig)) { + 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)) { + return ''; + } + // Add links + else { + return "" + link + ""; + } + }); + + return text; +} + +function getCookie(key) { + cookies = document.cookie.split("; "); + for (var i in cookies) { + cookie = cookies[i].split("="); + if (cookie[0] == key) { + return cookie[1]; + } + } + return false; +} + function editFriendship(userID, value) { $.post("API/editFriendship.php", { usr: userID, action: value }) .done(function() { @@ -42,4 +93,14 @@ function showGroups(groups, list) { } else { return false; } -} \ No newline at end of file +} + +$(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 diff --git a/website/public/js/masonry.js b/website/public/js/masonry.js index 7f6423e..b4370b7 100644 --- a/website/public/js/masonry.js +++ b/website/public/js/masonry.js @@ -19,10 +19,32 @@ function requestPost(postID) { var scrollBarWidth = window.innerWidth - document.body.offsetWidth; scrollbarMargin(scrollBarWidth, 'hidden'); $('#modal-response').show(); - $('#modal-response').html(data); + $('#modal-response').html(fancyText(data)); }); } +function postPost() { + title = $("input.newpost[name='title']").val(); + content = $("textarea.newpost[name='content']").val(); + + if (masonryMode == 2) { + $.post("API/postPost.php", { title: title, + content : content, + group : groupID }) + .done(function() { + masonry(masonryMode); + }); + } else { + $.post("API/postPost.php", { title: title, + content : content }) + .done(function() { + masonry(masonryMode); + }); + } + + +} + $(window).on("load", function() { $(".modal-close").click(function () { $(".modal").hide(); @@ -33,11 +55,15 @@ $(window).on("load", function() { }); var masonryMode = 0; +var windowWidth = $(window).width(); $(window).resize(function() { clearTimeout(window.resizedFinished); window.resizeFinished = setTimeout(function() { - masonry(masonryMode); + if ($(window).width() != windowWidth) { + windowWidth = $(window).width(); + masonry(masonryMode); + } }, 250); }); @@ -52,7 +78,7 @@ function masonry(mode) { * Initialise columns. */ var columns = new Array(columnCount); - var $columns = new Array(columnCount); + for (i = 0; i < columnCount; i++) { $column = $("
    "); $column.width(100/columnCount + "%"); @@ -60,19 +86,21 @@ function masonry(mode) { columns[i] = [0, $column]; } - if(mode == 1) { + if(mode > 0) { $postInput = $("
    "); - $form = $(""); + $form = $(""); $postInput.append($form); - $form.append($("")); - $form.append($("")); $form.append($("")); columns[0][1].append($postInput); - $postInput.on("load", function() { - columns[0][0] = $postInput.height() + margin; - }); + columns[0][0] = $postInput.height() + margin; } /* @@ -92,18 +120,19 @@ function masonry(mode) { /* * Get the posts from the server. */ - $.post("API/getPosts.php", { usr : userID }) + $.post("API/getPosts.php", { usr : userID, grp : groupID }) .done(function(data) { posts = JSON.parse(data); /* * Rearange the objects. */ - jQuery.each(posts, function() { + $.each(posts, function() { $post = $("
    "); - $post.append($("

    ").text(this["title"])); - $post.append($("

    ").html(this["content"])); + $post.append($("

    ").html(this["title"])); + $post.append($("

    ").html(fancyText(this["content"]))); $post.append($("

    ").text(this["nicetime"])); + $post.append($("

    ").text("comments: " + this["comments"] + ", niet slechts: " + this["niet_slechts"])); shortestColumn = getShortestColumn(columns); shortestColumn[1].append($post); diff --git a/website/public/js/post.js b/website/public/js/post.js index 62ace68..27bc34e 100644 --- a/website/public/js/post.js +++ b/website/public/js/post.js @@ -1,8 +1,14 @@ -function postComment() { +function postComment(buttonValue) { + formData = $("#newcommentform").serializeArray(); + formData.push({name: "button", value: buttonValue}); $.post( "API/postComment.php", - $("#newcommentform").serialize() - ); + formData + ).done(function (response) { + if (response == "frozen") { + alert("Je account is bevroren, dus je kan geen comments plaatsen of \"niet slechten\". Contacteer een admin als je denkt dat dit onjuist is."); + } + }); $("#newcomment").val(""); @@ -11,8 +17,6 @@ function postComment() { "API/loadPost.php", $("#newcommentform").serialize() ).done(function (data) { - $('#modal-response').html(data); + $('#modal-response').html(fancyText(data)); }); -} - - +} \ No newline at end of file diff --git a/website/public/js/registerAndLogin.js b/website/public/js/registerAndLogin.js index b2fda05..87522cf 100644 --- a/website/public/js/registerAndLogin.js +++ b/website/public/js/registerAndLogin.js @@ -1,5 +1,5 @@ function checkLoggedIn() { - if (confirm("You are already logged in!\nDo you want to logout?\nPress ok to logout.") == true) { + if (confirm("U bent al ingelogd!!\nWilt u uitloggen?\nKlik ok om uit te loggen.") == true) { window.location.href = "logout.php"; } else { window.location.href = "profile.php"; @@ -7,9 +7,9 @@ function checkLoggedIn() { } function bannedAlert(){ - alert("Your account is banned"); + alert("Uw account is geband!"); } function emailNotConfirmed(){ - alert("Your account has not been verified yet!\nAnother email has been sent to you") + alert("Uw account is nog niet bevestigd!\nEr is een nieuwe email gestuurd om uw account te bevestigen"); } diff --git a/website/public/js/search.js b/website/public/js/search.js index b3c322a..f7c4bbe 100644 --- a/website/public/js/search.js +++ b/website/public/js/search.js @@ -1,33 +1,41 @@ -function searchUsers(n, m) { +$(window).on('load', function () { + pageNumber(); +}); + +function searchUsers() { $.post( "API/searchUsers.php", - { - n: n, - m: m, - search: $("#search-input").val(), - filter: $("#search-filter").val() - } + $('#search-form').serialize() ).done(function(data) { - console.log(data); if (!showFriends(data, "#search-users-list", 0, "profile.php", "GET")) { $("#search-users-list").text("Niemand gevonden"); } }); } -function searchGroups(n, m) { +function searchGroups() { $.post( "API/searchGroups.php", - { - n: n, - m: m, - search: $("#search-input").val(), - filter: $("#search-filter").val() - } + $('#search-form').serialize() ).done(function(data) { - console.log(data); if (!showGroups(data, "#search-groups-list")) { $("#search-groups-list").text("Geen groepen gevonden"); } }); +} + +function pageNumber() { + var input = input2 = $('#search-form').serialize(); + $.post( + "API/searchPageNumber.php", + input + "&option=user" + ).done(function (data) { + $('#user-pageselect').html(data); + }); + $.post( + "API/searchPageNumber.php", + input2 + "&option=group" + ).done(function (data) { + $('#group-pageselect').html(data); + }); } \ No newline at end of file diff --git a/website/public/login.php b/website/public/login.php index 0515793..9fd7fb0 100644 --- a/website/public/login.php +++ b/website/public/login.php @@ -19,16 +19,24 @@ "; } + // define variables and set to empty values + $name = $surname = $bday = $username = $password = $confirmpassword = $location = $housenumber = $email = $confirmEmail = $captcha = $ip = ""; + $genericErr = $nameErr = $surnameErr = $bdayErr = $usernameErr = $passwordErr = $confirmpasswordErr = $locationErr = $housenumberErr = $emailErr = $confirmEmailErr = $captchaErr = ""; + $correct = true; + $day_date = "dag"; + $month_date = "maand"; + $year_date = "jaar"; + // Define variables and set to empty values - $uname = $psw =""; + $user = $psw = $remember =""; $loginErr = $resetErr =""; if ($_SERVER["REQUEST_METHOD"] == "POST") { switch ($_POST["submit"]) { case "login": try { - $uname = ($_POST["uname"]); - validateLogin($_POST["uname"], $_POST["psw"]); + $user = ($_POST["user"]); + validateLogin($_POST["user"], $_POST["psw"]); } catch(loginException $e) { $loginErr = $e->getMessage(); } @@ -46,19 +54,10 @@ "; } break; - + case "register": + include("register.php"); } } -// // Trying to login -// if ($_SERVER["REQUEST_METHOD"] == "POST") { -// try{ -// $uname = ($_POST["uname"]); -// validateLogin($_POST["uname"], $_POST["psw"]); -// } catch(loginException $e) { -// $loginErr = $e->getMessage(); -// } -// } - /* This view adds login view */ include("../views/login-view.php"); ?> diff --git a/website/public/profile.php b/website/public/profile.php index a79ad4c..05c661d 100644 --- a/website/public/profile.php +++ b/website/public/profile.php @@ -8,14 +8,16 @@ diff --git a/website/public/register(stash).php b/website/public/register(stash).php new file mode 100644 index 0000000..99ebc02 --- /dev/null +++ b/website/public/register(stash).php @@ -0,0 +1,116 @@ + + + + +getMessage(); + } + + try { + $surname = test_input(($_POST["surname"])); + checkInputChoice($surname, "lettersAndSpaces"); + } + catch(lettersAndSpacesException $e){ + $correct = false; + $surnameErr = $e->getMessage(); + } + + try{ + $day_date = test_input(($_POST["day_date"])); + $month_date = test_input(($_POST["month_date"])); + $year_date = test_input(($_POST["year_date"])); + $bday = $year_date . "-" . $month_date . "-" . $day_date; + checkInputChoice($bday, "bday"); + } catch(bdayException $e){ + $correct = false; + $bdayErr = $e->getMessage(); + } + + try{ + $username = str_replace(' ', '', test_input(($_POST["username"]))); + checkInputChoice($username, "username"); + } catch(usernameException $e){ + $correct = false; + $usernameErr = $e->getMessage(); + } + + try{ + $password = str_replace(' ', '', test_input(($_POST["password"]))); + checkInputChoice($password, "longerEight"); + matchPassword(); + } catch(passwordException $e){ + $correct = false; + $passwordErr = $e->getMessage(); + } catch(confirmPasswordException $e){ + $correct = false; + $confirmPasswordErr = $e->getMessage(); + } + + try{ + $location = test_input(($_POST["location"])); + checkInputChoice($location, "lettersAndSpaces"); + } catch(lettersAndSpacesException $e){ + $correct = false; + $locationErr = $e->getMessage(); + } + + try{ + $email = test_input(($_POST["email"])); + checkInputChoice($email, "email"); + $confirmEmail = test_input(($_POST["confirmEmail"])); + matchEmail(); + } catch(emailException $e){ + $correct = false; + $emailErr = $e->getMessage(); + } catch(confirmEmailException $e){ + $correct = false; + $confirmEmailErr = $e->getMessage(); + } + + try{ + $captcha = $_POST['g-recaptcha-response']; + checkCaptcha($captcha); + } catch(captchaException $e){ + $correct = false; + $captchaErr = $e->getMessage(); + } + + try { + getIp(); + registerCheck($correct); + sendConfirmEmailUsername($username); + } catch(registerException $e){ + $genericErr = $e->getMessage(); + } + } +/* This view adds register view */ +include("../views/register-view.php"); +?> + + diff --git a/website/public/register.php b/website/public/register.php index 1ce4817..6bebd7e 100644 --- a/website/public/register.php +++ b/website/public/register.php @@ -1,104 +1,91 @@ - - - -getMessage(); } - // define variables and set to empty values - $name = $surname = $bday = $username = $password = $confirmpassword = $location = $housenumber = $email = $captcha = $ip = ""; - $genericErr = $nameErr = $surnameErr = $bdayErr = $usernameErr = $passwordErr = $confirmpasswordErr = $locationErr = $housenumberErr = $emailErr = $captchaErr = ""; - $correct = true; - // Trying to register an account - if ($_SERVER["REQUEST_METHOD"] == "POST") { - try { - $name = test_input(($_POST["name"])); - checkInputChoice($name, "lettersAndSpaces"); - } catch(lettersAndSpacesException $e){ - $correct = false; - $nameErr = $e->getMessage(); - } - - try { - $surname = test_input(($_POST["surname"])); - checkInputChoice($surname, "lettersAndSpaces"); - } - catch(lettersAndSpacesException $e){ - $correct = false; - $surnameErr = $e->getMessage(); - } - - try{ - $bday = test_input(($_POST["bday"])); - checkInputChoice($bday, "bday"); - } catch(bdayException $e){ - $correct = false; - $bdayErr = $e->getMessage(); - } - - try{ - $username = str_replace(' ', '', test_input(($_POST["username"]))); - checkInputChoice($username, "username"); - } catch(usernameException $e){ - $correct = false; - $usernameErr = $e->getMessage(); - } - - try{ - $password = str_replace(' ', '', test_input(($_POST["password"]))); - checkInputChoice($password, "longerEight"); - matchPassword(); - } catch(passwordException $e){ - $correct = false; - $passwordErr = $e->getMessage(); - } catch(confirmPasswordException $e){ - $correct = false; - $confirmPasswordErr = $e->getMessage(); - } - - try{ - $location = test_input(($_POST["location"])); - checkInputChoice($location, "lettersAndSpaces"); - } catch(lettersAndSpacesException $e){ - $correct = false; - $locationErr = $e->getMessage(); - } - - try{ - $email = test_input(($_POST["email"])); - checkInputChoice($email, "email"); - } catch(emailException $e){ - $correct = false; - $emailErr = $e->getMessage(); - } - - try{ - $captcha = $_POST['g-recaptcha-response']; - checkCaptcha($captcha); - } catch(captchaException $e){ - $correct = false; - $captchaErr = $e->getMessage(); - } - - try { - getIp(); - registerCheck($correct); - sendConfirmEmailUsername($username); - } catch(registerException $e){ - $genericErr = $e->getMessage(); - } + try { + $surname = test_input(($_POST["surname"])); + checkInputChoice($surname, "lettersAndSpaces"); + } + catch(lettersAndSpacesException $e){ + $correct = false; + $surnameErr = $e->getMessage(); + } + + try{ + $day_date = test_input(($_POST["day_date"])); + $month_date = test_input(($_POST["month_date"])); + $year_date = test_input(($_POST["year_date"])); + $bday = $year_date . "-" . $month_date . "-" . $day_date; + checkInputChoice($bday, "bday"); + } catch(bdayException $e){ + $correct = false; + $bdayErr = $e->getMessage(); + } + + try{ + $username = str_replace(' ', '', test_input(($_POST["username"]))); + checkInputChoice($username, "username"); + } catch(usernameException $e){ + $correct = false; + $usernameErr = $e->getMessage(); + } + + try{ + $password = str_replace(' ', '', test_input(($_POST["password"]))); + checkInputChoice($password, "longerEight"); + matchPassword(); + } catch(passwordException $e){ + $correct = false; + $passwordErr = $e->getMessage(); + } catch(confirmPasswordException $e){ + $correct = false; + $confirmPasswordErr = $e->getMessage(); + } + + try{ + $location = test_input(($_POST["location"])); + checkInputChoice($location, "lettersAndSpaces"); + } catch(lettersAndSpacesException $e){ + $correct = false; + $locationErr = $e->getMessage(); + } + + try{ + $email = test_input(($_POST["email"])); + checkInputChoice($email, "email"); + $confirmEmail = test_input(($_POST["confirmEmail"])); + matchEmail(); + } catch(emailException $e){ + $correct = false; + $emailErr = $e->getMessage(); + } catch(confirmEmailException $e){ + $correct = false; + $confirmEmailErr = $e->getMessage(); + } + + try{ + $captcha = $_POST['g-recaptcha-response']; + checkCaptcha($captcha); + } catch(captchaException $e){ + $correct = false; + $captchaErr = $e->getMessage(); + } + + try { + getIp(); + registerCheck($correct); + sendConfirmEmailUsername($username); + } catch(registerException $e){ + echo ""; + $genericErr = $e->getMessage(); } -/* This view adds register view */ -include("../views/register-view.php"); -?> - - diff --git a/website/public/resetpassword.php b/website/public/resetpassword.php index 3ca2698..795e6e3 100644 --- a/website/public/resetpassword.php +++ b/website/public/resetpassword.php @@ -28,7 +28,7 @@ if ($_SERVER["REQUEST_METHOD"] == "GET") { } function changePassword() { - $stmt = $GLOBALS["db"]->prepare(" + $stmt = prepareQuery(" UPDATE `user` SET @@ -42,7 +42,7 @@ function changePassword() { } function verifyLink(int $userID, string $hash) { - $stmt = $GLOBALS["db"]->prepare(" + $stmt = prepareQuery(" SELECT `password` FROM diff --git a/website/public/styles/adminbutton.css b/website/public/styles/adminbutton.css new file mode 100644 index 0000000..2a8fb2a --- /dev/null +++ b/website/public/styles/adminbutton.css @@ -0,0 +1,3 @@ +#quick-links i { + font-size: 32px; +} \ No newline at end of file diff --git a/website/public/styles/adminpanel.css b/website/public/styles/adminpanel.css index f9410e1..0648118 100644 --- a/website/public/styles/adminpanel.css +++ b/website/public/styles/adminpanel.css @@ -4,7 +4,7 @@ .admin-panel input[type="radio"], input[type="checkbox"] { vertical-align: middle; - height: auto; + height: 28px; margin: 2px; } @@ -34,7 +34,6 @@ width: 100%; } -.usertable .table-checkbox {width: 20px} .usertable .table-username {width: 150px} .usertable .table-status {width: 100px} .usertable .table-action {width: 200px} @@ -44,10 +43,18 @@ padding: 3px; } -.usertable tr { +.usertable th, tr { text-align: left; } .usertable tr:hover { background-color: #f5f5f5; } + +.bancommentedit { + display: none; +} + +.bancommentform input[type="text"] { + width: 100%; +} \ No newline at end of file diff --git a/website/public/styles/chat.css b/website/public/styles/chat.css index 6822d21..cb0f19f 100644 --- a/website/public/styles/chat.css +++ b/website/public/styles/chat.css @@ -1,3 +1,8 @@ + +body { + overflow: hidden; +} + /* Overall chat-screen */ .chat { position: fixed; @@ -37,6 +42,22 @@ } /* Chat-message takes the whole width of the chat area */ +.day-message { + width: 100%; + min-height: 40px; + padding: 10px 0; + clear: both; + text-align: center; +} + +.day-message-content { + width: auto; + padding: 10px; + + background-color: #F8F8F8; + color: #666; +} + .chat-message { width: 100%; min-height: 40px; @@ -105,4 +126,40 @@ .active-friend-chat { background: #4CAF50; color: white; +} + +.chat-message img { + max-width: 100%; +} + +.chat-message a { + text-decoration: underline; +} + +.chat-time { + color: #666666; + font-size: 12px; + margin-bottom: -3px; +} + +.chat-message-other .chat-time { + text-align: right; +} + +@media only screen and (max-width: 1080px) { + .chat-message-self, .chat-message-other { + max-width: 75%; + } + .chat { + left: 0; + width: 100%; + } + #chat-recent-panel { + left: 0; + width: 320px; + } + #chat-history { + left: 50%; + width: calc(100% - 390px); + } } \ No newline at end of file diff --git a/website/public/styles/header.css b/website/public/styles/header.css index 70e8c80..d400e07 100644 --- a/website/public/styles/header.css +++ b/website/public/styles/header.css @@ -26,7 +26,8 @@ header { } #header-search { - padding-left: 42px; + margin: 24px 0 24px 32px; + vertical-align: middle; } @@ -48,5 +49,11 @@ header div { } #open-notifications { - padding: 5px 20px 5px 0px; + padding: 20px 20px 20px 0px; +} + +@media only screen and (max-width: 1080px) { + #header-logo { + display: none; + } } \ No newline at end of file diff --git a/website/public/styles/index.css b/website/public/styles/index.css index 97d6f63..6f7caf0 100644 --- a/website/public/styles/index.css +++ b/website/public/styles/index.css @@ -30,8 +30,10 @@ form { border-radius: 12px; height: 85%; margin: auto; - width: 80%; - overflow-y:auto; + width: 600px; + overflow-y: auto; + overflow-x: hidden; + } @@ -44,13 +46,13 @@ h1 { /* registreer titel*/ h2 { - padding: 16px; + padding: 8px; text-align: left; font-size: 2.0em; } h3 { - padding: 16px; + padding: 8px; text-align: center; font-size: 1.5em; } @@ -61,11 +63,15 @@ input[type=text], input[type=password], input[type=email], input[type="date"] { display: inline-block; height: 60%; font-size: 16px; - padding: 8px 20px; + padding: 8px 10px; margin: 4px 0; width: 55%; } +.middle{ + text-align: center; +} + .center{ text-align: center; } @@ -77,7 +83,7 @@ button { cursor: pointer; height: 50%; padding: 8px 20px; - margin: 10px; + margin: 5px; font-family: Arial; font-size: 22px; box-shadow: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.24); @@ -88,6 +94,7 @@ button { font-family: Arial; font-size: 15px; color: red; + text-align: left; } label { @@ -96,19 +103,19 @@ label { /* padding voor registreer container */ .login_containerregister { - padding: 16px; + padding: 8px; text-align: left; } /* padding voor login_containers */ .login_containerlogin { - padding:16px; + padding:8px; text-align: center; } /* padding voor foutmelding login */ .login_containerfault { - padding: 16px; + padding: 4px; text-align: center; color: red; } @@ -127,10 +134,14 @@ label { background-attachment: fixed;*/ box-shadow: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.24); height: 400px; - margin: 34px auto; + margin: 16px auto; overflow-y: auto; padding: 20px; - width: 45%; + width: 600px; +} + +select{ + width: 18%; } ul { @@ -143,12 +154,12 @@ ul { display: none; /* Hidden by default */ position: fixed; /* Stay in place */ z-index: 1; /* Sit on top */ - padding-top: 100px; /* Location of the box */ + padding-top: 30px; /* Location of the box */ left: 0; top: 0; width: 100%; /* Full width */ height: 100%; /* Full height */ - overflow: auto; /* Enable scroll if needed */ + overflow: hidden; /* Enable scroll if needed */ background-color: rgb(0,0,0); /* Fallback color */ background-color: rgba(0,0,0,0.4); /* Black w/ opacity */ } @@ -160,7 +171,7 @@ ul { margin: auto; padding: 0; border: 1px solid #888; - width: 500px; + width: 600px; box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2),0 6px 20px 0 rgba(0,0,0,0.19); -webkit-animation-name: animatetop; -webkit-animation-duration: 0.4s; @@ -183,7 +194,7 @@ ul { .close { color: white; float: right; - font-size: 28px; + font-size: 36px; font-weight: bold; } @@ -195,15 +206,16 @@ ul { } .modal-header { - padding: 2px 16px; + padding: 4px 16px; background-color: #FBC02D; color: black; } -.modal-body {padding: 2px 16px;} +.modal-body { + padding: 2px 16px; +} .modal-footer { - padding: 2px 16px; background-color: #FBC02D; color: black; -} \ No newline at end of file +} diff --git a/website/public/styles/main.css b/website/public/styles/main.css index abda8be..7fc03e1 100644 --- a/website/public/styles/main.css +++ b/website/public/styles/main.css @@ -92,21 +92,29 @@ p { border-radius: 50%; } +.online { + border: #4CAF50 solid 3px; +} + +.offline { + border: #666666 solid 3px; +} + .group-picture { border-radius: 5px; } .item-box, .item-box-full-width { - margin: 20px 0 0 0; padding: 25px; background-color: #FFFFFF; } .item-box { - width: calc(50% - 60px); + width: calc(33% - 50px); + display: inline-table; } -@media only screen and (max-width: 900px) { +@media only screen and (max-width: 1400px) { .item-box { width: calc(100% - 50px); } @@ -183,6 +191,10 @@ button.green { background-color: forestgreen; } +button.gray{ + background-color: #FFF; + color: #333; +} button, input[type="submit"], @@ -224,6 +236,7 @@ td { /* Custom title box, appears instantaneously */ a[data-title]:hover, +i[data-title]:hover, img[data-title]:hover, span[data-title]:hover, div[data-title]:hover { @@ -231,6 +244,7 @@ div[data-title]:hover { } a[data-title]:hover:after, +i[data-title]:hover:after, img[data-title]:hover:after, span[data-title]:hover:after, div[data-title]:hover:after { @@ -275,3 +289,34 @@ div[data-title]:hover:after { display: inline-block; 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; + } + button, input, select { + font-size: 28px; + height: 42px; + } + textarea { + font-size: 28px; + } + input[type="checkbox"], input[type="radio"] { + width: 28px; + height: 28px; + } + +} \ No newline at end of file diff --git a/website/public/styles/menu.css b/website/public/styles/menu.css index 303b9bc..3774143 100644 --- a/website/public/styles/menu.css +++ b/website/public/styles/menu.css @@ -5,7 +5,7 @@ left: 0; top: 80px; - height: calc(100% - 80px); + height: calc(100% - 120px); width: 236px; padding: 20px 10px; @@ -86,4 +86,18 @@ height: 100%; padding: 0; text-align: left; +} + +@media only screen and (max-width: 1080px) { + #contact-menu, #notification-center { + display: none; + background: rgba(0, 0, 0, 0.4); + width: calc(50% - 20px); + } + .content { + margin-left: 0; + } + #quick-links i { + font-size: 48px!important; + } } \ No newline at end of file diff --git a/website/public/styles/resetpassword.css b/website/public/styles/message-page.css similarity index 64% rename from website/public/styles/resetpassword.css rename to website/public/styles/message-page.css index a3d7942..7cc6f4b 100644 --- a/website/public/styles/resetpassword.css +++ b/website/public/styles/message-page.css @@ -1,6 +1,9 @@ +body { + background-color: #FBC02D; +} + .password-change { height: 100%; - background-color: #FBC02D; margin: auto; } @@ -12,6 +15,14 @@ margin: 30px auto auto; display: block; } -.password-change img { +.top-logo img { width: 50%; } + +.error-page { + text-align: center; +} + +.error-page img { + vertical-align: middle; +} \ No newline at end of file diff --git a/website/public/styles/mobilefriendly.css b/website/public/styles/mobilefriendly.css new file mode 100644 index 0000000..86ffab8 --- /dev/null +++ b/website/public/styles/mobilefriendly.css @@ -0,0 +1,47 @@ +/* MAIN */ +body { + font-size: 28px!important; +} +button { + font-size: 28px; +} + +/* HEADER */ +#header-logo { + display: none; +} + +/* PROFILE */ +.post-box { + width: calc(100% - 65px); +} + +/* MENU */ +#contact-menu, #notification-center { + display: none; + background: rgba(0, 0, 0, 0.4); + width: calc(50% - 20px); +} +.content { + margin-left: 0; +} +#quick-links i { + font-size: 48px!important; +} + +/* CHAT */ +.chat-message-self, .chat-message-other { + max-width: 75%; +} +.chat { + left: 0; + width: 100%; +} +#chat-recent-panel { + left: 0; + width: 320px; +} +#chat-history { + left: 50%; + width: calc(100% - 390px); +} \ No newline at end of file diff --git a/website/public/styles/post-popup.css b/website/public/styles/post-popup.css index c205c09..67d7880 100644 --- a/website/public/styles/post-popup.css +++ b/website/public/styles/post-popup.css @@ -69,4 +69,18 @@ .commentcontent { margin: 5px auto; width: 95%; +} + +.nietslecht-text { + font-family: Impact, Anton, sans-serif; + text-shadow: -1px 0 1px black, 0 1px 1px black, 1px 0 1px black, 0 -1px 1px black; +} + +.nietslecht { +} + +.nietslecht img { + vertical-align: middle; + height: 24px; + width: 24px; } \ No newline at end of file diff --git a/website/public/styles/profile.css b/website/public/styles/profile.css index 85b2db5..421e781 100644 --- a/website/public/styles/profile.css +++ b/website/public/styles/profile.css @@ -1,15 +1,60 @@ -.profile-box { - min-height: 150px; - padding: 25px; - background-color: #FFFFFF; +/* New */ + +.user-box { + text-align: center; } -.profile-box .profile-picture, .profile-box .group-picture { +.status-buttons-container { + position: relative; + float: left; + width: 200px; + display: inline-block; +} + +.friend-button-container { + position: relative; + float: right; + width: 200px; + display: inline-block; +} + +.friend-button-container button, .status-buttons-container button { + display: block; + + margin: 7px 0; + width: 200px; + + font-size: 18px; +} + +.empty-button { + background: none; + cursor: auto; +} +.empty-button:active { + box-shadow: none; +} + +.profile-info { + display: inline-block; + + min-width: 250px; + width: auto; + padding-top: 30px; +} + +.main-picture { + position: relative; + border-width: 5px; + + display: inline-block; width: 150px; height: 150px; - margin: 0 20px 20px 0; + margin-bottom: -45px; } +/* Old */ + .profile-box h1.profile-username { padding-top: 50px; } @@ -18,18 +63,17 @@ } div.posts { - padding-top: 20px; width: calc(100% + 20px); display: inline-flex; } div.posts div.post { display: block; - margin: 20px 0 0 0; padding: 10px; width: calc(100% - 40px); cursor: pointer; transition-duration: 250ms; + word-wrap: break-word; } div.posts div.post:hover { @@ -59,6 +103,12 @@ div.posts .post form textarea.newpost { height: 100px; } +.post .post-date { + float: right; + color: #aaaaaa; + font-size: 0.8em; +} + @media only screen and (max-width: 1500px) { .post-box { width: calc(50% - 68px); @@ -66,28 +116,12 @@ div.posts .post form textarea.newpost { } /* mobile */ -@media only screen and (max-width: 1000px) { +@media only screen and (max-width: 1080px) { .post-box { width: calc(100% - 65px); } + .modal { + left: 0!important; + width: 100%!important; + } } - -.post .post-date { - float: right; - color: #aaaaaa; - font-size: 0.8em; -} - -button.friend-button { - float: right; - height: auto; - padding: 10px; - margin-left: 10px; - border-radius: 5px; - transition-duration: 250ms; - cursor: pointer; -} - -button.friend-button:hover { - box-shadow: 0 10px 20px rgba(0,0,0,0.19), 0 6px 6px rgba(0,0,0,0.23); -} \ No newline at end of file diff --git a/website/queries/alerts.php b/website/queries/alerts.php new file mode 100644 index 0000000..f311098 --- /dev/null +++ b/website/queries/alerts.php @@ -0,0 +1,44 @@ +diff($today); + return $interval->y; +} \ No newline at end of file diff --git a/website/queries/checkInput.php b/website/queries/checkInput.php index 9b91833..52b830f 100644 --- a/website/queries/checkInput.php +++ b/website/queries/checkInput.php @@ -38,8 +38,7 @@ function checkName($variable){ if (empty($variable)) { throw new lettersAndSpacesException("Verplicht!"); } else if (!preg_match("/^[a-zA-Z ]*$/", $variable)) { - - throw new lettersAndSpacesException("Alleen letters en spaties zijn toegestaan!"); + throw new lettersAndSpacesException("Alleen letters en spaties zijn toegestaan!"); } } @@ -48,12 +47,12 @@ function validateBday($variable){ if (empty($variable)) { throw new bdayException("Verplicht!"); } else { - if (!(validateDate($variable, "Y/m/d"))) { + if (!(validateDate($variable, "Y-m-d"))) { throw new bdayException("Geen geldige datum"); } else { - $dateNow = date("Y/m/d"); + $dateNow = date("Y-m-d"); if ($dateNow < $variable) { - throw new bdayException("Geen geldige datum"); + throw new bdayException("Geen geldige datum!"); } } } @@ -97,6 +96,12 @@ function validateEmail($variable){ } } +function matchEmail(){ + if (strtolower($_POST["email"]) != strtolower($_POST["confirmEmail"])){ + throw new confirmEmailException("Emails matchen niet!"); + } +} + /* checks if an input is a valid email. */ function resetEmail($variable){ if (empty($variable)) { @@ -119,11 +124,11 @@ function matchPassword(){ /* Checks if captcha is correctly filled in */ function checkCaptcha($captcha){ if(!$captcha){ - throw new captchaException("Captcha needs to be filled in!"); + throw new captchaException("Captcha moet ingevuld worde!"); } else { $response=json_decode(file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=6Lc72xIUAAAAAPizuF3nUbklCPljVCVzgYespz8o&response=".$captcha."&remoteip=".$_SERVER['REMOTE_ADDR'])); if($response->success==false) { - throw new captchaException("You are a spammer!"); + throw new captchaException("Je bent een spammer!"); } } } @@ -206,6 +211,14 @@ class emailException extends Exception } } +class confirmEmailException extends Exception +{ + public function __construct($message = "", $code = 0, Exception $previous = null) + { + parent::__construct($message, $code, $previous); + } +} + class captchaException extends Exception { public function __construct($message = "", $code = 0, Exception $previous = null) diff --git a/website/queries/connect.php b/website/queries/connect.php index ddb3c9b..3971a74 100644 --- a/website/queries/connect.php +++ b/website/queries/connect.php @@ -8,4 +8,8 @@ else { $GLOBALS["db"] = new PDO("mysql:host=$dbconf->mysql_host;dbname=$dbconf->mysql_database;charset=utf8", "$dbconf->mysql_username", "$dbconf->mysql_password") or die('Error connecting to mysql server'); +} + +function prepareQuery(string $query) : PDOStatement { + return $GLOBALS["db"]->prepare($query); } \ No newline at end of file diff --git a/website/queries/emailconfirm.php b/website/queries/emailconfirm.php index 0b3224f..0e6aab1 100644 --- a/website/queries/emailconfirm.php +++ b/website/queries/emailconfirm.php @@ -1,7 +1,7 @@ prepare(" + $stmt = prepareQuery(" SELECT `userID` FROM @@ -16,7 +16,7 @@ function sendConfirmEmailUsername(string $username) { } function sendConfirmEmail(int $userID) { - $stmt = $GLOBALS["db"]->prepare(" + $stmt = prepareQuery(" SELECT `email`, `fname` diff --git a/website/queries/friendship.php b/website/queries/friendship.php index a1a23d8..a16d859 100644 --- a/website/queries/friendship.php +++ b/website/queries/friendship.php @@ -7,7 +7,7 @@ function selectFriends($userID) { } function selectLimitedFriends($userID, $limit) { - $stmt = $GLOBALS["db"]->prepare(" + $stmt = prepareQuery(" SELECT `userID`, `username`, @@ -16,7 +16,10 @@ function selectLimitedFriends($userID, $limit) { `profilepicture`, '../img/avatar-standard.png' ) AS profilepicture, - `onlinestatus`, + CASE `lastactivity` >= DATE_SUB(NOW(),INTERVAL 15 MINUTE) + WHEN TRUE THEN 'online' + WHEN FALSE THEN 'offline' + END AS `onlinestatus`, `role` FROM `user` @@ -29,6 +32,9 @@ function selectLimitedFriends($userID, $limit) { `friendship`.`user1ID` = `user`.`userID`) AND `user`.`role` != 'banned' AND `friendship`.`status` = 'confirmed' + ORDER BY + `user`.`lastactivity` + DESC LIMIT :limitCount "); @@ -41,7 +47,7 @@ function selectLimitedFriends($userID, $limit) { function selectAllFriends($userID) { - $stmt = $GLOBALS["db"]->prepare(" + $stmt = prepareQuery(" SELECT `userID`, `username`, @@ -50,7 +56,10 @@ function selectAllFriends($userID) { `profilepicture`, '../img/avatar-standard.png' ) AS profilepicture, - `onlinestatus`, + CASE `lastactivity` >= DATE_SUB(NOW(),INTERVAL 15 MINUTE) + WHEN TRUE THEN 'online' + WHEN FALSE THEN 'offline' + END AS `onlinestatus`, `role` FROM `user` @@ -73,7 +82,7 @@ function selectAllFriends($userID) { } function selectAllFriendRequests() { - $stmt = $GLOBALS["db"]->prepare(" + $stmt = prepareQuery(" SELECT `userID`, `username`, @@ -82,7 +91,10 @@ function selectAllFriendRequests() { `profilepicture`, '../img/avatar-standard.png' ) AS profilepicture, - `onlinestatus`, + CASE `lastactivity` >= DATE_SUB(NOW(),INTERVAL 15 MINUTE) + WHEN TRUE THEN 'online' + WHEN FALSE THEN 'offline' + END AS `onlinestatus`, `role` FROM `user` @@ -115,7 +127,7 @@ function getFriendshipStatus($userID) { return -1; } - $stmt = $GLOBALS["db"]->prepare(" + $stmt = prepareQuery(" SELECT CASE `status` IS NULL WHEN TRUE THEN 0 @@ -148,7 +160,7 @@ function getFriendshipStatus($userID) { } function requestFriendship($userID) { - $stmt = $GLOBALS["db"]->prepare(" + $stmt = prepareQuery(" INSERT INTO `friendship` (user1ID, user2ID) VALUES (:user1, :user2) "); @@ -159,7 +171,7 @@ function requestFriendship($userID) { } function removeFriendship($userID) { - $stmt = $GLOBALS["db"]->prepare(" + $stmt = prepareQuery(" DELETE FROM `friendship` WHERE `user1ID` = :user1 AND @@ -175,7 +187,7 @@ function removeFriendship($userID) { } function acceptFriendship($userID) { - $stmt = $GLOBALS["db"]->prepare(" + $stmt = prepareQuery(" UPDATE `friendship` SET `status`='confirmed' WHERE @@ -190,7 +202,7 @@ function acceptFriendship($userID) { } function setLastVisited($friend) { - $stmt = $GLOBALS["db"]->prepare(" + $stmt = prepareQuery(" UPDATE `friendship` SET `friendship`.chatLastVisted1=( @@ -220,7 +232,7 @@ function setLastVisited($friend) { } function searchSomeFriends($n, $m, $search) { - $stmt = $GLOBALS["db"]->prepare(" + $stmt = prepareQuery(" SELECT `userID`, `username`, @@ -229,7 +241,10 @@ function searchSomeFriends($n, $m, $search) { `profilepicture`, '../img/avatar-standard.png' ) AS profilepicture, - `onlinestatus`, + CASE `lastactivity` >= DATE_SUB(NOW(),INTERVAL 15 MINUTE) + WHEN TRUE THEN 'online' + WHEN FALSE THEN 'offline' + END AS `onlinestatus`, `role` FROM `user` diff --git a/website/queries/group_member.php b/website/queries/group_member.php index cba339f..cea4dde 100644 --- a/website/queries/group_member.php +++ b/website/queries/group_member.php @@ -5,7 +5,7 @@ function selectAllGroupsFromUser($userID) { } function selectLimitedGroupsFromUser($userID, $limit) { - $stmt = $GLOBALS["db"]->prepare(" + $stmt = prepareQuery(" SELECT `group_page`.`name`, `group_page`.`picture` @@ -28,7 +28,7 @@ function selectLimitedGroupsFromUser($userID, $limit) { } function searchSomeOwnGroups($n, $m, $search) { - $stmt = $GLOBALS["db"]->prepare(" + $stmt = prepareQuery(" SELECT `group_page`.`name`, `group_page`.`picture` diff --git a/website/queries/group_page.php b/website/queries/group_page.php index f3de045..83911f8 100644 --- a/website/queries/group_page.php +++ b/website/queries/group_page.php @@ -1,7 +1,90 @@ bindParam(':name', $name, PDO::PARAM_STR); + $stmt->bindParam(':userID', $_SESSION["userID"], PDO::PARAM_INT); + if (!$stmt->execute()) { + return False; + } + return $stmt->fetch(); +} + +function selectGroupRole(int $groupID) { + $stmt = prepareQuery(" + SELECT + `role` + FROM + `group_member` + WHERE + `groupID` = :groupID AND + `userID` = :userID + "); + + $stmt->bindParam(':groupID', $groupID, PDO::PARAM_INT); + $stmt->bindParam(':userID', $_SESSION["userID"], PDO::PARAM_INT); + if(!$stmt->execute()) { + return False; + } + if($stmt->rowCount() == 0) { + return "none"; + } + return $stmt->fetch()["role"]; +} + +function selectGroupMembers(int $groupID) { + $stmt = prepareQuery(" + SELECT + `username`, + `fname`, + `lname`, + `profilepicture` + FROM + `group_member` + LEFT JOIN + `user` + ON + `group_member`.`userID` = `user`.`userID` + WHERE + `groupID` = :groupID + LIMIT 20 + "); + + $stmt->bindParam(':groupID', $groupID); + if (!$stmt->execute()) { + return False; + } + return $stmt->fetchAll(); +} + function selectGroupById($groupID) { - $q = $GLOBALS["db"]->prepare(" + $q = prepareQuery(" SELECT `group_page`.`name`, `group_page`.`picture`, @@ -20,7 +103,7 @@ function selectGroupById($groupID) { } function select20GroupsFromN($n) { - $q = $GLOBALS["db"]->prepare(" + $q = prepareQuery(" SELECT `group_page`.`groupID`, `group_page`.`name`, @@ -42,7 +125,7 @@ function select20GroupsFromN($n) { } function select20GroupsByStatusFromN($n, $status) { - $q = $GLOBALS["db"]->prepare(" + $q = prepareQuery(" SELECT `group_page`.`groupID`, `group_page`.`name`, @@ -67,7 +150,7 @@ function select20GroupsByStatusFromN($n, $status) { } function search20GroupsFromNByStatus($n, $keyword, $status) { - $q = $GLOBALS["db"]->prepare(" + $q = prepareQuery(" SELECT `groupID`, `name`, @@ -94,7 +177,7 @@ function search20GroupsFromNByStatus($n, $keyword, $status) { } function searchSomeGroupsByStatus($n, $m, $keyword, $status) { - $q = $GLOBALS['db']->prepare(" + $q = prepareQuery(" SELECT `groupID`, `name`, @@ -122,7 +205,7 @@ function searchSomeGroupsByStatus($n, $m, $keyword, $status) { } function countSomeGroupsByStatus($keyword, $status) { - $q = $GLOBALS['db']->prepare(" + $q = prepareQuery(" SELECT COUNT(*) FROM @@ -143,20 +226,23 @@ function countSomeGroupsByStatus($keyword, $status) { } function changeGroupStatusByID($id, $status) { - $q = $GLOBALS["db"]->query(" + $q = prepareQuery(" UPDATE `group_page` SET - `status` = $status + `status` = :status WHERE - `groupID` = $id + `groupID` = :id "); + $q->bindParam(':status', $status); + $q->bindParam(':id', $id); + $q->execute(); return $q; } function changeMultipleGroupStatusByID($ids, $status) { - $q = $GLOBALS['db']->prepare(" + $q = prepareQuery(" UPDATE `group_page` SET @@ -173,7 +259,7 @@ function changeMultipleGroupStatusByID($ids, $status) { } function searchSomeGroups($n, $m, $search) { - $stmt = $GLOBALS["db"]->prepare(" + $stmt = prepareQuery(" SELECT `name`, `picture` @@ -196,7 +282,7 @@ function searchSomeGroups($n, $m, $search) { } function countSomeGroups($search) { - $stmt = $GLOBALS["db"]->prepare(" + $stmt = prepareQuery(" SELECT COUNT(*) FROM @@ -211,5 +297,4 @@ function countSomeGroups($search) { $stmt->bindParam(':keyword', $search); $stmt->execute(); return $stmt; -} -?> \ No newline at end of file +} \ No newline at end of file diff --git a/website/queries/header.php b/website/queries/header.php index b0dd42c..7410d17 100644 --- a/website/queries/header.php +++ b/website/queries/header.php @@ -1,6 +1,6 @@ prepare(" + $stmt = prepareQuery(" SELECT `fname`, `lname`, diff --git a/website/queries/login.php b/website/queries/login.php index 2af255a..c7e8383 100644 --- a/website/queries/login.php +++ b/website/queries/login.php @@ -1,7 +1,7 @@ prepare(" + $stmt = prepareQuery(" SELECT `password`, `userID`, @@ -9,10 +9,11 @@ function getUser() { FROM `user` WHERE - `username` LIKE :username + `username` LIKE :username OR + `email` LIKE :username "); - $stmt->bindParam(":username", $_POST["uname"]); + $stmt->bindValue(":username", test_input($_POST["user"])); $stmt->execute(); return $stmt->fetch(PDO::FETCH_ASSOC); } @@ -20,7 +21,7 @@ function getUser() { function validateLogin($username, $password){ // Empty username or password field if (empty($username) || empty($password)) { - throw new loginException("Gebruikersnaam of wachtwoord is niet ingevuld"); + throw new loginException("Inloggegevens zijn niet ingevuld"); } else { $psw = test_input($password); @@ -41,6 +42,9 @@ function validateLogin($username, $password){ "; } else { $_SESSION["userID"] = $userID; +// if($_POST[rememberMe] == 1){ +// ini_set("session.gc_maxlifetime", "10"); +// } header("location: profile.php"); } } else { @@ -57,5 +61,4 @@ class loginException extends Exception parent::__construct($message, $code, $previous); } } -?> diff --git a/website/queries/nicetime.php b/website/queries/nicetime.php index 4db6cbd..e2e509e 100644 --- a/website/queries/nicetime.php +++ b/website/queries/nicetime.php @@ -1,39 +1,39 @@ $unix_date) { -$difference = $now - $unix_date; -$tense = "geleden"; -} else { -$difference = $unix_date - $now; -$tense = "vanaf nu"; -} + if($now > $unix_date) { + $difference = $now - $unix_date; + $tense = "geleden"; + } else { + $difference = $unix_date - $now; + $tense = "vanaf nu"; + } -for($i = 0; $difference >= $lengths[$i] && $i < count($lengths) - 1; $i++) { -$difference /= $lengths[$i]; -} + for($i = 0; $difference >= $lengths[$i] && $i < count($lengths) - 1; $i++) { + $difference /= $lengths[$i]; + } -$difference = round($difference); + $difference = round($difference); -if($difference != 1) { -$period = $multiple_periods[$i]; -} else { -$period = $single_periods[$i]; -} + if($difference != 1) { + $period = $multiple_periods[$i]; + } else { + $period = $single_periods[$i]; + } -return "$difference $period $tense"; + return "$difference $period $tense"; } \ No newline at end of file diff --git a/website/queries/picture.php b/website/queries/picture.php new file mode 100644 index 0000000..8e99d9a --- /dev/null +++ b/website/queries/picture.php @@ -0,0 +1,138 @@ + 4000000) { + throw new AngryAlert("Bestand is te groot, maximaal 4MB toegestaan."); + } + $relativePath = $avatarDir . $_SESSION["userID"] . "_avatar.gif"; + $group ? removeOldGroupAvatar($_POST["groupID"]) : removeOldUserAvatar(); + move_uploaded_file($tmpImg, $publicDir . $relativePath); + } else { + $relativePath = $avatarDir . $_SESSION["userID"] . "_avatar.png"; + $scaledImg = scaleAvatar($tmpImg); + $group ? removeOldGroupAvatar($_POST["groupID"]) : removeOldUserAvatar(); + imagepng($scaledImg, $publicDir . $relativePath); + } + + $group ? setGroupAvatarToDatabase("../" . $relativePath, $_POST["groupID"]) : setUserAvatarToDatabase("../" . $relativePath); + throw new HappyAlert("Profielfoto veranderd."); +} + +/** + * Removes the old avatar from the uploads folder, for a user. + */ +function removeOldUserAvatar() { + $stmt = prepareQuery(" + SELECT + `profilepicture` + FROM + `user` + WHERE + `userID` = :userID + "); + $stmt->bindParam(":userID", $_SESSION["userID"]); + $stmt->execute(); + $old_avatar = $stmt->fetch()["profilepicture"]; + if ($old_avatar != NULL) { + unlink("/var/www/html/public/uploads/" . $old_avatar); + } +} +/** + * Removes the old avatar from the uploads folder, for a group. + * @param int $groupID + */ +function removeOldGroupAvatar(int $groupID) { + $stmt = prepareQuery(" + SELECT + `picture` + FROM + `group_page` + WHERE + groupID = :groupID + "); + $stmt->bindParam(":groupID", $groupID); + $stmt->execute(); + $old_avatar = $stmt->fetch()["picture"]; + if ($old_avatar != NULL) { + unlink("/var/www/html/public/uploads/" . $old_avatar); + } +} + +/** + * Inserts the the path to the avatar into the database, for Users. + * @param string $url path to the avatar + */ +function setUserAvatarToDatabase(string $url) { + $stmt = prepareQuery(" + UPDATE + `user` + SET + `profilepicture` = :avatar + WHERE + `userID` = :userID + "); + + $stmt->bindParam(":avatar", $url); + $stmt->bindParam(":userID", $_SESSION["userID"]); + $stmt->execute(); +} + +/** + * Inserts the the path to the avatar into the database, for Groups. + * @param string $url path to the avatar + * @param int $groupID + */ +function setGroupAvatarToDatabase(string $url, int $groupID) { + $stmt = prepareQuery(" + UPDATE + `group_page` + SET + `picture` = :avatar + WHERE + `groupID` = :groupID + "); + $stmt->bindParam(":avatar", $url); + $stmt->bindParam(":groupID", $groupID); + $stmt->execute(); +} + +/** + * Checks the resoluton of a picture. + * @param string $img + * @throws AngryAlert + */ +function checkAvatarSize(string $img) { + $minResolution = 200; + $imgSize = getimagesize($img); + if ($imgSize[0] < $minResolution or $imgSize[1] < $minResolution) { + throw new AngryAlert("Afbeelding te klein, minimaal 200x200 pixels."); + } +} + +/** + * Scales a picture, standard width is 600px. + * @param string $imgLink Path to a image file + * @param int $newWidth Custom image width. + * @return bool|resource Returns the image as an Resource. + * @throws AngryAlert + */ +function scaleAvatar(string $imgLink, int $newWidth = 600) { + $img = imagecreatefromstring(file_get_contents($imgLink)); + if ($img) { + return imagescale($img, $newWidth); + } else { + throw new AngryAlert("Afbeelding wordt niet ondersteund."); + } +} \ No newline at end of file diff --git a/website/queries/post.php b/website/queries/post.php index 5940267..a175cda 100644 --- a/website/queries/post.php +++ b/website/queries/post.php @@ -1,7 +1,53 @@ = 150 AND `post`.`content` NOT LIKE 'bindParam(':userID', $userID, PDO::PARAM_INT); + $stmt->bindParam(':groupID', $groupID , PDO::PARAM_INT); + if(!$stmt->execute()) { + return False; + } + return $stmt; + +} + function selectPostById($postID) { - $stmt = $GLOBALS["db"]->prepare(" + $stmt = prepareQuery(" SELECT `user`.`fname`, `user`.`lname`, @@ -26,7 +72,7 @@ function selectPostById($postID) { } function selectCommentsByPostId($postID) { - $stmt = $GLOBALS["db"]->prepare(" + $stmt = prepareQuery(" SELECT `comment`.`commentID`, `comment`.`postID`, @@ -52,7 +98,7 @@ function selectCommentsByPostId($postID) { } function makePost($userID, $groupID, $title, $content) { - $stmt = $GLOBALS["db"]->prepare(" + $stmt = prepareQuery(" INSERT INTO `post` ( `author`, @@ -75,8 +121,8 @@ function makePost($userID, $groupID, $title, $content) { $stmt->execute(); } -function makeComment($postID, $userID, $content) { - $stmt = $GLOBALS["db"]->prepare(" +function makeComment($postID, $userID, $content) : int { + $stmt = prepareQuery(" INSERT INTO `comment` ( `postID`, @@ -94,4 +140,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 = prepareQuery(" + 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 = prepareQuery(" + 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 = prepareQuery(" + 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/queries/private_message.php b/website/queries/private_message.php index fecea2b..4ac04a7 100644 --- a/website/queries/private_message.php +++ b/website/queries/private_message.php @@ -1,91 +1,107 @@ prepare(" - SELECT - * - FROM - `private_message` - WHERE - `origin` = :user1 AND - `destination` = :user2 OR - `origin` = :user2 AND - `destination` = :user1 - ORDER BY - `messageID` ASC - "); + $stmt->bindParam(":user1", $user1ID); + $stmt->bindParam(":user2", $user2ID); - $stmt->bindParam(":user1", $user1ID); - $stmt->bindParam(":user2", $user2ID); + $stmt->execute(); - $stmt->execute(); - - return json_encode($stmt->fetchAll()); + return json_encode($stmt->fetchAll()); + } else { + return "[]"; + } } function sendMessage($destination, $content) { - $stmt = $GLOBALS["db"]->prepare(" - INSERT INTO - `private_message` - ( - `origin`, - `destination`, - `content` - ) - VALUES - ( - :origin, - :destination, - :content - ) - "); + require_once("friendship.php"); + if (getFriendshipStatus($destination) == 1) { + $stmt = prepareQuery(" + INSERT INTO + `private_message` + ( + `origin`, + `destination`, + `content` + ) + VALUES + ( + :origin, + :destination, + :content + ) + "); - return $stmt->execute(array( - "origin" => $_SESSION["userID"], - "destination" => $destination, - "content" => $content - )); + return $stmt->execute(array( + "origin" => $_SESSION["userID"], + "destination" => $destination, + "content" => $content + )); + } else { + return false; + } } function getNewChatMessages($lastID, $destination) { - $stmt = $GLOBALS["db"]->prepare(" - SELECT - * - FROM - `private_message` - WHERE - ( - `origin` = :user1 AND - `destination` = :user2 OR - `origin` = :user2 AND - `destination` = :user1) AND - `messageID` > :lastID - ORDER BY - `messageID` ASC - "); + require_once("friendship.php"); + if (getFriendshipStatus($destination) == 1) { + $stmt = prepareQuery(" + SELECT + * + FROM + `private_message` + WHERE + ( + `origin` = :user1 AND + `destination` = :user2 OR + `origin` = :user2 AND + `destination` = :user1) AND + `messageID` > :lastID + ORDER BY + `creationdate` ASC + "); - $stmt->bindParam(':user1', $_SESSION["userID"]); - $stmt->bindParam(':user2', $destination); - $stmt->bindParam(':lastID', $lastID); + $stmt->bindParam(':user1', $_SESSION["userID"]); + $stmt->bindParam(':user2', $destination); + $stmt->bindParam(':lastID', $lastID); - $stmt->execute(); + $stmt->execute(); - return json_encode($stmt->fetchAll()); + return json_encode($stmt->fetchAll()); + } else { + return "[]"; + } } function selectAllUnreadChat() { - $stmt = $GLOBALS["db"]->prepare(" + $stmt = prepareQuery(" SELECT - LEFT(CONCAT(`user`.`fname`, ' ', `user`.`lname`), 15) as `fullname`, + LEFT(CONCAT(`user`.`fname`, ' ', `user`.`lname`), 15) AS `fullname`, `user`.`userID`, IFNULL( `profilepicture`, '../img/avatar-standard.png' ) AS profilepicture, - LEFT(`private_message`.`content`, 15) as `content` + LEFT(`private_message`.`content`, 15) AS `content` FROM `private_message`, `friendship`, @@ -101,7 +117,8 @@ function selectAllUnreadChat() { `friendship`.chatLastVisted2 IS NULL)) AND `private_message`.`origin` = `user`.`userID` AND `private_message`.`destination` = :userID AND - `user`.`role` != 'banned' + `user`.`role` != 'banned' AND + `friendship`.`status` = 'confirmed' GROUP BY `user`.`userID` diff --git a/website/queries/register.php b/website/queries/register.php index 738ef43..1aed0ef 100644 --- a/website/queries/register.php +++ b/website/queries/register.php @@ -1,7 +1,7 @@ prepare(" + $stmt = prepareQuery(" SELECT `username` FROM @@ -10,14 +10,14 @@ function getExistingUsername() { `username` LIKE :username "); - $stmt->bindParam(":username", $_POST["username"]); + $stmt->bindValue(":username", test_input($_POST["username"])); $stmt->execute(); return $stmt->rowCount(); } function getExistingEmail() { - $stmt = $GLOBALS["db"]->prepare(" + $stmt = prepareQuery(" SELECT `email` FROM @@ -26,14 +26,14 @@ function getExistingEmail() { `email` LIKE :email "); - $stmt->bindParam(":email", $_POST["email"]); + $stmt->bindValue(":email", test_input($_POST["email"])); $stmt->execute(); return $stmt->rowCount(); } function getResetEmail() { - $stmt = $GLOBALS["db"]->prepare(" + $stmt = prepareQuery(" SELECT `email` FROM @@ -42,14 +42,14 @@ function getResetEmail() { `email` LIKE :email "); - $stmt->bindParam(":email", $_POST["forgotEmail"]); + $stmt->bindValue(":email", test_input($_POST["forgotEmail"])); $stmt->execute(); return $stmt->rowCount(); } function registerAccount() { - $stmt = $GLOBALS["db"]->prepare(" + $stmt = prepareQuery(" INSERT INTO `user`(fname, lname, @@ -70,15 +70,21 @@ function registerAccount() { $hash=password_hash($_POST["password"], PASSWORD_DEFAULT); - $stmt->bindParam(":fname", $_POST["name"]); - $stmt->bindParam(":lname", $_POST["surname"]); - $stmt->bindParam(":bday", $_POST["bday"]); - $stmt->bindParam(":username", $_POST["username"]); - $stmt->bindParam(":password", $hash); - $stmt->bindParam(":location", $_POST["location"]); - $stmt->bindParam(":email", (strtolower($_POST["email"]))); + $stmt->bindValue(":fname", test_input($_POST["name"])); + $stmt->bindValue(":lname", test_input($_POST["surname"])); + $stmt->bindValue(":bday", test_input($_POST["bday"])); + $stmt->bindValue(":username", test_input($_POST["username"])); + $stmt->bindValue(":password", test_input($hash)); + $stmt->bindValue(":location", test_input($_POST["location"])); + $stmt->bindValue(":email", test_input(strtolower($_POST["email"]))); $stmt->execute(); $stmt->rowCount(); } + +function submitselect($date, $value){ + if ($date == $value){ + echo "selected"; + } +} ?> diff --git a/website/queries/requestpassword.php b/website/queries/requestpassword.php index c0ff462..a54bd7d 100644 --- a/website/queries/requestpassword.php +++ b/website/queries/requestpassword.php @@ -3,7 +3,7 @@ include_once "../queries/connect.php"; function sendPasswordRecovery(string $email) { if (filter_var($email, FILTER_VALIDATE_EMAIL)) { - $stmt = $GLOBALS["db"]->prepare(" + $stmt = prepareQuery(" SELECT `userID`, `username` @@ -39,7 +39,7 @@ function doSendPasswordRecovery(int $userID, string $email, string $username, st } function setHashToDatabase(int $userID, string $hash) { - $stmt = $GLOBALS["db"]->prepare(" + $stmt = prepareQuery(" UPDATE `user` SET @@ -50,5 +50,5 @@ function setHashToDatabase(int $userID, string $hash) { $stmt->bindParam(":hash", $hash); $stmt->bindParam(":userID", $userID); $stmt->execute(); - return $stmt->rowCount(); + $stmt->rowCount(); } \ No newline at end of file diff --git a/website/queries/settings.php b/website/queries/settings.php index 0bf8791..03f794f 100644 --- a/website/queries/settings.php +++ b/website/queries/settings.php @@ -1,44 +1,14 @@ prepare(" + $stmt = prepareQuery(" SELECT `fname`, `lname`, @@ -46,7 +16,9 @@ function getSettings() { `location`, `birthdate`, `bio`, - `profilepicture` + `profilepicture`, + `showBday`, + `showEmail` FROM `user` WHERE @@ -58,8 +30,12 @@ function getSettings() { return $stmt->fetch(); } +/** + * Gets the passwordHas form the database + * @return mixed passwordhash + */ function getPasswordHash() { - $stmt = $GLOBALS["db"]->prepare(" + $stmt = prepareQuery(" SELECT `password`, `username` @@ -73,8 +49,12 @@ function getPasswordHash() { return $stmt->fetch(); } +/** + * Changes the setting from post. + * @throws HappyAlert + */ function updateSettings() { - $stmt = $GLOBALS["db"]->prepare(" + $stmt = prepareQuery(" UPDATE `user` SET @@ -82,25 +62,45 @@ function updateSettings() { `lname` = :lname, `location` = :location, `birthdate` = :bday, - `bio` = :bio + `bio` = :bio, + `showEmail` = :showEmail, + `showBday` = :showBday WHERE `userID` = :userID "); + $bday = new DateTime(); + $bday->setDate(test_input($_POST["year"]), test_input($_POST["month"]), test_input($_POST["day"])); + checkBday($bday); $stmt->bindValue(":fname", test_input($_POST["fname"])); $stmt->bindValue(":lname", test_input($_POST["lname"])); $stmt->bindValue(":location", test_input($_POST["location"])); - $stmt->bindValue(":bday", test_input($_POST["bday"])); + $stmt->bindValue(":bday", $bday->format("Ymd")); $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(":userID", $_SESSION["userID"]); $stmt->execute(); throw new HappyAlert("Instellingen zijn opgeslagen."); } +function checkBday(DateTime $bday) { + $today = new DateTime(); + if ($bday >= $today) { + throw new AngryAlert("Jij bent vast niet in de toekomst geboren toch? ;)"); + } +} + + +/** + * Change + * @throws AngryAlert + */ function changePassword() { $user = getPasswordHash(); - if (password_verify($_POST["password-old"], $user["password"])) { - if ($_POST["password-new"] == $_POST["password-confirm"] && (strlen($_POST["password-new"]) >= 8)) { + if (password_verify($_POST["password-old"], test_input($user["password"]))) { + if (test_input($_POST["password-new"]) == test_input($_POST["password-confirm"]) && (strlen(test_input($_POST["password-new"])) >= 8)) { doChangePassword(); } else { throw new AngryAlert("Wachtwoorden komen niet overeen."); @@ -110,8 +110,12 @@ function changePassword() { } } +/** + * @throws AngryAlert + * @throws HappyAlert + */ function doChangePassword() { - $stmt = $GLOBALS["db"]->prepare(" + $stmt = prepareQuery(" UPDATE `user` SET @@ -134,8 +138,8 @@ function doChangePassword() { function changeEmail() { - if ($_POST["email"] == $_POST["email-confirm"]) { - $email = strtolower($_POST["email"]); + if (test_input($_POST["email"]) == test_input($_POST["email-confirm"])) { + $email = strtolower(test_input($_POST["email"])); if (filter_var($email, FILTER_VALIDATE_EMAIL)) { //check if email exists emailIsAvailableInDatabase($email); @@ -149,7 +153,7 @@ function changeEmail() { } function emailIsAvailableInDatabase($email) { - $stmt = $GLOBALS["db"]->prepare(" + $stmt = prepareQuery(" SELECT `email` FROM @@ -166,7 +170,7 @@ function emailIsAvailableInDatabase($email) { } function doChangeEmail($email) { - $stmt = $GLOBALS["db"]->prepare(" + $stmt = prepareQuery(" UPDATE `user` SET @@ -186,74 +190,4 @@ function doChangeEmail($email) { } else { throw new AngryAlert(); } -} - -function updateAvatar() { - $profilePictureDir = "/var/www/html/public/"; - $tmpImg = $_FILES["pp"]["tmp_name"]; - - checkAvatarSize($tmpImg); - removeOldAvatar(); - if (getimagesize($tmpImg)["mime"] == "image/gif") { - if ($_FILES["pp"]["size"] > 4000000) { - throw new AngryAlert("Bestand is te groot, maximaal 4MB toegestaan."); - } - $relativePath = "uploads/profilepictures/" . $_SESSION["userID"] . "_avatar.gif"; - move_uploaded_file($tmpImg, $profilePictureDir . $relativePath); - } else { - $relativePath = "uploads/profilepictures/" . $_SESSION["userID"] . "_avatar.png"; - $scaledImg = scaleAvatar($tmpImg); - imagepng($scaledImg, $profilePictureDir . $relativePath); - } - setAvatarToDatabase("../" . $relativePath); - throw new HappyAlert("Profielfoto veranderd."); -} - -function removeOldAvatar() { - $stmt = $GLOBALS["db"]->prepare(" - SELECT - `profilepicture` - FROM - `user` - WHERE - `userID` = :userID - "); - $stmt->bindParam(":userID", $_SESSION["userID"]); - $stmt->execute(); - $old_avatar = $stmt->fetch()["profilepicture"]; - if ($old_avatar != NULL) { - unlink("/var/www/html/public/uploads/" . $old_avatar); - } -} - -function setAvatarToDatabase(string $url) { - $stmt = $GLOBALS["db"]->prepare(" - UPDATE - `user` - SET - `profilepicture` = :avatar - WHERE - `userID` = :userID - "); - - $stmt->bindParam(":avatar", $url); - $stmt->bindParam(":userID", $_SESSION["userID"]); - $stmt->execute(); -} - -function checkAvatarSize(string $img) { - $minResolution = 200; - $imgSize = getimagesize($img); - if ($imgSize[0] < $minResolution or $imgSize[1] < $minResolution) { - throw new AngryAlert("Afbeelding te klein, minimaal 200x200 pixels."); - } -} - -function scaleAvatar(string $imgLink, int $newWidth = 600) { - $img = imagecreatefromstring(file_get_contents($imgLink)); - if ($img) { - return imagescale($img, $newWidth); - } else { - throw new AngryAlert("Afbeelding wordt niet ondersteund."); - } } \ No newline at end of file diff --git a/website/queries/user.php b/website/queries/user.php index 4a7ee57..e712a6c 100644 --- a/website/queries/user.php +++ b/website/queries/user.php @@ -1,9 +1,22 @@ bindParam(":userID", $_SESSION["userID"]); + return $stmt->execute(); +} function getUserID($username) { - $stmt = $GLOBALS["db"]->prepare(" + $stmt = prepareQuery(" SELECT `userID` FROM @@ -18,7 +31,7 @@ function getUserID($username) { } function getUsername($userID) { - $stmt = $GLOBALS["db"]->prepare(" + $stmt = prepareQuery(" SELECT `username` FROM @@ -33,8 +46,9 @@ function getUsername($userID) { } function selectUser($me, $other) { - $stmt = $GLOBALS["db"]->prepare(" + $stmt = prepareQuery(" SELECT + `userID`, `username`, `birthdate`, `location`, @@ -44,7 +58,11 @@ function selectUser($me, $other) { ) AS profilepicture, `bio`, `user`.`creationdate`, - `onlinestatus`, + CASE `lastactivity` >= DATE_SUB(NOW(),INTERVAL 15 MINUTE) + WHEN TRUE THEN 'online' + WHEN FALSE THEN 'offline' + END AS `onlinestatus`, + `role`, `fname`, `lname`, CASE `status` IS NULL @@ -80,7 +98,7 @@ function selectUser($me, $other) { } function selectAllUserGroups($userID) { - $stmt = $GLOBALS["db"]->prepare(" + $stmt = prepareQuery(" SELECT `group_page`.`groupID`, `name`, @@ -94,7 +112,7 @@ function selectAllUserGroups($userID) { `group_page`.`groupID` = `group_member`.`groupID` WHERE `userID` = :userID AND - `role` = 1 + `role` = 'member' "); $stmt->bindParam(':userID', $userID, PDO::PARAM_INT); @@ -102,38 +120,8 @@ function selectAllUserGroups($userID) { return $stmt; } -function selectAllUserPosts($userID) { - $stmt = $GLOBALS["db"]->prepare(" - SELECT - `postID`, - `author`, - `title`, - CASE LENGTH(`content`) >= 150 AND `content` NOT LIKE 'bindParam(':userID', $userID, PDO::PARAM_INT); - if(!$stmt->execute()) { - return False; - } - return $stmt; -} - function select20UsersFromN($n) { - $q = $GLOBALS["db"]->prepare(" + $q = prepareQuery(" SELECT `userID`, `username`, @@ -154,7 +142,7 @@ function select20UsersFromN($n) { } function search20UsersFromN($n, $keyword) { - $q = $GLOBALS["db"]->prepare(" + $q = prepareQuery(" SELECT `userID`, `username`, @@ -178,7 +166,7 @@ function search20UsersFromN($n, $keyword) { } function search20UsersFromNByStatus($n, $keyword, $status) { - $q = $GLOBALS["db"]->prepare(" + $q = prepareQuery(" SELECT `userID`, `username`, @@ -206,7 +194,7 @@ function search20UsersFromNByStatus($n, $keyword, $status) { } function searchSomeUsersByStatus($n, $m, $keyword, $status) { - $q = $GLOBALS["db"]->prepare(" + $q = prepareQuery(" SELECT `userID`, `username`, @@ -235,7 +223,7 @@ function searchSomeUsersByStatus($n, $m, $keyword, $status) { } function countSomeUsersByStatus($keyword, $status) { - $q = $GLOBALS["db"]->prepare(" + $q = prepareQuery(" SELECT COUNT(*) FROM @@ -258,7 +246,7 @@ function countSomeUsersByStatus($keyword, $status) { function changeUserStatusByID($id, $status) { - $q = $GLOBALS["db"]->prepare(" + $q = prepareQuery(" UPDATE `user` SET @@ -274,7 +262,7 @@ function changeUserStatusByID($id, $status) { } function changeMultipleUserStatusByID($ids, $status) { - $q = $GLOBALS["db"]->prepare(" + $q = prepareQuery(" UPDATE `user` SET @@ -290,8 +278,27 @@ function changeMultipleUserStatusByID($ids, $status) { return $q; } +function changeMultipleUserStatusByIDAdmin($ids, $status) { + $q = prepareQuery(" + UPDATE + `user` + SET + `role` = :status + WHERE + FIND_IN_SET (`userID`, :ids) + AND NOT `role` = 'admin' + AND NOT `role` = 'owner' + "); + + $ids = implode(',', $ids); + $q->bindParam(':ids', $ids); + $q->bindParam(':status', $status); + $q->execute(); + return $q; +} + function selectRandomNotFriendUser($userID) { - $stmt = $GLOBALS["db"]->prepare(" + $stmt = prepareQuery(" SELECT `user`.`username` FROM @@ -319,7 +326,7 @@ function selectRandomNotFriendUser($userID) { } function searchSomeUsers($n, $m, $search) { - $stmt = $GLOBALS["db"]->prepare(" + $stmt = prepareQuery(" SELECT `userID`, `username`, @@ -331,9 +338,10 @@ function searchSomeUsers($n, $m, $search) { FROM `user` WHERE - `username` LIKE :keyword OR + (`username` LIKE :keyword OR `fname` LIKE :keyword OR - `lname` LIKE :keyword + `lname` LIKE :keyword) AND + `role` != 'banned' ORDER BY `fname`, `lname`, @@ -353,15 +361,16 @@ function searchSomeUsers($n, $m, $search) { } function countSomeUsers($search) { - $q = $GLOBALS["db"]->prepare(" + $q = prepareQuery(" SELECT COUNT(*) FROM `user` WHERE - `username` LIKE :keyword OR + (`username` LIKE :keyword OR `fname` LIKE :keyword OR - `lname` LIKE :keyword + `lname` LIKE :keyword) AND + `role` != 'banned' ORDER BY `fname`, `lname`, @@ -373,3 +382,33 @@ function countSomeUsers($search) { $q->execute(); return $q; } + +function getRoleByID($userID) { + $stmt = prepareQuery(" + SELECT + `role` + FROM + `user` + WHERE + `userID` = :userID + "); + + $stmt->bindParam(':userID', $userID); + $stmt->execute(); + return $stmt->fetch()["role"]; +} + +function editBanCommentByID($userID, $comment) { + $stmt = prepareQuery(" + UPDATE + `user` + SET + `bancomment` = :comment + WHERE + `userID` = :userID + "); + + $stmt->bindParam(':userID', $userID, PDO::PARAM_INT); + $stmt->bindParam(':comment', $comment); + $stmt->execute(); +} \ No newline at end of file diff --git a/website/views/adminpanel-grouptable.php b/website/views/adminpanel-grouptable.php new file mode 100644 index 0000000..9d2c8e8 --- /dev/null +++ b/website/views/adminpanel-grouptable.php @@ -0,0 +1,46 @@ + + + Gebruikersnaam + Status + Aantekening + Actie + + +fetch(PDO::FETCH_ASSOC)) { + $groupID = $group['groupID']; + $name = $group['name']; + $role = $group['status']; + $description = $group['description']; + + echo(" + + + + $name + $role + $description + + + + + + + + + "); +} \ No newline at end of file diff --git a/website/views/adminpanel-page.php b/website/views/adminpanel-page.php new file mode 100644 index 0000000..cfd73bc --- /dev/null +++ b/website/views/adminpanel-page.php @@ -0,0 +1,30 @@ +fetchColumn(); + +?> +Pagina: + + \ No newline at end of file diff --git a/website/views/adminpanel-table.php b/website/views/adminpanel-table.php new file mode 100644 index 0000000..aa790e6 --- /dev/null +++ b/website/views/adminpanel-table.php @@ -0,0 +1,73 @@ + + + Gebruikersnaam + Status + Aantekening + Actie + + + +fetch(PDO::FETCH_ASSOC)) { + $userID = $user['userID']; + $username = $user['username']; + $role = $user['role']; + $bancomment = $user['bancomment']; + + echo(" + + + + + $username + $role + +

    $bancomment
    +
    +
    + + + +
    +
    + + + +
    + + + +
    + + + "); +} diff --git a/website/views/adminpanel.php b/website/views/adminpanel.php index d97a9e8..a4da648 100644 --- a/website/views/adminpanel.php +++ b/website/views/adminpanel.php @@ -1,15 +1,11 @@ - - +
    @@ -61,19 +30,21 @@ $listm = $currentpage * $perpage;
    Zoek naar gebruikers of groepen:
    " + id="admin-searchform" + action="javascript:searchFromOne();" method="get"> +
    Type gebruiker:
    - > -
    > -
    + > +
    > -
    + > +
    > -
    + > +
    > + >
    > -
    + > +
    > + >
    Type groep:
    - > -
    - > -
    - > -
    - > -
    + > +
    + > +
    + > +
    -
    -
    -
    -

    Resultaat:

    - - fetchColumn(); - $mincount = min($listm, $countresults); - $minlist = min($listn + 1, $countresults); - ?> - Pagina:
    - -
    - -
    -
    +
    +
    +
    +

    Resultaat:

    +
    + +
    + + + - -
    - - - - - - - - - - fetch(PDO::FETCH_ASSOC)) { - $userID = $user['userID']; - $username = $user['username']; - $role = $user['role']; - $bancomment = $user['bancomment']; - $thispage = htmlspecialchars(basename($_SERVER['REQUEST_URI'])); - $function = "checkCheckAll(document.getElementById('checkall'))"; - - echo(" - - - - - - - - "); - } - } else { - $q = searchSomeGroupsByStatus($listn, $listm, $search, $groupstatus); - - while ($group = $q->fetch(PDO::FETCH_ASSOC)) { - $groupID = $group['groupID']; - $name = $group['name']; - $role = $group['status']; - $description = $group['description']; - $thispage = htmlspecialchars(basename($_SERVER['REQUEST_URI'])); - $function = "checkCheckAll(document.getElementById('checkall'))"; - - echo(" - - - - - - - - "); - } + if ($userinfo == 'owner') { + echo " + "; } ?> -
    GebruikersnaamStatusAantekeningActie
    - $username$role$bancomment -
    - - - -
    -
    - $name$role$description -
    - - - -
    -
    + +
    + + + + + +
    + + + +
    +

    - + \ No newline at end of file diff --git a/website/views/bdayInput.php b/website/views/bdayInput.php new file mode 100644 index 0000000..f4e440f --- /dev/null +++ b/website/views/bdayInput.php @@ -0,0 +1,37 @@ + + + diff --git a/website/views/chat-view.php b/website/views/chat-view.php index 0d90149..974b441 100644 --- a/website/views/chat-view.php +++ b/website/views/chat-view.php @@ -74,6 +74,7 @@ name="content" id="newContent" placeholder="Schrijf een bericht..." + autocomplete="off" autofocus required /> diff --git a/website/views/forgotPasswordModal.php b/website/views/forgotPasswordModal.php new file mode 100644 index 0000000..d3f12f9 --- /dev/null +++ b/website/views/forgotPasswordModal.php @@ -0,0 +1,36 @@ + + + + + \ No newline at end of file diff --git a/website/views/group.php b/website/views/group.php index c8ed118..f2f797d 100644 --- a/website/views/group.php +++ b/website/views/group.php @@ -1,122 +1,36 @@
    - +

    Groep verlaten

    -

    [groepnaam]

    -

    Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec dictum turpis quam, eu ultrices sapien hendrerit tincidunt. Nunc aliquam neque turpis, id porta quam iaculis id. Sed suscipit, nisl a fermentum congue, nunc augue finibus lectus, id varius nunc purus nec dolor. Integer laoreet tellus sit amet sapien auctor congue. Mauris laoreet eu elit vel rhoncus. Nam et tortor arcu. Maecenas sit amet leo quis tellus varius gravida. Sed quis fermentum odio, sed dictum nulla. Donec aliquam rutrum orci cursus tempus. Quisque sit amet ipsum eget velit aliquam facilisis ultricies quis ligula. Nunc nisi lacus, luctus non bibendum quis, sagittis sit amet odio.

    +

    +

    -

    Leden

    +

    Leden ()

    - [gebruikersnaam]'s profielfoto - [gebruikersnaam]'s profielfoto - [gebruikersnaam]'s profielfoto - [gebruikersnaam]'s profielfoto - [gebruikersnaam]'s profielfoto - [gebruikersnaam]'s profielfoto - [gebruikersnaam]'s profielfoto - [gebruikersnaam]'s profielfoto - [gebruikersnaam]'s profielfoto - [gebruikersnaam]'s profielfoto - [gebruikersnaam]'s profielfoto - [gebruikersnaam]'s profielfoto - [gebruikersnaam]'s profielfoto - [gebruikersnaam]'s profielfoto - [gebruikersnaam]'s profielfoto - [gebruikersnaam]'s profielfoto - [gebruikersnaam]'s profielfoto - [gebruikersnaam]'s profielfoto - [gebruikersnaam]'s profielfoto - [gebruikersnaam]'s profielfoto - [gebruikersnaam]'s profielfoto - [gebruikersnaam]'s profielfoto - [gebruikersnaam]'s profielfoto - [gebruikersnaam]'s profielfoto - [gebruikersnaam]'s profielfoto - - ...en nog 25 anderen! + \"""; + } + ?>

    -
    -

    Lorem

    -

    Lorem ipsum dolor sit amet, consectetur.

    -

    Enkele minuten geleden geplaatst

    -
    -
    -

    Image

    - Olympic Mountains, Washington -

    Gisteren geplaatst

    -
    -
    -

    Ipsum

    -

    Lorem ipsum dolor sit amet, consectetur adipisicing elit. Rem nihil alias amet dolores fuga totam sequi a cupiditate ipsa voluptas id facilis nobis.

    -

    Maandag geplaatst

    -
    -
    -

    Dolor

    -

    Lorem ipsum dolor sit amet, consectetur adipisicing elit.

    -

    4 Januari geplaatst

    -
    -
    -

    Sit

    -

    Lorem ipsum dolor sit.

    -

    4 Januari geplaatst

    -
    -
    -

    Image

    - Nunobiki Falls, Kobe Japan -

    4 Januari geplaatst

    -
    -
    -

    Amet

    -

    Lorem ipsum dolor sit amet, consectetur adipisicing elit. Minima asperiores eveniet vero velit eligendi aliquid in.

    -

    4 Januari geplaatst

    -
    -
    -

    Consectetur

    -

    Lorem ipsum dolor sit amet, consectetur adipisicing elit. Error aliquid reprehenderit expedita odio beatae est.

    -

    4 Januari geplaatst

    -
    -
    -

    Adipisicing

    -

    Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quaerat architecto quis tenetur fugiat veniam iste molestiae fuga labore!

    -

    4 Januari geplaatst

    -
    -
    -

    Elit

    -

    Lorem ipsum dolor sit amet, consectetur adipisicing elit. Rem ut debitis dolorum earum expedita eveniet voluptatem quibusdam facere eos numquam commodi ad iusto laboriosam rerum aliquam.

    -

    4 Januari geplaatst

    -
    -
    -

    Geen error

    -

    Lorem ipsum dolor sit amet, consectetur adipisicing elit. Doloribus dolorem maxime minima animi cum.

    -

    4 Januari geplaatst

    -
    -
    -

    Image

    - Oregon cliffs are no joke. -

    4 Januari geplaatst

    -
    -
    -

    Aliquid

    -

    Lorem ipsum dolor sit amet, consectetur.

    -

    4 Januari geplaatst

    -
    -
    -

    Odit

    -

    Lorem ipsum dolor sit amet, consectetur adipisicing elit. Odit accusamus tempore at porro officia rerum est impedit ea ipsa tenetur. Labore libero hic error sunt laborum expedita.

    -

    4 Januari geplaatst

    -
    -
    -

    Accusamus

    -

    Lorem ipsum dolor sit amet, consectetur adipisicing elit. Nobis quaerat suscipit ad.

    -

    4 Januari geplaatst

    -
    +
    +
    \ No newline at end of file diff --git a/website/views/head.php b/website/views/head.php index b6c2f21..284abb4 100644 --- a/website/views/head.php +++ b/website/views/head.php @@ -5,7 +5,6 @@ -
    - "/> - + "/>
    diff --git a/website/views/login-view.php b/website/views/login-view.php index de4c48b..8edc777 100644 --- a/website/views/login-view.php +++ b/website/views/login-view.php @@ -13,12 +13,13 @@
    - +
    @@ -26,6 +27,7 @@
    + +
    + +
    +
    - -
    - Registreer een account + + -
    + \ No newline at end of file diff --git a/website/views/menu.php b/website/views/menu.php index ac06c12..dab8fce 100644 --- a/website/views/menu.php +++ b/website/views/menu.php @@ -1,7 +1,7 @@ -