<?php
include("require.php");
submitfilter(1,$_GET['bid']);
$phpcolor->table=$core_mysql_prefix."bar";
$phpcolor->field="*";
$phpcolor->where="id = '".$_GET['bid']."'";
$bar=$phpcolor->exist(1);
if(!$bar)
  Header("Location: index.php");
elseif($bar['merge']!="")
  Header("Location: create.php?barname=".$bar['merge']);
elseif($bar['state']=="0")
  Header("Location: error.php?id=5");
elseif($bar['state']=="2")
  Header("Location: error.php?id=6");
else
{
  $phpcolor->table=$core_mysql_prefix."ad";
  $phpcolor->field="name,site,type,theme,picture,link,code";
  $phpcolor->where="site = 6 order by rand()";
  $rs[6]=$phpcolor->assignment();
  for ($count=0;$count<count($rs[6]);$count++)
  {
    if($rs[6][$count]['type']==1)
      $ad[6][$count]="<a href=".$rs[6][$count]['link']." target='_blank'><img src=".$rs[6][$count]['picture']." width='728' height='90' style='border:0px;'></a>";
    elseif($rs[6][$count]['type']==2)
      $ad[6][$count]="<a href=".$rs[6][$count]['link']." target='_blank'>".$rs[6][$count]['theme']."</a>";
    else
      $ad[6][$count]=$rs[6][$count]['code'];
  }
  $phpcolor->where="site = 7 order by rand()";
  $rs[7]=$phpcolor->assignment();
  for ($count=0;$count<count($rs[7]);$count++)
  {
    if($rs[7][$count]['type']==1)
      $ad[7][$count]="<a href=".$rs[7][$count]['link']." target='_blank'><img src=".$rs[7][$count]['picture']." width='200' height='200' style='border:0px;'></a>";
    elseif($rs[7][$count]['type']==2)
      $ad[7][$count]="<a href=".$rs[7][$count]['link']." target='_blank'>".$rs[7][$count]['theme']."</a>";
    else
      $ad[7][$count]=$rs[7][$count]['code'];
  }
  if($bar['baruserp']=="1" && !isset($_COOKIE["core_user_name"]))
  {
    Header("Location: bar_user.php?bid=".$bar['id']);
	exit();
  }
  elseif($bar['baruserp']=="1")
  {
    $phpcolor->table=$core_mysql_prefix."bar_user";
    $phpcolor->field="*";
    $phpcolor->where="uid = '".$userv['id']."' and bid = '".$_GET['bid']."'";
    if(!$phpcolor->exist(2))
	{
	  Header("Location: bar_user.php?bid=".$bar['id']);
	  exit();
	}
  }
  $phpcolor->table=$core_mysql_prefix."bar";
  $friendbar = split("\|", $bar['friendbar']);
  for ($count=0;$count<count($friendbar);$count++)
  {
    $phpcolor->field="id";
    $phpcolor->where="barname = '".$friendbar[$count]."'";
    $friendbarid[$count]=$phpcolor->exist(1);
  }
  if(!isset($_GET['page']))
    $_GET['page']=0;
  $sort = 0;
  if($bar['barclass']!=0)
  {
    $phpcolor->table=$core_mysql_prefix."class";
    $phpcolor->field="classname";
    $phpcolor->where="id = '".$bar['barclass']."'";
    $sort = $phpcolor->exist(1);
  }
  $phpcolor->table=$core_mysql_prefix."topic";
  if(isset($_GET['show']) and $_GET['show'] == "boutique")
  {
    $phpcolor->field="*";
    $phpcolor->where="belong='".$bar['id']."' and boutique ='1' and state!='0' and state != '3' order by top desc,republished desc";
    $count = $phpcolor->exist(2);
    $phpcolor->where="belong='".$bar['id']."' and boutique ='1' and state!='0' and state != '3' order by top desc,republished desc limit ".($_GET['page']*$core_listpage).",".$core_listpage."";
  }
  elseif(isset($_GET['show']) and $_GET['show'] == "postclass")
  {
    submitfilter(1,$_GET['cid']);
    $phpcolor->field="*";
    $phpcolor->where="belong='".$bar['id']."' and postclass ='".$_GET['cid']."' and state!='0' and state != '3' order by top desc,republished desc";
    $count = $phpcolor->exist(2);
    $phpcolor->where="belong='".$bar['id']."' and postclass ='".$_GET['cid']."' and state!='0' and state != '3' order by top desc,republished desc limit ".($_GET['page']*$core_listpage).",".$core_listpage."";
  }
  else
  {
    $phpcolor->field="*";
    $phpcolor->where="belong = '".$bar['id']."' and state != '0' and state != '3' order by top desc,republished desc";
    $count = $phpcolor->exist(2);
    $phpcolor->where="belong = '".$bar['id']."' and state != '0' and state != '3' order by top desc,republished desc limit ".($_GET['page']*$core_listpage).",".$core_listpage."";
  }
  $phpcolor->field="id,theme,author,reauthor,published,republished,click,reply,top,boutique,locks,vote";
  $post=$phpcolor->assignment();
  $page=pages($count,$core_listpage,$_GET['page'],'list','&bid=',$bar['id'],$core_rewrite);
  $phpcolor->table=$core_mysql_prefix."user";
  $phpcolor->field="id";
  for ($count=0;$count<count($post);$count++)
  {
    $post[$count]['theme']=$phpcolor->mysubstr($post[$count]['theme'],0,52);
    if($post[$count]['authorip'] = is_ip($post[$count]['author']))
      $post[$count]['author'] = ip_three($post[$count]['author']);
    else
    {
      $phpcolor->where="username = '".$post[$count]['author']."'";
      $rsu=$phpcolor->exist(1);
	  $post[$count]['authorid']=$rsu['id'];
	}
	if($post[$count]['reauthorip'] = is_ip($post[$count]['reauthor']))
	  $post[$count]['reauthor'] = ip_three($post[$count]['reauthor']);
	else
	{
	  $phpcolor->where="username = '".$post[$count]['reauthor']."'";
	  $rsu=$phpcolor->exist(1);
	  $post[$count]['reauthorid']=$rsu['id'];
	}
    $date=substr($post[$count]['republished'],0,10);
    $time=substr($post[$count]['republished'],11,18);
    if($date==date('Y-m-d',strtotime(date('Y-m-d'))+$core_time*60*60))
	  $post[$count]['republished']=$time;
	else
	  $post[$count]['republished']=substr($date,0,10);
	$date=substr($post[$count]['published'],0,10);
    $time=substr($post[$count]['published'],11,18);
    if($date==date('Y-m-d',strtotime(date('Y-m-d'))+$core_time*60*60))
	  $post[$count]['published']=$time;
	else
	  $post[$count]['published']=substr($date,0,10);
  }
  $master = split("\|", $bar['barmaster']);
  $count = count($master);
  if($bar['barmaster']=="")
    $count=0;
  $show = "yes";
  $ismaster = 0;
  if($count >= $core_barmastercount and $bar['barmaster']!="")
    $show = "no";
  $isuser=0;
  $phpcolor->table=$core_mysql_prefix."bar_user";
  $phpcolor->field="*";
  $phpcolor->where="bid = '".$_GET['bid']."'";
  $barusercount=$phpcolor->exist(2);
  if(isset($_COOKIE['core_user_name']))
  {
    for($i=0;$i<$count;$i++)
    {
      if($master[$i]==$_COOKIE['core_user_name'])
      {
        $show = "no";
        $ismaster = 1;
      }
    }
	if($_COOKIE["core_user_rank"] != '0')
      $ismaster = 1;
    $phpcolor->where="uid = '".$userv['id']."' and bid = '".$_GET['bid']."'";
    $isuser=$phpcolor->exist(2);
  }
  $bar['introduction']=in_replace($bar['introduction']);
  if($bar['verify']==0)
    $core_verifyopen=0;
  elseif(($bar['verify']==1 && !isset($_COOKIE["core_user_name"])) || $bar['verify']==2 || ($bar['verify']==3 && $isuser==0))
    $core_verifyopen=1;
  elseif(isset($_COOKIE["core_user_name"]))
    $core_verifyopen=0;
  $visitoropen=1;
  if(($bar['visitor']==0 && !isset($_COOKIE["core_user_name"])) || ($bar['visitor']!=1 && $core_visitoropen==0 && !isset($_COOKIE["core_user_name"])))
    $visitoropen=0;
  elseif(($bar['baruserp']=="2" || $bar['baruserp']=="3") && $isuser==0)
	$visitoropen=2;
  $fileopen=0;
  if($core_file==2 || ($core_file==1 && isset($_COOKIE["core_user_name"])))
    $fileopen=1;
  $phpcolor->table=$core_mysql_prefix."postclass";
  $phpcolor->field="id, name";
  $phpcolor->where="belong = '".$_GET['bid']."'";
  $postclass=$phpcolor->assignment();
  $tpl -> assign("ad", $ad);
  $tpl -> assign("postclass", $postclass);
  $tpl -> assign("post", $post); 
  $tpl -> assign("page", $page);
  $tpl -> assign("visitoropen", $visitoropen);
  $tpl -> assign("core_verifyopen", $core_verifyopen);
  $tpl -> assign("core_opendomain", $core_opendomain);
  $tpl -> assign("core_erdomain", $core_erdomain);
  $tpl -> assign("fileopen", $fileopen);
  $tpl -> assign("verify", $_SESSION["verify"]);
  $tpl -> assign("ismaster", $ismaster);
  $tpl -> assign("friendbar", $friendbar);
  $tpl -> assign("friendbarid", $friendbarid);
  $tpl -> assign("barusercount", $barusercount);
  $tpl -> assign("isuser", $isuser); 
  $tpl -> assign("master", $master);
  $tpl -> assign("bar", $bar);
  $tpl -> assign("sort", $sort['classname']);
  $tpl -> assign("show", $show);
  $tpl -> assign("post_page", "list");
  $tpl -> assign("post_belong", $bar['id']);
  $tpl -> assign("core_header_title", $bar['barname']."吧 第".($_GET['page']+1)."页 - ");
  $tpl -> display("$core_style/list.htm");
}
?>