<!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;
	cursor:pointer;
}
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=Forum.postlist" class="nolink">帖子管理</a>
				<a href="index.php?r=Forum.postallreplylist" class="link">回复信息审核</a>
				<a href="index.php?r=Forum.accusationlist" class="link">举报信息管理</a>
				<a href="index.php?r=Forum.shortcutreplylist" class="link">快速回复语</a>
				<a href="index.php?r=Forum.postloglist" class="link">日志管理</a>
			</div>
			<div id="secrightContent">
				<div class="tableContent">
					<form id="ForumPostForm" action="index.php?r=Forum.updatepost" method="post">
						<input type="hidden" name="action" value="do"/>
						<input type="hidden" name="data[ForumPost][id]" value="<!--{$forumPost.id}-->"/>
						<input type="hidden" name="data[ForumPost][post_type]" value="<!--{$forumPost.post_type}-->"/>
						
						<table class="tbl_edit" width="100%">
							<tr>
								<td class="td_name">标题<span class="red">*</span></td>
								<td class="td_content"><input type="text" class="text" id="title" name="data[ForumPost][title]" value="<!--{$forumPost.title}-->" maxlength='256'/><span id="span_title"></span></td>
							</tr>
							<tr>
								<td class="td_name">是否头条</td>
								<td class="td_content">
									<input type="radio" name="data[ForumPost][bulletin_flag]" value="1" <!--{if $forumPost.bulletin_flag==1}-->checked<!--{/if}--> onclick="changeBulletinFlag()">是
									<input type="radio" name="data[ForumPost][bulletin_flag]" value="0" <!--{if $forumPost.bulletin_flag==0}-->checked<!--{/if}--> onclick="changeBulletinFlag()">否
								</td>
							</tr>
							<tr id="channelTr">
								<td class="td_name">所属频道<span class="red">*</span></td>
								<td class="td_content"><select id="channel_id" name="data[ForumPost][channel_id]">
									<option value="">--选择频道--</option>
									<!--{foreach from=$channelList name=foo item=channel}-->
										<option value="<!--{$channel.id}-->" <!--{if $forumPost.channel_id==$channel.id}-->selected<!--{/if}-->><!--{$channel.channel_text}--></option>
									<!--{/foreach}-->
								</select><span id="span_channel_id"></span></td>
							</tr>
							<tr>
								<td class="td_name">点击量</td>
								<td class="td_content"><input type="text" class="number" id="click_count" name="data[ForumPost][click_count]" value="<!--{$forumPost.click_count}-->"/><span id="span_click_count"></span></td>
							</tr>
							<tr>
								<td class="td_name">发布时间</td>
								<td class="td_content">
									<div style="float:left;"><input id="create_date" name="data[ForumPost][create_date]" class="text" value="<!--{$forumPost.create_date|date_format:'%Y-%m-%d %H:%M:%S'}-->"/></div>
									<div class="anchorbutton" style="margin-left:5px;line-height:25px;" onClick="currentTime('create_date')" onMouseOver="overanchor(this)" onMouseOut="outanchor(this)">当前时间</div>
									<div style="margin-left:5px;line-height:25px;"><span id="span_create_date"></span></div>
								</td>
							</tr>
							
							<tr <!--{if $forumPost.post_type!=1}-->style="display:none;"<!--{/if}--> id="show-tr-1">
								<td class="td_name">图片<span class="red">*</span></td>
								<td class="td_content">
									<div style="width:100%;" id="p-list">
									<div style="float:left;width:100%;" ><input type="hidden" id="inpu-img-size-0" name="annex_img_size[]" /><input type="hidden" id="inpu-img-fileext-0" name="annex_img_fileext[]" /><input type="hidden" id="inpu-img-filename-0" name="annex_img_filename[]" /><input style="float:left;width:200px;" id="inpu-img-0" name="annex_img[]" /><div id="img_annex_button0" class="button" style="float:left;">上传图片</div><div onclick="$(this).parent().remove();" class="button" style="float:left;">删除</div></div>
									</div>
									
									<div style="float:left;width:100%;"><a id="add-p-list" href="#">增加图片</a></div>
								</td>
							</tr>
							
							<tr <!--{if $forumPost.post_type!=2}-->style="display:none;"<!--{/if}--> id="show-tr-2">
								<td class="td_name">附件<span class="red">*</span></td>
								<td class="td_content">
									<div style="width:100%;" id="o-list">
									<!--{if !empty($annexList)}-->
									<!--{foreach from=$annexList key=key item=item}-->
									<div style="float:left;width:100%;" ><div style="float:left;line-height:25px;"><!--{$key+1}-->.<!--{$item.annex_url}--></div><div value="<!--{$item.id}-->" class="button deleteAnnex" style="float:left;">删除</div></div>
									<!--{/foreach}-->
									<!--{/if}-->
									<div style="float:left;width:100%;" ><input type="hidden" id="inpu-other-size-0" name="annex_other_size[]" /><input type="hidden" id="inpu-other-fileext-0" name="annex_other_fileext[]" /><input type="hidden" id="inpu-other-filename-0" name="annex_other_filename[]" /><input style="float:left;width:200px;" id="inpu-other-0" name="annex_other[]" /><div id="o_annex_button0" class="button" style="float:left;">上传附件</div><div onclick="$(this).parent().remove();" class="button" style="float:left;">删除</div></div>
									</div>
									
									<div style="float:left;width:100%;"><a id="add-o-list" href="#">增加附件</a></div>
								</td>
							</tr>
							
							<tr <!--{if $forumPost.post_type!=3}-->style="display:none;"<!--{/if}--> id="show-tr-3">
								<td class="td_name">投票项<span class="red">*</span></td>
								<td class="td_content">
									<div style="width:100%;" id="poll-list">
									<!--{if !empty($pollList)}-->
									<!--{foreach from=$pollList key=key item=item}-->
									<div style="float:left;width:100%;" ><div style="float:left;line-height:25px;"><!--{$key+1}-->.<!--{$item.text}--></div><div value="<!--{$item.id}-->" class="button deletePollItem" style="float:left;">删除</div></div>
									<!--{/foreach}-->
									<!--{/if}-->
									<div style="float:left;width:100%;" ><input maxlength="50" style="float:left;width:200px;" id="poll-0" name="poll[]" /><div onclick="$(this).parent().remove();" class="button" style="float:left;">删除</div></div>
									</div>
									<div style="float:left;width:100%;"><a id="add-poll-list" href="#">增加投票项</a></div>
								</td>
							</tr>
							
							<tr <!--{if $forumPost.post_type!=4}-->style="display:none;"<!--{/if}--> id="show-tr-4">
								<td class="td_name">登录可见内容<span class="red">*</span></td>
								<td class="td_content">
									<textarea id="logincontent" style="width:80%;" name="login_content"><!--{$lcontent}--></textarea>
								</td>
							</tr>
							
							<tr <!--{if $forumPost.post_type!=5}-->style="display:none;"<!--{/if}--> id="show-tr-5">
								<td class="td_name">回复可见内容<span class="red">*</span></td>
								<td class="td_content">
									<textarea id="replycontent" style="width:80%;"  name="reply_content"><!--{$rcontent}--></textarea>
								</td>
							</tr>
							
							<tr>
								<td class="td_name">内容<span class="red">*</span></td>
								<td class="td_content"><textarea id="content" name="data[ForumPostContent][content]"><!--{$forumPostContent.content}--></textarea><span id="span_content"></span></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>
