<?php
if (!defined('MOD')) die("access die");
checkAdminReferer();
$cid = intval($_GET['cid']);
if ($cid < 1) qbase::purviewCheckDie($channeltitle . "分类不存在");
$info = getCidInfo($channelid, $cid);
if(empty($info)) die('提交了错误的数据');

$num  =  $info['arrchildid'] ? qdb::QueryAlone("select count(*) as num from ".TABLEPRE."{$_MODULE[$channelselect][table_name]}_{$channelid} where cid in ({$info['arrchildid']}) ") : 0;
if( $num > 0) qbase::purviewCheckDie("该栏目下尚有相关信息,请先删除该栏目下的信息");
$arrchild = qdb::QueryAlone("SELECT arrchildid FROM `".TABLEPRE."acategory` WHERE `channelid`=" . $channelid . "  and  `cid` = '$cid' ");
$arrchildidid = explode(",", $arrchild);
if ($_GET['action'] == 'remove')
{
	while (list($key, $val) = each($arrchildidid))
	{
		$val = intval($val);
		qdb::Query("delete from `".TABLEPRE."acategory` where `channelid`='{$channelid}' and cid='{$val}'");
		cache::delete('cid_'.$cid);
	}
	qdb::Query("delete from `".TABLEPRE."acategory` where `channelid`='{$channelid}' and cid='{$cid}'");
}

qbase::get_object('category', $channelid)->update();
commonCache();
adminLog("删除栏目分类{$info['title']}");
qbase::showmsg($channeltitle . "分类及其分类下面的" . $channeltitle . "删除完成", 'default', "system.php?sys=acategory&channelid=" . $channelid . "&action=modify");
?>
