⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 onlineadmin.asp

📁 一个网站聊天室的模型
💻 ASP
📖 第 1 页 / 共 2 页
字号:
		'如果有,就更新该用户的记录
			newsql1="update Fault set FaultIP='" & hisip & ",IPIfClosed=true,IPCloseCount=ipclosecount+1,IPCloseTime='" & date() & "',IPOpenTime='" & dateadd("d",1,date()) & "' where FaultUserID='" & hisid & "'"
			newconn.Execute (newsql1)
		else
			'如果没有,就在Fault表中插入一条新记录,记录该用户犯规
			newsql3="insert into Fault(FaultUserID,FaultIP,IPCloseTime,IPOpenTime,IPCloseCount,ipifclosed) values ('" & hisid & "','" & hisip & "','" & date() & "','" & dateadd("d",1,date()) & "',1,1)" 
			newconn.Execute (newsql3)
		end if
		'从在线用户表中查找该用户所在的房间,把该房间中的人数减少一个
		newsql4="select RoomName from UserOnLine where OnLineUserID='" & hisid & "'"
 '通过connection对象的execute方法执行SQL语句并返回记录集
		set newrecord2=newconn.Execute (newsql4)		
		'使用变量记录用户的房间名
		hisroom=newrecord2(0)	
					
		newsql5="update RoomInfo set HowManyUsers=HowManyUsers-1 where RoomName='" & hisroom & "'"
		newconn.Execute (newsql5)		
		'从在线用户表中删除该用户
		newsql6="delete from UserOnLine where OnLineUserID='" & hisid & "'"
		newconn.Execute (newsql6)		
		'通知所有在线用户某个IP已经被封
		newsql7="select OnLineUserID from UserOnLine"
		set newrecord3=newconn.Execute (newsql7)
		if not newrecord3.bof then
			do while not newrecord3.eof
				application(newrecord3(0))="<br>因为用户" & hisid & "严重犯规,其IP--<font color=vbred>" & hisip & "</font>--已经被封!<br><br>" & application(newrecord3(0))
				newrecord3.movenext
			loop
		
		end if
		'反馈给管理员执行的封某用户的IP操作已经执行成功
		Response.Write "<br>用户" & hisid & "的IP地址--<font color=vbred>" & hisip & "</font>--已经被封!<br>"
		'关闭记录集对象
	newrecord.close
	    set newrecord=nothing
			newrecord1.close
	    set newrecord1=nothing
		newrecord2.close
	    set newrecord2=nothing
		newrecord3.close
	    set newrecord3=nothing
	end if		
	next
	
	 
    '以下程序段是执行封锁用户的帐号的
	
	'逐项检查管理页面提交的封锁用户帐号的复选框cUserID
	for each item in Request.Form ("cUserID")
	'如果复选框被选中了,就封锁用户的帐号,并把用户从聊天室中清除出去
	if item <>"" then
	'使用变量记录用户的帐号,item的值就是该用户的帐号,因为帐号能唯一确定一个用户
	    hisid=item	
		'从Fault表中查找该用户以前是否有犯规的记录.如果有,就更新该用户的记录
		'如果没有,就在Fault表中插入一条新记录,记录该用户的帐号被封
		newsql="select FaultUserID from Fault where FaultUserID='" & hisid & "'"
		set newrecord=newconn.Execute (newsql)
		if not newrecord.bof then
		newsql1="update Fault set IDIfClosed=true,IDCloseCount=idclosecount+1,IDCloseTime='" & date() & "',IDOpenTime='" & dateadd("d",2,date()) & "' where FaultUserID='" & hisid & "'"
		newconn.Execute (newsql1)
		else
			newsql2="insert into Fault(FaultUserID,IDCloseCount,IDCloseTime,IDOpenTime,idifclosed) values ('" & hisid & "',1,'" & date() & "','" & dateadd("d",2,date()) & "',1)" 
			newconn.Execute (newsql2)
		end if	
		
		'从在线用户表中查找该用户所在的房间,把该房间中的人数减少一个
		newsql3="select RoomName from UserOnLine where OnLineUserID='" & hisid & "'"
		set newrecord1=newconn.Execute (newsql3)		
		hisroom=newrecord1(0)				
		newsql4="update RoomInfo set HowManyUsers=HowManyUsers-1 where RoomName='" & hisroom & "'"
		newconn.Execute (newsql4)
		'从在线用户表中删除该用户
		newsql5="delete from UserOnLine where OnLineUserID='" & hisid & "'"
		newconn.Execute (newsql5)		
		'通知所有在线用户某用户的帐号已经被封
		newsql6="select OnLineUserID from UserOnLine"
		set newrecord2=newconn.Execute (newsql6)
		if not newrecord2.bof then
			do while not newrecord2.eof
				application(newrecord2(0))="<br>用户<font color=vbred>" & item & "</font>已经被封!<br><br>" & application(newrecord2(0))
				newrecord2.movenext
			loop		
		end if
		'反馈给管理员执行的封某用户的帐号的操作已经执行成功
		Response.Write "<br>用户<font color=vbred>" & item & "</font>已经被封!<br>"	
		'关闭记录集对象	
	newrecord.close
	    set newrecord=nothing
		newrecord1.close
	    set newrecord1=nothing
		newrecord2.close
	    set newrecord2=nothing
	end if
	next 
	
	
	'以下程序段是执行把犯规用户踢出聊天室的
	'逐项检查管理页面提交的把用户踢出聊天室的复选框kUserID
	for each item in Request.Form("kUserID")
	'如果复选框被选中了,就把用户从聊天室中踢出
	if item<>"" then
		hisid=item	
		'从Fault表中查找该用户以前是否有犯规的记录.如果有,就更新该用户的记录
		'如果没有,就在Fault表中插入一条新记录,记录该用户被踢出聊天室一次
		newsql="select FaultUserID from Fault where FaultUserID='" & hisid & "'"
		set newrecord=newconn.Execute (newsql)
		if not newrecord.bof then
			newsql1="update Fault set warnings=warnings+1 where FaultUserID='" & hisid & "'"
		    newconn.Execute (newsql1)			
		else
			newsql2="insert into Fault(FaultUserID,warnings) values ('" & hisid & "',1)" 
			Response.Write newsql2
			newconn.Execute (newsql2)
		end if
		'从在线用户表中查找该用户所在的房间,把该房间中的人数减少一个
		newsql3="select RoomName from UserOnLine where OnLineUserID='" & hisid & "'"
		set newrecord1=newconn.Execute (newsql3)		
		hisroom=newrecord1(0)				
		newsql4="update RoomInfo set HowManyUsers=HowManyUsers-1 where RoomName='" & hisroom & "'"
		newconn.Execute (newsql4)	
		'从在线用户表中删除该用户
		newsql5="delete from UserOnLine where OnLineUserID='" & hisid & "'"
		newconn.Execute (newsql5)		
		'通知所有在线用户某用户已被踢出聊天室		
		newsql6="select OnlineUserID from UserOnLine"
		set newrecord2=newconn.Execute (newsql6)		
		if not newrecord2.bof then
			do while not newrecord2.eof
				application(newrecord2(0))="<br>用户--<font color=vbred>" & hisid & "</font>--已经被踢出聊天室!<br><br>" & application(newrecord2(0))
				newrecord2.movenext
			loop		
		end if
		'定义application变量记录用户被踢出聊天室
		application(item)="***kickout***"		
		'反馈给管理员某用户已经被踢出聊天室
		Response.Write "用户<font color=vbred>" & hisid & "</font>已经被踢出聊天室!<br>"
		'关闭记录集对象,释放与其相关的资源
	newrecord.close
	    set newrecord=nothing
		newrecord2.close
	    set newrecord2=nothing
		newrecord3.close
	    set newrecord3=nothing
	end if
	next
