<%@ page contentType="text/html;charset=GBK" %>
<%
/**
 *	$RCSfile: threadMode1.jsp,v $
 *	$Revision: 1.4 $
 *	$Date: 2002/10/07 07:50:53 $
 */
%>

<%@ 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();
%>

<%  String title = "论坛 - " + thread.getName(); %>
<%@ include file="header.jsp" %>

<table cellpadding="0" cellspacing="0" border="0" width="100%">
<tr>
    <td width="99%" valign="top">

    <font face="<%= JiveGlobals.getJiveProperty("skin.default.fontFace") %>" color="<%= JiveGlobals.getJiveProperty("skin.default.linkColor") %>">
    <b><%= rootMessage.getSubject() %></b>
    </font>
    <br>

    <%-- Breadcrumbs --%>

    <font size="-1" face="<%= JiveGlobals.getJiveProperty("skin.default.fontFace") %>" color="<%= JiveGlobals.getJiveProperty("skin.default.linkColor") %>">
    <b>
    <a href="<%= JiveGlobals.getJiveProperty("skin.default.homeURL") %>"
    >首页</a>
    &raquo;
    <a href="index.jsp" title="返回论坛列表"
    >论坛</a>
    &raquo;
    <a href="forum.jsp?forum=<%= forumID %>" title="返回论坛主题列表"
    ><%= forum.getName() %></a>
    </b>
    </font>

    <p>

    <font class=p2 face="<%= JiveGlobals.getJiveProperty("skin.default.fontFace") %>">
    <b><%= numReplies %></b>回复.

<%  if (numReplies > 0) {
        String recentUsername = null;
        // Get the most recent message in this thread:
        ResultFilter filter = new ResultFilter();
        filter.setSortOrder(ResultFilter.DESCENDING);
        filter.setNumResults(1);
        Iterator recentMessages = thread.messages(filter);
        ForumMessage recentMessage = null;
        if (recentMessages.hasNext()) {
            recentMessage = (ForumMessage)recentMessages.next();
        }

        if (recentMessage != null) {
            User recentUser = recentMessage.getUser();
            long recentMessageID = recentMessage.getID();
            if (!recentMessage.isAnonymous()) {
                recentUsername = recentUser.getUsername();
            }
%>
    <a href="#<%= recentMessageID %>"
     title="此主题的更多回复">更多回复</a>:
本主题最后由 <%  if (recentMessage.isAnonymous()) { %><i>客人</i>
<%  } else { %>
<a href="profile.jsp?user=<%= recentUser.getID() %>" title="<%= recentUsername %>'s profile"><%= recentUsername %></a>
<%          }		%>
在<%= SkinUtils.formatDate(request, response, pageUser, recentMessage.getCreationDate()) %>回复
<%        }
    }
%>
    </font>

    </td>
    <td valign="top" width="1%" align="center">
    <%@ include file="loginbox.jsp" %>
    </td>
</tr>
</table>

<%  if (isGuest) { %>
<p>
<%  } %>

<%  if (isWatchedThread) { %>
<table bgcolor="<%= JiveGlobals.getJiveProperty("skin.default.tableBorderColor") %>"
 cellpadding="0" cellspacing="0" border="0">
<tr><td>
<table bgcolor="<%= JiveGlobals.getJiveProperty("skin.default.tableBorderColor") %>"
 cellpadding="3" cellspacing="1" border="0" width="100%">
<tr bgcolor="<%= JiveGlobals.getJiveProperty("skin.default.prefsHeaderBgColor") %>"><td>
    <font class=p2 face="<%= JiveGlobals.getJiveProperty("skin.default.fontFace") %>">
    您正在监控此主题. 按下面“停止监控”按钮可以停止查看.
    <br>
    [<a href="watches.jsp?forum=<%= forumID %>">监控选项</a>]
    </font>
</td></tr>
</table>
</td></tr>
</table><br>
<%  } %>

