<?php
require_once(dirname(__FILE__)."/config.php");
CheckPurview('group_Main');
require_once(dirname(__FILE__)."/../include/pub_datalist_dm.php");
require_once(dirname(__FILE__)."/../include/inc_functions.php");
setcookie("ENV_GOBACK_URL",$dedeNowurl,time()+3600,"/");
$db = new DedeSql(false);
function GetGroupname($id){
	global $db;
	$id = intval($id);
	$rs = $db->GetOne("SELECT groupname FROM #@__groups WHERE groupid='".$id."'");
	if(is_array($rs)) return $rs['groupname'];
	else return_nulls;
}
$ID = ereg_replace("[^0-9]","",$ID);
if(!empty($Ids)){
	foreach($Ids as $val)
	{
		$db->ExecuteNoneQuery("DELETE FROM #@__group_threads WHERE tid='{$val}'");
	}
}
//Function 主题操作
if($action=="del"){	
	if($ID > 0) $db->ExecuteNoneQuery("DELETE FROM #@__group_threads WHERE tid='$ID'");
}else if($action=="digest"){
	//精华
	$rs = $db->GetOne("SELECT digest FROM #@__group_threads WHERE tid='".$ID."'");	
	if(is_array($rs)){
		if(!$rs['digest']) $digestval = 1;
		else $digestval = 0;
		$db->ExecuteNoneQuery("UPDATE  #@__group_threads SET digest='$digestval' WHERE tid='$ID'");
	}
}else if($action=="close"){
	//关闭
	$rs = $db->GetOne("SELECT closed FROM #@__group_threads WHERE tid='".$ID."'");	
	if(is_array($rs)){
		if(!$rs['closed']) $closeval = 1;
		else $closeval = 0;
		$db->ExecuteNoneQuery("UPDATE  #@__group_threads SET closed='$closeval' WHERE tid='$ID'");
	}
}else if($action=="top"){
	//置顶
	$rs = $db->GetOne("SELECT displayorder FROM #@__group_threads WHERE tid='".$ID."'");	
	if(is_array($rs)){
		if(!$rs['displayorder']) $displayval = 1;
		else $displayval = 0;
		$db->ExecuteNoneQuery("UPDATE  #@__group_threads SET displayorder='$displayval' WHERE tid='$ID'");
	}	
}
//排序方法
$wheresql = "WHERE tid>0";
$sqlorders = "ORDER BY displayorder DESC,";
if($orders=="digest") $wheresql .= " AND digest=1"; 
if($orders=="close") $wheresql .= " AND closed=1";
if(!empty($keyword)) $wheresql .= " AND subject like '%".$keyword."%'";
if(!empty($username)) $wheresql .= " AND (author like '%".$username."%' OR lastposter like '%".$username."%')";
if($orders=="rep")	$sqlorders = "ORDER BY replies DESC,"; 
$sqlorders .= " dateline DESC";
//
$sql = "SELECT * FROM #@__group_threads $wheresql $sqlorders";
$dlist = new DataList();
$dlist->pageSize = 20;
$dlist->SetParameter("username",$username);
$dlist->SetParameter("orders",$orders);
$dlist->SetParameter("keyword",$keyword);
$dlist->SetSource($sql);
include(dirname(__FILE__)."/templets/group_threads.htm");
$dlist->Close();
$db->Close();
?>