<?php
//表前缀
if(!defined('InEmpireCMS'))
{$user_tbpre="phome_";}
else
{$user_tbpre=$dbtbpre;}

//----------------------下面开始会员相关设置----------------------

$user_tablename=$user_tbpre."enewsmember";                //用户表
$user_userid="userid";                                    //用户ID字段
$user_username="username";                                //用户名字段
$user_password="password";                                //密码字段
$user_dopass=0;                                           //密码保存形式,0为md5,1为明码,2为双重加密,3为16位md5
$user_rnd="rnd";                                          //随机密码
$user_email="email";                                      //邮箱字段
$user_registertime="registertime";                        //注册时间字段
$user_regcookietime=0;									  //注册信息保存时间(秒)
$user_register=0;                                         //注册时间保存形式,0为正常时间,1为数值型
$user_group="groupid";                                    //会员组字段
$user_userfen="userfen";                                  //点数字段
$user_userdate="userdate";                                //包月字段
$user_zgroup="zgroupid";								  //到期转向会员组
$user_money="money";                                      //帐户余额
$user_todaydate="todaydate";                              //下载日期
$user_todaydown="todaydown";                              //当天下载次数
$user_havemsg="havemsg";                                  //当天下载次数
$user_groupid=$public_r[defaultgroupid];                  //注册时会员组ID(ecms的会员组)

//会员页面
$registerurl="";										  //注册地址
$eloginurl="";											  //登陆地址
$equiturl="";											  //退出地址

//特殊设置(如vbb,molyx)
$user_salt="salt";                                        //salt
$user_saltnum=3;                                          //salt随机码字符数

$utfdata=0;    //数据是否是UTF8编码,0为正常数据,1为UTF8编码

//----------------------会员相关设置结束----------------------

//编码转换
function doUtfAndGbk($str,$phome=0){
	global $utfdata;
	//正常编码
	if(empty($utfdata))
	{
		return $str;
    }
	//是否支持iconv
	if(!function_exists("iconv"))
	{
		$fun="DoIconvVal";
		$code="GB2312";
		$targetcode="UTF8";
	}
	else
	{
		$fun="iconv";
		$code="GBK";
		$targetcode="UTF-8";
	}
	if(empty($phome))//gbk转utf
	{
		$str=$fun($code,$targetcode,$str);
	}
	else//utf转gbk
	{
		$str=$fun($targetcode,$code,$str);
	}
	return $str;
}

//-----------------------登录附加cookie
function AddLoginCookie($r){
}

