<%@ page contentType="text/html;charset=GBK" %>
<%
/**
 *	$RCSfile: settings.jsp,v $
 *	$Revision: 1.4 $
 *	$Date: 2002/10/08 14:16:27 $
 */
%>

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

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

<%! private static Locale[] locales = Locale.getAvailableLocales();
%>

<%
   int DEFAULT_THREAD_RANGE = 15;
  // default number of messages to show
   int DEFAULT_MESSAGE_RANGE = 15;

   int[] THREAD_RANGES = {15, 30, 50, 100};
   // possible values for message ranges
    int[] MESSAGE_RANGES = {5, 15, 30, 50, 100};

   // Timezones
   String[][] timeZones = SkinUtils.getTimeZoneList();


// Parameters
    //签名
	String signature = ParamUtils.getParameter(request,"signature");
    long userID = ParamUtils.getLongParameter(request,"user",-1L);
    String username = ParamUtils.getParameter(request,"user");
	String referer = ParamUtils.getParameter(request,"referer");
	boolean save = ParamUtils.getBooleanParameter(request,"doSave");
	String saveButton = ParamUtils.getParameter(request,"saveButton");
	String localeCode = ParamUtils.getParameter(request,"locale");
	String timeZoneID = ParamUtils.getParameter(request,"timeZone");
	int threadRange = ParamUtils.getIntParameter(request,"threadRange",DEFAULT_THREAD_RANGE);
	int messageRange = ParamUtils.getIntParameter(request,"messageRange",DEFAULT_MESSAGE_RANGE);
	String name = ParamUtils.getParameter(request,"name");
	String email = ParamUtils.getParameter(request,"email");
	String occupation = ParamUtils.getParameter(request,"occupation",true);
	String location = ParamUtils.getParameter(request,"location",true);
	String homepage =  ParamUtils.getParameter(request,"homepage",true);
	String icon =  ParamUtils.getParameter(request,"icon",true);
	boolean nameVisible = ParamUtils.getBooleanParameter(request,"nameVisible");
	boolean emailVisible = ParamUtils.getBooleanParameter(request,"emailVisible");
    // Watch params
    boolean autoAddEmailWatch = ParamUtils.getBooleanParameter(request,"autoAddEmailWatch");
    boolean autoWatchNewTopics = ParamUtils.getBooleanParameter(request,"autoWatchNewTopics");
    boolean autoWatchReplies = ParamUtils.getBooleanParameter(request,"autoWatchReplies");

    // Try to load a user (try by userID first, then try username)
    UserManager userManager = myEnv.getForumFactory().getUserManager();
    User user = null;
    try {
        user = userManager.getUser(userID);
    }
    catch (UserNotFoundException unfe) {
        try {
            user = userManager.getUser(username);
        }
        catch (UserNotFoundException ignored) {}
    }

    // Get the default locale
    Locale locale = JiveGlobals.getLocale();

	// Setup the correct values for the referer
	if ("取 消".equals(saveButton) && referer == null) {
		referer = "index.jsp";
	}
	else if (referer == null) {
		referer = request.getHeader("REFERER");
	}
    if ("取 消".equals(saveButton)) {
        response.sendRedirect(referer);
        return;
    }

	// Security check: make sure the user using this page is the same as the
	// loaded user. If they're different, set user=null so the rest of the
    // page will think that we're working with a guest user.
	if ((user != null) && (pageUser != null) && (user.getID() != pageUser.getID())) {
		user = null;
		isGuest = true;
	}

	// save user settings
	if (save) {
		// Save user settings
		if (user != null) {
            // Save the thread range, message range and timezone
			if (threadRange > -1) {
				user.setProperty("jiveThreadRange",new Integer(threadRange).toString());
			}
			if (messageRange > -1) {
				user.setProperty("jiveMessageRange",new Integer(messageRange).toString());
			}
			if (timeZoneID != null) {
				user.setProperty("jiveTimeZoneID",timeZoneID);
			}
			//保存签名
			if (signature != null) {
				user.setProperty("jiveUserSignature",signature);
			}
			// Save all other user profile properties (for users only)
			if (name != null) {
				user.setName(name);
			}
			if (email != null) {
				user.setEmail(email);
			}
            if (occupation != null && occupation.equals("")) {
                user.deleteProperty("jiveOccupation");
            } else if (occupation != null) {
				user.setProperty("jiveOccupation",occupation);
			}
            if (location != null && location.equals("")) {
                user.deleteProperty("jiveLocation");
            } else if (location != null) {
				user.setProperty("jiveLocation",location);
			}
            if (homepage != null && homepage.equals("")) {
                user.deleteProperty("jiveHomepage");
            } else if (homepage != null) {
				user.setProperty("jiveHomepage",homepage);
			}
            if (icon != null && icon.equals("")) {
                user.deleteProperty("jiveIcon");
            } else if (icon != null) {
				user.setProperty("jiveIcon",icon);
			}
			user.setNameVisible(nameVisible);
			user.setEmailVisible(emailVisible);
            // set watch settings
            user.setProperty("jiveAutoAddEmailWatch", ""+autoAddEmailWatch);
            user.setProperty("jiveAutoWatchNewTopics", ""+autoWatchNewTopics);
            user.setProperty("jiveAutoWatchReplies", ""+autoWatchReplies);
		}
        // Save guest settings
		else {
			if (threadRange > -1) {
				SkinUtils.store(request,response,"jiveThreadRange",
					new Integer(threadRange).toString(),60*60*24*30);
			}
			if (messageRange > -1) {
				SkinUtils.store(request,response,"jiveMessageRange",
					new Integer(messageRange).toString(),60*60*24*30);
			}
			if (timeZoneID != null) {
				SkinUtils.store(request,response,"jiveTimeZoneID",timeZoneID,60*60*24*30);
			}
		}
		// Redirect to the appropriate page:
		String redirectURL = null;
		if (referer != null) {
			redirectURL = "settings.jsp?referer=" + java.net.URLEncoder.encode(referer);
		}
		if ("保存/返回".equals(saveButton)) {
			redirectURL = referer;
		}
		else if ("取 消".equals(saveButton) && referer == null) {
			redirectURL = "index.jsp";
		}
		else if ("取 消".equals(saveButton) && referer != null) {
			redirectURL = referer;
		}
		else {
			if (user != null) {
				redirectURL += "&user=" + user.getID();
			}
		}
        response.sendRedirect(redirectURL);
        return;
	} // end save
