<!--#include file="../act_inc/ACT.User.asp"-->
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>用户管理中心</title>
<link href="Images/css/css.css" rel="stylesheet" type="text/css">
</head>
<body>
<%
Dim  UserHS
 Set UserHS = New ACT_User
		Private CurrentPage,totalPut
		Private RS,MaxPerPage,SQL,tablebody,strErr,action,boxName,smscount,smstype,readaction,turl
		Private ArticleStatus,ComeUrl,TotalPages
		MaxPerPage =50
		ComeUrl=Request.ServerVariables("HTTP_REFERER")
		IF Cbool(UserHS.UserLoginChecked)=false then
		  Response.Write "<script>top.location.href ='login.asp' ;</script>"
		  Response.end
		End If
		
		%>
		<table width="98%" height=20 border=0 align="center" cellPadding=2 cellSpacing=1 borderColor=#111111 class="table" id=AutoNumber3 style="BORDER-COLLAPSE: collapse">
                                       <tr>
                                         <td height=20 class="bg_tr"><B><SPAN style="FONT-SIZE: 10.5pt">好友管理</SPAN></B></td>
                                         <td width=583 height=20 align=right class="bg_tr">·<a href="?ListType=1">好友</a>[<a href="?Action=add&flag=1">添加</a>]</a> ·<a href="?ListType=2">陌生人</a>[<a href="?Action=add&flag=2">添加</a>] ·<a href="?ListType=3">黑名单</a>[<a href="?Action=add&flag=3">添加</a>]</td>
                                       </tr>
</table>
		<%
		action=Trim(request("action"))
		CurrentPage=Trim(request("page"))
		if Isnumeric(CurrentPage) then
			CurrentPage=Clng(CurrentPage)
		else
			CurrentPage=1
		end if
		select case action
		case "add"
		    Call AddFriend()
	    case "edit"
		    Call AddFriend()
		case "addsave"
		    call addsave()
		case "del"
		    call Del()
		case "info"
			call info()
		case "addF"
			call addF()
		case "saveF"
			call saveF()
		case "删除"
			call DelFriend()
		case "清空好友"
			call AllDelFriend()
		case else
			call info()
		end select
		  	%>
		</TD>    
		 </TR>
