<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<%option explicit%>
<!--#include file="../Conn.asp"-->
<!--#include file="../HSK_Cls/HSK.CommonCls.asp"-->
<!--#include file="../HSK_Cls/HSK.AdministratorCls.asp"-->
<!--#include file="Include/Session.asp"-->
<%

Dim KSCls
Set KSCls = New Admin_FriendManage
KSCls.Run()
Set KSCls = Nothing

Class Admin_FriendManage
        Private KS,Param,KSCls
		Private Action,i,strClass,sFileName,RS,SQL,maxperpage,CurrentPage,totalPut,TotalPageNum
        Private Sub Class_Initialize()
		  Set KS=New PublicCls
		  Set KSCls=New ManageCls
  		  maxperpage = 20 '###每页显示数
		End Sub
        Private Sub Class_Terminate()
		 Call CloseConn()
		 Set KS=Nothing
		End Sub

		Public Sub Run()
		 With KS
					If Not KS.ReturnPowerResult(0, "KSMS20000") Then          '检查是权限
					 Call KS.ReturnErr(1, "")
					 Response.End()
					 End If
              .echo "<!DOCTYPE html PUBLIC ""-//W3C//DTD XHTML 1.0 Strict//EN"" ""http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"">" & vbcrlf
			  .echo "<html xmlns=""http://www.w3.org/1999/xhtml"">"
			  .echo"<head>"
			  .echo"<meta http-equiv=""Content-Type"" content=""text/html; charset=gb2312"">"
			  .echo"<link href=""Include/Admin_Style.CSS"" rel=""stylesheet"" type=""text/css"">"
			  .echo "<script src=""../HSK_JS/common.js"" language=""JavaScript""></script>"
			  .echo "<script src=""../HSK_JS/jquery.js"" language=""JavaScript""></script>"
			  .echo "<script type=""text/javascript"" src=""../editor/ckeditor.js"" mce_src=""../editor/ckeditor.js""></script>"
			  .echo"</head>"
			  .echo"<body leftmargin=""0"" topmargin=""0"" marginwidth=""0"" marginheight=""0"">"
			  .echo "<ul id='menu_top'>"
			  .echo "<li style='margin-left:30px;margin-top:10px'><strong>查看方式:</strong><a href=""FriendManage.asp"">所有用户列表</a>  <a href=""FriendManage.asp?flag=1"">只显示好友</a> <a href=""FriendManage.asp?flag=2"">只显示陌生人</a> <a href=""FriendManage.asp?flag=3"">只显示黑名单</a></li>"

			  .echo "</ul>"
		
		If Not IsNumeric(Request("page")) And Len(Request("page")) <> 0 Then
			.echo ("错误的系统参数!请输入整数")
			Response.End
		End If
		If Not IsEmpty(Request("page")) And Len(Request("page")) <> 0 Then
			CurrentPage = CInt(Request("page"))
		Else
			CurrentPage = 1
		End If
		If CInt(CurrentPage) = 0 Then CurrentPage = 1
		
		Param=" where 1=1"
		If KS.G("KeyWord")<>"" Then
		  If KS.G("condition")="1" Then
		   Param= Param & " And (UserName like '%" & KS.G("KeyWord") & "%' Or Friend like '%" & KS.G("KeyWord") & "%') And flag=1"
		  ElseIf KS.G("condition")="2" Then
		   Param= Param & " And (UserName like '%" & KS.G("KeyWord") & "%' Or Friend like '%" & KS.G("KeyWord") & "%') And flag=2"
		  ElseIf KS.G("condition")="3" Then
		   Param= Param & " And (UserName like '%" & KS.G("KeyWord") & "%' Or Friend like '%" & KS.G("KeyWord") & "%') And flag=3"
		  ElseIf KS.G("condition")="4" Then
		   Param= Param & " And (UserName like '%" & KS.G("KeyWord") & "%' Or Friend like '%" & KS.G("KeyWord") & "%')"
		  End If
		End If
		
		If KS.G("Flag")<>"" Then
		  If KS.G("Flag")="1" Then Param=Param & " and flag=1"
		  If KS.G("Flag")="2" Then Param=Param & " and flag=2"
		  If KS.G("Flag")="3" Then Param=Param & " and flag=3"
		End If

		totalPut = Conn.Execute("Select Count(id) From KS_Friend " & Param)(0)
		TotalPageNum = CInt(totalPut / maxperpage)  '得到总页数
		If TotalPageNum < totalPut / maxperpage Then TotalPageNum = TotalPageNum + 1
		If CurrentPage < 1 Then CurrentPage = 1
		If CurrentPage > TotalPageNum Then CurrentPage = TotalPageNum
		Select Case KS.S("action")
		 Case "Del"  Call DoDel()
		 Case Else
				Call ShowList()
		End Select
	End With	
