<?php
require_once(dirname(__FILE__)."/config.php");
require_once(dirname(__FILE__)."/../include/pub_datalist_dm.php");
require_once(dirname(__FILE__)."/../include/inc_functions.php");
CheckPurview('group_Edit');
if(!isset($gid)) $gid = NULL;
$gid = ereg_replace("[^0-9]","",$gid);
if(!isset($ID)) $ID = NULL;
$ID = ereg_replace("[^0-9]","",$ID);
if($gid < 1){
	ShowMsg("含有非法操作!.","-1");
	exit();
}
$db = new DedeSql(false);
//操作
if(!isset($action)) $action = NULL;
if($action=="del"){
	if($ID > 0)	$db->ExecuteNoneQuery("DELETE FROM #@__group_guestbook WHERE bid='$ID'");	
}else if($action=="save"){
	if($ID > 0){
		$row = $db->GetOne("SELECT * FROM #@__group_guestbook WHERE bid='$ID'");
		if(empty($message)) $message = $row['message'];
		if(empty($title))		$title = $row['title'];
		$db->ExecuteNoneQuery("UPDATE #@__group_guestbook SET message='".$message."',title='".$title."' WHERE bid='$ID'");
	}
}else if($action=="edit"){
	$row = $db->GetOne("SELECT * FROM #@__group_guestbook WHERE bid='$ID'");
	$title = $row['title'];
	$message = $row['message'];
}
if(!isset($keyword)) $keyword = NULL;
if(!isset($username)) $username = NULL;
//列表加载模板
$wheresql = "WHERE gid='{$gid}'";
if(!empty($keyword)) $wheresql .= " AND	(title like '%".$keyword."%' OR message like '%".$keyword."%')";
if(!empty($username)) $wheresql .= " AND uname like '%".$username."%'";
$sql = "SELECT * FROM #@__group_guestbook $wheresql ORDER BY stime DESC";
$dlist = new DataList();
$dlist->pageSize = 20;
$dlist->SetParameter("keyword",$keyword);
$dlist->SetParameter("username",$username);
$dlist->SetParameter("gid",$gid);
$dlist->SetSource($sql);
include(dirname(__FILE__)."/templets/group_guestbook.htm");
$dlist->Close();
$db->Close();
ClearAllLink();
?>