<?php 
$this->display(tpl('head',true)); 
if($edit['bold']){
	$bold='checked';
}
if($nid>1){
	$display="style='display:none'";
}
?>

<style>
	.layui-form-select{
		width: 30%;
	}
	.my-input{
		width: 30%;
		display:  initial;
	}
	.color{
		width: 70px;
	}
	td .layui-form-item{
		margin-bottom: 0;
		border-bottom:1px solid #eee;
	}
	td .layui-form-label{
		width:14.1%;
		padding: 9px 15px;
		min-height: 20px;
		line-height: 20px;
		text-align: left;
		border-right: 1px solid #eee;
	}
	td .layui-input-block{
		margin-left: 0;
	}
	td .layui-input-block:before{
		content:'';
		margin-left:15px
	}
</style>
<script src="/public/global/js/colpick.js" type="text/javascript" charset="utf-8"></script>
<form class="layui-form" method="post" action="">
	<table class="layui-table my-tabel">
		<tbody>
			<tr>
				<td>所属栏目</td>
				<td>
					<select name="post[cid]" lay-filter="ciddb" class="my-input">
		    		<option value="">请选择要发布到的栏目</option>\r\n
					<?php
					foreach($allcidDB AS $row){
						$p_dis="";
						$setting=unserialize($row['setting'])['power'][C('mydb.groupid')];
				    	if(!$setting['add'] && C('mydb.groupid') !='3'){
				    		$p_dis='disabled';
				    	}
				    	$selected="";
				    	if($row['cid']==$cid && !$p_dis){
							$selected=" selected";
						}
					 ?>
					<option value="<?php echo $row[cid] ?>" <?php echo $selected; ?> <?php echo $p_dis ?>><?php echo $row[levels]; echo $row[name] ?></option>\r\n
					<?php } ?>
			    	</select>
				</td>
			</tr>
			<tr>
				<td>标题</td>
				<td>
					<input name="post[title]" value="<?php echo $edit[title] ?>"  lay-verify="required|title" placeholder="请输入标题" class="layui-input my-input" type="text">
					颜色
					<input name="post[color]" id="color" class="layui-input my-input color" type="text" value="<?php echo $edit[color] ?>">
					<input name="post[bold]" title="加粗" type="checkbox" value="1" <?php echo $bold ?>>
					<div id="picker"></div>
				    <script type="text/javascript">
				    	$("#color").css('background-color','#<?php echo $edit[color] ?>');
				    	$("#color").css('color','#fff');
				    	$('#color').colpick({
							layout:'hex',
							submit:0,
							colorScheme:'dark',
							onChange:function(hsb,hex,rgb,el,bySetColor) {
								$(el).css('border-color','#'+hex);
								$(el).css('color','#FFF');
								$(el).css('background-color','#'+hex);
								if(!bySetColor) $(el).val(hex);
							}
						}).keyup(function(){
							$(this).colpickSetColor(this.value);
						});
				    </script>
				    			
				</td>
			</tr>
			<tr>
				<td>关键字</td>
				<td>
					<input name="post[keyword]"  class="layui-input my-input" type="text" value="<?php echo $edit[keyword] ?>">
					<p>作为相关文章的索引,如多个用空格隔开</p>
				</td>
			</tr>
			<tr>
				<td colspan="2">
					<table class="layui-table my-tabel">
						<tbody>
							<tr>
								<td>作者</td>
								<td><input name="post[author]" class="layui-input" type="text" value="<?php echo $edit[author] ?>"></td>
								<td>来源</td>
								<td><input name="post[source]" class="layui-input" type="text" value="<?php echo $edit[source]?>"></td>
								<td>来源网址</td>
								<td><input name="post[source_url]" class="layui-input" type="text" value="<?php echo $edit[source_url]?>"></td>
							</tr>
						</tbody>
					</table>
				</td>
			</tr>
			<tr>
				<td colspan="2">
					<table class="layui-table my-tabel">
						<tbody>
							<tr>
								<?php if($setting['is_comment'] || C('mydb.groupid') =='3'){ ?>
								<td>是否禁止评论</td>
								<td><input name="post[is_comment]" class="layui-input" type="checkbox" value="1" title="勾选禁止评论" <?php echo $is_comment[1] ?>></td>
								<?php }  if($setting['is_sell'] || C('mydb.groupid') =='3'){ ?>
								<td>查看积分</td>
								<td><input name="post[sell_jifen]" class="layui-input" type="text" value="<?php echo $edit[sell_jifen] ?>"></td>
								<?php }  if($setting['is_pass'] || C('mydb.groupid') =='3'){ ?>
								<td>查看密码</td>
								<td><input name="post[password]" class="layui-input" type="text" value="<?php echo $edit[password] ?>"></td>
								<?php } ?>
							</tr>
						</tbody>
					</table>
				</td>
			</tr>
			<tr>
				<td>缩略图</td>
				<td>
					<input name="post[thumb]" id="thumb" class="layui-input  my-input" type="text" value="<?php echo $edit[thumb] ?>">
			    	<button type="button" class="layui-btn layui-btn-normal" id="select_pic">选择图片上传</button>
				</td>
			</tr>
			<?php if($Custom_Model_Template){ ?>
			<tr>
				<td colspan="2">
					<?php echo $Custom_Model_Template ?>
				</td>
			</tr>
			<?php } ?>
			<tr>
				<td>内容</td>
				<td>
					<?php
						$i=0;
						$num=count($cont_query);
						if($num >1){
					?>
					<div class="page">
					<?php 
						foreach($cont_query AS $row){
							$i++;
					?>
					<a href="javascript:void(0);" onclick="return content('<?php echo $row[nid] ?>',this);"> 第<?php echo $i ?>页</a>
					<?php } ?>
					</div>
					<script>
						var content_data=<?php echo json_encode($cont_query); ?>;
					</script>
					<?php } ?>
					<p>如果是多页在要分页的地方插入##page##</p>
					<textarea name="post[content]" style="height:300px; width: 100%; z-index: 1;" id="content" placeholder="请输入内容" ><?php echo $cont_query['0'][content] ?></textarea>
					<script type="text/javascript">
						var ue = UE.getEditor('content',{
							zIndex : 900,
							autoHeightEnabled:false,
					       	serverUrl: "/user/index/plugin/ueditor/setting/ueditor_config/",
					      	toolbars: [<?php echo json_encode(C('UEDITOR_CONFIG.function')) ;?>]
						});
						
					</script>
				</td>
			</tr>
			<tr>
				<td colspan="2" align="center">
					<input type="hidden" name="post[aid]" value="<?php echo $edit[aid] ?>" />
					<input type="hidden" id="nid" name="post[nid]" value="<?php echo $cont_query['0'][nid] ?>" />
					<input type="hidden" name="post[mid]" value="<?php echo $mid ?>" />
					<input type="hidden" name="post[step]" value="post" />
					<button class="layui-btn" lay-submit="" lay-filter="post">立即提交</button>
				</td>
				<script>
					var _this='';
					function content(nid,THIS){
						if(_this){
							_this.style.backgroundColor='';
							_this.style.color ='';
							_this.style.fontWeight ='';
						}
						console.log(content_data);
						_this=THIS;
						for(var i=0;i<content_data.length;i++){
							if(content_data[i].nid==nid){
								ue.setContent(content_data[i].content);
								$("#nid").val(nid);
							}
						}
						
						
						
						THIS.style.backgroundColor='red';
						THIS.style.color ='#fff';
						THIS.style.fontWeight ='bold';
					}
				</script>
			</tr>
		</tbody>
	</table>	
