From e464f5bca2535a1d80df8a535f318cc1c6329c21 Mon Sep 17 00:00:00 2001 From: Hendrik Date: Mon, 30 Jan 2017 16:32:57 +0100 Subject: [PATCH 1/4] cleaned admin.js, add admin/owner check (frontend), fix submit ajax --- website/public/API/adminChangeUser.php | 3 -- website/public/API/adminSearchUsers.php | 2 + website/public/admin.php | 2 +- website/public/js/admin.js | 56 ++++++++++++++++--------- website/public/styles/adminpanel.css | 2 +- website/views/adminpanel-grouptable.php | 6 +-- website/views/adminpanel-table.php | 28 ++++++++----- website/views/adminpanel.php | 27 ++++++++---- 8 files changed, 79 insertions(+), 47 deletions(-) diff --git a/website/public/API/adminChangeUser.php b/website/public/API/adminChangeUser.php index 067a7ba..5c9384c 100644 --- a/website/public/API/adminChangeUser.php +++ b/website/public/API/adminChangeUser.php @@ -15,6 +15,3 @@ if (isset($_POST["actions"]) && isset($_POST["userID"])) { } else if (isset($_POST["groupbatchactions"]) && isset($_POST["checkbox-group"])) { changeMultipleGroupStatusByID($_POST["checkbox-group"], $_POST["groupbatchactions"]); } - -//header("location: ../admin.php"); -print_r($_POST); \ No newline at end of file diff --git a/website/public/API/adminSearchUsers.php b/website/public/API/adminSearchUsers.php index c809db7..f1d7fc1 100644 --- a/website/public/API/adminSearchUsers.php +++ b/website/public/API/adminSearchUsers.php @@ -35,6 +35,8 @@ if (isset($_POST['groupstatus'])) { $groupstatus = $_POST["groupstatus"]; } +$userinfo = getRoleByID($_SESSION['userID'])->fetch(PDO::FETCH_ASSOC); + 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 2785606..13a025d 100644 --- a/website/public/admin.php +++ b/website/public/admin.php @@ -8,7 +8,7 @@ - + input, label").click(function(){ + $("#admin-filter, #admin-groupfilter > input, label").change(function(){ adminSearch(); }); $("#pagetype").change(function(){ 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')); + }); + adminSearch(); }); -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() { @@ -60,11 +66,21 @@ function adminSearch() { "API/adminSearchUsers.php", $("#admin-searchform").serialize() ).done(function (data) { - console.log(data); + // console.log(data); $("#usertable").html(data); }) } +function adminUpdate(form) { + console.log($(form).serialize()); + $.post( + "API/adminChangeUser.php", + $(form).serialize() + ).done(function () { + adminSearch(); + }) +} + function updatePageN() { $.post( "API/adminPageNumber.php", diff --git a/website/public/styles/adminpanel.css b/website/public/styles/adminpanel.css index f9410e1..75fa8b1 100644 --- a/website/public/styles/adminpanel.css +++ b/website/public/styles/adminpanel.css @@ -44,7 +44,7 @@ padding: 3px; } -.usertable tr { +.usertable th, tr { text-align: left; } 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(" @@ -25,15 +24,14 @@ while ($group = $q->fetch(PDO::FETCH_ASSOC)) { class='checkbox-list' value='$groupID' form='admin-groupbatchform' - onchange='$function'> + onchange='checkCheckAll();'> $name $role $description
+ onsubmit=\"adminUpdate(this); return false;\"> + Gebruikersnaam Status Aantekening @@ -14,7 +14,6 @@ while($user = $q->fetch(PDO::FETCH_ASSOC)) { $username = $user['username']; $role = $user['role']; $bancomment = $user['bancomment']; - $function = "checkCheckAll(document.getElementById('checkall'))"; echo(" @@ -24,20 +23,29 @@ while($user = $q->fetch(PDO::FETCH_ASSOC)) { class='checkbox-list' value='$userID' form='admin-batchform' - onchange='$function'> + onchange='checkCheckAll();'> $username $role $bancomment - + onsubmit=\"adminUpdate(this); return false;\"> +
diff --git a/website/views/adminpanel.php b/website/views/adminpanel.php index c48a28d..d2b83d2 100644 --- a/website/views/adminpanel.php +++ b/website/views/adminpanel.php @@ -7,6 +7,7 @@ $perpage = 20; $status = array("user", "frozen", "banned", "unconfirmed", "admin", "owner"); $groupstatus = array("hidden", "public", "membersonly"); $pagetype = "user"; +$userinfo = getRoleByID($_SESSION['userID'])->fetch(PDO::FETCH_ASSOC); if (isset($_GET["search"])) { $search = test_input($_GET["search"]); @@ -123,20 +124,30 @@ if ($_SERVER["REQUEST_METHOD"] == "POST") { -
+ + + Maak Admin + "; + } + ?>
-
+ + From eb12b6ba7da8194d479358a904837f919ead8c87 Mon Sep 17 00:00:00 2001 From: Hendrik Date: Tue, 31 Jan 2017 13:11:23 +0100 Subject: [PATCH 2/4] fixed pageselector in admin --- website/public/API/adminChangeUser.php | 8 ++++- website/public/API/adminPageNumber.php | 18 +++++++++--- website/public/API/adminSearchUsers.php | 8 ++--- website/public/js/admin.js | 19 +++++++----- website/queries/user.php | 19 ++++++++++++ website/views/adminpanel-page.php | 39 ++++++++++++------------- website/views/adminpanel.php | 15 ++-------- 7 files changed, 77 insertions(+), 49 deletions(-) diff --git a/website/public/API/adminChangeUser.php b/website/public/API/adminChangeUser.php index 5c9384c..72acb8c 100644 --- a/website/public/API/adminChangeUser.php +++ b/website/public/API/adminChangeUser.php @@ -6,12 +6,18 @@ 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"]); } 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 f1d7fc1..58b170a 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"]); diff --git a/website/public/js/admin.js b/website/public/js/admin.js index c43e6ae..7e2efad 100644 --- a/website/public/js/admin.js +++ b/website/public/js/admin.js @@ -1,14 +1,16 @@ $(window).on("load", function () { changeFilter(); + searchFromOne(); + $(".admin-searchinput").keyup(function(){ - adminSearch(); + searchFromOne(); }); // all inputs and labels directly under admin filter and groupfilter $("#admin-filter, #admin-groupfilter > input, label").change(function(){ - adminSearch(); + searchFromOne(); }); $("#pagetype").change(function(){ - adminSearch(); + searchFromOne(); }); /* Update hidden input to be equal to submit pressed, @@ -22,8 +24,6 @@ $(window).on("load", function () { $('#groupbatchinput').prop('value', $(this).prop('value')); console.log($('#batchinput').prop('value')); }); - - adminSearch(); }); function checkAll() { @@ -61,18 +61,23 @@ 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) { - // console.log(data); $("#usertable").html(data); + updatePageN(); }) } function adminUpdate(form) { - console.log($(form).serialize()); $.post( "API/adminChangeUser.php", $(form).serialize() diff --git a/website/queries/user.php b/website/queries/user.php index 0900d9f..bf20e7d 100644 --- a/website/queries/user.php +++ b/website/queries/user.php @@ -307,6 +307,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 diff --git a/website/views/adminpanel-page.php b/website/views/adminpanel-page.php index a17ce50..cfd73bc 100644 --- a/website/views/adminpanel-page.php +++ b/website/views/adminpanel-page.php @@ -5,27 +5,26 @@ if ($pagetype == "user") { $pages = countSomeGroupsByStatus($search, $groupstatus); } $countresults = $pages->fetchColumn(); -$mincount = min($listm, $countresults); -$minlist = min($listn + 1, $countresults); + ?> - Pagina: - + $i"; + } else { + echo ""; } - ?> - - + } + ?> + \ No newline at end of file diff --git a/website/views/adminpanel.php b/website/views/adminpanel.php index d2b83d2..f1d27a1 100644 --- a/website/views/adminpanel.php +++ b/website/views/adminpanel.php @@ -2,8 +2,6 @@
@@ -40,7 +31,7 @@ if ($_SERVER["REQUEST_METHOD"] == "POST") {