<?php
require_once(dirname(__FILE__)."/admin_inc.php");
/*******************************************************************************************
' Software name: DJCMS Content Management System
' Version:3.0
' Web: http://www.djcms.net
' Author: 心情(qq:1130731)
' Copyright (C) 2009-2010 DJCMS官方 版权所有
' 法律申明：DJCMS程序所有代码100%原创、未引入任何网上代码,对一切抄袭行为、坚决严肃追究法律责任
'*******************************************************************************************/
viewHead("评论管理"."-" .$menuList[7][0]);
$action = getForm("action", "get");
$keyword = getForm("keyword", "both");$where = getForm("where","get");
if (is_numeric($where)){ $where = intval($where); } else { $where=1;}

switch ($action) {
	case "del" : delReview();break;
	case "delall" : delAll();break;
	case "comment" : comment();break;
	case "deltotalcomment":delTotalComment();break;
	case "viewinfo":viewInfo();break;
	case "verifypic":verifypic();break;
	default:main();break;
}
viewFoot();

function DeMessage($str){
	return showFacel("".$str);
}

function showFacel($m_content) {
	return preg_replace("/\[em:(.*?):\]/is","<img src=\"../comment/images/cmt/\\1.gif\" border=\"0\"/>", $m_content);
}

function main(){
	global $action,$where,$menuList,$keyword;
	$id = getForm("id","get");
	$page = getForm("page","get") ;
	$keyword = unescape($keyword);
    $number = 30;
	$orderStr = " ORDER BY m_id DESC";
    if (!empty($where)) {
		$whereStr = "`m_type`='$where'";
	}
	if (!empty($keyword)) {
		$whereStr .= " AND (m_content LIKE '%$keyword%' OR m_ip LIKE '".replaceStr($keyword,"*","%")."')";
    }
    $sqlStr = "SELECT m_id,m_pic,m_author,m_addtime,m_ip,m_content,m_videoid,m_reply,m_agree,m_type,m_check FROM ".DB::table('review')." WHERE $whereStr$orderStr";
	$allRecordset = db::getCount($sqlStr);
	$tpagecount = ceil($allRecordset / $number);
	if ($page > $tpagecount) $page = $tpagecount;
?>
<div id="append_parent"></div>
<div class="container" id="cpcontainer">
<!--当前导航-->
<script type="text/JavaScript">if(parent.$('admincpnav')) parent.$('admincpnav').innerHTML='后台首页&nbsp;&raquo;&nbsp;<?=$menuList[7][0]?>&nbsp;&raquo;&nbsp;评论管理';</script>
<?php
if ($allRecordset > 0) {
?>
<table class="tb">
<tr class="thead"><th colspan="8"><em style="font-weight:bold">评论管理</em><em style="color:#000;">&nbsp;&nbsp;&nbsp;关键字：<input name="keyword" type="text" id="keyword" size="20" value="<?=$keyword?>"> <input type="submit" name="selectBtn" value="查 询..." class="btn" onclick="location.href='?action=<?=$action?>&where=<?=$where?>&keyword='+escape($('keyword').value);" /><?php if ($where!="") echo "&nbsp;&nbsp;搜索IP:192.168.1.*";?></em></th></tr>
<form name="newslistform" method="post">
	<tr>
		<td>ID</td>
		<td>评论内容</td>
		<td>评论数据名称(ID)</td>
		<td>时间</td>
		<td>评论者IP</td>
		<td>操作</td>
	</tr>
    <?php
$page = max(intval($page), 1);
$offset = $number*($page-1);
$query = DB::query("$sqlStr LIMIT $offset, $number");
while($row = DB::fetch($query)) {
    $m_id = $row['m_id'];
	$m_title= trim($row['m_author']);
	$m_check=$row['m_check'];
	$m_content= DeMessage($row['m_content']);
?> 
	<tr bgcolor="#ffffff" >
		<td><input type="checkbox" value="<?=$m_id?>" name="m_id[]"  class="checkbox" /><?=$m_id?></td>
		<td> <?=$m_content?> <a href="?action=viewinfo&type=1&m_id=<?=$m_id?>">查看详情</a></td>
		<td><?php
		if ($where == 2){
			$vrow = DB::fetch_first("SELECT m_title,m_type,m_entitle,m_datetime FROM ".DB::table('news')." WHERE m_id='".$row['m_videoid']."'");
			$m_videoname = $vrow['m_title'];
		}else{
			$vrow = DB::fetch_first("SELECT m_name,m_type,m_enname,m_datetime FROM ".DB::table('data')." WHERE m_id='".$row['m_videoid']."'");
			$m_videoname = $vrow['m_name'];
		}
		if (!empty($m_videoname)){
			if ($where==2){
				echo "<a href=\"".getNewsArticleLink($vrow['m_type'],$row['m_videoid'],$vrow['m_entitle'],$vrow['m_datetime'],"")."\" target=\"_blank\">".$m_videoname."(".$row['m_videoid'].")</a></td>";
			}else{
				echo "<a href=\"".getContentLink($vrow['m_type'],$row['m_videoid'],$vrow['m_enname'],$vrow['m_datetime'],"")."\" target=\"_blank\">".$m_videoname."(".$row['m_videoid'].")</a></td>";
			}
		}else{
			echo "该数据已删除</td>";
		}
		?></td>
		<td><span title="<?=date('Y-m-d H:i:s',$row['m_addtime'])?>"><?=isCurrentDay($row['m_addtime'])?></span></td>
		<td><?=DeMessage($row['m_author'])."(".$row['m_ip'].")"?></td>
		<td><a onClick="if(confirm('确定要删除吗')){return true;}else{return false;}" href="?action=del&m_id=<?=$m_id?>" >删除</a><?php if ($m_check==0){?>&nbsp;<a href="?action=verifypic&m_id=<?=$m_id?>">通过审核</a><?php }?></td>
	</tr>
<?php }?>	
	<tr>
		<td colspan="8">全选<input type="checkbox" name="chkall" id="chkall" class="checkbox" onClick="checkAll(this.checked,'input','m_id[]')"/>反选
			<input type="checkbox" name="chkothers" id="chkothers" class="checkbox" onClick="checkOthers('input','m_id[]')"/>
			<input type="submit" value="批量删除" onClick="if(confirm('确定要删除吗')){newslistform.action='?action=delall';}else{return false}" class="btn"/>
			<input type="submit" value="全部删除" onClick="if(confirm('确定要删除全部吗')){newslistform.action='?action=deltotalcomment&where=<?=$where?>'}" class="btn"/>
			<input type="submit" value="批量通过审核" onClick="if(confirm('确定要审核吗')){newslistform.action='?action=verifypic';}else{return false}" class="btn"/></td>
	</tr>
	<tr>
		<td colspan="8"><?=fPageCount($allRecordset, $number, $page)?></td>
	</tr>
</form>
</table>
<?php } else {
	$back='';
    if ($keyword!="") $back=",<a href='javascript:history.go(-1)'><u>返回上一页</u></a>";
	    die("<table class='tb'><tr><td>没有记录".$back."</td></tr></table>");
    }
}