%>

<%  String title = "论坛 - 用户参数设置"; %>
<%@ include file="header.jsp" %>

<%	// Getting to this point means there were no user settings to save, so
	// we should load up settings from the user object or from the session
	// (in the case of a guest)

    // User settings
	if (user != null) {
		try {
            threadRange = Integer.parseInt(user.getProperty("jiveThreadRange"));
        } catch (Exception e) {}
		try {
            messageRange = Integer.parseInt(user.getProperty("jiveMessageRange"));
        } catch (Exception e) {}
		timeZoneID = user.getProperty("jiveTimeZoneID");
		// load up other user profile properties
		String nameProp = user.getName();
		if (nameProp != null) {
			name = nameProp;
		}
		String emailProp = user.getEmail();
		if (emailProp != null) {
			email = emailProp;
		}
		String occupationProp = user.getProperty("jiveOccupation");
		if (occupationProp != null) {
			occupation = occupationProp;
		}
		String locationProp = user.getProperty("jiveLocation");
		if (locationProp != null) {
			location = locationProp;
		}
		String homepageProp = user.getProperty("jiveHomepage");
		if (homepageProp != null) {
			homepage = homepageProp;
		}
		String iconProp = user.getProperty("jiveIcon");
		if (iconProp != null) {
			icon = iconProp;
		}
		nameVisible = user.isNameVisible();
		emailVisible = user.isEmailVisible();
        autoAddEmailWatch = "true".equals(user.getProperty("jiveAutoAddEmailWatch"));
        autoWatchNewTopics = "true".equals(user.getProperty("jiveAutoWatchNewTopics"));
        autoWatchReplies = "true".equals(user.getProperty("jiveAutoWatchReplies"));
	}
    // Guest settings
	else if (isGuest) {
		try {
			threadRange = Integer.parseInt(
				SkinUtils.retrieve(request,response,"jiveThreadRange").trim()
			);
		} catch (Exception e) {}
		try {
			messageRange = Integer.parseInt(
				SkinUtils.retrieve(request,response,"jiveMessageRange").trim()
			);
		} catch (Exception e) {}
		timeZoneID = SkinUtils.retrieve(request,response,"jiveTimeZoneID");
	}
	// one more check for the timezone -- if the code is null, that means no
	// value was retrieved, so set it to the default:
	if (timeZoneID == null) {
		timeZoneID = JiveGlobals.getTimeZone().getID();
	}
