<?php
/*
'**************************************************************************************************
' 软件名称: 搜一次 Content Management System
' 版本编号: Version 1.X
' 官方网站: http://www.syccms.com
' 官方论坛：http://bbs.syccms.com
' 版权所有: 搜一次运营团队
' 法律顾问: 杭州市元茂律师事务所 严飞律师
' 郑重声明:
'    1、任何个人或组织不得在未经授权的情况下删除、修改、拷贝本软件及其他副本上一切关于版权的信息；
'    2、搜一次网络事业部保留此软件的法律追究权利
'**************************************************************************************************
*/
include "../../include/conn.php";
include "../../include/function.php";
include "../admin_version.php";
include "../admin_loginstate.php";
?>
<!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" />
<title>网友留言管理</title>
<script type="text/javascript" language="javascript">var tentpath='<?php echo S_SitePath?>';</script>
<script src="../js/jquery.js"></script>
<script src="../js/alerts.js"></script>
<link href="../images/alerts.css" rel="stylesheet" type="text/css" media="screen" />
<script language="javascript">
	$(document).ready(function(){
		$("#ChkAll").click(function(){
			if($(this).attr("checked")==true){
				$("input[id='S_ID']").each(function(){
					$(this).attr("checked",true);									 
				})							
			}else{
				$("input[id='S_ID']").each(function(){
					$(this).attr("checked",false);									 
				})							
			}
		})					   

	 $("#showmessage").click(function (){
		window.location='?action=noreply';
	});
	
		$("#delall").click(function(){
			jConfirm('确定删除全部留言吗?', '操作提示', function(r) {
					if(r==true){
						window.location='?action=deleteall';
						Feedback.submit();}
					});
		 })

	$("#button1").click(function(){
			jConfirm('确定删除全部留言吗?', '操作提示', function(r) {
					if(r==true){
						var types=$("#acval").val();
						document.Feedback.action='?action=delcheck&types='+types;
						Feedback.submit();}
					});								 
		})
	
	$("#delall").click(function(){
			jConfirm('确定删除全部吗?', '操作提示', function(r) {
					if(r==true){
						var types=$("#acval").val();
						document.Feedback.action='?action=delall&types='+types;
						Feedback.submit();}
					});								 
								
	})
		
})




function del(id,types){
	jConfirm('确定执行操作吗?', '操作提示', function(r) {
		if(r==true){
			window.location='?action=del&S_ID='+id+'&types='+types;
			}
				});
		
		}
	
function Reply(id,name,types,content){
	//jPrompt("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;回复网友：<font color='red'>"+name+"</font>","","留言回复<span style='cursor:pointer;margin-left:230px;' onclick='RemoveRe()'>[关闭]</span>",function(R){
	jPrompt("",content,"&nbsp;回复网友："+name+"<span style='margin-left:185px;' onclick='RemoveRe()'>[关&nbsp;闭]</span>",function(R){																																															
			window.location='?action=reply&S_ID='+id+'&content='+R+'&types='+types;															  
			})
	}
	
function RemoveRe(){
	$.alerts._hide();
	}	
</script>
<link  href="../images/style.css" rel="stylesheet" type="text/css" />
</head>

<body>

