<?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_email_calendar'] = my_htmlspecialchars($rec_account['c_email_calendar']);
		$_SESSION['edit_myprofile_album_folder'] = my_htmlspecialchars($rec_account['c_album_folder']);
		$_SESSION['edit_myprofile_body_background_color'] = my_htmlspecialchars($rec_account['c_body_background_color']);
		$_SESSION['edit_myprofile_msg'] = my_htmlspecialchars($rec_account['c_msg']);
		$_SESSION['edit_myprofile_fullname'] = my_htmlspecialchars($rec_account['c_fullname']);
		$_SESSION['edit_myprofile_zip1'] = my_htmlspecialchars($rec_account['c_zip1']);
		$_SESSION['edit_myprofile_zip2'] = my_htmlspecialchars($rec_account['c_zip2']);
		$_SESSION['edit_myprofile_home_address'] = my_htmlspecialchars($rec_account['c_home_address']);
		$_SESSION['edit_myprofile_home_address2'] = my_htmlspecialchars($rec_account['c_home_address2']);
		$_SESSION['edit_myprofile_cal_sbj_use'] = my_htmlspecialchars($rec_account['c_cal_sbj_use']);
	}
?>
<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>ハンドル名：<br>（全角10文字以下）</td>
	<td nowrap>
	<p><span style='color: #8080ff;'><?= my_htmlspecialchars($rec_account['c_handle']) ?></span></p>
	<input class="text" type="text" name="handle" value="<?= my_htmlspecialchars($_SESSION['edit_myprofile_handle']) ?>" size=20 onChange="HandleCheckOnChange()" style="ime-mode: active;">
	<button onclick="handleCheck();return false;">チェック</button>
	<span id="handleErrMsg" class="alarm_text"></span>
	</td>
</tr>
<tr>
	<td nowrap>電子メールアドレス：<br>（パスワード忘れ用）</td>
	<td nowrap>
	<p><span style='color: #8080ff;'><?= my_htmlspecialchars($rec_account['c_email']) ?></span></p>
	<input class="text" type="text" name="email" size=50 value="<?= my_htmlspecialchars($_SESSION['edit_myprofile_email']) ?>" style="ime-mode: disabled;">
	</td>
</tr>
<tr>
	<td nowrap>電子メールアドレス：<br>（スケジュール送信先）</td>
	<td nowrap>
	<p><span style='color: #8080ff;'><?= my_htmlspecialchars($rec_account['c_email_calendar']) ?></span></p>
	<input class="text" type="text" name="email_calendar" size=50 value="<?= my_htmlspecialchars($_SESSION['edit_myprofile_email_calendar']) ?>" style="ime-mode: disabled;">
	</td>
</tr>
<tr valign="top">
	<td nowrap>コメント：<br>（100文字以下）</td>
	<td nowrap>
<script language="JavaScript">
<!--
function textareaBigSmall(obj, bigSmall)
{
	if (bigSmall == "大") {
		document.form0.elements[obj].rows = document.form0.elements[obj].rows + 5;
	} else {
		if (document.form0.elements[obj].rows > 5) {
			document.form0.elements[obj].rows = document.form0.elements[obj].rows - 5;
		}
	}
}
-->
</script>
	<p><span style='color: #8080ff;'><?= ins_br(my_htmlspecialchars($rec_account['c_msg'])) ?></span></p>
	<div class="block_left">
	<textarea name="msg" style="width:400px;" rows=5 wrap="soft"><?= my_htmlspecialchars($_SESSION['edit_myprofile_msg']) ?></textarea>
	<span id="msgErrMsg" class="alarm_text"></span>
	</div>
	<div class="block_left">
	<input type="button" value="小" OnClick="textareaBigSmall('msg','小')"><br>
	<input type="button" value="大" OnClick="textareaBigSmall('msg','大')">
	</div>
	</td>
</tr>
<tr>
	<td nowrap>アルバムフォルダ：</td>
	<td nowrap>
