<?php
session_start();

include('includes/ajax_check_login.php');

if( !isset($_POST['author_id']) || ( $static_uint_author_id = (int)$_POST['author_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_author = $obj_class_admin->get_author_by_author_id($static_uint_author_id) ) )
	exit(json_encode(array('ErrCode'=>-1, 'ErrMessage'=>'指定的作者帳號不存在！', 'RedirectURL'=>'manage_authors.php?resume=1')));
else if( $arr_author[0]['LastLogin'] != '0000-00-00 00:00:00' )
	exit(json_encode(array('ErrCode'=>0, 'ErrMessage'=>'已登入啟用之帳號無法被刪除，如人員已離職，請將權限設定為禁止登入。', 'RedirectURL'=>'')));
else if( !$obj_class_admin->delete_author($static_uint_author_id) )
	exit(json_encode(array('ErrCode'=>0, 'ErrMessage'=>'作者帳號［' . $arr_author[0]['AuthorAccount'] . '］刪除失敗！', 'RedirectURL'=>'')));
else
	exit(json_encode(array('ErrCode'=>1, 'ErrMessage'=>'作者帳號［' . $arr_author[0]['AuthorAccount'] . '］已被刪除', 'RedirectURL'=>'')));
?>