<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head><title><!--{$UUDEV_PAGE_TITLE}--></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<!--{include file=elements/header.css.html}-->
<!--{include file=elements/header.js.html type=common}-->
<!--{include file=elements/header.js.html type=ubb}-->
<!--{include file=elements/header.js.html type=upload}-->
<!--{include file=elements/header.js.html type=valid}-->
<style type="text/css">
div.button {
	font-size:12px;
	color:#00f;
	line-height:25px;
	text-align:center;
	float:left;
	margin-left:5px;
}
div.button.hover{
	color:#f00;
}
.anchorbutton{
	font-size:12px;
	color:#00f;
	text-align:center;
	float:left;
	margin-left:5px;
	cursor:pointer;
}

.anchorbuttonon{
	color:#f00;
}
</style>
</head>
<body>
<div id="outside">
	<!--{include file=frame/top.html}-->
	<div id="mainareaContent">
		<!--{include file=frame/left.html}-->
		<div id="rightContent">
			<div id="topContent">
				<div class="sitmap">
					<span class="r"><!--{include file="elements/uuadvad.html"}--></span>模块管理&nbsp;&gt;&nbsp;游戏模块&nbsp;&gt;&nbsp;内容管理&nbsp;&gt;&nbsp;修改游戏
				</div>
			</div>
			<div class="tabcontent">
				<a href="index.php?r=Game.resource" class="nolink">内管管理</a>
				<a href="index.php?r=SiteSet.gameset" class="link">属性设置</a>
				<a href="index.php?r=Game.gameListLayout" class="link">列表页布局</a>
					<a href="index.php?r=Game.gamePageLayout" class="link">内容页布局</a>
			</div>
			<div id="secrightContent">
				<div class="tableContent">
					<form action="index.php?r=Game.editgameinfo" method="post" id="editForm">
						<input type="hidden" name="data[Game][id]" value="<!--{$data.id}-->"/>
						<input type="hidden" name="returnParams" value="<!--{$returnParams}-->"/>
						<table class="tbl_edit" width="100%">
							<tr>
								<td class="td_name">游戏名称<span class="red">*</span></td>
								<td class="td_content"><input type="text" name="data[Game][title]" id="Game_title" class="text" value="<!--{$data.title}-->" maxlength='256'/><span id="span_Game_title"></span></td>
							</tr>
							<tr>
								<td class="td_name">主图片</td>
								<td class="td_content">
									<div style="float:left;"><input type="text" class="text" name="data[Game][image_url]" id="Game_image_url" value="<!--{$data.image_url}-->"/></div>
									<div style="float:left;" id="button1" class="button">上传图片</div>
									<div style="float:left;line-height:25px;">&nbsp;<span id="main_img"></span></div>
									<input type="hidden" name="data[Game][thumb_image_url]" id="Game_thumb_image_url" value="<!--{$data.thumb_image_url}-->"/>
								</td>
							</tr>
							<tr>
								<td class="td_name">游戏截图</td>
								<td class="td_content">
									<!--{foreach from=$gamepics item=gamepic}-->
									<div style="clear:both;">
										<div style="float:left;"><input type="text" class="text" value="<!--{$gamepic.image_url}-->" readonly/></div>
										<div style="float:left;line-height:25px;" class="anchorbutton" onMouseOver="overanchor(this)" onMouseOut="outanchor(this)" onClick="deletescreenpic(this, <!--{$gamepic.id}-->)">删除截图</div>
									</div>
									<!--{/foreach}-->
									<div id="scpicurlcontainer" style="clear:both;"></div>
									<div id="addgamepicbutton" class="anchorbutton" style="clear:both;margin-left:0px;">添加截图</div>
								</td>
							</tr>
							<tr>
								<td class="td_name">发布频道</td>
								<td class="td_content">
								<!--{if !empty($channels)}-->
									<!--{foreach from=$channels item=channel name=foo}-->
										<input type="checkbox" name="channel_id[]" id="channel_id[]" value="<!--{$channel.channel_id}-->" <!--{if $channel.sel_channel_id != null}-->checked<!--{/if}-->/>[<!--{$channel.channel_id}-->]<!--{$channel.channel_text}-->&nbsp;
										<!--{if ($smarty.foreach.foo.index+1) % 4 == 0}--><br/><!--{/if}-->
									<!--{/foreach}-->
								<!--{else}-->
									无
								<!--{/if}-->	
								</td>
							</tr>
							<tr>
								<td class="td_name">创建时间</td>
								<td class="td_content">
									<div style="float:left;"><input type="text" name="data[Game][create_date]" id="Game_create_date" value="<!--{$data.create_date}-->" class="text"/></div>
									<div class="anchorbutton" style="margin-left:5px;line-height:25px;" onClick="currentTime('Game_create_date')" onMouseOver="overanchor(this)" onMouseOut="outanchor(this)">当前时间</div>
									<div style="margin-left:5px;line-height:25px;"><span id="span_Game_create_date"></span></div>
								</td>
							</tr>
							<tr>
								<td class="td_name">推荐等级</td>
								<td class="td_content"><select name="data[Game][recommend_level]">
									<option value="">推荐等级</option>
									<option value="1" <!--{if $data.recommend_level == 1}-->selected<!--{/if}-->>1</option>
									<option value="2" <!--{if $data.recommend_level == 2}-->selected<!--{/if}-->>2</option>
									<option value="3" <!--{if $data.recommend_level == 3}-->selected<!--{/if}-->>3</option>
									<option value="4" <!--{if $data.recommend_level == 4}-->selected<!--{/if}-->>4</option>
									<option value="5" <!--{if $data.recommend_level == 5}-->selected<!--{/if}-->>5</option>
								</select></td>
							</tr>
							<tr>
								<td class="td_name">好评数</td>
								<td class="td_content"><input type="text" class="number" id="good_count" name="data[Game][good_count]" value="<!--{$data.good_count}-->"/><span id="span_good_count"></span></td>
							</tr>
							<tr>
								<td class="td_name">中评数</td>
								<td class="td_content"><input type="text" class="number" id="normal_count" name="data[Game][normal_count]" value="<!--{$data.normal_count}-->"/><span id="span_normal_count"></span></td>
							</tr>
							<tr>
								<td class="td_name">差评数</td>
								<td class="td_content"><input type="text" class="number" id="bad_count" name="data[Game][bad_count]" value="<!--{$data.bad_count}-->"/><span id="span_bad_count"></span></td>
							</tr>
							<tr>
								<td class="td_name">人气</td>
								<td class="td_content"><input type="text" class="number" id="click_count" name="data[Game][click_count]" value="<!--{$data.click_count}-->"/><span id="span_click_count"></span></td>
							</tr>
							<tr>
								<td class="td_name">下载次数</td>
								<td class="td_content"><input type="text" class="number" id="down_count" name="data[Game][down_count]" value="<!--{$data.down_count}-->"/><span id="span_down_count"></span></td>
							</tr>
							<tr>
								<td class="td_name">收费类型</td>
								<td class="td_content"><select name="data[Game][fee_type]">
									<option value="">收费类型</option>
									<option value="1" <!--{if $data.fee_type == 1}-->selected<!--{/if}-->>免费</option>
									<option value="2" <!--{if $data.fee_type == 2}-->selected<!--{/if}-->>收费</option>
									<option value="3" <!--{if $data.fee_type == 3}-->selected<!--{/if}-->>其他</option>
								</select></td>
							</tr>
							<tr>
								<td class="td_name">收费说明</td>
								<td class="td_content"><input type="text" class="text" name="data[Game][fee_detail]" value="<!--{$data.fee_detail}-->" maxlength='64'/></td>
							</tr>
							<tr>
								<td class="td_name">厂商</td>
								<td class="td_content"><input type="text" class="text" name="data[Game][manufacturer]" value="<!--{$data.manufacturer}-->" maxlength='32'/></td>
							</tr>
							<tr>
								<td class="td_name">是否重命名上传包</td>
								<td class="td_content"><input type="radio" name="data[Game][rename_flag]" value="1" <!--{if $data.rename_flag == 1}-->checked<!--{/if}-->/>是&nbsp;&nbsp;<input type="radio" value="0" name="data[Game][rename_flag]" <!--{if $data.rename_flag == 0}-->checked<!--{/if}-->/>否</td>
							</tr>
							<tr>
								<td class="td_name">是否开启评论</td>
								<td class="td_content"><input type="radio" name="data[Game][comment_flag]" value="1" <!--{if $data.comment_flag == 1}-->checked<!--{/if}-->/>是&nbsp;&nbsp;<input type="radio" value="0" name="data[Game][comment_flag]" <!--{if $data.comment_flag == 0}-->checked<!--{/if}-->/>否</td>
							</tr>
							<tr>
								<td class="td_name">游戏介绍</td>
								<td class="td_content"><textarea id="introduction" name="data[Game][introduction]"><!--{$data.introduction}--></textarea></td>
							</tr>
							<tr>
								<td class="td_name">安装教程</td>
								<td class="td_content"><textarea id="install_tutorial" name="data[Game][install_tutorial]"><!--{$data.install_tutorial}--></textarea></td>
							</tr>
							<tr>
								<td class="noborder"></td>
								<td class="noborder"><button type="submit" class="butsubmit">提交</button>&nbsp;&nbsp;<button type="button" class="but2font" onClick="window.location.href='index.php?<!--{$returnParams}-->'">返回</button></td>
							</tr>
						</table>
					</form>
				</div>
			</div>
		</div>
	</div>
