<?php
/**
 * @version        Somao_Search X1.0 9:23 2012-1-1 Somao $
 * @package        Somao_Search.Site
 * @copyright      Copyright (c) 2009 - 2012, Somao, Inc.
 * @license        http://www.somao123.com/
 * @link           http://www.somao.cc/
 */
require_once("global.php");
CheckPurview('msgadmin',$authoritys,$rank);
$action=HtmlReplace($_GET["action"]);
$gid=intval($_GET['gid']);

if($action=="savegbform"){
	$replymsg=HtmlReplace($_POST["replymsg"]);
	$replyid=intval($_POST["replyid"]);
	$replyadmin=intval($_POST["replyadmin"]);
	if(empty($replymsg)){
	    jsalert ("请填写回复内容!","guestbook.php");
		exit();
	  }
	  $array=array('replymsg'=>$replymsg,'replyid'=>$replyid,'replyadmin'=>$replyadmin,'reply_time'=>time());
	  $db->insert("ve123_guestbook",$array);
	  jsalert ("提交成功!");
	  exit();

}

if($action=="editsave"){
	$title=Html2Text($_POST["title"]);
	$msg=HtmlReplace($_POST["msg"]);
	$gid=intval($_POST["gid"]);
    if(empty($title)||empty($msg)){
	    jsalert ("请填写标题和内容!","guestbook.php");
		exit();
	}
	$array=array('title'=>$title,'msg'=>$msg,'addtime'=>time());
	$db->update("ve123_guestbook",$array,"gid='$gid'");
	jsalert("修改成功","guestbook.php");
	exit();
}
if($action=="del"){
	$db->query("DELETE FROM ve123_guestbook WHERE gid='$gid'");
	$db->query("DELETE FROM ve123_guestbook WHERE replyid='$gid'");
    jsalert("删除成功");
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gbk">
<meta http-equiv="x-ua-compatible" content="ie=7" />
<link href="css/admincp.css" rel="stylesheet" type="text/css" />
<style>
<!--
.reply{border:1px dashed #cccccc;padding:5px;color:#666666;margin:5px;}
.replys{border:1px dashed #cccccc;padding:5px;color:#ff0000;margin:5px;}
-->
</style>
<script language="JavaScript">
function ResetReplyTitle(no, title) {
        document.gbform.title.value='回复' + no + '：' + title;	
		document.gbform.replyid.value=no;
		document.gbform.msg.focus();
        return true;
}
function checkgbform()
{
   if(document.gbform.title.value=="")
   {
       alert("标题不能为空！");
       document.gbform.title.focus();
	   return false;
   }
    if(document.gbform.msg.value=="")
   {
       alert("内容不能为空！");
       document.gbform.msg.focus();
	   return false;
   }
}
</script>
</head>
<body>
<div class="container">
  <div class="floattop">
    <div class="itemtitle"><h3>留言管理</h3>
      <ul class="tab1">
        <li class="current"><a href="guestbook.php"><span>管理列表</span></a></li>
      </ul>
     </div>
   </div>
 <div class="floattopempty"></div>

<?php if($action=="edit"){
	$rowt=$db->get_one("select * from ve123_guestbook where gid='".$gid."' ");
	?>
	<a name="edit" id="edit"></a>
	<form id="gbform" name="gbform" method="post" action="?action=editsave" onSubmit="return checkgbform();">
    <input type="hidden" name="gid" value="<?php echo $gid;?>">
      <table class="tb tb2 ">
        <tr>
          <td width="80">标题：</td>
          <td><input name="title" type="text" size="50" value="<?php echo $rowt["title"];?>"/></td>
        </tr>
        <tr>
          <td>内容：</td>
          <td><textarea name="msg" cols="80" rows="10"><?php echo $rowt["msg"];?></textarea></td>
        </tr>
        <tr>
          <td>&nbsp;</td>
          <td>
		  <input type="submit" name="Submit" value="提交留言"/></td>
        </tr>
      </table>
      </form>
<?php }elseif($action=="reply"){
    $rowt=$db->get_one("select * from ve123_guestbook where gid='".$gid."' ");
	?>
    <a name="replyid" id="replyid"></a>
	<form id="gbform" name="gbform" method="post" action="?action=savegbform" onSubmit="return checkgbform();">
    <input type="hidden" name="replyid" value="<?php echo $gid;?>">
    <input type="hidden" name="replyadmin" value="1">
      <table class="tb tb2 ">
        <tr>
          <td width="80">原标题：</td>
          <td><?php echo $rowt["title"];?></td>
        </tr>
        <tr>
          <td>回复内容：</td>
          <td><textarea name="replymsg" cols="80" rows="10"></textarea></td>
        </tr>
	
        <tr>
          <td>&nbsp;</td>
          <td>
		  
		  <input type="submit" name="Submit" value="提交留言"/></td>
        </tr>
      </table>
      </form>
<?php }?>
<table class="tb tb2 ">
	<?php
	  $sql="select * from ve123_guestbook where replyid='0' ";
	  $result=$db->query($sql);
      $total=$db->num_rows($result);//记录总数
      $pagesize=10;//每页显示数
      $totalpage=ceil($total/$pagesize);
      $page=intval($_GET["page"]);
      if($page<=0){$page=1;}
      $offset=($page-1)*$pagesize;
      $sql=$sql." order by addtime desc,reply_time desc limit $offset,$pagesize";
	  $query=$db->query($sql);//echo $sql;
	while($row=$db->fetch_array($query))
	{
	?>
      <tr>
        <td width="50" align="center"><?php echo $row["gid"];?></td>
        <td class="p14"><font color=#0000cc><a target="_blank" href="f/?kz=<?php echo $row["gid"];?>"><font color=\"#3366CC\"><?php echo $row["title"];?></a></font></td>
      </tr>
	  <tr>
	    <td>&nbsp;</td>
	  <td class="gray14"><?php echo str_cut(str_replace("<br/>","",$row["msg"]),200);?>
      <?php echo g_replymsg_admin($row["gid"]); ?>
	  <?php echo g_replymsg($row["gid"]); ?>
	  </td>
	  </tr>
	  <tr>
	    <td></td>
	  <td height="10"></td>
	  </tr>
	  	  <tr>
	  	    <td class="au">&nbsp;</td>
	  <td class="au"><div class="uau">作者：
	  <?php
	  $reg = '/((?:\d+\.){3})\d+/';
	  echo preg_replace($reg, "\\1*", $row["ip"]);
	   ?>
	  </div>
	  <div class="uau2"><font class="gray12"><?php echo date("Y-m-d H:i",$row["addtime"]);?></font>　
        <a href="?action=reply&gid=<?php echo $row["gid"];?>#replyid" class=t><font color=\"#3366CC\">回复</a>&nbsp;
        <a href="?action=edit&gid=<?php echo $row["gid"];?>#edit" class=t><font color=\"#3366CC\">修改</a>&nbsp;
        <a href="?action=del&gid=<?php echo $row["gid"];?>" class=t><font color=\"#3366CC\">删除</a>&nbsp;</div></td>
	  </tr>
      <tr>
        <td>&nbsp;</td>
        <td><hr class="fenge" align=left width="100%" size=1 ></td>
      </tr>
	  <?php
	  }
	  ?>
   <tr>
    <td height="36" colspan="10" align="center" bgcolor="#F9FCEF">
   
<?php
echo pageshow($page,$totalpage,$total,"?");
?>
    </td>
  </tr>
  </table>

</div>
</body>
</html>