<?php
session_start();

include('includes/ajax_check_login.php');

if( !isset($_POST['author_name']) 
|| !isset($_POST['author_account']) 
|| !isset($_POST['password']) 
|| !isset($_POST['password2']) 
|| !isset($_POST['author_level']) 
|| ( $static_str_author_name = trim($_POST['author_name']) ) == '' 
|| ( $static_str_author_account = trim($_POST['author_account']) ) == '' 
|| ( $static_str_password = trim($_POST['password']) ) == '' 
|| ( $static_str_password2 = trim($_POST['password2']) ) == '' )
	exit(json_encode(array('ErrCode'=>-1, 'ErrMessage'=>'輸入資料不足', 'RedirectURL'=>'')));
else
	$static_int_author_level = (int)$_POST['author_level'];

if( $static_str_password != $static_str_password2 )
	exit(json_encode(array('ErrCode'=>-1, 'ErrMessage'=>'設定密碼與重輸密碼不同，請重新輸入', 'RedirectURL'=>'')));

require_once('includes/common.php');

if( !isset($arr_author_level[$static_int_author_level]) )
	exit(json_encode(array('ErrCode'=>-1, 'ErrMessage'=>'輸入資料不正確', 'RedirectURL'=>'')));

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

if( !$obj_class_admin->add_author($static_str_author_name, $static_str_author_account, $static_str_password, $static_int_author_level) )
	exit(json_encode(array('ErrCode'=>0, 'ErrMessage'=>'新增作者帳號失敗！', 'RedirectURL'=>'')));
else
	exit(json_encode(array('ErrCode'=>1, 'ErrMessage'=>'新增作者帳號成功', 'RedirectURL'=>'manage_authors.php')));
?>