function viewInfo() {
	$id = getForm("m_id","get");
?>
<div class="container" id="cpcontainer">
<table class="tb">
<tr class="thead"><th colspan="2">评论详情查看</th></tr>
<tr><td>
<?php
$row = DB::fetch_first("SELECT m_content FROM ".DB::table('review')." WHERE m_id=$id");
if (is_array($row)) { 
    echo DeMessage($row['m_content']);
} else {
	echo "没有找到记录";
}
?> 
</td></tr>
<tr><td><input type="button" value="返    回" onClick="self.location.href='<?=getRefer()?> '" class="btn" /></td></tr>
</table>
<?php
}

function delAll(){
	$ids = getForm("m_id","both");
	DB::delete('review', 'm_id IN ('.dimplode($ids).')');
	alertMsg("",getRefer());
}

//<!--7.02开始-->
function delTotalComment(){
	global $where;
	$query = DB::query("SELECT m_id FROM ".DB::table('review')." WHERE m_type='$where'");
	while($row = DB::fetch($query)) {
		DB::delete('review', array('m_id' => $row['m_id']));
	}
	alertMsg("",getRefer());
}
//<!--7.02结束 -->
function delReview(){
	$id = getForm("m_id","both");
	DB::delete('review', array('m_id' => $id));
	DB::update('review', array('m_reply' => 0),array('m_reply' => $id));
	alertMsg("",getRefer());
}

function comment(){
	main();
}

function verifypic(){
	$id = getForm("m_id","both");
	if (!empty($id)){
		DB::update('review', array('m_check' => 1),'m_id IN ('.dimplode($ids).')');
	}
	alertMsg("",getRefer());
}
?>
