<?
/*
	[SueamCMS] (C)2009-2010 ZMRNet Studio
	art_add.php by 2009-10-13 zmrnet
*/
require_once(dirname(__FILE__).'/include/manage.php');

$art_act = trim($_POST['action']);
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title><? echo $sys_title; ?></title>
<link href="images/sueam.css" rel="stylesheet" type="text/css" />
<?
if($art_act=='add'){
	$art_pic	= trim($_POST['pic']);
	$art_img	= trim($_POST['img']);
	$art_name	= trim($_POST['name']);
	$art_type	= trim($_POST['type']);
	$art_keys	= trim($_POST['keys']);
	$art_desc	= trim($_POST['desc']);
	$art_info	= trim($_POST['info']);
	$art_info	= htmlspecialchars_decode($art_info);
	
	if($art_name==''){
		die(refresh('art_add.php').'<script>alert(\'文章标题不能为空！\')</script>');
	}
	if($art_type==''){
		die(refresh('art_add.php').'<script>alert(\'请选择文章分类！\')</script>');
	}
	if($art_info==''){
		die(refresh('art_add.php').'<script>alert(\'文章内容不能为空！\')</script>');
	}
	
	$_LST = $vdb->opendir($art_type.'/list');
	if(empty($_LST)){
		$_LST = array();
		$art_id = 1;
	}else{
		$_MAX = max($_LST);
		$art_id = $_MAX['id'] + 1;
		unset($_MAX);
	}
	$art_time = date('Y-m-d H:i:s', time()+(time_zone*3600));
	
	$vdb->open($art_type.'/view/'.$art_id);
	$_ART = array();
	$_ART['this_type']	= $_VDB['art'][$art_type];
	$_ART['this_dir']	= $art_type;
	$_ART['this_id']	= $art_id;
	$_ART['this_pic']	= $art_pic;
	$_ART['this_img']	= $art_img;
	$_ART['this_name']	= $art_name;
	$_ART['this_time']	= $art_time;
	$_ART['this_keys']	= $art_keys;
	$_ART['this_desc']	= $art_desc;
	$vdb->update($_ART, $art_info);
	$vdb->write();
	unset($_ART);

	$_ART = array();
	$_ART['id']		= $art_id;
	$_ART['pic']	= $art_pic;
	$_ART['img']	= $art_img;
	$_ART['name']	= $art_name;
	$_ART['time']	= $art_time;
	array_unshift($_LST, $_ART);
	$vdb->writedir($art_type.'/list', $_LST);
	unset($_ART);
	unset($_LST);
	
	$vdb->open('index');
	$vdb->write();
	
	die(refresh('art_list.php?type='.$art_type).'<script>alert(\'文章添加成功！\')</script>');
}
?>
<script language="javascript">
function chkform(o){
	if(o.name.value==''){
		alert('文章标题不能为空！');
		o.name.focus();
		return false;
	}else if(o.type.value==''){
		alert('请选择文章分类！');
		o.type.focus();
		return false;
	}
	return true;
}
</script>
</head>
<body>
<div style="margin:20px;">
	<div style="margin:10px;font-size:14px;color:green"><b>添加文章</b></div>
	<div class="sec_menu">
	<form action="art_add.php" method="post" onsubmit="return chkform(this);" style="margin:auto;padding:25px;width:600px;text-align:left">
		文章标题：<input type="text" name="name" class="input_txt2"><br>
		<br>关 键 词：<input type="text" name="keys" class="input_txt2"><br>
		<br>文章描述：<input type="text" name="desc" class="input_txt2"><br>
		<br>文章分类：<select name="type">
			<option value="">选择分类</option>
<?
$art = $_VDB['art'];
foreach($art as $type => $name){
?>
			<option value="<? echo $type; ?>"><? echo $name; ?></option>
<?
}
unset($art);

unset($_VDB);
unset($vdb);
?>
		</select><br>
		<br>缩略图片：<input type="text" name="pic" value="" class="input_txt2"><br>
		<br>原始图片：<input type="text" name="img" value="" class="input_txt2"><br>
		<br>文章内容：<input type="hidden" name="info"><br>
		<iframe id="editor" src="editor/editor.htm?id=info&style=coolblue" frameborder="0" scrolling="no" width="550" height="350"></iframe><br><br>
		<input type="reset" value="还原">&nbsp;&nbsp;&nbsp;&nbsp;<input type="submit" value="提交">
		<input type="hidden" name="action" value="add">
	</form>
	</div><br>
</div>
</body>
</html>