<?php
include("require.php");
if(!isset($_COOKIE['core_user_name']))
  jump("index.php");
if($_GET['action']=="adddo")
{
  $_POST['addname']=mb_convert_encoding($_POST['addname'], "gbk", "UTF-8");
  $_POST['addurl']=mb_convert_encoding($_POST['addurl'], "gbk", "UTF-8");
  if($_POST['addname']=="" || strlen($_POST['addname'])>30 || $_POST['addurl']=="" || strlen($_POST['addurl'])>255 || !eregi("^[0-9]+$",$_POST['addqueue']))
    die("2");
  $phpcolor->table="indexu";
  $phpcolor->field="uid, urlname, url, click, queue, belong";
  $phpcolor->where="'".$userv['id']."','".$_POST['addname']."','".$_POST['addurl']."','0','".$_POST['addqueue']."','1'";
  $phpcolor->write();
  die("1");
}
elseif($_GET['action']=="editdo")
{
  $_POST['editname']=mb_convert_encoding($_POST['editname'], "gbk", "UTF-8");
  $_POST['editurl']=mb_convert_encoding($_POST['editurl'], "gbk", "UTF-8");
  if($_POST['editname']=="" || strlen($_POST['editname'])>30 || $_POST['editurl']=="" || strlen($_POST['editurl'])>255 || !eregi("^[0-9]+$",$_POST['editqueue']))
    die("2");
  $phpcolor->table="indexu";
  $phpcolor->field="urlname='".$_POST['editname']."',url='".$_POST['editurl']."',queue='".$_POST['editqueue']."'";
  $phpcolor->where="id = '".$_POST['id']."' and uid = '".$userv['id']."'";
  $phpcolor->upgrade();
  die("1");
}
$phpcolor->table="indexu";
$phpcolor->field="id,urlname,url,queue";
$phpcolor->where="uid = '".$userv["id"]."' and belong='1' order by queue";
$daohang=$phpcolor->assignment();
$daohangrs=count($daohang);
$daohangs=5-$daohangrs%5;
if($daohangs==5)
  $daohangs=0;
$phpcolor->table="qiandao";
$phpcolor->field="*";
$yztime=date('Y-m-d',strtotime(date('Y-m-d H:i:s'))+$core_time*3600);
$phpcolor->where="published like '%".$yztime."%' and belong='".$userv['id']."' and type='1'";
$pd=$phpcolor->exist(2);
if($pd)
  $qiandao="1";
else
  $qiandao="0";
