diff --git a/website/public/groupAdmin.php b/website/public/groupAdmin.php index 6095149..ec6eee8 100644 --- a/website/public/groupAdmin.php +++ b/website/public/groupAdmin.php @@ -21,6 +21,8 @@ require_once "../queries/alerts.php"; include("../views/main.php"); $alertClass; $alertMessage; + +// Select which button has been pressed. if ($_SERVER["REQUEST_METHOD"] == "POST") { try { switch ($_POST["form"]) { @@ -44,6 +46,15 @@ if ($_SERVER["REQUEST_METHOD"] == "POST") { } upgradeUser($_POST["groupID"], $_POST["userID"], "admin"); break; + case "deadmin": + if (!array_key_exists("userID", $_POST)) { + throw new AngryAlert("Geen gebruiker geselecteerd."); + } + upgradeUser($_POST["groupID"], $_POST["userID"], "member"); + break; + case "delete": + deleteGroup(); + break; } } catch (AlertMessage $w) { $alertClass = $w->getClass(); diff --git a/website/public/js/admin.js b/website/public/js/admin.js index e0dc9f7..76180d9 100644 --- a/website/public/js/admin.js +++ b/website/public/js/admin.js @@ -24,12 +24,14 @@ $(window).on("load", function () { }); }); +// Toggles all checkboxes based on one. function checkAll() { $('.checkbox-list').each(function () { $(this).prop('checked', $('#checkall').prop('checked')); }); } +// Simple function that checks if checkall should stay checked. function checkCheckAll() { var checked = true; @@ -43,6 +45,7 @@ function checkCheckAll() { $('#checkall').prop('checked', checked); } +// Toggle of filter options. function changeFilter() { if ($('#pagetype').find(":selected").val() == "group") { document.getElementById('admin-filter').style.display = 'none'; @@ -59,11 +62,13 @@ function changeFilter() { } } +// Sets the search page to one, relevant when changing filter or search. function searchFromOne() { $('#currentpage').prop('value', 1); adminSearch(); } +// AJAX live search. function adminSearch() { $.post( "API/adminSearchUsers.php", @@ -74,6 +79,7 @@ function adminSearch() { }) } +// AJAX live update. function adminUpdate(form) { $.post( "API/adminChangeUser.php", @@ -83,6 +89,7 @@ function adminUpdate(form) { }) } +// AJAX pagenumber functionality. function updatePageN() { $.post( "API/adminPageNumber.php", @@ -92,11 +99,13 @@ function updatePageN() { }) } +// Intended for the edit button to show a form. function toggleBancomment(button) { $(button).siblings("div").toggle(); $(button).toggle(); } +// AJAX value editing. function editComment(form) { $.post( "API/adminChangeUser.php", diff --git a/website/public/js/masonry.js b/website/public/js/masonry.js index d43577b..1a27677 100644 --- a/website/public/js/masonry.js +++ b/website/public/js/masonry.js @@ -91,6 +91,21 @@ $(window).on("load", function() { loadMorePosts(userID, groupID, postAmount, postLimit); } }; + + $(document).keyup(function(e) { + if (e.keyCode == 27) { + closeModal(); + } + }); + + $('.modal').click(function() { + closeModal(); + }); + + $('.modal-content').click(function(event){ + event.stopPropagation(); + }); + }); function closeModal() { diff --git a/website/public/settings.php b/website/public/settings.php index 9247d26..7208141 100644 --- a/website/public/settings.php +++ b/website/public/settings.php @@ -14,6 +14,8 @@ getClass(); diff --git a/website/public/styles/adminpanel.css b/website/public/styles/adminpanel.css index 3e97ace..888b4ca 100644 --- a/website/public/styles/adminpanel.css +++ b/website/public/styles/adminpanel.css @@ -36,9 +36,10 @@ width: 100%; } -.usertable .table-username {width: 150px} -.usertable .table-status {width: 100px} -.usertable .table-action {width: 200px} +.table-checkbox {width: 20px} +.table-username {width: 150px} +.table-status {width: 100px} +.table-action {width: 200px} .usertable th, td { border-bottom: 1px solid #ddd; @@ -54,6 +55,10 @@ background-color: #f5f5f5; } +.bancomment { + width: 80%; +} + .bancommentedit { display: none; } diff --git a/website/queries/checkInput.php b/website/queries/checkInput.php index 247050b..3d17f43 100644 --- a/website/queries/checkInput.php +++ b/website/queries/checkInput.php @@ -216,6 +216,7 @@ function test_input($data) { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); + $data = trim($data); return $data; } diff --git a/website/queries/connect.php b/website/queries/connect.php index 3971a74..30ce271 100644 --- a/website/queries/connect.php +++ b/website/queries/connect.php @@ -10,6 +10,11 @@ else { or die('Error connecting to mysql server'); } +/** + * Helperfunction to create a database query. + * @param string $query + * @return PDOStatement + */ function prepareQuery(string $query) : PDOStatement { return $GLOBALS["db"]->prepare($query); } \ No newline at end of file diff --git a/website/queries/createGroup.php b/website/queries/createGroup.php index 20ee28b..1b093fb 100644 --- a/website/queries/createGroup.php +++ b/website/queries/createGroup.php @@ -2,6 +2,10 @@ require_once "../queries/checkInput.php"; require_once "../queries/picture.php"; require_once "../queries/alerts.php"; + +/** + * Creates a group. + */ function createGroup() { $createGroup = prepareQuery(" diff --git a/website/queries/groupAdmin.php b/website/queries/groupAdmin.php index e3580b6..8cefb9b 100644 --- a/website/queries/groupAdmin.php +++ b/website/queries/groupAdmin.php @@ -1,4 +1,9 @@ fetch(); } +/** + * Updates the settings for a group. + * @param int $groupID + * @throws AngryAlert + * @throws HappyAlert + */ function updateGroupSettings(int $groupID) { if (!checkGroupAdmin($groupID, $_SESSION["userID"])) { @@ -40,6 +51,12 @@ function updateGroupSettings(int $groupID) } } +/** + * Checks if an user is an admin for a page. + * @param int $groupID + * @param int $userID + * @return bool + */ function checkGroupAdmin(int $groupID, int $userID) : bool { $stmt = prepareQuery(" SELECT @@ -60,7 +77,40 @@ function checkGroupAdmin(int $groupID, int $userID) : bool { return ($role == "admin"); } -function getAllGroupMembers(int $groupID) { +/** + * Returns all normal members for a group. + * @param int $groupID + * @return array|bool + */ +function getAllGroupUsers(int $groupID) { + return getAllGroupMembers($groupID, 'member'); +} + +/** + * Returns all admin for a group. + * @param int $groupID + * @return array|bool + */ +function getAllGroupAdmins(int $groupID) { + return getAllGroupMembers($groupID, 'admin'); +} + +/** + * Returns all Moderators for a group. + * @param int $groupID + * @return array|bool + */ +function getAllGroupMods(int $groupID) { + return getAllGroupMembers($groupID, 'mod'); +} + +/** + * Returns all members for a group specified by a string. + * @param int $groupID + * @param string $role + * @return array|bool + */ +function getAllGroupMembers(int $groupID, string $role) { $stmt = prepareQuery(" SELECT `username`, @@ -74,16 +124,25 @@ function getAllGroupMembers(int $groupID) { ON `group_member`.`userID` = `user`.`userID` WHERE - `groupID` = :groupID AND `group_member`.`role` = 'member' + `groupID` = :groupID AND `group_member`.`role` = :role "); $stmt->bindParam(':groupID', $groupID); + $stmt->bindParam(":role", $role); if (!$stmt->execute()) { return False; } return $stmt->fetchAll(); } +/** + * Upgrades or downgrades a groupmember to a different role. + * @param int $groupID + * @param int $userID + * @param string $role + * @throws AngryAlert + * @throws HappyAlert + */ function upgradeUser(int $groupID, int $userID, string $role) { if (!checkGroupAdmin($groupID, $_SESSION["userID"])) { throw new AngryAlert("Geen toestemming om te wijzigen"); @@ -106,4 +165,28 @@ function upgradeUser(int $groupID, int $userID, string $role) { } else { throw new AngryAlert("Er is iets mis gegaan"); } +} + +/** + * Removes a group form the database. + * @throws AngryAlert + * @throws HappyAlert + */ +function deleteGroup() { + if (!checkGroupAdmin($_POST["groupID"], $_SESSION["userID"])) { + throw new AngryAlert("Geen toestemming om de groep te verwijderen!"); + } + $stmt = prepareQuery(" + DELETE FROM + `group_page` + WHERE + `groupID` = :groupID + "); + $stmt->bindValue(":groupID", $_POST["groupID"]); + $stmt->execute(); + if ($stmt->rowCount()) { + throw new HappyAlert("Group verwijderd!"); + } else { + throw new AngryAlert("Er is iets mis gegaan"); + } } \ No newline at end of file diff --git a/website/queries/login.php b/website/queries/login.php index 3480991..4b8dcfa 100644 --- a/website/queries/login.php +++ b/website/queries/login.php @@ -35,8 +35,7 @@ function getUserID() { } function validateLogin($username, $password, $url){ - echo $url; - // Empty username or password field + // Empty username or password field if (empty($username) || empty($password)) { throw new loginException("Inloggegevens zijn niet ingevuld"); } diff --git a/website/queries/settings.php b/website/queries/settings.php index 26237ec..6d6dc74 100644 --- a/website/queries/settings.php +++ b/website/queries/settings.php @@ -16,7 +16,10 @@ function getSettings() { `location`, `birthdate`, `bio`, - `profilepicture`, + IFNULL( + `profilepicture`, + '../img/avatar-standard.png' + ) AS profilepicture, `showBday`, `showEmail`, `showProfile` diff --git a/website/views/adminpanel-grouptable.php b/website/views/adminpanel-grouptable.php index 2449b3d..d30e2ba 100644 --- a/website/views/adminpanel-grouptable.php +++ b/website/views/adminpanel-grouptable.php @@ -3,7 +3,7 @@