<?php
/**
 *	Generated by miceCMS
 *	http://www.miceCMS.com/
 */
class user_updateAction extends security_login {
	function action(){
		ModuleLimit(__CLASS__);
		global $conn;

		

		$miceSession = new session();
		$user_id=$miceSession->get('userid');
		if($user_id){
			$user=new model_User();
			$user->setSubsection('WHERE user_id='.$user_id);
			$results=$user->doSelectOne();
		}else{
			$user_id=0;
		}

		$loginname=strtolower($_POST['loginname']);
		$password1=$_POST['pw1'];
		$password2=$_POST['pw2'];
		$pwd='';
		if($password1==$password2 and strlen($password1)>0 and strlen($loginname)>0)
		{
			$salt = md5(rand(100000, 999999).$loginname);
			$pwd=sha1($salt.$password1);
		}
		$realname=$_POST['realname'];
		$explam=$_POST['explam'];
		$url=$_POST['url'];
		$email=strtolower($_POST['email']);
		$userusergroup_id=$_POST['usergroup_id'];
		$status=$_POST['status'];
		$nicename=$_POST['nicename'];
		$address=$_POST['address'];
		$headimg=$_POST['headimg'];
		$brothday=$_POST['brothday'];
		$sex=$_POST['sex'];
		$im=$_POST['im'];
		$telno=$_POST['telno'];
		$stopdate=0;
		if($_POST['stopdate']>0)	$stopdate=Time2Num($_POST['stopdate']);
		$pointnum=$_POST['pointnum'];

		if($loginname==""){
			$jsstring='Dialog.alert("登录名不能为空",function(){history.back(-1);});';
			MessageBox($jsstring);
			exit;
		}

		//判断用户名是否被占用
		$user2=new model_User();
		$user2->setSubsection('WHERE loginname=\''.$loginname.'\' and user_id<>'.$user_id);
		$results2=$user2->doSelectOne();

		if($results2){
			$jsstring='Dialog.alert("登录名已经被占用",function(){history.back(-1);});';
			MessageBox($jsstring);
			exit;
		}

		if($results)
		{
			$ins='内容已存在';
			$uid=$results->getUserId();
			$user->setLoginname($loginname);
			if(strlen($pwd)>0){
				$user->setSalt($salt);
				$user->setPassword($pwd);
			}
			$user->setRealname($realname);
			$user->setExplam($explam);
			$user->setUrl($url);
			$user->setEmail($email);
			$user->setUsergroupId($userusergroup_id);
			$user->setStatus($status);
			$user->setNicename($nicename);
			$user->setAddress($address);
			$user->setHeadimg($headimg);
			$user->setBrothday($brothday);
			$user->setSex($sex);
			$user->setIm($im);
			$user->setTelno($telno);
			$user->setStopdate($stopdate);
			$user->setPointnum($pointnum);
			$results=$user->doUpdate();
			if($results)
				$exeresult='更新成功';
			else
				$exeresult='更新失败';

		}else{
			$ins='内容已不存在';
			$user=new model_User();
			$user->setLoginname($loginname);
			if(strlen($pwd)>0){
				$user->setSalt($salt);
				$user->setPassword($pwd);
			}
			$user->setRealname($realname);
			$user->setExplam($explam);
			$user->setUrl($url);
			$user->setEmail($email);
			$user->setUsergroupId($userusergroup_id);
			$user->setStatus($status);
			$user->setNicename($nicename);
			$user->setAddress($address);
			$user->setHeadimg($headimg);
			$user->setBrothday($brothday);
			$user->setSex($sex);
			$user->setIm($im);
			$user->setTelno($telno);
			$user->setRegdate(time());
			$user->setStopdate($stopdate);
			$user->setPointnum($pointnum);
			$results=$user->doInsert();
			if($results){
				$exeresult='插入成功';
				$uid=$conn->Insert_ID();
			}else
				$exeresult='插入失败';
		}

		if($_POST['goon']==1){
			$jsstring='Dialog.alert(\''.$exeresult.'\',function(){window.location.href="'.MICE_URL.'admin.php/user/edit";window.event.returnValue = false;},300,100,"继续添加会员");';
			MessageBox($jsstring);
		}else{
			$jsstring='Dialog.alert(\''.$exeresult.'\',function(){window.location.href="'.MICE_URL.'admin.php/user";window.event.returnValue = false;},300,100,"返回会员列表");';
			MessageBox($jsstring);
		}
		exit;
	}
}
?>