<!--#include file=../conn.asp-->
<!-- #include file="inc/const.asp" -->
<%Head()
	dim admin_flag
	admin_flag=",18,"
	if not master or instr(","&session("flag")&",",admin_flag)=0 then
		Errmsg=ErrMsg + "<BR><li>本页面为管理员专用，请<a href=../"&LoginUrl&" target=_top>登录</a>后进入。<br><li>您没有管理本页面的权限。"
		Call Ms_error()
	End If
		Main(1)
		Select Case Request("action")
		Case "search"''读取数据列表
		call diary()
		Case "view"
		call view()
		Case "Toctrl"''控制操作
		call Toctrl()
		Case "list_d"''评论管理
		call list_d()
		Case "disr_s"''删除管理
		call disr_s()
		Case "view_d"''查看评论
		call view_d()
		Case Else
		call SIndex()''搜索表单
		End Select
		Main(0)
		Footer()

sub main(Str)
if Str=1 then%>
<table width="95%" border="0" cellspacing="1" cellpadding="3"  align=center class="tableBorder">
  <tr> 
    <th height="23" colspan="8" class="tableHeaderText">日记管理中心</th>
  </tr>
  <tr> 
    <td width="16%" height="24" align="right" class="forumrow">说明：</td>
    <td width="84%" height="24" class="forumrow" colspan=7>
	<li>日记审核、删除管理，此操作不可逆；</li>
	<li>点击相关日记进入查看；</li>
	<li>点击日记之后数字进入评论管理；</li>
	<li>日记操作必须选择设置/取消，再选择对象；</li>
	</td>
  </tr>
  <tr> 
    <td height="25" colspan=8 class="forumrow">快捷方式：<a href="diary.asp">管理首页</a> 
      | <a href=?action=search&t=1>所有日记</a> | <a href=?action=search&t=2>未 
      审 核</a> | <a href=?action=search&t=3>Top推荐</a> | <a href=?action=search&t=4>Top固顶</a> | <a href=?action=search&t=5>Top热门</a> | <a href=?action=search&t=6>Top佳作</a> | <a href=?action=search&t=9>人气榜</a></td>
  </tr>
<%
	Else
%>
</table>
<p></p>
<%end if
end sub

'管理首页，搜索项
Sub SIndex()%>
<form action="?action=search" method=post>
<input type=hidden name="T" value="8"> 
<tr>
<th align=left colspan=8 height=23>高级查询</th>
</tr>
<tr>
<td width=20% class=forumrow>注意事项</td>
<td width=80% class=forumrow colspan=7>在记录很多的情况下搜索条件越多查询越慢，请尽量减少查询条件</td>
</tr>
<tr>
<td width=20% class=forumrow>会员姓名</td>
<td width=80% class=forumrow colspan=7><input name="username" type="text" size="20">&nbsp;<input type=checkbox name="like" value="1" checked>
      完整匹配</td>
</tr>
<tr>
<td width=20% class=forumrow>日记标题</td>
<td width=80% class=forumrow colspan=7><input name="Title" type="text" size="30">
</td>
</tr>
<tr>
<td width=20% class=forumrow>所属类别</td>
<td width=80% class=forumrow colspan=7>
<select name="Typeid">
<option value=""></option>
     <option value="1">以文会友</option>
     <option value="2">生活点滴</option>
     <option value="3">情感话题</option>
     <option value="4">人生感悟</option>
	<option value="5">胡思乱想</option>
	<option value="6">此刻心情</option>
    </select></td>
</tr>
<tr>
<td width=100% class=forumrow align=center colspan=8><input name="submit" type=submit value="   搜  索   "></td>
</tr>
</form>
<%
End Sub