</TABLE>
		 <%
	   '删除好友
	   Sub Del()
	     conn.execute("delete from Friend_ACT where id=" & actcms.ChkNumeric(actcms.s("id")))
		 response.redirect request.servervariables("http_referer")
	   end sub
		'添加好友
		Sub AddFriend()
		  dim flag,username,realname,phone,mobile,qq,msn,email,note
		  dim id:id=actcms.ChkNumeric(actcms.s("id"))
		 if actcms.s("action")="edit" then
		   dim rs:set rs=server.createobject("adodb.recordset")
		   rs.open "select * from Friend_ACT where id=" & id,conn,1,1
		   if rs.eof and rs.bof then
		    rs.close:set rs=nothing
		    call ACTCMS.Alert("参数传递出错!",""):exit sub
		   else
		     username=rs("friend")
			 flag=rs("flag")
			 realname=rs("realname")
			 phone=rs("phone")
			 mobile=rs("mobile")
			 qq=rs("qq")
			 msn=rs("msn")
			 email=rs("email")
			 note=rs("note")
		   end if
		   rs.close:set rs=nothing
		 else
		  flag=actcms.s("flag")
		 end if%>
		<script>
		 function checkform()
		 {
		   if (document.myform.username.value=='')
		   {
		     alert('请输入好友的用户名!');
			 document.myform.username.focus();
			 return false;
		   }
		   return true;
		 }
		</script>
		<table width="98%" border="0" align="center" cellpadding="0" cellspacing="1"  class="table">
		<form action="?action=addsave" method="post" name="myform" onSubmit="return(checkform())">
			<tr height="23" class="bg_tr">
				<td width="25%" height="25" align="center">添加好友</td>
			</tr>
			<tr> 
			  <td>
			    <table border="0" cellpadding="0" cellspacing="1" width="100%">
				 <tr class='tdbg'>
				  <td width="344"><b>用户名</b><br>
			       登录会员中心的用户名，必须填写。</td>
				  <td width="607"><input type="text" class="textbox" name="username" value="<%=username%>" size=20 style="width:150"> <font color=red>*</font></td>
				 </tr>
				 <tr class='tdbg'>
				  <td><b>类 型</b><br>加入黑名单以后，就不会受到这个用户的短信骚扰了。</td>
				  <td><select name="flag" style="width:150">
				      <option value="1" <%if flag="1" then response.write " selected"%>>好朋友</option>
				      <option value="2" <%if flag="2" then response.write " selected"%>>陌生人</option>
				      <option value="3" <%if flag="3" then response.write " selected"%>>黑名单</option>
					  
				  </select></td>
				 </tr>
				 <tr class='tdbg'>
				  <td><b>真实姓名</b><br>你好友的姓名，可选填。</td>
				  <td><input type="text" class="textbox" value="<%=realname%>" name="realname" size=20 style="width:150"></td>
				 </tr>
				 <tr class='tdbg'>
				  <td><b>电子邮箱</b><br>好友电子邮箱号码，可选填。</td>
				  <td><input type="text" class="textbox" value="<%=email%>" name="email" size=20 style="width:150"></td>
				 </tr>
				 <tr class='tdbg'>
				  <td><b>备注信息</b><br/>必须小于255个字符</td>
				  <td><textarea class="textbox" name="note" cols=50 rows=5><%=note%></textarea></td>
				 </tr>
				 <tr class='tdbg'>
				  <td height="30" colspan=2 align="center">
				  <input type="hidden" name="id" value="<%=id%>">
				  <input type="submit" class="ACT_btn" value=" OK,保存 ">
				  &nbsp;<input type="button" class="ACT_btn" value=" 取 消 " onClick="javascript:history.back()"></td>
				 </tr>
			    </table>
			  </td>
			</tr>
		  </form>
		</table>
		<%
		End Sub
		'保存
		sub addsave()
		 dim flag:flag=actcms.ChkNumeric(actcms.s("flag"))
		 dim username:username=ACTCMS.RSQL(actcms.s("username"))
		 dim realname:realname=ACTCMS.RSQL(actcms.s("realname"))
		 dim phone:phone=ACTCMS.RSQL(actcms.s("phone"))
		 dim mobile:mobile=ACTCMS.RSQL(actcms.s("mobile"))
		 dim qq:qq=ACTCMS.RSQL(actcms.s("qq"))
		 dim msn:msn=ACTCMS.RSQL(actcms.s("msn"))
		 dim email:email=ACTCMS.RSQL(actcms.s("email"))
		 dim note:note=actcms.s("note")
		 if username="" then call actcms.Alert("用户名必须填写",""):exit sub
		 if username=UserHS.username then call actcms.Alert("不能将自己加为好友!",""):exit sub
		 if len(note)>255 then call actcms.Alert("备注信息必须小于255个字符!",""):exit sub
		 dim rs:set rs=server.createobject("adodb.recordset")
		 rs.open "select username from "&UserHS.TableName(UserHS.UModeID)&" where username='" & username & "'",conn,1,1
		 if rs.eof and rs.bof then
		  rs.close:set rs=nothing
		  call actcms.alert("对不起，你输入的用户名不存在!","")
		  exit sub
		 end if
		 rs.close
		 rs.open "select * from Friend_ACT where friend='" & username & "'",conn,1,3
		 if rs.eof then
		   rs.addnew
		 end if
		   rs("username")=UserHS.username
		   rs("friend")=username
		   rs("addtime")=now
		   rs("realname")=realname
		   rs("phone")=phone
		   rs("mobile")=mobile
		   rs("qq")=qq
		   rs("msn")=msn
		   rs("email")=email
		   rs("note")=note
		   rs("flag")=flag
		  rs.update
		
		  if actcms.ChkNumeric(actcms.s("id"))<>0 then
		   response.write "<script>alert('好友资料修改成功！');location.href='?';</script>"
		  else
		  response.write "<script>if (confirm('好友添加成功，继续添加吗?')){location.href='?action=add&flag=" & flag & "';}else{location.href='Friend_User.asp';}</script>"
		  end if
		end sub
		
		sub info()
		%>
		<script>
		 function viewnote(obj)
		 {
		  if (eval("document.all."+obj+".style.display=='none'"))
		   eval("document.all."+obj+".style.display='';")
		  else
		   eval("document.all."+obj+".style.display='none';")
		 }
		</script>
		<table width="98%" border="0" align="center" cellpadding="0" cellspacing="1"  class="table">
		<form action="Friend_User.asp" method=post name=inbox>
			<tr height="23" class="bg_tr">
				<td width="5%" align="center">选择</td>
				<td width="18%" align="center">类 型</td>
				<td width="16%" height="25" align="center">用户名</td>
				<td width="18%" align="center">真实姓名</td>
				<td width="21%" align="center">操 作</td>
				<td width="22%" align="center">备 注</td>
			</tr>
		<%  dim param
		    if actcms.ChkNumeric(actcms.s("listtype"))<>0 then param=param & " and flag=" & actcms.ChkNumeric(actcms.s("listtype"))
			set rs=server.createobject("adodb.recordset")
			sql="select F.id,f.friend,f.flag,f.note,f.email,U.UserID,f.Email,f.RealName from Friend_ACT F inner join "&UserHS.TableName(UserHS.UModeID)&" U on F.Friend=U.UserName where F.Username='"&UserHS.UserName&"' " & param & " order by F.addtime desc"
			rs.open sql,Conn,1,1
			if rs.eof and rs.bof then
		%>
						<tr>
						<td height="26" colspan=6 align=center valign=middle  class="td_bg">
						<% select case actcms.s("listtype")
						    case "2"
							 response.write "你没有添加陌生人。"
							case "3"
							 response.write "你没有添加黑名单。"
							case else
							 response.write "你没有添加好朋友。"
						   end select
						 %>
						</td>
						</tr>
				
		<%else
		do while not rs.eof
		%>
						<tr class="td_bg"  onMouseOver=overColor(this) onMouseOut=outColor(this)>
						<td align=center><input type=checkbox name=id value=<%=rs(0)%>></td>
							<td align=center>
							<%
							select case rs(2)
							 case 2
							  response.write "陌生人"
							 case 3
							  response.write "黑名单"
							 case else
							  response.write "好朋友"
							 end select
							%></td>
						  <td height="25" align=center valign=middle><a href="ShowUser.Asp?UserID=<%'=rs(9)%>" target=_blank><%=actcms.HTMLEncode(rs(1))%></a></td>
							<td align=center valign=middle><%'=actcms.HTMLEncode(rs(11))%></td>
							<td align=center><a href="Message_User.asp?action=new&touser=<%=actcms.HTMLEncode(rs(1))%>">发送短信</a> <a href="?action=edit&id=<%=rs("id")%>">修改</a> <a href="?action=del&id=<%=rs(0)%>" onClick="return(confirm('确定删除该位好友吗？'))">移除</a></td>
							<td align=center><a href="javascript:viewnote('note<%=rs(0)%>')">查看备注</a></td>
						</tr>
						<tr class="td_bg" id="note<%=rs(0)%>" style="display:none">
						 <td colspan="6">
						  <table border="0" cellspacing="1" cellpadding="2" class="table" width="98%" align="center">
						   <tr class="tdbg"> 
						     <td width="19%">姓名：<%=rs(7)%></td><td width="39%">邮箱：<%=rs(6)%></td>
						   </tr>
						  					   
						   </table>
						 </td>
						</tr>
		<%
			rs.movenext
			loop
			end if
			rs.close
			set rs=Nothing
		%>
						
				<tr class='tdbg' > 
				  <td colspan=6 align=right valign=middle><input type=checkbox id=chkall name=chkall value=on onClick="CheckAll(this.form)"><label for="chkall">选中所有显示记录&nbsp;</label><input class="ACT_btn" type=button name=action onClick="location.href='Friend_User.asp?action=addF'" value="快速添加好友">&nbsp;<input class="ACT_btn" type=submit name=action onClick="{if(confirm('确定删除选定的纪录吗?')){this.document.inbox.submit();return true;}return false;}" value="删除">&nbsp;<input class="ACT_btn" type=submit name=action onClick="{if(confirm('确定清除所有的纪录吗?')){this.document.inbox.submit();return true;}return false;}" value="清空好友"></td>
				</tr>
		  </form>
