1 | <%-- $Id: submit_user.jsp 2978 2006-11-30 07:27:42Z nicklas $ |
---|
2 | ------------------------------------------------------------------ |
---|
3 | Copyright (C) Authors contributing to this file. |
---|
4 | |
---|
5 | This file is part of BASE - BioArray Software Environment. |
---|
6 | Available at http://base.thep.lu.se/ |
---|
7 | |
---|
8 | BASE is free software; you can redistribute it and/or |
---|
9 | modify it under the terms of the GNU General Public License |
---|
10 | as published by the Free Software Foundation; either version 2 |
---|
11 | of the License, or (at your option) any later version. |
---|
12 | |
---|
13 | BASE is distributed in the hope that it will be useful, |
---|
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
16 | GNU General Public License for more details. |
---|
17 | |
---|
18 | You should have received a copy of the GNU General Public License |
---|
19 | along with this program; if not, write to the Free Software |
---|
20 | Foundation, Inc., 59 Temple Place - Suite 330, |
---|
21 | Boston, MA 02111-1307, USA. |
---|
22 | ------------------------------------------------------------------ |
---|
23 | |
---|
24 | This page will save user information and preferences. |
---|
25 | |
---|
26 | @param cmd The command to execute |
---|
27 | - SaveSettings: Save the settings from the settings.jsp page. |
---|
28 | - SavePreferences: Save preferences from the preferences.jsp page. |
---|
29 | |
---|
30 | @author Nicklas |
---|
31 | @version 2.0 |
---|
32 | --%> |
---|
33 | <%@ page session="false" |
---|
34 | import="net.sf.basedb.core.SessionControl" |
---|
35 | import="net.sf.basedb.core.DbControl" |
---|
36 | import="net.sf.basedb.core.Item" |
---|
37 | import="net.sf.basedb.core.User" |
---|
38 | import="net.sf.basedb.core.ItemContext" |
---|
39 | import="net.sf.basedb.clients.web.Base" |
---|
40 | import="net.sf.basedb.clients.web.WebException" |
---|
41 | import="net.sf.basedb.clients.web.util.HTML" |
---|
42 | import="net.sf.basedb.clients.web.formatter.FormatterSettings" |
---|
43 | import="net.sf.basedb.util.Values" |
---|
44 | import="java.util.Arrays" |
---|
45 | %> |
---|
46 | <%@ taglib prefix="base" uri="/WEB-INF/base.tld" %> |
---|
47 | <% |
---|
48 | SessionControl sc = Base.getExistingSessionControl(pageContext, true); |
---|
49 | String ID = sc.getId(); |
---|
50 | String cmd = request.getParameter("cmd"); |
---|
51 | String message = ""; |
---|
52 | String root = request.getContextPath()+"/"; |
---|
53 | |
---|
54 | DbControl dc = sc.newDbControl(); |
---|
55 | try |
---|
56 | { |
---|
57 | if ("SaveSettings".equals(cmd)) |
---|
58 | { |
---|
59 | String email = Values.getStringOrNull(request.getParameter("email")); |
---|
60 | if (email != null && !HTML.isValidEmail(email)) |
---|
61 | { |
---|
62 | throw new WebException("popup", "Invalid email address", |
---|
63 | "The email address {1} is not a valid email address.", |
---|
64 | HTML.encodeTags(email) |
---|
65 | ); |
---|
66 | } |
---|
67 | User user = (User)sc.getSessionSetting("user"); |
---|
68 | dc.reattachItem(user); |
---|
69 | |
---|
70 | // Contact information tab |
---|
71 | user.setEmail(email); |
---|
72 | user.setOrganisation(Values.getStringOrNull(request.getParameter("organisation"))); |
---|
73 | user.setAddress(Values.getStringOrNull(request.getParameter("address"))); |
---|
74 | user.setPhone(Values.getStringOrNull(request.getParameter("phone"))); |
---|
75 | user.setFax(Values.getStringOrNull(request.getParameter("fax"))); |
---|
76 | user.setUrl(Values.getStringOrNull(request.getParameter("url"))); |
---|
77 | |
---|
78 | // Password tab |
---|
79 | String password = Values.getStringOrNull(request.getParameter("password")); |
---|
80 | if (password != null) user.setPassword(password); |
---|
81 | |
---|
82 | // Other settings tab |
---|
83 | user.setDescription(Values.getStringOrNull(request.getParameter("description"))); |
---|
84 | |
---|
85 | dc.commit(); |
---|
86 | sc.setSessionSetting("user", null); |
---|
87 | message = "Information saved"; |
---|
88 | } |
---|
89 | else if ("SavePreferences".equals(cmd)) |
---|
90 | { |
---|
91 | int newScale = Values.getInt(request.getParameter("scale"), 100); |
---|
92 | sc.setUserClientSetting("appearance.scale", Integer.toString(newScale)); |
---|
93 | sc.setUserClientSetting("appearance.fontsize", Values.getString(request.getParameter("fontsize"), "size_m.css")); |
---|
94 | sc.setSessionSetting("appearance.scale", new Float(newScale / 100.0)); |
---|
95 | int newMaxRecent = Values.getInt(request.getParameter("recent"), 4); |
---|
96 | sc.setUserClientSetting("appearance.recent", Integer.toString(newMaxRecent)); |
---|
97 | sc.setSessionSetting("appearance.recent", newMaxRecent); |
---|
98 | ItemContext cc = sc.getCurrentContext(Item.USERCLIENTSETTING); |
---|
99 | int maxRecent = Base.getMaxRecent(sc); |
---|
100 | |
---|
101 | String toolbar = request.getParameter("toolbar"); |
---|
102 | boolean hasImages = true; |
---|
103 | boolean hasText = true; |
---|
104 | if ("text".equals(toolbar)) |
---|
105 | { |
---|
106 | hasImages = false; |
---|
107 | } |
---|
108 | else if ("images".equals(toolbar)) |
---|
109 | { |
---|
110 | hasText = false; |
---|
111 | } |
---|
112 | sc.setUserClientSetting("toolbar.images", hasImages ? "1" : "0"); |
---|
113 | sc.setUserClientSetting("toolbar.text", hasText ? "1" : "0"); |
---|
114 | String minColor = Values.getString(request.getParameter("mincolor"), "0000FF"); |
---|
115 | String midColor = Values.getString(request.getParameter("midcolor"), "FFFFFF"); |
---|
116 | String maxColor = Values.getString(request.getParameter("maxcolor"), "FFFF00"); |
---|
117 | sc.setUserClientSetting("ratiocolor.min", minColor); |
---|
118 | sc.setUserClientSetting("ratiocolor.mid", midColor); |
---|
119 | sc.setUserClientSetting("ratiocolor.max", maxColor); |
---|
120 | cc.setRecent("colors", minColor + "," + midColor + "," + maxColor, maxRecent); |
---|
121 | |
---|
122 | String dateFormat = request.getParameter("date_format"); |
---|
123 | String dateTimeFormat = request.getParameter("datetime_format"); |
---|
124 | FormatterSettings.setDateFormat(sc, dateFormat); |
---|
125 | FormatterSettings.setDateTimeFormat(sc, dateTimeFormat); |
---|
126 | cc.setRecent("dateFormats", dateFormat, maxRecent); |
---|
127 | cc.setRecent("dateTimeFormats", dateTimeFormat, maxRecent); |
---|
128 | |
---|
129 | sc.setUserClientSetting("plugins.sendmessage", Values.getString(request.getParameter("sendmessage"), "0")); |
---|
130 | String[] mostRecent = request.getParameterValues("enabled"); |
---|
131 | sc.setUserClientSetting("menu.mostRecent", |
---|
132 | mostRecent == null ? "" : Values.getString(Arrays.asList(mostRecent), ":", true)); |
---|
133 | sc.setUserClientSetting("menu.mostRecent.loadNames", Values.getString(request.getParameter("loadNames"), "0")); |
---|
134 | |
---|
135 | message = "Preferences saved"; |
---|
136 | } |
---|
137 | else if ("ReloadPermissions".equals(cmd)) |
---|
138 | { |
---|
139 | sc.reloadPermissions(); |
---|
140 | sc.reloadSettings(true, false); |
---|
141 | sc.setSessionSetting("menu.standard.html", null); |
---|
142 | message = "Permissions reloaded"; |
---|
143 | } |
---|
144 | } |
---|
145 | finally |
---|
146 | { |
---|
147 | if (dc != null) dc.close(); |
---|
148 | } |
---|
149 | response.sendRedirect(root + "common/close_popup.jsp?ID="+ID+"&refresh_opener=1&&message="+HTML.urlEncode(message)); |
---|
150 | %> |
---|
151 | |
---|