<?php

/*
'**************************************************************************************************
' 程序名称: CCTVAI开源音乐管理系统
' 官方网站: http://www.cctvai.com
' 联系 Q Q: 1542367792
' QQ交流群：136687984
' 版本：(终结版)
' 备注：未经书面授权，不得向任何第三方提供本软件系统！
' 功能，模板，插件，扩展，定制请联系QQ：1542367792
'**************************************************************************************************
*/
error_reporting(0);
include "../../include/cctvai.conn.php";
include "../function_common.php";
admincheck(4);
/*if(Smallfivesolution()==$_SERVER['SERVER_NAME']) {
} else {
	echo Smallfivesq();
	exit();
}*/
$action=SafeRequest("action", "get");
?>
<!DOCTYPE html>
<html>
 <head> 
  <meta charset="gbk" /> 
  <meta name="renderer" content="webkit" /> 
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" /> 
  <title>后台管理中心</title> 
  <link href="../css/add.css" rel="stylesheet" /> 
  <style type="text/css">
.table2{width: 100%;max-width: 100%;border-collapse: collapse;border-spacing: 0;}
.table2 td{font-size: 12px;border-top: 1px solid #ddd;padding: 8px;vertical-align: top;}
.table2 tr:hover{text-decoration: none;background-color: #e6f2fb;}
.table2 th{border-bottom: 2px solid #ddd;vertical-align: bottom;padding: 2px;text-align: left;}
.table3{width: 100%;max-width: 100%;border-collapse: collapse;border-spacing: 0;}
.table3 tr:hover{text-decoration: none;background-color: #e6f2fb;}
.table3 td{font-size: 12px;line-height:25px;border-top: 1px solid #ddd;padding: 5px;vertical-align: top;border-right: solid 1px #ddd;}
.table3 th{border-bottom: 2px solid #ddd;vertical-align: bottom;padding: 2px;text-align: left;}
</style>
 </head>   
 <body> <?php if($row['cd_channel']==1){echo "音乐";}else if($row['cd_channel']==2){echo "视频";}else if($row['cd_channel']==3){echo "歌手";}else if($row['cd_channel']==4){echo "音乐专辑";}else if($row['cd_channel']==5){echo "视频专辑";}else if($row['cd_channel']==6){echo "文章";}else if($row['cd_channel']==7){echo "相册";}else if($row['cd_channel']==8){echo "会员空间";} ?>
<?php
switch($action){
	case 'del':
		del();
		break;
	case 'alldel':
		alldel();
		break;
	case 'keyword':
		$key=SafeRequest("key","get");
		main("select * from ".tname('comment')." where cd_content like '%".$key."%' or cd_uname like '%".$key."%' order by cd_addtime desc",20);
		break;
	case 'play':
		main("select * from ".tname('comment')." where cd_channel=1 order by cd_addtime desc",20);
		break;
	case 'video':
		main("select * from ".tname('comment')." where cd_channel=2 order by cd_addtime desc",20);
		break;
	case 'singer':
		main("select * from ".tname('comment')." where cd_channel=3 order by cd_addtime desc",20);
		break;
	case 'malbum':
		main("select * from ".tname('comment')." where cd_channel=4 order by cd_addtime desc",20);
		break;
	case 'valbum':
		main("select * from ".tname('comment')." where cd_channel=5 order by cd_addtime desc",20);
		break;
	case 'news':
		main("select * from ".tname('comment')." where cd_channel=6 order by cd_addtime desc",20);
		break;
	case 'pic':
		main("select * from ".tname('comment')." where cd_channel=7 order by cd_addtime desc",20);
		break;
	case 'user':
		main("select * from ".tname('comment')." where cd_channel=8 order by cd_addtime desc",20);
		break;
	case 'blog':
		main("select * from ".tname('comment')." where cd_channel=9 order by cd_addtime desc",20);
		break;
	default:
		main("select * from ".tname('comment')." order by cd_addtime desc",20);
		break;
	}
?>
</body>
</html>
<?php
function main($sql,$size){
	global $db,$action;
	$Arr=getpagerow($sql,$size);
	$result=$db->query($Arr[2]);
	$videonum=$db->num_rows($result);
?>
<?php
if($action=="") {
	$x5='btn_success';
	$name="所有评论";
} elseif($action=="play") {
	$x51='btn_success';
	$name="音乐评论";
} elseif($action=="video") {
	$x52='btn_success';
	$name="视频评论";
} elseif($action=="malbum") {
	$x53='btn_success';
	$name="音乐专辑评论";
} elseif($action=="valbum") {
	$x54='btn_success';
	$name="视频专辑评论";
} elseif($action=="singer") {
	$x55='btn_success';
	$name="歌手评论";
} elseif($action=="news") {
	$x56='btn_success';
	$name="文章评论";
} elseif($action=="user") {
	$name="会员空间评论";
	$x57='btn_success';
} elseif($action=="pic") {
	$name="会员相册评论";
	$x58='btn_success';
} elseif($action=="blog") {
	$name="说说评论";
	$x59='btn_success';
} elseif($action=="keyword") {
	$key=SafeRequest("key","get");
	$name="搜索：".$key."";
} else {
	$x5='btn_success';
}
?>
<script type="text/javascript">
function CheckAll(form){
	for (var i=0;i<form.elements.length;i++){
		var e = form.elements[i];
		if (e.name != 'chkall')
			e.checked = form.chkall.checked;
	}
}
</script>
<div class="contents"> 
   <div class="panel"> 
    <div style="padding: 8px;"> 
     <a href="comment.php" class="btn <?php echo $x5;?>">所有评论</a> 
     <a href="?action=play" class="btn <?php echo $x51;?>">音乐</a> 
     <a href="?action=video" class="btn <?php echo $x52;?>">视频</a> 
     <a href="?action=malbum" class="btn <?php echo $x53;?>">音乐专辑</a> 
     <a href="?action=valbum" class="btn <?php echo $x54;?>">视频专辑</a> 
     <a href="?action=singer" class="btn <?php echo $x55;?>">歌手</a> 
     <a href="?action=news" class="btn <?php echo $x56;?>">文章</a> 
     <a href="?action=user" class="btn <?php echo $x57;?>">会员空间</a> 
	 <a href="?action=pic" class="btn <?php echo $x58;?>">相册</a>
	 <a href="?action=blog" class="btn <?php echo $x59;?>">说说</a>
    </div> 
   </div> 
  </div>
<div class="contents"> 
   <div class="panel"> 
    <div class="panel-head">
     <strong><?php echo $name?></strong>
    </div> 
  <form method="get" action="comment.php"> 
   <div class="search_type cc mb10"> 
    <div class="ul_wrap"> 
     <ul class="cc"> 
      <li> <label>关键字：</label> <input type="hidden" name="action" value="keyword"> <input name="key" id="key" value="" type="text" class="input length_3" placeholder="支持会员帐号,关键词"> &nbsp;&nbsp;<button class="btn mr20" type="submit">搜索</button> </li> 
     </ul> 
    </div> 
   </div> 
  </form>
<form name="form" method="post" action="?action=alldel">
    <table class="table2" id="dellist"> 
     <tbody>
      <tr>
       <td width="100" align="left"> 序号</td>
       <td align="left">类型</td>
	   <td align="left">评论内容</td>
	   <td align="left">所属会员</td>
	   <td align="left">更新时间</td>
	   <td width="120" align="left">操作</td>
      </tr>
<?php
if($videonum==0){
?>
<tr><td height="30" colspan="12" align="center" bgcolor="#FFFFFF" class="td_border"><br><br>没有数据<br><br><br></td></tr> 
<?php
}
if($result){
while ($row = $db ->fetch_array($result)){
$row['cd_content']=str_description($row['cd_content']);	
$cd_content = preg_replace('/\[em:(\d+)]/is', '*', $row['cd_content']);
$cd_content = getlen("len","40",$cd_content);
?>
      <tr>
       <td width="100" align="left"> <input class="checkbox" type="checkbox" name="cd_id[]" id="cd_id" value="<?php echo $row['cd_id']; ?>"><?php echo $row['cd_id']; ?></td>
       <td align="left"><?php if($row['cd_channel']==1){echo "音乐";}else if($row['cd_channel']==2){echo "视频";}else if($row['cd_channel']==3){echo "歌手";}else if($row['cd_channel']==4){echo "音乐专辑";}else if($row['cd_channel']==5){echo "视频专辑";}else if($row['cd_channel']==6){echo "文章";}else if($row['cd_channel']==7){echo "相册";}else if($row['cd_channel']==8){echo "会员空间";}else if($row['cd_channel']==9){echo "说说";} ?></td>
	   <td align="left"><span title="<?php echo $row['cd_content']?>"><?php echo ReplaceStr($cd_content,SafeRequest("key","get"),"<font color=\"red\">".SafeRequest("key","get")."</font>"); ?><span></td>
	   <td align="left"><a href="?action=keyword&key=<?php echo $row['cd_uname']; ?>" class="act"><?php echo ReplaceStr($row['cd_uname'],SafeRequest("key","get"),"<font color=\"red\">".SafeRequest("key","get")."</font>"); ?></a></td>
	   <td align="left"><?php if(date("Y-m-d",strtotime($row['cd_addtime']))==date('Y-m-d')){ echo "<font color=\"red\">".date("Y-m-d",strtotime($row['cd_addtime']))."</font>"; }else{ echo date("Y-m-d",strtotime($row['cd_addtime'])); } ?></td>
	   <td width="120" align="left"><a href="?action=del&cd_id=<?php echo $row['cd_id']; ?>" class="btn" onClick="return confirm('确定要删除吗？不可恢复！');">删除</a></td>
      </tr>
<?php
}
}
?>
       <tr> 
        <td height="35" colspan="12" align="left" bgcolor="#FAFBF7" class="td_border"><input type="checkbox" id="chkall" class="checkbox" onClick="CheckAll(this.form)" /><label for="chkall">全选</label> &nbsp;&nbsp; <input type="submit" name="alldel" class="btn btn_submit J_ajax_submit_btn" value="批量删除" onClick="{if(confirm('确定要删除所选定的评论吗？')){this.document.form.submit();return true;}return false;}" /></td> 
       </tr> 
     </tbody>
    </table> 
</form>
   </div> 
   </div>
  <div class="p10" style="margin-bottom: 0px;"> 
   <div class="pages"><?php echo $Arr[0];?></div>
  </div> 
<?php
}
	//批量删除
	function alldel(){
		global $db;
		$cd_id = RequestBox("cd_id");
		if($cd_id==0){
			showmessage("出错了，请先勾选要删除的评论", "comment.php", 0);
		}else{
			$query = $db->query("select * from ".tname('comment')." where cd_id in ($cd_id)");
        		while ($comment = $db->fetch_array($query)) {
				$db->query("delete from ".tname('comment')." where cd_id=".$comment['cd_id']."");
				$db->query("update ".tname('user')." set cd_points=cd_points-".cd_userdeletecommentspoints.",cd_rank=cd_rank-".cd_userdeletecommentsrank." where cd_id=".$comment['cd_uid']."");
			if($comment['cd_channel']=="7"){
				$db->query("update ".tname('pic')." set cd_replynum=cd_replynum-1 where cd_id=".$comment['cd_dataid']);
			}elseif($comment['cd_channel']=="9"){
				$db->query("update ".tname('blog')." set cd_commentnum=cd_commentnum-1 where cd_id=".$comment['cd_dataid']);
			}
				if(cd_userdeletecommentspoints >= 1){
					$setarr = array(
						'cd_type' => 0,
						'cd_uid' => $comment['cd_uid'],
						'cd_uname' => $comment['cd_uname'],
						'cd_icon' => 'comment',
						'cd_title' => '评论被删除',
						'cd_points' => cd_userdeletecommentspoints,
						'cd_state' => 0,
						'cd_addtime' => date('Y-m-d H:i:s'),
						'cd_endtime' => date('Y-m-d H:i:s')
					);
					inserttable('bill', $setarr, 1);
				}
        		}
			showmessage("恭喜您，评论删除成功！", "comment.php", 0);
		}
	}

	//删除
	function del(){
		global $db;
		$cd_id=SafeRequest("cd_id","get");
		$row=$db->getrow("select * from ".tname('comment')." where cd_id=".$cd_id."");
		if($row){
			$db->query("delete from ".tname('comment')." where cd_id=".$cd_id."");
			$db->query("update ".tname('user')." set cd_points=cd_points-".cd_userdeletecommentspoints.",cd_rank=cd_rank-".cd_userdeletecommentsrank." where cd_id=".$row['cd_uid']."");
			if($row['cd_channel']=="7"){
				$db->query("update ".tname('pic')." set cd_replynum=cd_replynum-1 where cd_id=".$row['cd_dataid']);
			}elseif($row['cd_channel']=="9"){
				$db->query("update ".tname('blog')." set cd_commentnum=cd_commentnum-1 where cd_id=".$row['cd_dataid']);
			}
			if(cd_userdeletecommentspoints >= 1){
				$setarr = array(
					'cd_type' => 0,
					'cd_uid' => $row['cd_uid'],
					'cd_uname' => $row['cd_uname'],
					'cd_icon' => 'comment',
					'cd_title' => '评论被删除',
					'cd_points' => cd_userdeletecommentspoints,
					'cd_state' => 0,
					'cd_addtime' => date('Y-m-d H:i:s'),
					'cd_endtime' => date('Y-m-d H:i:s')
				);
				inserttable('bill', $setarr, 1);
			}
			showmessage("恭喜您，评论删除成功！", "comment.php", 0);
		}
	}
?>