<?php
	require("__include-common.php");
	require("__include-login.php");
	require("__include-account-check.php");
	$error_msg = "";
	if ($_POST) {
		check_post_account($_POST['login_id']);
		$error_msg = post_done_proc();
	}
	html_header(HTML_TITLE, "_add_newaccount_header.php");
	page_header(False);
	input_form($error_msg);
	page_footer();
	html_footer();
	exit();
?>
<?php
function input_form($error_msg) {
	$con = my_mysql_connect(_DB_ACCOUNT_SCHEMA);
	$sql = "SELECT * FROM m_account WHERE id_account = '" . $_SESSION['login_id'] . "'";
	$rs_account = my_mysql_query($sql);
	$row = mysql_num_rows($rs_account);
	if ($row == 0) {
		error_exit("アカウントがみつかりません", True);
	}
	$rec_account = mysql_fetch_array($rs_account);
	if (!$_POST) {
		$_SESSION['edit_myprofile_handle'] = my_htmlspecialchars($rec_account['c_handle']);
		$_SESSION['edit_myprofile_email'] = my_htmlspecialchars($rec_account['c_email']);
		$_SESSION['edit_myprofile_msg'] = my_htmlspecialchars($rec_account['c_msg']);
	}
?>
<div class="input_form">
<h3>パスワード修正<a class="a_cancel_back" href="myprofile.php">[キャンセル]</a></h3>
<form name="form0" method="POST" action="<?= $_SERVER['SCRIPT_NAME'] ?>">
	<input type="hidden" name="login_id" value="<?= $_SESSION['login_id'] ?>">
	<input type="hidden" name="current_id" value="<?= $_SESSION['current_id'] ?>">
<table>
<tr>
	<td nowrap>アカウント名：</td>
	<td nowrap><?= my_htmlspecialchars($rec_account['c_account']) ?></td>
</tr>
<tr valign="top">
	<td nowrap>パスワード(英数記号/5～30文字)：</td>
	<td nowrap>
	<input class="password" type="password" name="password" size=30 onChange="PasswordCheckOnChange()">
	<span id="passwordErrMsg" class="alarm_text"></span>
	</td>
</tr>
<tr valign="top">
	<td nowrap>パスワード(再入力)：</td>
	<td nowrap>
	<input class="password" type="password" name="password2" size=30 onChange="Password2CheckOnChange()">
	<span id="password2ErrMsg" class="alarm_text"></span>
	</td>
</tr>
</table>
	<input class="input_form_button" type="submit" name="修正" value="修正">
	<input class="input_form_button" type="reset" name="リセット" value="リセット">
</form>
	<p class="error_msg"><?= $error_msg ?><p>
</div>
<?php
	return(0);
}
?>
<?php
function post_done_proc() {
	$password = $_POST['password'];
	if (($ret = ac_chk_password($password, $_POST['password2'])) <> "") return ($ret);

	$con = my_mysql_connect(_DB_ACCOUNT_SCHEMA);
	$sql = "update m_account";
	$sql .= " set c_password = '". str_for_mysql($password) . "'";
	$sql .= ", c_updatetime = '". date("Y/m/d H:i:s") . "'";
	$sql .= " where id_account = '" . $_SESSION['login_id'] . "'";
	$ret = my_mysql_query($sql);
	if (!$ret) {
		$con = mysql_close($con);
		return "パスワード修正に失敗しました。";
	}
	$con = mysql_close($con);

	setcookie("login_account_okuser_pass", $password, time() + LOGIN_COOKIE_EXPIRE, "/");
	redirect("myprofile.php");
}
?>