$phpcolor->table="user";
$phpcolor->field="picture";
$phpcolor->where="username='".$_COOKIE['core_user_name']."'";
$users=$phpcolor->exist(1);
$phpcolor->table="user_friends";
$phpcolor->field="did";
$phpcolor->where="uid = '".$userv['id']."'";
$rs=$phpcolor->assignment();
$fid=$userv['id'];
for($count=0;$count<count($rs);$count++)
{
  $fid.=",".$rs[$count]['did'];
}
$where="belong in (".$fid.") and ishide!='1'";
$phpcolor->table="new";
$phpcolor->field="*";
$phpcolor->where=$where;
$count=$phpcolor->exist(2);
$page=pages($count,10,$_GET['page'],'index_u','','',"0");
$phpcolor->where=$where." order by published desc limit ".($_GET['page']*20).",20";
$new=$phpcolor->assignment();
for($count=0;$count<count($new);$count++)
{
  $phpcolor->table="attest";
  $phpcolor->where="uid = '".$new[$count]['belong']."' and type='1'";
  $new[$count]['userv']="0";
  if($phpcolor->exist(2))
    $new[$count]['userv']="1";
  $phpcolor->table="user";
  $phpcolor->field="username";
  $phpcolor->where="id = '".$new[$count]['belong']."'";
  $userrs=$phpcolor->exist(1);
  $new[$count]['belongn']=$userrs['username'];
  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='space.php?pages=album&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>";
  }
}
//公告
$phpcolor->table="placard";
$phpcolor->field="tid,theme";
$phpcolor->where="type = 1 order by placardtime desc limit 5";
$notice=$phpcolor->assignment();
for ($count=0;$count<count($notice);$count++)
{ 
  $notice[$count]['url']=htmlurl($core_url,"read",$notice[$count]['tid'],0,$core_rewrite);
}
$barcount=0;
//是吧主的吧
$phpcolor->table="bar_user";
$phpcolor->field="bid";
$phpcolor->where="uid = '".$userv['id']."' and rank = 2";
$mbar=$phpcolor->assignment();
for ($count=0;$count<count($mbar);$count++)       
{
  $phpcolor->table="bar";
  $phpcolor->field="barname";
  $phpcolor->where="id='".$mbar[$count]['bid']."'";
  $barrs=$phpcolor->exist(1);
  $bar[$barcount]=$mbar[$count];
  $bar[$barcount]['name'] = $barrs['barname'];
  $bar[$barcount]['rank'] = "2";
  $bar[$barcount]['url']=htmlurl($core_url,"list",$bar[$barcount]['bid'],0,$core_rewrite);
  $barcount++;
}
//是小吧主的吧
$phpcolor->table="bar_user";
$phpcolor->field="bid";
$phpcolor->where="uid = '".$userv['id']."' and rank = 1";
$smbar=$phpcolor->assignment();
for ($count=0;$count<count($smbar);$count++)       
{
  $phpcolor->table="bar";
  $phpcolor->field="barname";
  $phpcolor->where="id='".$smbar[$count]['bid']."'";
  $barrs=$phpcolor->exist(1);
  $bar[$barcount]=$smbar[$count];
  $bar[$barcount]['name'] = $barrs['barname'];
  $bar[$barcount]['rank'] = "1";
  $bar[$barcount]['url']=htmlurl($core_url,"list",$bar[$barcount]['bid'],0,$core_rewrite);
  $barcount++;
}
//是会员的吧
$phpcolor->table="bar_user";
$phpcolor->field="bid";
$phpcolor->where="uid = '".$userv['id']."' and rank = 0";
$jbar=$phpcolor->assignment();
for ($count=0;$count<count($jbar);$count++)
{
  $phpcolor->table="bar";
  $phpcolor->field="barname";
  $phpcolor->where="id='".$jbar[$count]['bid']."'";
  $barrs=$phpcolor->exist(1);
  $bar[$barcount]=$jbar[$count];
  $bar[$barcount]['name'] = $barrs['barname'];
  $bar[$barcount]['rank'] = "0";
  $bar[$barcount]['url']=htmlurl($core_url,"list",$bar[$barcount]['bid'],0,$core_rewrite);
  $barcount++;
}
$bars=5-$barcount%5;
if($bars==5)
  $bars=0;
//猜你喜欢
$yztime=date('Y-m-d',strtotime(date('Y-m-d H:i:s'))+$core_time*3600-86400*7);
$phpcolor->table="hotkey_so";
$phpcolor->field="hotkey";
$phpcolor->where="users='".$_COOKIE['core_user_name']."' order by click desc limit 5";
$clikers=$phpcolor->assignment();
$where="content like '%".$clikers[0]['hotkey']."%'";
for($count=1;$count<count($clikers);$count++)
{
  $where.=" or content like '%".$clikers[$count]['hotkey']."%'";
}
$phpcolor->table="topic";
$phpcolor->field="id,theme";
$phpcolor->where="(".$where.") and state = '1' order by published desc limit 10";
$clike=$phpcolor->assignment();
for($count=0;$count<count($clike);$count++)
{
  $clike[$count]['url']=htmlurl($core_url,"read",$clike[$count]['id'],0,$core_rewrite);
}
$tpl -> assign("clike", $clike);
$tpl -> assign("bar", $bar);
$tpl -> assign("bars", $bars);
$tpl -> assign("notice", $notice);
$tpl -> assign("new", $new);
$tpl -> assign("page", $page);
$tpl -> assign("daohang", $daohang);
$tpl -> assign("daohangs", $daohangs);
$tpl -> assign("users", $users);
$tpl -> assign("core_yjcm", $core_yjcm);
$tpl -> assign("core_keyword", $core_keyword);
$tpl -> assign("core_description", $core_description);
$tpl -> assign("qiandao", $qiandao);
$tpl -> assign("action", $_GET['action']);
$tpl -> assign("core_header_title", "我的首页 - ");
$tpl -> display("$core_style/index_u.htm");
?>