</table>
		<script language=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; 
		}
		}
		
function overColor(Obj)
{
	var elements=Obj.childNodes;
	for(var i=0;i<elements.length;i++)
	{
		elements[i].className="tdbg1"
		Obj.bgColor="";
	}
	
}
function outColor(Obj)
{
	var elements=Obj.childNodes;
	for(var i=0;i<elements.length;i++)
	{
		elements[i].className="tdbg";
		Obj.bgColor="";
	}
}
</script>	
		
		<%
		end sub
		
		sub delFriend()
		dim delid
		delid=replace(request.form("id"),"'","")
		if delid="" or isnull(delid) then
			Call ACTCMS.Alert("您没有选择要删除好友名单。","")
			exit sub
		else
			Conn.Execute("delete from Friend_ACT where username='"&UserHS.UserName&"' and id in ("&delid&")")
			Call ACTCMS.Alert("您已经删除选定的好友记录。","Friend_User.asp")
		end if
		end sub
		
		sub AllDelFriend()
			Conn.Execute("delete from Friend_ACT where username='"&UserHS.UserName&"'")
			Call ACTCMS.Alert("您已经删除了所有好友列表。","Friend_User.asp")
		end sub
		
	Public Function ShowPagePara(totalnumber, MaxPerPage, FileName, ShowAllPages, strUnit, CurrentPage, ParamterStr)
		  Dim N, I, PageStr
				Const Btn_First = "第一页"'样式定义
				Const Btn_Prev = "上一页" 
				Const Btn_Next = "下一页" 
				Const Btn_Last = "最后一页" 
				  PageStr = ""
					If totalnumber Mod MaxPerPage = 0 Then
						N = totalnumber \ MaxPerPage
					Else
						N = totalnumber \ MaxPerPage + 1
					End If
				If N > 1 Then
					PageStr = PageStr & ("页次：<font color=red>" & CurrentPage & "</font>/" & N & "页 共有:" & totalnumber & strUnit & " 每页:" & MaxPerPage & strUnit & " ")
					If CurrentPage < 2 Then
						PageStr = PageStr & Btn_First & " " & Btn_Prev & " "
					Else
						PageStr = PageStr & ("<a href=" & FileName & "?page=1" & "&" & ParamterStr & ">" & Btn_First & "</a> <a href=" & FileName & "?page=" & CurrentPage - 1 & "&" & ParamterStr & ">" & Btn_Prev & "</a> ")
					End If
					
					If N - CurrentPage < 1 Then
						PageStr = PageStr & " " & Btn_Next & " " & Btn_Last & " "
					Else
						PageStr = PageStr & (" <a href=" & FileName & "?page=" & (CurrentPage + 1) & "&" & ParamterStr & ">" & Btn_Next & "</a> <a href=" & FileName & "?page=" & N & "&" & ParamterStr & ">" & Btn_Last & "</a> ")
					End If
					If ShowAllPages = True Then
						PageStr = PageStr & ("GO:<select  onChange='location.href=this.value;' style='width:55;' name='select'>")
				   For I = 1 To N
					 If Cint(CurrentPage) = I Then
						PageStr = PageStr & ("<option value=" & FileName & "?page=" & I & "&" & ParamterStr & " selected>NO." & I & "</option>")
					 Else
						 PageStr = PageStr & ("<option value=" & FileName & "?page=" & I & "&" & ParamterStr & ">NO." & I & "</option>")
					 End If
				   Next
				  PageStr = PageStr & "</select>"
				  End If
			 End If
			 ShowPagePara = PageStr
			 response.write ShowPagePara
	End Function
	
	
			sub addF()
		call userlist()
		Response.write "<div align=center style=""margin-top:5px"">"
		Call  ShowPagePara(totalPut, MaxPerPage,"Friend_User.asp", True, "个用户", CurrentPage, "action=addF&flag=" &actcms.s("flag"))
		Response.write "</div>"
		%>
		<br>
		<table border="0" align=center cellpadding=0 cellspacing=1 class="table">
			<form action="Friend_User.asp" method=post name=messager>
				  <tr   class="bg_tr"> 
					<td height="25" colspan=2 align=center class="bg_tr"> 
					  <input type=hidden name="action" value="saveF">
				    批量添加好友</td>
				  </tr>
				  <tr height=50 class="tdbg"> 
					<td width=80><b>好友名单：</b></td>
					<td height="25" valign=middle>
					  <input type=text name="touser" size=50 value="<%=request("myFriend")%>">
					  &nbsp;用户之间使用逗号（,）分开					</td>
				  </tr>
				  <tr class="tdbg"> 
					<td colspan=2 align=center valign=middle> 
					  <input class="ACT_btn" type=Submit value=" 保 存 " name=Submit>
					  &nbsp; 
					  <input class="ACT_btn" type="reset" name="Clear" value=" 清 除 ">
					</td>
				  </tr>
		  </form>
