<?php
require_once(dirname(__FILE__)."/config.php");
require_once(dirname(__FILE__)."/../include/pub_datalist_dm.php");
require_once(dirname(__FILE__)."/../include/inc_functions.php");
$tid = ereg_replace("[^0-9]","",$tid);
$id = ereg_replace("[^0-9]","",$id);
if($id < 1 || $tid < 1) {
	ShowMsg("错误,未定义的操作！","-1");
	exit(); 
}
$db = new DedeSql(false);
$rs = $db->GetOne("SELECT ishidden,groupname,ismaster,smalltype,des,uid FROM #@__groups WHERE groupid='$id'");
if(!is_array($rs)){
	$db->Close();
	ShowMsg("圈子不存在,或被删除！","-1");
	exit(); 
}else if($rs['ishidden']){
	$db->Close();
	ShowMsg("圈子被管理员屏蔽中！","-1");
	exit();
}
$title = $rs['groupname'];
$des = $rs['des'];
if(empty($des)) $des = "本圈还没有介绍说明.";
$master = $rs['ismaster'];
//检测管理员
$ismaster    = @explode(",",$master);
$ismaster	 = in_array($cfg_ml->M_UserName,$ismaster);
if(empty($cfg_ml->M_UserName)) $ismaster = 0;
$smalltype = $rs['smalltype'];
$userid	= $rs['uid'];
$db->ExecuteNoneQuery("UPDATE #@__group_threads SET views=views+1 WHERE tid='$tid';");
$rs = $db->GetOne("SELECT subject FROM #@__group_threads WHERE gid='$id' AND tid='$tid'");
$subject = $rs['subject'];
//删除贴子操作
if(!isset($do)) $do = '';
if($do=="del"){
	if($ismaster){
		$rs = $db->GetOne("SELECT authorid,first FROM #@__group_posts WHERE pid='$pid'");
		$uid = $rs['authorid'];
		$first = $rs['first'];
		if($first){
			//开始移除相关贴子
			$db->ExecuteNoneQuery("DELETE FROM #@__group_posts WHERE tid='$tid'");
			$db->ExecuteNoneQuery("DELETE FROM #@__group_threads WHERE tid='$tid'");
			//更新统计
			Upcountgroups($id);
			Upcontuserpost($id,$uid,"post");
		}else{
			//移除指定贴子
			$db->ExecuteNoneQuery("DELETE FROM #@__group_posts WHERE pid='$pid'");
		}
		//更新回复统计
		Upcontuserpost($id,$uid,"replies");
	}else{
		$db->Close();
		ShowMsg("现您没该操作权限！","-1");
		exit();
	}
}
$sql = "SELECT pid,first,subject,authorid,author,dateline,message FROM #@__group_posts WHERE gid='$id' AND tid='$tid' ORDER BY dateline ASC";
$dlist = new DataList();
$dlist->pageSize = 5;
if($nowpage<2) $i=0;
else $i=($nowpage-1)*5;
$dlist->SetParameter("id",$id);
$dlist->SetParameter("tid",$tid);
$dlist->SetSource($sql);
require_once(dirname(__FILE__)."/templets/viewthread.htm");
$dlist->Close();
unset($rs);
$db->Close();
?>