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

<%
/**
 *	$RCSfile: forumContent_delete.jsp,v $
 *	$Revision: 1.1.1.1 $
 *	$Date: 2002/09/09 13:50:12 $
 */
%>

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

<%!	// Global variables, methods, etc

    // default range & starting point for the thread iterators
	private final static int RANGE = 15;
	private final static int START = 0;
%>

<%@ 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);
	boolean doDelete = ParamUtils.getBooleanParameter(request,"doDelete");
    String submitButton = ParamUtils.getParameter(request,"submitButton");

    // Load the forum we're working with
    Forum forum = forumFactory.getForum(forumID);

    // Optionally load the thread we're working with
    ForumThread thread = null;
    if (threadID != -1L) {
        thread = forum.getThread(threadID);
    }

    // Optionally load the message we're working with
    ForumMessage message = null;
    if (messageID != -1L && thread != null) {
        message = thread.getMessage(messageID);
    }

    // variables to indicate what this page does
    boolean deleteThread = false;
    if (thread != null) {
        if (message == null) {
            deleteThread = true;
        }
        else {
            if (thread.getRootMessage().getID() == message.getID()) {
                deleteThread = true;
            }
        }
    }

    // Cancel if requested
    if ("取消".equals(submitButton)) {
        if (deleteThread) {
            response.sendRedirect("forumContent.jsp?forum="+forumID);
            return;
        } else {
            response.sendRedirect("forumContent_thread.jsp?forum="+forumID+"&thread="+threadID);
            return;
        }
    }

    // Delete a thread if necessary
	if (doDelete) {
        if (deleteThread) {
		    forum.deleteThread(thread);
        }
        else {
            thread.deleteMessage(message);
        }
        // Indicate that the thread was deleted successfully
        if (deleteThread) {
            setOneTimeMessage(session, "message", "主题被删除");
        }
        else {
            setOneTimeMessage(session, "message", "消息被删除");
        }
        if (deleteThread) {
		    response.sendRedirect("forumContent.jsp?forum="+forumID);
		    return;
        } else {
		    response.sendRedirect("forumContent_thread.jsp?forum="+forumID+"&thread="+threadID);
		    return;
        }
	}
%>

<%  // special onload command to load the sidebar
    onload = " onload=\"parent.frames['sidebar'].location.href='sidebar.jsp?sidebar=forum';\"";
%>
<%@ include file="header.jsp" %>

<p>

<%  // Title of this page and breadcrumbs
    String title = null;
    if (deleteThread) {
        title = "删除";
    }
    else { // delete message
        title = "删除消息";
    }
    String[][] breadcrumbs = {
        {"主页面", "main.jsp"},
        {"论坛", "forums.jsp"},
        {"编辑论坛", "editForum.jsp?forum="+forumID},
        {"内容管理", "forumContent.jsp?forum="+forumID},
        {title, "forumContent_delete.jsp?forum="+forumID+"&thread="+threadID+"&message="+messageID}
    };
%>
<%@ include file="title.jsp" %>

<font size="-1">
<%  if (deleteThread) { %>
警告! 你正试图删除一个主题及其回复！
<%  } else { %>
警告! 你正试图删除一个消息及其回复！
<%  } %>
</font>

<p>

<form action="forumContent_delete.jsp">
<input type="hidden" name="doDelete" value="true">
<input type="hidden" name="forum" value="<%= forumID %>">
<input type="hidden" name="thread" value="<%= threadID %>">
<input type="hidden" name="message" value="<%= messageID %>">

<%  if (deleteThread) {
        User author = thread.getRootMessage().getUser();
%>
<font size="-1">
你确定要删除下面的主题？
<p>
<table bgcolor="<%= tblBorderColor %>" cellpadding="0" cellspacing="0" border="0" width="100%">
<tr><td>
<table bgcolor="<%= tblBorderColor %>" cellpadding="3" cellspacing="1" border="0" width="100%">
<tr bgcolor="#eeeeee">
    <td align="center"><font size="-2" face="verdana"><b>主题</b></font></td>
    <td align="center"><font size="-2" face="verdana"><b>回复数</b></font></td>
    <td align="center"><font size="-2" face="verdana"><b>作者</b></font></td>
    <td align="center"><font size="-2" face="verdana"><b>创建日期</b></font></td>
    <td align="center"><font size="-2" face="verdana"><b>修改日期</b></font></td>
</tr>
<tr bgcolor="#ffffff">
    <td width="96%"><font size="-1"><%= thread.getName() %></font></td>
    <td align="center" width="1%" nowrap><font size="-1"><%= thread.getMessageCount()-1 %></font></td>
    <td align="center" width="1%" nowrap>
    <%  if (author != null) { %>
        <font size="-1"><%= author.getUsername() %></font>
    <%  } else { %>
        <font size="-1"><i>来客</i></font>
    <%  } %>
    </td>
    <td align="center" width="1%" nowrap><font size="-1">&nbsp;<%= JiveGlobals.formatDate(thread.getCreationDate()) %>&nbsp;</font></td>
    <td align="center" width="1%" nowrap><font size="-1">&nbsp;<%= JiveGlobals.formatDate(thread.getModifiedDate()) %>&nbsp;</font></td>
</tr>
</table>
</td></tr>
</table>
<p>
<center>
<input type="submit" name="submitButton" value="删除">
<input type="submit" name="submitButton" value="取消">
</center>
</font>
<%  } else {
        User author = message.getUser();
        TreeWalker treeWalker = thread.treeWalker();
%>
<font size="-1">
你确定删除下面的消息及其回复？
<p>
<table bgcolor="<%= tblBorderColor %>" cellpadding="0" cellspacing="0" border="0" width="100%">
<tr><td>
<table bgcolor="<%= tblBorderColor %>" cellpadding="3" cellspacing="1" border="0" width="100%">
<tr bgcolor="#eeeeee">
    <td align="center"><font size="-2" face="verdana"><b>主题</b></font></td>
    <td align="center"><font size="-2" face="verdana"><b>回复数</b></font></td>
    <td align="center"><font size="-2" face="verdana"><b>作者</b></font></td>
    <td align="center"><font size="-2" face="verdana"><b>创建日期</b></font></td>
    <td align="center"><font size="-2" face="verdana"><b>修改日期</b></font></td>
</tr>
<tr bgcolor="#ffffff">
    <td width="96%"><font size="-1"><%= message.getSubject() %></font></td>
    <td align="center" width="1%" nowrap><font size="-1"><%= treeWalker.getRecursiveChildCount(message) %></font></td>
    <td align="center" width="1%" nowrap>
    <%  if (author != null) { %>
        <font size="-1"><%= author.getUsername() %></font>
    <%  } else { %>
        <font size="-1"><i>Guest</i></font>
    <%  } %>
    </td>
    <td align="center" width="1%" nowrap><font size="-1">&nbsp;<%= JiveGlobals.formatDate(message.getCreationDate()) %>&nbsp;</font></td>
    <td align="center" width="1%" nowrap><font size="-1">&nbsp;<%= JiveGlobals.formatDate(message.getModifiedDate()) %>&nbsp;</font></td>
</tr>
<tr bgcolor="#ffffff">
    <td colspan="5"><font size="-1"><%= message.getBody() %></font></td>
</tr>
</table>
</td></tr>
</table>
<p>
<center>
<input type="submit" name="submitButton" value="删除">
<input type="submit" name="submitButton" value="取消">
</center>
</font>
<%  } %>
</form>

<p>

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