<!--#include File="conn.asp"-->
<%
dim action,id
action = be("get", "action")
id = be("get", "id") : id = chkSql(id, True)

Select Case action
	Case "vodhit", "arthit": gethit
	Case "goodnum", "badnum": goodbad
	Case "vodgood", "vodbad": voddigg
	Case "diypage": diypage
	Case "desktop": desktop
	Case "score": score
	Case "getscore" : getscore
	Case "loginstatus": loginstatus
	Case "userfav" : userfav
	Case "reporterr": reporterr
	Case Else: main
End Select
dispseObj()

Sub main()
    
End Sub

Sub goodbad()
	dim rs,result
	If Not isNum(id) Then writeA "err": Exit Sub
	result=0
	Set rs = objdb.DB("SELECT d_good,d_bad FROM {pre}vod WHERE d_id=" & id, "rs1")
	if not rs.eof then
		if action = "goodnum" then 
			result = rs("d_good")
		else
			result = rs("d_bad")
		end if
	end if
	objdb.C (rs)
	writeA result
End Sub

Sub voddigg()
	Dim good, bad,rs,result
	If getCookie("digg_" & action & id) = "ok" Then writeA "haved": Exit Sub
	Set rs = objdb.DB("SELECT d_good,d_bad FROM {pre}vod WHERE d_id=" & id, "rs3")
	If Not rs.EOF Then
		If action = "vodgood" Then
			rs("d_good") = rs("d_good") + 1
			result = rs("d_good")
		Else
			rs("d_bad") = rs("d_bad") + 1
			result = rs("d_bad")
		End If
		rs.update
	End If
	objdb.C (rs)
	setCookie "digg_" & action & id, "ok"
	writeA result
End Sub

Sub gethit()
	Dim sday, sweek, smonth,result,rs,dayhits,weekhits,monthhits,hitstime
	If Not isNum(id) Then writeA "err": Exit Sub
	result = 0
	sday = Year(Date) & "-" & Month(Date) & "-" & Day(Date)
	smonth = Year(Date) & "-" & Month(Date)
	
	If action = "arthit" Then
		Set rs = objdb.DB("SELECT a_hits,a_dayhits,a_weekhits,a_monthhits,a_hitstime FROM {pre}art WHERE a_id=" & id, "rs3")
		If Not rs.EOF Then
			dayhits=rs("a_dayhits")
			weekhits=rs("a_weekhits")
			monthhits=rs("a_monthhits")
			
			if objFile.isFileExists(app_installdir & "inc/hitstimeart.txt") then 
				hitstime = objFile.getFile(app_installdir & "inc/hitstimeart.txt")
			end if
			if Not isN(hitstime) then
				if Month(Date) <> month( hitstime ) then
					objdb.DB "UPDATE {pre}art set a_monthhits=0", "exe"
					monthhits=0
				end if
				If DateDiff("ww",hitstime,now)>0 Then
					objdb.DB "UPDATE {pre}art set a_weekhits=0", "exe"
					weekhits=0
				End If
				If Day(Date) <> Day(hitstime) Then
					objdb.DB "UPDATE {pre}art set a_dayhits=0", "exe"
					dayhits=0
				End If
			end if
			rs("a_hitstime") = Now()
			rs("a_hits") = rs("a_hits") + 1
			rs("a_dayhits") = dayhits + 1
			rs("a_weekhits") = weekhits + 1
			rs("a_monthhits") = monthhits + 1
			rs.update
			objFile.createFile app_installdir & "inc/hitstimeart.txt",now
			result = rs("a_hits")
		End If
	Else
		Set rs = objdb.DB("SELECT d_hits,d_dayhits,d_weekhits,d_monthhits,d_hitstime FROM {pre}vod WHERE d_id=" & id, "rs3")
		If Not rs.EOF Then
			dayhits=rs("d_dayhits")
			weekhits=rs("d_weekhits")
			monthhits=rs("d_monthhits")
			if objFile.isFileExists(app_installdir & "inc/hitstimevod.txt") then 
				hitstime = objFile.getFile(app_installdir & "inc/hitstimevod.txt")
			end if
			if Not isN(hitstime) then
				if Month(Date) <> month( hitstime ) then
					objdb.DB "UPDATE {pre}vod set d_monthhits=0", "exe"
					monthhits=0
				end if
				If DateDiff("ww",hitstime,now)>0 Then
					objdb.DB "UPDATE {pre}vod set d_weekhits=0", "exe"
					weekhits=0
				End If
				If Day(Date) <> Day(hitstime) Then
					objdb.DB "UPDATE {pre}vod set d_dayhits=0", "exe"
					dayhits=0
				End If
			end if
			rs("d_hitstime") = Now()
			rs("d_hits") = rs("d_hits") + 1
			rs("d_dayhits") = dayhits + 1
			rs("d_weekhits") = weekhits + 1
			rs("d_monthhits") = monthhits + 1
			rs.update
			objFile.createFile app_installdir & "inc/hitstimevod.txt",now
			result = rs("d_hits")
		End If
	End If
	objdb.C (rs)
	writeA result
End Sub
    
Sub diypage()
	Dim cacheName, Path
	Path = be("get", "path")
	cacheName = "template_diypage_" & Path
	If chkCache(cacheName) Then
		objTemplate.html = getCache(cacheName)
	Else
		Path = app_installdir & Path
		objTemplate.html = objFile.getFile(Path)
		objTemplate.mark
		setCache cacheName, objTemplate.html
		objTemplate.run "vod"
	End If
	writeA objTemplate.html