//-----------------------后台修改资料
function admin_EditMember($add,$logininid,$loginin){
	global $empire,$user_tablename,$user_username,$user_userid,$user_password,$user_dopass,$user_group,$user_email,$user_userfen,$user_money,$user_userdate,$user_saltnum,$user_salt,$user_zgroup,$dbtbpre;
	if(!trim($add[userid])||!trim($add[email])||!trim($add[username])||!$add[groupid])
	{printerror("EmptyEmail","history.go(-1)");}
    //验证权限
    CheckLevel($logininid,$loginin,$classid,"member");
	//变量
	$add[userid]=(int)$add[userid];
	//编码转换
	$dousername=$add[username];
	$add[username]=doUtfAndGbk($add[username],0);
	$add[oldusername]=doUtfAndGbk($add[oldusername],0);
	$add[password]=doUtfAndGbk($add[password],0);
	$add[email]=doUtfAndGbk($add[email],0);
	//修改密码
	if($add[password])
	{
		if(empty($user_dopass))//单重md5
		{
		   $add[password]=md5($add[password]);
	    }
		elseif($user_dopass==2)//双重md5
		{
			$salt=make_password($user_saltnum);
			$add[password]=md5(md5($add[password]).$salt);
			$sa=",".$user_salt."='$salt'";
		}
		elseif($user_dopass==3)//16位md5
		{
			$add[password]=substr(md5($add[password]),8,16);
		}
		else
		{}
		$add1=",".$user_password."='".$add[password]."'".$sa;
    }
	//修改用户名
	if($add[oldusername]<>$add[username])
	{
		$num=$empire->gettotal("select count(*) as total from ".$user_tablename." where ".$user_username."='$add[username]' and ".$user_userid."<>".$add[userid]." limit 1");
		$add1.=",".$user_username."='$add[username]'";
		if($num)
		{
			printerror("ReUsername","history.go(-1)");
		}
	}
	//包月
	$add[zgroupid]=(int)$add[zgroupid];
	if($add[userdate]>0)
	{
		$userdate=time()+$add[userdate]*24*3600;
	}
	else
	{
		$add[zgroupid]=0;
	}
	//变量
	$add[groupid]=(int)$add[groupid];
	$add[userfen]=(int)$add[userfen];
	$userdate=(int)$userdate;
	$add[money]=(float)$add[money];
	$sql=$empire->query("update ".$user_tablename." set ".$user_email."='$add[email]',".$user_group."=$add[groupid],".$user_userfen."=$add[userfen],".$user_money."=$add[money],".$user_userdate."=$userdate,".$user_zgroup."=$add[zgroupid]".$add1." where ".$user_userid."='$add[userid]'");
	//附加表
	$addnum=$empire->gettotal("select count(*) as total from {$dbtbpre}enewsmemberadd where userid='$add[userid]'");
	if(empty($addnum))
	{
	   $sql1=$empire->query("insert into 		{$dbtbpre}enewsmemberadd(userid,truename,oicq,msn,`call`,phone,address,zip) values($add[userid],'$add[truename]','$add[oicq]','$add[msn]','$add[call]','$add[phone]','$add[address]','$add[zip]');");
    }
	else
	{
	   $sql1=$empire->query("update {$dbtbpre}enewsmemberadd set truename='$add[truename]',oicq='$add[oicq]',msn='$add[msn]',`call`='$add[call]',phone='$add[phone]',address='$add[address]',zip='$add[zip]' where userid='$add[userid]'");
    }
	if($sql)
	{
	   //操作日志
	   insert_dolog("userid=".$add[userid]."<br>username=".$dousername);
	   printerror("EditMemberSuccess","ListMember.php");
	}
    else
	{
		printerror("DbError","history.go(-1)");
	}
}

//---------------------后台删除会员
function admin_DelMember($userid,$loginuserid,$loginusername){
	global $empire,$user_tablename,$user_username,$user_userid,$dbtbpre;
	$userid=(int)$userid;
	if(empty($userid))
	{printerror("NotDelMemberid","history.go(-1)");}
    //验证权限
    CheckLevel($loginuserid,$loginusername,$classid,"member");
	$r=$empire->fetch1("select ".$user_username." from ".$user_tablename." where ".$user_userid."='$userid'");
	if(empty($r[$user_username]))
	{
		printerror("NotDelMemberid","history.go(-1)");
	}
    $sql=$empire->query("delete from ".$user_tablename." where ".$user_userid."='$userid'");
	//删除附加表
	$sql1=$empire->query("delete from {$dbtbpre}enewsmemberadd where userid='$userid'");
	//删除收藏
	$del=$empire->query("delete from {$dbtbpre}enewsfava where userid='$userid'");
	$del=$empire->query("delete from {$dbtbpre}enewsfavaclass where userid='$userid'");
	//删除短信息
	$dousername=doUtfAndGbk($r[$user_username],1);
	$del=$empire->query("delete from {$dbtbpre}enewsqmsg where to_username='".$dousername."'");
	//删除购买记录
	$del=$empire->query("delete from {$dbtbpre}enewsbuybak where userid='$userid'");
	//删除下载记录
	$del=$empire->query("delete from {$dbtbpre}enewsdownrecord where userid='$userid'");
	//删除好友记录
	$del=$empire->query("delete from {$dbtbpre}enewshy where userid='$userid'");
	$del=$empire->query("delete from {$dbtbpre}enewshyclass where userid='$userid'");
    if($sql)
	{
		//操作日志
	    insert_dolog("userid=".$userid."<br>username=".$dousername);
		printerror("DelMemberSuccess","ListMember.php");
	}
    else
	{
		printerror("DbError","history.go(-1)");
	}
}

