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

$btn_ok = '添加';
$art_act = trim($_GET['act']);

if($art_act=='add'){
	$art_act = trim($_POST['act']);
	$art_set = trim($_POST['set']);
	$art_name = trim($_POST['name']);
	$art_type = trim($_POST['type']);
	
	if($art_name==''){
		die(refresh('art_type.php').'<script>alert(\'分类名称不能为空！\')</script>');
	}
	if($art_type==''){
		die(refresh('art_type.php').'<script>alert(\'分类目录不能为空！\')</script>');
	}
	
	$fs = new sueam_vfs();
	if(($art_act=='set')&&($art_set!='')){
		if($art_type!=$art_set){
			$fs->rename('../'.$art_set, '../'.$art_type);
			unset($vdb->dat['art'][$art_set]);
		}
		$vdb->dat['art'][$art_type] = $art_name;
		$vdb->save();
	}else{
		if(!is_dir('../'.$art_type)){
			$fs->mkdir('../'.$art_type);
			$fs->mkdir('../'.$art_type.'/list');
			$fs->mkdir('../'.$art_type.'/view');
			$vdb->dat['art'][$art_type] = $art_name;
			$vdb->save();
		}
	}
	unset($fs);
	
	$art_name = '';
	$art_type = '';
}

if($art_act=='del'){
	$art_type = trim($_GET['type']);
	if($art_type!=''){
		$fs = new sueam_vfs();
		$fs->rmdir('../'.$art_type);
		unset($fs);
		
		unset($vdb->dat['art'][$art_type]);
		$vdb->save();
		
		$art_type = '';
	}
}

$art = $vdb->dat['art'];
if($art_act=='set'){
	$btn_ok = '修改';
	$art_type = trim($_GET['type']);
	$art_name = $art[$art_type];
}
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>
	<a href="art_type.php">[添加]</a></div>
	<div class="sec_menu" style="padding:10px;">
	<div style="float:left;width:300px;border:0px;color:blue">
		<div style="text-align:left;">
			<font color="red">[</font>&nbsp;
			<font color="blue">分类操作</font>&nbsp;
			<font color="red">]</font>
			<font color="black">分类名称</font>
			(目录)
		</div>
<?
foreach($art as $type => $name){
?>
		<div style="text-align:left;">
			<font color="red">[</font>
			<a href="art_type.php?act=set&type=<? echo $type; ?>">修改</a>
			<a href="art_type.php?act=del&type=<? echo $type; ?>">删除</a>
			<font color="red">]</font>
			<font color="black"><? echo $name; ?></font>
			(<? echo $type; ?>)
		</div>
<?
}
unset($art);
?>
	</div>
	<div style="float:right;padding:10px;border:gray 1px dashed;">
		<form action="?act=add" method="post" onSubmit="return chkform(this);">
			<br>分类名称：<input type="text" name="name" value="<? echo $art_name; ?>" class="input_txt"><br>
			<br>分类目录：<input type="text" name="type" value="<? echo $art_type; ?>"  class="input_txt"><br>
			<br><input type="reset" value="还原">&nbsp;&nbsp;&nbsp;&nbsp;<input type="submit" value="<? echo $btn_ok; ?>">
			<input type="hidden" name="set" value="<? echo $art_type; ?>">
			<input type="hidden" name="act" value="<? echo $art_act; ?>">
		</form>
	</div>
	</div>
</div>
</body>
</html>