sub diary()''搜索列表
strFileName="diary.asp?action="&Request("action") & "&t="&request("t")&"&username="&request("username")&"&Typeid="&request("typeid")&"&like="&request("like")&"&title="&request("title")&""
call tumppages()
dim sqlt
sqlt = " Did,Username,Title,Ispublic,Hits,Disdiary,Typeid,Checked,Datetime,Addtime "
%>
<tr>
<th colspan=8 align=left height=23>搜索结果</th>
</tr>
<FORM METHOD=POST ACTION="?action=Toctrl">
<tr align=center height=23>
<td class=forumRowHighlight width="16%"><B>用户名</B></td>
<td class=forumRowHighlight width="32%"><B>日记标题</B></td>
<td class=forumRowHighlight width="10%"><B>评论与否</B></td>
<td class=forumRowHighlight width="10%"><B>日记日期</B></td>
<td class=forumRowHighlight width="7%"><B>状态</B></td>
<td class=forumRowHighlight width="10%"><B>所属类别</B></td>
<td class=forumRowHighlight width="8%"><B>人气</B></td>
<td class=forumRowHighlight><B>操作</B></td>
</tr>
<%dim sqlstr
set rs=server.createobject("adodb.recordset")
Select Case Request("t")
	Case 1
		Sql = "SELECT " & sqlt & " from Ms_diary ORDER BY DID DESC"
	Case 2
		Sql = "SELECT " & sqlt & " from Ms_diary where Checked=0 ORDER BY DID DESC"
	case 3
		sql="select top 100 " & sqlt & " from Ms_diary  where Istop=1 order by DID desc"
	case 4
		sql="select top 100 " & sqlt & " from Ms_diary  where Istop=2 order by DID desc"
	case 5
		sql="select top 100 " & sqlt & " from Ms_diary  where Ishot=1 order by DID desc"
	case 6
		sql="select top 100 " & sqlt & " from Ms_diary  where Isbest=1 order by DID desc"
	case 7''列出同类日记
		sql="select " & sqlt & " from Ms_diary  where Typeid="&request("typeid")&" order by DID desc"
	case 9''人气排行榜
		sql="select " & sqlt & " from Ms_diary order by hits desc"	
	case 8''搜索提交? 
	sqlstr=""''搜索开始
	if request("username")<>"" then
			if request("like")=1 then
			sqlstr=" username='"&request("username")&"'"
			else
			sqlstr=" username like '%"&request("username")&"%'"
			end if
		end if
	if request("title")<>"" then
			if sqlstr<>"" then
			sqlstr=sqlstr & " and title like '%"&request("title")&"%' "
			else
			sqlstr=" title like '%"&request("title")&"%' "
			end if
	end if
	if request("typeid")<>"" then
			if sqlstr<>"" then
			sqlstr=sqlstr & " and typeid="&request("typeid")&""
			else
			sqlstr=" typeid="&request("typeid")&""
			end if
	end if	
	if sqlstr<>"" then
		sql="select " & sqlt & " from Ms_diary  where "&sqlstr&" order by DID desc"
		else
		Response.Write "<tr><td colspan=8 class=forumrow>搜索条件不能都为空。</td></tr>"
		Response.End
		end if							
	case else
		Response.Write "<tr><td colspan=8 class=forumrow>错误的参数。</td></tr>"
		Response.End
	End Select
rs.Open sql,conn,1,1
if not (rs.eof and rs.bof) then
call rspages()
do while not rs.eof and page_count<Cint(MaxPerPage)%>
<tr>
<td class=forumrow align="center"><a href="admin_user.asp?action=modify&username=<%=rs("username")%>"><%=rs("username")%></a></td>
<td class=forumrow align="left"><a href=?action=view&id=<%=rs(0)%> title="查看日记"><%=rs(2)%></a> <font color=#999999>[<a href=?action=list_d&id=<%=rs(0)%> title="查看评论"><%=rs(5)%></a>]</font>
</td>
<td class=forumrow align=center><%if rs(3)=1 then
response.Write("<font color=red>允许评论</font>")
elseif rs(3)=2 then
response.Write("<font color=#ff9900>不可评论</font>")
else
response.Write("<font color=blue>不公开</font>")
end if%></td>
<td class=forumrow align=center><%=rs(8)%></td>
<td class=forumrow align=center>
<%if rs(7)=1 then
response.write("<font color=red>审核</font>")
else
response.write("<font color=blue>未审</font>")
end if%></td>
<td class=forumrow  align=center><%
Select Case rs(6)
	Case 1
	response.Write("<a href=?action=search&t=7&Typeid=1>以文会友</a>")
	Case 2
	response.Write("<a href=?action=search&t=7&Typeid=2>生活点滴</a>")
	Case 3
	response.Write("<a href=?action=search&t=7&Typeid=3>情感话题</a>")
	Case 4
	response.Write("<a href=?action=search&t=7&Typeid=4>人生感悟</a>")
	Case 5
	response.Write("<a href=?action=search&t=7&Typeid=5>胡思乱想</a>")
	Case 6
	response.Write("<a href=?action=search&t=7&Typeid=6>此刻心情</a>")
