<!--#include file="user_top.asp"-->
<!--#include file="inc/class_blog.asp"-->
<%
Dim action
action = Trim(request("action"))
%>
</head>
<body scroll="no" style="overflow:auto!important;overflow:hidden;background:#fff;">
<%
Dim sIp, sGuide
Dim rs, sql,mainid
Dim id, cmd, Keyword, sField

Keyword = Trim(request("keyword"))
If Keyword <> "" Then
    Keyword = oblog.filt_badstr(Keyword)
End If
sField = Trim(request("Field"))
cmd = Trim(request("cmd"))

id = Trim(request("id"))
mainid = Int(request("mainid"))
sIp = CheckIP(request("IP"))
If cmd = "" Then
    cmd = 0
Else
    cmd = Int(cmd)
End If
G_P_FileName = "user_comments.asp?cmd=" & cmd
If Keyword <> "" Then
    G_P_FileName="user_comments.asp?cmd=10&keyword="&Keyword&"&Field="&sField
End If
G_P_FileName =G_P_FileName & "&page="
If request("page") <> "" Then G_P_This = Int(request("page")) Else G_P_This = 1
If sIp <> "" Then G_P_FileName = "user_comments.asp"

If action = "modify" Then
    Call modify
ElseIf action = "savemodify" Then
    Call Savemodify
ElseIf action = "del" Then
    Call delcomment
ElseIf action = "passcomment" Then
	Call passcomment
Else
    Call main
End If
%>

</body>
</html>
<script language=javascript>

function VerifySubmit()
{
    topic = del_space(document.oblogform.topic.value);
     if (topic.length == 0)
     {
        alert("您忘了填写题目!");
    return false;
     }

    submits();
    if (document.oblogform.edit.value == "")
     {
        alert("请输入内容!");
    return false;
     }
    return true;
}
</script>
<%