'从useronline表和Fault表中查找在线用户的相关信息
		newsql1="select OnLineUserID,NickName,RoomName,warnings,idclosecount,ipclosecount,OnLineuserip,logintime,lasttalkingtime from useronline left join fault on useronline.onlineuserid=fault.faultuserid"
'由于通常情况下,useronline表中用户的数量一般比Fault表中用户的数量多,应该采用"left join"语句允许fault表中的字段为空,on后的语句是两个表连接的条件
'LEFT JOIN 操作可以创建一个左外部联接。左外部联接包含两个表中第一个(左)表中的所有记录,第二个(右)表中可以没有匹配的记录值		
'还有右外部联接RIGHT JOIN 操作,右外部联接包含两个表中第二个(右)表中的所有记录,而第一个(左)表中可以没有匹配的记录值
'left join和right join都只是access数据库中的外部连接操作,各种不同的数据库中的外部连接的操作语句不尽相同

		set newrecord1=newconn.Execute (newsql1)
'判断目前是否有在线用户		
			if newrecord1.bof then
				Response.Write ("目前没有在线用户!<br>")	
%>
<p align="center"><font color="#FF6633"><strong><big>在线用户信息管理</big></strong></font></p>
<center>
  <table border="1"
  style="text-align: center; color: rgb(0,0,255)">
    <tr>
      <td>用户名</td>
      <td>昵称</td>
      <td>房间名</td>
      <td>警告次数</td>
      <td>ID被封次数</td>
      <td>IP被封次数</td>
      <td>是否Kick</td>
      <td>封ID</td>
      <td>Ip地址</td>
      <td>封IP</td>
      <td>登录时间</td>
      <td>最后发言时间</td>
    </tr>
  </table>
