<?php
class userupdateAction extends security_normal {
	function action(){
		global $conn;

		$miceSession = new session();
		if(!$miceSession->get('mu__userid')){
			$jsstring='Dialog.alert(\'您尚未登录\',function(){window.location.href="'.MICE_URL.'";window.event.returnValue = false;},300,100,"提示信息");';
			MessageBox($jsstring);
			exit;
		}

		$user=new model_User();
		$user->setSubsection('WHERE user_id='.$miceSession->get('mu__userid'));
		$results=$user->doSelectOne();

		$password1=$_POST['pwd1'];
		$password2=$_POST['pwd2'];
		$pwd='';
		$info='';
		if($password1==$password2 and strlen($password1)>4)
		{
			$salt = md5(rand(100000, 999999).$results->getLoginname());
			$pwd=sha1($salt.$password1);
			$info.='密码修改成功，';
		}
		$realname=$_POST['realname'];
		$explam=$_POST['explam'];
		$url=$_POST['url'];
		$email=strtolower($_POST['email']);
		$address=$_POST['address'];
		$sex=$_POST['sex'];
		$im=$_POST['im'];
		$telno=$_POST['telno'];

		if($results)
		{
			if(strlen($pwd)>0){
				$user->setSalt($salt);
				$user->setPassword($pwd);
			}
			$user->setRealname($realname);
			$user->setExplam($explam);
			$user->setUrl($url);
			$user->setEmail($email);
			$user->setAddress($address);
			$user->setSex($sex);
			$user->setIm($im);
			$user->setTelno($telno);
			$results=$user->doUpdate();

			if($results)
				$exeresult='更新成功';
			else
				$exeresult='更新失败';
			$info.='用户资料修改成功';
		}

		$jsstring='Dialog.alert(\''.$exeresult.'\',function(){window.location.href="'.MICE_URL.'index.php/user";window.event.returnValue = false;},300,100,"'.$info.'");';
		MessageBox($jsstring);
		exit;
	}
}
?>