Sub main()
    server.scriptTimeOut = 999999999
    Dim  ssql,i,lPage,lAll,lPages,iPage
    ssql = "userid,mainid,commenttopic,addtime,commentid,comment_user,addip,comment,iState"
    sGuide = ""
    Select Case cmd
        Case 0
            sql="select "&ssql&" from [oblog_comment] where userid="&oblog.l_uid&" order by commentid desc"
            sGuide = sGuide & "所有评论"
        Case 1
            sql="select "&ssql&" from [oblog_comment] where userid="&oblog.l_uid&" order by commentid desc"
            sGuide = sGuide & "我文章里的评论"
        Case 2
            sql="select "&ssql&" from [oblog_comment] where userid="&oblog.l_uid&" and iState=1 order by commentid desc"
            sGuide = sGuide & "已审核的的评论"
        Case 3
            sql="select "&ssql&" from [oblog_comment] where userid="&oblog.l_uid&" and iState=0 order by commentid desc"
            sGuide = sGuide & "未审核的的评论"
        Case 10
            If Keyword = "" Then
                oblog.adderrstr ("错误：关键字不能为空！")
                oblog.showusererr
                Exit Sub
            Else
                Select Case sField
                Case "id"
                    sql="select "&ssql&" from [oblog_comment] where comment_user like '%" & Keyword&" %' and userid="&oblog.l_uid&" order by commentid desc"
                    sGuide = sGuide & "作者名称含有<font color=red> " & Keyword & " </font>的评论"
                Case "topic"
                    sql="select "&ssql&" from [oblog_comment] where commenttopic like '%" & Keyword & "%' and userid="&oblog.l_uid&" order by commentid desc"
                    sGuide = sGuide & "标题中含有“ <font color=red>" & Keyword & "</font> ”的评论"
                Case "ip"
                    sql="select "&ssql&" from [oblog_comment] where addip='" & Keyword&"' and userid="&oblog.l_uid&" order by commentid desc"
                    sGuide = sGuide & "作者ip含有<font color=red> " & Keyword & " </font>的评论"
                Case "content"
                    sql="select "&ssql&" from [oblog_comment] where comment like '%" & Keyword&"%'  and userid="&oblog.l_uid&" order by commentid desc"
                    sGuide = sGuide & "评论内容中包含<font color=red> " & Keyword & " </font>的评论"
                End Select
            End If
        Case Else
    End Select
    Set rs = server.CreateObject("Adodb.RecordSet")
    rs.Open sql, conn, 1, 3
    lAll=INT(rs.recordcount)
    If lAll=0 Then    	
    	rs.Close
    	Set rs=Nothing
    	%>
    	<div id="user_page_content">
		   <div id="content_li">
		   	<ul class="content_li_conten">
		   		<li class="t1"></li>
		   		<li class="t3">&nbsp;</li>
		   	</ul>
		   	<ul class="content_li_conten">
		   		<li class="t1"></li>
		   		<li class="t3"><%=sGuide & " 没有相关纪录" %></li></ul>
		  	</div>
		  </div>
    	<%
    	Exit Sub
    End If
    i=0
    iPage=12
	'分页
	If Request("page") = "" Or Request("page") ="0" then
		lPage = 1
	Else
		lPage = Int(Request("page"))
	End If
	
	'设置缓存大小 = 每页需显示的记录数目
	rs.CacheSize = iPage
	rs.PageSize = iPage
	rs.movefirst		
	lPages = rs.PageCount
	If lPage>lPages Then lPage=lPages
	rs.AbsolutePage = lPage
	i=0
	%>
	<ul id="user_page_top">
		<li id="p7"><a href="#" onclick="chk_idAll(myform,1)">全部选择</a></li>
		<li id="p8"><a href="#" onclick="chk_idAll(myform,0)">全部取消</a></li>
		<li id="p7"><a href="#" onclick="if (chk_idBatch(myform,'通过审核选中的评论吗?')==true) {document.myform.action.value='passcomment';document.myform.iState.value='1'; document.myform.submit();}">通过审核</a></li>
		<li id="p8"><a href="#" onclick="if (chk_idBatch(myform,'取消审核选中的评论吗?')==true) {document.myform.action.value='passcomment';document.myform.iState.value='0'; document.myform.submit();}">取消审核</a></li>
		<li id="p4"><a href="#" onclick="if (chk_idBatch(myform,'删除选中的评论吗?')==true) {document.myform.action.value='del'; document.myform.submit();}">删除评论</a></li>
	</ul>
	<div id="showpage">
	  <%=MakeMiniPageBar(lAll,iPage,lPage,G_P_FileName)%>
	</div>
<style type="text/css">
<!--
	.content_li_top .t2 {width:88px;padding:0 0 0 10px;}
	.content_li_top .t3 {width:38%;text-align:left}
	.content_li_top .t4 {width:107px; text-align:left;padding-left:14px;}
	.content_li_top .t5 {width:100px;text-align:left;margin:-2px 0 0 0;}
	.content_li_top .t6 {width:100px;text-align:left}
	#content_li .content_li_conten .t2 {width:85px;margin:-2px 0 0 0;color:#f60;text-align:left}
	#content_li .content_li_conten .t3 {width:38%;line-height:1.5;margin:-2px 0 0 0;text-align:left;overflow:hidden;}
	#content_li .content_li_conten .t4 {width:130px;color:#888;text-align:center;font-size:10px;}
	#content_li .content_li_conten .t5 {width:120px;text-align:left;}
	#content_li .content_li_conten .t6 a {color:#069;text-align:left}
	#content_li .content_li_conten .t6 a:hover {color:#06c;text-align:left}
	#content_li .content_li_conten .t6 {width:100px;text-align:left;font-size:10px;}
