<%@ page contentType="text/html;charset=GBK" %>
<%
/**
 *	$RCSfile: editUser.jsp,v $
 *	$Revision: 1.1.1.1 $
 *	$Date: 2002/09/09 13:50:11 $
 */
%>

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

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

<%	// get parameters

	boolean save = ParamUtils.getBooleanParameter(request,"save");
	String username = ParamUtils.getParameter(request,"user");
    long userID = ParamUtils.getLongParameter(request,"user",-1L);
	String name = ParamUtils.getParameter(request,"name",true);
	String email = ParamUtils.getParameter(request,"email");
	boolean isNameVisible = ParamUtils.getBooleanParameter(request,"isNameVisible");
	boolean isEmailVisible = ParamUtils.getBooleanParameter(request,"isEmailVisible");
	String password = ParamUtils.getParameter(request,"password");
	String confirmPassword = ParamUtils.getParameter(request,"confirmPassword");
    boolean changePassword = ParamUtils.getBooleanParameter(request,"changePassword");

    // Get a user manager to get and set user properties
	UserManager userManager = forumFactory.getUserManager();

    // Load the user
    User user = userManager.getUser(userID);

    // Put the forum in the session (is needed by the sidebar)
    session.setAttribute("admin.sidebar.users.currentUserID", ""+userID);

    // Do error checking
	boolean errors = false;
    String errorMessage = "";
    if (save && email == null) {
        errors = true;
        errorMessage = "Email字段不能为空。";
    }

    // save user changes if necessary
	if (!errors && save) {
		if (name != null) {
			user.setName(name);
		}
        user.setEmail(email);
		user.setNameVisible(isNameVisible);
		user.setEmailVisible(isEmailVisible);

		// done, so redirect
		response.sendRedirect("editUser.jsp?user="+userID);
		return;
	}

    // check for password errors
    if (changePassword) {
        if (password == null) {
            errors = true;
        }
        if (confirmPassword == null) {
            errors = true;
        }
        if (!errors && !password.equals(confirmPassword)) {
            errors = true;
        }
        if (errors) {
            errorMessage = "无效的新口令";
        }
        else {
            // no errors, so set new password
            user.setPassword(password);
            // done, so set a success message, then redirect
            setOneTimeMessage(session,"admin.users.message","口令修改成功");
            response.sendRedirect("editUser.jsp?user="+userID);
            return;
        }
    }

    // user properties
    username = user.getUsername();
	name = user.getName();
	email = user.getEmail();
	isNameVisible = user.isNameVisible();
	isEmailVisible = user.isEmailVisible();

    // Extended user properties
	Iterator userProperties = user.propertyNames();
%>

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

<p>

<%  // Title of this page and breadcrumbs
    String title = "编辑用户属性";
    String[][] breadcrumbs = {
        {"主页面", "main.jsp"},
        {"用户概览", "users.jsp"},
        {title, "editUser.jsp?user="+userID}
    };
%>
<%@ include file="title.jsp" %>

<font size="-1">
设置以下用户的属性。
</font>

<p>

<%  if (errors) { %>
    <font size="-1"><i><%= errorMessage %></i></font>
    <p>
<%  } %>

<%  String message = getOneTimeMessage(session,"admin.users.message");
    if (message != null) {
%>
    <font size="-1"><i><%= message %></i></font>
<%  }
%>

<form action="editUser.jsp">
<input type="hidden" name="save" value="true">
<input type="hidden" name="user" value="<%= userID %>">

<font size="-1"><b>编辑用户属性</b></font><p>
<ul>
    <table cellpadding="3" cellspacing="0" border="0">
    <tr>
    	<td><font size="-1">用户ID:</font></td>
    	<td><font size="-1"><%= userID %></font></td>
    </tr>
    <tr>
    	<td><font size="-1">用户名:</font></td>
    	<td><font size="-1"><%= username %></font></td>
    </tr>
    <tr>
    	<td><font size="-1">姓名:</font></td>
    	<td>
    		<input type="text" name="name" value="<%= (name!=null)?name:"" %>">
    	</td>
    </tr>
    <tr>
    	<td><font size="-1">Email:</font></td>
    	<td>
    		<input type="text" name="email" value="<%= (email!=null)?email:"" %>">
    	</td>
    </tr>
    <tr>
    	<td><font size="-1">公开姓名:</font></td>
    	<td>
    		<input type="radio" name="isNameVisible" value="true" id="rb01"<%= isNameVisible?" checked":"" %>>
    		<label for="rb01"><font size="-1">是</font></label>
            &nbsp;
    		<input type="radio" name="isNameVisible" value="false" id="rb02"<%= !isNameVisible?" checked":"" %>>
    		<label for="rb02"><font size="-1">否</font></label>
    	</td>
    </tr>
    <tr>
    	<td><font size="-1">公开Email:</font></td>
    	<td>
    		<input type="radio" name="isEmailVisible" value="true" id="rb03"<%= isEmailVisible?" checked":"" %>>
    		<label for="rb03"><font size="-1">是</font></label>
            &nbsp;
    		<input type="radio" name="isEmailVisible" value="false" id="rb04"<%= !isEmailVisible?" checked":"" %>>
    		<label for="rb04"><font size="-1">否</font></label>
    	</td>
    </tr>
    <tr>
    	<td colspan="2"><br><input type="submit" value="保存设置"></td>
    </tr>
    </table>
</ul>
</form>

<form action="editUser.jsp" method="post">
<input type="hidden" name="user" value="<%= userID %>">
<input type="hidden" name="changePassword" value="true">
<font size="-1"><b>修改用户口令</b></font><p>
<ul>
    <table cellpadding="3" cellspacing="0" border="0">
    <tr>
    	<td><font size="-1">新口令:</font></td>
    	<td><input type="password" name="password" size="20" maxlength="30"></td>
    </tr>
    <tr>
    	<td><font size="-1">口令确认:</font></td>
    	<td><input type="password" name="confirmPassword" size="20" maxlength="30"></td>
    </tr>
    <tr>
    	<td colspan="2"><br><input type="submit" value="修改口令"></td>
    </tr>
    </table>
</ul>
</form>

<font size="-1"><b>其它属性</b></font><p>
<ul>

<table bgcolor="<%= tblBorderColor %>" cellpadding="0" cellspacing="0" border="0">
<td>
<table bgcolor="<%= tblBorderColor %>" cellpadding="3" cellspacing="1" border="0" width="100%">
<%	if (!userProperties.hasNext()) { %>
<tr bgcolor="#ffffff">
	<td align="center"><font size="-1"><i>没有其它属性</i></font></td>
</tr>
<%	}
    else {
%>
    <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>
    </tr>
<%  }
    while (userProperties.hasNext()) {
		String propName = (String)userProperties.next();
		String propValue = user.getProperty(propName);
%>
<tr bgcolor="#ffffff">
	<td><font size="-1"><%= propName %></font></td>
	<td><font size="-1"><%= propValue %></font></td>
</tr>
<%	} %>
</table></td></table>
</ul>

<p>

</body>
</html>
