<!DOCTYPE html>
<html lang="zh-CN">
  
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>{$site_name}</title>
<meta name="keywords" content="{$title}">
<meta name="description" content="{$title}">
<link href="css/dialog.css" rel="stylesheet">
<link href="css/style.css" rel="stylesheet">
<link href="css/fonts.css" rel="stylesheet">
<script src="js/jquery.min.js"></script>
<script src="js/superslide.js"></script>
<script src="js/code.js"></script>
<script src="js/tn_code.js"></script>
<script src="js/sucai.js"></script>
<script src="js/masonry.js"></script>
<script src="js/MiniDialog.js"></script>
<script src="js/bootstrap.js"></script>
<script src="xheditor/xheditor-1.2.2.min.js"></script>
<script src="xheditor/zh-cn.js"></script>

<script>
function getSelectVal(){ 
	$.getJSON("select_cate.php",{bigname:$("#bigname").val()},function(json){ 
		var smallname = $("#smallname"); 
		$("option",smallname).remove(); //清空原有的选项 
		$.each(json,function(index,array){ 
			var option = "<option value='"+array['category_id']+"'>"+array['category_name']+"</option>"; 
			smallname.append(option); 
		}); 
	}); 
} 
</script>
<link type="image/png" href="favicon.ico" rel="shortcut icon">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>

<script>
$(function(){ 
    getSelectVal(); 
    $("#bigname").change(function(){ 
        getSelectVal(); 
    }); 
}); 
</script>

  <body>
    <?php 
	include_once('search_nav.php');
	?>
    <div class="fa-pins container clear" style="overflow:hidden;">
      <div class="fa-crumbs">
        <i class="ftsucai-227"></i>当前位置 :
        <!--{if $html_flag==1}-->
        <a href="index">首页</a>
        <!--{else}-->
        <a href="index.php">首页</a>
        <!--{/if}-->
		<span>></span>
        <a href="usercenter.php">用户管理中心</a>
	  </div>
      <div class="fa-pins-other left" style="margin-bottom:-9999px;padding-bottom:9999px;width:220px;height:800px;">
         <?php 
	     include_once('control_left.php');
	     ?>
      </div>
	  <div class="overlay"></div>
       <div class="fa-pins-info right" style="margin-bottom:-9999px;padding-bottom:9999px;width:928px;">
        <div class="pins-info" style="padding-top:0px;">
          <div class="text">
			<form action="" method="post" name="form" enctype="multipart/form-data" id="form">
			  <table width="98%" border="0" class="font16">
				  <!--{if $html_flag==1}-->
				  <tr>
					<td width="20%" height="60" align="right" >说明：</td>
					<td width="80%"><font color="blue">对用户发布的信息需进行编辑审核后才能对外显示!</font></td>
				  </tr>
				  <!--{/if}-->
				  <tr>
					<td width="20%" height="60" align="right" >素材标题：</td>
					<td width="80%">
					  <input name="msg_title" type="text" class="myinput" id="msg_title" style="width:550px;">
					</td>
				  </tr>
				  <tr>
					<td  height="60" align="right">所属大类：</td>
					<td>
					<select class="myinput" name="bigname" id="bigname" style="width:185px;">
					  <!--{loop $rscate $v}-->
					  <option value="{$v[category_id]}">{$v[category_name]}</option>
					  <!--{/loop}-->
					</select>
					<select class="myinput" name="smallname" id="smallname" style="width:180px;">
					</select>
					</td>
				  </tr>
				  <tr>
					<td  height="60" align="right">下载地址：</td>
					<td><input name="msg_downurl" type="text" class="myinput" id="msg_downurl" style="width:550px;">
					</td>
				  </tr>
				  <tr>
					<td  height="60" align="right">所需积分：</td>
					<td><input name="msg_integral" type="text" class="myinput" id="msg_integral" style="width:60px;" value="0">
					下载要扣下载用户的积分,请填写整数
					</td>
				  </tr>
				  <tr>
					<td  height="60" align="right">演示地址：</td>
					<td><input name="msg_demourl" type="text" class="myinput" id="msg_demourl" style="width:550px;">
					</td>
				  </tr>
				  <tr>
					<td  height="60" align="right">上传图片：</td>
					<td>
					<input id='location' class="myinput" onClick="$('#i-file').click();" style="width:460px;">
					<input type="file" name="pic_file" id='i-file'  accept="{$ext_str}" onChange="$('#location').val($('#i-file').val());" style="display: none">
					<input type="button" id="i-check" value="浏览文件" class="filebtn" style="background:#d9d9d9; color:#333;" onClick="$('#i-file').click();">
					</td>
				  </tr>
				  <tr>
					<td  height="60" align="right">信息说明：</td>
					<td>
					<textarea id="content" name="msg_content" class="xheditor-simple" rows="15" cols="80" style="width: 85%"></textarea>
					</td>
				  </tr>
				  <tr>
					<td height="60" align="right">信息验证：</td>
					<td align="left"><div class="tncode" style="text-align: center;"></div></td>
				  </tr>
				  <tr>
					<td height="80" align="right"></td>
					<td  height="80" align="left"> <!--onClick="chk(form);" -->
					<input id="mybtn" class="mybtn" name="mybtn" type="button" value=" 确认提交 " style="width:370px;cursor:pointer;">
					</td>
				  </tr>
			  </table>
		  </form> 
          </div>
        </div>
      </div>
    </div>
    <?php 
	include_once('bottom.php');
	?>

