<?php
include("require.php");
if(!isset($_GET['id']) and !isset($_GET['un']) and !isset($_COOKIE['core_user_name']))
  jump("index.php");
if(!isset($_GET['id']) and !isset($_GET['un']))
  $_GET['id']=$userv['id'];
$phpcolor->table="user";
$phpcolor->field="*";
//是否访问本人空间
$isme=0;
//是否是好友
$ishy="0";
if(isset($_GET['id']))
{
  submitfilter($_GET['id']);
  $phpcolor->where="id = '".$_GET['id']."'";
  if($_GET['id']==$userv['id'])
    $isme=1;
}
else
{
  $phpcolor->where="username = '".$_GET['un']."'";
  if($_GET['un']==$_COOKIE["core_user_name"])
    $isme=1;
}
//用户不存在
if(!$user=$phpcolor->exist(1))
  jump("error.php?id=13");
//我的好友
$phpcolor->table="user_friends";
if($isme!=1 and isset($_COOKIE['core_user_name']))
{
  $phpcolor->field="*";
  $phpcolor->where="uid = '".$user['id']."' and did = '".$userv['id']."'";
  if($phpcolor->exist(2))
    $ishy="1";
}
$phpcolor->field="did";
$phpcolor->where="uid = '".$user['id']."' limit 8";
$friends=$phpcolor->assignment();
$phpcolor->table="user";
for($count=0;$count<count($friends);$count++)
{
  $phpcolor->field="username,picture";
  $phpcolor->where="id = '".$friends[$count]['did']."'";
  $rs=$phpcolor->exist(1);
  $friends[$count]['username']=$rs['username'];
  $friends[$count]['picture']=$rs['picture'];
}
//认证用户
$phpcolor->table="attest";
$phpcolor->field="*";
$phpcolor->where="uid='".$user['id']."' and type='1'";
$user['userv']="0";
if($rs=$phpcolor->exist(1))
{
  $user['userv']="1";
  $user['uservxx']=$rs['attest'];
}
//VIP
$user['uservip']=$phpcolor->isvord($user['id'],1);
//达人
$user['userdr']=$phpcolor->isvord($user['id'],2);
if($user['userfriendp']==1 && $ishy=="0" && $isme=="0")
  jump("space.php?action=friendsadd&id=".$user['id']);