%>

<table cellpadding="0" cellspacing="0" border="0" width="100%">
<tr>
    <td valign="top" width="99%">

    <%-- Breadcrumbs --%>

    <font face="<%= JiveGlobals.getJiveProperty("skin.default.fontFace") %>"
     color="<%= JiveGlobals.getJiveProperty("skin.default.linkColor") %>">
    <b>
    <a href="<%= JiveGlobals.getJiveProperty("skin.default.homeURL") %>"
     >首页</a>
    &raquo;
    <a href="index.jsp" title="返回论坛列表"
     >论坛</a>
    &raquo;
    您的设置
    </b>
    </font>
    <p>
    <font size="-1" face="<%= JiveGlobals.getJiveProperty("skin.default.fontFace") %>">
    修改您的显示参数方便您浏览论坛！
    <% if (user != null) { %>
	改变您的配置文件以设置您对别的用户可不可见，您也可以不设置任何参数。
    <%  } %>
    </font>
    </td>
    <td valign="top" width="1%" align="center">
    <%@ include file="loginbox.jsp" %>
    </td>
</tr>
</table>
<p>
<script>
function MM_openBrWindow(theURL,features) { //v2.0
   window.open(theURL,"upload",features);

}
</script>

<form action="settings.jsp" name="form1">
<input type="hidden" name="referer" value="<%= ((referer!=null)?referer:"") %>">
<input type="hidden" name="doSave" value="true">
<%	if (user != null) { %>
<input type="hidden" name="user" value="<%= userID %>">
<%	} %>

<table bgcolor="<%= JiveGlobals.getJiveProperty("skin.default.tableBorderColor") %>"
 cellspacing="0" cellpadding="0" border="0" width="500" align="center">
<td>
<table bgcolor="<%= JiveGlobals.getJiveProperty("skin.default.tableBorderColor") %>"
 cellspacing="1" cellpadding="3" border="0" width="100%">
<tr bgcolor="<%= JiveGlobals.getJiveProperty("skin.default.prefsHeaderBgColor") %>">
	<td>
	<font class=p3 face="<%= JiveGlobals.getJiveProperty("skin.default.headerFontFace") %>"
     color="<%= JiveGlobals.getJiveProperty("skin.default.prefsHeaderTextColor") %>">
	<b>显示参数</b>
	</font>
	</td>