</center>
<%
			else'这个else是与if newrecord1.bof then语句相对应的
			
%>
<p align="center"><font color="#FF6633"><strong><big>在线用户信息管理</big></strong></font></p>
<!--提交管理内容的表单,该表单是将管理内容提交到该页面本身进行处理的-->
<form name="admin" method="POST" action="onlineadmin.asp">
  <center>
    <!--使用表格列出用户信息-->
    <table border="1"
  style="text-align: center; color: rgb(0,0,255)">
      <tr>
        <td>用户名</td>
        <td>昵称</td>
        <td>房间名</td>
        <td>警告次数</td>
        <td>ID被封次数</td>
        <td>IP被封次数</td>
        <td>是否Kick</td>
        <td>封ID</td>
        <td>Ip地址</td>
        <td>封IP</td>
        <td>登录时间</td>
        <td>最后发言时间</td>
      </tr>
      <%
	do while not newrecord1.eof 
%>
      <tr>
        <td><a href="adminspeak.asp?userid=<% =newrecord1(0) %>">
          <% =newrecord1(0) %>
          </a></td>
        <td><% =newrecord1(1) %></td>
        <td><% =newrecord1(2) %></td>
        <td><% =newrecord1(3) %></td>
        <td><% =newrecord1(4) %></td>
        <td><% =newrecord1(5) %></td>
        <td><input name="kUserID" type="checkbox" value="<% =newrecord1(0) %>"></td>
        <td><input name="cUserID" type="checkbox" value="<% =newrecord1(0) %>"></td>
        <td><% =newrecord1(6) %></td>
        <td><input name="Ip" type="checkbox" id="Ip" value="<% =newrecord1(0) %>"></td>
        <td><% =newrecord1(7) %></td>
        <td><% =newrecord1(8) %></td>
      </tr>
      <%
			newrecord1.movenext
			loop
			end if'与if newrecord1.bof then语句相对应

%>
    </table>
  </center>
  </p>
  <table width="133" align="center">
    <tr>
      <td width="52"><div align="center">
          <input type="submit" value="提交"  name="B1">
        </div></td>
      <td width="12"><div align="center"></div></td>
      <td width="53"><div align="center">
          <input type="reset" value="重置" name="B2">
        </div></td>
    </tr>
  </table>
  <!--链接到注册用户管理和发送信息页面-->
</form>
<center>
  <a href="useradmin.asp">注册用户管理</a>
</center>
<center>
  <a href="adminspeak.asp">发送信息</a>
</center>
<% 
		else '与if newrecord0(0)=9 then语句相对应
			Response.Write ("你没有权限进入!<br>")
			'关闭记录集对象
		'newrecord1.close
	    'set newrecord1=nothing
		end if'与if newrecord0(0)=9 then语句相对应
	end if'与if newrecord0.bof then语句相对应

else'与if Request.ServerVariables ("REQUEST_METHOD")="POST" then语句相对应
%>
<!--提交输入用户名和密码等待验证管理员权限的表单-->
<form method="POST" action="onlineadmin.asp" name="check">
  <p>
  <div align="center">
    <center>
      请输入帐号:
      <input name="Admin_UID"  type="text" maxlength="10">
    </center>
  </div>
  <div align="center">
    <center>
      <p> 请输入密码:
        <input name="Admin_PWD"  type="password" maxlength="10">
      </p>
    </center>
  </div>
  <div align="center">
    <center>
      <table width="135">
        <tr>
          <td width="59"><div align="center">
              <input type="submit" value="提交"  name="B1">
            </div></td>
          <td width="30"><div align="center"></div></td>
          <td width="63"><div align="center">
              <input type="reset" value="重置" name="B2">
            </div></td>
        </tr>
      </table>
    </center>
  </div>
</form>
<% 
end if'与if Request.ServerVariables ("REQUEST_METHOD")="POST" then语句相对应的
end if'与if session("admin_pass")="ok" then语句相对应
%>
</body>
</html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -