<%@ page contentType="text/html;charset=GBK" %>

<%@ page import="java.util.*,
                 com.jivesoftware.forum.*,
                 com.jivesoftware.forum.util.*"
    errorPage="error.jsp"
%>

<%@ include file="global.jsp" %>

<%  // Get parameters
    long forumID = ParamUtils.getLongParameter(request,"forum",-1L);
    long threadID = ParamUtils.getLongParameter(request,"thread",-1L);
    long messageID = ParamUtils.getLongParameter(request,"message",-1L);
    int start = ParamUtils.getIntParameter(request,"start",0);
    int range = myEnv.du.getMessageRange(request,response,pageUser);
    boolean hilite = ParamUtils.getBooleanParameter(request,"hilite");
    boolean redirect = ParamUtils.getBooleanParameter(request,"redirect");
    String searchWords = ParamUtils.getParameter(request,"q");

    // Load the forum
    Forum forum = myEnv.getForumFactory().getForum(forumID);
    // The requested thread object
    ForumThread thread = forum.getThread(threadID);

    // Compute number of topics, messages in this forum, number of pages
    int numMessages = thread.getMessageCount();
        int numReplies = numMessages-1; // subtract 1 because the root message is counted

        // TreeWalker lets us get an iterator of nested messages
        TreeWalker treeWalker = thread.treeWalker();
        // Root message of the thread
        ForumMessage rootMessage = thread.getRootMessage();
    // Message iterator
        Iterator messages = treeWalker.recursiveChildren(rootMessage);

    // A user manager lets us get information about users
    UserManager userManager = myEnv.getForumFactory().getUserManager();

    // Get a thread iterator (for the next/previous thread feature)
    ForumThreadIterator threadIterator = forum.threads();
    // Set its index to this thread
    threadIterator.setIndex(thread);

    // Get a watch manager to manage watches on this page.
    WatchManager watchManager = null;
    // Indicates if this thread is watched
    boolean isWatchedThread = false;
    if (!isGuest) {
        watchManager = myEnv.getForumFactory().getWatchManager();
        isWatchedThread = watchManager.isWatchedThread(pageUser, thread, WatchManager.NORMAL_WATCH);
    }

    // Get the minimum moderation value for this forum since we need to manually
    // mark each message as moderated or not
    int minModValue = forum.getModerationMinMessageValue();
%>