-->
</style>
	<div id="user_page_content">
		<ul class="content_li_top">
			<li class="t1">选中</li>
			<li class="t2">作者</li>
			<li class="t3">评论内容</li>
			<li class="t4">发表时间</li>
			<li class="t5">评论者IP</li>
			<li class="t6">操作</li>
			
		</ul>
   		<div id="content_li">
			<form name="myform" method="Post" action="user_comments.asp" onSubmit="return confirm('确定要执行选定的操作吗？');">
          <%
          Do while not rs.EOF
          	i = i + 1%>
		   <ul class="content_li_conten" id="u<%=rs("commentid")%>"  onclick="chk_iddiv('<%=rs("commentid")%>')">
			<li class="t1" title="点击选中"><input name='id' type='checkbox' id="c<%=rs("commentid")%>" value='<%=rs("commentid")%>' onclick="chk_id('<%=rs("commentid")%>')" /></li>
			<li class="t2" title="作者：<%=rs("comment_user")%>"><%=rs("comment_user")%></li>
			<li class="t3" ><a href=go.asp?logid=<%=rs("mainid")%>#<%=rs("commentid")%> target="_blank"
			title="
				cssbody=[dvbdy1] cssheader=[dvhdr1] header=[<%=oblog.filt_html(rs("commenttopic"))%>] body=[<%=oblog.filt_html(FilterUbb(rs("comment")))%>]"
			><%If rs("iState") = 0 Then %><font color=black>[待审]</font><%End if%><%=oblog.filt_html(rs("commenttopic"))%></a></li>
			<li class="t4"><%=rs("addtime")%></li>
			<li class="t6"><%=rs("addip")%></li>
			<li class="t5"><a href="user_comments.asp?action=modify&id=<%=rs("commentid")%>&re=true">回复</a>&nbsp; <a href="user_comments.asp?action=modify&id=<%=rs("commentid")%>">修改</a>&nbsp;<a href="user_comments.asp?action=del&id=<%=rs("commentid")%>" onClick="return confirm('确定要删除此评论吗？');">删除</a></li>
			
    	</ul>
<%
    	If i>iPage Then Exit Do
	    rs.movenext
	Loop
    rs.Close
    Set rs = Nothing
    %>
<INPUT TYPE="hidden" name="iState">
<input type="hidden" name="action" value="">
     </form>
    </div>
	</div>
    <%
End Sub


%>

<div id="user_page_search">
    <form action="user_comments.asp" name=form1 method="get">
快速查找评论:
    <select size=1 name="cmd" onChange="javascript:submit()">
          <option value="0">列出所有评论</option>
		  <option value="2">已审核的评论</option>
		  <option value="3">待审核的评论</option>
          <option value="10" selected>请选择查询类型</option>

        </select>
搜索:
         <select name="Field" id="Field">
        <option value="id">作者</option>
        <option value="ip">作者ip</option>
        <option value="topic" selected>评论标题</option>
      </select>
      <input name="Keyword" type="text" id="Keyword" size="20" maxlength="30">
      <input type="submit"  value="搜索" />
    </form>
</div>
<%


Sub modify()
    Dim id
    Dim rsblog, sql
    Dim restr
    id = Trim(request("id"))
    If id = "" Then
        oblog.adderrstr ("错误：参数不足！")
        oblog.showusererr
        Exit Sub
    Else
        id = Int(id)
    End If
    Set rsblog = server.CreateObject("Adodb.RecordSet")
    sql="select * from [oblog_comment] where commentid=" & id&" and userid="&oblog.l_uid
    rsblog.Open sql, conn, 1, 1
    If rsblog.EOF Then
        rsblog.Close
        Set rsblog = Nothing
        oblog.adderrstr ("错误：无权限，只有blog主人才能操作！")
        oblog.showusererr
        Exit Sub
    End If
%>
<SCRIPT language=javascript>
var ubbimg='';
</SCRIPT>
<form action="user_comments.asp?action=savemodify" method="post" name="oblogform" onSubmit="">
	<table  class="dTab12_body" align="center" border="0" cellpadding="0" cellspacing="1">
	  <tr>
	  	<%if Request("re") <> "true" then%>
		<td class="dTab12_body_td" style="text-align:left;">
