<?php
session_start();

include('includes/ajax_check_login.php');

if( !isset($_POST['admin_id']) || ( $static_uint_admin_id = (int)$_POST['admin_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_admin = $obj_class_admin->get_admin_by_admin_id($static_uint_admin_id) ) )
	exit(json_encode(array('ErrCode'=>-1, 'ErrMessage'=>'指定的帳號不存在！', 'RedirectURL'=>'list_admins.php?resume=1')));
else if( $arr_admin[0]['LastLogin'] != '0000-00-00 00:00:00' )
	exit(json_encode(array('ErrCode'=>0, 'ErrMessage'=>'已登入啟用之帳號無法被刪除，如人員已離職，請將權限設定為禁止登入。', 'RedirectURL'=>'')));
else if( (int)$arr_admin[0]['Level'] > $_SESSION['admin_level'] )
	exit(json_encode(array('ErrCode'=>0, 'ErrMessage'=>'權限不足', 'RedirectURL'=>'')));
else if( !$obj_class_admin->delete_admin($static_uint_admin_id) )
	exit(json_encode(array('ErrCode'=>0, 'ErrMessage'=>'帳號［' . $arr_admin[0]['Account'] . '］刪除失敗！', 'RedirectURL'=>'')));
else
	exit(json_encode(array('ErrCode'=>1, 'ErrMessage'=>'帳號［' . $arr_admin[0]['Account'] . '］已被刪除', 'RedirectURL'=>'')));
?>