add pagetype selector, add search filter

This commit is contained in:
Hendrik
2017-01-18 14:20:32 +01:00
parent 8ce6cd1aa2
commit b5ceb1b5e0
3 changed files with 104 additions and 22 deletions

View File

@@ -32,7 +32,7 @@
margin-bottom: 10px; margin-bottom: 10px;
} }
.admin-filter, .admin-filtertype { .admin-filter, .admin-filtertype, .admin-groupfilter {
display: inline-block; display: inline-block;
margin: 10px; margin: 10px;
vertical-align: top; vertical-align: top;
@@ -40,6 +40,14 @@
margin-left: 50px; margin-left: 50px;
} }
.admin-filter, .admin-groupfilter {
width: 120px;
}
.admin-groupfilter {
display: none;
}
.admin-users { .admin-users {
margin: 10px; margin: 10px;
} }

View File

@@ -41,4 +41,32 @@ function search20UsersFromN($db, $n, $keyword) {
return $q; return $q;
} }
function search20UsersFromNByStatus($db, $n, $keyword, $status) {
$q = $db->prepare("
SELECT
`userID`,
`username`,
`role`,
`bancomment`
FROM
`user`
WHERE
`username` LIKE :keyword AND
FIND_IN_SET (`role`, :statuses)
ORDER BY
`username`
LIMIT
:n, 20
");
$keyword = "%$keyword%";
$q->bindParam(':keyword', $keyword);
$q->bindParam(':n', $n, PDO::PARAM_INT);
$statuses = implode(',', $status);
$q->bindParam(':statuses', $statuses);
$q->execute();
return $q;
}
?> ?>

View File

@@ -4,6 +4,10 @@
<meta charset="utf-8"> <meta charset="utf-8">
<title>Admin Panel</title> <title>Admin Panel</title>
<script type="text/javascript"> <script type="text/javascript">
window.onload = function() {
changeFilter();
};
function checkAll(allbox) { function checkAll(allbox) {
var checkboxes = document.getElementsByName('checkbox-user[]'); var checkboxes = document.getElementsByName('checkbox-user[]');
@@ -13,6 +17,17 @@
} }
} }
} }
function changeFilter() {
if (document.getElementById('group').checked) {
document.getElementById('admin-filter').style.display = 'none';
document.getElementById('admin-groupfilter').style.display = 'inline-block';
} else {
document.getElementById('admin-filter').style.display = 'inline-block';
document.getElementById('admin-groupfilter').style.display = 'none';
}
}
</script> </script>
<?php include_once("../queries/user.php"); ?> <?php include_once("../queries/user.php"); ?>
</head> </head>
@@ -20,13 +35,14 @@
<!-- 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 = $pagetype = $searchvalue = ""; $search = "";
$listnr = 0; $listnr = 0; // TODO: add page functionality
$status = array(); $status = $groupstatus = array();
$pagetype = "user";
if ($_SERVER["REQUEST_METHOD"] == "POST") { if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (!empty($_POST["search"])) { if (!empty($_POST["search"])) {
$search = $searchvalue = test_input($_POST["search"]); $search = test_input($_POST["search"]);
} }
if (!empty($_POST["pagetype"])) { if (!empty($_POST["pagetype"])) {
@@ -37,6 +53,11 @@ if ($_SERVER["REQUEST_METHOD"] == "POST") {
$status = $_POST["status"]; $status = $_POST["status"];
} }
if (!empty($_POST["groupstatus"])) {
$groupstatus = $_POST["groupstatus"];
}
} }
function test_input($data) { function test_input($data) {
@@ -67,34 +88,57 @@ function test_input($data) {
value="<?php echo $search;?>"> <br> value="<?php echo $search;?>"> <br>
<input type="submit" value="Search"> <input type="submit" value="Search">
</div> </div>
<div class="admin-filter">
<div class="admin-filter" id="admin-filter">
<h2>Show:</h2> <h2>Show:</h2>
<input type="checkbox" name="status[]" id="normal" value="normal"
<?php if (in_array("normal", $status)) echo "checked";?>> <input type="checkbox" name="status[]" id="normal" value="1"
<?php if (in_array("1", $status)) echo "checked";?>>
<label for="normal">Normal</label><br> <label for="normal">Normal</label><br>
<input type="checkbox" name="status[]" id="frozen" value="frozen" <input type="checkbox" name="status[]" id="frozen" value="2"
<?php if (in_array("frozen", $status)) echo "checked";?>> <?php if (in_array("2", $status)) echo "checked";?>>
<label for="frozen">Frozen</label><br> <label for="frozen">Frozen</label><br>
<input type="checkbox" name="status[]" id="banned" value="banned" <input type="checkbox" name="status[]" id="banned" value="3"
<?php if (in_array("banned", $status)) echo "checked";?>> <?php if (in_array("3", $status)) echo "checked";?>>
<label for="banned">Banned</label><br> <label for="banned">Banned</label><br>
<input type="checkbox" name="status[]" id="admin" value="admin" <input type="checkbox" name="status[]" id="admin" value="5"
<?php if (in_array("admin", $status)) echo "checked";?>> <?php if (in_array("5", $status)) echo "checked";?>>
<label for="admin">Admin</label><br> <label for="admin">Admin</label><br>
<input type="checkbox" name="status[]" id="unvalidated" value="unvalidated" <input type="checkbox" name="status[]" id="unvalidated" value="0"
<?php if (in_array("unvalidated", $status)) echo "checked";?>> <?php if (in_array("0", $status)) echo "checked";?>>
<label for="unvalidated">Unvalidated</label> <label for="unvalidated">Unvalidated</label><br>
<input type="checkbox" name="status[]" id="owner" value="42"
<?php if (in_array("42", $status)) echo "checked";?>>
<label for="owner">Owner</label>
</div> </div>
<div class="admin-groupfilter" id="admin-groupfilter">
<h2>Show:</h2>
<input type="checkbox" name="groupstatus[]" id="hidden" value="0"
<?php if (in_array("0", $groupstatus)) echo "checked";?>>
<label for="hidden">Hidden</label><br>
<input type="checkbox" name="groupstatus[]" id="public" value="1"
<?php if (in_array("1", $groupstatus)) echo "checked";?>>
<label for="public">Public</label><br>
<input type="checkbox" name="groupstatus[]" id="membersonly" value="2"
<?php if (in_array("2", $groupstatus)) echo "checked";?>>
<label for="membersonly">Members-only</label><br>
</div>
<div class="admin-filtertype"> <div class="admin-filtertype">
<h2>Page Type:</h2> <h2>Page Type:</h2>
<input type="radio" name="pagetype" id="user" value="user" <input type="radio" name="pagetype" id="user" value="user"
<?php if (isset($pagetype) && $pagetype=="user") echo "checked";?>> <?php if (isset($pagetype) && $pagetype=="user") echo "checked";?>
onchange="changeFilter()">
<label for="user">Users</label><br> <label for="user">Users</label><br>
<input type="radio" name="pagetype" id="group" value="group" <input type="radio" name="pagetype" id="group" value="group"
<?php if (isset($pagetype) && $pagetype=="group") echo "checked";?>> <?php if (isset($pagetype) && $pagetype=="group") echo "checked";?>
onchange="changeFilter()">
<label for="group">Groups</label> <label for="group">Groups</label>
</div> </div>
</form> </form>
<div class="admin-actions"> <div class="admin-actions">
<h2>Batch Actions: </h2> <h2>Batch Actions: </h2>
<input type="radio" name="actions" id="freeze" value="freeze"> <input type="radio" name="actions" id="freeze" value="freeze">
@@ -107,8 +151,10 @@ function test_input($data) {
</div> </div>
</div> </div>
<br> <br>
<div class="admin-users"> <div class="admin-users">
<h2>Users:</h2> <h2>Users:</h2>
<div class="admin-userpage"> <div class="admin-userpage">
<input type="submit" name="prev" value="prev"> <input type="submit" name="prev" value="prev">
1 / 1 1 / 1
@@ -126,8 +172,9 @@ function test_input($data) {
<th class="table-action">Action</th> <th class="table-action">Action</th>
</tr> </tr>
<!-- Table construction via php PDO. -->
<?php <?php
$q = search20UsersFromN($db, $listnr, $searchvalue); $q = search20UsersFromNByStatus($db, $listnr, $search, $status);
while($user = $q->fetch(PDO::FETCH_ASSOC)) { while($user = $q->fetch(PDO::FETCH_ASSOC)) {
$userID = $user['userID']; $userID = $user['userID'];
@@ -135,6 +182,7 @@ function test_input($data) {
$role = $user['role']; $role = $user['role'];
$bancomment = $user['bancomment']; $bancomment = $user['bancomment'];
$thispage = htmlspecialchars($_SERVER['PHP_SELF']); $thispage = htmlspecialchars($_SERVER['PHP_SELF']);
echo(" echo("
<tr> <tr>
<td><input type='checkbox' <td><input type='checkbox'
@@ -164,8 +212,6 @@ function test_input($data) {
</table> </table>
</div> </div>
</form> </form>
<pre><?php print_r($_POST); ?></pre>
</div> </div>
</div> </div>
</body> </body>