{template header}
<script type="text/javascript">
// 设置RuleSet头像路径
<!--{if !empty($groomid) && $groomid > 0}-->
	<!--{eval $result = $db->query("SELECT gruleset FROM {$gtablepre}game WHERE groomid = {$groomid}");}-->
	<!--{if $db->num_rows($result)}-->
		<!--{eval $room_data = $db->fetch_array($result);}-->
		<!--{eval $ruleset_id = $room_data['gruleset'];}-->
		<!--{if !empty($ruleset_id)}-->
			<!--{eval include_once GAME_ROOT.'./gamedata/ruleset/ruleset_config.php';}-->
			<!--{eval $ruleset_config = get_ruleset_config($ruleset_id);}-->
			<!--{if $ruleset_config && isset($ruleset_config['avatar_config']) && $ruleset_config['avatar_config']['use_ruleset_avatars']}-->
				window.rulesetAvatarPath = '$ruleset_config[avatar_config][avatar_path]';
			<!--{/if}-->
		<!--{/if}-->
	<!--{/if}-->
<!--{/if}-->
</script>
<div class="subtitle" align="center">{lang user}</div>

<p align="center" class="linen">
	需要修改密码则输入原密码和新密码，留空为不修改。<br />
	注意：若玩家已进入游戏，对性别和头像的修改将在下一局生效。<br />
	<span id="notice"></span><br />
	<span id="info" class="yellow"></span>
</p>
<center>
<form method="post" action="user.php" name="userdata">
	<input type="hidden" name="mode" value="edit">
	<div>
		<div style="display:inline-block;">
			<span class ="yellow b">{lang basicdata}</span>
				{template userbasicdata}
		</div>
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
		<div style="display:inline-block;">
			<span class ="yellow b">{lang advanceddata}</span>
				{template useradvdata}
		</div>
	</div>


	<div id="postdata">
		<input type="submit" id="post" onClick="postCmd('userdata','user.php');return false;" value="{lang submit}">
		<input type="reset" id="reset" name="reset" value="{lang reset}">
	</div>
</form>
	<!--{if $show_sync_button && !$show_reverse_migrate_button}-->
	<div style="margin-top: 20px; padding: 15px; border: 2px solid #FFD700; background-color: #FFFACD; border-radius: 5px;">
		<div style="text-align: center; font-weight: bold; color: #B8860B; margin-bottom: 10px;">
			主从数据库同步功能
		</div>
		<form method="post" action="user.php" name="syncdata" id="syncform">
			<input type="hidden" name="mode" value="sync_master">
			<table align="center" style="border-collapse: collapse;">
				<tr>
					<td style="padding: 5px; text-align: right;">主服务器用户名：</td>
					<td style="padding: 5px;">
						<input type="text" name="master_username" id="master_username" size="20" placeholder="在{$master_server_name}的用户名">
					</td>
				</tr>
				<tr>
					<td style="padding: 5px; text-align: right;">主服务器密码：</td>
					<td style="padding: 5px;">
						<input type="password" name="master_password" id="master_password" size="20" placeholder="在{$master_server_name}的密码">
					</td>
				</tr>
				<tr>
					<td colspan="2" style="padding: 10px; text-align: center;">
						<input type="button" value="{$sync_button_text}" onclick="syncMasterData();" style="padding: 8px 15px; background-color: #FFD700; border: 1px solid #B8860B; border-radius: 3px; cursor: pointer;">
					</td>
				</tr>
			</table>
		</form>
		<!--{if $user_sync_status}-->
		<div style="margin-top: 10px; text-align: center; font-size: 12px; color: #666;">
			已绑定主服务器账户：{$user_sync_status['master_username']} (上次同步：{$user_sync_status['sync_time_formatted']})
		</div>
		<!--{/if}-->
		<div style="margin-top: 10px; text-align: center; font-size: 11px; color: #888;">
			注意：同步将覆盖当前账户的积分、成就、头衔等数据。每个主服务器账户只能绑定一个从服务器账户。
		</div>
	</div>

	<script type="text/javascript">
	function syncMasterData() {
		var username = document.getElementById('master_username').value;
		var password = document.getElementById('master_password').value;

		if(!username || !password) {
			alert('请输入主服务器的用户名和密码');
			return false;
		}

		if(!confirm('确定要从主服务器同步数据吗？这将覆盖当前账户的相关数据。')) {
			return false;
		}

		postCmd('syncform', 'user.php');
		return false;
	}
	</script>
	<!--{/if}-->

	<!--{if $show_reverse_migrate_button}-->
	<div style="margin-top: 20px; padding: 15px; border: 2px solid #FF6347; background-color: #FFF5EE; border-radius: 5px;">
		<div style="text-align: center; font-weight: bold; color: #CD5C5C; margin-bottom: 10px;">
			反向迁移功能 (推送到远端从服务器)
		</div>
		<div style="text-align: center; font-size: 12px; color: #8B4513; margin-bottom: 10px;">
			当前模式：反向迁移模式 | 目标服务器：{$master_server_name}
		</div>
		<form method="post" action="user.php" name="reversemigratedata" id="reversemigrateform">
			<input type="hidden" name="mode" value="reverse_migrate">
			<table align="center" style="border-collapse: collapse;">
				<tr>
					<td style="padding: 5px; text-align: right;">远端用户名：</td>
					<td style="padding: 5px;">
						<input type="text" name="remote_username" id="reverse_remote_username" size="20" placeholder="在{$master_server_name}的用户名">
					</td>
				</tr>
				<tr>
					<td style="padding: 5px; text-align: right;">远端密码：</td>
					<td style="padding: 5px;">
						<input type="password" name="remote_password" id="reverse_remote_password" size="20" placeholder="在{$master_server_name}的密码">
					</td>
				</tr>
				<tr>
					<td colspan="2" style="padding: 10px; text-align: center;">
						<input type="button" value="{$reverse_migrate_button_text}" onclick="reverseMigrateData();" style="padding: 8px 15px; background-color: #FF6347; color: white; border: 1px solid #CD5C5C; border-radius: 3px; cursor: pointer;">
					</td>
				</tr>
			</table>
		</form>
		<!--{if $user_reverse_migrate_status}-->
		<div style="margin-top: 10px; text-align: center; font-size: 12px; color: #666;">
			已推送到远端服务器：{$user_reverse_migrate_status['master_username']} (上次推送：{$user_reverse_migrate_status['sync_time_formatted']})
		</div>
		<!--{/if}-->
		<div style="margin-top: 10px; text-align: center; font-size: 11px; color: #888;">
			注意：反向迁移将把您的本地账户数据推送到远端从服务器 {$master_server_name}，需要在远端服务器有有效账户进行身份验证。本地数据不会受影响。
		</div>
	</div>

	<script type="text/javascript">
	function reverseMigrateData() {
		var username = document.getElementById('reverse_remote_username').value;
		var password = document.getElementById('reverse_remote_password').value;

		if(!username || !password) {
			alert('请输入远端从服务器的用户名和密码');
			return false;
		}

		if(!confirm('确定要将本地账户数据推送到远端从服务器吗？需要使用远端服务器的有效账户进行身份验证。本地数据不会受影响。')) {
			return false;
		}

		postCmd('reversemigrateform', 'user.php');
		return false;
	}
	</script>
	<!--{/if}-->
</center>
	<br />
{template footer}