<!--#Include File="conn.asp"-->
<!--#Include File="inc/const.asp"-->
<!--#Include File="inc/sub.asp"-->
<!--#Include File="inc/PrintMsg.asp"-->
<!--#Include File="CurrExecuteFile.asp"-->
<%

	function newincept()
		msql = "Select Count(id) from [message] " &_
			"where flag=0 and issend=1 and delR=0 and incept='" & Cook_UserName & "'"
		set rsm = conn.execute(msql)
			newincept = rsm(0)
		set rsm = nothing

		if isnull(newincept) then
			newincept=0
		end if
	end function




	sub OnlineUser()
		if not isLogin then
			exit sub
		end if

		dim sqlo

		'首先，删除 20 分钟不活动用户
		'--------------------------------------------------
		dim strOnlineTimedOut
		strOnlineTimedOut = 1200
		sqlo = "delete from [Online] where DateDiff(s, lastimebk, getdate()) > " & strOnlineTimedOut
		Conn.Execute sqlo


		'而后，记录在线用户到数据库
		'--------------------------------------------------
		MyIp = Request.ServerVariables("REMOTE_HOST")
		MyId = replace(MyIp,".","")
		MyActforip = Request.ServerVariables("HTTP_X_FORWARDED_FOR")

		sqlo = "select username from [Online] where username='" & Cook_UserName & "'"
		rs.open sqlo,conn,1,3
		if rs.eof and rs.bof then
			sql="insert into Online" &_
				"(id,username,userclass,ip,startime,lastimebk,lastime,stats,actforip) values "&_
				"(" & MyId & ",'" & Cook_UserName & "','" & Cook_adminFlag & "','" & MyIp & "',getdate(),getdate(),'" & DateToStr(now()) & "'," &_
				"'系统管理区','" & MyActforip & "')"
			conn.execute(sql)
		else
			sql = "update [Online] set " &_
				"lastimebk=getdate()," &_
				"lastime='" & DateToStr(now()) & "' " &_
				"where username='" & Cook_UserName & "'"
			conn.execute(sql)
		end if
		rs.close

		sqlo = "select count(username) from [Online]"
		rs.open sqlo,conn,1,1
			OnlineMemberNum = rs(0)
		rs.close
		if isnull(OnlineMemberNum) or OnlineMemberNum="" then
			OnlineMemberNum = 0
		end if
	end sub



	function DateToStr(dtDateTime)
		DateToStr = year(dtDateTime) &_
			doublenum(Month(dtdateTime)) &_
			doublenum(Day(dtdateTime)) &_
			doublenum(Hour(dtdateTime)) &_
			doublenum(Minute(dtdateTime)) &_
			doublenum(Second(dtdateTime)) & ""
	end function
%>

