From ac83bb750bbe3359904f8d3b0e90788c0064c304 Mon Sep 17 00:00:00 2001 From: Hendrik Date: Mon, 23 Jan 2017 16:05:22 +0100 Subject: [PATCH 1/3] fix status for enums, fix pages --- website/views/adminpanel.php | 64 ++++++++++++++++++------------------ 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/website/views/adminpanel.php b/website/views/adminpanel.php index e53d679..834f54f 100644 --- a/website/views/adminpanel.php +++ b/website/views/adminpanel.php @@ -85,37 +85,37 @@ $listm = $currentpage * $perpage;

Show:

- > + >
- > + >
- > + >
- > + >
- > + >
- > + >

Show:

- > + >
- > + >
- > + >
@@ -138,11 +138,11 @@ $listm = $currentpage * $perpage; id="admin-batchform" action="" method="post"> - +
- +
- +

@@ -154,11 +154,11 @@ $listm = $currentpage * $perpage; id="admin-groupbatchform" action="" method="post"> - +
- +
- +

@@ -225,7 +225,7 @@ $listm = $currentpage * $perpage; $listm = $currentpage * $perpage; if ($pagetype == 'user') { - $q = searchSomeUsersByStatus($listn, $listm, $search, $status); + $q = searchSomeUsersByStatus($listn, $perpage, $search, $status); while($user = $q->fetch(PDO::FETCH_ASSOC)) { $userID = $user['userID']; @@ -252,9 +252,9 @@ $listm = $currentpage * $perpage; action='$thispage' method='post'> @@ -264,7 +264,7 @@ $listm = $currentpage * $perpage; "); } } else { - $q = searchSomeGroupsByStatus($listn, $listm, $search, $groupstatus); + $q = searchSomeGroupsByStatus($listn, $perpage, $search, $groupstatus); while ($group = $q->fetch(PDO::FETCH_ASSOC)) { $groupID = $group['groupID']; @@ -291,9 +291,9 @@ $listm = $currentpage * $perpage; action='$thispage' method='post'> From 1a53d01747efff5f90c995f91e2b226ffea7fe23 Mon Sep 17 00:00:00 2001 From: Hendrik Date: Thu, 26 Jan 2017 13:29:56 +0100 Subject: [PATCH 2/3] add authentication --- website/public/admin.php | 8 ++++++++ website/queries/user.php | 15 +++++++++++++++ website/views/adminpanel.php | 1 + 3 files changed, 24 insertions(+) diff --git a/website/public/admin.php b/website/public/admin.php index 5faa096..fcd386a 100644 --- a/website/public/admin.php +++ b/website/public/admin.php @@ -12,6 +12,14 @@ * This view adds the main layout over the screen. * Header and menu. */ +include_once ("../queries/user.php"); + +$userinfo = getRoleByID($_SESSION['userID'])->fetch(PDO::FETCH_ASSOC); + +if ($userinfo['role'] != 'admin' AND $userinfo['role'] != 'owner') { + header("location:profile.php"); +} + include("../views/main.php"); /* Add your view files here. */ diff --git a/website/queries/user.php b/website/queries/user.php index be06197..104d526 100644 --- a/website/queries/user.php +++ b/website/queries/user.php @@ -370,3 +370,18 @@ function countSomeUsers($search) { $q->execute(); return $q; } + +function getRoleByID($userID) { + $stmt = $GLOBALS['db']->prepare(" + SELECT + `role` + FROM + `user` + WHERE + `userID` = :userID + "); + + $stmt->bindParam(':userID', $userID); + $stmt->execute(); + return $stmt; +} \ No newline at end of file diff --git a/website/views/adminpanel.php b/website/views/adminpanel.php index 86fbb36..fd10d15 100644 --- a/website/views/adminpanel.php +++ b/website/views/adminpanel.php @@ -2,6 +2,7 @@ Date: Fri, 27 Jan 2017 16:14:54 +0100 Subject: [PATCH 3/3] improve adminpanel w/ ajax, enum fixes, misc fixes --- website/public/API/adminChangeUser.php | 20 +++ website/public/API/adminPageNumber.php | 28 ++++ website/public/API/adminSearchUsers.php | 44 +++++ website/public/admin.php | 7 +- website/public/js/admin.js | 43 ++++- website/queries/group_page.php | 9 +- website/views/adminpanel-grouptable.php | 48 ++++++ website/views/adminpanel-page.php | 31 ++++ website/views/adminpanel-table.php | 47 ++++++ website/views/adminpanel.php | 210 ++++-------------------- 10 files changed, 302 insertions(+), 185 deletions(-) create mode 100644 website/public/API/adminChangeUser.php create mode 100644 website/public/API/adminPageNumber.php create mode 100644 website/public/API/adminSearchUsers.php create mode 100644 website/views/adminpanel-grouptable.php create mode 100644 website/views/adminpanel-page.php create mode 100644 website/views/adminpanel-table.php diff --git a/website/public/API/adminChangeUser.php b/website/public/API/adminChangeUser.php new file mode 100644 index 0000000..067a7ba --- /dev/null +++ b/website/public/API/adminChangeUser.php @@ -0,0 +1,20 @@ + - + + fetch(PDO::FETCH_ASSOC); if ($userinfo['role'] != 'admin' AND $userinfo['role'] != 'owner') { diff --git a/website/public/js/admin.js b/website/public/js/admin.js index e3dfdd7..140c99a 100644 --- a/website/public/js/admin.js +++ b/website/public/js/admin.js @@ -1,6 +1,18 @@ -window.onload = function() { +$(window).on("load", function () { changeFilter(); -}; + $(".admin-searchinput").keyup(function(){ + adminSearch(); + }); + // all inputs and labels directly under admin filter and groupfilter + $("#admin-filter, #admin-groupfilter > input, label").click(function(){ + adminSearch(); + }); + $("#pagetype").change(function(){ + adminSearch(); + }); + + adminSearch(); +}); function checkAll(allbox) { var checkboxes = document.getElementsByClassName('checkbox-list'); @@ -32,13 +44,32 @@ function changeFilter() { document.getElementById('admin-filter').style.display = 'none'; document.getElementById('admin-groupfilter').style.display = 'inline-block'; - document.getElementById('admin-batchactions').style.display = 'none'; - document.getElementById('admin-groupbatchactions').style.display = 'inline-block'; + document.getElementById('admin-batchform').style.display = 'none'; + document.getElementById('admin-groupbatchform').style.display = 'inline-block'; } else { document.getElementById('admin-filter').style.display = 'inline-block'; document.getElementById('admin-groupfilter').style.display = 'none'; - document.getElementById('admin-batchactions').style.display = 'inline-block'; - document.getElementById('admin-groupbatchactions').style.display = 'none'; + document.getElementById('admin-batchform').style.display = 'inline-block'; + document.getElementById('admin-groupbatchform').style.display = 'none'; } } + +function adminSearch() { + $.post( + "API/adminSearchUsers.php", + $("#admin-searchform").serialize() + ).done(function (data) { + console.log(data); + $("#usertable").html(data); + }) +} + +function updatePageN() { + $.post( + "API/adminPageNumber.php", + $("#admin-searchform").serialize() + ).done(function (data) { + $("#admin-pageinfo").html(data); + }) +} \ No newline at end of file diff --git a/website/queries/group_page.php b/website/queries/group_page.php index f3de045..cdef6ae 100644 --- a/website/queries/group_page.php +++ b/website/queries/group_page.php @@ -143,15 +143,18 @@ function countSomeGroupsByStatus($keyword, $status) { } function changeGroupStatusByID($id, $status) { - $q = $GLOBALS["db"]->query(" + $q = $GLOBALS["db"]->prepare(" 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; } diff --git a/website/views/adminpanel-grouptable.php b/website/views/adminpanel-grouptable.php new file mode 100644 index 0000000..4999666 --- /dev/null +++ b/website/views/adminpanel-grouptable.php @@ -0,0 +1,48 @@ + + + Gebruikersnaam + Status + Aantekening + Actie + + +fetch(PDO::FETCH_ASSOC)) { + $groupID = $group['groupID']; + $name = $group['name']; + $role = $group['status']; + $description = $group['description']; + $function = "checkCheckAll(document.getElementById('checkall'))"; + + 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..a17ce50 --- /dev/null +++ b/website/views/adminpanel-page.php @@ -0,0 +1,31 @@ +fetchColumn(); +$mincount = min($listm, $countresults); +$minlist = min($listn + 1, $countresults); +?> + 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..a21c9d6 --- /dev/null +++ b/website/views/adminpanel-table.php @@ -0,0 +1,47 @@ + + + Gebruikersnaam + Status + Aantekening + Actie + + + +fetch(PDO::FETCH_ASSOC)) { + $userID = $user['userID']; + $username = $user['username']; + $role = $user['role']; + $bancomment = $user['bancomment']; + $function = "checkCheckAll(document.getElementById('checkall'))"; + + echo(" + + + + + $username + $role + $bancomment + +
+ + + +
+ + + "); +} diff --git a/website/views/adminpanel.php b/website/views/adminpanel.php index fd10d15..c48a28d 100644 --- a/website/views/adminpanel.php +++ b/website/views/adminpanel.php @@ -1,15 +1,11 @@ - -
@@ -62,7 +38,8 @@ $listm = $currentpage * $perpage;
Zoek naar gebruikers of groepen:
" + id="admin-searchform" + action="javascript:adminSearch();" method="get"> +
Type gebruiker:
- > -
> -
+
> -
+
> -
+
> -
+
Type groep:
- > -
- > -
- > -
- > -
+ > +
+ > +
+ > +
+

Resultaat:

- - fetchColumn(); - $mincount = min($listm, $countresults); - $minlist = min($listn + 1, $countresults); - ?> - Pagina:
- -
- -
+ + +
+
+ + + + +
- - - - - - - - - - - if ($pagetype == 'user') { - $q = searchSomeUsersByStatus($listn, $listm, $search, $status); - while($user = $q->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(" - - - - - - - - "); - } - } - ?>
GebruikersnaamStatusAantekeningActie
- $username$role$bancomment -
- - - -
-
- $name$role$description -
- - - -
-