<?

error_reporting(0);
require_once('data.php');
require_once('../inc/config.php');

function check_out($msg){
	$msg = str_replace('&amp;','&',$msg);
	$msg = str_replace('&nbsp;',' ',$msg);
	$msg = str_replace('"','&quot;',$msg);
	$msg = str_replace("'",'&#39',$msg);
	$msg = str_replace("\t","   &nbsp;  &nbsp;",$msg);
	$msg = str_replace("<","&lt;",$msg);
	$msg = str_replace(">","&gt;",$msg);
	$msg = str_replace("\r","",$msg);
	$msg = str_replace("\n","<br />",$msg);
	$msg = str_replace("|","│",$msg);
	$msg = str_replace("   "," &nbsp; ",$msg);
	return $msg;
}
function write($f,$infoata,$method="w") {
	$filenum=@fopen($f,$method);
	@flock($filenum,LOCK_EX);
	$file_data=@fwrite($filenum,$infoata);
	@fclose($filenum);
	return $file_data;
}
function read($f) {
	$filenum=@fopen($f,"r");
	@flock($filenum,LOCK_SH);
	$file_data=@fread($filenum,filesize($f));
	@fclose($filenum);
	return $file_data;
}
function PageNav($maxpageno,$sum,$page,$url,$colspan){
echo "<tr class=\"firstalt\"><td colspan=$colspan align=right>";
if ($maxpageno<=1) echo " 共有记录 {$sum} 条 | 只有一页";
else { 
      $nextpage=$page+1;
      $previouspage=$page-1;
	  echo " 共有记录 {$sum} 条 | ";
	  if ($page<=1) echo " 首页　上一页　<a href={$url}page=$nextpage>下一页</a>　<a href={$url}page=$maxpageno>尾页</a> ";
	  elseif($page>=$maxpageno) echo " <a href={$url}page=1>首页</a>　<a href={$url}page=$previouspage>上一页</a>　下一页　尾页 ";
	  else echo " <a href={$url}page=1>首页</a>　<a href={$url}page=$previouspage>上一页</a>　<a href={$url}page=$nextpage>下一页</a>　<a href={$url}page=$maxpageno>尾页</a> ";
	  echo " | $page/$maxpageno  20个/页 ";
  }
  echo"</td></tr>";
}
function get_attm_list($page){
       if(empty($page) or $page<=0) $page=1;
       settype($page, integer);
	   
       $attmlist=file("../db/attachment/list.php");
	   $l=count($attmlist);
	   if($l!=0 && file_exists("../db/attachment/list.php")){
		for ($i=0; $i<$l; $i++) {
	           $detail=explode("|",$attmlist[$i]);
               $pubtime=$detail[2]."&nbsp;".$detail[3];
			   echo '<tr align=center class="firstalt"><td><a  target="_blank" title="点击预览" href="../html.php?id='.$detail[4].'">'.$detail[4].'</a></td><td >'.$detail[1].'</td><td >'.$pubtime.'</td><td style="text-align:center"><a href="?action=del&attid='.$detail[4].'&id='.$detail[0].'">删除</a></td></tr>'."\r\n";
			   if(empty($detail[0]) || $detail[0]==''){
			   break;
			   }
			  
	       }
	   }
	   else{
	       echo '<tr align=center class="firstalt"><td colspan=4>暂时还没有评论信息</td></tr>';
	   }
	   $pageurl="editattm.php&";
       PageNav($maxpageno,$l,$page,$pageurl,4);
}

if($_COOKIE['x_Cookie']!=$adminname or $_COOKIE['y_Cookie']!=md5($password)){
	echo"<script>location.href='index.php';</script>";
	exit;
}
function filedate( $flietime ){    
$_flietime = date( "Y-m-d H:i:s", @filemtime( $flietime ) );    
return $_flietime;
}
$page=$_GET['page'];
?>
<!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=gb2312">
<link rel="stylesheet" type="text/css" href="css/admin.css">
</head>
<body>

<div class="right">
   <? include_once "welcome.php";?>
  <div class="right_main">
      <table width="98%" border="0" cellpadding="4" cellspacing="1" class="tableoutline">
        <tr class="tb_head">
          <td colspan="5"><h2>评论管理：</h2></td>
        </tr>
        <tr align=center class="firstalt">
          <td width="10%" >文章ID</td>
          <td width="50%" >评论内容</td>
          <td width="20%" nowrap>发表时间</td>
          <td width="20%" nowrap>操作</td>
        </tr>
        <?php get_attm_list($page);?>
		</table>

  </div>
</div>
<?php
$action=$_GET['action'];
if($action=='del'){
    $delid = $_GET['id'];
	$attid = $_GET['attid'];
	$attm= file("../db/attachment/$attid.php");
	 for($a=0;$a<count($attm);$a++)
			{
				$info=explode("|",$attm[$a]);
				if($info[0]==$delid)
					{
						unset($attm[$a]);
						break;
					}
			}
		write("../db/attachment/$attid.php",implode("",$attm));
		if(empty($attm)) unlink("../db/attachment/$attid.php");
	 $attm_list= file("../db/attachment/list.php");
	 for($a=0;$a<count($attm_list);$a++)
			{
				$info_list=explode("|",$attm_list[$a]);
				if($info_list[0]==$delid)
					{
						unset($attm_list[$a]);
						break;
					}
			}
		write("../db/attachment/list.php",implode("",$attm_list));
		if(empty($attm_list)) unlink("../db/attachment/list.php");
		echo "<script>alert('删除成功!');location.href='editattm.php';</script>";
}
?>
<? include "footer.php"; ?>
</body>
</html>