End Sub
    
Sub desktop()
	Dim url, name, rc : rc=false
	url = be("get", "url"): name = be("get", "name")
	if isN(name) then rc=true : name = app_sitename
	session.CodePage = 936	
	Response.ContentType = "APPLICATION/OCTET-STREAM;charset=utf-8"
	Response.AddHeader "Content-Disposition", "attachment;filename=" & name & ".url"
	session.CodePage = 65001
	Response.Write ("[InternetShortcut]") & Chr(13)
	if rc then
		Response.Write ("URL=http://" & app_siteurl) & Chr(13)
	elseif instr(url,"ttp://") > 0 then
		Response.Write ("URL=" & url) & Chr(13)
	else
		Response.Write ("URL=http://" & app_siteurl & url) & Chr(13)
	end if
	Response.Write ("IDList=") & Chr(13)
	Response.Write ("[{000214A0-0000-0000-C000-000000000046}]") & Chr(13)
	Response.Write ("Prop3=19,2") & Chr(13)
	Response.End
End Sub
    
Sub score()
	Dim score,result,rs,ac3
	score = be("get", "score"): score = chkSql(score, True)
	ac3 = be("get","ac3")
	If getCookie("vodscore_" & id) = "ok" Then writeA "haved": Exit Sub
	If Not isNum(id) Then writeA "err": Exit Sub
	If Not isNum(score) Then score = 0 Else score = CInt(score)
	If score < 0 Then score = 0
	If score > 10 Then score = 10
	result = 0
	Set rs = objdb.DB("SELECT d_id,d_score,d_scorecount FROM {pre}vod WHERE d_id=" & id, "rs3")
	If Not rs.Bof Then
		rs("d_score") = rs("d_score") + score
		rs("d_scorecount") = rs("d_scorecount") + 1
		rs.update
		result = FormatNumber(CDbl(rs("d_score")) / CDbl(rs("d_scorecount")), 1, -1, -1, 0)
		if ac3="all" then
			result =  rs("d_score") & "," &  rs("d_scorecount")  & "," &  FormatNumber(CDbl(rs("d_score")) / CDbl(rs("d_scorecount")), 1, -1, -1, 0)
		end if
	End If
	objdb.C (rs)
	setCookie "vodscore_" & id, "ok"
	writeA result
End Sub

sub getscore()
	dim result,rs,ac2,ac3,d_scorecount
	ac2=be("get","ac2")
	ac3=be("get","ac3")
	result=0
	if ac2="count" then
		result = objdb.DB("SELECT d_scorecount FROM {pre}vod WHERE d_id=" & id, "exe")(0)
	elseif ac2="pjf" then
		Set rs = objdb.DB("SELECT d_score,d_scorecount FROM {pre}vod WHERE d_id=" & id, "rs1")
		If Not rs.Bof Then
			d_scorecount = rs("d_scorecount")
			if d_scorecount=0 then d_scorecount=1
			result = FormatNumber(CDbl(rs("d_score")) / CDbl(d_scorecount), 1, -1, -1, 0)
			if ac3="all" then
				result =  rs("d_score") & "," &  d_scorecount & "," &  FormatNumber(CDbl(rs("d_score")) / CDbl(d_scorecount), 1, -1, -1, 0)
			end if
		End If
		objdb.C (rs)
	else
		result = objdb.DB("SELECT d_score FROM {pre}vod WHERE d_id=" & id, "exe")(0)
	end if
	writeA result
end sub

sub loginstatus()
	
end sub

sub userfav()
	dim rs,result,u_fav
	If Not isNum(id) Then writeA "err": Exit Sub
	if isN(Session("userid")) then writeA "login": Exit Sub
	result = "err"
	set rs = objdb.db("select * from {pre}user where u_id = " & session("userid"),"rs3")
	if not rs.bof then
		u_fav = rs("u_fav")
		if isN(u_fav) then
			rs("u_fav") = ","& id & ","
			result = "ok"
		else
			if instr( ","&u_fav ,","&id&",") then
				result = "haved"
			else
				u_fav = u_fav & id & ","
				rs("u_fav") = u_fav
				result = "ok"
			end if
		end if
		rs.update
	end if
	objdb.C (rs)
	writeA result
end sub

sub reporterr()
	dim g_vid,g_name,g_content,g_audit,g_ip,g_time
	g_vid = be("post","g_vid") : g_vid = chkSql(g_vid, True)
	g_name = be("post","g_name") : g_name = chkSql(g_name, True)
	g_content = be("post","g_content") : g_content = chkSql(g_content, True)
	if not isNum(g_vid) then alert "请填写正确参数" : exit sub
	if len(g_name) > 64 then g_name = left(g_name,64)
	if len(g_content) > 255 then g_content = left(g_content,255)
	if app_gbookaudit=1 then g_audit=0 else g_audit=1
	g_ip = getIP()
    g_time = Now()
    If getTimeSpan("lastreportErrTime") < app_gbooktime Then alert "请稍后再试": Exit Sub
    
	objdb.add "{pre}gbook", Array("g_vid","g_audit","g_name", "g_ip", "g_time", "g_content"), Array(g_vid, g_audit, g_name, g_ip, g_time, g_content)
	Session("lastreportErrTime") = Now
	writeA "报错成功,多谢支持!<script>setTimeout(""window.close()"",1000)</script>"
end sub
%>