<?php
include('./cms_inc.php');
include('./cms_check.php');
if ( isset($_POST['save']) ) {
	$_data['d_name'] = $_POST['d_name'];
	$_data['d_picture'] = $_POST['d_picture'];
	$_data['d_parent'] = $_POST['d_parent'];
	$_data['d_rec'] = $_POST['d_rec'];
	$_data['d_hot'] = $_POST['d_hot'];
	$_data['d_cov'] = $_POST['d_cov'];
	$_data['d_content'] = $_POST['d_content'];
	$_data['d_scontent'] = ($_POST['d_scontent'] == '') ? cut_str(clear_html($_POST['d_content']),100) : $_POST['d_scontent'];
	$_data['d_mcontent'] = $_POST['d_mcontent'];
	$_data['d_slideshow'] = $_POST['d_slideshow'];
	$_data['d_keywords'] = $_POST['d_keywords'];
	$_data['d_description'] = $_POST['d_description'];
	$_data['d_seoname'] = $_POST['d_seoname'];
	$_data['d_file'] = $_POST['d_file'];
	$_data['d_p1'] = $_POST['d_p1'];
	$_data['d_p2'] = $_POST['d_p2'];
	$_data['d_p3'] = $_POST['d_p3'];
	$_data['d_p4'] = $_POST['d_p4'];
	$_data['d_link'] = $_POST['d_link'];
	$_data['d_order'] = $_POST['d_order'];
	$_data['d_author'] = $_POST['d_author'];
	$_data['d_source'] = $_POST['d_source'];
	$_data['d_hits'] = 0;
	$_data['d_date'] = strtotime($_POST['d_date']);
	$str = arrtoinsert($_data);
	$sql = 'insert into cms_detail ('.$str[0].') values ('.$str[1].')';
	if (sql_query($sql)) {
		$order = sql_insert_id();
		if ( $_POST['d_order'] == 0 ) {
			sql_query('update cms_detail set d_order = '.$order.' where id = '.$order);
		}
		alert_href('详情添加成功!','cms_detail_add.php?cid='.$_POST['d_parent']);
	} else {
		alert_back('详情添加失败!');
	}
}
?>
<!doctype html>
<html>
<head>
<?php include('./cms_inc_head.php') ?>
<script type="text/javascript">
KindEditor.ready(function(K) {
	K.create('#d_content');
	K.create('#d_mcontent');
	K.create('#d_slideshow',{
		items:[
			'source', 'image', 'multiimage', 'undo', 'redo', 'fullscreen'
		],
		cssData:'img { width: 88px !important; height: 88px !important; margin: 4px; border: 1px solid #EEE; padding: 4px;}'
	});
	var editor = K.editor();
	K('#picture').click(function() {
		editor.loadPlugin('image', function() {
			editor.plugin.imageDialog({
			imageUrl : K('#d_picture').val(),
			clickFn : function(url, title, width, height, border, align) {
				K('#d_picture').val(url);
				editor.hideDialog();
				}
			});
		});
	});

	K('#file').click(function() {
		editor.loadPlugin('insertfile', function() {
			editor.plugin.fileDialog({
				fileUrl : K('#d_file').val(),
				clickFn : function(url, title) {
					K('#d_file').val(url);
					editor.hideDialog();
				}
			});
		});
	});
});
$(function(){
	laydate.render({
		elem: '#d_date',
		type: 'datetime',
		format: 'yyyy-MM-dd HH:mm:ss'
	});
});
</script>
</head>
<body>
<div id="layout">
	<?php include('./cms_inc_header.php') ?>
	<div id="main">
		<div id="content">
			<?php include('./cms_inc_left.php') ?>
			<div id="right">
				<div class="hd-1">添加详情</div>
				<div class="bd-1">
					<form method="post">
						<div class="l20">
							<div class="form-group x4">
								<div class="label"><label for="d_parent">所属频道 <span class="badge bg-dot">必选</span></label></div>
								<div class="field">
									<select id="d_parent" class="input" data-validate="required:请选择上级频道" name="d_parent">
										<option value="">请选择上级频道</option>
										<?php echo channel_select_list(0,0,(isset($_GET['cid'])) ? $_GET['cid'] : 0,0); ?>
									</select>
									<div class="input-note">请选择详情属于哪个频道</div>
								</div>
							</div>
							<div class="form-group x5">
								<div class="label"><label for="d_name">详情名称 <span class="badge bg-dot">必填</span></label></div>
								<div class="field">
									<input id="d_name" class="input" name="d_name" type="text" size="60" data-validate="required:请输入详情名称" value="" />
									<div class="input-note">请输入详情名称</div>
								</div>
							</div>
							<div class="form-group x3">
								<div class="label"><label for="d_picture">缩略图</label> <span class="badge bg-green cp" id="picture">上传</span></div>
								<div class="field">
									<input id="d_picture" class="input" name="d_picture" type="text" size="60" value="" />
									<div class="input-note">图片列表显示的缩略图</div>
								</div>
							</div>
							<div class="fc"></div>
							<div class="form-group xx18">
								<div class="label"><label for="d_rec">推荐</label></div>
								<div class="field">
									<label class="btn"><input id="d_rec" name="d_rec" type="radio" value="0" checked="checked"/>否</label>
									<label class="btn"><input name="d_rec" type="radio" value="1" />是</label>
									<div class="input-note">选择是否推荐</div>
								</div>
							</div>
							<div class="form-group xx18">
								<div class="label"><label for="d_hot">热门</label></div>
								<div class="field">
									<label class="btn"><input id="d_hot" name="d_hot" type="radio" value="0" checked="checked"/>否</label>
									<label class="btn"><input name="d_hot" type="radio" value="1" />是</label>
									<div class="input-note">选择是否热门</div>
								</div>
							</div>
							<div class="form-group xx18">
								<div class="label"><label for="d_cov">封面</label></div>
								<div class="field">
									<label class="btn"><input id="d_cov" name="d_cov" type="radio" value="0" checked="checked"/>否</label>
									<label class="btn"><input name="d_cov" type="radio" value="1" />是</label>
									<div class="input-note">选择是否封面</div>
								</div>
							</div>
							<div class="form-group xx15">
								<div class="label"><label for="d_order">排序 <span class="badge bg-dot">必填</span></label></div>
								<div class="field">
									<input id="d_order" class="input" name="d_order" type="text" size="60" data-validate="required:必填,plusinteger:请输入排序数字" value="0" />
									<div class="input-note">0识别为详情ID</div>
								</div>
							</div>
							<div class="form-group xx15">
								<div class="label"><label for="d_author">作者</label></div>
								<div class="field">
									<input id="d_author" class="input" name="d_author" type="text" size="12" value="" />
									<div class="input-note">请输入作者</div>
								</div>
							</div>
							<div class="form-group xx15">
								<div class="label"><label for="d_source">来源</label></div>
								<div class="field">
									<input id="d_source" class="input" name="d_source" type="text" size="12" value="" />
									<div class="input-note">请输入来源</div>
								</div>
							</div>
							<div class="form-group xx21">
								<div class="label"><label for="d_date">发布日期</label></div>
								<div class="field">
									<input id="d_date" class="input" name="d_date" type="text" maxlength="255" size="60" readonly="readonly" value="<?php echo date('Y-m-d H:i:s',time());?>" data-validate="required:必须选择日期" />
									<div class="input-note">请选择日期</div>
								</div>
							</div>
							<div class="fc"></div>
							<div class="form-group x12">
								<div class="label"><label for="d_content">详细内容</label></div>
								<div class="field">
									<textarea id="d_content" class="input" name="d_content" /></textarea>
									<div class="input-note">支持图文混排等</div>
								</div>
							</div>
							<div class="form-group x12<?php echo ($system_closem) ? ' dn' : '' ;?>">
								<div class="label"><label for="d_mcontent">手机详细内容</label></div>
								<div class="field">
									<textarea id="d_mcontent" class="input" name="d_mcontent" /></textarea>
									<div class="input-note">留空自动识别为详细内容</div>
								</div>
							</div>
							<div class="fc"></div>
							<div class="form-group x12">
								<div class="label"><label for="d_scontent">简短内容</label></div>
								<div class="field">
									<textarea id="d_scontent" class="input" name="d_scontent" row="5" /></textarea>
									<div class="input-note">一般用于内容摘要，留空后自动截取部分详细内容。</div>
								</div>
							</div>
							<div class="fc"></div>
							<div class="form-group x12">
								<div class="label"><label for="d_slideshow">组图</label></div>
								<div class="field">
									<textarea id="d_slideshow" class="input" name="d_slideshow" row="5" /></textarea>
									<div class="input-note">系统会自动提取图片组成幻灯</div>
								</div>
							</div>
							<div class="fc"></div>
							<div class="form-group x4">
								<div class="label"><label for="d_keywords">关键字</label></div>
								<div class="field">
									<input id="d_keywords" class="input" name="d_keywords" type="text" size="60" value="" />
									<div class="input-note">请输入关键字</div>
								</div>
							</div>
							<div class="form-group x4">
								<div class="label"><label for="d_description">关键描述</label></div>
								<div class="field">
									<input id="d_description" class="input" name="d_description" type="text" size="60" value="" />
									<div class="input-note">请输入关键描述</div>
								</div>
							</div>
							<div class="form-group x4">
								<div class="label"><label for="d_seoname">优化标题</label></div>
								<div class="field">
									<input id="d_seoname" class="input" name="d_seoname" type="text" size="60" value="" />
									<div class="input-note">请输入优化标题</div>
								</div>
							</div>
							<div class="fc"></div>
							<div class="form-group x6">
								<div class="label"><label for="d_file">附件下载</label> <span class="badge bg-green cp" id="file">上传</span></div>
								<div class="field">
									<input id="d_file" class="input" name="d_file" type="text" size="30" value="" />
									<div class="input-note">请上传或填写附件地址</div>
								</div>
							</div>
							<div class="form-group x6">
								<div class="label"><label for="d_link">链接</label></div>
								<div class="field">
									<input id="d_link" class="input" name="d_link" type="text" size="60" data-validate="url:请填写合法的URL地址" value="" />
									<div class="input-note">外部用http://开头</div>
								</div>
							</div>
							<div class="fc"></div>
							<div class="x3">
								<div class="form-group">
									<div class="label"><label for="d_p1"><?php echo $system_p1;?></label></div>
									<div class="field">
										<input id="d_p1" class="input" name="d_p1" type="text" size="60" value="" />
									</div>
								</div>
							</div>
							<div class="x3">
								<div class="form-group">
									<div class="label"><label for="d_p2"><?php echo $system_p2;?></label></div>
									<div class="field">
										<input id="d_p2" class="input" name="d_p2" type="text" size="60" value="" />
									</div>
								</div>
							</div>
							<div class="x3">
								<div class="form-group">
									<div class="label"><label for="d_p3"><?php echo $system_p3;?></label></div>
									<div class="field">
										<input id="d_p3" class="input" name="d_p3" type="text" size="60" value="" />
									</div>
								</div>
							</div>
							<div class="x3">
								<div class="form-group">
									<div class="label"><label for="d_p4"><?php echo $system_p4;?></label></div>
									<div class="field">
										<input id="d_p4" class="input" name="d_p4" type="text" size="60" value="" />
									</div>
								</div>
							</div>
							<div class="fc"></div>
							<div class="form-group x12">
								<div class="label"><label></label></div>
								<div class="field">
									<input id="save" class="btn bg-dot" name="save" type="submit" value="添加详情" />
								</div>
							</div>
						</div>
					</form>
				</div>
			</div>
		</div>
	</div>
	<?php include('./cms_inc_footer.php') ?>
</div>
</body>
</html>