</tr>
<tr bgcolor="<%= JiveGlobals.getJiveProperty("skin.default.prefsBgColor") %>">
	<td align="center">
	<table cellpadding="3" cellspacing="0" border="0">
	<tr>
		<td align="right" width="50%">
            <font class=p2 face="<%= JiveGlobals.getJiveProperty("skin.default.fontFace") %>">
            每页显示的主题:
            </font>
        </td>
		<td width="50%">
        <font class=p2 face="<%= JiveGlobals.getJiveProperty("skin.default.fontFace") %>">
		<select class=p2 name="threadRange">
		<%	for (int i=0; i<THREAD_RANGES.length; i++) {
				String selected = ((THREAD_RANGES[i]==threadRange)?" selected":"");
		%>
		<option value="<%= THREAD_RANGES[i] %>"<%= selected %>><%= THREAD_RANGES[i] %>
		<%	} %>
		</select>
        </font>
		</td>
	</tr>
	<tr>
		<td align="right" width="50%">
            <font class=p2 face="<%= JiveGlobals.getJiveProperty("skin.default.fontFace") %>">
            每主题显示的消息:
            </font>
        </td>
		<td width="50%">
        <font size="-1" face="<%= JiveGlobals.getJiveProperty("skin.default.fontFace") %>">
		<select class=p2 name="messageRange">
		<%	for (int i=0; i<MESSAGE_RANGES.length; i++) {
				String selected = ((MESSAGE_RANGES[i]==messageRange)?" selected":"");
		%>
		<option value="<%= MESSAGE_RANGES[i] %>"<%= selected %>><%= MESSAGE_RANGES[i] %>
		<%	} %>
		</select>
        </font>
		</td>
	</tr>
	<tr>
		<td colspan="2">
            <font class=p2 face="<%= JiveGlobals.getJiveProperty("skin.default.fontFace") %>">
            时　区
            </font>
        </td>
    </tr>
    <tr>
		<td colspan="2">
        <font class=p2 face="<%= JiveGlobals.getJiveProperty("skin.default.fontFace") %>">
		<select class=p2 name="timeZone">
		<%	for (int i=0; i<timeZones.length; i++) {
				String selected = (timeZones[i][0].equals(timeZoneID))?" selected":"";
		%>
		<option value="<%= timeZones[i][0] %>"<%= selected %>><%= timeZones[i][1] %>
		<%	} %>
		</select>
        </font>
		</td>
	</tr>
	</table>
	</td>
</tr>
</table>
</td>
</table>

