Fix date/timezone bugs with the admin reports

master
Skylar Ittner 8 years ago
parent b2b2cae813
commit cc59866fcc

@ -22,7 +22,6 @@ if (!isAdmin()) {
<div class="col-xs-9 text-right">
<div class="huge">
<?php
date_default_timezone_set("UTC");
echo $database->count("players", ['lastping[>]' => date('Y-m-d H:i:s', strtotime('-1 minute'))]);
?>
</div>

@ -76,7 +76,7 @@ if (!is_empty($_GET['addr'])) {
<div class="row">
<div class="col-lg-12">
<h1 class="page-header">Locations <span class="pull-right"><small><?php echo date_tz('h:i:s a'); ?></small></span></h1>
<h1 class="page-header">Locations <span class="pull-right"><small><?php echo date('h:i:s a'); ?></small></span></h1>
</div>
</div>

@ -2,17 +2,42 @@
if (IN_ADMIN !== true) {
die("Error.");
}
$update_success = 0;
// Handle updating
if ($_SERVER['REQUEST_METHOD'] === 'POST' && !is_empty($_POST['msg']) && !is_empty($_POST['uuid'])) {
if (!$database->has("players", ['uuid' => $_POST['uuid']])) {
$update_success = -1;
} else {
$database->update("players", ["kick" => $_POST['msg']], ["uuid" => $_POST['uuid']]);
$update_success = 1;
}
}
?>
<div class="row">
<div class="col-lg-12">
<h1 class="page-header">Active Sessions <span class="pull-right"><small><?php echo date_tz('h:i:s a'); ?></small></span></h1>
<h1 class="page-header">Active Sessions <span class="pull-right"><small><?php echo date('h:i:s a'); ?></small></span></h1>
</div>
</div>
<div class="alert alert-dismissable alert-success" id="kicksuccessmsg" style="display: none;">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<i class="fa fa-check"></i> User <span id="kickusername">undefined</span> kicked from the server.
</div>
<?php
if ($update_success == -1) {
?>
<div class="alert alert-dismissable alert-danger" id="kickerrormsg">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<i class="fa fa-times"></i> The user does not exist.
</div>
<?php
} else if ($update_success == 1) {
?>
<div class="alert alert-dismissable alert-success" id="kicksuccessmsg">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<i class="fa fa-check"></i> User kicked from the server.
</div>
<?php
}
?>
<div class="row">
<table cellpadding="0" cellspacing="0" border="0" class="table table-striped table-bordered" id="player-list">
@ -27,15 +52,18 @@ if (IN_ADMIN !== true) {
</thead>
<tbody>
<?php
$players = $database->select("players", "*", ['lastping[>]' => date('Y-m-d H:i:s', strtotime('-30 seconds'))]);
$players = $database->select("players", "*", ['lastping[>]' => date('Y-m-d H:i:s', strtotime('-1 minute'))]);
foreach ($players as $player) {
$lastping = date_tz('Y-m-d h:i:s A', $player['lastping']);
$lastping = date('Y-m-d h:i:s A', strtotime($player['lastping']));
echo "\n"
. " <tr>\n"
. " <td>" . $player['nickname'] . "</td>\n"
. " <td>\n"
. " <input type='text' class='form-control' id='" . $player['uuid'] . "-kickmsg' placeholder='Enter a kick message.' value='" . $player['kick'] . "' />\n"
. " <a class='btn btn-warning' onclick=\"kickPlayer('" . $player['uuid'] . "', '" . $player['nickname'] . "');\">Kick</a>\n"
. " <form method='POST'>"
. " <input type='text' class='form-control' name='msg' placeholder='Enter a kick message.' value='" . $player['kick'] . "' />\n"
. " <input type='hidden' name='uuid' value='" . $player['uuid'] . "' />\n"
. " <input type='submit' class='btn btn-warning' value='Kick' />\n"
. " </form>\n"
. " </td>\n"
. " <td>" . $player['level'] . "</td>\n"
. " <td>" . getTeamNameFromId($player['teamid']) . "</td>\n"
@ -52,15 +80,4 @@ if (IN_ADMIN !== true) {
$(document).ready(function () {
$('#player-list').dataTable();
});
function kickPlayer(uuid, name) {
var kick_reason = $('#' + uuid + "-kickmsg").val();
$.post("kickplayer.php", {
uuid: uuid,
msg: kick_reason
}, function () {
$('#kickusername').text(name);
$('#kicksuccessmsg').css('display', 'block');
});
}
</script>

@ -35,7 +35,7 @@ if (IN_ADMIN !== true) {
<div class="row">
<div class="col-lg-12">
<h1 class="page-header">Players <span class="pull-right"><small><?php echo date_tz('h:i:s a'); ?></small></span></h1>
<h1 class="page-header">Players <span class="pull-right"><small><?php echo date('h:i:s A'); ?></small></span></h1>
</div>
</div>
@ -66,7 +66,7 @@ if ($_GET['msg'] == 'success') {
<?php
$players = $database->select("players", "*");
foreach ($players as $player) {
$lastping = date_tz('Y-m-d h:i:s A', $player['lastping']);
$lastping = date('Y-m-d h:i:s A', strtotime($player['lastping']));
echo "\n"
. " <tr>\n"
. " <td>"

@ -18,7 +18,7 @@ $out = [
];
foreach ($players as $player) {
// Format stuff
$lastping = date_tz('Y-m-d h:i:s A', $player['lastping']);
$lastping = date('Y-m-d h:i:s A', strtotime($player['lastping']));
$level = floatval($player['level']);
$energy = intval($player['energy']);

@ -21,8 +21,6 @@ try {
die("Database error.");
}
date_default_timezone_set('UTC');
/**
* Convert a UTC datetime to local time.
* @param String $format see date()
@ -30,9 +28,10 @@ date_default_timezone_set('UTC');
* @return output of date()
*/
function date_tz($format, $date = 'NOW', $intz = 'UTC', $outtz = TIMEZONE) {
$d = new DateTime($date, new DateTimeZone($intz));
$d->setTimezone(new DateTimeZone($outtz));
return $d->format($format);
return date($format, strtotime($date));
//$d = new DateTime($date, new DateTimeZone($intz));
//$d->setTimezone(new DateTimeZone($outtz));
//return $d->format($format);
}
/**