Add ban check form.

This commit is contained in:
Ruan 2015-06-06 10:27:57 +02:00
parent ec16759705
commit 88fba6ed62
5 changed files with 76 additions and 8 deletions

View File

@ -10,6 +10,40 @@
</ol>
</div>
</div>
<br/>
<!-- Ban check form -->
<form id="form" class="form-inline">
<div class="form-group">
<input type="text" class="form-control" id="user" placeholder="Player">
</div>
<button type="submit" class="btn btn-default">Check</button>
</form>
<script type="text/javascript">
function runCheck() {
$.ajax({
type: 'POST',
url: 'check.php',
data: {name: document.getElementById('user').value, table: 'bans'}
}).done(function (msg) {
document.getElementById('output').innerHTML = msg;
});
}
// prevent page from being reloaded on submit
// https://stackoverflow.com/questions/5384712/capture-a-form-submit-in-javascript
function processForm(e) {
if (e.preventDefault) e.preventDefault();
runCheck();
return false;
}
var form = document.getElementById('form');
if (form.attachEvent) {
form.attachEvent("submit", processForm);
} else {
form.addEventListener("submit", processForm);
}
</script>
<div id="output"></div>
<!-- End ban check form -->
<div class="row" style="margin-bottom:60px;">
<div class="col-lg-12">
<table class="table table-hover table-bordered table-condensed">
@ -37,9 +71,8 @@
global $table_bans, $conn;
$result = run_query($table_bans);
while ($row = $result->fetch(PDO::FETCH_ASSOC)) {
date_default_timezone_set("UTC");
$timeResult = date('F j, Y, g:i a', $row['time'] / 1000);
$expiresResult = date('F j, Y, g:i a', $row['until'] / 1000);
$timeResult = millis_to_date($row['time']);
$expiresResult = millis_to_date($row['until']);
?>
<tr>
<td><?php echo get_avatar($row['name']); ?></td>

33
check.php Normal file
View File

@ -0,0 +1,33 @@
<?php
if (isset($_POST['name'], $_POST['table'])) {
require 'includes/page.php';
$name = $_POST['name']; // user input
global $table_bans, $table_history, $conn;
$stmt = $conn->prepare("SELECT uuid FROM " . $table_history . " WHERE name=? ORDER BY date LIMIT 1");
if ($stmt->execute(array($name))) {
if ($row = $stmt->fetch()) {
$uuid = $row['uuid'];
}
}
if (isset($uuid)) {
$stmt = $conn->prepare("SELECT * FROM " . $table_bans . " WHERE (uuid=? AND active=1) LIMIT 1");
if ($stmt->execute(array($uuid))) {
if ($row = $stmt->fetch()) {
$banner = get_banner_name($row['banned_by_name']);
$reason = $row['reason'];
$time = millis_to_date($row['time']);
$until = millis_to_date($row['until']);
echo($name . ' is banned! <br>');
echo('Banned by ' . $banner . '<br>');
echo('Reason: ' . $reason . '<br>');
echo('Banned on: ' . $time . '<br>');
echo('Banned until: ' . $until . '<br>');
} else {
echo($name . ' is not banned.');
}
}
} else {
echo($name . ' has not joined before.');
}
}
?>

View File

@ -32,4 +32,8 @@ function get_banner_name($banner) {
return $banner;
}
function millis_to_date($millis) {
date_default_timezone_set("UTC");
return date('F j, Y, g:i a', $millis / 1000);
}
?>

View File

@ -27,9 +27,8 @@
global $table_mutes, $conn;
$result = run_query($table_mutes);
while ($row = $result->fetch(PDO::FETCH_ASSOC)) {
date_default_timezone_set("UTC");
$timeResult = date('F j, Y, g:i a', $row['time'] / 1000);
$expiresResult = date('F j, Y, g:i a', $row['until'] / 1000);
$timeResult = millis_to_date($row['time']);
$expiresResult = millis_to_date($row['until']);
?>
<tr>
<td><?php echo get_avatar($row['name']); ?></td>

View File

@ -34,8 +34,7 @@
global $table_warnings, $conn;
$result = run_query($table_warnings);
while ($row = $result->fetch(PDO::FETCH_ASSOC)) {
date_default_timezone_set("UTC");
$expiresResult = date('F j, Y, g:i a', $row['until'] / 1000);
$expiresResult = millis_to_date($row['until']);
?>
<tr>
<td><?php echo get_avatar($row['name']); ?></td>