<?php
|
include_once "/Common/Logging.php";
|
include_once "/Account/User.php";
|
include_once "/language/lang.php";
|
|
\Logging\CreateLogging("online.php");
|
$Permission = \User\Permission::P_Online;
|
|
$alertMsg = "";
|
$channel = $_SESSION['spid'];
|
$UserAccount = $_SESSION['UserAccount'];
|
$user = new \User\User($UserAccount);
|
if (!$user->HavePermission($Permission)) {
|
exit;
|
}
|
|
$serversArray = $user->GetServers();
|
|
// 默认当天
|
$startDate = array_key_exists("startDate", $_POST) ? $_POST["startDate"] : date("Y-m-d");
|
$endDate = array_key_exists("endDate", $_POST) ? $_POST["endDate"] : date("Y-m-d");
|
$onlyServerIDHis = $_POST["onlyServerIDHis"];
|
$OnlyServerID = null;
|
if ($onlyServerIDHis == "on") {
|
$OnlyServerID = 1; // 默认只查指定服
|
}
|
|
// 设置默认数据,开界面默认查选中服
|
$_POST["startDate"] = $startDate;
|
$_POST["endDate"] = $endDate;
|
$_POST["eventType"] = "OnlinePlayer";
|
$_POST["queryAllData"] = "on"; // 设置可查询备份数据
|
// echo "_POST:", print_r($_POST, true), "<br/>";
|
\CommFunc\QueryEventData($user, $retInfo);
|
|
$showTime = \CommFunc\StrDateTimeToTime(date("Y-m-d"));
|
$endTime = strtotime("+1 days", $showTime);
|
$labels = array(); // x轴为一天的时间
|
$doCount = 0;
|
while ($showTime < $endTime && $doCount < 1440) {
|
$doCount += 1;
|
$label = date("Y-m-d H:i:s", $showTime);
|
array_push($labels, substr($label, 11, 5));
|
$showTime = strtotime("+5 minutes", $showTime); // 时间间隔5分钟
|
}
|
|
?>
|
|
<!DOCTYPE html>
|
<html>
|
|
<head>
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
<title><?php echo \Lang\gettext("在线人数"); ?></title>
|
<link rel="gettext" type="application/x-po" href="../language/<?php echo \Lang\getLang(); ?>/LC_MESSAGES/<?php echo \Lang\getjspodomain(); ?>.po" />
|
</head>
|
|
<body>
|
<center>
|
<p><b><?php echo \Lang\gettext("在线人数"); ?></b></P>
|
</center>
|
<form id="online" action="online.php" method="post">
|
<?php echo \Lang\gettext("查询时间"); ?>:
|
<input type="text" name="startDate" id="startDate" onclick="new Calendar().show(this);" readonly value="<?php echo $startDate; ?>" size="8" />
|
~
|
<input type="text" name="endDate" id="endDate" onclick="new Calendar().show(this);" readonly value="<?php echo $endDate; ?>" size="8" />
|
<input type="submit" value="<?php echo \Lang\gettext("查询本服"); ?>" onclick="onCurSubmit()" />
|
<?php
|
echo " ";
|
echo '<input type="checkbox" name="onlyServerIDHis" id="onlyServerIDHis" ' . ($onlyServerIDHis == "on" ? "checked" : "") . ' onchange="onOnlyServerIDHisChange()" />' . \Lang\gettext("查询单服历史");
|
?>
|
<div id="OnlinePlayerInfo"></div>
|
<hr />
|
<?php
|
include_once "/Common/SelectServer.php";
|
?>
|
<input type="submit" name="submit" id="submit" value="<?php echo \Lang\gettext("查询多服"); ?>" onclick="return checkMultiSubmit()" />
|
<br />
|
<br />
|
</form>
|
</body>
|
<script type='text/javascript' src='/language/gettext.js'></script>
|
<script type='text/javascript' src="/js/calendar.js"></script>
|
<script type='text/javascript' src="/js/common.js"></script>
|
<script type='text/javascript' src="/Common/selectserver.js"></script>
|
<script type='text/javascript' src="/js/chart.min.js"></script>
|
<script type="text/javascript">
|
window.onload = function() {
|
var retInfo = '<?php echo json_encode($retInfo); ?>';
|
if (retInfo == 'null') {
|
return;
|
}
|
retInfo = JSON.parse(retInfo);
|
|
let chartNum = 0;
|
let insHtml, info;
|
for (const serverName in retInfo) {
|
let chartID;
|
insHtml = "";
|
insHtml += "<hr />";
|
info = retInfo[serverName];
|
console.log(serverName, info);
|
if (info && info["OK"]) {
|
chartID = "myChart" + chartNum;
|
chartNum += 1;
|
// insHtml += "<center>" + serverName + "</center>" + "<br/>";
|
insHtml += "<canvas id=\"" + chartID + "\" ></canvas>"; // 插入画布
|
} else {
|
insHtml += serverName + " : " + info + "<br/>";
|
}
|
document.getElementById("OnlinePlayerInfo").insertAdjacentHTML("beforeEnd", insHtml);
|
if (chartID) {
|
drawChartLine(chartID, serverName, info["DRData"]);
|
}
|
}
|
}
|
|
function onOnlyServerIDHisChange() {
|
if (document.getElementById("onlyServerIDHis").checked) {
|
document.getElementById("OnlyServerID").selectedIndex = 1;
|
} else {
|
document.getElementById("OnlyServerID").selectedIndex = 0;
|
}
|
}
|
|
function drawChartLine(chartID, serverName, drData) {
|
|
var backgroundColors = [
|
'rgba(79, 66, 255, 0.2)',
|
'rgba(255, 99, 132, 0.2)',
|
'rgba(255, 206, 86, 0.2)',
|
'rgba(54, 162, 235, 0.2)',
|
'rgba(75, 192, 192, 0.2)',
|
'rgba(153, 102, 255, 0.2)',
|
'rgba(255, 159, 64, 0.2)'
|
];
|
|
var borderColors = [
|
'rgba(79, 66, 255, 1)',
|
'rgba(255, 99, 132, 1)',
|
'rgba(255, 206, 86, 1)',
|
'rgba(54, 162, 235, 1)',
|
'rgba(75, 192, 192, 1)',
|
'rgba(153, 102, 255, 1)',
|
'rgba(255, 159, 64, 1)'
|
];
|
|
var colorIndex = 0;
|
var labels = JSON.parse('<?php echo json_encode($labels); ?>');
|
// console.log("labels", labels);
|
var datasets = [];
|
var dateStrList = Object.keys(drData);
|
dateStrList.sort();
|
// console.log("dateStrList", dateStrList);
|
for (let i = 0; i < dateStrList.length; i++) {
|
let dateStr = dateStrList[i];
|
const hmInfo = drData[dateStr];
|
// console.log(dateStr, "hmInfo", hmInfo);
|
|
let hmCount = 0;
|
let playerCountList = []
|
for (let j = 0; j < labels.length; j++) {
|
const hm = labels[j];
|
if (hmInfo[hm] >= 0) {
|
playerCountList.push(hmInfo[hm]);
|
// playerCountList.push(random(100, 200));
|
hmCount += 1;
|
if (hmCount >= Object.keys(hmInfo).length) {
|
// 已达到记录
|
break;
|
}
|
} else {
|
playerCountList.push(0);
|
}
|
}
|
|
// console.log(dateStr, "playerCountList", playerCountList.length, playerCountList);
|
datasets.push({
|
label: dateStr,
|
data: playerCountList,
|
backgroundColor: backgroundColors[colorIndex % backgroundColors.length],
|
borderColor: borderColors[colorIndex % borderColors.length],
|
borderWidth: 1,
|
lineTension: 0.5,
|
pointRadius: 1
|
});
|
colorIndex += 1;
|
}
|
|
var ctx = document.getElementById(chartID);
|
ctx.width = 400;
|
ctx.height = 100;
|
var myLineChart = new Chart(ctx, {
|
type: "line",
|
data: {
|
labels: labels,
|
datasets: datasets
|
},
|
options: {
|
plugins: {
|
title: {
|
display: true,
|
text: serverName
|
}
|
},
|
scales: {
|
x: {
|
title: {
|
display: true,
|
text: "时间"
|
}
|
},
|
y: {
|
title: {
|
display: true,
|
text: "人数"
|
},
|
beginAtZero: true,
|
ticks: {
|
stepSize: 1, // 刻度间隔1
|
}
|
}
|
}
|
}
|
});
|
}
|
|
function onCurSubmit() {
|
document.getElementById("MultiServer").value = 0;
|
return true;
|
}
|
|
function checkMultiSubmit() {
|
|
if (!checkHaveServerSelected()) {
|
return false;
|
}
|
|
if (!setSubmitQuerying("submit")) {
|
return false;
|
}
|
|
return true;
|
}
|
</script>
|
|
</html>
|