<?php
session_start();

include('includes/ajax_check_login.php');

require_once('includes/common.php');

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

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->update_news_cate($static_uint_news_cate_id, $static_str_news_cate_name, $static_uint_order) )
	exit(json_encode(array('ErrCode'=>0, 'ErrMessage'=>'新聞類別編輯失敗！', 'RedirectURL'=>'')));
else
	exit(json_encode(array('ErrCode'=>1, 'ErrMessage'=>'新聞類別編輯成功', 'RedirectURL'=>'manage_news_cates.php')));
?>