<%@ page contentType="text/html; charset=gb2312"%>
<%@ page import="java.sql.*"%> 
<%@ page import="java.util.*"%>
<%@ page import="java.util.Date"%>
<%@ page import="java.text.*"%>
<%@ include file="../inc/conn.jsp"%>
<%!String tlk1,alk,blk,BBS_Cate_Name_1,BBS_Cate_Name_2,BBS_Cate_Manager_Name,searchcontent;%>
<%
String layer_1 = request.getParameter("layer_1");
String layer_2 = request.getParameter("layer_2");
String sign = request.getParameter("sign");
String huati = request.getParameter("huati");
String order_key = request.getParameter("order_key");

String searchkind = request.getParameter("searchkind");
//String searchcontent = request.getParameter("searchcontent");
if(searchkind!=null){
searchcontent =new String(request.getParameter("searchcontent").getBytes("iso-8859-1"));
}

String sql,lk1,lk2,signstr,huatistr,searchkindstr;
ResultSet rs1,rs2,rs3;
String ext = request.getParameter("ext");

if(searchkind!=null&&searchcontent!=null){
searchkindstr="and " +searchkind+ " like '%"+searchcontent+"%'";
}
else{
searchkindstr="";
}

if(order_key==null){
   order_key="bbstop desc,redate desc";
}
else{
   order_key=order_key+" desc";
}
//out.print(order_key);
//out.close();

if(sign!=null){
signstr="and sign=1";
}
else{
signstr="";
}
if(huati!=null){
huatistr="and huati=1";
}
else{
huatistr="";
}

if(ext==null){
ext="n";
}
if (ext.equals("y"))
//if (ext=="y")
   {
   //String bbsuser = (String)session.getAttribute("name"); 
   session.setAttribute("name","");
   session.setAttribute("bz","");
   session.setAttribute("bbsadmin","");
   session.setAttribute("payuser","");
   
   out.print("<script language='javascript'>");
   out.print("window.location.href='main.jsp';");
   out.print("parent.left.document.location.reload();");
   out.print("</script>");
  }
//  
if(layer_1!=null)
{
String str="select BBS_Cate_Name,BBS_Cate_Manager_Name,BBS_Cate_Manager_Email,BBS_Cate_Topic,BBS_Cate_Reply from BBS_Cate where BBS_Cate_ID='"+layer_1+"' and deleted=0";
Statement stmt1=conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
rs1=stmt1.executeQuery(str);
rs1.next();
BBS_Cate_Name_1=rs1.getString("BBS_Cate_Name");
BBS_Cate_Manager_Name=rs1.getString("BBS_Cate_Manager_Name");
}
else
{
BBS_Cate_Name_1="";
BBS_Cate_Manager_Name="";
}
if(layer_2!=null)
{
String sqlstr="select BBS_Cate_Name,BBS_Cate_Manager_Name from BBS_Cate where BBS_Cate_ID='"+layer_2+"'";
Statement stmt2=conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
rs2=stmt2.executeQuery(sqlstr);
rs2.next();
BBS_Cate_Name_2=rs2.getString("BBS_Cate_Name");
BBS_Cate_Manager_Name=rs2.getString("BBS_Cate_Manager_Name");
}
else
{
BBS_Cate_Name_2="";
BBS_Cate_Manager_Name="";
}

if(layer_1!=null)
{
lk1="&layer_1="+layer_1;
tlk1="?layer_1="+layer_1;
//alk="?sign=1";
//blk="?huati=1";
}
else
{
lk1="";
tlk1="";
}

if(layer_2!=null)
{
lk2="&layer_2="+layer_2;
}
else
{
lk2="";
}
if(layer_1!=null||layer_2!=null)
{
alk="&sign=1";
blk="&huati=1";
}
else
{
alk="?sign=1";
blk="?huati=1";
}
%>
<HTML><HEAD>
<title>飞天论坛(ftbbs ACCESS 3.0.1)</title>
<META http-equiv=Content-Type content=text/html;charset=gb2312>
<link href="../css/news2.css" rel="stylesheet" type="text/css">
<STYLE type=text/css>
BODY {
	BACKGROUND: #ffffff; MARGIN: 5px
}
.sec_menu {
	BORDER-RIGHT: white 1px solid; BACKGROUND: #d6dff7; OVERFLOW: hidden; BORDER-LEFT: white 1px solid; BORDER-BOTTOM: white 1px solid
}
.menu_title SPAN {
	FONT-WEIGHT: bold; LEFT: 10px; COLOR: #215dc6; POSITION: relative; TOP: 2px
}
.menu_title2 SPAN {
	FONT-WEIGHT: bold; LEFT: 10px; COLOR: #428eff; POSITION: relative; TOP: 2px
}
</STYLE>
</HEAD>
<script language=javascript src="../inc/wyjs.js"></script>

<script language="javascript">
	function check_search(form)
		{
		if (form.searchcontent.value=="")
			{
			alert("请输入搜索内容！");
			form.searchcontent.focus();
			return false;
			}
			return true;
		}
</script>
<script language="javascript">

function check(form)
	{
    if (form.bbsuser.value=="")
    	{
    		alert("请填写用户名！");
    		form.bbsuser.focus();
    		return false;
  	}
    if (form.password.value=="")
    	{
    		alert("请填写密码！");
    		form.password.focus();
    		return false;
  	}
return true;
	}
</script>
<script language="JavaScript" type="text/JavaScript">
function MM_jumpMenu(targ,selObj,restore){ 
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
</script>
<table width="99%" border="0" cellspacing="0" cellpadding="0" align="center">
  <tr>
    <td> 
      <table width="100%" border=0 cellpadding=2 cellspacing=1 bgcolor="#A4B6D7">
        <tbody>
          <tr> 
            <td width="51%" background="../images/bbs_bg1.gif" ><img src="../images/bbs_t1.gif" align="absmiddle"> 
              <a href="../bbs/main.jsp">论坛首页</a>>><a href="main.jsp<%=tlk1%>"><%=BBS_Cate_Name_1%></a>>><a href="main.jsp<%=tlk1%><%=lk2%>"><%=BBS_Cate_Name_2%></a></td>
            <td align=right background="../images/bbs_bg1.gif" > <div align="center"><a href="main.jsp<%=tlk1%><%=lk2%><%=blk%>">精华贴</a> 
                <a href="main.jsp<%=tlk1%><%=lk2%><%=alk%>">推荐贴</a> 
                总版主:xmfangzi</div></td>
          </tr>
        </tbody>
      </table>
      <table cellspacing=0 cellpadding=0 width="100%" border=0>
        <tbody> 
        <tr> 
            <td width="17%" height="40"><a href="fbht.jsp<%=tlk1%><%=lk2%>"><img src="../images/bbs_add.gif" width="81" height="21" border="0"></a><!--&nbsp;<a href="bbspoll.jsp<%=tlk1%><%=lk2%>"><img src="../images/poll_add.gif" width="81" height="21" border="0"></a>--></td>
          <FORM METHOD=POST ACTION="main.jsp" onsubmit="return check_search(this)">
            <td width="63%" align=right> 
              <div align="center"><img src="../images/bbs_find.gif" width="16" height="16"> 
                  <%if(layer_1!=null){%>
				  <input type="hidden" name="layer_1" value="<%=layer_1%>">
				  <%}%>
                  <input type=text name="searchcontent" size=25 class=p1 value="">
                <select name="searchkind" style="width:70">
                  <option value="title" selected>按主题</option>
                  <option value="user_id" >按用户名</option>
                </select>
                <input name="search" src="images/d_search.gif" type="image" value="Submit" width="37" height="21" border="0" align="absmiddle">
                <img src="images/refesh.gif" width="37" height="21" align="absmiddle" onClick="javascript:window.location.reload();" style="CURSOR: hand">
                </div>
            </td>
          </form>
          <form name="form1" method="post" style="MARGIN-BOTTOM: 0px">     
            <td width="20%" valign="middle"> 
              <div align="center">排序 
                <select name="menu1" style="width:75px" onChange="MM_jumpMenu('self',this,0)">
                  <option value="main.jsp?order_key=date">发帖时间
                  <option value="main.jsp?order_key=redate">跟帖时间 
                  <option value="main.jsp?order_key=hit">浏览量 
                  <option value="main.jsp?order_key=rep">跟帖数 
                </select>
                  <input name="layer_2" type="hidden" id="layer_2" value="<%=layer_2%>">
				  <input name="layer_1" type="hidden" id="layer_1" value="<%=layer_1%>">
                </div>
            </td>
          </form>
        </tr>
        </tbody> 
      </table>
      <table width="100%" border=0 cellpadding=2 cellspacing=1 bgcolor="#A4B6D7" align="center">
        <tbody>
          <tr align=middle> 
            <td width="6%" background="../images/bbs_bg1.gif">点击</td>
            <td width="52%" background="../images/bbs_bg1.gif" >论坛主题</td>
            <td width="5%" background="../images/bbs_bg1.gif" >回复</td>
            <td width="11%" background="../images/bbs_bg1.gif" >作者</td>
            <td width="25%" background="../images/bbs_bg1.gif" >更新时间</td>
          </tr>
<%
if(layer_1!=null)
{
  if (layer_2!=null)
  {
  sql="select * from bbstitle where deleted=0 "+signstr+" "+huatistr+" "+searchkindstr+" and BoardID_1='" + layer_1 + "' and BoardID_2='" + layer_2 + "' order by "+order_key; //bbstop desc,redate desc";
  }
  else
  {
  sql="select * from bbstitle where deleted=0 "+signstr+" "+huatistr+" "+searchkindstr+" and BoardID_1='" + layer_1 + "' order by "+order_key;
  }
}
else
{
sql="select * from bbstitle where deleted=0 "+signstr+" "+huatistr+" "+searchkindstr+" order by "+order_key;
}
//out.print(sql);
ResultSet rs=stmt.executeQuery(sql);

int intPageSize; //一页显示的记录数
int intRowCount; //记录总数
int intPageCount; //总页数
int intPage; //待显示页码
String strPage;
int i;

//设置一页显示的记录数
intPageSize = 25;

//取得待显示页码
strPage = request.getParameter("pages");
if(strPage==null){
//表明在QueryString中没有page这一个参数，此时显示第一页数据
intPage = 1;
}
else
{
//将字符串转换成整型
intPage = Integer.parseInt(strPage);
if(intPage<1){ intPage = 1;}
}
//获取记录总数 
rs.last(); 
intRowCount = rs.getRow(); 
//计算总页数
intPageCount =(intRowCount+intPageSize-1) / intPageSize;

//调整待显示的页码
if(intPage>intPageCount) intPage = intPageCount;
if(intPageCount>0){
//将记录指针定位到待显示页的第一条记录上 
rs.absolute((intPage-1) * intPageSize+1); 
//显示数据 
i = 0; 

//if (rs.next()){
while(i< intPageSize && !rs.isAfterLast()){ 
int id=rs.getInt("id");
String repTime=rs.getString("redate");
String bbs_img_display=rs.getString("bbs_img_display");
String dTime=repTime.substring(2,16);

String stsql="select top 1 user_id,rename from bbsmenu where pid="+id+" order by id desc";
Statement stmt3=conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
rs3=stmt3.executeQuery(stsql);
%>
          <tr align=middle> 
            <td bgcolor="#ECF5FF" width="6%" height="28"><%=rs.getString("hit")%></td>
            <td width="52%" align=left valign="middle" bgcolor="#F2F8FF">
              <%if(rs.getString("bbstop").equals("1")){%>
              <img src="images/ding.gif" width="15" height="13" align="absmiddle"> 
              <%}%>
              <%if(rs.getString("sign").equals("1")){%>
              <img src="images/jian.gif" width="15" height="13" align="absmiddle"> 
              <%}%>
              <%if(rs.getString("huati").equals("1")){%>
              <img src="images/jing.gif" width="15" height="13" align="absmiddle"> 
              <%}%>
              <%if(rs.getString("P_display").equals("0")){%>
              <img src="images/suo.gif" width="12" height="13" align="absmiddle"> 
              <%}%>
              <%if(rs.getInt("P_display")!=0 && rs.getInt("bbstop")!=1 && rs.getInt("sign")!=1 && rs.getInt("huati")!=1){%>
              <img src="../images/<%=rs.getString("picture")%>" width="19" height="19" align="absmiddle"> 
              <%}%>
			  <a class=f14 href="checkasp.jsp?id=<%=id%>"><%=rs.getString("title")%></a>
			  <%if(rs.getString("bbs_img")!=null){%>
              <font color=red> [图]</font> 
              <%}%>
			</td>
            <td bgcolor="#ECF5FF" width="7%" ><%=rs.getString("rep")%></td>
            <td bgcolor="#F2F8FF" width="9%" ><a href="main.jsp?searchkind=user_id&searchcontent=<%=rs.getString("user_id")%>&layer_1=<%=rs.getString("boardid_1")%>"><%=rs.getString("user_id")%></a></td>
            <td bgcolor="#F2F8FF" width="16%" align=left><%=dTime%><%if(rs3.next()){%><font color=red>|</font><%=rs3.getString("user_id")%><%}%>
			</td>
          </tr>
<%
rs.next(); 
i++; 
  } 
  }
rs.close();
stmt.close(); 
conn.close();
%>
          <tr valign="top"> 
            <td colspan="6"  background="../images/bbs_bg1.gif"><table width="100%" border="0" cellspacing="0" cellpadding="0" align="center">
                <tr> 
                  <td align="left" width="322">&nbsp; 
                    <%out.print("共<font color=red>"+intRowCount+"</font>个主题 <font color=red>"+intPageSize+"</font>/页 共<font color=red>"+intPageCount+"</font>页");%>
                    当前第<font color=red><%=intPage%></font>页 </td>
                  <td width="439" height="23" align="right">&nbsp;
				    <%if(intPage<=1){%>
				    首页
				    <%}else{%>
                    <a href="main.jsp?pages=1<%=lk1%><%=lk2%>">首页</a>
					<%}%>
                    <%if(intPage>1){%>
                    <a href="main.jsp?pages=<%=intPage-1%><%=lk1%><%=lk2%>">上一页</a> 
                    <%}else{%>
                    上一页 
                    <%
	                }%>
                    <%if(intPage<intPageCount){%>
                    <a href="main.jsp?pages=<%=intPage+1%><%=lk1%><%=lk2%>">下一页</a> 
                    <%}else{%>
                    下一页 
                    <%
	                }%>
				    <%if(intPageCount<=1||intPage==intPageCount){%>
				    尾页
				    <%}else{%>
                    &nbsp;<a href="main.jsp?pages=<%=intPageCount%><%=lk1%><%=lk2%>">尾页</a>&nbsp;
					<%}%>					
                    </td>
                </tr>
              </table></td>
          </tr>
<%//}
//else{
/*
%>
          <tr bgcolor="#EFF7FA"> 
            <td colspan=6 align=center height=20> 欢迎到本论坛发表贴子！ </td>
          </tr>
<%//}
*/
%>
        </tbody>
      </table>
    </td>
  </tr>
</table>
<%@ include file="../inc/bbstail.jsp"%>