<!--#include file="conn.asp"-->
<!--#include file="inc/const.asp"-->
<!-- #include file="inc/DvADChar.asp" -->
<%
'==============================================================
' for DVBBS7.1 自助工资1.0 纯绿色插件
' 由打火机修改，不存在版权问题，敬请随意传播
' 我的主站: http://www.52pm.com   论坛：http://www.52pm.com/bbs 
' 欢迎大家前来进行动网技术探讨交流
' 技术支持：http://www.52pm.Com/bbs  站长集中营QQ群：1246219
'==============================================================
response.buffer=true
Dvbbs.BoardID=0
Dvbbs.LoadTemplates("index")
Dvbbs.stats="退出存点"
Dvbbs.Nav()
Dvbbs.Head_var 2,0,"",""
if Cint(Dvbbs.GroupSetting(14))=0 then
	Errmsg=Errmsg+"<br>"+"<li>您没有在本社区积分的权限，请<a href=login.asp>登陆</a>或者同管理员联系。"
	call dvbbs_error()
else
	dim msgtext,savestats
	dim jf_StartTime,jf_WealthRate,jf_CPRate,jf_EPRate,SuanfaValue    '积分间隔时间，计算财产比率，计算魅力比率，计算经验比率，算法选择
	jf_StartTime=20
	jf_WealthRate=20
	jf_CPRate=20
	jf_EPRate=30
	call main()
	call exit1()
end if

sub main()
 dim username
 username=Dvbbs.membername
 dim stat,online,onlineT
 dim Srs
 set rs=server.createobject("adodb.recordset")
 sql="select * from [Dv_User] where username='"&username&"'"
 rs.open sql,conn,1,1

	dim srss,Q,W,C,T
	set Srs=conn.execute("select stats,startime from Dv_Online where username='"&username&"'")
	if Srs.eof and Srs.bof then        '用户在线数据未写入online表中或因超时已从online表中删除  
		rs.close
		set rs=nothing
		call exit1()
		Response.End
		end if 
	
	online=datediff("n",Srs(1),Now()) '提取在线时间  online=在线时间（分）
	onlineT=online + 5
	T=jf_StartTime            '在线时间（分）后开始计算,在此更改计算方法。

			Q=Int(online / jf_WealthRate) 
			W=Int(online / jf_EPRate) 
			C=Int(online / jf_CPRate) 
			'计算方法二
			'Q=Int(onlineT / jf_WealthRate)
			'W=Int(onlineT / jf_EPRate) 
			'C=Int(onlineT / jf_CPRate) 		
			'计算方法三
			'Q=iif(Int(onlineT / jf_WealthRate)>0,Int(onlineT / jf_WealthRate),1) 
			'W=iif(Int(onlineT / jf_EPRate)>0,Int(onlineT / jf_EPRate),1) 
			'C=iif(Int(onlineT / jf_CPRate)>0,Int(onlineT / jf_CPRate),1) 	

	
	dim rsl,sqll
	sqll="select * from [Dv_User] where  username='"&username&"'"
		set rsl=server.createobject("adodb.recordset")
	 rsl.open sqll,conn,1,3
	
	'userCP     魅力值
	'userEP     经验值
	'userWealth 财产值
	
	if online>=T then
		sqll="update [Dv_User] set userWealth=userWealth+"&Q&",userEP=userEP+"&W&",userCP=userCP+"&C&" where username='"&username&"'"
		conn.execute(sqll)
		rsl.close
		set rsl=nothing
	'保存当前时间
		set Srss=conn.execute("update [Dv_Online] set startime=Now() where username='"&username&"'") 
		Srs.close
		set Srs=nothing
		rs.close
		set rs=nothing
		%>
		<table cellpadding=3 cellspacing=1 align=center class=tableborder1>
		<tr><th height=25>安全退出</th></tr>
		<tr align=center><td class=tablebody1>你已经安全退出，并增加了<%=Q%>个金币，增加了<%=W%>点经验，增加了<%=C%>点魅力。</td></tr></table>
<%
	else     
		 %>
		<table cellpadding=3 cellspacing=1 align=center class=tableborder1>
		<tr><th height=25>安全退出</th></tr>
		<tr align=center><td class=tablebody1>你已经安全退出，但没有增加任何属性。</td></tr></table>
		<%
	end if 
end sub

sub exit1()
If IsArray(Session(Dvbbs.CacheName & "UserID")) Then
	If Not IsObject(Conn) Then ConnectionDatabase
	Dim activeuser,TempNum
	If Session(Dvbbs.CacheName & "UserID")(0)="Dvbbs" Then
		activeuser="delete from Dv_online where username='"&Session(Dvbbs.CacheName & "UserID")(5)&"'"
		Conn.Execute activeuser,TempNum
		'更新缓存总用户在线数据
		MyBoardOnline.Forum_UserOnline = MyBoardOnline.Forum_UserOnline - TempNum
		Dvbbs.Name="Forum_UserOnline"
		Dvbbs.value=MyBoardOnline.Forum_UserOnline
	Else
		If IsNumeric(Session(Dvbbs.CacheName & "UserID")(0)) Then 
			activeuser="delete from Dv_online where id="&Session(Dvbbs.CacheName & "UserID")(0)
			Conn.Execute activeuser,TempNum
			'更新缓存总用户在线数据
			MyBoardOnline.Forum_GuestOnline = MyBoardOnline.Forum_GuestOnline - TempNum
			Dvbbs.Name="Forum_GuestOnline"
			Dvbbs.value=MyBoardOnline.Forum_GuestOnline
		End If 
	End If
	MyBoardOnline.Forum_Online = MyBoardOnline.Forum_Online - TempNum
	Dvbbs.Name="Forum_Online"
	Dvbbs.value=MyBoardOnline.Forum_Online
	Response.Cookies(Dvbbs.Forum_sn).path=Dvbbs.cookiepath
	Response.Cookies(Dvbbs.Forum_sn)("username")=""
	Response.Cookies(Dvbbs.Forum_sn)("password")=""
	Response.Cookies(Dvbbs.Forum_sn)("userclass")=""
	Response.Cookies(Dvbbs.Forum_sn)("userid")=""
	Response.Cookies(Dvbbs.Forum_sn)("userhidden")=""
	Response.Cookies(Dvbbs.Forum_sn)("usercookies")=""
	Session(Dvbbs.CacheName & "UserID")=Empty
	Session("flag")=Empty
End If 
    %>
    <meta HTTP-EQUIV=REFRESH CONTENT="2; URL=index.asp">
    <%
end sub

function iif(expr,truepart,falsepart)
	'函数功能：如果表达式 expr 为真，则返回 truepart 的值；否则返回 falsepart 的值
	if expr then 
		iif=truepart
	else
		iif=falsepart
	end if	
end function
%>