<script>
	$("#mybtn").click(function(){
		var formData  = new FormData();

		var msg_title    = $("#msg_title").val();
		var msg_downurl  = $("#msg_downurl").val();
		var msg_demourl  = $("#msg_demourl").val();
		var msg_integral = $("#msg_integral").val();
		var smallname    = $("#smallname").val();
		var msg_content  = $("#content").val(); 

		if (msg_title==''){
		   Dialog.warn("{$site_name}提醒您","素材标题不能为空！");
		   return false;
		}else if (msg_downurl==''){
		   Dialog.warn("{$site_name}提醒您","下载地址不能为空！");
		   return false;
		}else if(isNaN(msg_integral) || msg_integral<0){
		   Dialog.warn("{$site_name}提醒您","所需积分只能是数字且为正整数或0！");
		   return false;
		}else if ($("#location").val()==''){
		   Dialog.warn("{$site_name}提醒您","上传图片不能为空！");
		   return false;
		}

        formData.append("msg_title", msg_title);
		formData.append("msg_downurl", msg_downurl);
		formData.append("msg_demourl", msg_demourl);
		formData.append("msg_integral", msg_integral);
		formData.append("smallname", smallname);
		formData.append("msg_content", msg_content);
		formData.append("file", $("#i-file")[0].files[0]);

		var file = $("#i-file")[0].files[0];
		var reader = new FileReader();
		reader.readAsDataURL(file);
		reader.onload = function (e) {

			var data = e.target.result;
			//加载图片获取图片真实宽度和高度
			var image = new Image();
			image.src = data;

			//图片先加载完，才可以得到图片宽度和高度
			image.onload = function(){
				var width  = image.width;
				var height = image.height;
                if (width>680 || width<265){
					pic_err="上传的图片宽度范围只能在265~680之间";
					Dialog.warn("提交失败", pic_err);
					return false;
                }

				formData.append("width", width);
				formData.append("height", height);

				$.ajax({
					url: "submit_pub.php",
					type: "post",
					data: formData,
					processData: false,
					contentType: false,
					dataType: 'text',
					success: function(data) {
						var rs  = eval('('+data+')');
						var msg = rs.message;

						if (rs.status==0){
						  Dialog.warn("提交失败", msg);
					    }
					    if (rs.status==1){
						  Dialog.success("提交成功", msg).ok(function () {
							 window.location="userpost.php?a=2";
						  });
					    }
					},
					error: function(data) {
						Dialog.warn("提交失败", '服务器异常,请稍后再试~');
					}
				});
			}
		}
	});
</script>
  </body>
</html>