<table cellpadding="0" cellspacing="2" border="0">
<tr>
	<td><a href="post.jsp?forum=<%= forumID %>&thread=<%= threadID %>&reply=true"><img src="images/reply.gif" width="17" height="17" alt="回复此主题" border="0"></a></td>
	<td nowrap><font class=p2 face="<%= JiveGlobals.getJiveProperty("skin.default.buttonFontFace") %>">
        &nbsp;<a href="post.jsp?forum=<%= forumID %>&thread=<%= threadID %>&reply=true" title="Click to reply to this topic">回复此主题</a>
        </font>
    </td>
    <td><img src="images/blank.gif" width="10" height="1" border="0"></td>
	<td><a href="search.jsp?forums=<%= forumID %>"><img src="images/search.gif" width="17" height="17" alt="Click to search messages in this forum" border="0"></a></td>
	<td nowrap><font class=p2 face="<%= JiveGlobals.getJiveProperty("skin.default.buttonFontFace") %>">
        &nbsp;<a href="search.jsp?forums=<%= forumID %>" title="在此论坛中搜索">搜索论坛</a>
        </font>
    </td>
    <td><img src="images/blank.gif" width="10" height="1" border="0"></td>
    <%  if (!isGuest) {
            if (isWatchedThread) {
    %>
	<td><a href="watches.jsp?forum=<%= forumID %>&thread=<%= threadID %>&remove=true"><img src="images/watch.gif" width="17" height="17" alt="停止监控此主题" border="0"></a></td>
	<td nowrap><font class=p2 face="<%= JiveGlobals.getJiveProperty("skin.default.buttonFontFace") %>">
        &nbsp;<a href="watches.jsp?forum=<%= forumID %>&thread=<%= threadID %>&remove=true" title="Click to stop watching this topic">停止监控</a>
        </font>
    </td>
    <%      } else { %>
	<td><a href="watches.jsp?forum=<%= forumID %>&thread=<%= threadID %>&add=true"><img src="images/watch.gif" width="17" height="17" alt="开始监控此主题" border="0"></a></td>
	<td nowrap><font class=p2 face="<%= JiveGlobals.getJiveProperty("skin.default.buttonFontFace") %>">
        &nbsp;<a href="watches.jsp?forum=<%= forumID %>&thread=<%= threadID %>&add=true" title="Click to start watching this topic">监控此主题</a>
        </font>
    </td>
    <%      }
        }
    %>
</tr>
</table>

<table cellpadding="0" cellspacing="2" border="0" width="100%" align="center">
<tr><td colspan="3"><img src="images/blank.gif" width="1" height="5" border="0"></td></tr>
<tr>
    <td width="1%" nowrap>
<%  if (threadIterator.hasPrevious()) {
        ForumThread prevThread = (ForumThread)threadIterator.previous();
        // advance the iterator pointer back to the original index
        threadIterator.next();
        String subj = prevThread.getRootMessage().getSubject();
        // Replace any " in the subject
        subj = StringUtils.replace(subj, "\"", "&quot;");
%>
    <a href="thread.jsp?forum=<%= forumID %>&thread=<%= prevThread.getID() %>"
     title="<%= subj %>"><img src="images/prev.gif" width="10" height="10" hspace="2" alt="Topic: <%= subj %>" border="0"></a>
    <font class=p2 face="<%= JiveGlobals.getJiveProperty("skin.default.buttonFontFace") %>">
    <a href="thread.jsp?forum=<%= forumID %>&thread=<%= prevThread.getID() %>"
     title="Topic: <%= subj %>">上一主题</a>
    </font>
<%  } else { %>
    &nbsp;
<%  } %>
    </td>
    <td width="98%" align="center">

<table cellpadding="0" cellspacing="2" border="0">
<tr>
	<td><a href="forum.jsp?forum=<%= forumID %>"><img src="images/back_to.gif" width="12" height="12" alt="Go back to the topic listing" border="0"></a></td>
	<td nowrap><font class=p2 face="<%= JiveGlobals.getJiveProperty("skin.default.buttonFontFace") %>">
        &nbsp;<a href="forum.jsp?forum=<%= forumID %>" title="返回主题列表">返回主题列表</a>
        </font>
    </td>
</tr>
</table>

    </td>
    <td width="1%" nowrap>
<%  if (threadIterator.hasNext()) {
        ForumThread nextThread = (ForumThread)threadIterator.next();
        String subj = nextThread.getRootMessage().getSubject();
%>
    <font class=p2 face="<%= JiveGlobals.getJiveProperty("skin.default.buttonFontFace") %>">
    <a href="thread.jsp?forum=<%= forumID %>&thread=<%= nextThread.getID() %>"
     title="<%= subj %>">下一主题</a>
    </font>
    <a href="thread.jsp?forum=<%= forumID %>&thread=<%= nextThread.getID() %>"
     title="<%= subj %>"><img src="images/next.gif" width="10" height="10" hspace="2" alt="Topic: <%= subj %>" border="0"></a>
<%  } else { %>
    &nbsp;
<%  } %>
    </td>
</tr>
</table>


<%	// There are messages, so iterate and print them out
    String bgcolor = "";
    int row = 1;
	boolean rootDisplayed = false;
    int lastMessageDepth = 0;
	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 bgcolor="<%= JiveGlobals.getJiveProperty("skin.default.tableBorderColor") %>"
 cellpadding="0" cellspacing="0" border="0" width="100%" align="center">
<tr>
	<td>
    <table bgcolor="<%= JiveGlobals.getJiveProperty("skin.default.tableBorderColor") %>"
     cellpadding="4" cellspacing="1" border="0" width="100%">
    <tr bgcolor="<%= bgcolor %>">
        <td width="1%" rowspan="2" valign="top">
        <table cellpadding="0" cellspacing="0" border="0" width="140">
        <tr><td>
            <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>
