<!--#include file="../conn.asp"-->
<!--#include file="admin_check.asp"-->
<!--#include file="../inc/Function.asp"-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
<title>管理页面</title>
<link id="maincss" rel="stylesheet" href="images/css/admin_style_<%= AdminSkin %>.css" type="text/css" media="all" />
<script language="javascript">
function CheckAll()
{
var length = document.formed.checkbox.length;
var tocheck = document.formed.SelectAll.checked;

  if (length>=2)
  {
    for (var i=0; i<length; i++){document.formed.checkbox[i].checked = tocheck;}
   }
  else
  {
    document.formed.checkbox.checked = tocheck;    
  }
   
}
</script>
</head>
<body leftmargin="0" bottommargin="0" rightmargin="0" topmargin="5" marginheight="0" marginwidth="0" bgcolor="#DDEEFF">
<%
Call chkFlag(4)
Dim act
act=Trim(Request.QueryString("act"))
opendb
Select Case act
	Case "del"
	  Call del()
	Case "TjNum"
	  Call TjNum()
	Case else
	   Call Main()
End Select
closedb

Sub Del()
   Dim Tid,checkbox
   Tid=Trim(Request.Form("tid"))
   checkbox=Trim(Request.Form("checkbox"))
   IF checkbox<>"" Then
   IF Tid=1 Then 
      Conn.execute("Delete From "&predb&"UserTj where ID in("&checkbox&")")   
	  Call SendMsg("删除推荐成功！")
      Response.Write("<script>setTimeout(""location.href='?'"",2000)</script>")
   Else
      Conn.execute("Delete From "&predb&"UserTj where askid in("&checkbox&")")
	  Call SendMsg("删除推荐成功！")
      Response.Write("<script>setTimeout(""location.href='?act=TjNum'"",2000)</script>")
   End IF
   Else
      Response.Write("<script>location.href='?'</script>")
   End IF
End Sub

Sub Main()
dim rs,i,rs1,sql,c
Dim idcount,maxperpage,n,page,minid
maxperpage=25
page=clng(Request.QueryString("page"))
        set rs=conn.execute("select count(id) from "&predb&"UserTj")
		idcount=rs(0) 
		set rs=nothing
		
		If idcount Mod maxperpage = 0 Then
			n = idcount \ maxperpage
		else
			n = idcount \ maxperpage + 1
		end If
		
IF page>n then page=n
IF page<1 then page=1

		if page=1 then
           set rs=conn.execute("select top "&maxperpage&" * from "&predb&"UserTj order by id desc")
		else
		'Response.Write(page&"select min(id) from (select top "&(page-1)*maxperpage&" id from "&predb&"UserTj order by id desc) d")
			set rs1=conn.execute("select min(id) from (select top "&(page-1)*maxperpage&" id from "&predb&"UserTj order by id desc) d")
			    minid=rs1(0)
			set rs1=nothing
			set rs=conn.execute("select top "&maxperpage&" * from "&predb&"UserTj where id<"&minid&" order by id desc")
		end if
%>
<table class="tableBorder" cellspacing="1" cellpadding="2" width="96%" align="center" border="0">
  <tr>
	<th height="25" colspan="4" align="left">用户推荐管理</th>
  </tr>
	<tr>
		<td class="BodyTitle" height="23" align="left" colspan="4"></td>
	</tr>
  <tr>
    <td colspan="4" class="TableRow2"><font color="red"><strong>说明</strong>：设置用户推荐的目的是为了了解网友的关注，为管理员推荐问题提供参考。</font></td>
  </tr>
  <form method="post" action="?act=del" name="formed" onSubmit="return confirm('请确认您的操作？');">
  <input name="tid" type="hidden" value="1">
 <tr>
    <td width="10%" align="center" class="TableRow1"><strong>选择</strong></td>
    <td align="center" class="TableRow1"><strong>提问标题</strong></td>
    <td width="17%" align="center" class="TableRow1"><strong>推荐者</strong></td>
    <td width="15%" align="center" class="TableRow1"><strong>推荐时间</strong></td>
  </tr>
  <%
  do while not rs.eof
i=i+1
if i mod 2=0 then
  c=1
else
  c=2
end if
  %>
  <tr>
    <td align="center" class="TableRow<%= c %>"><input name="checkbox" type="checkbox" value="<%= rs("id") %>"></td>
    <td class="TableRow<%= c %>">
    <%
	set rs1=conn.execute("select Title from "&predb&"ask where askid="&rs("askid"))
	IF rs1.bof and rs1.eof Then
	   Response.Write("<font color=""#999999"">该提问被删除</font>")
    Else
	   Response.Write("<a href=""admin_ask.asp?act=show&id="&rs("askid")&""">"&rs1("title")&"</a>")
	End IF 
	set rs1=nothing
	%>    
    </td>
    <td class="TableRow<%= c %>">
    <%
	set rs1=conn.execute("select userid,LastIP from "&predb&"user where id="&rs("TjUser"))
	IF rs1.bof and rs1.eof Then
	   Response.Write("<font color=""#999999"">该用户被删除</font>")
    Else
	   Response.Write("<a href=""admin_user.asp?act=change&id="&rs("TjUser")&""" Title=""上次登陆IP："&rs1("LastIP")&""">"&rs1("userid")&"</a>")
	End IF 
	set rs1=nothing
	%> 
    </td>
    <td align="center" class="TableRow<%= c %>"><%= rs("TjTime") %></td>
  </tr>
  <% 
  rs.movenext
  loop
  %>
  <tr>
    <td colspan="6" align="center" class="TableRow1">共<b><%= idcount %></b>则 <font color="#FF0000"><%= page %></font>/<%= n %>页&nbsp;&nbsp; <a href="?page=1">首页</a>&nbsp;&nbsp; <a href="?page=<%= page-1 %>">上一页</a>&nbsp;&nbsp; <a href="?page=<%= page+1 %>">下一页</a>&nbsp;&nbsp; <a href="?page=<%= n %>">尾页</a></td>
  </tr>
  <tr>
    <td colspan="4" class="TableRow1">
    <label><input type="checkbox" name="SelectAll" id="SelectAll" onClick="CheckAll()">全选\全不选</label>
    &nbsp; <input type="submit" name="button" id="button" value="删除选中的推荐">
    &nbsp; <input type="button" name="button" id="button" value="按推荐次数排列" onClick="location.href='?act=TjNum'">    </td>
  </tr>
  </form>
</table>
<%
set rs=nothing
End Sub


Sub TjNum()
dim rs,i,rs1,sql,c,TempTable,tjTime
TempTable="(Select Count(id) as TjNum,askid from "&predb&"UserTj group by askid) d"
Dim idcount,maxperpage,n,page,minid
maxperpage=25
page=clng(Request.QueryString("page"))
        set rs=conn.execute("select count(TjNum) from "&TempTable)
		idcount=rs(0) 
		set rs=nothing
		
		If idcount Mod maxperpage = 0 Then
			n = idcount \ maxperpage
		else
			n = idcount \ maxperpage + 1
		end If

IF page>n then page=n		
IF page<1 then page=1


		if page=1 then
           set rs=conn.execute("select top "&maxperpage&" * from "&TempTable&" order by TjNum desc")
		else
			set rs1=conn.execute("select min(TjNum) from (select top "&(page-1)*maxperpage&" id from "&TempTable&" order by Tjnum desc) d")
			    minid=rs1(0)
			set rs1=nothing
			set rs=conn.execute("select top "&maxperpage&" * from "&TempTable&" where TjNum<"&minid&" order by TjNum desc")
		end if
%>
<table class="tableBorder" cellspacing="1" cellpadding="2" width="96%" align="center" border="0">
  <tr>
	<th height="25" colspan="5" align="left">用户推荐管理</th>
  </tr>
	<tr>
		<td class="BodyTitle" height="23" align="left" colspan="5"></td>
	</tr>
  <tr>
    <td colspan="5" class="TableRow2"><font color="red"><strong>说明</strong>：设置用户推荐的目的是为了了解网友的关注，为管理员推荐问题提供参考。</font></td>
  </tr>
  <form method="post" action="?act=del" name="formed" onSubmit="return confirm('将删除所有同一标题的推荐？');">
  <input name="tid" type="hidden" value="2">
  <tr>
    <td width="10%" align="center" class="TableRow1"><strong>选择</strong></td>
    <td align="center" class="TableRow1"><strong>提问标题</strong></td>
    <td width="10%" align="center" class="TableRow1"><strong>推荐次数</strong></td>
    <td width="17%" align="center" class="TableRow1"><strong>最后推荐者</strong></td>
    <td width="15%" align="center" class="TableRow1"><strong>最后推荐时间</strong></td>
  </tr>
  <%
  do while not rs.eof
i=i+1
if i mod 2=0 then
  c=1
else
  c=2
end if
  %>
  <tr>
    <td align="center" class="TableRow<%= c %>"><input name="checkbox" type="checkbox" value="<%= rs("askid") %>"></td>
    <td class="TableRow<%= c %>">
    <%
	set rs1=conn.execute("select Title from "&predb&"ask where askid="&rs("askid"))
	IF rs1.bof and rs1.eof Then
	   Response.Write("<font color=""#999999"">该提问被删除</font>")
    Else
	   Response.Write("<a href=""admin_ask.asp?act=show&id="&rs("askid")&""">"&rs1("title")&"</a>")
	End IF 
	set rs1=nothing
	%>    </td>
    <td align="center" class="TableRow<%= c %>"><b><%= rs("TjNum") %></b></td>
    <td class="TableRow<%= c %>">
    <%
	set rs1=conn.execute("select top 1 a.id,userid,tjtime from "&predb&"user a inner join "&predb&"UserTj b on a.id=b.tjuser where b.askid="&rs("askid")&" order by b.id desc")
	IF rs1.bof and rs1.eof Then
	   Response.Write("<font color=""#999999"">该用户被删除</font>")
    Else
	   Response.Write("<a href=""admin_user.asp?act=change&id="&rs1("id")&""">"&rs1("userid")&"</a>")
	   Tjtime=rs1("Tjtime")
	End IF 
	set rs1=nothing
	%> 
    </td>
    <td align="center" class="TableRow<%= c %>"><%= Tjtime %></td>
  </tr>
  <% 
  rs.movenext
  loop
  %>
  <tr>
    <td colspan="7" align="center" class="TableRow1">共<b><%= idcount %></b>则 分<font color="#FF0000"><%= n %></font>页&nbsp;&nbsp; <a href="?page=1">首页</a>&nbsp;&nbsp; <a href="?page=<%= page-1 %>">上一页</a>&nbsp;&nbsp; <a href="?page=<%= page+1 %>">下一页</a>&nbsp;&nbsp; <a href="?page=<%= n %>">尾页</a></td>
  </tr>
  <tr>
    <td colspan="5" class="TableRow1">
    <label><input type="checkbox" name="SelectAll" id="SelectAll" onClick="CheckAll()">全选\全不选</label>
    &nbsp; <input type="submit" name="button" id="button" value="删除选中的推荐">
    &nbsp; <input type="button" name="button" id="button" value="返回管理" onClick="location.href='?'">    </td>
  </tr>
  </form>
</table>
<%
set rs=nothing
End Sub
%>
<br>
</body>
</html>
