<?php
include("require.php");
submitfilter($_GET['bid']);
$phpcolor->table="bar";
$phpcolor->field="*";
$phpcolor->where="id = '".$_GET['bid']."'";
if(!($bar=$phpcolor->exist(1)))
  jump("index.php");
if($bar['merge']!="")
  jump("create.php?barname=".$bar['merge']);
if($bar['state']=="0")
  jump("error.php?id=5");
if($bar['state']=="2")
  jump("error.php?id=6");
if(!isset($_COOKIE["core_user_name"]))
  jump("login.php?action=login&last=".$last);
if($bar['style']!="0")
{
  $phpcolor->table="style";
  $phpcolor->field="link,phpfile";
  $phpcolor->where="id=".$bar['style'];
  if($style=$phpcolor->exist(1))
    $core_style=$style['link'];
}
//是否拥有管理权限
$ismaster = $phpcolor->isuorm($userv['id'],$_GET['bid'],2);
if($_COOKIE["core_user_rank"]=="2")
  $ismaster = 1;
//是否是本吧会员
$isuser=$phpcolor->isuorm($userv['id'],$_GET['bid'],1);
//贴吧网址
$barurl=htmlurl($core_url,"list",$_GET['bid'],0,$core_rewrite);
if(isset($_GET['action']) && $_GET['action']=='join' && $bar['apply']=="0")
{
  if($isuser)
    jump("error.php?id=15&last=".$barurl);
  $time=date('Y-m-d H:i:s',strtotime(date('Y-m-d H:i:s'))+$core_time*3600);
  $phpcolor->table="bar_user";
  $phpcolor->field="uid, bid , integral, accesstime";
  $phpcolor->where="'".$userv['id']."', '".$_GET['bid']."', '2', '".$time."'";
  $phpcolor->write();
  //更新吧排名（会员加入）
  $phpcolor->upranking($int_hyjr,$_GET['bid']);
  jump($barurl);
}
if(isset($_GET['action']) && $_GET['action']=='applysubmit' && isset($_GET['bn']))
{
  $phpcolor->table="apply_user";
  $phpcolor->field="*";
  $phpcolor->where="username='".$_COOKIE['core_user_name']."' and object='".$bar['barname']."' and type='1'";
  if($phpcolor->exist(1))
    jump("error.php?id=9"); 
  $phpcolor->table="apply_user";
  $phpcolor->field="username, object, why, type";
  $phpcolor->where="'".$_COOKIE["core_user_name"]."', '".$_GET['bn']."', '".$_POST['reason']."', '1'";
  $phpcolor->write();
  if($bar['baruserp']=="1")
    jump("index.php");
  jump($barurl);
}
if(isset($_GET['action']) && $_GET['action']=='quit')
{
  $phpcolor->table="bar_user";
  $phpcolor->field="*";
  $phpcolor->where="bid = '".$_GET['bid']."' and uid = '".$userv['id']."' and rank = 2";
  if($phpcolor->exist(2))
    jump("bar_manage.php?bid=".$_GET['bid']."&action=apply");
  $phpcolor->where="uid = '".$userv['id']."' and bid = '".$_GET['bid']."'";
  $phpcolor->delete();
  //更新吧排名（会员退出）
  $phpcolor->upranking($int_hytc,$_GET['bid']);
  jump("index.php");
}
//友情吧
$phpcolor->table="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);
  $friendbarid[$count]['url']=htmlurl($core_url,"list",$friendbarid[$count]['id'],0,$core_rewrite);
}
$sort = 0;
if($bar['barclass']!=0)
{
  $phpcolor->table="class";
  $phpcolor->field="classname";
  $phpcolor->where="id = '".$bar['barclass']."'";
  $sort = $phpcolor->exist(1);
}
$audit=0;
if($bar['apply']=="1" && !$isuser)
  $audit=1;
if($bar['apply']=="0" && !$isuser)
  jump("bar_user.php?action=join&bid=".$bar['id']);
if(!isset($_GET['page']))
  $_GET['page']=0;
$phpcolor->table="bar_user";
$phpcolor->field="*";
$phpcolor->where="bid = '".$_GET['bid']."'";
$barusercount=$phpcolor->exist(2);
$phpcolor->where="bid = '".$_GET['bid']."' limit ".($_GET['page']*50).",50";
$baruser=$phpcolor->assignment();
$page=pages($barusercount,50,$_GET['page'],'bar_user','&bid=',$bar['id'],"0");
for ($count=0;$count<count($baruser);$count++)
{
  $phpcolor->table="user";
  $phpcolor->field="username, picture";
  $phpcolor->where="id = '".$baruser[$count]['uid']."'";
  $rs=$phpcolor->exist(1);
  $baruser[$count]['username']=$rs['username'];
  $baruser[$count]['picture']=$rs['picture'];
}
$tpl -> assign("page", $page);
$tpl -> assign("baruser", $baruser);
$phpcolor->table="bar_user";
$phpcolor->field="uid";
$phpcolor->where="bid = '".$bar['id']."' and rank=2";
$rs=$phpcolor->assignment();
for($count=0;$count<count($rs);$count++)
{
  $phpcolor->table="user";
  $phpcolor->field="username";
  $phpcolor->where="id = '".$rs[$count]['uid']."'";
  $rsm=$phpcolor->exist(1);
  $master[$count]['username'] = $rsm['username'];
  $master[$count]['uid'] = $rs[$count]['uid'];
}
//本吧地址
$phpcolor->table="bar_domain";
$phpcolor->field="domain";
$phpcolor->where="bid = '".$_GET['bid']."'";
if($bardomain=$phpcolor->exist(1))
{
  $bar['url']="http://".$bardomain['domain']."/";
  $barurl=$bar['url'];
}
else
  $bar['url']=htmlurl($core_url,"list",$_GET['bid'],0,$core_rewrite);
$tpl -> assign("core_style", $core_style);
$tpl -> assign("bar", $bar);
$tpl -> assign("friendbar", $friendbar);
$tpl -> assign("friendbarid", $friendbarid);
$tpl -> assign("sort", $sort['classname']);
$tpl -> assign("master", $master);
$tpl -> assign("audit", $audit);
$tpl -> assign("ismaster", $ismaster);
$tpl -> assign("core_header_title", $bar['barname']."吧吧内会员 - ");
$tpl -> display("$core_style/bar_user.htm");
?>