<%	if (user != null && pageUser != null && (user.getID() == pageUser.getID())) { %>

<p>

<table bgcolor="<%= JiveGlobals.getJiveProperty("skin.default.tableBorderColor") %>"
 cellspacing="0" cellpadding="0" border="0" width="500" align="center">
<tr><td>
<table bgcolor="<%= JiveGlobals.getJiveProperty("skin.default.tableBorderColor") %>"
 cellspacing="1" cellpadding="3" border="0" width="100%">
<tr bgcolor="<%= JiveGlobals.getJiveProperty("skin.default.prefsHeaderBgColor") %>">
	<td>
	<font class=p3 face="<%= JiveGlobals.getJiveProperty("skin.default.headerFontFace") %>"
     color="<%= JiveGlobals.getJiveProperty("skin.default.prefsHeaderTextColor") %>">
	<b>您的配置文件</b>
	</font>
	</td>
</tr>
<tr bgcolor="<%= JiveGlobals.getJiveProperty("skin.default.prefsBgColor") %>">
	<td align="center">
	<table cellpadding="3" cellspacing="0" border="0">
	<tr>
		<td align="right">
            <font class=p2 face="<%= JiveGlobals.getJiveProperty("skin.default.fontFace") %>">
            姓名公开:
            </font>
        </td>
		<td>
        <font class=p2 face="<%= JiveGlobals.getJiveProperty("skin.default.fontFace") %>">
		<input type="radio" name="nameVisible" value="true"
		<%= ((nameVisible)?"checked":"") %> id="p1"><label for="p1">是</label>
        &nbsp;
		<input type="radio" name="nameVisible" value="false"
		<%= ((!nameVisible)?"checked":"") %> id="p2"><label for="p2">否</label>
        </font>
		</td>
	</tr>
	<tr>
		<td align="right">
            <font class=p2 face="<%= JiveGlobals.getJiveProperty("skin.default.fontFace") %>">
            邮件公开:
            </font>
        </td>
		<td>
        <font class=p2 face="<%= JiveGlobals.getJiveProperty("skin.default.fontFace") %>">
		<input type="radio" name="emailVisible" value="true"
		<%= ((emailVisible)?"checked":"") %> id="p3"><label for="p3">是</label>
        &nbsp;
		<input type="radio" name="emailVisible" value="false"
		<%= ((!emailVisible)?"checked":"") %> id="p4"><label for="p4">否</label>
        </font>
		</td>
	</tr>
	<tr>
		<td align="right">
            <font class=p2 face="<%= JiveGlobals.getJiveProperty("skin.default.fontFace") %>">
            职　业:
            </font>
        </td>
		<td>
		<input type="text" name="occupation" value="<%= ((occupation!=null)?occupation:"") %>"
		 size="30" maxlength="255" onfocus="this.select();">
		</td>
	</tr>
	<tr>
		<td align="right">
            <font class=p2 face="<%= JiveGlobals.getJiveProperty("skin.default.fontFace") %>">
            地　址:
            </font>
        </td>
		<td>
		<input type="text" name="location" value="<%= ((location!=null)?location:"") %>"
		 size="30" maxlength="255" onfocus="this.select();">
		</td>
	</tr>
	<tr>
		<td align="right">
            <font class=p2 face="<%= JiveGlobals.getJiveProperty("skin.default.fontFace") %>">
            主　页:
            </font>
        </td>
		<td>
		<input type="text" name="homepage" value="<%= ((homepage!=null)?homepage:"") %>"
		 size="30" maxlength="255" onfocus="this.select();">
		</td>
	</tr>
	</table>
	</td>
</tr></table>
</td></tr>
</table>

<p>

<table bgcolor="<%= JiveGlobals.getJiveProperty("skin.default.tableBorderColor") %>"
 cellspacing="0" cellpadding="0" border="0" width="500" align="center">
<tr><td>
<table bgcolor="<%= JiveGlobals.getJiveProperty("skin.default.tableBorderColor") %>"
 cellspacing="1" cellpadding="3" border="0" width="100%">
<tr bgcolor="<%= JiveGlobals.getJiveProperty("skin.default.prefsHeaderBgColor") %>">
	<td>
	<font class=p3 face="<%= JiveGlobals.getJiveProperty("skin.default.headerFontFace") %>"
     color="<%= JiveGlobals.getJiveProperty("skin.default.prefsHeaderTextColor") %>">
	<b>显示设置</b>
	</font>
	</td>
</tr>
<tr bgcolor="<%= JiveGlobals.getJiveProperty("skin.default.prefsBgColor") %>">
	<td align="center">
	<table cellpadding="3" cellspacing="0" border="0">
	<tr>
		<td align="right" width="50%">
            <font class=p2 face="<%= JiveGlobals.getJiveProperty("skin.default.fontFace") %>">
            始终可见我创建的主题:
            </font>
        </td>
		<td width="50%">
        <font class=p2 face="<%= JiveGlobals.getJiveProperty("skin.default.fontFace") %>">
		<input type="radio" name="autoWatchNewTopics" value="true"
		<%= ((autoWatchNewTopics)?"checked":"") %> id="w1"><label for="w1">是</label>
        &nbsp;
		<input type="radio" name="autoWatchNewTopics" value="false"
		<%= ((!autoWatchNewTopics)?"checked":"") %> id="w2"><label for="w2">否</label>
        </font>
		</td>
	</tr>
	<tr>
		<td align="right" width="50%">
            <font class=p2 face="<%= JiveGlobals.getJiveProperty("skin.default.fontFace") %>">
            始终可见我回复的主题:
            </font>
        </td>
		<td width="50%">
        <font class=p2 face="<%= JiveGlobals.getJiveProperty("skin.default.fontFace") %>">
		<input type="radio" name="autoWatchReplies" value="true"
		<%= ((autoWatchReplies)?"checked":"") %> id="w3"><label for="w3">是</label>
        &nbsp;
		<input type="radio" name="autoWatchReplies" value="false"
		<%= ((!autoWatchReplies)?"checked":"") %> id="w4"><label for="w4">否</label>
        </font>
		</td>
	</tr>
	<tr>
		<td align="right" width="50%">
            <font class=p2 face="<%= JiveGlobals.getJiveProperty("skin.default.fontFace") %>">
            始终邮件提醒我更新信息:
            </font>
        </td>
		<td width="50%">
        <font class=p2 face="<%= JiveGlobals.getJiveProperty("skin.default.fontFace") %>">
		<input type="radio" name="autoAddEmailWatch" value="true"
		<%= ((autoAddEmailWatch)?"checked":"") %> id="w5"><label for="w5">是</label>
        &nbsp;
		<input type="radio" name="autoAddEmailWatch" value="false"
		<%= ((!autoAddEmailWatch)?"checked":"") %> id="w6"><label for="w6">否</label>
        </font>
		</td>
	</tr>
	</table>
	</td>
</tr></table>
</td></tr>
</table>

<p>

<table bgcolor="<%= JiveGlobals.getJiveProperty("skin.default.tableBorderColor") %>"
 cellspacing="0" cellpadding="0" border="0" width="500" align="center">
<tr><td>
<table bgcolor="<%= JiveGlobals.getJiveProperty("skin.default.tableBorderColor") %>"
 cellspacing="1" cellpadding="3" border="0" width="100%">
<tr bgcolor="<%= JiveGlobals.getJiveProperty("skin.default.prefsHeaderBgColor") %>">
	<td>
	<font class=p3 face="<%= JiveGlobals.getJiveProperty("skin.default.headerFontFace") %>"
     color="<%= JiveGlobals.getJiveProperty("skin.default.prefsHeaderTextColor") %>">
	<b>您的头像</b>
	</font>
	</td>
</tr>
<tr bgcolor="<%= JiveGlobals.getJiveProperty("skin.default.prefsBgColor") %>">
	<td align="center">
	<table cellpadding="3" cellspacing="0" border="0">
	<tr>
		<td align="right">
            <font class=p2 face="<%= JiveGlobals.getJiveProperty("skin.default.fontFace") %>">
            您的头像:
            </font>
        </td>
		<td>
		<%if (icon==null)
		 {
 		   %><img src="images/white_pix.gif" name="icon"> <%
		 }else{
		   %><img src="<%= ((icon!=null)?icon:"") %>" name="icon"> <%
		 }
		%>

		  <input type="hidden" name="icon" > <script>
 			 document.form1.icon.value="<%= ((icon!=null)?icon:"") %>";

			 </script> <br> <br>
			 <input type="button" value=" Change / Add "
           onClick="MM_openBrWindow('upload.jsp?pic=<%=pageUser.getUsername()%>&maxwidth=120&maxheight=120','width=450,height=400,scrollbars=yes')" >

		</td>
	</tr>
	</table>
	</td>
</tr></table>
</td></tr>
</table>
<%//签名设置开始＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝%>
<p>

<table bgcolor="<%= JiveGlobals.getJiveProperty("skin.default.tableBorderColor") %>"
 cellspacing="0" cellpadding="0" border="0" width="500" align="center">
<tr><td>
<table bgcolor="<%= JiveGlobals.getJiveProperty("skin.default.tableBorderColor") %>"
 cellspacing="1" cellpadding="3" border="0" width="100%">
<tr bgcolor="<%= JiveGlobals.getJiveProperty("skin.default.prefsHeaderBgColor") %>">
	<td>
        <font size="<%= JiveGlobals.getJiveProperty("skin.default.headerFontSize") %>"
         face="<%= JiveGlobals.getJiveProperty("skin.default.headerFontFace") %>"
         color="<%= JiveGlobals.getJiveProperty("skin.default.prefsHeaderTextColor") %>">
        <b>签名设置</b>
        </font>
	</td>
</tr>
<tr bgcolor="<%= JiveGlobals.getJiveProperty("skin.default.prefsBgColor") %>">
<td align="center">
<% signature = user.getProperty("jiveUserSignature");
;%>
<textarea name="signature" rows="6" cols="40"><%=(signature!=null?signature:"")%></textarea>
</td>
</tr></table>
</td></tr>
</table>
<%//签名设置结束%>
<%	} // end if user != null %>

<p>

<center>
<input type="submit" value="保 存" name="saveButton">
<%	if (referer != null) { %>
<input type="submit" value="保存/返回" name="saveButton">
<%	} %>
<input type="submit" value="取 消" name="saveButton">
</center>

</form>

<br>

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