</table><br>
		<%
		end sub
		
		sub saveF()
		dim incept,i
		if request("touser")="" then
			Call ACTCMS.Alert("请填写对象。","")
			exit sub
		else
			incept=ACTCMS.RSQL(request("touser"))
			incept=split(incept,",")
		end if
		
		for i=0 to ubound(incept)
		set rs=server.createobject("adodb.recordset")
		sql="select UserName from "&UserHS.TableName(UserHS.UModeID)&" where UserName='"&incept(i)&"'"
		set rs=Conn.Execute(sql)
		if rs.eof and rs.bof then
			Call actcms.alert("系统没有（"&incept(i)&"）这个用户，操作失败。","")
			exit sub
		end if
		set rs=Nothing
		
		if UserHS.UserName=Trim(incept(i)) then
			Call ACTCMS.Alert("不能把自已添加为好友。","")
		end if
		
		sql="select friend from Friend_ACT where username='"&UserHS.UserName&"' and  friend='"&incept(i)&"'"
		set rs=Conn.Execute(sql)
		if rs.eof and rs.bof then
			sql="insert into Friend_ACT (username,friend,addtime,flag) values ('"&UserHS.UserName&"','"&Trim(incept(i))&"',"&NowString&",1)"
			set rs=Conn.Execute(sql)
		end if
		next
		Call actcms.Alert("恭喜您，好友添加成功。","Friend_User.asp")
		end sub
		
		sub userlist()
		Response.Write "<table width=""98%"" class='table' align=center cellpadding=2 cellspacing=1 border=0><tr  class='bg_tr'><td>管理员组:</td></tr></table>"
		Response.Write "<table width=""98%"" class='table' align=center cellpadding=2 cellspacing=1 border=0><tr class='tdbg'>"
		dim admin_face
		sql="select UserName,Sex,Email from "&UserHS.TableName(UserHS.UModeID)&" where GroupID=4 order by UserID"
		set rs=Conn.Execute(sql)
		i=0
		do while not rs.eof
		admin_face="<img src=""Images/admin_face.gif"" width=24 height=30>"
		if UserHS.UserName=rs(0) then
			Response.Write "<td width=""14%"">" & admin_face&"&nbsp;<a href=Friend_User.asp?action=saveF&touser="&rs(0)&" title=""管理员""><font color=""#0000ff"">"&rs(0)&"</font></a></td>"
		else
			Response.Write "<td width=""14%"">" & admin_face&"&nbsp;<a href=Friend_User.asp?action=saveF&touser="&rs(0)&" title=""管理员"">"&rs(0)&"</a></td>"
		end if
		i=i+1
		if i>=6 then
			Response.Write "</tr><tr>"
			i=0
		end if
		rs.movenext
		loop
		Response.Write "</tr></TABLE><br>"
		set rs=Nothing
		
		Response.Write "<table width=""98%"" class='table' align=center cellpadding=2 cellspacing=1 border=0><tr class='bg_tr'><td>非管理员组:</td></tr></table>"
		Response.Write "<table width=""98%"" class='table' align=center cellpadding=2 cellspacing=1 border=0><tr class='td_bg'>"
		dim user_face,user_info,sex,i,n
		sql="select UserName,Sex,Email from "&UserHS.TableName(UserHS.UModeID)&" where GroupID<>4 order by UserID"
		set rs=Server.CreateObject("adodb.recordSet")
		rs.Open sql,Conn,1,1
		i=0:n=0:TotalPut=0
		if not (rs.bof and rs.eof) then
			TotalPut=rs.recordcount
			if (TotalPut mod MaxPerPage)=0 then
				TotalPages = TotalPut \ MaxPerPage
			else
				TotalPages = TotalPut \ MaxPerPage + 1
			end if
			if CurrentPage > TotalPages then CurrentPage=TotalPages
			if CurrentPage < 1 then CurrentPage=1
			rs.move (CurrentPage-1)*MaxPerPage
			do while not rs.eof
			
			user_info="性别："& rs("sex") & vbcrlf & "Q&nbsp;&nbsp;Q："&  vbcrlf &"Email："& rs(2)
			user_face="<img src=""images/user_face.gif"" width=12 height=11>"
			if UserHS.UserName=rs(0) then
				Response.Write "<td height=20 width=""14%""  class='td_bg'>" & user_face&"&nbsp;<a href=Friend_User.asp?action=saveF&touser="&rs(0)&" title="""& user_info &""">"&rs(0)&"</a></td>"
			else
				Response.Write "<td height=20 width=""14%""  class='td_bg'>" & user_face&"&nbsp;<a href=Friend_User.asp?action=saveF&touser="&rs(0)&" title="""& user_info &""">"&rs(0)&"</a></td>"
			end if
			i=i+1
			if i>=6 then 
				if i=6 then Response.Write "</tr><tr>"
				i=0
			end if
			n=n+1
			if n>= MaxPerPage then Exit Do
			rs.movenext
			loop
		else
			Response.Write "<td >无任何用户</td>"
		end if
		Response.Write "</tr></TABLE><br>"
		set rs=Nothing
		end sub
%> 
