<?php
session_start();
require_once("../common/init.php");
require_once("security.inc.php");

$OldPassword = $_POST['OldPassword'];
$Password = $_POST['Password'];
$Password_C = $_POST['Password_C'];

//更新用户密码
if($Password != ""){
	$sql="select * from users where UserName='$_SESSION[User_S]'";
	$rs=$db->query($sql);
	$UInfo=$db->fetch_array($rs);
	$Password=trim($Password);
	if($Password!=""){
	   if($UInfo[Password]!=md5($OldPassword)){
		  $message = "<font color='red'>旧密码错误!</font>";
	   }else{
		  $sql="update users set Password='".md5($Password)."' where UserName='$_SESSION[User_S]'";
		  $db->query($sql);
		  $message = "<font color='green'>密码修改成功，请记好新密码！</font>";
	   }
	}else{
	   $message = "<font color='red'>密码不能为空或含有空格</font>";
	}
}
// end of 更新用户密码
$UserSurplus = GetSurplus($_SESSION['User_S']);
if($UserSurplus>=0) $UserSurplusD = $UserSurplus;
else $UserSurplusD = "欠费".abs($UserSurplus);
$UserLevel = $_SESSION['iLevel_S']>0?$_SESSION['iLevel_S'].'级会员':'普通会员';
$smarty->assign("CurUser",$_SESSION['User_S']);
$smarty->assign("UserLevel",$UserLevel);
$smarty->assign("UserSurplus",$UserSurplusD);
$smarty->assign("message",$message);
$smarty->display('user_password.html');
$db->close();
?>