<span class="user_post_inputtxt">评论标题:</span><input style="height:16px;padding:2px 0 0 0;margin:0px 0 -3px 0;" name="topic" type=text class="cont" id="topic" value="<%=rsblog("commenttopic")%>" size="53" maxlength="30" /><br /><br />
		<%else%>
		<td class="dTab12_body_td" style="text-align:left;">
<div class="messagetopic"><%=rsblog("commenttopic")%></div>
<div class="message"><%=oblog.ubb_comment(rsblog("comment"))%></div><br /><br />
<div style="color:#CCC;margin:-10px 0 0 0px;">回复此评论:</div>
		<%end if%>
<style type='text/css'>@import url('editor/ubb.css');</style>
<Script src="editor/ubb.js"></Script>
<div id="oblog_ubb">
	<div class="oblog_ubbtoolbar" style="width:98%;">
	<a href="javascript:InsertText(objActive,ReplaceText(objActive,'[B]','[/B]'),true);void(0)"><img src="images/bold.gif" alt="粗体"  border="0" align="absmiddle"></a>
	<a href="javascript:InsertText(objActive,ReplaceText(objActive,'[I]','[/I]'),true);void(0)"><img src="images/italic.gif" alt="斜体" border="0" align="absmiddle" ></a>
	<a href="javascript:InsertText(objActive,ReplaceText(objActive,'[U]','[/U]'),true);void(0)"><img src="images/underline.gif" alt="下划线" border="0" align="absmiddle"></a>
	<a href="javascript:InsertText(objActive,ReplaceText(objActive,'[QUOTE]','[/QUOTE]'),true);void(0)"><img src="images/quote.gif" alt="插入引用" border="0" align="absmiddle"></a>
	<a href="javascript:UBB_smiley();void(0)"><img src="images/smiley.gif" alt="插入表情" border="0" align="absmiddle" id="A_smiley"></a>
	</div>
	<div id="oblog_ubbemot">
	</div>
	  <textarea name="edit" style="border:0;width:100%x;"cols="92" rows="6" id="oblog_edittext" class="oblog_ubbtext" ><%if rsblog("comment")<>"" and Request("re") <> "true" then response.Write Server.HtmlEncode(rsblog("comment"))%></textarea>
</div>
<ul id="user_post_input">
<input type="hidden" name="id" value="<%=rsblog("commentid")%>" /><input type="hidden" name="re" value="<%=request("re")%>" /><input type="submit" name="Submit2" value=" 提交 " />
</ul>
</td>
	 </tr>
  </table>
</form>
<%
    rsblog.Close
    Set rsblog = Nothing
End Sub

Sub Savemodify()
    Dim id, rsblogchk, blog, logid, uid
    id = Int(Trim(request("id")))
    sql="select * from oblog_comment where commentid="&id&" and userid="&oblog.l_uid
    Set rs = server.CreateObject("adodb.recordset")
    rs.Open sql, conn, 1, 3
    uid = rs("userid")
    logid = rs("mainid")
   if request("re")="true" then
		rs("comment") = rs("comment")&"[quote][b]以下为blog主人的回复：[/b]"&vbcrlf&oblog.filt_badword(Request("edit"))&"[/quote]"
	else
		rs("comment") = oblog.filt_badword(Request("edit"))
		rs("commenttopic") = oblog.InterceptStr(oblog.filt_badword(Trim(Request("topic"))), 250)
	end if
    rs.Update
    rs.Close
    Set rs = Nothing
    Set blog = New class_blog
    blog.userid = uid
    blog.Update_log logid, 0
    Set blog = Nothing
    oblog.showok "修改评论成功！", ""
End Sub


Sub delcomment()
    Dim blog, rstComment
    If id = "" Then
        oblog.adderrstr ("错误：请指定要删除的评论！")
        oblog.showusererr
        Exit Sub
    End If
    If InStr(id, ",") > 0 Then
        id = FilterIDs(id)
        Dim n, i
        n = Split(id, ",")
        For i = 0 To UBound(n)
            delonecomment (n(i))
        Next
    Else
        delonecomment (id)
    End If
    oblog.showok "删除评论成功!", ""
End Sub