//--------------------后台批量删除会员
function admin_DelMember_all($userid,$logininid,$loginin){
	global $empire,$user_tablename,$user_username,$user_userid,$dbtbpre;
    //验证权限
    CheckLevel($logininid,$loginin,$classid,"member");
    $count=count($userid);
    if(!$count)
	{
		 printerror("NotDelMemberid","history.go(-1)");
	}
	for($i=0;$i<$count;$i++)
	{
		$dh=",";
		if($i==0)
		{
			$dh="";
		}
		//删除短信息
		$ur=$empire->fetch1("select ".$user_username." from ".$user_tablename." where ".$user_userid."='".$userid[$i]."'");
		if(empty($ur[$user_username]))
		{
			continue;
		}
		$dousername=doUtfAndGbk($ur[$user_username],1);
		$del=$empire->query("delete from {$dbtbpre}enewsqmsg where to_username='".$dousername."'");
		//集合
		$inid.=$dh.$userid[$i];
    }
	if(empty($inid))
	{
		printerror("NotDelMemberid","history.go(-1)");
	}
	$add=$user_userid." in (".$inid.")";
	$adda="userid in (".$inid.")";
	$sql=$empire->query("delete from ".$user_tablename." where ".$add);
	//删除附加表
	$sql1=$empire->query("delete from {$dbtbpre}enewsmemberadd where ".$adda);
	//删除收藏
	$del=$empire->query("delete from {$dbtbpre}enewsfava where ".$adda);
	$del=$empire->query("delete from {$dbtbpre}enewsfavaclass where ".$adda);
	//删除购买记录
	$del=$empire->query("delete from {$dbtbpre}enewsbuybak where ".$adda);
	//删除下载记录
	$del=$empire->query("delete from {$dbtbpre}enewsdownrecord where ".$adda);
	//删除好友记录
	$del=$empire->query("delete from {$dbtbpre}enewshy where ".$adda);
	$del=$empire->query("delete from {$dbtbpre}enewshyclass where ".$adda);
	if($sql)
	{
		//操作日志
	    insert_dolog("");
		printerror("DelMemberSuccess","ListMember.php");
    }
	else
	{
		printerror("DbError","history.go(-1)");
    }
}

//---------------取得邮件地址
function GetUserEmail($userid,$username){
	global $empire,$user_tablename,$user_email,$user_userid;
	$r=$empire->fetch1("select ".$user_email." from ".$user_tablename." where ".$user_userid."='$userid' limit 1");
	return doUtfAndGbk($r[$user_email],1);
}

//-------------返回修改资料
function ReturnUserInfo($userid){
	global $empire,$user_tablename,$user_userid,$user_username,$user_email,$user_group,$user_userfen,$user_money,$user_userdate,$user_todaydown,$user_zgroup;
	$r=$empire->fetch1("select ".$user_username.",".$user_email.",".$user_group.",".$user_userfen.",".$user_money.",".$user_userdate.",".$user_todaydown.",".$user_zgroup." from ".$user_tablename." where ".$user_userid."='$userid' limit 1");
	$re[username]=doUtfAndGbk($r[$user_username],1);
	$re[email]=doUtfAndGbk($r[$user_email],1);
	$re[userfen]=$r[$user_userfen];
	$re[money]=$r[$user_money];
	$re[groupid]=$r[$user_group];
	$re[userdate]=$r[$user_userdate];
	$re[zgroupid]=$r[$user_zgroup];
	$re[todaydown]=$r[$user_todaydown];
	return $re;
}

