📄 forumperms.jsp
字号:
<%
/**
* $RCSfile: forumPerms.jsp,v $
* $Revision: 1.3.2.1 $
* $Date: 2001/02/09 20:38:41 $
*/
%>
<%@ page import="java.util.*,
java.net.URLEncoder,
com.coolservlets.forum.*,
com.coolservlets.forum.util.*,
com.coolservlets.forum.util.admin.*"%>
<jsp:useBean id="adminBean" scope="session"
class="com.coolservlets.forum.util.admin.AdminBean"/>
<%! ////////////////////////
// global page variables
private final int READ = ForumPermissions.READ;
private final int CREATE_THREAD = ForumPermissions.CREATE_THREAD;
private final int CREATE_MESSAGE = ForumPermissions.CREATE_MESSAGE;
private final int[] perms = { READ, CREATE_THREAD, CREATE_MESSAGE };
private final String[] permDescriptions = {
"浏览论坛内容","发表论坛论题","回复论坛帖子"
};
%>
<%! ///////////////////
// global methods
private int[] getIntListboxParams( String[] paramVal ) {
if( paramVal == null ) {
return new int[0];
}
int[] params = new int[paramVal.length];
for (int i=0;i<paramVal.length;i++)
{
try {
params[i] = Integer.parseInt(paramVal[i]);
} catch( NumberFormatException nfe ) {}
}
return params;
}
%>
<% ////////////////////////////////
// Jive authorization check
// check the bean for the existence of an authorization token.
// Its existence proves the user is valid. If it's not found, redirect
// to the login page
Authorization authToken = adminBean.getAuthToken();
if( authToken == null ) {
response.sendRedirect( "/mainctrl/bbs/admin" );
return;
}
%>
<% ////////////////////
// Security check
// make sure the user is authorized to administer users:
ForumFactory forumFactory = ForumFactory.getInstance(authToken);
ForumPermissions permissions = forumFactory.getPermissions(authToken);
boolean isSystemAdmin = permissions.get(ForumPermissions.SYSTEM_ADMIN);
boolean isForumAdmin = permissions.get(ForumPermissions.FORUM_ADMIN);
// redirect to error page if we're not a group admin or a system admin
if( !isForumAdmin && !isSystemAdmin ) {
request.setAttribute("message","您没有权限管理论坛!");
response.sendRedirect("error.jsp");
return;
}
%>
<% ////////////////////
// get parameters
int forumID = ParamUtils.getIntParameter(request,"forum",-1);
// action parameters
boolean doAddUserPerm = ParamUtils.getBooleanParameter(request,"doAddUserPerm");
boolean doAddGroupPerm = ParamUtils.getBooleanParameter(request,"doAddGroupPerm");
boolean doRemoveUserPerm = ParamUtils.getBooleanParameter(request,"doRemoveUserPerm");
boolean doRemoveGroupPerm = ParamUtils.getBooleanParameter(request,"doRemoveGroupPerm");
int permType = ParamUtils.getIntParameter(request,"permType",-1);
int[] usersWithPerm = getIntListboxParams(request.getParameterValues("usersWithPerm"));
int[] groupsWithPerm = getIntListboxParams(request.getParameterValues("groupsWithPerm"));
int[] userList = getIntListboxParams(request.getParameterValues("userList"));
String userAddUsername = request.getParameter("userListField");
int[] groupList = getIntListboxParams(request.getParameterValues("groupList"));
int[] userPermTypesList = getIntListboxParams(request.getParameterValues("userPermTypes"));
int[] groupPermTypesList = getIntListboxParams(request.getParameterValues("groupPermTypes"));
%>
<% /////////////////////
// other page variables
boolean doAction = (
doAddUserPerm || doAddGroupPerm || doRemoveUserPerm || doRemoveGroupPerm
);
%>
<% ///////////////////////
// error variables
boolean errors = false;
%>
<% //////////////////////////////////
// global variables
ProfileManager manager = forumFactory.getProfileManager();
%>
<% /////////////////////
// try to load the forum from the passed in forumID
Forum forum = null;
try {
forum = forumFactory.getForum(forumID);
}
catch( ForumNotFoundException fnfe ) {
response.sendRedirect("error.jsp?msg="
+ URLEncoder.encode("论坛 " + forumID + " 没有发现!") );
return;
}
catch( UnauthorizedException ue ) {
response.sendRedirect("error.jsp?msg="
+ URLEncoder.encode("您没有权限管理此论坛!"));
return;
}
%>
<% /////////////////////
// this forum's properties
String forumName = forum.getName();
String forumDescription = forum.getDescription();
Iterator allUsers = manager.users();
Iterator allGroups = manager.groups();
int[] usersWithReadPerm = new int[0];
int[] usersWithThreadPerm = new int[0];
int[] usersWithMessagePerm = new int[0];
int[] groupsWithReadPerm = new int[0];
int[] groupsWithThreadPerm = new int[0];
int[] groupsWithMessagePerm = new int[0];
try {
usersWithReadPerm = forum.usersWithPermission(READ);
usersWithThreadPerm = forum.usersWithPermission(CREATE_THREAD);
usersWithMessagePerm = forum.usersWithPermission(CREATE_MESSAGE);
groupsWithReadPerm = forum.groupsWithPermission(READ);
groupsWithThreadPerm = forum.groupsWithPermission(CREATE_THREAD);
groupsWithMessagePerm = forum.groupsWithPermission(CREATE_MESSAGE);
}
catch( UnauthorizedException ue ) {}
%>
<% /////////////////////////
// do an action!
if( doAction ) {
// add a new user permission
if( doAddUserPerm ) {
try {
for( int i=0; i<userList.length; i++ ) {
User user = manager.getUser(userList[i]);
for( int j=0; j<userPermTypesList.length; j++ ) {
forum.addUserPermission(user,userPermTypesList[j]);
}
}
} catch( UserNotFoundException unfe ) {
} catch( UnauthorizedException ue ) {
}
try {
if( !"-Enter Username-".equals(userAddUsername)
&& userAddUsername != null )
{
User user = manager.getUser(userAddUsername);
for( int j=0; j<userPermTypesList.length; j++ ) {
forum.addUserPermission(user,userPermTypesList[j]);
}
}
} catch( UserNotFoundException unfe ) {
} catch( UnauthorizedException ue ) {
}
}
// remove a user permission
if( doRemoveUserPerm ) {
try {
for( int i=0; i<usersWithPerm.length; i++ ) {
User user = manager.getUser(usersWithPerm[i]);
forum.removeUserPermission(user,permType);
}
} catch( UserNotFoundException unfe ) {
} catch( UnauthorizedException ue ) {
}
}
// add a new group permission
if( doAddGroupPerm ) {
try {
for( int i=0; i<groupList.length; i++ ) {
Group group = manager.getGroup(groupList[i]);
for( int j=0; j<groupPermTypesList.length; j++ ) {
forum.addGroupPermission(group,groupPermTypesList[j]);
}
}
} catch( GroupNotFoundException gnfe ) {
} catch( UnauthorizedException ue ) {
}
}
// remove a user permission
if( doRemoveGroupPerm ) {
try {
for( int i=0; i<groupsWithPerm.length; i++ ) {
Group group = manager.getGroup(groupsWithPerm[i]);
forum.removeGroupPermission(group,permType);
}
} catch( GroupNotFoundException gnfe ) {
} catch( UnauthorizedException ue ) {
}
}
}
%>
<% ////////////////////
// if we did something, redirect to this page again (since we're doing POSTS
// on the form)
// uncommented so i can debug parameters!!
if( doAction ) {
response.sendRedirect("forumPerms.jsp?forum="+forumID);
return;
}
%>
<html>
<head>
<title></title>
<link rel="stylesheet" href="style/global.css">
<script language="JavaScript" type="text/javascript">
<!--
function selAllListBox( el, chkbx ) {
if( chkbx.checked ) {
for( var i=0; i<el.options.length; i++ ) {
el.options[i].selected = true;
}
}
}
//-->
</script>
</head>
<body background="images/shadowBack.gif" bgcolor="#ffffff" text="#000000" link="#0000ff" vlink="#800080" alink="#ff0000">
<% ///////////////////////
// pageTitleInfo variable (used by include/pageTitle.jsp)
String[] pageTitleInfo = { "论坛: 论坛许可" };
%>
<% ///////////////////
// pageTitle include
%><%@ include file="include/pageTitle.jsp" %>
<p>
<b>此论坛的许可状况:</b>
<%= forumName %>
<p>
<%-- Permissions summary table --%>
<table bgcolor="#666666" cellpadding="0" cellspacing="0" width="80%" align="center" border="0">
<td>
<table bgcolor="#666666" cellpadding="3" cellspacing="1" width="100%" border="0">
<tr bgcolor="#eeeeee">
<td>
许可列表
</td>
</tr>
<tr bgcolor="#ffffff">
<td>
<table cellpadding="3" cellspacing="0" width="100%" border="0">
<td>
<br>
<%-- user permission summary --%>
用户 在此论坛中的许可详细情况:
<p>
<table cellpadding="3" cellspacing="0" border="0" align="center">
<tr>
<form action="forumPerms.jsp">
<input type="hidden" name="forum" value="<%= forumID %>">
<input type="hidden" name="doRemoveUserPerm" value="true">
<input type="hidden" name="permType" value="<%= READ %>">
<td align="center">
<b><%= usersWithReadPerm.length %></b>
拥有<font color="#008000">论坛浏览</font>许可:
<br>
<select size="5" name="usersWithPerm" multiple>
<% for( int i=0; i<usersWithReadPerm.length; i++ ) { %>
<% try { %>
<% User user = manager.getUser(usersWithReadPerm[i]); %>
<% int userID = user.getID(); %>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -