<!-- #include file="../inc/conn.asp" -->
<%
response.Charset="GBK"
Response.Buffer = True
Response.ExpiresAbsolute = Now() - 1
Response.Expires = 0
Response.CacheControl = "no-cache"


Dim action
action = SafeData("RQ","action",0)

Select case action
Case "add"
	Call add
Case Else
	Call main
End Select

Sub add
Dim C_VID,C_Name,C_Content,C_AddTime,C_Ip
C_VID= SafeData("R","C_VID",0)

If Not isNum(C_VID)   then
	Call AlertUrl("请勿传递非法参数！","/Index.ASP")
End IF

C_Name = badFilter(HtmlEncode(unescape(SafeData("R","user",0))))
C_Content=badFilter(HtmlEncode(unescape(SafeData("R","content",0))))
C_Ip = GetIP()
C_AddTime = now()

If C_VID="" Or C_Name="" Or C_Content="" Then 
	response.write"<div id='comment_load'>null</div>"
	response.End
End If 

Dim result : result = DataBase.AddRecord("Tbl_Comment",Array("C_Name:"&C_Name, "C_Content:"&C_Content,"C_Ip:"&C_Ip,"C_AddTime:"&C_AddTime,"C_VID:"&C_VID)) 
		
response.redirect "?C_VID="&C_VID
End Sub 

Sub main
Dim C_VID,page,total,p,rs,sql,i,bgcolorArr
Dim commentStr,C_Name,C_Content,C_AddTime

C_VID=SafeData("R","C_VID",0)
page=SafeData("R","page",0)

if isN(page) then page = 1 else page=cint(page)

If IsNum(C_VID)=False Then 
	response.write "<div id='comment_load'>null</div>"
	response.End
End If 

response.write "<div id='comment_load'>"
set rs = server.createobject("adodb.recordset")
sql="select C_ID,C_Name,C_Content,C_AddTime,C_Ip,C_VID from Tbl_Comment Where C_VID="&C_VID&" order by C_ID desc"
rs.open sql,conn,1,1
i=0
If rs.bof Or rs.eof Then
	response.write "<center><BR><h2>该片暂无评论，快来抢沙发吧！</h2></center>"
Else 
rs.pagesize=10

total = rs.pagecount
p = rs.recordcount
if page>total then
page=total
else
rs.absolutepage = page
end If
response.write "<div class='a_page'>共<strong style=""font-size:18px;"";>"&p&"</strong>位网友参与评论</div><div class='c_page'>"&getPageInfo(total,Page,C_VID)&"</div>"
bgcolorArr=Array("#D66103","#512DBD","#780E1A","#C5A200","#DA4912","#530752","#C5A200","#512DBD","#D66103","#530752")
Do while not rs.eof
i=i+1

C_VID= rs("C_VID")
C_Name= getData(rs("C_Name"))
C_Content= getData(rs("C_Content"))
C_AddTime = getData(rs("C_AddTime"))

%><div style="clear:both;padding:10px; border:solid 1px #F3F3F3; margin-top:10px; background:#F7F7F7; word-wrap:break-word;" onmouseover="this.style.backgroundColor='#FFFFFF';" onmouseout="this.style.backgroundColor='#F7F7F7';">
	<span style="float:right">第<%=p-(page-1)*10-(i-1)%>楼</span>
	<span style="background-color:<%=bgcolorArr(rnd_num(1))%>;color:#FFFFFF;padding:2px 5px;"><b><%=C_Name%></b></span> 发表于 <%=C_AddTime%>
	<p style="padding-top:5px;margin:0px;margin-top:5px;"><%=C_Content%></p>
	</div>