var clist = 0;
$().ready(function(){
	$("#content").addClass("cleditorTextarea").cleditor({
		width: "80%",
		height: 120,
		controls: "bold italic underline break | undo redo | " +
			" image link file | basic-function advertising-system access-statistics"
	});
	
	$(".deleteAnnex").click(function(){
		var id = $(this).attr("value");
		var _this = $(this);
		if(id>0){
			$(this).html("<img src=\"images/ajax.gif\"/>");
			$.get('index.php?r=Forum.deleteAnnex',{id:id},function(data){
				if(data.status==1){
					_this.parent().remove();
				}else{
					_this.html("删除");
				}
			},"json");
		}
	});
	
	$(".deletePollItem").click(function(){
		var id = $(this).attr("value");
		var _this = $(this);
		if(id>0){
			$(this).html("<img src=\"images/ajax.gif\"/>");
			$.get('index.php?r=Forum.deletePollItem',{id:id},function(data){
				if(data.status==1){
					_this.parent().remove();
				}else{
					_this.html("删除");
				}
			},"json");
		}
	});
	
	$("#add-p-list").click(function(){
		clist++;
		var index = clist;
		var htl = '<div style="float:left;width:100%;" ><input type="hidden" id="inpu-img-size-'+index+'" name="annex_img_size[]" /><input type="hidden" id="inpu-img-fileext-'+index+'" name="annex_img_fileext[]" /><input type="hidden" id="inpu-img-filename-'+index+'" name="annex_img_filename[]" /><input style="float:left;width:200px;" id="inpu-img-'+index+'" name="annex_img[]" /><div id="img_annex_button'+index+'" class="button" style="float:left;">上传图片</div><div onclick="$(this).parent().remove();" class="button" style="float:left;">删除</div></div>';
		$("#p-list").append(htl);
		
		new AjaxUpload($("#img_annex_button"+index), {
			action: 'index.php?r=Forum.postannexupload&type=img',
			name: 'img_file',
			onSubmit : function(file, ext){
				this.disable();
				$("#img_annex_button"+index).html('<img src="images/ajax.gif"/>');
			},
			onComplete: function(file, response){
				//alert(response);
				//{"size":1,"name":"\/uploads\/post\/201103\/img\/2011032317484831.gif","fileext":"gif","filename":"3glooked","flag":1,"width":164,"height":38}
				var data = eval("("+response+")");
				if(data.flag == 1){
					$("#img_annex_button"+index).html('上传图片');
					$("#inpu-img-"+index).val(data.name);
					$("#inpu-img-size-"+index).val(data.size);
					$("#inpu-img-fileext-"+index).val(data.fileext);
					$("#inpu-img-filename-"+index).val(data.filename);
					$("#inpu-img-"+index).parent().children("span").filter(".error").remove();
					this.enable();
				} else {
					alert("上传文件失败!");
					$("#img_annex_button"+index).html('上传图片');
					this.enable();
				}
			}
		});
		
	});
	
	$("#add-poll-list").click(function(){
		var htl = '<div style="float:left;width:100%;" ><input maxlength="50"  style="float:left;width:200px;" name="poll[]" /><div onclick="$(this).parent().remove();" class="button" style="float:left;">删除</div></div>';
		$("#poll-list").append(htl);
	});
	
	$("#add-o-list").click(function(){
		clist++;
		var index = clist;
		var htl = '<div style="float:left;width:100%;" ><input type="hidden" id="inpu-other-size-'+index+'" name="annex_other_size[]" /><input type="hidden" id="inpu-other-fileext-'+index+'" name="annex_other_fileext[]" /><input type="hidden" id="inpu-other-filename-'+index+'" name="annex_other_filename[]" /><input style="float:left;width:200px;" id="inpu-other-'+index+'" name="annex_other[]" /><div id="o_annex_button'+index+'" class="button" style="float:left;">上传附件</div><div onclick="$(this).parent().remove();" class="button" style="float:left;">删除</div></div>';
		$("#o-list").append(htl);
		
		new AjaxUpload($("#o_annex_button"+index), {
			action: 'index.php?r=Forum.postannexupload&type=other',
			name: 'other_file',
			onSubmit : function(file, ext){
				this.disable();
				$("#o_annex_button"+index).html('<img src="images/ajax.gif"/>');
			},
			onComplete: function(file, response){
				var data = eval("("+response+")");
				if(data.flag == 1){
					$("#o_annex_button"+index).html('上传附件');
					$("#inpu-other-"+index).val(data.name);
					$("#inpu-other-size-"+index).val(data.size);
					$("#inpu-other-fileext-"+index).val(data.fileext);
					$("#inpu-other-filename-"+index).val(data.filename);
					$("#inpu-other-"+index).parent().children("span").filter(".error").remove();
					this.enable();
				} else {
					alert("上传文件失败!");
					$("#o_annex_button"+index).html('上传附件');
					this.enable();
				}
			}
		});
		
	});
	
	new AjaxUpload($("#img_annex_button0"), {
		action: 'index.php?r=Forum.postannexupload&type=img',
		name: 'img_file',
		onSubmit : function(file, ext){
			this.disable();
			$("#img_annex_button0").html('<img src="images/ajax.gif"/>');
		},
		onComplete: function(file, response){
			var data = eval("("+response+")");
			if(data.flag == 1){
				$("#img_annex_button0").html('上传图片');
				$("#inpu-img-0").val(data.name);
				$("#inpu-img-size-0").val(data.size);
				$("#inpu-img-fileext-0").val(data.fileext);
				$("#inpu-img-filename-0").val(data.filename);
				$("#inpu-img-0").parent().children("span").filter(".error").remove();
				this.enable();
			} else {
				alert("上传文件失败!");
				$("#img_annex_button0").html('上传图片');
				this.enable();
			}
		}
	});
	new AjaxUpload($("#o_annex_button0"), {
		action: 'index.php?r=Forum.postannexupload&type=other',
		name: 'other_file',
		onSubmit : function(file, ext){
			this.disable();
			$("#o_annex_button0").html('<img src="images/ajax.gif"/>');
		},
		onComplete: function(file, response){
			var data = eval("("+response+")");
			if(data.flag == 1){
				$("#o_annex_button0").html('上传附件');
				$("#inpu-other-0").val(data.name);
				$("#inpu-other-size-0").val(data.size);
				$("#inpu-other-fileext-0").val(data.fileext);
				$("#inpu-other-filename-0").val(data.filename);
				$("#inpu-other-0").parent().children("span").filter(".error").remove();
				this.enable();
			} else {
				alert("上传文件失败!");
				$("#o_annex_button0").html('上传附件');
				this.enable();
			}
		}
	});

	
	var validate = $("#ForumPostForm").validate({
		rules: {
			'data[ForumPost][title]': {
				required:true,
				rangelength:[1,256]
			},
			'data[ForumPost][channel_id]':'required',
			'data[ForumPost][post_type]':'required',
			'data[ForumPost][click_count]': {
				number: true,
				digits : true,
				min:0
			}
		},
		messages: {
			'data[ForumPost][title]': {
				required:'标题不能为空',
				rangelength:jQuery.format('标题长度必须为{0}位至{1}位')
			},
			'data[ForumPost][channel_id]':'请选择所属频道',
			'data[ForumPost][post_type]':'请选择帖子类型',
			'data[ForumPost][click_count]': {
				number: "点击量必须为正整数",
				digits : "点击量必须为正整数",
				min:jQuery.format('点击量必须大于{0}')
			}
		},
		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");
		},
		onkeyup:false
	});
	
	$("#ForumPostForm").submit(function(){
		
		var post_type = <!--{$forumPost.post_type}-->;
			if(post_type == 1){
				if(check_input("annex_img[]","图片地址"))
				{
					if($("#content").val()==''){
						$("#span_content").addClass("error").html("内容不能为空！");
						return false;
					}else{
						$("#span_content").removeClass("error").html("");
					}
					
				}
				
			}else if(post_type == 2){
				if(check_input("annex_other[]","附件地址"))
				{
					if($("#content").val()==''){
						$("#span_content").addClass("error").html("内容不能为空！");
						return false;
					}else{
						$("#span_content").removeClass("error").html("");
					}
					
				}
			}else if(post_type == 3){
				return check_input("poll[]","投票项");
			}else if(post_type == 4){
				return check_input("login_content","登录可见内容");
			}else if(post_type == 5){
				return check_input("reply_content","回复内容");
			}else if(post_type == 0){
				if($("#content").val()==''){
					$("#span_content").addClass("error").html("内容不能为空！");
					return false;
				}else{
					$("#span_content").removeClass("error").html("");
				}
			}
		
		if (validate.numberOfInvalids() <= 0) {
			setDisabled(":button",window.document);
			return true;
		} else {
			return false;
		}
	});
	
	//changeBulletinFlag()();
});

