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

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

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

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

<%! // Global variables, methods, etc

    // Permission presets
    static final int USE_GLOBAL_PERMS = 1;
    static final int ALL_ACCESS = 2;
    static final int USERS_ONLY = 3;
    static final int USERS_AND_ANON_READ = 4;

    static final int DEFAULT_PERM_PRESET = USE_GLOBAL_PERMS;

    static final int[] PERM_PRESETS = {
        USE_GLOBAL_PERMS,
        USERS_ONLY,
        USERS_AND_ANON_READ,
        ALL_ACCESS
    };

    static final String[][] PERM_PRESET_INFO = {
        {"使用全局权限","对此论坛使用全局权限设置。"},
        {"注册用户","只有注册用户可以阅读和发表消息。"},
        {"注册用户，来客可读","来客只能阅读，注册用户可以阅读和发布消息。"},
        {"无限制","任何人都可以阅读和发布消息。"}
    };
%>

<%	// Get parameters
    String submitButton = ParamUtils.getParameter(request,"submitButton");
	boolean doCreate = ParamUtils.getBooleanParameter(request,"doCreate");
	String name = ParamUtils.getParameter(request,"name");
	String description = ParamUtils.getParameter(request,"description");
    int permPreset = ParamUtils.getIntParameter(request,"permPreset",DEFAULT_PERM_PRESET);
    // Remove the forum in the session (if we come to this page, the sidebar
    // shouldn't show the specific forum options).
    session.removeAttribute("admin.sidebar.forums.currentForum");

    // Cancel, if requested
    if ("取消".equals(submitButton)) {
        response.sendRedirect("forums.jsp");
        return;
    }

	// Check for errors
	boolean errors = false;
    if (doCreate) {
        if (name == null) {
            errors = true;
        }
    }

    // Create a forum if requested
	if (doCreate && !errors) {
	    ////
		////System.out.println("**DEBUG**"+name+","+ description);
		Forum forum = forumFactory.createForum(name, description);

        // Get a permissions manager so we can set permissions below
        PermissionsManager permManager = forum.getPermissionsManager();

        // set permissions
        switch (permPreset) {
            case USE_GLOBAL_PERMS:
                // do nothing -- global permission are used by default
                break;
            case USERS_ONLY:
                permManager.addRegisteredUserPermission(ForumPermissions.READ);
                permManager.addRegisteredUserPermission(ForumPermissions.CREATE_THREAD);
                permManager.addRegisteredUserPermission(ForumPermissions.CREATE_MESSAGE);
                break;
            case USERS_AND_ANON_READ:
                permManager.addRegisteredUserPermission(ForumPermissions.READ);
                permManager.addRegisteredUserPermission(ForumPermissions.CREATE_THREAD);
                permManager.addRegisteredUserPermission(ForumPermissions.CREATE_MESSAGE);
                permManager.addAnonymousUserPermission(ForumPermissions.READ);
                break;
            case ALL_ACCESS:
                permManager.addRegisteredUserPermission(ForumPermissions.READ);
                permManager.addRegisteredUserPermission(ForumPermissions.CREATE_THREAD);
                permManager.addRegisteredUserPermission(ForumPermissions.CREATE_MESSAGE);
                permManager.addAnonymousUserPermission(ForumPermissions.READ);
                permManager.addAnonymousUserPermission(ForumPermissions.CREATE_THREAD);
                permManager.addAnonymousUserPermission(ForumPermissions.CREATE_MESSAGE);
                break;
            default:
        }

        // redirect back to the forums page
        response.sendRedirect("forums.jsp");
        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 = "创建新论坛";
    String[][] breadcrumbs = {
        {"主页面", "main.jsp"},
        {"论坛", "forums.jsp"},
        {title, "createForum.jsp"}
    };
%>
<%@ include file="title.jsp" %>

<font size="-1">
注意：这将创建一个没有权限的论坛。创建完成后，你将被带到论坛权限设置页面。
</font>

<p>

<%	// error messages
	if(errors) {
%>
    <font color="<%= errorColor %>" size="-1">
    论坛创建错误。请确认你输入了论坛名！
    </font>
    <p>
<%	} %>

<form action="createForum.jsp" method="post" name="createForm">
<input type="hidden" name="doCreate" value="true">

<font size="-1"><b>论坛名</b></font>
<ul>
    <input type="text" name="name" size="40" maxlength="100" value="<%= (name!=null)?name:"" %>">
</ul>

<font size="-1"><b>论坛描述</b> (可选)</font>
<ul>
    <textarea name="description" cols="40" rows="5" wrap="virtual"><%= (description!=null)?description:"" %></textarea>
</ul>

<font size="-1"><b>论坛权限先期设置</b></font>
<ul>
    <font size="-1">
    要获得更好的权限控制(包括用户组设置)，请查看权限设置页面。
    <p>
    </font>
    <table cellpadding="3" cellspacing="0" border="0">
<%  for (int i=0; i<PERM_PRESETS.length; i++) {
        String checked = "";
        if (PERM_PRESETS[i] == permPreset) {
            checked = " checked";
        }
%>
    <tr>
    	<td valign="top"><input type="radio" name="permPreset" value="<%= PERM_PRESETS[i] %>" id="rb<%= i %>"<%= checked %>></td>
    	<td><font size="-1"><label for="rb<%= i %>">
            <b><%= PERM_PRESET_INFO[i][0] %></b>
            --
            <%= PERM_PRESET_INFO[i][1] %>
            </label></font>
        </td>
    </tr>
<%  } %>
    </table>
</ul>

<input type="submit" name="submitButton" value="创建论坛">
<input type="submit" name="submitButton" value="取消">
</form>

<script language="JavaScript" type="text/javascript">
<!--
document.createForm.name.focus();
//-->
</script>

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