End Sub

Private Sub ShowList()
Dim U_Rs
%>
<script src="../HSK_JS/HSK.box.js"></script>
		<script type="text/javascript">
		 function checkmsg()
		 {
		     var message=escape($("#message").val());
			 var username=escape($("#username").val());
			 if (username==''){
			  alert('参数传递出错!');
			  closeWindow();
			 }
			 if (message==''){
			   alert('请输入消息内容!');
			   $("#message").focus();
			   return false;
			 }
			 $.get("../plus/ajaxs.asp",{action:"SendMsg",username:username,message:message},function(r){
			   r=unescape(r);
			   if (r!='success'){
				alert(r);
			   }else{
				 alert('恭喜，您的消息已发送!');
				 closeWindow();
			   }
			 });
         }
		 function sendMsg(ev,username)
		 {
		  new KesionPopup().mousepopup("<img src='../images/user/mail.gif' align='absmiddle'>发送消息","对方登录后可以看到您的消息(可输入255个字符)<br /><textarea name='message' id='message' style='width:340px;height:80px'></textarea><div style='text-align:center;margin:10px'><input type='button' onclick='return(checkmsg())' value=' 确 定 ' class='button'><input type='hidden' value="+username+" name='username' id='username'> <input type='button' value=' 取 消 ' onclick='closeWindow()' class='button'></div>",350)
		 }
		 
		</script>
<table width="100%" border="0" align="center" cellspacing="0" cellpadding="0">
<tr height="25" align="center" class='sort'>
	<td width='5%' nowrap>选择</td>
	<td nowrap>用户账号</td>
	<td nowrap>用户姓名</td>
	<td nowrap>性别</td>
	<td nowrap>来自地区</td>
	<td nowrap>好友账号</td>
	<td nowrap>建立关系时间</td>
    <td nowrap width="50">关系</td>
    <td nowrap width="130">状态</td>
	<td nowrap width="90">管理操作</td>
</tr>
<%
	sFileName = "FriendManage.asp?"
	Set Rs = Server.CreateObject("ADODB.Recordset")
	SQL = "select * from KS_Friend " & Param & " order by id desc"
	If DataBaseType = 1 Then
		If CurrentPage > 100 Then
			Rs.Open SQL, Conn, 1, 1
		Else
			Set Rs = Conn.Execute(SQL)
		End If
	Else
		Rs.Open SQL, Conn, 1, 1
	End If
	If Rs.bof And Rs.EOF Then
		Response.Write "<tr><td height=""25"" align=center bgcolor=""#ffffff"" colspan=10>还没有任何好友！</td></tr>"
	Else
		If TotalPageNum > 1 then Rs.Move (CurrentPage - 1) * maxperpage
		i = 0
%>
<form name=selform method=post action=?action=Del>
<%
	On Error Resume Next
	Do While Not Rs.EOF And i < CInt(maxperpage)
		If Not Response.IsClientConnected Then Response.End
		
%>
<tr height="25" class='list' onMouseOver="this.className='listmouseover'" onMouseOut="this.className='list'">
	<td align="center" class="splittd"><input type=checkbox name=ID value='<%=rs("id")%>'></td>
	<td align="center" class="splittd"><%=Rs("UserName")%></td>
	<td align="center" class="splittd"><%=Rs("realname")%>&nbsp;</td>
	<td align="center" class="splittd"><%
	Set U_Rs = Conn.Execute("select userface,sex,province,city,isonline from KS_user where UserName='"& Rs("UserName") &"'")
	IF Not U_Rs.Eof Then
		KS.Echo U_Rs("Sex")
	Else
		KS.Echo "没有此用户,可能该用户已经删除！</td>"
	End If
	%></td>
	<td align="center" class="splittd"><%=U_Rs("province") & U_Rs("city")%></td>
	<td align="center" class="splittd"><%=Rs("Friend")%></td>
    <td align="center" class="splittd"><%=Rs("Addtime")%></td>
	<td align="center" class="splittd"><%if rs("flag")="1" then
								  response.write "好朋友"
								  elseif rs("flag")="2" then
								  response.write "陌生人"
								  else
								  response.write "黑名单"
								  end if%></td>
    <td align="center" class="splittd"><%
	IF rs("flag")="3" Then
		KS.Echo "拉黑天数："
		IF DateDiff("d",rs("Addtime"),Now)>rs("BlackDays") then
			KS.echo rs("BlackDays")		
		Else
			KS.Echo DateDiff("d",rs("Addtime"),Now) & "/" & rs("BlackDays")
		End If
	End If
	%>
    <% if U_Rs("isonline")="1" then response.write " <font color=red>在线</font>" else response.write "离线" %>
    </td>
    <td align="center" class="splittd"><a href="javascript:void(0)" onClick="sendMsg(event,'<%=rs("username")%>')">发送消息</a> <a href="?Action=Del&ID=<%=rs("id")%>" onclick="return(confirm('确定要彻底删除吗？'));">删除</a>
    </td>
</tr>
<%
		Set U_Rs=Nothing
		Rs.movenext
			i = i + 1
			If i >= maxperpage Then Exit Do
		Loop
	End If
	Rs.Close:Set Rs = Nothing
%>
<tr>
	<td class='list' onMouseOver="this.className='listmouseover'" onMouseOut="this.className='list'" height='25' colspan=10>
	&nbsp;&nbsp;<input id="chkAll" onClick="CheckAll(this.form)" type="checkbox" value="checkbox"  name="chkAll">全选
	<input class="button" type="submit" name="Submit2" value=" 删除选中的好友 " onclick="{if(confirm('此操作不可逆，确定要删除选中的记录吗?')){this.document.selform.submit();return true;}return false;}"></td>
</tr>
</form>
<tr>
	<td  colspan=10 align=right>
	<%
	 Call KSCLS.ShowPage(totalPut, MaxPerPage, "FriendManage.asp", True, "个", CurrentPage, KS.QueryParam("page"))
	%></td>
</tr>
</table>
<div>
<form action="FriendManage.asp" name="myform" method="get">
   <div style="border:1px dashed #cccccc;margin:3px;padding:4px">
      &nbsp;<strong>快速搜索=></strong>
	 &nbsp;好友账号:<input type="text" class='textbox' name="keyword">&nbsp;类型:
	 <select name="condition">
	  <option value=1>按好友搜索</option>
	  <option value=2>按陌生人搜索</option>
	  <option value=3>按黑名单搜索</option>
	 </select>
	  &nbsp;<input type="submit" value="开始搜索" class="button" name="s1">
    </div>
</form>
</div>
</body>
</head>
</html>
<%
End Sub

Sub DoDel()
Dim ID: ID=KS.G("ID")
IF KS.CheckOuterUrl()=False Then
	If ID <> "" Then
		Conn.Execute("Delete From KS_Friend Where id In("& id & ")")
		KS.AlertHintScript("删除成功！")
	End If
End If
End Sub

End Class
%> 
