<?php
session_start();

include('includes/ajax_check_login.php');

if( !isset($_POST['old_password']) || !isset($_POST['new_password']) || !isset($_POST['new_password2']) || ( $static_str_old_password = trim($_POST['old_password']) ) == '' || ( $static_str_new_password = trim($_POST['new_password']) ) == '' || ( $static_str_new_password2 = trim($_POST['new_password2']) ) == '' )
	exit(json_encode(array('ErrCode'=>-1, 'ErrMessage'=>'輸入資料不足', 'RedirectURL'=>'')));
else if( $static_str_new_password != $static_str_new_password2 )
	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( !$obj_class_admin->modify_password($static_str_old_password, $static_str_new_password) )
	exit(json_encode(array('ErrCode'=>0, 'ErrMessage'=>'密碼變更失敗', 'RedirectURL'=>'')));
else
{
	unset($_SESSION['admin_id']);
	unset($_SESSION['admin_account']);
	unset($_SESSION['admin_level']);
	
	exit(json_encode(array('ErrCode'=>1, 'ErrMessage'=>'密碼變更成功，請重新登入', 'RedirectURL'=>'login.php')));
}
?>
