<?php
|
include_once "/Account/User.php";
|
include_once "/db/DBOper.php";
|
include_once "/Common/Logging.php";
|
include_once "/Common/ServerOPS.php";
|
include_once "/Common/CommFunc.php";
|
include_once "/language/lang.php";
|
|
\Logging\CreateLogging("serverops.serverGroup.php");
|
|
$Permission = \User\Permission::P_OPSServerList;
|
$channel = $_SESSION['spid'];
|
$user = new \User\User($_SESSION['UserAccount']);
|
if (!$user->HavePermission($Permission)) {
|
exit;
|
}
|
|
// echo "_POST:" . print_r($_POST, true), "<br/>";
|
\Logging\LogInfo(" _POST:" . print_r($_POST, true));
|
|
$alertMsg = "";
|
$groupJsonFile = \ServerOPS\GetServerGroup($channel);
|
|
$opType = $_POST["opType"];
|
|
if ($opType == "del") {
|
$SortNum = intval($_POST["SortNum"]);
|
$groupArray = json_decode(\CommFunc\GetFileContents($groupJsonFile, "[]"), true);
|
\Logging\LogInfo("start to del servergroup channel:" . $channel . " SortNum:" . $SortNum . " groupInfo:" . \CommFunc\MyJson_encode($groupArray));
|
foreach ($groupArray as $key => $value) {
|
if ($SortNum == $value["SortNum"]) {
|
unset($groupArray[$key]);
|
|
$updateGroupArray = array();
|
foreach ($groupArray as $value) {
|
array_push($updateGroupArray, $value);
|
}
|
$updateGroupInfo = \CommFunc\MyJson_encode($updateGroupArray);
|
\Logging\LogInfo("update servergroup channel:" . $channel . " updateGroupInfo:" . $updateGroupInfo);
|
file_put_contents($groupJsonFile, $updateGroupInfo);
|
$alertMsg = "删除成功!";
|
break;
|
}
|
}
|
} elseif ($opType == "save") {
|
\Logging\LogInfo("start to save servergroup channel:" . $channel);
|
$i = 0;
|
$saveGroupArray = array();
|
while (true) {
|
if (!array_key_exists("SortNum" . $i, $_POST)) {
|
\Logging\LogInfo("post SortNum not exists:" . "SortNum" . $i);
|
break;
|
}
|
$SortNum = intval($_POST["SortNum" . $i]);
|
if ($SortNum <= 0) {
|
\Logging\LogInfo("post SortNum <=0 :" . "SortNum" . $i);
|
break;
|
}
|
$GroupTitle = $_POST["GroupTitle" . $i];
|
$ServerIDList = json_decode($_POST["ServerIDList" . $i], true);
|
array_push($saveGroupArray, array("SortNum" => $SortNum, "GroupTitle" => $GroupTitle, "ServerIDList" => $ServerIDList));
|
$i += 1;
|
}
|
//排序 根据 SortNum 倒序排序 SORT_ASC 和 SORT_DESC
|
array_multisort(array_column($saveGroupArray, 'SortNum'), SORT_DESC, $saveGroupArray);
|
$saveGroupInfo = \CommFunc\MyJson_encode($saveGroupArray);
|
\Logging\LogInfo("save servergroup channel:" . $channel . " saveGroupInfo:" . $saveGroupInfo);
|
file_put_contents($groupJsonFile, $saveGroupInfo);
|
$alertMsg = "保存成功!";
|
}
|
|
if ($alertMsg) {
|
echo "<script>alert('" . $alertMsg . "')</script>";
|
}
|
|
$pageTitle = "区服分组";
|
|
$groupArray = json_decode(\CommFunc\GetFileContents($groupJsonFile, "[]"), true);
|
|
// echo "groupArray:" . print_r($groupArray, true);
|
|
//插入3个空分组待添加
|
for ($i = 0; $i < 3; $i++) {
|
array_push($groupArray, array());
|
}
|
|
//显示表格字段配置 key-参数名,value-说明
|
$tableArray = array(
|
"SortNum" => array("排序序号", "10%", "center", 5),
|
"GroupTitle" => array("分组标题", "15%", "center", 10),
|
"ServerIDList" => array("区服列表", "50%", "center", 50),
|
"" => array("操作", "", "center", 0),
|
);
|
|
?>
|
|
<html>
|
|
<head>
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
<title><?php echo $pageTitle; ?></title>
|
<link rel="stylesheet" type="text/css" href="/css/table.css">
|
</head>
|
|
<body>
|
<center>
|
<p><b><?php echo $pageTitle; ?></b></P>
|
</center>
|
<hr />
|
<form action="serverGroup.php" method="post">
|
<table width="50%">
|
<caption>
|
<p>
|
<input type="submit" value="保存分组" onclick="return CheckSubmit()" />
|
<input type="hidden" name="opType" id="opType" value="save" />
|
</p>
|
<p>
|
直接修改或在空分组直接输入新分组内容<br />
|
调整分组排序或区间后建议刷新选服列表<br />
|
</p>
|
</caption>
|
<?php
|
echo "<thead><tr>";
|
foreach ($tableArray as $value) {
|
echo "<th width=\"" . $value[1] . "\">" . $value[0] . "</td>";
|
}
|
echo "</tr></thead>";
|
|
foreach ($groupArray as $i => $groupInfo) {
|
echo "<tr class='trc'>";
|
$SortNum = $groupInfo["SortNum"];
|
$GroupTitle = $groupInfo["GroupTitle"];
|
foreach ($tableArray as $key => $value) {
|
if (!$key) {
|
echo "<td align='center'>";
|
if ($groupInfo) {
|
echo " <input type=\"button\" value=\"删\" onclick=\"return suredel('$channel', '$SortNum', '$GroupTitle')\"/> ";
|
}
|
echo "</td>";
|
continue;
|
}
|
|
$inputType = "text";
|
$tdContent = $groupInfo[$key];
|
if ($key == "ServerIDList" && $tdContent) {
|
$tdContent = json_encode($tdContent);
|
} else if ($key == "SortNum") {
|
// $inputType = "number";
|
}
|
$name = $key . $i;
|
echo "<td align='" . $value[2] . "'>" .
|
"<input type=\"" . $inputType . "\" name=\"" . $name . "\" id=\"" . $name . "\" value=\"" . $tdContent . "\" size=\""
|
. $value[3] . "\" style=\"text-align: center;\" placeholder=\"空分组\"/>" .
|
"</td>";
|
}
|
echo "</tr>";
|
}
|
?>
|
</table>
|
|
</form>
|
|
<script type="text/javascript">
|
function CheckSubmit() {
|
var i = 0;
|
var sortNumList = [];
|
while (document.getElementById("SortNum" + i)) {
|
if (!document.getElementById("SortNum" + i).value) {
|
i += 1;
|
continue;
|
}
|
var SortNum = Number(document.getElementById("SortNum" + i).value);
|
if (!SortNum || SortNum <= 0) {
|
alert("排序序号需要大于0的值!");
|
document.getElementById("SortNum" + i).focus();
|
return false;
|
}
|
if (sortNumList.indexOf(SortNum) != -1) {
|
alert("排序序号不能重复!");
|
document.getElementById("SortNum" + i).focus();
|
return false;
|
}
|
sortNumList.push(SortNum);
|
|
// alert(i + "=" + SortNum);
|
if (!document.getElementById("GroupTitle" + i).value) {
|
alert("区服标题不能为空!");
|
document.getElementById("GroupTitle" + i).focus();
|
return false;
|
}
|
|
if (!document.getElementById("ServerIDList" + i).value) {
|
alert("区服列表不能为空!");
|
document.getElementById("ServerIDList" + i).focus();
|
return false;
|
}
|
|
try {
|
JSON.parse(document.getElementById("ServerIDList" + i).value)
|
} catch (error) {
|
alert("区服列表格式错误!");
|
document.getElementById("ServerIDList" + i).focus();
|
return false;
|
}
|
i += 1;
|
}
|
return true;
|
}
|
|
function doPost(to, p) { // to:提交动作(action),p:参数
|
var myForm = document.createElement("form");
|
myForm.method = "post";
|
myForm.action = to;
|
for (var i in p) {
|
var myInput = document.createElement("input");
|
myInput.setAttribute("name", i); // 为input对象设置name
|
myInput.setAttribute("value", p[i]); // 为input对象设置value
|
myForm.appendChild(myInput);
|
}
|
document.body.appendChild(myForm);
|
myForm.submit();
|
document.body.removeChild(myForm); // 提交后移除创建的form
|
}
|
|
function suredel(Channel, SortNum, GroupTitle) {
|
if (!window.confirm("确定删除" + Channel + "服务器分组[" + GroupTitle + "]?")) {
|
return false;
|
}
|
doPost("serverGroup.php", {
|
"opType": "del",
|
"SortNum": SortNum,
|
});
|
return true;
|
}
|
</script>
|
</body>
|
|
</html>
|