<?php
|
include_once "/Common/CommFunc.php";
|
include_once "/Common/Logging.php";
|
include_once "/Account/User.php";
|
include_once "/language/lang.php";
|
|
\Logging\CreateLogging("CompensationTempMgr.php");
|
|
$pack_type = $_POST['pack_type'];
|
$Permission = $pack_type == "GMT_AddEntireCompensation" ? \User\Permission::P_ServerMailTempMgr : \User\Permission::P_PersonalMailTempMgr;
|
|
$user = new \User\User($_SESSION['UserAccount']);
|
if (!$user->HavePermission($Permission)) {
|
exit;
|
}
|
|
\Logging\LogInfo("Post数据" . print_r($_POST, true));
|
|
$tempData = array(); // 模板数据
|
|
// 公共数据
|
$tempData["Name"] = $_POST["MailTempName"];
|
|
if ($_POST["LimitDays"] != "") {
|
$tempData["LimitDays"] = intval($_POST["LimitDays"]);
|
} else {
|
$tempData["LimitDays"] = 7; // 默认7天有效期
|
}
|
|
$tempData["Title"] = $_POST["Title"];
|
$tempData["Text"] = $_POST["Text"];
|
|
$items = array(); // 物品数据
|
$itemNums = explode(",", $_POST["itemNums"]);
|
for ($i = 0; $i < count($itemNums); $i++) {
|
$num = $itemNums[$i];
|
$itemID = intval($_POST["ItemID" . $num]);
|
$ItemCnt = intval($_POST["ItemCnt" . $num]);
|
$IsBind = intval($_POST["IsBind" . $num]);
|
if ($itemID <= 0 || $ItemCnt <= 0) {
|
continue;
|
}
|
array_push($items, array($itemID, $ItemCnt, $IsBind));
|
}
|
$tempData["Items"] = $items;
|
|
$spID = $user->GetSPID();
|
$backUrl = "AddPersonalCompensation.php";
|
$tempJsonFile = "MailTemp/" . $spID . "_Person.json";
|
// 全服邮件独有数据
|
if ($pack_type == "GMT_AddEntireCompensation") {
|
$backUrl = "AddEntireCompensation.php";
|
$tempJsonFile = "MailTemp/" . $spID . "_Entire.json";
|
$tempData["PlayerLV"] = intval($_POST["PlayerLV"]);
|
$tempData["LimitLVType"] = intval($_POST["LimitLVType"]);
|
$tempData["CheckState"] = intval($_POST["CheckState"]);
|
}
|
|
$readTempContent = \CommFunc\GetFileContents($tempJsonFile, "[]");
|
// echo "<br/>readTempContent:" . $readTempContent . "<br/>";
|
\Logging\LogInfo("readTempContent: " . $readTempContent);
|
$mailTempArray = json_decode($readTempContent, true);
|
if (!$mailTempArray) {
|
$mailTempArray = array();
|
}
|
|
$backIndex = -1;
|
$MailTempIndex = intval($_POST["MailTemp"]); // 模板索引
|
$opStr = "";
|
if ($_POST["saveTemp"] != "") {
|
$opStr = \Lang\gettext("修改");
|
$mailTempArray[$MailTempIndex] = $tempData;
|
$backIndex = $MailTempIndex;
|
} elseif ($_POST["delTemp"] != "") {
|
$opStr = \Lang\gettext("删除");
|
array_splice($mailTempArray, $MailTempIndex, 1);
|
} elseif ($_POST["saveNewTemp"] != "") {
|
$opStr = \Lang\gettext("新增");
|
array_push($mailTempArray, $tempData);
|
$backIndex = count($mailTempArray) - 1;
|
}
|
|
$saveTempContent = \CommFunc\MyJson_encode($mailTempArray);
|
// echo "<br/>saveTempContent:" . $saveTempContent . "<br/>";
|
\Logging\LogInfo("saveTempContent: " . $saveTempContent);
|
|
$opStr = "[" . $opStr . "] ";
|
if (!$saveTempContent) {
|
echo $opStr . \Lang\gettext("数据异常");
|
return;
|
}
|
|
// 使用 JsonFormat 格式化后存储,方便阅读及手动修改
|
$ret = file_put_contents($tempJsonFile, \CommFunc\JsonFormat($saveTempContent));
|
// echo "<br/>file_put_contents ret:" . $ret . "<br/>";
|
if ($ret == false) {
|
echo $opStr . \Lang\gettext("失败") . "<br/>";
|
} else {
|
echo $opStr . \Lang\gettext("成功") . "<br/>";
|
}
|
echo "<a href='" . $backUrl;
|
if ($backIndex >= 0) {
|
echo "?tempIndex=" . $backIndex;
|
}
|
echo "'>" . \Lang\gettext("返回") . "</a><br/>";
|