//相册
if($_GET['pages']=="album")
{
  if(isset($_GET['action']) && $_GET['action']=="albumpic")
  {
    submitfilter($_GET['aid']);
    $phpcolor->table="album";
    $phpcolor->field="*";
    $phpcolor->where="id = '".$_GET['aid']."'";
    $album=$phpcolor->exist(1);
    if(isset($_POST['pwd']))
      $_GET['pwd']=$_POST['pwd'];
    if($album['belong']!=$user['id'])
      jump("index.php");
    if($album['type']==2 && ($ishy=="0" && $isme=="0"))
      jump("space.php?action=friendsadd&id=".$user['id']);
    elseif($album['type']==3 && (!isset($_GET['pwd']) or $_GET['pwd']!=$album['passwd']))
       $_GET['action']="albumpwd";
    if(!isset($_GET['page']))
      $_GET['page']=0;
    $phpcolor->table="picture";
    $phpcolor->where="belong = '".$_GET['aid']."'";
    $count = $phpcolor->exist(2);
    $phpcolor->where="belong = '".$_GET['aid']."' order by id limit ".($_GET['page']*12).",12";
    $pic=$phpcolor->assignment();
    for ($i=0;$i<count($pic);$i++)
    {
      $pic[$i]['filename']="upload/album/".$pic[$i]['uid']."/".$pic[$i]['belong']."/".$pic[$i]['filename'];
    }
    $page=pages($count,12,$_GET['page'],'album','&id='.$userv["id"].'&action=albumpic&aid=',$_GET['aid'],"0");
    $tpl -> assign("album", $album);
    $tpl -> assign("pic", $pic);
    $tpl -> assign("page", $page);
    $tpl -> assign("core_header_title", $album['name']." - ".$user['username']."的相册 - ");
  }
  elseif($_GET['action']=="addpic")
  {
    submitfilter($_GET['aid']);
    $phpcolor->table="album";
    $phpcolor->field="name";
    $phpcolor->where="id = '".$_GET["aid"]."'";
    $album=$phpcolor->exist(1);
    $tpl -> assign("id", $_GET["aid"]); 
    $tpl -> assign("album", $album); 
    $tpl -> assign("core_user_passwd", $_COOKIE["core_user_passwd"]);
    $tpl -> assign("uid", $userv["id"]);
    $tpl -> assign("core_header_title", $album['name']." - ".$user['username']."上传照片 - ");
  }
  elseif($_GET['action']=="editpic")
  {
    submitfilter($_GET['pid']);
    $phpcolor->table="picture";
    $phpcolor->field="*";
    $phpcolor->where="id = '".$_GET['pid']."'";
    $pic = $phpcolor->exist(1);
    if($pic['uid']==$userv["id"])
      $tpl -> assign("pic", $pic); 
    else
      jump("error.php?id=2");
  }
  elseif($_GET['action']=="readpic")
  {
    submitfilter($_GET['aid']);
    $phpcolor->table="picture";
    $phpcolor->field="*";
    $phpcolor->where="id = '".$_GET['aid']."'";
    $pic=$phpcolor->exist(1);
    $pic['filename']="upload/album/".$pic['uid']."/".$pic['belong']."/".$pic['filename'];
    $phpcolor->where="id < '".$pic['id']."' and belong = '".$pic['belong']."' order by id desc limit 0,1";
    $qpic=$phpcolor->exist(1);
    $phpcolor->where="id > '".$pic['id']."' and belong = '".$pic['belong']."' order by id limit 0,1";
    $hpic=$phpcolor->exist(1);
    $phpcolor->table="album";
    $phpcolor->field="type,belong,passwd";
    $phpcolor->where="id = '".$pic['belong']."'";
    $album=$phpcolor->exist(1);
    if(isset($_POST['pwd']))
      $_GET['pwd']=$_POST['pwd'];
    if($album['belong']!=$user['id'])
      jump("index.php");
    if($album['type']==2 && ($ishy=="0" && $isme=="0"))
      jump("space.php?action=friendsadd&id=".$user['id']);
    elseif($album['type']==3 && (!isset($_GET['pwd']) or $_GET['pwd']!=$album['passwd']))
      $_GET['action']="albumpwd";
    if(!isset($_GET['page']))
      $_GET['page']=0;
    $tpl -> assign("album", $album);
    $tpl -> assign("pic", $pic);
    $tpl -> assign("qpic", $qpic);
    $tpl -> assign("hpic", $hpic);
    $tpl -> assign("core_header_title", $pic['name']." - ".$user['username']."的照片 - ");
  }
  elseif($_GET['action']=="addalbum")
    $tpl -> assign("core_header_title", $user['username']."创建相册 - ");
  elseif($_GET['action']=="editalbum")
  {
    submitfilter($_GET['aid']);
    $phpcolor->table="album";
    $phpcolor->field="belong";
    $phpcolor->where="id = '".$_GET['aid']."'";
    $rs = $phpcolor->exist(1);
    if($rs['belong']==$userv["id"])
    {
      $phpcolor->field="*";
      $album=$phpcolor->exist(1);
      $tpl -> assign("album", $album); 
      $tpl -> assign("core_header_title", $user['username']."编辑相册 - ");
    }
    else
      jump("error.php?id=2");
  }
  else
  {
    if(!isset($_GET['page']))
      $_GET['page']=0;
    $phpcolor->table="album";
    $phpcolor->field="*";
    $phpcolor->where="belong = '".$user['id']."'";
    $count = $phpcolor->exist(2);
    $phpcolor->where="belong = '".$user['id']."' limit ".($_GET['page']*8).",8";
    $album=$phpcolor->assignment();
    $phpcolor->table="picture";
    $phpcolor->field="filename";
    for ($i=0;$i<count($album);$i++)
    {
      $phpcolor->where="belong = '".$album[$i]["id"]."' order by uptime desc limit 1";
	  $album[$i]['indexpic']="images/img/barlogo.gif";
      if($rs=$phpcolor->exist(1))
        $album[$i]['indexpic']="upload/album/".$user['id']."/".$album[$i]['id']."/".$rs['filename'];
    }
    $page=pages($count,8,$_GET['page'],'album','&action=album&id=',$user['id'],"0");
    $tpl -> assign("album", $album);
    $tpl -> assign("page", $page);
    $tpl -> assign("core_header_title", $user['username']."的相册 - ");
  }
  $tpl -> assign("isme", $isme);
  $tpl -> assign("user", $user);
  $tpl -> assign("action", $_GET['action']);
  $tpl -> display("$core_style/space_album.htm");
}
//心情
elseif($_GET['pages']=="mood")
{
  if(!isset($_GET['page']))
    $_GET['page']=0;
  $phpcolor->table="qiandao";
  $phpcolor->field="*";
  $phpcolor->where="belong = '".$user['id']."' order by published desc";
  $count = $phpcolor->exist(2);
  $phpcolor->where="belong = '".$user['id']."' order by published desc limit ".($_GET['page']*15).",15";
  $qiandao=$phpcolor->assignment();
  $page=pages($count,15,$_GET['page'],'mood','&id=',$user['id'],"0");
  $tpl -> assign("isme", $isme);
  $tpl -> assign("qiandao", $qiandao);
  $tpl -> assign("page", $page);
  $tpl -> assign("core_header_title", $user['username']."的心情 - ");
  $tpl -> assign("user", $user);
  $tpl -> display("$core_style/space_mood.htm");
}
//个人信息
elseif($_GET['pages']=="info")
{
  if($_GET['action']=="attest")
  {
    $phpcolor->table="attest";
    $phpcolor->field="*";
    $phpcolor->where="uid = '".$userv['id']."'";
    $attest=$phpcolor->exist(1);
    $tpl -> assign("attest", $attest);
    $tpl -> assign("core_header_title", $user['username']."个人认证 - ");
  }
  else
  {
    $user['introduction']=autourl(str_replace("&lt;br /&gt;","<br />",$user['introduction']));
    $user['signature'] = str_replace("&lt;br /&gt;","<br />",$user['signature']);
    $phpcolor->table="topic";
    $phpcolor->field="id,theme,belong";
    $phpcolor->where="author = '".$user['username']."' and state!='0' and state != '3' order by published desc limit 0,10";
    $post=$phpcolor->assignment();
    $tpl -> assign("core_header_title", $user['username']."的个人信息 - ");
    $tpl -> assign("post", $post);
  }
  $tpl -> assign("isme", $isme);
  $tpl -> assign("user", $user);
  $tpl -> assign("action", $_GET['action']);
  $tpl -> display("$core_style/space_info.htm");
}
//空间主页
else
{
  
  if(!isset($_GET['page']))
    $_GET['page']=0;
  $phpcolor->table="new";
  $phpcolor->field="*";
  $phpcolor->where="belong = '".$user['id']."' and ishide!='1'";
  if($isme==1)
    $phpcolor->where="belong = '".$user['id']."'";
  $count=$phpcolor->exist(2);
  $page=pages($count,10,$_GET['page'],'space','&id=',$user['id'],"0");
  $phpcolor->where="belong = '".$user['id']."' and ishide!='1' order by published desc limit ".($_GET['page']*20).",20";
  if($isme==1)
  $phpcolor->where="belong = '".$user['id']."' order by published desc limit ".($_GET['page']*20).",20";
  $new=$phpcolor->assignment();
  for($count=0;$count<count($new);$count++)
  {
    $new[$count]['belongn']=$user['username'];
    if($count=="0")
    {
      $phpcolor->table="attest";
      $phpcolor->where="uid = '".$new[$count]['belong']."' and type='1'";
      $new[$count]['userv']="0";
      if($phpcolor->exist(2))
        $new[$count]['userv']="1";
    }
    else
      $new[$count]['userv']=$new[0]['userv'];
    if($new[$count]['type']=="2")
    {
      $phpcolor->table="picture";
      $phpcolor->field="*";
      $phpcolor->where="id = '".$new[$count]['cid']."'";
      $new[$count]['theme']="此信息已不存在，如有疑问请联系管理员咨询。";
      if($rs=$phpcolor->exist(1))
        $new[$count]['theme']="上传了新的照片 <a href='album.php?id=".$new[$count]['belong']."&action=readpic&uid=".$new[$count]['id']."' style='text-decoration:none'>《".$rs['name']."》</a>";
    }
    elseif($new[$count]['type']=="3")
    {
      $phpcolor->table="qiandao";
      $phpcolor->field="*";
      $phpcolor->where="id = '".$new[$count]['cid']."'";
      $new[$count]['theme']="此信息已不存在，如有疑问请联系管理员咨询。";
      if($rs=$phpcolor->exist(1))
        $new[$count]['theme']=$rs['content'];
    }
    elseif($new[$count]['type']=="4")
    {
      $phpcolor->table="bar";
      $phpcolor->field="*";
      $phpcolor->where="id = '".$new[$count]['cid']."'";
      $new[$count]['theme']="此信息已不存在，如有疑问请联系管理员咨询。";
      if($rs=$phpcolor->exist(1))
	  {
		$new[$count]['url']=htmlurl($core_url,"list",$new[$count]['cid'],0,$core_rewrite);
        $new[$count]['theme']="创建了 <a href='".$new[$count]['url']."' style='text-decoration:none'>".$rs['barname']."吧</a> ，大家都来看看吧！";
	  }
	}
    elseif($new[$count]['type']=="5")
    {
      $phpcolor->table="topic";
      $phpcolor->field="*";
      $phpcolor->where="id = '".$new[$count]['cid']."'";
      $new[$count]['theme']="此信息已不存在，如有疑问请联系管理员咨询。";
      if($rs=$phpcolor->exist(1))
        $new[$count]['theme']="发表了新主题 <a href='read.php?id=".$new[$count]['cid']."' style='text-decoration:none'>《".$rs['theme']."》</a>";
    }
    elseif($new[$count]['type']=="6")
    {
      $phpcolor->table="repost";
      $phpcolor->field="*";
      $phpcolor->where="id = '".$new[$count]['cid']."'";
      $rs1=$phpcolor->exist(1);
      $phpcolor->table="topic";
      $phpcolor->field="*";
      $phpcolor->where="id = '".$rs1['belong']."'";
      $new[$count]['theme']="此信息已不存在，如有疑问请联系管理员咨询。";
      if($rs=$phpcolor->exist(1))
        $new[$count]['theme']="回复了主题 <a href='read.php?id=".$rs['id']."' style='text-decoration:none'>《".$rs['theme']."》</a>";
    }
    elseif($new[$count]['type']=="7")
    {
      $phpcolor->table="bar";
      $phpcolor->field="*";
      $phpcolor->where="id = '".$new[$count]['cid']."'";
      $new[$count]['theme']="此信息已不存在，如有疑问请联系管理员咨询。";
      if($rs=$phpcolor->exist(1))
	  {
		$new[$count]['url']=htmlurl($core_url,"list",$rs['id'],0,$core_rewrite);
        $new[$count]['theme']="收藏了 <a href='".$new[$count]['url']."' style='text-decoration:none'>".$rs['barname']."吧</a>，大家也去看看吧~";
	  }
 	}
    elseif($new[$count]['type']=="8")
    {
      $phpcolor->table="topic";
      $phpcolor->field="id,theme";
      $phpcolor->where="id = '".$new[$count]['cid']."'";
      $new[$count]['theme']="此信息已不存在，如有疑问请联系管理员咨询。";
      if($rs=$phpcolor->exist(1))
        $new[$count]['theme']="收藏了主题 <a href='read.php?id=".$rs['id']."' style='text-decoration:none'>《".$rs['theme']."》</a>";
    }
  }
  if(count($new)==0)
    $new="0";
  $tpl -> assign("new", $new);
  $tpl -> assign("page", $page);
  $tpl -> assign("isme", $isme);
  $tpl -> assign("user", $user);
  $tpl -> assign("friends", $friends);
  $tpl -> assign("action", $_GET['action']);
  $tpl -> assign("core_header_title", $user['username']."的新鲜事 - ");
  $tpl -> display("$core_style/space_index.htm");
}
?>