</div>
</body>
<script>
$(document).ready(function(){
	$("#introduction").addClass("cleditorTextarea").cleditor({
		width : "80%",
		height: 120,
		controls: "bold italic underline break | undo redo | " +
			" image link file | basic-function advertising-system access-statistics"
	});
	$("#install_tutorial").addClass("cleditorTextarea").cleditor({
		width : "80%",
		height: 120,
		controls: "bold italic underline break | undo redo | " +
			" image link file | basic-function advertising-system access-statistics"
	});
	
	var button1 = $("#button1");
	new AjaxUpload(button1, {
		action: 'index.php?r=Game.gameimageupload',
		name: 'image_file',
		onSubmit : function(file, ext){
			this.disable();
			button1.html('<img src="images/ajax.gif"/>');
		},
		onComplete: function(file, response){
			var data = eval("("+response+")");
			if(data.flag == 1){
				$("#Game_image_url").val(data.name);
				$("#Game_thumb_image_url").val(data.thumb_name);
				button1.html('上传图片');
				$("#main_img").html(file);
				this.enable();
			} else if(data.flag == -1){
				alert("不能上传格式为" + data.fileext + "的文件!");
				button1.html('上传图片');
				this.enable();
			} else if(data.flag == -2){
				alert("上传文件的大小超出指定范围!");
				button1.html('上传图片');
				this.enable();
			} else if(data.flag == -10){
				//if(data.compress_error_code == 7){
					alert("水印文字过长,压缩文件失败!请调整游戏属性设置中图片压缩和水印设置后,重新上传!");
				//}
				button1.html('上传图片');
				this.enable();
			} else {
				alert("上传文件失败!");
				button1.html('上传图片');
				this.enable();
			}
		}
	});

	var uploadimgbuttoncount = 0;
	$("#addgamepicbutton").click(function(){
		uploadimgbuttoncount = uploadimgbuttoncount + 1;
		var str = "<div style=\"clear:both;\">";
		str = str + "<div style=\"float:left;\"><input type=\"text\" class=\"text anchorinput\" name=\"data[GamePicture][image_url][]\" id=\"GamePicture_image_url[]\" value=\"\" /></div>";
		str = str + "<div id=\"uploadimgbutton"+uploadimgbuttoncount+"\" class=\"button\">上传图片</div>";
		str = str + "<div style=\"float:left;line-height:25px;\" class=\"anchorbutton\" onMouseOver=\"overanchor(this)\" onMouseOut=\"outanchor(this)\" onclick=\"deletepic(this)\">删除截图</div>";
		str = str + "<div style=\"float:left;line-height:25px;\">&nbsp;<span class=\"img_src_name\"></span></div></div>";
		$(str).appendTo("#scpicurlcontainer");

		var uploadimgbutton = $("#uploadimgbutton"+uploadimgbuttoncount);
		new AjaxUpload(uploadimgbutton, {
			action: 'index.php?r=Game.screenimgupload',
			name: 'image_file',
			onSubmit : function(file, ext){
				this.disable();
				uploadimgbutton.html('<img src="images/ajax.gif"/>');
			},
			onComplete: function(file, response){
				var data = eval("("+response+")");
				if(data.flag == 1){
					$(uploadimgbutton).parent().find(".anchorinput").val(data.name);
					uploadimgbutton.html('上传图片');
					$(uploadimgbutton).parent().find(".img_src_name").html(file);
					this.enable();
				} else if(data.flag == -1){
					alert("不能上传格式为" + data.fileext + "的文件!");
					uploadimgbutton.html('上传图片');
					this.enable();
				} else if(data.flag == -2){
					alert("上传文件的大小超出指定范围!");
					uploadimgbutton.html('上传图片');
					this.enable();
				} else {
					alert("上传文件失败!");
					uploadimgbutton.html('上传图片');
					this.enable();
				}
			}
		});
	});

	$(".anchorbutton").hover(
			function(){$(this).addClass("anchorbuttonon")},
			function(){$(this).removeClass("anchorbuttonon")}
	);
	
	jQuery.validator.addMethod("datetime", function(value, element) {    
		  return this.optional(element) || /^((((1[6-9]|[2-9]\d)\d{2})-(0?[13578]|1[02])-(0?[1-9]|[12]\d|3[01]))|(((1[6-9]|[2-9]\d)\d{2})-(0?[13456789]|1[012])-(0?[1-9]|[12]\d|30))|(((1[6-9]|[2-9]\d)\d{2})-0?2-(0?[1-9]|1\d|2[0-8]))|(((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))-0?2-29-)) (20|21|22|23|[0-1]?\d):[0-5]?\d:[0-5]?\d$/.test(value);   
		}, "日期时间格式不正确");

	var validate = $("#editForm").validate({
		rules: {
			'data[Game][title]' : {
				'required' : true
			},
			'data[Game][good_count]':{
				'number': true,
				'digits' : true
			},
			'data[Game][normal_count]':{
				'number': true,
				'digits' : true
			},
			'data[Game][bad_count]':{
				'number': true,
				'digits' : true
			},
			'data[Game][click_count]':{
				'number': true,
				'digits' : true
			},
			'data[Game][down_count]':{
				'number': true,
				'digits' : true
			},
			'data[Game][create_date]':{
				'required' : true,
				'datetime' : true
			}
		},
		messages: {
			'data[Game][title]' : {
				'required' : '请填写游戏名称'
			},
			'data[Game][good_count]':{
				'number': '好评数必须为正整数',
				'digits':'好评数必须为正整数'
			},
			'data[Game][normal_count]':{
				'number': '中评数必须为正整数',
				'digits':'中评数必须为正整数'
			},
			'data[Game][bad_count]':{
				'number': '差评数必须为正整数',
				'digits':'差评数必须为正整数'
			},
			'data[Game][click_count]':{
				'number': '人气值必须为正整数',
				'digits':'人气值必须为正整数'
			},
			'data[Game][down_count]':{
				'number': '下载次数必须为正整数',
				'digits':'下载次数必须为正整数'
			},
			'data[Game][create_date]':{
				'required':'日期不能为空',
				'datetime':'日期格式有误，正确格式为：YYYY-MM-DD HH:MM:SS'
			}
		},
		errorPlacement: function(error, element){
			$("#span_" + element.attr("id")).html(error).attr("class", "error");
		},
		errorClass: "invalid",
		success: function(label){
			label.parent().html("&nbsp;").attr("class", "valid");
		}
	});
	
	$("#editForm").submit(function(){
		if (validate.numberOfInvalids() <= 0) {
			setDisabled(":button",window.document);
			return true;
		} else {
			return false;
		}
	});
});

function deletescreenpic(deletebutton, picid){
	if(confirm('删除之后，信息无法恢复，是否确定删除？')) {
		$(deletebutton).html("<img src=\"images/ajax.gif\"/>");
		$.get("index.php?r=Game.deletegamepic&picid="+picid, function(data){
			if(data == "1"){
				$(deletebutton).parent().remove();
			} else {
				alert("删除截图失败");
			}
		});
	}
}

function deletepic(deletebutton){
	$(deletebutton).html("<img src=\"images/ajax.gif\"/>");
	if($(deletebutton).parent().find(".anchorinput").val()){
		$.post("index.php?r=Game.deletepic", {picdir : $(deletebutton).parent().find(".anchorinput").val()}, function(data){
			$(deletebutton).parent().remove();
		});
	} else {
		$(deletebutton).parent().remove();
	}
}

function overanchor(button){
	$(button).addClass("anchorbuttonon");
}

function outanchor(button){
	$(button).removeClass("anchorbuttonon");
}
</script>
</html>