//------------------用户注册
function register($username,$password,$repassword,$email){
	global $empire,$user_tablename,$public_r,$user_groupid,$user_username,$user_userid,$user_email,$user_password,$user_dopass,$user_rnd,$user_registertime,$user_register,$user_group,$user_saltnum,$user_salt,$user_seting,$forumgroupid,$registerurl,$dbtbpre,$user_regcookietime;
	//关闭
	if($public_r['register_ok'])
	{printerror("CloseRegister","history.go(-1)",1);}
	if(!empty($registerurl))
	{
		Header("Location:$registerurl");
		exit();
    }
	$username=trim($username);
	$password=trim($password);
	$username=RepPostVar($username);
	$password=RepPostVar($password);
	if(!$username||!$password||!$email)
	{printerror("EmptyMember","history.go(-1)",1);}
	//用户字数
	$pr=$empire->fetch1("select min_userlen,max_userlen,min_passlen,max_passlen from {$dbtbpre}enewspublic limit 1");
	$userlen=strlen($username);
	if($userlen<$pr[min_userlen]||$userlen>$pr[max_userlen])
	{printerror("FaiUserlen","history.go(-1)",1);}
	//密码字数
	$passlen=strlen($password);
	if($passlen<$pr[min_passlen]||$passlen>$pr[max_passlen])
	{printerror("FailPasslen","history.go(-1)",1);}
	if($repassword!=$password)
	{printerror("NotRepassword","history.go(-1)",1);}
	if(!chemail($email))
	{printerror("EmailFail","history.go(-1)",1);}
	if(strstr($username,"|")||strstr($username,"*"))
	{printerror("NotSpeWord","history.go(-1)",1);}
	$username=RepPostStr($username);
	$num=$empire->gettotal("select count(*) as total from ".$user_tablename." where ".$user_username."='$username' limit 1");
	if($num)
	{printerror("ReUsername","history.go(-1)",1);}
	//注册时间
	if($user_register)
	{
		$registertime=time();
		$dyh="";
	}
	else
	{
		$registertime=date("Y-m-d H:i:s");
		$dyh="'";
	}
	$birthday=$y.$m.$d;
	$rnd=make_password(12);//产生随机密码
	//密码
	if(empty($user_dopass))//单重md5
	{
		$password=md5($password);
	}
	elseif($user_dopass==2)//双重md5
	{
		$salt=make_password($user_saltnum);
		$password=md5(md5($password).$salt);
	}
	elseif($user_dopass==3)//16位md5
	{
		$password=substr(md5($password),8,16);
	}
	$user_groupid=(int)$user_groupid;
	$email=RepPostStr($email);
	$sql=$empire->query("insert into ".$user_tablename."(".$user_username.",".$user_password.",".$user_email.",".$user_registertime.",".$user_group.",".$user_rnd.") values('$username','$password','$email',".$dyh."$registertime".$dyh.",$user_groupid,'$rnd');");
	//取得userid
	$userid=$empire->lastid();
	//附加表
	$addnum=$empire->gettotal("select count(*) as total from {$dbtbpre}enewsmemberadd where userid='$userid'");
	if(!$addnum)
	{
		$truename=RepPostStr($_POST['truename']);
		$oicq=RepPostStr($_POST['oicq']);
		$msn=RepPostStr($_POST['msn']);
		$call=RepPostStr($_POST['call']);
		$phone=RepPostStr($_POST['phone']);
		$address=RepPostStr($_POST['address']);
		$zip=RepPostStr($_POST['zip']);
		$sql1=$empire->query("insert into {$dbtbpre}enewsmemberadd(userid,truename,oicq,msn,`call`,phone,address,zip) values($userid,'$truename','$oicq','$msn','$call','$phone','$address','$zip');");
	}
	if($sql)
	{
		$logincookie=0;
		if($user_regcookietime)
		{
			$logincookie=time()+$user_regcookietime;
		}
		$set1=esetcookie("mlusername",$username,$logincookie);
		$set2=esetcookie("mluserid",$userid,$logincookie);
		$set3=esetcookie("mlgroupid",$user_groupid,$logincookie);
		$set4=esetcookie("mlrnd",$rnd,$logincookie);
		$location="../../";
		$returnurl=getcvar('returnurl');
		if($returnurl&&!strstr($returnurl,"e/member/iframe"))
		{
			$location=$returnurl;
		}
		$set5=esetcookie("returnurl","");
		printerror("RegisterSuccess",$location,1);
	}
	else
	{printerror("DbError","history.go(-1)",1);}
}