<html><!-- #BeginTemplate "/Templates/module.dwt" --><!-- DW6 -->
<head>
<!-- #BeginEditable "doctitle" -->
<title></title>
<!-- #EndEditable -->
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<style type="text/css">
<!--
.black {
	color: #000000;
}
.ziti {  font-weight: bold; color: #999999; text-decoration: underline}
.unnamed1 {  font-size: 14px; color: #7386AA; text-decoration: underline}
.unnamed2 {  font-weight: normal; color: #FFFFFF; font-size: 14px; text-decoration: none}
A.a03:link {text-decoration:none;color:#FFFFFF;}
A.a03:visited {text-decoration:none;color:#FFFFFF;}
A.a03:active {text-decoration:none;color:#ff0000;}
A.a03:hover {text-decoration:none;color:#ff0000;}
A.a03:link {text-decoration:none;color:#FFFFFF;}
A.a03:visited {text-decoration:none;color:#FFFFFF;}
A.a03:active {text-decoration:none;color:#ff0000;}
A.a03:hover {text-decoration:none;color:#ff0000;}

A.a04:link {text-decoration:none;color:#000000;}
A.a04:visited {text-decoration:none;color:#000000;}
A.a04:active {text-decoration:none;color:#333333;}
A.a04:hover {text-decoration:none;color:#333333;}

p,td,select,input{font-size:14.9px;}
A:link {color: #0000ff;}
A:visited {color: #800080;}
A:active,A:hover {color : #ff0000}

-->
</style>
</head>

<body bgcolor="#DADEDE" text="#000000">
<table width="770" border="0" cellspacing="0" cellpadding="0" align="center">
  <tr>
    <td bgcolor="#EAEEEE" colspan="7" class="dixian">
      <div align="center"></div>
      <div align="center">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
                  <td height="98" bgcolor="#EAEEEE" width="127" rowspan="3" class="dixian">

              <div align="center"><img src="http://www.jdon.com/images/newlogo.gif" width="80" height="80" border="0"></div>
                  </td>
                  <td height="72" bgcolor="#EAEEEE" colspan="6">&nbsp;</td>
                </tr>
                <tr>

            <td height="26" bgcolor="#707070">&nbsp;</td>

            <td height="26" width="70" bgcolor="#707070">
              <div align="center"><a href="http://www.jdon.com/index.html" class="a03">首&nbsp;&nbsp;&nbsp;&nbsp;页</a></div>
                  </td>
                  <td height="26" width="70" bgcolor="#707070" class="unnamed2">

              <div align="center"><a href="http://www.jdon.com/idea.html" class="a03">心&nbsp;&nbsp;&nbsp;&nbsp;得</a></div>
                  </td>
                  <td height="26" width="70" bgcolor="#707070" class="unnamed2">

              <div align="center"><a href="http://www.jdon.com/designpatterns/index.htm" class="a03">设计模式</a></div>
                  </td>
                  <td height="26" width="70" bgcolor="#707070" class="unnamed2">

              <div align="center"><a href="http://www.jdon.com/res.html" class="a03">工程方法</a></div>
                  </td>
                  <td height="26" width="70" bgcolor="#707070">

              <div align="center" class="unnamed2"> <a href="http://www.jdon.com/dl/dl.html" class="a03">资&nbsp;&nbsp;&nbsp;&nbsp;料</a></div>
                  </td>
				  <td height="26" width="70" bgcolor="#707070">

              <div align="center" class="unnamed2"> <a href="http://www.jdon.com/jive"  class="a03">论&nbsp;&nbsp;&nbsp;&nbsp;坛</a></div>
                  </td>
                </tr>
                <tr>
                  <td height="15" bgcolor="#EAEEEE" class="dixian" colspan="6">&nbsp;</td>
                </tr>

        </table>
      </div>
      </td>
  </tr>
  <tr>
    <td height="11" colspan="7" bgcolor="#FFFFFF" class="bianxian">
      <table width="800" border="0" cellspacing="0" cellpadding="0" height="1" bordercolor="#000000">
        <tr>
          <td>
            <table width="800" border="0" cellspacing="0" cellpadding="0" height="2" bgcolor="#000000">
              <tr>
                <td></td>
              </tr>
            </table>
          </td>
        </tr>
      </table>
    </td>
  </tr>
  <tr>

    <td bgcolor="#FFFFFF"  valign="top">
      <table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td width="127" valign="top">
            <table width="127" border="0" cellspacing="0" cellpadding="0" height="477">
              <tr>
                <td valign="top" height="41">
                  <div align="center" class="ziti"></div>
                  <div align="center"> </div>
                  <table width="92" border="0" cellspacing="0" cellpadding="3" height="200" align="center">
                    <tr>
                      <td align="left" valign="top">
                        <div align="center">
                          <form method=GET action=http://www.google.com/custom>
                            <table  cellspacing=0 border=0>
                              <tr valign=top>
                                <td align=right> <a href=http://www.google.com/search>
                                  <img src=../images/Logo_25wht.gif width="75" height="32" border=0 alt=Google align=middle></a>
                                </td>
                              </tr>
                              <tr>
                                <td  align=right>
                                  <p>
                                    <input type=text name=q size="14" maxlength="255" value="">
                                    <input type=hidden name=hl value="zh-CN">
                                    <input type=submit name=sa value="Search">
                                    <br>
                                    <input type=hidden name=hl value="zh-CN">
                                    <input type=hidden name=cof value="L:http://www.jdon.com/images/newlogo.gif;BGC:#eeeeee;AH:left;GL:0;S:http://www.jdon.com;AWFID:c74cf53925b3abd3;">
                                    <input type=hidden name=domains value="jdon.com" >
                                    <input type=radio name=sitesearch value="jdon.com" checked>
                                    <font face=arial,sans-serif size=-1>
                                    本站<input type=radio name=sitesearch value="" >全部</font></p>
                                  </td>
                              </tr>
                            </table>
                          </form>
                        </div>
                      </td>
                    </tr>
                    <tr>
                      <td align="right"> <p><a href="http://www.jdon.com/ejbcmp2.htm" class="a04"><font color="#FF0000"><strong>热门教程</strong></font><br>
                          <span class="a04"> JBoss＋MySQL<br>
                          ＋Jbuilder 7<br>
                          整合以及<br>
                          EJB的开发<br>
                          部署和配置</span></a></p>
                        <p><font color="#FF0000"><strong>热门软件</strong></font><br>
                          <a href="http://www.jdon.com/jive.htm"  class="a04">Jive(J道版)<br>
                          源代码下载</a></p>
                        <p><br>
                          <a href="http://www.jdon.com/jive"><img src="http://www.jdon.com/images/luntan.gif" width="58" height="24" border="0"></a><br>
                          <a href="http://www.jdon.com/mypaint/bqrj.htm"><img src="http://www.jdon.com/images/bqz.gif" width="58" height="24" border="0"></a>
                        </p>
                        <P>&nbsp;</P>
                      </td>
                    </tr>
                  </table>
                </td>
              </tr>
            </table>
          </td>
          <td valign="top">
            <table width="100%" border="0" cellspacing="3" cellpadding="3">
              <tr>
                <td><!-- #BeginEditable "main" -->


<%	// There are messages, so iterate and print them out
    String bgcolor = "";
    int row = 1;
	boolean rootDisplayed = false;
    int lastMessageDepth = 0;
	int maxnumReplies=10;
	while (messages.hasNext() || !rootDisplayed) {
		ForumMessage message = null;
		if (!rootDisplayed) {
			message = rootMessage;
			rootDisplayed = true;
		}
		else {
			message = (ForumMessage)messages.next();
		}
        // Get the tree depth for this message. This tells us how far to indent
        // it.
		int messageDepth = treeWalker.getMessageDepth(message);
        // Message moderation:
        // For each of the message, get its moderation value. If it's less
        // than the minimum moderation value for the thread, don't display it.
        int messageMinModValue = message.getModerationValue();
        // Only display this message if this message's moderation value meets
        // or exceeds the minimum moderation value.
        if (messageMinModValue >= minModValue) {
            if (messageDepth <= lastMessageDepth+1) {
                lastMessageDepth = messageDepth;

        		boolean isRootMessage = (message.getID() == rootMessage.getID());
        		User author = message.getUser();
                if (row++%2 == 1) {
                    bgcolor = JiveGlobals.getJiveProperty("skin.default.tableRowColor1");
                }
                else {
                    bgcolor = JiveGlobals.getJiveProperty("skin.default.tableRowColor2");
                }
                // Check to see if there is an extended property for name & email
                // since the gateway feature imports names and emails as extended
                // props.
                String nameAndEmail = null;
                if (author == null) {
                    String name = message.getProperty("name");
                    String email = message.getProperty("email");
                    nameAndEmail = myEnv.du.getNameAndEmailDisplay(name, email);
                }

                String body = message.getBody();
                if (hilite) {
                    String[] queryWords = StringUtils.toLowerCaseWordArray(searchWords);
                    body = StringUtils.highlightWords(body, queryWords, "<font style='background-color:#ffff00'><b>", "</b></font>");
                }
%>

<a name="<%= message.getID() %>"></a>
<%  if (isRootMessage) { %>
<table  cellpadding="0" cellspacing="0" border="0" width="100%" align="center">
<tr><td>


                <h3 align="center"><%= message.getSubject() %></h3>
                <%        String userStatus = author.getProperty("status");
        String authorName = author.getName();
%>
                <p align="center">
                <a href="profile.jsp?user=<%= author.getID() %>" title="<%= (authorName!=null)?authorName:"" %>">
                <b><%= author.getUsername() %></b></a> http://www.jdon.com <%= SkinUtils.formatDate(request,response,pageUser,message.getCreationDate()) %>
                <a href="post.jsp?forum=<%= forumID %>&thread=<%= threadID %>&message=<%= message.getID() %>&reply=true"
                     ><img src="images/reply.gif" width="17" height="17" alt="回复此消息" hspace="3" border="0"
                     ></a>
                 <font >
                <a href="post.jsp?forum=<%= forumID %>&thread=<%= threadID %>&message=<%= message.getID() %>&reply=true"
                 title="回复此消息">回复</a>
                </font>
                </p>
                  <p><%= body %></p>
</td></tr></table>
<%  } else { // if not rootMessage %>
<%
if (maxnumReplies<=0){
%>
<p align="right"><a href="thread.jsp?forum=<%= forumID %>&thread=<%= threadID %>" target="_blank">更多讨论..</a></p>
<%
 return;

}else{
maxnumReplies--;
%>
<table bgcolor="<%= JiveGlobals.getJiveProperty("skin.default.tableBorderColor") %>"
 cellpadding="0" cellspacing="0" border="0" width="100%" align="center">
<tr>
    <td width="1%" bgcolor="<%= JiveGlobals.getJiveProperty("skin.default.bgColor") %>"
        ></td>
	<td width="99%">
    <table bgcolor="<%= JiveGlobals.getJiveProperty("skin.default.tableBorderColor") %>"
     cellpadding="4" cellspacing="1" border="0" width="100%">
    <tr bgcolor="<%= bgcolor %>">
        <td width="98%">
        <font size="-1" face="<%= JiveGlobals.getJiveProperty("skin.default.fontFace") %>"
        color="<%= JiveGlobals.getJiveProperty("skin.default.textColor") %>">
        <b><%= message.getSubject() %></b>
        </font>
		</td>
        <td width="1%" nowrap>
        <font class=p2 face="<%= JiveGlobals.getJiveProperty("skin.default.fontFace") %>"
        color="<%= JiveGlobals.getJiveProperty("skin.default.textColor") %>">
        发表时间: <%= SkinUtils.formatDate(request,response,pageUser,message.getCreationDate()) %>
        </font>
        </td>

        <td width="1%" nowrap align="center">
            <table cellpadding="2" cellspacing="0" border="0">
            <tr>
                <td><a href="post.jsp?forum=<%= forumID %>&thread=<%= threadID %>&message=<%= message.getID() %>&reply=true"
                     ><img src="images/reply.gif" width="17" height="17" alt="回复此消息" hspace="3" border="0"
                     ></a></td>
                <td>
                <font class=p2 face="<%= JiveGlobals.getJiveProperty("skin.default.fontFace") %>">
                <a href="post.jsp?forum=<%= forumID %>&thread=<%= threadID %>&message=<%= message.getID() %>&reply=true"
                 title="回复此消息">回复</a>
                </font>
                </td>
            </tr>
            </table>
        </td>
    </tr>
    <tr bgcolor="<%= bgcolor %>">
        <td colspan="3" valign="top">
        <font class=p2 face="<%= JiveGlobals.getJiveProperty("skin.default.fontFace") %>"
         color="<%= JiveGlobals.getJiveProperty("skin.default.textColor") %>">
        发表人:
        <%  if (author == null) { %>
            <%  if (nameAndEmail != null) { %>
                <i>客人: <%= nameAndEmail %></i>
            <%  } else { %>
                <i>客人</i>
            <%  } %>
            </font>
        <%  } else { %>
            <a href="profile.jsp?user=<%= author.getID() %>"><b><%= author.getUsername() %></b></a>
        </font>
        &nbsp;&nbsp;
        <font class=p2 face="<%= JiveGlobals.getJiveProperty("skin.default.fontFace") %>"
         color="<%= JiveGlobals.getJiveProperty("skin.default.textColor") %>">
        发表文章: <%= userManager.userMessageCount(author) %>
        /
        <%  String location = author.getProperty("jiveLocation");
            if (location != null) { %>
        来　　自: <%= location %> /
        <%  } %>
        注册时间: <%= myEnv.shortDateFormatter.format(author.getCreationDate()) %>
        </font>
        <%  } %>
        </td>
    </tr>
    <tr bgcolor="<%= bgcolor %>">
        <td colspan="3" valign="top">
        <font size="-1" face="<%= JiveGlobals.getJiveProperty("skin.default.fontFace") %>"
         color="<%= JiveGlobals.getJiveProperty("skin.default.textColor") %>">
        <%= body %>
        </font><p>
        </td>
    </tr>
    </table>
</td></tr>
</table>
<%} %>

<%  } // end if (messageDepth <= lastMessageDepth+1) %>
<br>
<%  } // end if moderation value is high enough %>

<%  } // end if rootMessage %>

<%  } // end of while %>


                  <!-- #EndEditable --></td>
              </tr>
            </table>
          </td>
        </tr>
      </table>
    </td>
  </tr>
</table>
</body>
<!-- #EndTemplate --></html>