<%
If i>=10 Then Exit Do 
rs.movenext
Loop 
rs.close
set rs=Nothing
Response.write"<div class='c_page'>"&getPageInfo(total,Page,C_VID)&"</div>"
End If %>
<div style="padding:2px;font-size:13px;font-weight:bold;margin-top:5px;">发表评论</div>
<div>
<a name="post"></a>
<p><span style="font-size:13px;">您的大名：</span>
<input id="name" name="name" type="text" value="游客" class="text" size=15/>
<font color="#FF0000">*</font>
小提示：<font color=red>按Ctrl+Enter(回车)可直接发表留言，发表评论页面不会跳转。</font>
</p>
<p><textarea id="content" name="content" wrap="virtual" onkeydown="ctlent()" rows=6 style="width:96%;background:#fffff9;border:1px #eaeaea solid;" class="text"></textarea>
</p>
<div>
<input type="hidden" id="C_VID" name="C_VID" value="<%=C_VID%>">
<input name="post" type="button" id="post_btn" value="发表评论" onClick="submit_comment();" style="padding:3px; font-weight:bold; font-size:1.1em;"/>

<div id="msg" style="margin-top:10px;"></div>
</div>
<div style="text-align:right">以上节目和评论均不代表『<%=app_sitename%>』观点</div>
</div>
<%End Sub 

'生成0-9间的随机数
function rnd_num(digits)
	dim rndnum,num
	Randomize
	Do while Len(rndnum)<digits
		num = Cstr(Chr((57-48)*rnd+48))
		rndnum = rndnum & num
	Loop
	rnd_num = rndnum
End Function

'脏字过滤
Function badFilter(Str)
Dim filters ,badKeywordArr,s_i
filters = "胡锦涛,温家宝,尻,屌,操你,干死你,贱人,狗娘,婊子,表子,靠你,叉你,叉死,插你,插死,干你,干死,日你,日死,鸡巴,睾丸,包皮,龟头,屄,赑,妣,肏,奶子,奶头,阴毛,阴道,阴茎,叫床,强奸,爱液,性高潮,做爱,性交,口交,肛交,chdy8,http,//,com,cn,net,org,www"
	badKeywordArr=split(filters,",")
	for s_i=0 to ubound(badKeywordArr)	
		Str=replace(Str,badKeywordArr(s_i),"***") 
	Next
	badFilter=Str
End Function

%>
<script language="javascript" runat="server"> 
function getPageInfo(totalPage,absolutePage,lid){ 
    if(isNaN(totalPage))totalPage=1; 
    var pgStr=""; 
    var has1=absolutePage-5>=1; 
    var has2=absolutePage+5<=totalPage; 
    var begin=end=1; 
    if(has1 && has2){ 
      begin=absolutePage-4; 
      end=absolutePage+5; 
    }else if(!has1 && has2){ 
      begin=1; 
      end=totalPage>=10?10:totalPage; 
    }else if(has1 && !has2){ 
      begin=totalPage-9;begin=begin<1?1:begin; 
      end=totalPage; 
    }else{ 
      begin=1; 
      end=totalPage; 
    } 
		pgStr='共'+totalPage+'页&nbsp;'
    if(absolutePage>1){ 
		pgStr+="<a href='javascript:' onClick='page("+lid+",1);return false;' title='第一页'>首页</a>";
    }else{ 
        pgStr+=' '; 
    } 
    if(absolutePage>1){ 
		pgStr+=" <a href='javascript:' onclick='page("+lid+","+eval(absolutePage-1)+");return false;' title='上一页'>上一页</a>";
    }else{ 
        pgStr+=' '; 
    } 
    for(i=begin;i<=end;i++){
		if(i!=absolutePage){
			pgStr+=" <a href='javascript:' onclick='page("+lid+","+i+");return false;'";
		}else{
			pgStr+=" <a class=\"is_on\"";
		}
		pgStr+=">"+i+"</a>";
    } 
    if(absolutePage<totalPage){ 
        pgStr+=" <a href='javascript:' onclick='page("+lid+","+eval(absolutePage+1)+");return false;' title='下一页'>下一页</a>";
    }else{ 
        pgStr+=' ' 
    } 
	if(absolutePage<totalPage){ 
        pgStr+=" <a href='javascript:' onclick='page("+lid+","+eval(totalPage)+");return false;' title='最后一页'>尾页</a>";
    }else{ 
        pgStr+='  '; 
    }
    return ""+pgStr+""; 
} 
</script>