<?php
	$photo_folder = '';
	if (defined("photo_LIMITED_IMAGES_FOLDER") and photo_LIMITED_IMAGES_FOLDER <> '') {
		$photo_folder = photo_LIMITED_IMAGES_FOLDER.'/';
	}
?>
	<p><span style='color: #8080ff;'><?= $photo_folder ?><?= my_htmlspecialchars($rec_account['c_album_folder']) ?></span></p>
	<?= $photo_folder ?><input class="text" type="text" name="album_folder" size=60 value="<?= my_htmlspecialchars($_SESSION['edit_myprofile_album_folder']) ?>" style="ime-mode: inactive;">
	<? if ($photo_folder = '') { ?>
	<p><span style='color: #00a000;'>ex: D:\xampp\htdocs\_myhome\z_photo_sample</span></p>
	<p><span style='color: #00a000;'>ex: DOCUMENT_ROOT/_myhome/z_photo_sample</span></p>
	<? } ?>
	</td>
</tr>
<tr>
	<td nowrap>ページ背景色：</td>
	<td nowrap>
	<p><span style='color: #8080ff;'><?= my_htmlspecialchars($rec_account['c_body_background_color']) ?></span></p>
	<input class="text" type="text" name="body_background_color" size=10 value="<?= my_htmlspecialchars($_SESSION['edit_myprofile_body_background_color']) ?>" style="ime-mode: inactive;">&nbsp;&nbsp;<span style='color: #00a000;'>(ex.#F0F0FF)</span>&nbsp;&nbsp;
	<a href="../__common__/color-chart.php" target="_blank">カラーチャート</a>
	</td>
</tr>
<tr valign="top">
	<td nowrap>氏名（フルネーム）：</td>
	<td nowrap>
	<p><span style='color: #8080ff;'><?= my_htmlspecialchars($rec_account['c_fullname']) ?></span></p>
	<input class="text" type="text" name="fullname" value="<?= my_htmlspecialchars($_SESSION['edit_myprofile_fullname']) ?>" size=60 style="ime-mode: active;">
	</td>
</tr>
<tr valign="top">
	<td nowrap>〒番号：</td>
	<td nowrap>
	<p><span style='color: #8080ff;'><?= my_htmlspecialchars($rec_account['c_zip1']) ?>-<?= my_htmlspecialchars($rec_account['c_zip2']) ?></span></p>
	<input class="text" type="text" name="zip1" value="<?= my_htmlspecialchars($_SESSION['edit_myprofile_zip1']) ?>" size=5 style="ime-mode: disabled;">-
	<input class="text" type="text" name="zip2" value="<?= my_htmlspecialchars($_SESSION['edit_myprofile_zip2']) ?>" size=10 style="ime-mode: disabled;">
	</td>
</tr>
<tr valign="top">
	<td nowrap>住所（Google<br>経路検索起点）：</td>
	<td nowrap>
	<p><span style='color: #8080ff;'><?= my_htmlspecialchars($rec_account['c_home_address']) ?></span></p>
	<input class="text" type="text" name="home_address" value="<?= my_htmlspecialchars($_SESSION['edit_myprofile_home_address']) ?>" size=60 style="ime-mode: active;">
	</td>
</tr>
<tr valign="top">
	<td nowrap>住所2（マンション名など）：<br>（住所録葉書差出人用）</td>
	<td nowrap>
	<p><span style='color: #8080ff;'><?= my_htmlspecialchars($rec_account['c_home_address2']) ?></span></p>
	<input class="text" type="text" name="home_address2" value="<?= my_htmlspecialchars($_SESSION['edit_myprofile_home_address2']) ?>" size=60 style="ime-mode: active;">
	</td>
</tr>
<tr valign="top">
	<td nowrap>カレンダー：</td>
	<td nowrap>
	<input type="checkbox" name="cal_sbj_use" value="NO"<?php if ($_SESSION['edit_myprofile_cal_sbj_use'] == 'NO') echo ' checked' ?>>件名を使わない（スケジュール本文のみを使う）
	</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() {
	$handle = form_str_adjust_strip_tags($_POST['handle']);
	$email = form_str_adjust_strip_tags($_POST['email']);
	$email_calendar = form_str_adjust_strip_tags($_POST['email_calendar']);
	$album_folder = form_str_adjust_strip_tags($_POST['album_folder']);
	$body_background_color = form_str_adjust_strip_tags($_POST['body_background_color']);
	$msg = form_str_adjust_strip_tags($_POST['msg']);
	$fullname = form_str_adjust_strip_tags($_POST['fullname']);
	$zip1 = form_str_adjust_strip_tags($_POST['zip1']);
	$zip2 = form_str_adjust_strip_tags($_POST['zip2']);
	$home_address = form_str_adjust_strip_tags($_POST['home_address']);
	$home_address2 = form_str_adjust_strip_tags($_POST['home_address2']);
	$cal_sbj_use = $_POST['cal_sbj_use'];

	$_SESSION['edit_myprofile_handle'] = $handle;
	$_SESSION['edit_myprofile_email'] = $email;
	$_SESSION['edit_myprofile_email_calendar'] = $email_calendar;
	$_SESSION['edit_myprofile_album_folder'] = $album_folder;
	$_SESSION['edit_myprofile_body_background_color'] = $body_background_color;
	$_SESSION['edit_myprofile_msg'] = $msg;
	$_SESSION['edit_myprofile_fullname'] = $fullname;
	$_SESSION['edit_myprofile_zip1'] = $zip1;
	$_SESSION['edit_myprofile_zip2'] = $zip2;
	$_SESSION['edit_myprofile_home_address'] = $home_address;
	$_SESSION['edit_myprofile_home_address2'] = $home_address2;
	$_SESSION['edit_myprofile_cal_sbj_use'] = $cal_sbj_use;

	if (($ret = ac_chk_handle($handle, $_SESSION['login_id'])) <> "") return ($ret);
	if (($ret = ac_chk_email($email)) <> "") return ($ret);
	if (($ret = ac_chk_email($email_calendar)) <> "") return ($ret);
	if (($ret = ac_chk_msg($msg)) <> "") return ($ret);

	$con = my_mysql_connect(_DB_ACCOUNT_SCHEMA);
	$sql = "update m_account";
	$sql .= " set c_handle = '". str_for_mysql($handle) . "'";
	$sql .= ", c_email = '". trim(str_for_mysql($email)) . "'";
	$sql .= ", c_email_calendar = '". trim(str_for_mysql($email_calendar)) . "'";
	$sql .= ", c_album_folder = '". trim(str_for_mysql($album_folder)) . "'";
	$sql .= ", c_body_background_color = '". trim(str_for_mysql($body_background_color)) . "'";
	$sql .= ", c_msg = '". str_for_mysql($msg) . "'";
	$sql .= ", c_fullname = '". trim(str_for_mysql($fullname)) . "'";
	$sql .= ", c_zip1 = '". trim(str_for_mysql($zip1)) . "'";
	$sql .= ", c_zip2 = '". trim(str_for_mysql($zip2)) . "'";
	$sql .= ", c_home_address = '". trim(str_for_mysql($home_address)) . "'";
	$sql .= ", c_home_address2 = '". trim(str_for_mysql($home_address2)) . "'";
	$sql .= ", c_cal_sbj_use = '". trim(str_for_mysql($cal_sbj_use)) . "'";
	$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);

	$_SESSION['login_handle'] = $handle;

	$_SESSION['login_friends_handle_'.$_SESSION['login_id']] = $handle;
	$_SESSION['login_friends_album_folder_'.$_SESSION['login_id']] = get_album_folder($album_folder);
	$_SESSION['login_friends_body_background_color_'.$_SESSION['login_id']] = $body_background_color;
	$_SESSION['login_friends_home_address_'.$_SESSION['login_id']] = $home_address;
	$_SESSION['login_friends_cal_sbj_use_'.$_SESSION['login_id']] = $cal_sbj_use;

	redirect("myprofile.php");
}
?>
