<?
	require_once("user__check.php");

	// 已提交表单
	if($check=="ok"){	
		$which=floor($which);
		$flag=false;
		switch($which){
			case 1:
				if(md5($password)<>$user["password"]){
					show_msg("输入的密码错误！","-1");
				}
				else{
					$flag=true;
					$sql="update ".TBL_USER." set truename='$truename',im='$im',phone='$phone',site='$site',remark='$remark' where id=".$uid;	
				}
				break;
			case 2:
				if(md5($password)<>$user["password"]){
					show_msg("输入的原始密码错误！","-1");
				}
				if(strlen($password1)<6 or md5($password1)<>md5($password2)){
					show_msg("两次输入的密码不一致或者长度太短！","-1");
				}
				$flag=true;
				$sql="update ".TBL_USER." set password='".md5($password1)."' where id=".$uid;	
				break;
			case 3:
				if($user["question"]<>"" and md5($answer)<>md5($user["answer"])){
					show_msg("输入的问题答案错误！","-1");
				}
				else{
					$flag=true;
					$sql="update ".TBL_USER." set bank='".$pay_bank." ".$pay_name." ".$pay_code."' ".($user["question"]==""?",question='".$question."',answer='".$answer."'":"")." where id=".$uid;	
				}
				break;
			default:
				show_msg("未知操作！");
				break;
		}

		// 更新数据
		if($flag){
			mysql_query($sql);
			if(mysql_error()<>""){
				show_msg("数据库操作出错，请联系客服！");			
			}
			else{				
				show_msg("资料更新成功！","#");
			}
		}
	}

	// 未提交表单
	$user=mysql_fetch_array(mysql_query("select * from ".TBL_USER." where id=".$uid));
	list($pay_bank,$pay_name,$pay_code)=explode(" ",$user["bank"]);
?>

<fieldset>基本信息</fieldset>

<form method="post" onsubmit="return validate(this);">
<table cellspacing='0' cellpadding='3' border='0'>
	<tr>
		<td width="120" align="right">登录帐号：</td>
		<td><input type="text" name="truename" value="<?=$user["username"];?>" disabled></td>
	</tr>
	<tr>
		<td align="right">登录密码：</td>
		<td><input type="password" name="password" value=""></td>
	</tr>
	<tr>
		<td align="right">Email：</td>
		<td><input type="text" name="email" value="<?=$user["email"];?>" title="不可修改" disabled></td>
	</tr>
	<tr>
		<td align="right">QQ/MSN：</td>
		<td><input type="text" name="im" value="<?=$user["im"];?>"></td>
	</tr>
	<tr>
		<td align="right">TEL/Mobile：</td>
		<td><input type="text" name="phone" value="<?=$user["phone"];?>"></td>
	</tr>
	<tr>
		<td align="right">真实姓名：</td>
		<td><input type="text" name="truename" value="<?=$user["truename"];?>"></td>
	</tr>
	<tr>
		<td align="right">网站名称：</td>
		<td><input type="text" name="site" value="<?=$user["site"];?>"></td>
	</tr>
	<tr>
		<td align="right">网站地址：</td>
		<td><input type="text" name="domain" value="<?=$user["domain"];?>" title="不可修改" disabled></td>
	</tr>
	<tr>
		<td align="right">其他备注：</td>
		<td><input type="text" name="remark" value="<?=$user["remark"];?>" title="<?=$user["rate"];?>"></td>
	</tr>	
	<tr align="left">
		<td>
			<input type="hidden" name="which" value="1">
			<input type="hidden" name="check" value="ok">
		</td>
		<td>
			<button type="submit">保存</button>
			&nbsp;
			<button type="reset" >还原</button>
		</td>
	</tr>
</table>
</form>

<fieldset>密码信息</fieldset>

<form method="post" onsubmit="return validate(this);">
<table cellspacing='0' cellpadding='3' border='0'>
	<tr>
		<td width="120" align="right">登录帐号：</td>
		<td><input type="text" name="username" value="<?=$user["username"];?>" disabled></td>
	</tr>
	<tr>
		<td align="right">帐号原密码：</td>
		<td><input type="password" name="password" value=""></td>
	</tr>
	<tr>
		<td align="right">帐号新密码：</td>
		<td><input type="password" name="password1" value=""></td>
	</tr>
	<tr>
		<td align="right">重复新密码：</td>
		<td><input type="password" name="password2" value=""></td>
	</tr>
	<tr align="left">
		<td>
			<input type="hidden" name="which" value="2">
			<input type="hidden" name="check" value="ok">
		</td>
		<td>
			<button type="submit">保存</button>
			&nbsp;
			<button type="reset" >还原</button>
		</td>
	</tr>
</table>
</form>

<fieldset>银行帐户信息（可选）</fieldset>

<form method="post" onsubmit="return validate(this);">
<table cellspacing='0' cellpadding='3' border='0'>
	<tr>
		<td width="120" align="right">登录帐号：</td>
		<td><input type="text" name="username" value="<?=$user["username"];?>" disabled></td>
	</tr>
	<tr>
		<td align="right">开户银行：</td>
		<td><input type="text" name="pay_bank" value="中国工商银行" readonly></td>
	</tr>
	<tr>
		<td align="right">收款人姓名：</td>
		<td><input type="text" name="pay_name" value="<?=$pay_name;?>"></td>
	</tr>
	<tr>
		<td align="right">收款人帐号：</td>
		<td><input type="text" name="pay_code" value="<?=$pay_code;?>"></td>
	</tr>
	<tr>
		<td align="right">提示问题：</td>
		<td><input type="text" name="question" value="<?=$user["question"];?>" <?=$user["question"]==""?"":"disabled";?>></td>
	</tr>
	<tr>
		<td align="right">问题答案：</td>
		<td><input type="text" name="answer" value="" style="ime-mode:disabled;"></td>
	</tr>
	<tr align="left">
		<td>
			<input type="hidden" name="which" value="3">
			<input type="hidden" name="check" value="ok">
		</td>
		<td>
			<button type="submit">保存</button>
			&nbsp;
			<button type="reset" >还原</button>
		</td>
	</tr>
</table>
</form>

<script language="javascript">
function validate(obj)
{
	flag=true;
	frm=document.forms;
	if(frm[0]==obj && frm[0].password.value.length<6)
	{
		flag=false;
		show_tip("请输入正确的登录密码");
	}
	if(frm[1]==obj)
	{
		if(frm[1].password.value.length<6 || frm[1].password1.value.length<6)
		{		
			flag=false;
			show_tip("输入密码的长度不符合要求");
		}
		if(frm[1].password1.value!=frm[1].password2.value)
		{		
			flag=false;
			show_tip("两次输入的新密码不一致");
		}
	}
	if(frm[2]==obj && frm[2].answer.value.length<1)
	{
		flag=false;
		show_tip("请输入提示问题的答案");
	}	
	return flag;
}
</script>