End Select%></td>
<td class=forumrow align=center>
<%=rs(4)%></td>
<td class=forumrow align=center><input type="checkbox" name="id" value="<%=rs("Did")%>"></td>
</tr>
<%page_count=page_count+1
  rs.movenext
  loop
  end if
  %>
    <tr align="center"> 
      <td height="24" colspan="8" class=forumrow> <%if totalrec>0 then
		  	call showpage(strFileName)
		  end if%></td>
    </tr>
<tr align="center"> 
      <td height="24" colspan="8" class=forumrow><input type="radio" name="paction" value=1>删除记录
	  <input type="radio" name="paction" value=2>审核操作
	  <select name="Pset">
	  <option value=""></option>
	  <option value=1>审核</option>
	  <option value=0>撤消</option>
	  </select>
	  <input type="radio" name="paction" value=3>删除评论
	  <input type="radio" name="paction" value=4>日记操作
	  <select name="Tsto">
	  <option value=""></option>
	  <option value=1>设置</option>
	  <option value=0>取消</option>
	  </select>－<select name="Tset">
	  <option value=""></option>
	  <option value=1>推荐</option>
	  <option value=2>热点</option>
	  <option value=3>固顶</option>
	  <option value=4>佳作</option>
	  </select>
      全部选定
<input type=checkbox value="on" name="chkall" onclick="CheckAll(this.form)"></td>
    </tr>
	<tr align="center"> 
      <td height="24" colspan="8" class=forumRowHighlight><input type=submit name=submit value="执行操作"  onclick="{if(confirm('确定执行操作吗?')){return true;}return false;}"></td>
    </tr>
</form>
<%end sub

sub list_d()''评论管理
strFileName="diary.asp?action="&Request("action") & "&id="&request("id")&""
call tumppages()
dim sql
sql = " DID,LastPost,Title,Topic,LastTime "%>
<tr>
<th colspan=8 align=left height=23>日记评论管理</th>
</tr>
<FORM METHOD=POST ACTION="?action=disr_s">
<tr align=center height=23>
<td class=forumRowHighlight width="16%"><B>评论者</B></td>
<td class=forumRowHighlight width="50%"><B>标题名称</B></td>
<td class=forumRowHighlight width="8%"><B>表情</B></td>
<td class=forumRowHighlight width="17%"><B>发表时间</B></td>
<td class=forumRowHighlight colspan="3"><B>操作</B></td>
</tr>
<%set rs=server.createobject("adodb.recordset")
Sql = "SELECT " & sql & " from Ms_diaryb where Tid="&request("id")&" ORDER BY dID DESC"
rs.Open sql,conn,1,1
if not (rs.eof and rs.bof) then
call rspages()
do while not rs.eof and page_count<Cint(MaxPerPage)%>
<tr align=center height=23>
<td class=forumrow width="16%"><a href="admin_user.asp?action=modify&username=<%=rs(1)%>"><%=rs(1)%></a></td>
<td class=forumrow width="50%" align="left"><a href=?action=view_d&id=<%=rs(0)%> title="查看内容"><%=rs(2)%></a></td>
<td class=forumrow width="8%"><img src=../<%=rs(3)%> border=0 width=20></td>
<td class=forumrow width="17%"><%=rs(4)%></td>
<td class=forumrow colspan="3"><input type="checkbox" name="id" value="<%=rs(0)%>"></td>
</tr>
<%page_count=page_count+1
  rs.movenext
  loop
  end if
  if totalrec>0 then%>
  <tr align="center"> 
      <td height="24" colspan="8" class=forumrow> <%
		  	call showpage(strFileName)
		  %></td>
    </tr>
