Marijn button #99
@@ -69,6 +69,57 @@ function search20UsersFromNByStatus($db, $n, $keyword, $status) {
|
|||||||
return $q;
|
return $q;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function searchSomeUsersByStatus($db, $n, $m, $keyword, $status) {
|
||||||
|
$q = $db->prepare("
|
||||||
|
SELECT
|
||||||
|
`userID`,
|
||||||
|
`username`,
|
||||||
|
`role`,
|
||||||
|
`bancomment`
|
||||||
|
FROM
|
||||||
|
`user`
|
||||||
|
WHERE
|
||||||
|
`username` LIKE :keyword AND
|
||||||
|
FIND_IN_SET (`role`, :statuses)
|
||||||
|
ORDER BY
|
||||||
|
`role`,
|
||||||
|
`username`
|
||||||
|
LIMIT
|
||||||
|
:n, :m
|
||||||
|
");
|
||||||
|
|
||||||
|
$keyword = "%$keyword%";
|
||||||
|
$q->bindParam(':keyword', $keyword);
|
||||||
|
$q->bindParam(':n', $n, PDO::PARAM_INT);
|
||||||
|
$q->bindParam(':m', $m, PDO::PARAM_INT);
|
||||||
|
$statuses = implode(',', $status);
|
||||||
|
$q->bindParam(':statuses', $statuses);
|
||||||
|
$q->execute();
|
||||||
|
return $q;
|
||||||
|
}
|
||||||
|
|
||||||
|
function countSomeUsersByStatus($db, $keyword, $status) {
|
||||||
|
$q = $db->prepare("
|
||||||
|
SELECT
|
||||||
|
COUNT(*)
|
||||||
|
FROM
|
||||||
|
`user`
|
||||||
|
WHERE
|
||||||
|
`username` LIKE :keyword AND
|
||||||
|
FIND_IN_SET (`role`, :statuses)
|
||||||
|
ORDER BY
|
||||||
|
`role`,
|
||||||
|
`username`
|
||||||
|
");
|
||||||
|
|
||||||
|
$keyword = "%$keyword%";
|
||||||
|
$q->bindParam(':keyword', $keyword);
|
||||||
|
$statuses = implode(',', $status);
|
||||||
|
$q->bindParam(':statuses', $statuses);
|
||||||
|
$q->execute();
|
||||||
|
return $q;
|
||||||
|
}
|
||||||
|
|
||||||
function changeUserStatusByID($db, $id, $status) {
|
function changeUserStatusByID($db, $id, $status) {
|
||||||
$q = $db->query("
|
$q = $db->query("
|
||||||
UPDATE
|
UPDATE
|
||||||
|
|||||||
@@ -18,6 +18,23 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function checkCheckAll(allbox) {
|
||||||
|
var checkboxes = document.getElementsByClassName('checkbox-list');
|
||||||
|
var checked = true;
|
||||||
|
|
||||||
|
for (var i = 0; i < checkboxes.length; i++) {
|
||||||
|
if (checkboxes[i].type == 'checkbox') {
|
||||||
|
if (checkboxes[i].checked == false) {
|
||||||
|
checked = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
document.write(checked);
|
||||||
|
allbox.checked = checked;
|
||||||
|
}
|
||||||
|
|
||||||
function changeFilter() {
|
function changeFilter() {
|
||||||
if (document.getElementById('group').checked) {
|
if (document.getElementById('group').checked) {
|
||||||
document.getElementById('admin-filter').style.display = 'none';
|
document.getElementById('admin-filter').style.display = 'none';
|
||||||
@@ -45,7 +62,10 @@
|
|||||||
<!-- function test_input taken from http://www.w3schools.com/php/php_form_validation.asp -->
|
<!-- function test_input taken from http://www.w3schools.com/php/php_form_validation.asp -->
|
||||||
<?php
|
<?php
|
||||||
$search = "";
|
$search = "";
|
||||||
$listnr = 0; // TODO: add page functionality
|
$listn = 0; // TODO: add page functionality
|
||||||
|
$listm = 20;
|
||||||
|
$currentpage = 1;
|
||||||
|
$perpage = 20;
|
||||||
$status = $groupstatus = array();
|
$status = $groupstatus = array();
|
||||||
$pagetype = "user";
|
$pagetype = "user";
|
||||||
|
|
||||||
@@ -83,6 +103,10 @@ if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
|||||||
changeMultipleGroupStatusByID($db, $_POST["checkbox-group"], $_POST["groupbatchactions"]);
|
changeMultipleGroupStatusByID($db, $_POST["checkbox-group"], $_POST["groupbatchactions"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isset($_POST["pageselect"])) {
|
||||||
|
$currentpage = $_POST["pageselect"];
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function test_input($data) {
|
function test_input($data) {
|
||||||
@@ -199,15 +223,37 @@ function test_input($data) {
|
|||||||
<h2 class="usertitle">Users:</h2>
|
<h2 class="usertitle">Users:</h2>
|
||||||
|
|
||||||
<div class="admin-userpage">
|
<div class="admin-userpage">
|
||||||
|
<p class="pagenumber">Showing results
|
||||||
|
<?php $pages = countSomeUsersByStatus($db, $search, $status);
|
||||||
|
$countresults = $pages->fetchColumn();
|
||||||
|
$mincount = min($listm, $countresults);
|
||||||
|
echo "$listn to $mincount out of $countresults"; ?></p><br>
|
||||||
<input type="submit" name="prev" value="prev">
|
<input type="submit" name="prev" value="prev">
|
||||||
1 / 1
|
<form class="admin-pageselector"
|
||||||
|
action="<?php htmlspecialchars(basename($_SERVER['REQUEST_URI'])) ?>"
|
||||||
|
method="post">
|
||||||
|
<select class="admin-pageselect"
|
||||||
|
name="pageselect"
|
||||||
|
onchange="this.form.submit()"
|
||||||
|
value="">
|
||||||
|
<?php
|
||||||
|
for ($i=1; $i <= $countresults / $perpage + 1; $i++) {
|
||||||
|
if ($currentpage == $i) {
|
||||||
|
echo "<option value='$i' selected>$i</option>";
|
||||||
|
} else {
|
||||||
|
echo "<option value='$i'>$i</option>";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
</select>
|
||||||
|
</form>
|
||||||
<input type="submit" name="next" value="next">
|
<input type="submit" name="next" value="next">
|
||||||
</div> <br>
|
</div> <br>
|
||||||
|
|
||||||
<table class="usertable">
|
<table class="usertable">
|
||||||
<tr>
|
<tr>
|
||||||
<th class="table-checkbox">
|
<th class="table-checkbox">
|
||||||
<input type="checkbox" name="checkall" onchange="checkAll(this)">
|
<input type="checkbox" id="checkall" name="checkall" onchange="checkAll(this)">
|
||||||
</th>
|
</th>
|
||||||
<th class="table-username">User</th>
|
<th class="table-username">User</th>
|
||||||
<th class="table-status">Status</th>
|
<th class="table-status">Status</th>
|
||||||
@@ -217,8 +263,11 @@ function test_input($data) {
|
|||||||
|
|
||||||
<!-- Table construction via php PDO. -->
|
<!-- Table construction via php PDO. -->
|
||||||
<?php
|
<?php
|
||||||
|
$listn = ($currentpage-1) * 20;
|
||||||
|
$listm = $currentpage * 20;
|
||||||
|
|
||||||
if ($pagetype == 'user') {
|
if ($pagetype == 'user') {
|
||||||
$q = search20UsersFromNByStatus($db, $listnr, $search, $status);
|
$q = searchSomeUsersByStatus($db, $listn, $listm, $search, $status);
|
||||||
|
|
||||||
while($user = $q->fetch(PDO::FETCH_ASSOC)) {
|
while($user = $q->fetch(PDO::FETCH_ASSOC)) {
|
||||||
$userID = $user['userID'];
|
$userID = $user['userID'];
|
||||||
@@ -233,7 +282,8 @@ function test_input($data) {
|
|||||||
name='checkbox-user[]'
|
name='checkbox-user[]'
|
||||||
class='checkbox-list'
|
class='checkbox-list'
|
||||||
value='$userID'
|
value='$userID'
|
||||||
form='admin-batchform'>
|
form='admin-batchform'
|
||||||
|
onchange='checkCheckAll(document.getElementById('checkall'))'>
|
||||||
</td>
|
</td>
|
||||||
<td>$username</td>
|
<td>$username</td>
|
||||||
<td>$role</td>
|
<td>$role</td>
|
||||||
@@ -255,7 +305,7 @@ function test_input($data) {
|
|||||||
");
|
");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$q = search20GroupsFromNByStatus($db, $listnr, $search, $groupstatus);
|
$q = search20GroupsFromNByStatus($db, $listn, $search, $groupstatus);
|
||||||
|
|
||||||
while ($group = $q->fetch(PDO::FETCH_ASSOC)) {
|
while ($group = $q->fetch(PDO::FETCH_ASSOC)) {
|
||||||
$groupID = $group['groupID'];
|
$groupID = $group['groupID'];
|
||||||
@@ -295,9 +345,6 @@ function test_input($data) {
|
|||||||
?>
|
?>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
<pre>
|
|
||||||
<?php print_r($_POST); ?>
|
|
||||||
</pre>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
Reference in New Issue
Block a user