<?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[1][0]);
$CONST_USER = gbookUser;$CONST_PWD = gbookPwd;
$action = getForm("action", "get");
$keyword = getForm("keyword", "both");
switch ($action) {
	case "del" : delNews();break;
	case "delgbook" : delGbook();break;
	case "delall" : delAll();break;
	case "delallgbook" :  delAllGbook();break;
	case "reporterror" : reportError();break;
	case "deltotalgbook": delTotalGbook();break;
	case "viewinfo":viewInfo();break;
	default:main();break;
}
viewFoot();

function main() {
	global $action,$keyword,$CONST_USER,$CONST_PWD,$menuList;
	$id = getForm("id","get");
	$page = getForm("page","get") ;
	$where = getForm("where","get") ;
	$keyword = unescape($keyword);
    $number = 30;
	$orderStr = " ORDER BY m_id DESC";
	if ($where == "gbook") {
		$whereStr = "`m_replyid`=0"; 
	} else {
		$whereStr = "`m_type`='$where'";
	}
	if (!empty($keyword)) {
		if ($where != "gbook") {
			$whereStr .= " AND (`m_title` LIKE '%$keyword%' OR `m_content` LIKE '%$keyword%' OR `m_ip` LIKE '".replaceStr($keyword,"*","%")."')";
        } else {
			$whereStr .= " AND (`m_content` LIKE '%$keyword%' OR `m_ip` LIKE '".replaceStr($keyword,"*","%")."')";
        }
    }
	if ($where == "gbook") {
		$sqlStr = "SELECT m_id,m_author,m_content,m_addtime,m_ip FROM ".DB::table('leaveword')." WHERE $whereStr$orderStr";
		dsetcookie("loginflag", gbookUser.gbookPwd, 3600 * 24);
	} else {
		 $sqlStr = "SELECT m_id,m_author,m_title,m_addtime,m_ip,m_content,m_videoid,m_color,m_hit,m_type FROM ".DB::table('info')." 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[1][0]?>&nbsp;&raquo;&nbsp;<?=echoNewsType($where)?>';</script>
<?php
if ($allRecordset > 0) {
?>
<table class="tb">
<tr class="thead"><th colspan="8"><em style="font-weight:bold"><?=echoNewsType($where)?></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);" /></em></th></tr>
<form name="newslistform" method="post">
<tr><td>ID </td><td><?php if ($where == "reporterror") {?>报错内容<?php } else if ($where == "gbook") {?>留言内容<?php }?> </td>
<?php if (empty($where)){?><td>点击率</td><?php }?>
<?php if ($where == "reporterror") {?><td>错误数据名称(ID)</td><?php }?> 
<?php if ($where == "reporterror") {?><td>报错IP </td><?php }?>
<td>时间 </td><td><?php if ($where == "reporterror") {?>报错者<?php } else if ($where == "gbook") {?>留言人<?php }?></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'];
    if ($where != "gbook") {
?> 
    <tr bgcolor="#ffffff" ><td><input type="checkbox" value="<?=$m_id?>" name="m_id[]"  class="checkbox" /><?=$m_id?> </td><?php if (!empty($where)){?><td >
		<?=showFace(encodeHtml(msubstr($row['m_content'],40)))?><a href="?action=viewinfo&type=<?=$where?>&m_id=<?=$m_id?>">查看详情</a> </td>
    <?php } else { ?>
    <td><a href="<?=getNewsContentLink($row['m_id'],$row['m_addtime'])?>" target="_blank"><?=msubstr($row['m_title'],40)?></a></td>
    <?php }?>
	<?php } else { ?>
	<tr bgcolor="#ffffff" ><td><input type="checkbox" value="<?=$m_id?>" name="m_id[]"  class="checkbox" /><?=$m_id?> </td><td title="<?=$row['m_content']?>"><?=showFace(msubstr($row['m_content'],40))?></td>
	<?php }?>
   <?php if ($where == "reporterror") {?><td>
                <?php
                $vrow = DB::fetch_first("SELECT m_id,m_name,m_type,m_enname,m_datetime FROM ".DB::table('data')." WHERE m_id='".$row['m_videoid']."'");
                if (is_array($vrow)) {
					if ($where == "reporterror") {
				?>
				<a href='<?=getPlayLink2($vrow['m_type'], $vrow['m_id'],$vrow['m_enname'],$vrow['m_datetime'],0,0)?>' target='_blank'><?=$vrow['m_name']?></a>
				(<?=$vrow['m_id']?>)<a href='admin_video.php?action=edit&id=<?=$row['m_videoid']?>'> <font color="#FF0000">处理</font></a></td>
				<?php
					} else {
                   ?>
				<a href='<?=getContentLink($vrow['m_type'], $vrow['m_id'],$vrow['m_enname'],$vrow['m_datetime'], "")?>' target='_blank' ><?=$vrow['m_name']?>(<?=$vrow['m_id']?>)</a></td>
                <?php
					}
				} else { 
					echo "该数据已删除</td>";
				}
			}
	?>
    <?php if ($where == "reporterror"){?><td><?=$row['m_ip']?></td><?php }?><td><?=isCurrentDay($row['m_addtime'])?></td><td>
<?=$row['m_author']?> 
 </td><td> 
     <a onClick="if(confirm('确定要删除吗')){return true;}else{return false;}" <?php if ($where == "gbook"){?>href="?action=delgbook&id=<?=$m_id?>" <?php } else {?>href="?action=del&id=<?=$m_id?>"<?php }?> >删除</a></td></tr>
<?php }?>	
		
    <tr>
    <td colspan="5">全选<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='?<?php if ($where=="gbook"){?>action=delallgbook'<?php }else{?>action=delall'<?php }?>;}else{return false}" class="btn"  />
    <?php if ($where=="gbook") {?>
    <input type="submit" value="全部删除" onClick="if(confirm('确定要删除全部吗')){newslistform.action='?action=deltotalgbook'}" class="btn"/>
    <?php }?>
&nbsp;&nbsp;<?=fPageCount($allRecordset, $number, $page)?></tr>
</form>
</table>
<?php 
    } else { 
?> 
 <table class='tb'><tr><td>没有记录</td></tr></table>
<?php 
    }
}

