<?php include $this->admin_tpl('meta', 'admin');?>
<title>编辑广告 - YzmCMS内容管理系统</title>
</head>
<body>
<article class="page-container">
<div class="formdoby_normal"> 
	<form method="post" onsubmit="return dosub(this)">
		<ul>
			 <li><label><span class="c-red">*</span>广告名称</label><input type="text" placeholder="广告名称" class="input" name="title" value="<?php echo $data['title'];?>"></li>
			 <li><label><span class="c-red">*</span>链接地址</label><input type="url" placeholder="要加http://" class="input" name="url" value="<?php echo $data['url'];?>" style="width:400px"></li>
			 <li><label><span class="c-red">*</span>广告类型</label>
			 <span class="span_input">
			 	<label class="label_radio"><input name="type" type="radio" value="1" <?php if($data['type'] == 1) echo 'checked';?>> 文字形式</label>
			 	<label class="label_radio"><input name="type" type="radio" value="2" <?php if($data['type'] == 2) echo 'checked';?>> HTML代码</label>
			 	<label class="label_radio"><input name="type" type="radio" value="3" <?php if($data['type'] == 3) echo 'checked';?>> 图片形式</label>
			 </span>
			 </li>
			 <li id="adver_text"<?php if($data['type'] == 3) echo ' style="display:none"';?>><label><span class="c-red">*</span>广告值</label><textarea name="text" class="textarea" style="width:400px"><?php echo $data['text'];?></textarea></li>
			 <li id="adver_img"<?php if($data['type'] != 3) echo ' style="display:none"';?>><label><span class="c-red">*</span>选择图像</label><?php echo form::image('img', $data['img']);?></li>
			 <li class="yzm-explain-box"><label>开始时间</label><input type="text" class="input-text laydate-icon" id="start" style="width:230px;height:30px;" name="start_time" value="<?php echo $data['start_time'] ? date('Y-m-d', $data['start_time']) : '';?>">
			 	<span class="yzm-explain">留空为不限制</span>
			 </li>
			 <li class="yzm-explain-box"><label>结束时间</label><input type="text" class="input-text laydate-icon" id="end" style="width:230px;height:30px;" name="end_time" value="<?php echo $data['end_time'] ? date('Y-m-d', $data['end_time']) : '';?>">
			 	<span class="yzm-explain">留空为不限制</span>
			 </li>
			 <li><label>简洁描述</label><span class="span_input"><input type="text" class="input" name="describe" value="<?php echo $data['describe'];?>" style="width:500px"></span></li>			 
			 <li><input type="hidden" name="dosubmit" value="1"><input type="hidden" name="id" value="<?php echo $data['id'];?>">
			 <input class="dosubmit w_120 btn-primary radius" type="submit" value="提交">
			 <input class="btn w_120 btn-default radius" type="button" value="取消" onclick="yzmcms_close()">
			</li>
		</ul>
	</form>
</div>
</article>
<?php include $this->admin_tpl('footer', 'admin');?>
<script type="text/javascript" src="<?php echo STATIC_URL;?>plugin/laydate/1.1/laydate.js"></script>
<script type="text/javascript">

	$(function(){
		$('input:radio[name="type"]').change(function(){  
			if($(this).val()=='3') {
				$('#adver_img').css('display','');
				$('#adver_text').css('display','none');
			}else{
				$('#adver_img').css('display','none');
				$('#adver_text').css('display','');
			}
		}); 
	});

	function dosub(obj){
		 if(obj.title.value==''){
			 layer.msg('广告名称不能为空！');
			 return false;
		 }
		 if(obj.url.value==''){
			 layer.msg('链接地址不能为空！');
			 return false;
		 }
		 if($("input[name='type']:checked").val()=='3'){
			 if(obj.img.value==''){
				 layer.msg('图像地址不能为空！');
				 return false;
			 }
		 }else{
			 if(obj.text.value==''){
				 layer.msg('广告值不能为空！');
				 return false;
			 }
		 }
		 
        $.ajax({
            type: 'POST',
            url: '<?php echo U('edit');?>', 
            data: $(obj).serialize(),
		    dataType: "json", 
            success: function (msg) {
				if(msg.status == 1){
					layer.msg(msg.message, {icon:1, time:800}, function(){
						parent.location.reload();
					});
			    }else{
					layer.msg(msg.message, {icon:2});
				}
            }
        })		 
		return false;			 
	}
	
	
	var start = {
		elem: '#start',
		format: 'YYYY-MM-DD', 
		istime: false,
		istoday: false,
		choose: function(datas){
			 end.min = datas; 
			 end.start = datas 
		}
	};

	var end = {
		elem: '#end',
		format: 'YYYY-MM-DD',
		istime: false,
		istoday: false,
		choose: function(datas){
			start.max = datas; 
		}
	};
	laydate(start);
	laydate(end);
</script> 

</body>
</html>