Sub delonecomment(id)
    Dim blog, rstComment, CommentNum
    id = Int(id)
    Dim uid, mainid
    sql = "select userid,mainid from [oblog_comment] where commentid=" & Int(id) & " and userid=" & oblog.l_uId
    Set rs = server.CreateObject("adodb.recordset")
    rs.Open sql, conn, 1, 3
    If Not rs.EOF Then
        uid = rs(0)
        mainid = rs(1)
        rs.Delete
        rs.Close
        Set blog = New class_blog
        blog.userid = uid
        '重新计算评论数目
        Set rstComment = server.CreateObject("adodb.recordset")
        rstComment.Open "Select Count(commentid) From [oblog_comment] Where mainid=" & Int(mainid), conn, 1, 1
        If rstComment.EOF Then
            CommentNum = 0
        Else
            If IsNull(rstComment(0)) Or Not IsNumeric(rstComment(0)) Then
                CommentNum = 0
            Else
                CommentNum = rstComment(0)
            End If
        End If
        Set rstComment = Nothing
        oblog.Execute ("update [oblog_log] set commentnum=" & CommentNum & ",scores=scores-" & oblog.CacheScores(6) & " where logid=" & mainid)
        blog.Update_log mainid, 0
        oblog.Execute ("update [oblog_user] set comment_count=comment_count-1,scores=scores-" &  oblog.CacheScores(6) & " where userid=" & uid)
        Set blog = Nothing
    Else
        rs.Close
        Set rs = Nothing
        oblog.adderrstr ("错误：无删除权限！")
        oblog.showusererr
        Exit Sub
    End If
End Sub

Function FilterUbb(byval strHTML)
	Dim objRegExp, strOutput
	Set objRegExp = New Regexp	  
	strOutput=strHTML	
	objRegExp.IgnoreCase = True
	objRegExp.Global = True
	objRegExp.Pattern="(\[EMOT\])(.[^\[]*)(\[\/EMOT\])"
	strOutput = objRegExp.Replace(strOutput, "")	
	objRegExp.Pattern =  "\[[^\]]*\]"
	strOutput = objRegExp.Replace(strOutput, " ")	
	FilterUbb = strOutput   
	Set objRegExp = Nothing
End Function

Sub passcomment()
	Dim iState
	iState=request("iState")
    Dim blog, rstComment
    If id = "" Then
        oblog.adderrstr ("错误：请指定要审核的评论！")
        oblog.showusererr
        Exit Sub
    End If
    If InStr(id, ",") > 0 Then
        id = FilterIDs(id)
        Dim n, i
        n = Split(id, ",")
        For i = 0 To UBound(n)
            passonecomment n(i),iState
        Next
    Else
        passonecomment id,iState
    End If
    oblog.showok "审核评论成功!", ""
End Sub

Sub passonecomment(id,iState)
    Dim blog
    id = Int(id)
	iState=CLng(iState)
    Dim uid, mainid
	Dim sScore
	If iState = 1 Then
		sScore=oblog.CacheScores(6)
	Else 
		sScore=-1*Abs(oblog.CacheScores(6))
	End if
    sql = "select userid,mainid,iState from [oblog_comment] where commentid=" & Int(id) & " and userid=" & oblog.l_uId
    Set rs = server.CreateObject("adodb.recordset")
    rs.Open sql, conn, 1, 3
    If Not rs.EOF Then
        uid = rs(0)
        mainid = rs(1)
		If rs("iState")<>iState Then
			If oblog.CacheConfig(50) = 0 Then 
				oblog.GiveScore "",sScore,""
			End If
		Else 
			Exit Sub
		End if
		rs("iState")=iState
        rs.Update
        rs.Close
        Set blog = New class_blog
        blog.userid = uid
		blog.Update_log mainid, 0
        Set blog = Nothing
    Else
        rs.Close
        Set rs = Nothing
        oblog.adderrstr ("错误：无操作权限！")
        oblog.showusererr
        Exit Sub
    End If
End Sub
%>