<%      }
    } else {
        // author != null
        String userStatus = author.getProperty("status");
        String authorName = author.getName();
%>
			<a href="profile.jsp?user=<%= author.getID() %>" title="<%= (authorName!=null)?authorName:"" %>"
             ><b><%= author.getUsername() %></b></a>
            </font>

            <font class=p2 face="<%= JiveGlobals.getJiveProperty("skin.default.fontFace") %>"
            color="<%= JiveGlobals.getJiveProperty("skin.default.textColor") %>">
            <br><br>
            <a href="usermessages.jsp?user=<%=author.getID()%>" target=_blank>发表文章: <%= userManager.userMessageCount(author) %></a>
            <%
			if (author.getProperty("jiveIcon")!=null){
			   %><br><img src="<%= author.getProperty("jiveIcon") %>" name="icon"> <%
			}
             %>
            <br>
            <%  String location = author.getProperty("jiveLocation");
            if (location != null) { %>
            来　　自: <%= location %><br>
            <%  } %>
            注册时间: <%= myEnv.shortDateFormatter.format(author.getCreationDate()) %>
            <br><br>
<%  } // end if author == null %>
            </font>
            </td>
        </tr>
        </table>
        </td>
        <td width="97%">
        <font class=p2 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 width="99%" colspan="3" valign="top">
        <font class=p2 face="<%= JiveGlobals.getJiveProperty("skin.default.fontFace") %>"
         color="<%= JiveGlobals.getJiveProperty("skin.default.textColor") %>">
        <%= body %>
        </font><p>
        </td>
    </tr>
    </table>
</td></tr>
</table>

<%  } else { // if not rootMessage %>

<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") %>"
        ><img src="images/blank.gif" width="<%= (30*messageDepth) %>" height="1" border="0"
        ></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 %>

<%  // Reset the forumThread iterator so we can display the next/previous
    // buttons again
    threadIterator = forum.threads();
    threadIterator.setIndex(thread);
%>
<table cellpadding="0" cellspacing="2" border="0" width="100%" align="center">
<tr>
    <td width="1%" nowrap valign="top">
<%  if (threadIterator.hasPrevious()) {
        ForumThread prevThread = (ForumThread)threadIterator.previous();
        // advance the iterator pointer back to the original index
        threadIterator.next();
        String subj = prevThread.getRootMessage().getSubject();
        // Replace any " in the subject
        subj = StringUtils.replace(subj, "\"", "&quot;");
%>
    <a href="thread.jsp?forum=<%= forumID %>&thread=<%= prevThread.getID() %>"
     title="<%= subj %>"><img src="images/prev.gif" width="10" height="10" hspace="2" alt="Topic: <%= subj %>" border="0"></a>
    <font class=p2 face="<%= JiveGlobals.getJiveProperty("skin.default.buttonFontFace") %>">
    <a href="thread.jsp?forum=<%= forumID %>&thread=<%= prevThread.getID() %>"
     title="Topic: <%= subj %>">上一主题</a>
    </font>
<%  } else { %>
    &nbsp;
<%  } %>
    </td>
    <td width="98%" align="center">

<table cellpadding="0" cellspacing="2" border="0">
<tr>
	<td><a href="forum.jsp?forum=<%= forumID %>"><img src="images/back_to.gif" width="12" height="12" alt="Go back to the topic listing" border="0"></a></td>
	<td nowrap><font class=p2 face="<%= JiveGlobals.getJiveProperty("skin.default.buttonFontFace") %>">
        &nbsp;<a href="forum.jsp?forum=<%= forumID %>" title="返回主题列表">返回主题列表</a>
        </font>
    </td>
    <td nowrap>&nbsp;&nbsp;</td>
	<td><a href="#top"><img src="images/up_to.gif" width="12" height="12" alt="返回页首" border="0"></a></td>
	<td nowrap><font class=p2 face="<%= JiveGlobals.getJiveProperty("skin.default.buttonFontFace") %>">
        &nbsp;<a href="#top" title="返回页首">返回页首</a>
        </font>
    </td>
</tr>
</table>

    </td>
    <td width="1%" nowrap valign="top">
<%  if (threadIterator.hasNext()) {
        ForumThread nextThread = (ForumThread)threadIterator.next();
        String subj = nextThread.getRootMessage().getSubject();
%>
    <font class=p2 face="<%= JiveGlobals.getJiveProperty("skin.default.buttonFontFace") %>">
    <a href="thread.jsp?forum=<%= forumID %>&thread=<%= nextThread.getID() %>"
     title="<%= subj %>">下一主题</a>
    </font>
    <a href="thread.jsp?forum=<%= forumID %>&thread=<%= nextThread.getID() %>"
     title="<%= subj %>"><img src="images/next.gif" width="10" height="10" hspace="2" alt="Topic: <%= subj %>" border="0"></a>
<%  } else { %>
    &nbsp;
<%  } %>
    </td>
</tr>
</table>
<br>

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