diff --git a/website/public/API/adminChangeUser.php b/website/public/API/adminChangeUser.php index 067a7ba..359497a 100644 --- a/website/public/API/adminChangeUser.php +++ b/website/public/API/adminChangeUser.php @@ -6,15 +6,20 @@ require_once ("../../queries/checkInput.php"); require_once ("../../queries/user.php"); require_once ("../../queries/group_page.php"); +$userinfo = getRoleByID($_SESSION['userID'])->fetch(PDO::FETCH_ASSOC); + if (isset($_POST["actions"]) && isset($_POST["userID"])) { changeUserStatusByID($_POST["userID"], $_POST["actions"]); } else if (isset($_POST["actions"]) && isset($_POST["groupID"])) { changeGroupStatusByID($_POST["groupID"], $_POST["actions"]); } else if (isset($_POST["batchactions"]) && isset($_POST["checkbox-user"])) { - changeMultipleUserStatusByID($_POST["checkbox-user"], $_POST["batchactions"]); + if ($userinfo['role'] == 'owner') { + changeMultipleUserStatusByID($_POST["checkbox-user"], $_POST["batchactions"]); + } else { + changeMultipleUserStatusByIDAdmin($_POST["checkbox-user"], $_POST["batchactions"]); + } } else if (isset($_POST["groupbatchactions"]) && isset($_POST["checkbox-group"])) { changeMultipleGroupStatusByID($_POST["checkbox-group"], $_POST["groupbatchactions"]); +} else if (isset($_POST['bancommentuserID']) && isset($_POST['bancommenttext'])) { + editBanCommentByID($_POST['bancommentuserID'], $_POST['bancommenttext']); } - -//header("location: ../admin.php"); -print_r($_POST); \ No newline at end of file diff --git a/website/public/API/adminPageNumber.php b/website/public/API/adminPageNumber.php index a6ac554..c829249 100644 --- a/website/public/API/adminPageNumber.php +++ b/website/public/API/adminPageNumber.php @@ -5,6 +5,7 @@ session_start(); require_once ("../../queries/connect.php"); require_once ("../../queries/checkInput.php"); require_once ("../../queries/user.php"); +require_once ("../../queries/group_page.php"); $search = ""; if (isset($_POST["search"])) { @@ -21,8 +22,17 @@ if (isset($_POST['status'])) { $status = $_POST["status"]; } -if ($pagetype == "user") { - include ("../../views/adminpanel-page.php"); -} else { - echo "Pagenumber failed!"; +$groupstatus = array(); +if (isset($_POST['groupstatus'])) { + $groupstatus = $_POST["groupstatus"]; } + +$entries = 20; +$currentpage = 1; +if (isset($_POST['currentpage'])) { + $currentpage = (int) test_input($_POST["currentpage"]); +} + +$offset = (int) $currentpage * $entries - $entries; + +include ("../../views/adminpanel-page.php"); diff --git a/website/public/API/adminSearchUsers.php b/website/public/API/adminSearchUsers.php index c809db7..5f7944b 100644 --- a/website/public/API/adminSearchUsers.php +++ b/website/public/API/adminSearchUsers.php @@ -8,13 +8,11 @@ require_once ("../../queries/user.php"); require_once ("../../queries/group_page.php"); $offset = 0; -if (isset($_POST["n"])) { - $offset = (int) test_input($_POST["n"]); -} $entries = 20; -if (isset($_POST["m"])) { - $entries = (int) test_input($_POST["m"]); +if (isset($_POST["currentpage"])) { + $offset = (int) test_input($_POST["currentpage"]) * $entries - $entries; } + $search = ""; if (isset($_POST["search"])) { $search = test_input($_POST["search"]); @@ -35,6 +33,8 @@ if (isset($_POST['groupstatus'])) { $groupstatus = $_POST["groupstatus"]; } +$userinfo = getRoleByID($_SESSION['userID']); + if ($pagetype == "user") { include ("../../views/adminpanel-table.php"); } else if ($pagetype == "group") { diff --git a/website/public/admin.php b/website/public/admin.php index b264c25..ddcbbf2 100644 --- a/website/public/admin.php +++ b/website/public/admin.php @@ -8,7 +8,7 @@ - +
input, label").click(function(){ - adminSearch(); + $("#admin-filter, #admin-groupfilter > input, label").change(function(){ + searchFromOne(); }); $("#pagetype").change(function(){ - adminSearch(); + searchFromOne(); }); - adminSearch(); + /* Update hidden input to be equal to submit pressed, + because serialize doesn't take submit values. */ + $('#admin-batchform > button').click(function () { + $('#batchinput').prop('value', $(this).prop('value')); + console.log($('#batchinput').prop('value')); + }); + + $('#admin-groupbatchform > button').click(function () { + $('#groupbatchinput').prop('value', $(this).prop('value')); + console.log($('#batchinput').prop('value')); + }); }); -function checkAll(allbox) { - var checkboxes = document.getElementsByClassName('checkbox-list'); - - for (var i = 0; i < checkboxes.length; i++) { - if (checkboxes[i].type == 'checkbox') { - checkboxes[i].checked = allbox.checked; - } - } +function checkAll() { + $('.checkbox-list').each(function () { + $(this).prop('checked', $('#checkall').prop('checked')); + }); } -function checkCheckAll(allbox) { - var checkboxes = document.getElementsByClassName('checkbox-list'); +function checkCheckAll() { var checked = true; - for (var i = 0; i < checkboxes.length; i++) { - if (checkboxes[i].type == 'checkbox') { - if (checkboxes[i].checked == false) { - checked = false; - break; - } + $('.checkbox-list').each(function () { + if ($(this).prop('checked') == false) { + checked = false; + return; } - } - allbox.checked = checked; + }); + + $('#checkall').prop('checked', checked); } function changeFilter() { @@ -55,12 +61,28 @@ function changeFilter() { } } +function searchFromOne() { + $('#currentpage').prop('value', 1); + adminSearch(); +} + function adminSearch() { + console.log($("#admin-searchform").serialize()); $.post( "API/adminSearchUsers.php", $("#admin-searchform").serialize() ).done(function (data) { $("#usertable").html(data); + updatePageN(); + }) +} + +function adminUpdate(form) { + $.post( + "API/adminChangeUser.php", + $(form).serialize() + ).done(function () { + adminSearch(); }) } @@ -71,4 +93,18 @@ function updatePageN() { ).done(function (data) { $("#admin-pageinfo").html(data); }) +} + +function toggleBancomment(button) { + $(button).siblings("div").toggle(); + $(button).toggle(); +} + +function editComment(form) { + $.post( + "API/adminChangeUser.php", + $(form).serialize() + ).done(function (data) { + adminSearch(); + }); } \ No newline at end of file diff --git a/website/public/styles/adminpanel.css b/website/public/styles/adminpanel.css index 4d55945..0648118 100644 --- a/website/public/styles/adminpanel.css +++ b/website/public/styles/adminpanel.css @@ -43,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/queries/user.php b/website/queries/user.php index 2d6a8c0..e712a6c 100644 --- a/website/queries/user.php +++ b/website/queries/user.php @@ -278,6 +278,25 @@ 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 = prepareQuery(" SELECT @@ -377,4 +396,19 @@ function getRoleByID($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 index 4999666..9d2c8e8 100644 --- a/website/views/adminpanel-grouptable.php +++ b/website/views/adminpanel-grouptable.php @@ -16,7 +16,6 @@ while ($group = $q->fetch(PDO::FETCH_ASSOC)) { $name = $group['name']; $role = $group['status']; $description = $group['description']; - $function = "checkCheckAll(document.getElementById('checkall'))"; echo("