<?php
session_start();

include('includes/ajax_check_login.php');

if( !isset($_POST['news_cate_id']) || ( $static_uint_news_cate_id = (int)$_REQUEST['news_cate_id'] ) <= 0 )
	exit(json_encode(array('ErrCode'=>-1, 'ErrMessage'=>'輸入資料不足', 'RedirectURL'=>'')));

require_once('includes/common.php');

require_once('includes/admin.php');
$obj_class_admin = new class_admin();

if( !( $arr_news_cate = $obj_class_admin->get_news_cate_by_news_cate_id($static_uint_news_cate_id) ) )
{
	$_SESSION['init_info'] = '指定的分類不存在！';

	exit(json_encode(array('ErrCode'=>-1, 'ErrMessage'=>'', 'RedirectURL'=>'manage_news_cates.php')));
}
else if( $obj_class_admin->check_news_cate_has_news($static_uint_news_cate_id) )
	exit(json_encode(array('ErrCode'=>0, 'ErrMessage'=>'類別內尚有新聞，無法刪除！', 'RedirectURL'=>'')));
else if( !$obj_class_admin->delete_news_cate($static_uint_news_cate_id) )
	exit(json_encode(array('ErrCode'=>0, 'ErrMessage'=>'類別刪除失敗！', 'RedirectURL'=>'')));
else
	exit(json_encode(array('ErrCode'=>1, 'ErrMessage'=>'類別刪除成功', 'RedirectURL'=>'')));
?>