<%
'**************************************
'* 最后更新 2013-02-27 by 56770.kingdge
'* Copyright www.56770.com
'**************************************
Select Case request("do")
       Case "save" : save()
	   Case "rating" : rating()
End Select

rem 2008-3-8 添加敏感文字过滤  by 56770.WangLei
Sub save()
        Dim content,downid,name,sql
        content=replace(replace(replace(request("content"), "'","&#180;"), "<", "&lt; "), ">", "&gt; ")
		content=reBadWord(content)
        name=safereplace(request("name"))
		name=reBadWord(name)
        downid=CLng(request("id"))
        If content="" Then
                response.redirect Eshop_url & PagePath(1) &"?action=comment"
		        response.End
        Else
                'If session("truevote")<>downid Then
		        Dim rsdvote
                Set rsdvote=Server.CreateObject("ADODB.RecordSet")
                sql="select * from [Lebi_Dvote] where (id is null)"
                rsdvote.open sql, conn, 1,3
                rsdvote.addnew
                rsdvote("content")=content
                rsdvote("downid")=downid
                session("truevote")=downid
                if Lebi_UserId <>"" then
                        rsdvote("user_id") = Lebi_UserId
                end if
                rsdvote("vtime")=now()
                rsdvote("name")=name
                rsdvote("show")="0"
                rsdvote("ip")=GetIP()
				rsdvote("LangTxt")=LangTxt
                rsdvote.update
                rsdvote.close:Set rsdvote=Nothing
		        '更新状态 用于更新HTML 2006-4-20 Lebi.kingdge
                conn.execute("update [Lebi_product] set html=0 where id="& downid &"")
                response.redirect Eshop_url & PagePath(2) &"?do=comment&suc_1="& Request.ServerVariables("HTTP_REFERER")
		        response.End
        End If
End Sub

Sub rating()
        id = checknum(request("id"),0)
		Rank = checknum(request("Rank"),0)
	    If Lebi_UserId ="" Then
                response.redirect Eshop_url & PagePath(1) &"?action=needlogin&HTTP_REFERER="& server.urlencode(GetFileUrl())
		        response.End
		End If
		Set rs = server.CreateObject("adodb.recordset")
		rs.open "select * from [Lebi_rating] where p_id = "& id &" and r_user = '"& Lebi_UserId &"'",conn,1,3
		If rs.eof Then
		        rs.addnew
                rs("r_num") = Rank
				rs("r_user") = Lebi_UserId
				rs("r_time") = Now()
				rs("p_id") = id
		        rs.update
				Set rss = conn.execute("select r_num from [Lebi_rating] where p_id = "& id &"")
				total_rating = 0 : total_user = 0
				Do While Not rss.eof
				total_rating = total_rating + rss(0)
				total_user = total_user + 1
				rss.movenext
				Loop
				rss.close : Set rss = Nothing
				conn.execute("update [Lebi_product] set p_rating = "& CDbl(total_rating/total_user) &" where id = "& id &"")
				backurl = Request.ServerVariables("HTTP_REFERER")
				If Instr(backurl,"REDIRECT=") > 0 Then backurl = urldecode(Split(backurl,"REDIRECT=")(1))
				If backurl = "" Then
					backurl = Request.ServerVariables("QUERY_STRING")
					If Instr(backurl,"REDIRECT=") > 0 Then backurl = urldecode(Split(backurl,"REDIRECT=")(1))
				End If 
				response.redirect backurl
				response.End
		Else
                response.redirect Eshop_url & PagePath(1) &"?action=rating"
		        response.End
		End If
		rs.close
End Sub
%>
