<?php
require_once(dirname(__FILE__)."/config.php");
if(!$cfg_ml->IsLogin()){
	ShowMsg("未登录前不充许该操作！","-1");
	exit(); 
}
$id = ereg_replace("[^0-9]","",$id);
if($id < 1) {
	ShowMsg("错误,未定义的操作！","-1");
	exit(); 
}
$db = new DedeSql(false);
if(!isset($action)) $action = '';

if($action=="save"){
	$svali = GetCkVdValue();
  if(strtolower($vdcode)!=$svali || $svali==""){
  	$db->Close();
  	ShowMsg("认证码错误！","-1");
  	exit();
  }
  $subject = cn_substr(trim(ClearHtml($subject)),80);
  $text = eregi_replace("<(iframe|script)","",$text);
	if(CountStrLen($text)<3||CountStrLen($text)>1000){
		$db->Close();
		ShowMsg("内容字数应该在3-1000个汉字！","-1");
		exit();
	}
	if(ereg("$cfg_notallowstr",$subject)||ereg("$cfg_notallowstr",$text)){
		$db->Close();
		ShowMsg("含有非法字符！","-1");
		exit();
	}
	$subject = preg_replace("/$cfg_replacestr/","***",$subject);
	$text = preg_replace("/$cfg_replacestr/","***",$text);
	$userip = GetIP();
	$SetQuery = "INSERT INTO #@__group_guestbook(gid,title,uname,userid,stime,message,ip) ";
	$SetQuery .= "VALUES('$id','$subject','".$cfg_ml->M_UserName."','".$cfg_ml->M_ID."','".time()."','$text','$userip');";
	if($db->ExecuteNoneQuery($SetQuery)){
		$db->Close();
		ShowMsg("留言成功！","guestbook.php?id={$id}");
		exit();
	}else{
		$db->Close();
		ShowMsg("出错了！","-1");
		exit();
	}
}
$rs = $db->GetOne("SELECT * FROM #@__groups WHERE groupid='$id'");
if(!is_array($rs)){
	$db->Close();
	ShowMsg("圈子不存在,或被删除！","-1");
	exit(); 
}else if($rs['ishidden']){
	$db->Close();
	ShowMsg("圈子被管理员屏蔽中！","-1");
	exit();
}
$master = $rs['ismaster'];
$title = $rs['groupname'];
//检测管理员
$ismaster    = @explode(",",$master);
$userid	= $rs['uid'];
$smalltype = $rs['smalltype'];
$ismaster	 = in_array($cfg_ml->M_UserName,$ismaster);
if(empty($cfg_ml->M_UserName)) $ismaster = 0;
$des = $rs['des'];
require_once(dirname(__FILE__)."/templets/guestbookform.htm");
$db->Close();
?>