<?php
class ui_message{
	public function mlist($sql,$count){
		global $db;
		$action=SafeRequest("action","get");
		if($action=="error"){
			$ptitle="视频报错处理";
			}
		elseif($action=="noreply"){
			$ptitle="待审留言管理";
			}	
		else{
			$ptitle="留言管理";
			}	
		$Arr=getpagerow($sql,$count);//sql,每页显示条数
		$result=$db->query($Arr[2]);
		$recount=$db->num_rows($result);
?>	
<div class="r_main">
	<div class="r_content">
		<div class="r_content_1">
					<form method="post" name="Feedback" action=""> 
                        <table width="100%" border="0" align="center" cellpadding="0" cellspacing="0"  class="tb_style">         
                            <tr>
                              <td  height="30" colspan="7" class="td_title">&nbsp;<?php echo $ptitle?></td>
                              </tr>
<?php
	if($recount=="0"){
?>
          <tr>
            <td height="30" colspan="10" align="center" bgcolor="#FFFFFF" class="td_border"><strong>暂无留言！</strong></td>
          </tr>
<?php		}
	else{
?>                              
          <tr>                        
              <td> 
<?php
		if($result){
			while ($row = $db ->fetch_array($result)){
				if($row['S_VID']!=0){
					$url="<a href=".LinkUrl("s_video",0,1,$row['S_VID'])." target=_blank>".LinkUrl("s_video",0,1,$row['S_VID'])."</a>";
					}
				else{
					$url="";
					}	
				if($row['S_Reply']=="1" && trim($row['S_ReContent'])!=""){
?>                           
               		<div style="width:100%; border:1px solid #B5D6E6; margin-top:10px;"><div style="width:100%; height:30px; line-height:30px; font-size:12px; background:#EEF7FE">
                        <div style="width:70%; float:left;  color:#185691; "><input type="checkbox" name="S_ID[]" value="<?php echo $row['S_ID']?>" class="checkbox" id="S_ID">&nbsp;<strong><?php echo $row['S_Name']?></strong>&nbsp;&nbsp;IP：<?php echo $row['S_IP']?></div>
                        <div style="width:28%; float:left;text-align:right; font-size:12px;">留言时间:<font color=red><?php echo $row['S_AddTime']?></font></div>
                    </div>
                    <div style="width:95%; margin:0 auto; height:80px; font-size:12px; line-height:25px; border-bottom:1px solid #CCC">&nbsp;<?php echo $row['S_Content']?><br />&nbsp;视频地址：<?php echo $url?></div>
                    	<div style="width:100%; height:20px; text-align:right; font-size:12px; line-height:20px;">&nbsp;
						[<a style="cursor:pointer" onclick="Reply(<?php echo $row['S_ID']?>,'<?php echo $row['S_Name']?>','<?php echo $action?>','<?php echo $row['S_ReContent']?>')">回复</a>]&nbsp;
						[<a style="cursor:pointer" onclick="del(<?php echo $row['S_ID']?>,'<?php echo $action?>')">删除</a>]&nbsp;</div>
                        <div style="font-size:12px; line-height:25px; width:95%;margin:0 auto;"><font color="red">&nbsp;站长回复(<?php echo $row['S_ReTime']?>):</font></div>
                        <div style="width:95%;margin:0 auto; line-height:25px; font-size:12px;">&nbsp;<?php echo $row['S_ReContent']?></div>
                      </div>
<?php
				}
				else{
?>
					<div style="width:100%; border:1px solid #B5D6E6; margin-top:10px;" >
                    	<div style="width:100%; height:30px; line-height:30px; font-size:12px; background:#EEF7FE">
                        	<div style="width:70%; float:left;  color:#185691; "><input type="checkbox" name="S_ID[]" value="<?php echo $row['S_ID']?>" class="checkbox" id="S_ID">&nbsp;<strong><?php echo $row['S_Name']?></strong>&nbsp;IP:<?php echo $row['S_IP']?></div>
                        	<div style="width:28%; float:left;text-align:right; font-size:12px;">留言时间:<font color=red><?php echo $row['S_AddTime']?></font></div>
                        </div>
                        <div style="width:95%; margin:0 auto; height:50px; font-size:12px; line-height:25px; border-bottom:1px solid #CCC">&nbsp;<?php echo $url.$row['S_Content']?></div>
                        <div style="width:100%; height:20px; text-align:right;font-size:12px; line-height:20px;">&nbsp;
						[<a style="cursor:pointer" onclick="Reply(<?php echo $row['S_ID']?>,'<?php echo $row['S_Name']?>','<?php echo $action?>','<?php echo $row['S_ReContent']?>')">回复</a>]&nbsp;
						[<a style="cursor:pointer" onclick="del(<?php echo $row['S_ID']?>,'<?php echo $action?>')">删除</a>]&nbsp;</div>
						</div>
<?php 
				}
			}
		}
?>
          	</td>
          </tr>
          <tr>
            <td colspan="4" class="td_border"><input type="checkbox" name="ChkAll" id="ChkAll"  ids="S_ID"  class="checkbox"/>全选&nbsp;&nbsp;<input type="button" name="button1" id="button1"value="删除所选信息" class="rb1" /><input type="hidden" value="<?php echo $action?>" id="acval"> 
              &nbsp;
              <input name="button" type="button" class="rb1"  value="一键删除全部" id="delall"/>
              &nbsp;&nbsp; <input type="button" id="showmessage" name="showmessage" value="等待回复留言" class="rb1"/></td>
          </tr>
          <tr>
          	<td class="td_border" height="35" align="right"><?php echo $Arr[0]?>&nbsp;&nbsp;</td>
          </tr>
        			
<?php
	}
?>                        
                    </table>
                    	</form>
		</div>
	</div>
</div>
<?php
		
		}
	
	}//end class

