<?php
session_start();

if( isset($_SESSION['init_info']) )
{
	if( ( $str_temp = trim($_SESSION['init_info']) ) != '' )
		$str_init_info = $str_temp;

	unset($_SESSION['init_info']);
}

include('includes/check_level.php');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="utf-8" lang="utf-8">
<head>
	<meta http-equiv="content-type" content="text/html; charset=utf-8" />
	<meta http-equiv="content-language" content="zh-tw" />
	<meta name="robots" content="none" />
	<link rel="stylesheet" type="text/css" href="author.css" />
	<title>變更密碼</title>
	<script type="text/javascript" src="scripts/jquery.js"></script>
	<script type="text/javascript">
<!--
var global_bool_processing = false;

function do_modify_password(element_form)
{
	if( element_form.old_password.value == '' )
	{
		alert('請輸入舊密碼');
		return false;
	}

	if( element_form.new_password.value == '' )
	{
		alert('請輸入新密碼');
		return false;
	}

	if( element_form.new_password2.value == '' )
	{
		alert('請重輸新密碼');
		return false;
	}

	if( element_form.new_password.value.length < 6 || element_form.new_password.value.length > 12 )
	{
		alert('設定之新密碼必須為6至12個字元，請重新輸入');
		return false;
	}

	if( element_form.old_password.value == element_form.new_password.value )
	{
		alert('設定之新密碼與舊密碼相同，請檢查之後重新輸入');
		return false;
	}

	if( element_form.new_password.value != element_form.new_password2.value )
	{
		alert('設定之新密碼與重輸之新密碼不同，請重新輸入');
		return false;
	}

	var obj_form_data = new FormData(element_form);

	global_bool_processing = true;

	$.ajax(
	{
		url: 'ajax_do_modify_password.php',
		type: 'POST',
		data: obj_form_data,
		cache: false,
		processData: false,
		contentType: false,
		dataType: 'json',
		success: function(jdata)
		{
			if( jdata['ErrMessage'] != '' )
				alert(jdata['ErrMessage']);
			else if( jdata['ErrCode'] != '1' )
				alert('Error:' + jdata['ErrCode']);

			if( jdata['RedirectURL'] )
				location.replace(jdata['RedirectURL']);

			global_bool_processing = false;
		}
	});

	return false;
}
//-->
	</script>
</head>

<body<?=( isset($str_init_info) ? ' onLoad="javascript:alert(\'' . $str_init_info . '\');"' : '' )?>>
<? include('_title.php'); ?>
<? include('_menu.php'); ?>
<div id="content">
<h2>變更密碼：<?=$_SESSION['author_account']?></h2>
<form onsubmit="return do_modify_password(this);">
<fieldset class="data">
<legend>變更密碼</legend>
<div class="field"><span class="subject">請輸入舊密碼</span><input class="content" type="password" name="old_password" size="12" maxlength="12" /></div>
<div class="field"><span class="subject">請設定新密碼</span><input class="content" type="password" name="new_password" size="12" maxlength="12" /></div>
<div class="field"><span class="subject">請重輸新密碼</span><input class="content" type="password" name="new_password2" size="12" maxlength="12" /></div>
</fieldset>
<div class="buttons"><input class="submit" type="submit" value="確定變更" /></div>
</form>
</div>
<? include('_footer.php'); ?>
</body>

</html>