<? require "../../admin_header.php"?>
<?
/**
 * @version		1.0
 * @package		HonoWeb->HonoBBS
 * @copyright	Copyright (C) HonoWeb. All rights reserved.
 * @Website		www.honoweb.com.
 */
 ?>
<?
	//delete
	$status=$_POST['status'];
	if($status=="remove")
	{
		$id=$_POST['id'];
		$sql=" select * from ".$TableBbs_answer."  where id=".$id;
		$row=$db->getRow($sql);
		$FileName=$UploadPath."upload/bbs/".$TableBbs_answer."/".$row['id'].$row['picture'];
		if(file_exists($FileName))
		{
			 unlink($FileName);
		}
	    $sql="delete from ".$TableBbs_answer."   where id=".$id;
	    $query=$db->query($sql);
	}
	//delete 
	if($status=="removeSelect")
	{
	  $checkednums=array();
	  $ids=$_POST['ids'];
	  $checkednums=explode('.',$ids);
	  $filter="";
	  for($i=0;$i<count($checkednums)-2;$i++)
	  {
	     	$filter=$filter.$checkednums[$i].",";
	  }
	  $filter=$filter.$checkednums[count($checkednums)-2].")";
	  $sql=" select * from ".$TableBbs_answer."  where id in (".$filter;
	  $results=$db->getAll($sql);
	  for($i=0;$i<count($results);$i++)
	  {
	     	$FileName=$UploadPath."upload/bbs/".$TableBbs_answer."/".$results[$i]['id'].$results[$i]['picture'];
			if(file_exists($FileName))
			{ 
				 unlink($FileName);
			}
	  }
	  $sql="delete from  ".$TableBbs_answer."  where id in (".$filter;
	  $query=$db->query($sql);
	}
	$page=$_POST['page'];
	if(empty($page))
    	{$page=1;}
    else
    {
		 if($page<1){ $page=1;}
	}
             $b=false;
             $filter="";
             $cid=$_GET['cid'];
             $fvalue=$cid;
             if(!empty($fvalue))
             {
                 if($b)
                     $filter.=" and";
                 $filter.=" cid = ".$fvalue." ";
                 $b=true;
             }
             $bcategoryid=$_POST['bcategoryid'];
             $fvalue=$bcategoryid;
             if(!empty($fvalue))
             {
                 if($b)
                     $filter.=" and";
                 $filter.=" bcategoryid = ".$fvalue." ";
                 $b=true;
             }
             $categoryid=$_POST['categoryid'];
             $fvalue=$categoryid;
             if(!empty($fvalue))
             {
                 if($b)
                     $filter.=" and";
                 $filter.=" categoryid = ".$fvalue." ";
                 $b=true;
             }
             $username=$_POST['username'];
             $fvalue=$username;
             if(!empty($fvalue))
             {
                 if($b)
                     $filter.=" and";
                 $filter.=" username = '".$fvalue."' ";
                 $b=true;
             }
             $content=$_POST['content'];
             $fvalue=$content;
             if(!empty($fvalue))
             {
                 if($b)
                     $filter.=" and";
                 $filter.=" content = '".$fvalue."' ";
                 $b=true;
             }
             $publictime=$_POST['publictime'];
             $fvalue=$publictime;
             if(!empty($fvalue))
             {
                 if($b)
                     $filter.=" and";
                 $filter.=" TO_DAYS(publictime) = TO_DAYS('".$fvalue."') ";
                 $b=true;
             }
             $picture=$_POST['picture'];
             $fvalue=$picture;
             if(!empty($fvalue))
             {
                 if($b)
                     $filter.=" and";
                 $filter.=" picture = '".$fvalue."' ";
                 $b=true;
             }
	$sql="select * from  ".$TableBbs_answer;
	$sql1="select count(*) as num from  ".$TableBbs_answer;
	if($b)
	{
		$sql.=" where ".$filter."  order by id desc  limit ".(($page-1)*$pagenum).",$pagenum";
		$sql1.=" where ".$filter."  order by id desc  ";
	}
	else
	{
		$sql.="  order by id desc  limit ".(($page-1)*$pagenum).",$pagenum";
		$sql1.="   order by id desc  ";
	}
	$result=$db->getAll($sql);
	$row=$db->getRow($sql1);
	$totalnum=$row['num'];
	$page_num=ceil($totalnum/$pagenum);
?>
<html>
<head>
<title><?=$bbs_config_row['bbs_name']?></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link href="../../css/css.css" rel="stylesheet" type="text/css">
<script language="javascript" src="../../js/check.js"></script>
</head>
<body>
<form name="form1" method="post" >
  <table border="0" cellpadding="0"  cellspacing="0" class="firsttable">
    <tr>
      <td align="center" valign="top">
	  	<table   class="centertable">
      		<tr>
            	<td>&nbsp;
            	</td>
       		</tr>
        	<tr>
       		  <td align="center" valign="top">
				  <table class="containContentsTable">
              			<tr align="right">
           				  <td colspan="2" >
回复内容:
  <input type="text" size=10 name="content" value="<?=$content?>">
