File: //www/wwwroot/www.luckcjtw.com/admin_items_edit.php
<?PHP
set_time_limit(0);
header('Content-Type: text/html; charset=UTF-8');
#加载系统配置文件 该文件只包含各种系统配置项
require "./include/config.h";
#加载公共函数 主要是一些工具函数
require "./include/functions.php";
#开启数据库连接
$db = tools::get_db();
$db_ = clone $db;
//获取活动ID
$nGameId = (int)$_REQUEST["game_id"];
$sAction = trim($_REQUEST["action"]);
if ( $sAction == "save" ) {
$aInfo = $_REQUEST["info"];
#判断活动ID
if ( (int)$aInfo["game_id"] <= 0 ) {
exit("failed:game_id");
}
#判断是否新增
if ( $aInfo["item_id"] <= 0 ) {
#新增奖品信息
$sSql = "INSERT INTO gift_items(game_id,item_name,is_force,orderby) VALUES('".$aInfo["game_id"]."','".$aInfo["item_name"]."','".$aInfo["is_force"]."','".$aInfo["orderby"]."')";
if ( $db->query($sSql) ) {
exit("success");
}
#修改奖品内容
} else {
$sSql = "UPDATE gift_items SET item_name = '".$aInfo["item_name"]."',is_force = '".$aInfo["is_force"]."',orderby = '".$aInfo["orderby"]."' WHERE game_id = ".$aInfo["game_id"]." AND item_id = ".$aInfo["item_id"];
if ( $db->query($sSql) ) {
exit("success");
}
}
exit("failed");
} elseif ( $sAction == "del" ) {
$nItemId = (int)$_REQUEST["item_id"];
if ( $nItemId > 0 ) {
$sSql = "DELETE FROM gift_items WHERE item_id = ".$nItemId;
if ( $db->query($sSql) ) {
exit("success");
}
}
exit("failed");
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>獎品內容</title>
<style>
body {
margin:0px;text-align:center;
font-family:微软雅黑;font-size:25px;color:#000000;
}
input,select {
font-size:25px;
}
table, td{ border:1px solid #CCC; padding-top:4px; padding-bottom:4px;}
table{
border-collapse:collapse;
}
.button {
background-color: #4CAF50; /* Green */
border: none;
color: white;
padding: 15px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 26px;
cursor: pointer;
}
.btn1 {
margin:5px;
padding: 10px 10px;
font-size: 25px;
font-weight:bold;
}
.btn2 {
margin:2px;
padding: 5px 10px 5px 10px;
font-size: 23px;
}
h2{line-height:30px; font-size:30px;}
a,a:hover{ text-decoration:none;}
pre{font-family:'微软雅黑'}
.box{width:100px; padding:10px 20px; background-color:#fff; margin:10px auto;}
.box a{padding-right:20px;}
</style>
<script src="js/jquery-3.5.1.min.js"></script>
<script type='text/javascript'>
$(document).ready(function(){
$("button#admin_items_save").click(function(data){
//console.log($("#admin_items_edit").serialize());
$.ajax({
type: "post",
url: "admin_items_edit.php?action=save",
data: $("#admin_items_edit").serialize(),
//dataType: "json",
success: function(data) {
alert("保存成功");
},
error: function(err) {
alert("保存失敗");
}
});
});
$("button#admin_game_add").click(function(data){
window.location.href = "./admin_game_edit.php";
});
$("button#admin_game_edit").click(function(data){
window.location.href = "./admin_game_edit.php?game_id=" + data.currentTarget.name;
});
$("button#admin_items").click(function(data){
window.location.href = "./admin_items.php?game_id=" + data.currentTarget.name;
});
$("button#admin_user").click(function(data){
window.location.href = "./admin_user.php?game_id=" + data.currentTarget.name;
});
$("button#back").click(function(data){
//history.go(-1);
//history.back(-1);
window.location.href = "./admin_items.php?game_id=" + data.currentTarget.name;;
});
});
</script>
</head>
<body>
<?PHP
//获取奖品ID
$nItemId = (int)$_REQUEST["item_id"];
#获取 奖品信息
$sSql = "SELECT * FROM gift_items WHERE item_id = ".$nItemId;
$db->query( $sSql );
$aItemInfo = $db->next_row();
if ( $nGameId <= 0 ) {
$nGameId = $aItemInfo["game_id"];
}
$sHtml = "<form id=admin_items_edit>";
$sHtml .= "<table align=center><tr><td colspan=6 style='font-size:30px;color:white;font-weight:bold;padding:10px;background-color:#4CAF50;'>獎品內容</td></tr>";
$sHtml .= "<tr style='font-size:25px;font-weight:bold;'><td width=120>獎品內容</td><td align=left> <input type=text name=info[item_name] value='".$aItemInfo[item_name]."'></td></tr>";
$sHtml .= "<tr style='font-size:25px;font-weight:bold;'><td>固定獎品</td><td align=left style='font-size:22px;font-weight:normal;'> <select name=info[is_force]><option value=1 ".($aItemInfo[is_force]?"selected":"").">是</option><option value=0 ".(!$aItemInfo[is_force]?"selected":"").">否</option></select>(普通用戶隨機抽取固定獎品)</td></tr>";
$sHtml .= "<tr style='font-size:25px;font-weight:bold;'><td>顯示順序</td><td align=left style='font-size:22px;font-weight:normal;'> <input size=3 type=text name=info[orderby] value=".$aItemInfo[orderby].">(請填寫1到8之間數字)</td></tr>";
$sHtml .= "<tr style='font-size:25px;font-weight:bold;'><td> </td><td><button type=button class='button btn2' id=admin_items_save>保存</button> <button type=button class='button btn2' id=back name=".$nGameId.">返回</button></td></tr>";
$sHtml .= "</table><input type=hidden name=info[game_id] value='".$nGameId."'><input type=hidden name=info[item_id] value=".$nItemId."></form>";
echo $sHtml;
?>
</body>
</html>