<!--#include file="../Conn.asp"-->
<!--#include file="../Cache/QvodCms.Admin.asp"-->
<!--#include file="QvodCms.Security.asp"-->
<!--#include file="QvodCms.Fun.asp"-->
<%
Call OpenConn()
Dim uname,uid
Response.Buffer=True
Response.Expires=0
Response.Charset="gb2312"
uname=Request.Cookies("qvodcms")("Ulc")
uid=QvodCms_CLng(Request.Cookies("qvodcms")("Uid"))
upic=Trim(Request.Cookies("qvodcms")("UPic"))

If QvodCms_CLng(AdminId(10))=0 Then 
	Response.Write"<div id='comment_loadd'>SORRY！本站已关闭评论功能！</div>"
	Response.End 
End If
Dim Action,cm_id,data_id,cm_username,cm_content,cm_date,cm_ip,cm_pic,Psize,cm_code
Action=Request.QueryString("Action")
data_id=QvodCms_CLng(Request("data_id"))
cm_username=FilterDirty(Bad_Url(NoSqlHack(Request.Form("cm_username"))))
cm_content=FilterDirty(Bad_Url(NoSqlHack(Request.Form("cm_content"))))
cm_code=Trim(Request.QueryString("cm_code"))
Psize=QvodCms_CLng(AdminId(23))'分页大小
page=QvodCms_CLng(Request.QueryString("page"))
If page<1 Then page=1'页数初始化

Select Case Lcase(Action)
Case "add"
	Call add
Case "vertify"
	Call vertify
Case Else
	Call main
End Select

Sub vertify
    If cm_code="" or cm_code <> Session("CheckCode")  Then
        Response.Write "err2"
	Elseif Request.Cookies("LeaveWord_Flag")="yes" then
		Response.Write("yes")
	Else
		Response.Cookies("LeaveWord_Flag")="yes"
		Response.Cookies("LeaveWord_Flag").Expires=DateAdd("s",40,now())	
		Response.Write("no")
	End if
End Sub

Sub add	
    cm_id=Max_id("cm")
	cm_username=UserName(uname,uid)
	cm_content=Replacehtml(cm_content)
	cm_ip=QvodCms_Ip()
	cm_pic=UserPic(uname,uid,upic)
	If data_id="" Or cm_username="" Or cm_content="" Then 
		Response.Write cm_id&cm_content&"<div id='comment_load'>非法提交!</div>"
		Response.End
	End If 
	Conn.Execute("insert into qvodcms_cm(cm_id,data_id,cm_username,cm_content,cm_date,cm_ip,cm_pic) values("&cm_id&","&data_id&",'"&Replacehtml(cm_username)&"','"&Replacehtml(cm_content)&"','"&now()&"','"&cm_ip&"','"&cm_pic&"')")
	Response.Redirect"?data_id="&data_id
End Sub 

Sub main
Response.Write"<div id='comment_load'>"
%>
<!--<div id="commenttop">
<li>发表评论</li>
<li><span  class="comment_right">以下任何影评均不代表『<%=Config(8)%>』观点!</span></li>
</div>-->
<!--调用评论开始-->
<%
Set rs=server.createobject("adodb.recordset")
sql="select * from qvodcms_cm where data_id="&data_id&" order by cm_id desc"
rs.open sql,conn,1,1
i=0
If rs.bof Or rs.eof Then
    Response.write"<center><h4>该片暂无评论，快来抢沙发吧！</h2></center>"
Else 
	rs.pagesize=Psize    '每页数量
	total=rs.pagecount   '总页数
	p=rs.recordcount     '总记录数
	If page>total then
	    page=total
	Else
	    rs.absolutepage = page
	End If
	response.write"<div class='cm_all'>共<strong style=""font-size:18px;"";>"&p&"</strong>位网友参与评论</div><div class='cm_page'>"&getPageInfo(total,Page,data_id)&"</div>"
	bgcolorArr=Array("#D66103","#512DBD","#780E1A","#C5A200","#DA4912","#530752","#C5A200","#512DBD","#D66103","#530752")
	Do while not rs.eof
	i=i+1
	cm_username=rs("cm_username")
	cm_content=server.htmlencode(rs("cm_content"))
	cm_date=rs("cm_date")
	cm_pic=rs("cm_pic")
	If cm_pic="nobody" or cm_pic="0"  then
     cm_t=Config(0)&"images/faces/nobody.gif"
    Elseif Instr(cm_pic,"http://")>0 Then
     cm_t=cm_pic
	Else
	 cm_t=Config(0)&"images/faces/"&cm_pic&".gif"
    End if	
%> 
<div class="cmtcontent">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td width="4%" rowspan="2" valign="top"><div class="cpic"><img  src="<%=cm_t%>" border="0" width="40" height="40"/></div></td>
    <td width="49%" class="cnamebg" align="left"><span class="cname"><%=Trim(cm_username)%> 发表于 <%=cm_date%></span></td>
    <td width="47%" class="cnamebg"><span style="float:right; padding-right:5px;">第<%=p-(page-1)*Psize-(i-1)%>楼</span></td>
  </tr>
  <tr>
    <td height="30" colspan="2"><div class="ctext"><%=cm_content%></div></td>
  </tr>
</table>
</div>
<%
    If i>=Psize Then Exit Do 
    rs.movenext
    Loop 
    rs.close
    Set rs=Nothing
    Response.write"<div class='c_page'>"&getPageInfo(total,Page,data_id)&"</div>"
End If 
%>
<!--调用评论结束-->
<a name="post"></a>
<table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td colspan="2"><textarea name="cm_content" wrap="virtual" onkeydown="ctlent()" id="cm_content" class="cmtextarea" rows=6 onchange="textCounter(this,300)" onkeyup="textCounter(this,300)" ></textarea></td></tr><tr class="cptop"><td>您还可以输入<input name="remLen" id="remLen" value="300" readonly="readonly" type="text" size=3 maxlength=3 style="width:25px;padding-bottom:0px;border:0;color:#1A85DE; padding-top:2px;">个字 <input type="hidden" id="vertifyinput"/><input type="hidden" id="data_id" value="<%=data_id%>"><input type="hidden" id="maxu" value="10"><input type="hidden" id="maxc" value="300"> 验证码：<input onfocus="GetCodeFile();this.onfocus=null;" name="cm_code" type="text" class="code" id="cm_code" size="8" maxlength="4"/><span id="getcode"></span></td><td width="14%" align="right"><input name="post" type="button" id="post_btn" value=" 发表评论 " onclick="Vertify_Comment_Time();" style="font-weight:bold; font-size:1.1em; "/></td></tr></table>
<div>
<div id="msg" style="margin-top:10px; border:0px;"></div>
</div>
<div style="text-align:left"></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 UserName(uname,uid)
   if uname="" or uid<0  then
     UserName="网友"
   Else
     UserName=uname
   End if	 	 
End Function

Function UserPic(uname,uid,upic)
   if uname=""  then
     UserPic="nobody"
   Else
     UserPic=upic
   End if	 	 
End Function
Call CloseConn()
%>
<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>