<input name="button" type='button'  class='button' onClick="javascript:query()" value='查询' >
           				  </td>
       				    </tr>
              			<tr>
               				 <td colspan="2">
								<?
								echo "<table  class='contentsTable' border='0'  cellpadding='0'  cellspacing='1'>";
								echo "<tr class='tr1'  align=center ><td width=5% ></td><td>回复人</td><td>回复内容</td><td>回复日期</td><td width='20%' >&nbsp;</td></tr>";
								for($i=0;$i<count($result);$i++)
								{
				  					echo "<tr   onMouseOver=\"old_bg=this.getAttribute('bgcolor');this.setAttribute('bgcolor', '".$T_Bgcolor[1]."', 0);\" onMouseOut=\"this.setAttribute('bgcolor', old_bg, 0);\" bgColor='".$T_Bgcolor[2]."' >";
				  					echo "<td><input type='checkbox' name=checkvalue value='".$result[$i]['id']."'></td>";
				  					echo "<td>".$result[$i]['username']."</td>";
				  					echo "<td>".$result[$i]['content']."</td>";
				  					echo "<td>".FormatDate($result[$i]['publictime'])."</td>";
				  					echo "<td align='center'><a   href='javascript:remove(".$result[$i]['id'].")'>删除</a></td></tr>";
								}
				 				echo "</table>";
								?>
                			        </td>
              			</tr>
              			<tr>
						<td>
							  <input name="cboAll" type="checkbox" id="cboAll" value="checkbox" onClick="checkBoxAll()">
							  选择所有
						      <input name="button2" type='button'  class='button' style='width:80px' onClick="javascript:removeSelect()" value='删除' ></td>
						<td align="right">共
                          <?=$totalnum?>
条, 共
<?=$page_num?>
页, 第
<?=$page?>
页 <a href="javascript:first()">第一页</a> <a href="javascript:next()">下一页</a> <a  href="javascript:pre()">上一页</a> <a  href="javascript:last()" >最后一页</a>
<select name="position" id="position"  onChange="goposition()">
  <option value=""></option>
  <?
					     			for($i=1;$i<=$page_num;$i++)
					     			{
						   			echo "<option ";
						   				if(page==$i){echo "selected";}
						   					echo " value=$i>";
						   					echo $i;
						   					echo "</option>" ;
					     			}
					     	?>
</select></td>
           			</tr>
                      </table>
					</td>
                  </tr>
				<tr>
                    <td></td>
				</tr>
              </table>
	      </td>
      </tr>
</table>
  <input type="hidden" name="status" value="">
  <input type="hidden" name="page" value=<?=$page?>>
  <input type="hidden" name="totalpage" value=<?=$page_num?>>
   <input type="hidden" name="id" value="">
   <input type="hidden" name="cid" value="<?=$cid?>">
   <input type="hidden" name="ids" value="">
</form>
</body>
</html>
<script language="JavaScript" type="text/JavaScript">
	function checkBoxAll()//全选
	{
		var form = form1;
		for(i=0; i<form.elements.length; i++)
		{
			if(form.elements[i].type=="checkbox" &&  form.elements[i].name=="checkvalue")
			{
				form.elements[i].checked = form.cboAll.checked;
			}
		}
	}

	function edit(id){
		var form=form1;
		form.id.value=id;
		form.action="bbs_answeredit.php";
		form.submit();
	}

	function look(id){
		var form=form1;
		form.id.value=id;
		form.action="bbs_answerlook.php";
		form.submit();
	}

	function remove(id){
		if(confirm("真的想要删除吗?")==true){
			var form=form1;
			form.id.value=id;
			form.status.value="remove";
			form.submit();
		}
	}

	function removeSelect(){
		var form=form1;
		for(i=0; i<form.elements.length; i++)
		{
			if(form.elements[i].type=="checkbox" &&  form.elements[i].name=="checkvalue")
			{
				if(form.elements[i].checked==true)
				{
					form.ids.value+=form.elements[i].value+".";
				}
			}
		}
		if(form.ids.value=="")
		{
			alert("请选择记录!");
			return;
		}
		if(confirm("真的想要删除吗?")==false)
			return;
		form.status.value="removeSelect";
		form.submit();
	}

	function add(){
		location="bbs_answeradd.php";
	}

	function query()
	{
		var form=form1;
		form.submit();
	}

	function first()
	{
		var form=form1;
		if(eval(form.page.value)==1)
			return;
		form.page.value=1;
		form.submit();
	}

	function next()
	{
		var form=form1;
		if(eval(form.page.value)>=eval(form.totalpage.value))
			return;
		form.page.value=eval(form.page.value)+1;
		form.submit();
	}

	function last()
	{
		var form=form1;
		if(eval(form.page.value)==eval(form.totalpage.value))
			return;
		form.page.value=eval(form.totalpage.value);
		form.submit();
	}

	function pre()
	{
		var form=form1;
		if(form.page.value<=1)
			return;
		form.page.value=eval(form.page.value)-1;
		form.submit();
	}

	function  goposition()
	{
		var form=form1;
		form.page.value=form.position.value;
		form.submit();
	}
</script>
<? $db->close_db();?>
