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

<%@ 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="include/global.jsp" %>
 
<%	// Get parameters
	long forumID = ParamUtils.getLongParameter(request,"forum",-1L);
	long threadID = ParamUtils.getLongParameter(request,"thread",-1L);
	boolean deleteThread = ParamUtils.getBooleanParameter(request,"deleteThread");
	int start = ParamUtils.getIntParameter(request,"start",START);
	int range = ParamUtils.getIntParameter(request,"range",RANGE);
    
    // if the start isn't passed in as a parameter, look for it in the session
    if (request.getParameter("start") == null) {
        try {
            start = Integer.parseInt((String)session.getAttribute("admin.forumContent.start"));
        } catch (Exception e) {}
    }
    else {
        session.setAttribute("admin.forumContent.start",start+"");
    }
    
    // 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);
    }
    
    // An iterator of threads in this forum
    ResultFilter filter = new ResultFilter();
    filter.setStartIndex(start);
    filter.setNumResults(range);
    Iterator threads = forum.threads(filter);
    
    // Number of threads in the iterator
    int threadCount = forum.getThreadCount(filter);
    
    // Get a user manager to get user objects
	UserManager manager = forumFactory.getUserManager();
    
    // Delete a thread if necessary
	if (deleteThread) {
		forum.deleteThread(thread);
        // Indicate that the thread was deleted successfully
        setOneTimeMessage(session, "message", "Thread deleted");
		response.sendRedirect("forumContent.jsp?forum="+forumID);
		return;
	}
%>

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

<p>

<%  // Title of this page and breadcrumbs
    String title = "Manage Content";
    String[][] breadcrumbs = {
        {"Main", "main.jsp"},
        {"Forums", "forums.jsp"},
        {"Edit Forum", "editForum.jsp?forum="+forumID},
        {"Manage Content", "forumContent.jsp?forum="+forumID}
    };
%>
<%@ include file="include/title.jsp" %>

<font size="-1">
<%= threadCount %> total threads (<%= range %> displayed per page).
</font>

<p>

<table bgcolor="<%= tableBorderColor %>" cellpadding="0" cellspacing="0" border="0" width="100%">
<tr><td>
<table bgcolor="<%= tableBorderColor %>" cellpadding="3" cellspacing="1" border="0" width="100%">
<tr bgcolor="#eeeeee">
    <td align="center"><font size="-2" face="verdana"><b>THREAD</b></font></td>
    <td align="center"><font size="-2" face="verdana"><b>REPLIES</b></font></td>
    <td align="center"><font size="-2" face="verdana"><b>AUTHOR</b></font></td>
    <td align="center"><font size="-2" face="verdana"><b>LAST MODIFIED</b></font></td>
    <td align="center"><font size="-2" face="verdana"><b>EDIT</b></font></td>
    <td align="center"><font size="-2" face="verdana"><b>DELETE</b></font></td>
</tr>
<%  while (threads.hasNext()) {
        ForumThread theThread = (ForumThread)threads.next();
        User author = theThread.getRootMessage().getUser();
%>
<tr bgcolor="#ffffff">
    <td><font size="-1"><b><a href="forumContent_thread.jsp?forum=<%=forumID%>&thread=<%= theThread.getID() %>"><%= theThread.getName() %></a></b></font></td>
    <td align="center"><font size="-1"><%= theThread.getMessageCount()-1 %></font></td>
    <td>
    <%  if (author != null) { %>
        <font size="-1"><%= author.getUsername() %></font>
    <%  } else { %>
        <font size="-1"><i>Guest</i></font>
    <%  } %>
    </td>
    <td nowrap><font size="-1"><%= JiveGlobals.formatDateTime(theThread.getModifiedDate()) %></font></td>
    <td align="center"><a href="forumContent_thread.jsp?forum=<%=forumID%>&thread=<%= theThread.getID() %>"><img src="images/button_edit.gif" width="17" height="17" alt="Edit the content of this thread..." border="0"></a></td>
    <td align="center"><a href="forumContent_delete.jsp?forum=<%= forumID %>&thread=<%= theThread.getID() %>"><img src="images/button_delete.gif" width="17" height="17" alt="Delete this thread..." border="0"></a></td>
</tr>
<%  } %>
</table>
</td></tr>
</table>

<p>

<table cellpadding="0" cellspacing="0" border="0" width="100%">
<tr>
<%  if (start > 0) { %>
	<td width="1%" nowrap><font size="-1"><a href="forumContent.jsp?forum=<%= forumID %>&start=<%= start-range %>">Previous <%= range %> threads</a></font></td>
<%  } else { %>
	<td width="1%" nowrap><font size="-1">&nbsp;</font></td>
<%  } %>

<%  if (start > 0) { %>
	<td width="98%" align="center"><font size="-1"><a href="forumContent.jsp?forum=<%= forumID %>&start=0">Front Page</a></font></td>
<%  } else { %>
	<td width="98%" nowrap><font size="-1">&nbsp;</font></td>
<%  } %>

<%  if (start+range < threadCount) { %>
	<td width="1%" nowrap><font size="-1"><a href="forumContent.jsp?forum=<%= forumID %>&start=<%= start+range %>">Next <%= range %> threads</a></font></td>
<%  } else { %>
	<td width="1%" nowrap><font size="-1">&nbsp;</font></td>
<%  } %>
</tr>
</table>

<p>

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