<%end if%>
<tr align="center"> 
      <td height="24" colspan="8" class=forumrow align=right><input type="radio" name="faction" value=1>删除评论
	  <input type="radio" name="faction" value=2>清空评论
	   <input type="hidden" name="Tid" value=<%=request("id")%>>
全部选定<input type=checkbox value="on" name="chkall" onclick="CheckAll(this.form)"></td>
    </tr>
	<tr align="center"> 
      <td height="24" colspan="8" class=forumRowHighlight><input type=submit name=submit value="执行操作"  onclick="{if(confirm('确定执行操作吗?')){return true;}return false;}"></td>
    </tr>
</forM>
<%end sub

sub disr_s()''删除操作
dim delid,fixid,splitid
response.write "<tr><th colspan=8 height=23 align=left>执行结果</th></tr>"
	if request("faction")="" then
		response.write "<tr><td colspan=8 class=forumrow>请指定相关参数。</td></tr>"
		founderr=true
	end if
	delid=replace(request.form("id"),"'","")
	delid=replace(delid,";","")
	delid=replace(delid,"--","")
	delid=replace(delid,")","")
	fixid=replace(delid,",","")
	fixid=Trim(replace(fixid," ",""))
	splitid=ubound(split(delid,","))
	if not founderr then
		if request("faction")=1 then''删除操作
				Conn.Execute("delete from Ms_diaryb where Did in ("&delid&")")
				Conn.Execute("update Ms_diary set Disdiary=Disdiary-"&(splitid+1)&" where Did="&request("Tid")&"")''更新记录
				response.write "<tr><td colspan=8 class=forumrow>删除评论成功。</td></tr>"
		elseif request("faction")=2 then''清空操作
		Conn.Execute("delete from Ms_diaryb where TID="&Cint(request("Tid"))&"")
		Conn.Execute("update Ms_diary set Disdiary=0 where Did="&request("Tid")&"")''更新记录
				response.write "<tr><td colspan=8 class=forumrow>清空评论成功。</td></tr>"
		end if
	else
	response.write "<tr><td colspan=8 class=forumrow>错误的参数。</td></tr>"
	end if
end sub