function check_input(name,txt)
{
	 var item = $("[name="+name+"]");
	 if(item.size()>0){
	 	var r = true;
	 	item.each(function(){
			if($(this).val()==""){
				$(this).parent().children("span").filter(".error").remove();
				$(this).parent().append('<span class="error">'+txt+'不能为空！</span>');
				r= false;
			}else{
				$(this).parent().children("span").filter(".error").remove();
			}
		});
		
		return r;
	 }else{
	 	alert(txt+"必须不能为空！");
	 	return false;
	 }
}

function deleteannex(deletebutton){
	$(deletebutton).html("<img src=\"images/ajax.gif\"/>");
	$.post("index.php?r=Forum.postannexdelete", {annexdir : $(deletebutton).parent().find(".anchorinput").val()}, function(data){
		$(deletebutton).parent().remove();
	});
}

function changeBulletinFlag(){
	var bulletinFlag = 0;
	$("input[name='data[ForumPost][bulletin_flag]']").each(function(index,element){
		if($(element).attr('checked')==true){
			bulletinFlag = $(element).val();
			return false;
		}
	});
	if(bulletinFlag==1){
		$("#channelTr").hide();
		$("#channel_id").rules("remove");
	}else{
		$("#channelTr").show();
		$("#channel_id").rules("add",{
			required:true
		});
	}
}
function overanchor(button){
	$(button).addClass("anchorbuttonon");
}

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