//---------------------信息修改
function EditInfo($password,$repassword,$oldpassword,$email){
	global $empire,$user_tablename,$public_r,$user_userid,$user_username,$user_password,$user_dopass,$user_email,$user_salt,$user_saltnum,$dbtbpre;
	//是否登陆
	$user_r=islogin();
	$userid=$user_r[userid];
	$username=$user_r[username];
	$rnd=$user_r[rnd];
	$groupid=$user_r[groupid];
	if(!$userid||!$username||!trim($email))
	{printerror("NotEmpty","history.go(-1)",1);}
	if(!chemail($email))
	{printerror("EmailFail","history.go(-1)",1);}
	$email=RepPostStr($email);
	$post=$_POST;
	//编码转换
	$username=doUtfAndGbk($username,0);
	$email=doUtfAndGbk($email,0);
	//修改密码
	if($password)
	{
		if($password!=$repassword)
		{printerror("NotRepassword","history.go(-1)",1);}
		$password=RepPostVar($password);
		$oldpassword=RepPostVar($oldpassword);
		$password=doUtfAndGbk($password,0);
		$oldpassword=doUtfAndGbk($oldpassword,0);
		if(empty($user_dopass))//单重加密
		{
			$password=md5($password);
			$oldpassword=md5($oldpassword);
	    }
		elseif($user_dopass==2)//双重加密
		{
			$salt=make_password($user_saltnum);
			$password=md5(md5($password).$salt);
			$sa=",".$user_salt."='$salt'";
		}
		elseif($user_dopass==3)//16位md5
		{
			$password=substr(md5($password),8,16);
			$oldpassword=substr(md5($oldpassword),8,16);
		}
		else
		{}
	    $num=0;
		//双重md5
		if($user_dopass==2)
		{
			$ur=$empire->fetch1("select ".$user_userid.",".$user_salt.",".$user_password." from ".$user_tablename." where ".$user_username."='$username'");
			$oldpassword=md5(md5($oldpassword).$ur[$user_salt]);
			$num=0;
			if($oldpassword==$ur[$user_password])
			{$num=1;}
			if(empty($ur[$user_userid]))
			{$num=0;}
		}
		else
		{
			$num=$empire->gettotal("select count(*) as total from ".$user_tablename." where ".$user_username."='$username' and ".$user_password."='".$oldpassword."'");
		}
		if(!$num)
		{printerror("FailOldPassword","history.go(-1)",1);}
		$add=",".$user_password."='".$password."'".$sa;
	}
    $sql=$empire->query("update ".$user_tablename." set ".$user_email."='$email'".$add." where ".$user_userid."='$userid'");
	//附加表
	$truename=RepPostStr($_POST['truename']);
	$oicq=RepPostStr($_POST['oicq']);
	$msn=RepPostStr($_POST['msn']);
	$call=RepPostStr($_POST['call']);
	$phone=RepPostStr($_POST['phone']);
	$address=RepPostStr($_POST['address']);
	$zip=RepPostStr($_POST['zip']);
	$addnum=$empire->gettotal("select count(*) as total from {$dbtbpre}enewsmemberadd where userid='$userid'");
	if(empty($addnum))
	{
	   $sql1=$empire->query("insert into 		{$dbtbpre}enewsmemberadd(userid,truename,oicq,msn,`call`,phone,address,zip) values($userid,'$truename','$oicq','$msn','$call','$phone','$address','$zip');");
    }
   else
	{
	   $sql1=$empire->query("update {$dbtbpre}enewsmemberadd set truename='$truename',oicq='$oicq',msn='$msn',`call`='$call',phone='$phone',address='$address',zip='$zip' where userid='$userid'");
    }
    if($sql)
    {
		printerror("EditInfoSuccess","../member/EditInfo",1);
	}
    else
    {printerror("DbError","history.go(-1)",1);}
}

