<%
Public Forum_sdjy
dim sdbbsuser
dim MemberName,MemberClass,UserID,Founduser,Memberword

Forum_sdjy = "sdjy"
if Request.Cookies("iscookies")="" then
	Response.Cookies("iscookies")="0"
	Response.Cookies("iscookies").Expires=date+365
'	response.write "<META http-equiv=Content-Type content=text/html; charset=gb2312><meta HTTP-EQUIV=REFRESH CONTENT=3>正在登陆"& Site_Name &"……<br><br>本系统要求使用COOKIES，假如您的浏览器禁用COOKIES，您将不能登录本系统……"
'	response.end
end if

Founduser=false

sdbbsuser=Request.Cookies("DvForum")("username")
abcedas=Request.Cookies(Forum_sdjy)("username")
if sdbbsuser<>"" and abcedas="" then
        set rs=server.CreateObject("adodb.recordset")
		sqla="select userid,username,sex,userpass,grade from user_info where username='"&sdbbsuser&"'"
		rs.open sqla,conn,1		
		if not(rs.eof or rs.bof) then		

dim Sd_userid1,Sd_userpass1,Sd_userclass1,Sd_username1
sd_sex=rs("sex")



Sd_username1=rs("username")
Sd_userpass1=rs("userpass")
select case rs("grade")
  case 1
    Sd_userclass1="注册会员"
  case 2
    Sd_userclass1="普通会员"
  case 3
    Sd_userclass1="VIP会员"
end select
Sd_userid1=rs("userid")
rs.close
set rs=nothing

conn.execute("insert into sd_online(userid,username,starttime,starttimebk) values('"& Sd_userid1 &"','"& Sd_username1 &"','"& now() &"','"& now() &"')")

Response.Cookies(Forum_sdjy)("usercookies")=0
Response.Cookies(Forum_sdjy)("username")=Sd_username1
Response.Cookies(Forum_sdjy)("password")=Sd_userpass1
Response.Cookies(Forum_sdjy)("userclass")=Sd_userclass1
Response.Cookies(Forum_sdjy)("UserID")=Sd_userid1
end if
end if



MemberName = checkStr(Trim(Request.Cookies(Forum_sdjy)("username")))
UserID = checkStr(Trim(Request.Cookies(Forum_sdjy)("UserID")))
Memberword=checkStr(Trim(Request.Cookies(Forum_sdjy)("password")))
memberclass=checkStr(request.cookies(Forum_sdjy)("Userclass"))


If IsNumeric(UserID) = 0 Or UserID="" Then UserID=0
UserID = Clng(UserID)


Public function isInteger(para)
       'on error resume next
       dim str
       dim l,i
       if isNUll(para) then 
          isInteger=false
          exit function
       end if
       str=cstr(para)
       if trim(str)="" then
          isInteger=false
          exit function
       end if
       l=len(str)
       for i=1 to l
           if mid(str,i,1)>"9" or mid(str,i,1)<"0" then
              isInteger=false 
              exit function
           end if
       next
       isInteger=true
       if err.number<>0 then err.clear
end function

Public Sub EmptyCookies()
		Response.Cookies(Forum_sdjy)("usercookies") = 0		
		Response.Cookies(Forum_sdjy)("username") = ""
		Response.Cookies(Forum_sdjy)("userpass") = ""
		Response.Cookies(Forum_sdjy)("UserID") = 0
		Response.Cookies(Forum_sdjy)("userclass") = ""	
End Sub

if userid<>"" and isInteger(userid) then
    set rs=server.CreateObject("adodb.recordset")
	sql="select Userid,Userpass,Username from [user_info] where userid="&userid
	set rs=conn.execute(sql)
	if rs.eof and rs.bof then
		founduser=false
		Rs.Close:Set Rs = Nothing
		zsql="select * from sd_online where datediff(mi,starttime,starttimebk)>30 and userid="&userid
	'	response.Write(zsql)
	'	response.End()
		set zxrs=conn.execute(zsql)
if not zxrs.eof then
conn.execute("update user_info set jf=jf+5 where userid="&userid)
end if
		
		conn.execute("delete from sd_online where userid="& userid &"")
			UserID = 0
			EmptyCookies
			'删除在线状态
	else	   
		if trim(rs(1))=trim(Memberword) and lcase(trim(MemberName))=lcase(trim(rs(2))) then
			founduser=true
			userid=rs(0)			
			conn.execute("update sd_online set starttimebk='"& now() &"' where userid="& userid &"")			
		else
			founduser=false
		end if       		    
		rs.close
	    set rs=nothing
	end if	
end if


set scs=conn.execute("select * From [sd_Online] Where UserID>0 And Datediff(Mi, starttimebk,getdate()) > 30") 

do while not scs.eof 
zsql="select * from sd_online where datediff(mi,starttime,starttimebk)>30 and userid= " & scs("userid")
'	response.Write(zsql)
'		response.End()
set zxrs=conn.execute(zsql)
if not zxrs.eof then
conn.execute("update user_info set jf=jf+5 where userid="&zxrs("userid"))

end if
scs.movenext
loop


conn.execute("Delete From [sd_Online] Where UserID>0 And Datediff(Mi, starttimebk,getdate()) > 30")  '删除超过30分钟无动作用户
set rs=conn.execute("Select * from [sd_online] where userid="& userid &"")
if rs.eof and rs.bof then
  	UserID = 0
	EmptyCookies
end if
rs.close
set rs=nothing
%>