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

$art_act = trim($_POST['act']);

if($art_act=='set'){
	$art_id	= trim($_POST['id']);
	$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);
	
	$url_err = 'art_set.php?type='.$art_type.'&id='.$art_id;
	if($art_name==''){
		die(refresh($url_err).'<script>alert(\'文章标题不能为空！\')</script>');
	}
	if($art_type==''){
		die(refresh($url_err).'<script>alert(\'请选择文章分类！\')</script>');
	}
	if($art_info==''){
		die(refresh($url_err).'<script>alert(\'文章内容不能为空！\')</script>');
	}
	
	$_LST = $vdb->opendir($art_type.'/list');
	if(empty($_LST)){
		$_LST = array();
	}
	$key = array_find($_LST, 'id', $art_id);
	if($key<0){
		die('ID Error! ( id = '.$art_id.' )');
	}else{
		$this_pic = $_LST[$key]['pic'];
		$this_img = $_LST[$key]['img'];
		$this_name = $_LST[$key]['name'];
		if(($this_name!=$art_name)
		  ||($this_pic!=$art_pic)
		  ||($this_img!=$art_img)){
			$_LST[$key]['pic'] = $art_pic;
			$_LST[$key]['img'] = $art_img;
			$_LST[$key]['name'] = $art_name;
			$vdb->writedir($art_type.'/list', $_LST);
		
			$vdb->open('index');
			$vdb->write();
		}
	}
	
	$_ART = $vdb->open($art_type.'/view/'.$art_id);
	$_ART['this_type']	= $_VDB['art'][$art_type];
	$_ART['this_dir']	= $art_type;
	$_ART['this_pic']	= $art_pic;
	$_ART['this_img']	= $art_img;
	$_ART['this_name']	= $art_name;
	$_ART['this_keys']	= $art_keys;
	$_ART['this_desc']	= $art_desc;
	$vdb->update($_ART, $art_info);
	$vdb->write();
	unset($_ABT);
	
	unset($_LST);
	unset($_VDB);
	unset($vdb);
	
	die(refresh('art_list.php?type='.$art_type).'<script>alert(\'文章修改成功！\')</script>');
}else{
	$art_id	= trim($_GET['id']);
	if(!$art_id){die('ID Error!');}
	
	$art_type = trim($_GET['type']);
	$type_name = $_VDB['art'][$art_type];
	
	$_ART = $vdb->open($art_type.'/view/'.$art_id);
	$art_pic = $_ART['this_pic'];
	$art_img = $_ART['this_img'];
	$art_name = $_ART['this_name'];
	$art_time = $_ART['this_time'];
	$art_keys = $_ART['this_keys'];
	$art_desc = $_ART['this_desc'];
	$art_info = htmlspecialchars($vdb->txt);

	unset($_ART);
	unset($_VDB);
	unset($vdb);
}
?>
<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" />
<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_set.php" method="post" onSubmit="return chkform(this);" style="margin:auto;padding:25px;width:600px;text-align:left">
		<input type="hidden" name="id" value="<? echo $art_id; ?>">
		<input type="hidden" name="type" value="<? echo $art_type; ?>">
		文章标题：<input type="text" name="name" value="<? echo $art_name; ?>" class="input_txt2"><br>
		<br>关 键 词：<input type="text" name="keys" value="<? echo $art_keys; ?>" class="input_txt2"><br>
		<br>文章描述：<input type="text" name="desc" value="<? echo $art_desc; ?>" class="input_txt2"><br>
		<br>文章分类：<select disabled="disabled">
			<option value="<? echo $art_type; ?>"><? echo $type_name; ?></option>
		</select><br>
		<br>缩略图片：<input type="text" name="pic" value="<? echo $art_pic; ?>" class="input_txt2"><br>
		<br>原始图片：<input type="text" name="img" value="<? echo $art_img; ?>" class="input_txt2"><br>
		<br>文章内容：<input type="hidden" name="info" value="<? echo $art_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="act" value="set">
	</form>
	</div><br>
</div>
</body>
</html>