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

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

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

<%  // Get the forumID and threadID parameters
    long forumID = ParamUtils.getLongParameter(request,"forum",-1L);
    long threadID = ParamUtils.getLongParameter(request,"thread",-1L);

    // Before any other code, check the "subject" and "body" parameters. If a
    // value is found in either, put it in the session.
    String subject = ParamUtils.getParameter(request, "subject", true);
    String body = ParamUtils.getParameter(request, "body", true);
    if (subject != null) {
        session.setAttribute("jive.message.subject."+forumID+"."+threadID, subject);
    }
    if (body != null) {
        session.setAttribute("jive.message.body."+forumID+"."+threadID, body);
    }
%>
<%  // Get parameters
    long messageID = ParamUtils.getLongParameter(request,"message",-1L);
    boolean reply = ParamUtils.getBooleanParameter(request,"reply");
    String postButton = ParamUtils.getParameter(request,"postButton");
    boolean post = "发新贴".equals(postButton);
    boolean edit = "回复/编辑".equals(postButton);
    String name = ParamUtils.getParameter(request, "name");
    String email = ParamUtils.getParameter(request, "email");

    if (post || edit) {
        // Redirect back to the post page
        StringBuffer buf = new StringBuffer("post.jsp?");
        buf.append("forum=").append(forumID);
        buf.append("&thread=").append(threadID);
        buf.append("&message=").append(messageID);
        buf.append("&fromPreview=true");
        buf.append("&reply=").append(reply);
        buf.append("&name=").append(name);
        buf.append("&email=").append(email);
        if (!isGuest) {
            buf.append("&isLoggedIn=").append(true);
        }
        if (post) {
            buf.append("&doPost=true");
        }
        response.sendRedirect(buf.toString());
        return;
    }

    // Get the subject and body from the session
    subject = (String)session.getAttribute("jive.post.subject."+forumID+"."+threadID);
    body = (String)session.getAttribute("jive.post.body."+forumID+"."+threadID);

    // Load the forum we're posting in.
    Forum forum = myEnv.getForumFactory().getForum(forumID);

    // Load a user manager
    UserManager userManager = myEnv.getForumFactory().getUserManager();

    ForumMessage newMessage = null;
    if (isGuest) {
        newMessage = myEnv.getForumFactory().createMessage();
    }
    else {
        newMessage = myEnv.getForumFactory().createMessage(pageUser);
    }
    newMessage.setSubject(subject);
    newMessage.setBody(body);
    // set message properties if this is a guest user
    if (isGuest) {
        if (name != null) { newMessage.setProperty("name", name); }
        if (email != null) { newMessage.setProperty("email", email); }
    }
    if (subject != null) {
        session.setAttribute("jive.message.subject."+forumID+"."+threadID,subject);
    }
    if (body != null) {
        session.setAttribute("jive.message.body."+forumID+"."+threadID,body);
    }
//    newMessage = applyFilters(forumFactory, forum, newMessage);

    FilterManager filterManager = myEnv.getForumFactory().getFilterManager();
    newMessage = filterManager.applyFilters(newMessage);
    filterManager = forum.getFilterManager();
    newMessage = filterManager.applyFilters(newMessage);
%>

<%  String title = "论坛 - 发信息到 " + forum.getName(); %>
<%@ include file="header.jsp" %>