function viewInfo() {
	$id = getForm("m_id","get");$viewType = getForm("type","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('info')." WHERE m_id=$id");
if (is_array($row)) { 
	echo replaceStr(showFace(encodeHtml(msubstr($row['m_content'],40))),chr(13)&chr(10),"<br/>");
} else {
	echo "没有找到记录";
}
?> 
</td></tr>
<tr><td><input type="button" value="返    回" onClick="self.location.href='<?=getRefer()?> '" class="btn" /></td></tr>
</table>
<?php
}

function delAll() {
	$id = getForm("m_id","post");
	DB::delete('info', 'm_id IN ('.dimplode($id).')');
	alertMsg("",getRefer());
}

function delAllGbook() {
	$id = getForm("m_id","post");
	DB::delete('leaveword', 'm_id IN ('.dimplode($id).')');
	alertMsg("",getRefer());
}

function delTotalGbook() {
	DB::delete('leaveword');
	alertMsg("",getRefer());
}

function delNews() {
	$id = getForm("id","get");
	DB::delete('info', array('m_id' => $id));
	alertMsg("", getRefer());
}

function delGbook() {
	$id = getForm("id","get");
	DB::delete('leaveword', array('m_id' => $id));
	alertMsg("", getRefer());
}

function reportError() {
	$where = getForm("where","get");
	main();
}

function echoNewsType($str) {
	if($str == 'reporterror') {
		echo "报错处理";
	} else if ($str == 'gbook') {
		echo "留言管理";
	}
}
?>
