<!--#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
Dim rs, sql, blog,sGuide
Dim id, usersearch, Keyword, sField
Keyword = Trim(Request("keyword"))
If Keyword <> "" Then
    Keyword = oblog.filt_badstr(Keyword)
End If
sIP=CheckIP(Request("IP"))
sField = Trim(Request("Field"))
usersearch = Trim(Request("usersearch"))
id = Trim(Request("id"))
If usersearch = "" Then
    usersearch = 0
Else
    usersearch = Int(usersearch)
End If
G_P_FileName = "user_messages.asp?usersearch=" & usersearch

If Keyword <> "" Then
    G_P_FileName="user_messages.asp?usersearch=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_messages.asp"
Select Case action
    Case "modify"
        Call modify
    Case "savemodify"
        Call savemodify
    Case "del"
        Call delmessage
	Case "passmessage"
		Call passmessage
    Case Else
        Call ClearIpMessages(sIp)
        Call main
End Select
Set rs = Nothing
Set blog = Nothing
%>


<div id="user_page_search">
  <form name="form1" action="user_messages.asp" method="get">
快速查找留言:
        <select size=1 name="usersearch" 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>
</body>
</html>

<%
Sub main()
    server.ScriptTimeOut = 999999999
    Dim  ssql,lPage,lAll,lPages,iPage,i
    ssql = "userid,messagetopic,addtime,messageid,message_user,addip,message,iState"
    G_P_Guide = ""
    Select Case usersearch
        Case 0
            sql="select "&ssql&" from [oblog_message] where userid="&oblog.l_uid&" order by messageid desc"
            G_P_Guide = G_P_Guide & "所有留言"
        Case 1
            sql="select "&ssql&" from [oblog_message] where userid="&oblog.l_uid&" order by messageid desc"
            G_P_Guide = G_P_Guide & "我的留言"
        Case 2
            sql="select "&ssql&" from [oblog_message] where userid="&oblog.l_uid&" and iState=1 order by messageid desc"
            G_P_Guide = G_P_Guide & "已审核的留言"
        Case 3
            sql="select "&ssql&" from [oblog_message] where userid="&oblog.l_uid&" and iState=0 order by messageid desc"
            G_P_Guide = G_P_Guide & "待审核的留言"
        Case 10
            If Keyword = "" Then
                oblog.adderrstr ("错误：关键字不能为空！")
                oblog.showusererr
                Exit Sub
            Else
                Select Case sField
                Case "id"
                    sql="select "&ssql&" from [oblog_message] where message_user like '%" & Keyword&"%' and userid="&oblog.l_uid&" order by messageid desc"
                    G_P_Guide = G_P_Guide & "作者名称中还有含有<font color=red> " & Keyword & " </font>的留言"
                Case "topic"
                    sql="select "&ssql&" from [oblog_message] where messagetopic like '%" & Keyword & "%' and userid="&oblog.l_uid&" order by messageid desc"
                    G_P_Guide = G_P_Guide & "标题中含有“ <font color=red>" & Keyword & "</font> ”的留言"
                Case "ip"
                    sql="select "&ssql&" from [oblog_message] where addip='" & Keyword&"' and userid="&oblog.l_uid&" order by messageid desc"
                    G_P_Guide = G_P_Guide & "作者ip为<font color=red> " & Keyword & " </font>的留言"
                Case "content"
                    sql="select "&ssql&" from [oblog_message] where message like '%" & Keyword&"%' and userid="&oblog.l_uid&" order by messageid desc"
                    G_P_Guide = G_P_Guide & "留言内容中包含<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
    %>
<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>
	<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='passmessage';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='passmessage';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>
	<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_messages.asp" onSubmit="return confirm('确定要执行选定的操作吗？');">
          <%
          Do while not rs.EOF
          	i = i + 1%>
		   <ul class="content_li_conten" id="u<%=rs("messageid")%>" onclick="chk_iddiv('<%=rs("messageid")%>')">
		   	<li class="t1" title="点击选中"><input name='id' type='checkbox' id="c<%=rs("messageid")%>" value='<%=rs("messageid")%>' onclick="chk_iddiv('<%=rs("messageid")%>')" /></li>
			<li class="t2" title="作者：<%=oblog.filt_html(rs("message_user"))%>"><%=oblog.filt_html(rs("message_user"))%></li>
		    <li class="t3"><a href="go.asp?messageid=<%=rs("messageid")%>" target="_blank" title="
				cssbody=[dvbdy1] cssheader=[dvhdr1] header=[<%=oblog.filt_html(rs("messagetopic"))%>] body=[<%=oblog.filt_html(FilterUbb(rs("message")))%>]"><%If rs("iState") = 0 Then %><font color=black>[待审]</font><%End if%><%=oblog.filt_html(rs("messagetopic"))%></a></li>
			<li class="t4"><%=rs("addtime")%></li>
			<li class="t6"><%=rs("addip")%></li>
		    <li class="t5">
		  	<%
        response.write "<a href='user_messages.asp?action=modify&id=" & rs("messageid") & "&re=true'>回复</a>&nbsp;"
        response.write "<a href='user_messages.asp?action=modify&id=" & rs("messageid") & "'>修改</a>&nbsp;"
        response.write "<a href='user_messages.asp?action=del&id=" & rs("messageid") & "' onClick='return confirm(""确定要删除此留言吗？"");'>删除</a>"
			%>
		   </li>
			
    	</ul>
    	<%
    	If i>iPage Then Exit Do
    	rs.Movenext
    Loop
    rs.Close
    Set rs = Nothing