//----------------------------------是否登陆
function islogin($uid=0,$uname='',$urnd=''){
	global $empire,$public_r,$editor,$user_tablename,$user_userid,$user_username,$user_email,$user_userfen,$user_money,$user_group,$user_groupid,$user_rnd,$user_zgroup,$user_userdate,$user_todaydown,$user_havemsg,$user_todaydate,$ecmsreurl,$eloginurl;
	if($uid)
	{$userid=(int)$uid;}
	else
	{$userid=(int)getcvar('mluserid');}
	if($urnd)
	{$rnd=$urnd;}
	else
	{$rnd=getcvar('mlrnd');}
	if($eloginurl)
	{$gotourl=$eloginurl;}
	else
	{$gotourl=$public_r['newsurl']."e/member/login";}
	if(!$userid)
	{
		if(!getcvar('returnurl'))
		{
			esetcookie("returnurl",$_SERVER['HTTP_REFERER'],0);
		}
		if($ecmsreurl==1)
		{
			$gotourl="history.go(-1)";
		}
		printerror("NotLogin",$gotourl,1);
	}
	$rnd=RepPostVar($rnd);
	$cr=$empire->fetch1("select ".$user_userid.",".$user_username.",".$user_email.",".$user_group.",".$user_userfen.",".$user_money.",".$user_userdate.",".$user_todaydown.",".$user_zgroup.",".$user_havemsg.",".$user_todaydate." from ".$user_tablename." where ".$user_userid."='$userid' and ".$user_rnd."='$rnd' limit 1");
	if(!$cr[$user_userid])
	{
		EmptyEcmsCookie();
		if(!getcvar('returnurl'))
		{
			esetcookie("returnurl",$_SERVER['HTTP_REFERER'],0);
		}
		if($ecmsreurl==1)
		{
			$gotourl="history.go(-1)";
		}
		printerror("NotSingleLogin",$gotourl,1);
	}
	//默认会员组
	if(empty($cr[$user_group]))
	{
		$usql=$empire->query("update ".$user_tablename." set ".$user_group."='$user_groupid' where ".$user_userid."='".$cr[$user_userid]."'");
		$cr[$user_group]=$user_groupid;
	}
	//是否过期
	if($cr[$user_userdate])
	{
		if($cr[$user_userdate]-time()<=0)
		{
			OutTimeZGroup($cr[$user_userid],$cr[$user_zgroup]);
			$cr[$user_userdate]=0;
			if($cr[$user_zgroup])
			{
				$cr[$user_group]=$cr[$user_zgroup];
				$cr[$user_zgroup]=0;
			}
		}
	}
	$re[userid]=$cr[$user_userid];
	$re[username]=doUtfAndGbk($cr[$user_username],1);
	$re[email]=doUtfAndGbk($cr[$user_email],1);
	$re[userfen]=$cr[$user_userfen];
	$re[money]=$cr[$user_money];
	$re[groupid]=$cr[$user_group];
	$re[userdate]=$cr[$user_userdate];
	$re[zgroupid]=$cr[$user_zgroup];
	$re[todaydown]=$cr[$user_todaydown];
	$re[todaydate]=$cr[$user_todaydate];
	/*
	if($cr[$user_havemsg])
	{
		echo"<script>window.status='您有新的悄悄话,请注意查收!';</script>";
	}
	*/
	return $re;
}

//-------------------------------------退出登陆
function loginout1($userid,$username,$rnd){
	global $empire,$public_r,$equiturl;
	//是否登陆
	$user_r=islogin();
	if($equiturl)
	{
		Header("Location:$equiturl");
		exit();
	}
	EmptyEcmsCookie();
	$dopr=1;
	if($_GET['prtype'])
	{
		$dopr=9;
	}
	$gotourl="../../";
	if(strstr($_SERVER['HTTP_REFERER'],"e/member/iframe"))
	{
		$gotourl=$public_r['newsurl']."e/member/iframe";
	}
	printerror("ExitSuccess",$gotourl,$dopr);
}

//-----------------------------------清空COOKIE
function EmptyEcmsCookie(){
	$set1=esetcookie("mlusername","",0);
	$set2=esetcookie("mluserid","",0);
	$set3=esetcookie("mlgroupid","",0);
	$set4=esetcookie("mlrnd","",0);
}