</div>
</form>
<script>

layui.config({
	version: '<?php echo $NOWTIME ?>'
});
layui.use(['upload','form','layer','element','laydate'], function(){
  	var $ = layui.jquery
  	,element = layui.element
  	,upload = layui.upload;
   	var $ = layui.jquery, layer = layui.layer;
	var form = layui.form;
	form.on('select(ciddb)', function(data){
		var type=data.elem.selectedOptions[0].attributes.type.value;
			var mid=data.elem.selectedOptions[0].attributes.mid.value;
		if(type !=0){
			$('.layui-btn').attr("disabled",true);
			alert("只有栏目才可以发布内容，请重新选择");
			return false;
		}else if(data.value > 0){
			window.location.href='/user/articles/add/cid/'+data.value;
			$('.layui-btn').attr("disabled",false); 
		}
	});
	var laydate = layui.laydate;
	laydate.render({
		elem: '#posttime',
		type: 'datetime'
	});
	form.verify({
	    title: function(value){
		    if(value.length < 5){
		        return '标题至少得5个字符';
		    }
	    }
  	});


	
	
	//选完文件后不自动上传
	upload.render({
	    elem: '#select_pic',
	    url: '/user/upfile/up/thumb/1/json/true/',
	    auto: true,
	    bindAction: '#star_upload',
	    before: function(obj){
	    	files = obj.pushFile(); //将每次选择的文件追加到文件队列
	    	loading = layer.load();
	    },
	    done: function(res, index, upload){
	    	layer.close(loading);
		    if(res.code != 0){
		    	layer.msg(res.text);
		    }else{
		      	$('#thumb').val(res.url); 
		    }
		    delete files[index]; //删除对应的文件
	    }
	});
});
</script>
<?php $this->display(tpl('foot',true)); ?>