?>        

<?php
$ui=new ui_message;
$action=SafeRequest("action","get");
switch($action){
	case 'mlist':
		mlist();
		break;
	case 'noreply':
		noreply();
		break;
	case 'del':
		del();
		break;
	case 'reply':
		reply();
		break;
	case 'delcheck':
		delcheck();
		break;
	case 'delall':
		delall();
		break;
	case 'error':
		error();
		break;
	case 'listvip':
		listvip();
		break;
	default:
		mlist();
	}
	
function listvip(){
	global $ui;
	$sql="select * from s_gbook where S_VID=0 and S_IsVip=1 order by S_ID desc";
	$ui->mlist($sql,10);
}

function error(){
	global $ui;
	$sql="select * from s_gbook where S_VID<>0 order by S_ID desc";
	$ui->mlist($sql,10);
	}
	
function delall(){
	global $db;
	$types=SafeRequest("types","get");
	if($types=="error"){
		$sql="delete from s_gbook where S_VID<>0";
		}
	else{
		$sql="delete from s_gbook where S_VID=0";
		}	
	if($db->query($sql)){
		//header("Location:admin_message.php?action=".$types."");
		die("<script>window.location='admin_message.php?action=".$types."'</script>");
		}	
}

function delcheck(){
	global $db;
	$types=SafeRequest("types","get");
	$S_ID=RequestBox("S_ID");
	$sql="delete from s_gbook where S_ID in ($S_ID)";
	if($S_ID=="0"){
		die("<script>jAlert('请选择要删除的数据?','操作提示',function(R){history.back();})</script>");
		}
	else{
		if($db->query($sql)){
			die("<script>jAlert('恭喜你！操作成功了！','成功提示',function(R){window.location='?action=".$types."';})</script>");
			}
		}	
	}	

function reply(){
	global $db;
	$types=SafeRequest("types","get");
	$S_ID=SafeRequest("S_ID","get");
	$S_Content=SafeRequest("content","get");
	$S_ReTime=date('Y-m-d H:i:s');
	$sql="Update s_gbook set S_ReContent='".$S_Content."',S_ReTime='".$S_ReTime."',S_Reply=1 where S_ID=".$S_ID."";
	if($db->query($sql)){
		//header("Location:?action=".$types."");
		die("<script>window.location='?action=".$types."'</script>");
		}
	}

function del(){
	global $db;
	$types=SafeRequest("types","get");
	$S_ID=SafeRequest("S_ID","get");
	if(!IsNum($S_ID)){echo "<script>jAlert('参数传输错误?','操作提示',function(R){history.back();})</script>";}
	$sql="delete from s_gbook where S_ID=".$S_ID."";
	if($db->query($sql)){
		//header("Location:admin_message.php?action=".$types."");
		die("<script>window.location='?action=".$types."'</script>");
		}
	
	}

function mlist(){
	global $ui;
	$sql="select * from s_gbook where S_VID=0 and S_IsVip=0 order by S_ID desc";
	$ui->mlist($sql,10);
	}

function noreply(){
	global $ui;
	$sql="select * from s_gbook where S_VID=0 and  S_Reply=2  order by S_ID desc";
	$ui->mlist($sql,10);
	}
?>
<?php include "../admin_bottom.php"; ?>
</body>
</html>