sub Toctrl()''控制操作
dim delid,fixid,Maxnum
response.write "<tr><th colspan=8 height=23 align=left>执行结果</th></tr>"
	if request("paction")="" then
		response.write "<tr><td colspan=8 class=forumrow>请指定相关参数。</td></tr>"
		founderr=true
	end if
	delid=replace(request.form("id"),"'","")
	delid=replace(delid,";","")
	delid=replace(delid,"--","")
	delid=replace(delid,")","")
	fixid=replace(delid,",","")
	fixid=Trim(replace(fixid," ",""))
	if not founderr then
		if request("paction")=1 then''删除操作
		Maxnum=ubound(split(delid,","))
				Conn.Execute("delete from Ms_diary where Did in ("&delid&")")
				conn.execute("Update Ms_setup set Userdiary=Userdiary-"&(Maxnum+1)&" where Cid=1")
				response.write "<tr><td colspan=8 class=forumrow>删除日记记录成功。</td></tr>"
		elseif request("paction")=2 then''审核操作
			Conn.Execute("update Ms_diary set Checked="&Cint(request("Pset"))&" where Did in ("&delid&")")''审核记录
			response.write "<tr><td colspan=8 class=forumrow>审核日记记录成功。</td></tr>"
		elseif request("paction")=3 then''删除评论操作
			Conn.Execute("delete from Ms_diaryb where Did in ("&delid&")")''删除评论记录
			response.write "<tr><td colspan=8 class=forumrow>删除评论记录成功。</td></tr>"
		elseif request("paction")=4 then''日记操作
		if request("Tsto")<>"" then
			if request("Tset")=1 then''推荐
			if request("Tsto")=1 then
			Conn.Execute("update Ms_diary set Istop=1 where Did in ("&delid&")")''日记操作
			else
			Conn.Execute("update Ms_diary set Istop=0 where Did in ("&delid&")")''日记操作
			end if
			response.write "<tr><td colspan=8 class=forumrow>设置推荐成功。</td></tr>"
			elseif request("Tset")=2 then''热点
			if request("Tsto")=1 then
			Conn.Execute("update Ms_diary set Ishot=1 where Did in ("&delid&")")''日记操作
			else
			Conn.Execute("update Ms_diary set Ishot=0 where Did in ("&delid&")")''日记操作
			end if
			response.write "<tr><td colspan=8 class=forumrow>设置为热点成功。</td></tr>"
			elseif request("Tset")=3 then''固顶
			if request("Tsto")=1 then
			Conn.Execute("update Ms_diary set Istop=2 where Did in ("&delid&")")''日记操作
			else
			Conn.Execute("update Ms_diary set Istop=0 where Did in ("&delid&")")''日记操作
			end if
			response.write "<tr><td colspan=8 class=forumrow>设置固顶成功。</td></tr>"
			elseif request("Tset")=4 then''佳作
			if request("Tsto")=1 then
			Conn.Execute("update Ms_diary set Isbest=1 where Did in ("&delid&")")''日记操作
			else
			Conn.Execute("update Ms_diary set Isbest=0 where Did in ("&delid&")")''日记操作
			end if
			response.write "<tr><td colspan=8 class=forumrow>设置佳作成功。</td></tr>"
			end if
		else
		response.write "<tr><td colspan=8 class=forumrow>请选择设置/取消。</td></tr>"
		end if	
		else
			response.write "<tr><td colspan=8 class=forumrow>错误的参数。</td></tr>"
		end if
	end if
end sub

sub view()''查看日记记录
sql="select * from [Ms_diary] where Did="&request("id")&""
		set rs=conn.execute(Sql)
		if not (rs.eof and rs.bof) then
		%>
<tr><th colspan=8 height=23 align=center><b><%=rs("Title")%></b></th></tr>
   <tr> 
    <td height="27" align="center" colspan=8 class=forumrow>作者：<%=rs("Username")%>　　最近更新：<%=replace(rs("Lasttime"),right(rs("Lasttime"),3),"")%>　　人气：<%=rs("hits")%></td>
              </tr>
    <tr> 
                <td height="28" align="center" colspan=8  class=forumrow>日期：<%=rs("Datetime")%>　 <%=weekdayname(WeekDay(rs("Datetime")))%> 　天气：<img src=../Skins/Default/weather/<%=rs("Weather")%>.gif border=0 width=13>　 
                  　　心情：<img src=../<%=rs("Topic")%> width=20 border=0 align="absmiddle"> 
                </td>
              </tr>
              <tr> 
                <td height="29" colspan=8  class=forumrow><blockquote><%=rs("Content")%></blockquote></td>
              </tr>
<tr>
<td width=80% class=forumrow colspan=8>
</td>
</tr>
<%end if
rs.close
end sub

sub view_d()
sql="select * from [Ms_diaryb] where Did="&request("id")&""
		set rs=conn.execute(Sql)
		if not (rs.eof and rs.bof) then
		%>
<tr><th colspan=8 height=23 align=center><b><%=rs("Title")%></b></th></tr>
   <tr> 
    <td height="27" align="center" colspan=8 class=forumrow>作者：<%=rs("LastPost")%>　　最近更新：<%=rs("LastTime")%></td>
              </tr>
              <tr> 
                <td height="29" colspan=8  class=forumrow><blockquote><%=rs("Content")%></blockquote></td>
              </tr>
<tr>
<td width=80% class=forumrow colspan=8>
</td>
</tr>
<%end if
rs.close
end sub%>