<?php


require_once( "_inc.php" );
util::auth( );
$categoryId = !empty( $_GET['cId'] ) ? trim( $_GET['cId'] ) : "";
$backUrl = !empty( $_GET['back'] ) ? trim( $_GET['back'] ) : base64_encode( "category_list.php" );
if ( empty( $categoryId ) )
{
	$tpl->assign( "msg", "缺少参数" );
	$tpl->display( "_msg.tpl" );
	exit( );
}
$sql = "DELETE FROM ".$gDb['prefix'].( "sites WHERE (f_categoryId='".$categoryId."')" );
$db->query( $sql );
$parentId = $db->fetchone( "SELECT f_parentId FROM ".$gDb['prefix'].( "categories WHERE (f_id='".$categoryId."')" ) );
$count = $db->fetchone( "SELECT COUNT(f_id) FROM ".$gDb['prefix'].( "categories WHERE (f_parentId='".$parentId."')" ) );
if ( $count <= 1 )
{
	$db->query( "UPDATE ".$gDb['prefix'].( "categories SET f_haveChild=0 WHERE (f_id='".$parentId."')" ) );
}
$sql = "DELETE FROM ".$gDb['prefix'].( "categories WHERE (f_id='".$categoryId."')" );
$db->query( $sql );
@unlink( "../".$gCategoryDir.( "/".$categoryId.".html" ) );
$tpl->assign( "msg", "删除成功。" );
$tpl->assign( "refreshUrl", "sort.php" );
$tpl->assign( "backUrl", base64_decode( $backUrl ) );
$tpl->display( "_msg.tpl" );
?>