//----------------------------------------登陆
function login1($username,$password,$lifetime,$key,$location){
	global $empire,$user_tablename,$user_userid,$user_username,$user_password,$user_dopass,$user_group,$user_groupid,$user_rnd,$public_r,$user_salt,$user_saltnum,$dbtbpre,$eloginurl;
	if($eloginurl)
	{
		Header("Location:$eloginurl");
		exit();
	}
	$dopr=1;
	if($_POST['prtype'])
	{
		$dopr=9;
	}
	if(!trim($username)||!trim($password))
	{printerror("EmptyLogin","history.go(-1)",$dopr);}
	//验证码
	if($public_r['loginkey_ok'])
	{
		$checkplkey=getcvar('checkplkey');
		if($key<>$checkplkey||empty($checkplkey))
		{printerror("FailKey","history.go(-1)",$dopr);}
	}
	$username=RepPostVar($username);
	$password=RepPostVar($password);
	//编码转换
	$utfusername=doUtfAndGbk($username,0);
	$password=doUtfAndGbk($password,0);
	//密码
	if(empty($user_dopass))//单重md5
	{
		$password=md5($password);
	}
	if($user_dopass==3)//16位md5
	{
		$password=substr(md5($password),8,16);
	}
	//双重md5
	$num=0;
	if($user_dopass==2)
	{
	    $ur=$empire->fetch1("select ".$user_userid.",".$user_salt.",".$user_password." from ".$user_tablename." where ".$user_username."='$utfusername'");
		$password=md5(md5($password).$ur[$user_salt]);
		$num=0;
		if($password==$ur[$user_password])
		{$num=1;}
		if(empty($ur[$user_userid]))
		{$num=0;}
    }
	else
	{
		$num=$empire->gettotal("select count(*) as total from ".$user_tablename." where ".$user_username."='$utfusername' and ".$user_password."='".$password."' limit 1");
	}
	if(!$num)
	{
		printerror("FailPassword","history.go(-1)",$dopr);
	}
	$r=$empire->fetch1("select * from ".$user_tablename." where ".$user_username."='$utfusername' limit 1");
	$time=date("Y-m-d H:i:s");
	$rnd=make_password(12);//取得随机密码
	//默认会员组
	if(empty($r[$user_group]))
	{$r[$user_group]=$user_groupid;}
	$r[$user_group]=(int)$r[$user_group];
	$usql=$empire->query("update ".$user_tablename." set ".$user_rnd."='$rnd',".$user_group."=".$r[$user_group]." where ".$user_userid."='$r[$user_userid]'");
	//设置cookie
	$logincookie=0;
	if($lifetime)
	{
		$logincookie=time()+$lifetime;
	}
	$set1=esetcookie("mlusername",$username,$logincookie);
	$set2=esetcookie("mluserid",$r[$user_userid],$logincookie);
	$set3=esetcookie("mlgroupid",$r[$user_group],$logincookie);
	$set4=esetcookie("mlrnd",$rnd,$logincookie);
	//登录附加cookie
	AddLoginCookie($r);
	$location="../../";
	$returnurl=getcvar('returnurl');
	if($returnurl)
	{
		$location=$returnurl;
	}
	if(strstr($_SERVER['HTTP_REFERER'],"e/member/iframe"))
	{$location="../member/iframe";}
	$set5=esetcookie("checkplkey","");
	$set6=esetcookie("returnurl","");
	if($set1&&$set2)
	{
		printerror("LoginSuccess",$location,$dopr);
    }
	else
	{
		printerror("NotCookie","history.go(-1)",$dopr);
	}
}

//----------------------------------批量赠送点数
function GetFen_all($cardfen,$userid,$username){
	global $empire,$user_tablename,$user_userfen;
	$cardfen=(int)$cardfen;
	if(!$cardfen)
	{printerror("EmptyGetFen","history.go(-1)");}
	//验证权限
	CheckLevel($userid,$username,$classid,"card");
	$sql=$empire->query("update ".$user_tablename." set ".$user_userfen."=".$user_userfen."+$cardfen");
	if($sql)
	{
		//操作日志
		insert_dolog("cardfen=$cardfen");
		printerror("GetFenSuccess","GetFen.php");
	}
	else
	{printerror("DbError","history.go(-1)");}
}

//----------------------------------增加点数
function AddInfoFen($cardfen,$userid){
	global $empire,$user_tablename,$user_userfen,$user_userid;
	$cardfen=(int)$cardfen;
	$sql=$empire->query("update ".$user_tablename." set ".$user_userfen."=".$user_userfen."+".$cardfen." where ".$user_userid."='$userid'");
}

//转向会员组
function OutTimeZGroup($userid,$zgroupid){
	global $empire,$user_tablename,$user_group,$user_zgroup,$user_userdate,$user_userid;
	if($zgroupid)
	{
		$sql=$empire->query("update ".$user_tablename." set ".$user_group."='".$zgroupid."',".$user_userdate."=0 where ".$user_userid."='$userid'");
	}
	else
	{
		$sql=$empire->query("update ".$user_tablename." set ".$user_userdate."=0 where ".$user_userid."='$userid'");
	}
}

if($utfdata&&!function_exists("iconv"))
{
	@include_once("doiconv.php");
}
?>