<table cellpadding="0" ccellspacing="0" border="0" width="100%">
<tr>
    <td>
    <font face="<%= JiveGlobals.getJiveProperty("skin.default.fontFace") %>" color="<%= JiveGlobals.getJiveProperty("skin.default.linkColor") %>">
    <%  if (reply) { %>
        <b>回复 : 预览</b>
    <%  } else { %>
        <b>发新贴:预览</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>
    </td>
</tr>
</table>

<p>

<font class=p2 face="<%= JiveGlobals.getJiveProperty("skin.default.fontFace") %>">
下面是预览的发布信息，如果您要发布信息，您可以点击“发表”按钮，如果您想修改，请点击
“返回/修改”按钮。<br>
</font>
<p>

<script language="JavaScript" type="text/javascript">
<!--
var checked = false;
function checkPost() {
    if (!checked) {
        checked = true;
        return true;
    }
    return false;
}
//-->
</script>

<form action="preview.jsp" method="post" name="postForm" onsubmit="return checkPost();">
<input type="hidden" name="doPost" value="true">
<input type="hidden" name="reply" value="<%=reply%>">
<input type="hidden" name="forum" value="<%=forumID%>">
<input type="hidden" name="thread" value="<%=threadID%>">
<input type="hidden" name="message" value="<%=messageID%>">
<%  if (subject != null) { %>
<input type="hidden" name="subject" value="<%= URLEncoder.encode(subject) %>">
<%  } %>
<%  if (body != null) { %>
<input type="hidden" name="body" value="<%= URLEncoder.encode(body) %>">
<%  } %>
<%  if (name != null) { %>
<input type="hidden" name="name" value="<%= URLEncoder.encode(name) %>">
<%  } %>
<%  if (email != null) { %>
<input type="hidden" name="email" value="<%= URLEncoder.encode(email) %>">
<%  } %>

<%	User author = newMessage.getUser(); %>

<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="<%= JiveGlobals.getJiveProperty("skin.default.tableRowColor2") %>">
        <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") %>">
<%	    if (author == null) {
            // Check to see if there is an extended property for name & email
            // since the gateway feature imports names and emails as extended
            // props.
            String guestName = newMessage.getProperty("name");
            String guestEmail = newMessage.getProperty("email");
            String nameAndEmail = myEnv.du.getNameAndEmailDisplay(guestName, guestEmail);
            if (nameAndEmail != null) {
%>
            <i>客人: <%= nameAndEmail %></i>
<%          } else { %>
			<i>客人</i>
<%          }
        } else {
            String userStatus = author.getProperty("status");
%>
			<a href="profile.jsp?user=<%= author.getID() %>"
             ><b><%= author.getUsername() %></b></a>
            </font>

            <font class=p2 face="verdana,arial,sans-serif">
            <br><br>
            发表文章: <%= userManager.userMessageCount(author) %>
            <br>
            <%  String location = author.getProperty("location");
            if (location != null) { %>
            来　　自: <%= location %><br>
            <%  } %>
            注册时间: <%= myEnv.shortDateFormatter.format(author.getCreationDate()) %>
            <br><br>
<%      } %>
            </font>
            </td>
        </tr>
        </table>
        </td>
        <td width="97%">
        <font class=p2 face="<%= JiveGlobals.getJiveProperty("skin.default.fontFace") %>">
        <b><%= newMessage.getSubject() %></b>
        </font>
		</td>
        <td width="1%" nowrap>
        <font class=p2 face="<%= JiveGlobals.getJiveProperty("skin.default.fontFace") %>">
        发表时间: <%= SkinUtils.formatDate(request,response,pageUser,newMessage.getCreationDate()) %>
        </font>
        </td>

        <td width="1%" nowrap align="center">
            <table cellpadding="2" cellspacing="0" border="0">
            <tr>
                <td><img src="images/reply.gif" width="17" height="17" alt="Reply to this message" hspace="3" border="0"></td>
                <td>
                <font class=p2 face="<%= JiveGlobals.getJiveProperty("skin.default.fontFace") %>">
                <b>回复</b>
                </font>
                </td>
            </tr>
            </table>
        </td>
    </tr>
    <tr bgcolor="<%= JiveGlobals.getJiveProperty("skin.default.tableRowColor2") %>">
        <td width="99%" colspan="3" valign="top">
        <font class=p2 face="<%= JiveGlobals.getJiveProperty("skin.default.fontFace") %>">
        <%= newMessage.getBody() %>
        </font>
		<p>
        </td>
    </tr>
    </table>
</td></tr>
</table><br>

<input type="submit" value="回复/编辑" name="postButton">
<input type="submit" value="发新贴" name="postButton">
</form>

<br>

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