<?php
include_once("inc/config.php");
include_once("inc/ftbbsdbclass.php");
include_once("inc/publicfun.php");
include_once("conn.php");
include_once("ftbbs_nav.php");
include_once("inc/ftcode.php");
include_once("checkuser.php");
include_once("bbsuser.php");

$username=get_cookie('username');
$password=ftbbs_request(trim($_POST["password"]));
$username=ftbbs_request($username);
$password=ftbbs_request($password);
$question=ftbbs_request(trim($_POST["question"]));
$answer=ftbbs_request(trim($_POST["answer"]));
$url=ftbbs_request($_POST["url"]);
$oldpwd=ftbbs_request(trim($_POST["oldpwd"]));
$clubuser_marriage=ftbbs_request($_POST["clubuser_marriage"]);
$signname=ftbbs_request(trim($_POST["signname"]));
$signname=htmlspecialchars($signname);
$signname=nohtml($signname);
$email=ftbbs_request(trim($_POST["email"]));
$clubuser_province=ftbbs_request(trim($_POST["province"]));
$clubuser_city=ftbbs_request(trim($_POST["city"]));
$clubuser_address=ftbbs_request(trim($_POST["clubuser_address"]));
$clubuser_sex=ftbbs_request($_POST["sex"]);
$userimg=ftbbs_request($_POST["img"]);

$query = "SELECT * FROM {$tablepre}ftbbsmb";
$ftbbsmb=makecache('ftbbsmb.html',$query,$expire);
$usernamelng=$ftbbsmb[22];
$pswlng=$ftbbsmb[23];
$pwdarr=explode("-",$pswlng);
$pswlng1=$pwdarr[0];
$pswlng2=$pwdarr[1];

if ((strlen($password)>$pswlng2 || strlen($password)<$pswlng1) && $password!=""){
   ftbbs_msg("密码长度为".$pswlng."个字符!","moduserinfo.php");
   exit;
}
if (strlen($signname)>150){
   ftbbs_msg("签名档不能超过150字！","moduserinfo.php");
   exit;
}

//阻止签名档中的关键字
$sql_arrest="select * from {$tablepre}bbs_arrest where Kind='Keyword' order by id asc";
$qsrs=mysql_query($sql_arrest);
$qsrow = mysql_fetch_array($qsrs);
$numrows = mysql_num_rows($qsrs);
if ($numrows!=0){
   do {
    $content=$qsrow["Content"];
	$signname = str_replace($content,'*****',$signname);		
  }
   while ($qsrow = mysql_fetch_array($qsrs)); 
}

$sql="select * from {$tablepre}clubuser where clubuser_name='".$username."'";
$rs=mysql_query($sql);
$row = mysql_fetch_array($rs);
$numrows = mysql_num_rows($rs);
$clubuser_password=$row["clubuser_password"];
$clubuser_answer=$row["clubuser_answer"];

if ($clubuser_answer!=$answer){
$answer=md5($answer);
}
$dbuserimg=$row["userimg"];
if ($userimg==""){
$userimg=$dbuserimg;
}
if ($password!=""){
   if ($clubuser_password==md5($oldpwd)){
   $password=md5($password);
   $str="update {$tablepre}clubuser set clubuser_password='".$password."',clubuser_question='".$question."',clubuser_answer='".$answer."',clubuser_sex='".$clubuser_sex."',clubuser_email='".$email."',signname='".$signname."',clubuser_marriage='".$clubuser_marriage."',clubuser_province='".$clubuser_province."',clubuser_city='".$clubuser_city."'',clubuser_address='".$clubuser_address."',userimg='".$userimg."' where clubuser_name='".$username."'";
   mysql_query($str);
   set_cookie('clubuser_password', base64_encode($password), 3600);
   }
   else{
   ftbbs_msg("密码修改要验证原始密码，你输入的原始密码不正确,修改失败!","moduserinfo.php");
   exit;
   }
}
elseif ($password=="" && $clubuser_answer!=$answer){
   if ($clubuser_password==md5($oldpwd)){
   $str="update {$tablepre}clubuser set clubuser_question='".$question."',clubuser_answer='".$answer."',clubuser_sex='".$clubuser_sex."',clubuser_email='".$email."',signname='".$signname."',clubuser_marriage='".$clubuser_marriage."',clubuser_province='".$clubuser_province."',clubuser_city='".$clubuser_city."',clubuser_address='".$clubuser_address."',userimg='".$userimg."' where clubuser_name='".$username."'";
   mysql_query($str);
   }
   else{
   ftbbs_msg("问题答案修改要验证原始密码，你输入的原始密码不正确,修改失败!","moduserinfo.php");
   exit;
   }
}
else{
   $str="update {$tablepre}clubuser set clubuser_question='".$question."',clubuser_answer='".$answer."',clubuser_sex='".$clubuser_sex."',clubuser_email='".$email."',signname='".$signname."',clubuser_marriage='".$clubuser_marriage."',clubuser_province='".$clubuser_province."',clubuser_city='".$clubuser_city."',clubuser_address='".$clubuser_address."',userimg='".$userimg."' where clubuser_name='".$username."'";
   mysql_query($str);
}
ftbbs_msg("恭喜你，修改个人信息成功！",$url);
?>