<?php
include(dirname(__FILE__)."/require.php");
if($ppurview[19]!=1)
  jump("jump.php?id=25&jump=main.php");
$phpcolor->table="user";
$phpcolor->where="id = '".$_GET['id']."'";
if(isset($_GET['action']) and isset($_GET['id']) and $_GET['action']=="on")
{
  $phpcolor->field="state='1'";
  $phpcolor->upgrade();
  jump("jump.php?id=24&jump=user.php");
}
if(isset($_GET['action']) and isset($_GET['id']) and $_GET['action']=="off")
{
  $phpcolor->field="state='0'";
  $phpcolor->upgrade();
  jump("jump.php?id=24&jump=user.php");
}
if(isset($_GET['action']) and isset($_GET['id']) and $_GET['action'] == "editdo")
{
  if ($_POST['passwd']!="" and (strlen($_POST['passwd'])<$core_pwdshort or strlen($_POST['passwd'])>$core_pwdlong))
	jump("jump.php?id=8&jump=user.php?action=edit=and=id=".$_GET['id']);
  if($_POST['passwd']!="")
  {
    $user_passwd = md5($_POST['passwd']);
    $phpcolor->field="passwd='".$user_passwd."', email='".$_POST['email']."', safemail='".$_POST['safemail']."', question='".$_POST['question']."', answer='".$_POST['answer']."', picture='".$_POST['picture']."', userfrom='".$_POST['userfrom']."', sex='".$_POST['sex']."', age='".$_POST['age']."', birthday='".$_POST['birthday']."', zodiac='".$_POST['zodiac']."', constellation='".$_POST['constellation']."', blood='".$_POST['blood']."', school='".$_POST['school']."', profession='".$_POST['profession']."', qq='".$_POST['qq']."', mobile='".$_POST['mobile']."', phone='".$_POST['phone']."', signature='".$_POST['signature']."', introduction='".$_POST['introduction']."', state='".$_POST['state']."'";
    $phpcolor->upgrade();
  }
  else
  {
    $phpcolor->field="email='".$_POST['email']."', safemail='".$_POST['safemail']."', question='".$_POST['question']."', answer='".$_POST['answer']."', picture='".$_POST['picture']."', userfrom='".$_POST['userfrom']."', sex='".$_POST['sex']."', age='".$_POST['age']."', birthday='".$_POST['birthday']."', zodiac='".$_POST['zodiac']."', constellation='".$_POST['constellation']."', blood='".$_POST['blood']."', school='".$_POST['school']."', profession='".$_POST['profession']."', qq='".$_POST['qq']."', mobile='".$_POST['mobile']."', phone='".$_POST['phone']."', signature='".$_POST['signature']."', introduction='".$_POST['introduction']."', state='".$_POST['state']."'";
    $phpcolor->upgrade();
  }
  jump("jump.php?id=24&jump=user.php");
}
if(isset($_GET['action']) and isset($_GET['id']) and $_GET['action'] == "edit")
{
  $phpcolor->field="*";
  $user = $phpcolor->exist(1);
  $phpcolor->table="bar_user";
  $phpcolor->field="*";
  $phpcolor->where="uid = '".$user['id']."' and rank='2'";
  $barm = $phpcolor->assignment();
  for($count=0;$count<count($barm);$count++)
  {
    $phpcolor->table="bar";
    $phpcolor->field="barname";
    $phpcolor->where="id = '".$barm[$count]['bid']."'";
    $rs=$phpcolor->exist(1);
	$barm[$count]['barname']=$rs['barname'];
  }  $phpcolor->table="attest";
  $phpcolor->field="attest";
  $phpcolor->where="uid='".$user['id']."' and type='1'";
  $user['userv']="0";
  if($rs=$phpcolor->exist(1))
  {
    $user['userv']="1";
	$user['attest']=$rs['attest'];
  }
  //是否是VIP会员
  $user['uservip']="0";
  $uservip=$phpcolor->isvord($user['id'],3);
  if(isset($uservip['etime']))
  {
	$user['uservip']="1";
	$user['vipetime']=$uservip['etime'];
  }
  //是否是达人
  $user['userr']="0";
  $userdr=$phpcolor->isvord($user['id'],4);
  if(isset($userdr['etime']))
  {
    $user['userr']="1";
	$user['retime']=$userdr['etime'];
  }
  $tpl -> assign("user", $user);
  $tpl -> assign("barm", $barm);
  $tpl -> display("user_edit.htm");
}
else
{
  if(!isset($_GET['page']))
    $_GET['page']=0;
  $phpcolor->field="*";
  if(isset($_GET['username']))
  {
    $phpcolor->where="username like '%".$_GET['username']."%'";
    $count = $phpcolor->exist(2);
    $phpcolor->where="username like '%".$_GET['username']."%' order by registered desc limit ".($_GET['page']*24).",24";
    $page=pages($count,24,$_GET['page'],'user','&username=',$_GET['username'],'0');
  }
  else
  {
    $phpcolor->where="1=1";
    $count = $phpcolor->exist(2);
    $phpcolor->where="1=1 order by registered desc limit ".($_GET['page']*24).",24";
    $page=pages($count,24,$_GET['page'],'user','','','0');
  }
  $user = $phpcolor->assignment();
  $userrs=count($user);
  $users=4-$userrs%4;
  for($count=0;$count<$userrs;$count++)
  {
    $phpcolor->table="attest";
	$phpcolor->where="uid='".$user[$count]['id']."' and type='1'";
    $user[$count]['userv']="0";
	if($phpcolor->exist(2))
	  $user[$count]['userv']="1";
    //是否是VIP会员
	$user[$count]['uservip']=$phpcolor->isvord($user[$count]['id'],1);
    //是否是达人
	$user[$count]['userr']=$phpcolor->isvord($user[$count]['id'],2);
  }
  $tpl -> assign("users", $users);
  $tpl -> assign("user", $user);
  $tpl -> assign("page", $page);
  $tpl -> display("user.htm");
}
?>