%>
    </ul>
<INPUT TYPE="hidden" name="iState">
<input type="hidden" name="action" value="">
    </form>
</div>
<%
End Sub

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_message] where messageid=" & id&" and userid="&oblog.l_uid
    rsblog.open sql, conn, 1, 1
    If rsblog.EOF Then
        rsblog.Close
        Set rsblog = Nothing
        oblog.adderrstr ("错误：找不到指定的留言！")
        oblog.showusererr
        Exit Sub
    End If
%>
<SCRIPT language=javascript>
var ubbimg='';
</SCRIPT>
<form action="user_messages.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("messagetopic")%>" size="53" maxlength="30" /><br /><br />
		<%else%>
		<td class="dTab12_body_td" style="text-align:left;">
<div class="messagetopic"><%=rsblog("messagetopic")%></div>
<div class="message"><%=oblog.ubb_comment(rsblog("message"))%></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("message")<>"" and Request("re") <> "true" then response.Write Server.HtmlEncode(rsblog("message"))%></textarea>
</div>
<ul id="user_post_input">
<input type="hidden" name="id" value="<%=rsblog("messageid")%>" /><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, blog, userid
    id = Int(Trim(Request("id")))
    sql="select * from oblog_message where messageid="&id&" and userid="&oblog.l_uid
    Set rs = server.CreateObject("adodb.recordset")
    rs.open sql, conn, 1, 3
    If Not rs.EOF Then
        userid = rs("userid")
        if request("re")="true" then
			rs("message") = rs("message")&"[quote][b]以下为blog主人的回复：[/b]"&vbcrlf&oblog.filt_badword(Request("edit"))&"[/quote]"
		else
			rs("message") = oblog.filt_badword(Request("edit"))
			rs("messagetopic") = oblog.InterceptStr(oblog.filt_badword(Trim(Request("topic"))), 250)
		end if
        rs.Update
        rs.Close
        Set blog = New class_blog
        blog.userid = userid
        blog.Update_message 0
        Set rs = Nothing
        Set blog = Nothing
    End If
    oblog.showok "修改留言成功！", "user_messages.asp"
End Sub

Sub delmessage()
    If id = "" Then
        oblog.adderrstr ("错误：请指定要删除的留言！")
        oblog.showusererr
        Exit Sub
    End If
    If InStr(id, ",") > 0 Then
        Dim n, i
        id = FilterIDs(id)
        n = Split(id, ",")
        For i = 0 To UBound(n)
            delonemessage (n(i))
        Next
    Else
        delonemessage (id)
    End If
    Set rs = Nothing
    oblog.showok "删除留言成功!", ""
End Sub

Sub delonemessage(id)
    id = Int(id)
    Dim userid, messagefile
    'Response.Write "idgfgfgfgf" & id
  	'Response.End
    sql = "select * from [oblog_message] where messageid=" & Int(id) & " and userid=" & oblog.l_uId
    Set rs = server.CreateObject("adodb.recordset")
    rs.open sql, conn, 1, 3
    If Not rs.EOF Then
        userid = rs("userid")
        messagefile = rs("messagefile")
        rs.Delete
        rs.Close
        Set blog = New class_blog
        blog.userid = userid
        'blog.update_message 0,0,0,""
        blog.Update_message 0
        blog.Update_newmessage userid
        oblog.execute("update [oblog_user] set message_count=message_count-1,scores=scores-" & oblog.CacheScores(5)&" where userid="&userid)

        Set blog = Nothing
    Else
        rs.Close
        Set rs = Nothing
        oblog.adderrstr ("错误：无删除权限！")
        oblog.showusererr
        Exit Sub
    End If
End Sub

Sub ClearIpMessages(sIp)
    If sIp <> "" Then oblog.Execute ("Delete From oblog_message Where addIp='" & sIp & "' and userid=" & oblog.l_uId)
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 passmessage()
	Dim iState
	iState=request("iState")
    If id = "" Then
        oblog.adderrstr ("错误：请指定要审核的留言！")
        oblog.showusererr
        Exit Sub
    End If
    If InStr(id, ",") > 0 Then
        Dim n, i
        id = FilterIDs(id)
        n = Split(id, ",")
        For i = 0 To UBound(n)
            passonemessage n(i),iState
        Next
    Else
        passonemessage id,iState
    End If
    Set rs = Nothing
    oblog.showok "审核留言成功!", ""
End Sub

Sub passonemessage(id,iState)
    id = Int(id)
	iState= CLng(iState)
    Dim userid
	Dim sScore
	If iState = 1 Then
		sScore=oblog.CacheScores(5)
	Else 
		sScore=-1*Abs(oblog.CacheScores(5))
	End if
    sql = "select * from [oblog_message] where messageid=" & Int(id) & " and userid=" & oblog.l_uId
    Set rs = server.CreateObject("adodb.recordset")
    rs.open sql, conn, 1, 3
    If Not rs.EOF Then
        userid = rs("userid")
		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 = userid
        'blog.update_message 0,0,0,""
        blog.Update_message 0
        blog.Update_newmessage userid
        Set blog = Nothing
    Else
        rs.Close
        Set rs = Nothing
        oblog.adderrstr ("错误：无操作权限！")
        oblog.showusererr
        Exit Sub
    End If
End Sub
%>