source: trunk/www/my_base/user/submit_user.jsp @ 3492

Last change on this file since 3492 was 3492, checked in by Nicklas Nordborg, 15 years ago

Fixes #578

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 6.2 KB
Line 
1<%-- $Id: submit_user.jsp 3492 2007-06-14 08:44:39Z 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<%
48SessionControl sc = Base.getExistingSessionControl(pageContext, true);
49String ID = sc.getId();
50String cmd = request.getParameter("cmd");
51String message = "";
52String root = request.getContextPath()+"/";
53
54DbControl dc = sc.newDbControl();
55try
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    ItemContext cc = sc.getCurrentContext(Item.USERCLIENTSETTING);
96    int maxRecent = Base.getMaxRecent(sc);
97 
98    String toolbar = request.getParameter("toolbar");
99    boolean hasImages = true;
100    boolean hasText = true;
101    if ("text".equals(toolbar))
102    {
103      hasImages = false;
104    }
105    else if ("images".equals(toolbar))
106    {
107      hasText = false;
108    }
109    sc.setUserClientSetting("toolbar.images", hasImages ? "1" : "0");
110    sc.setUserClientSetting("toolbar.text", hasText ? "1" : "0");
111    String minColor = Values.getString(request.getParameter("mincolor"), "0000FF");
112    String midColor = Values.getString(request.getParameter("midcolor"), "FFFFFF");
113    String maxColor = Values.getString(request.getParameter("maxcolor"), "FFFF00");
114    sc.setUserClientSetting("ratiocolor.min", minColor);
115    sc.setUserClientSetting("ratiocolor.mid", midColor);
116    sc.setUserClientSetting("ratiocolor.max", maxColor);
117    cc.setRecent("colors", minColor + "," + midColor + "," + maxColor, maxRecent);
118   
119    String dateFormat = request.getParameter("date_format");
120    String dateTimeFormat = request.getParameter("datetime_format");
121    FormatterSettings.setDateFormat(sc, dateFormat);
122    FormatterSettings.setDateTimeFormat(sc, dateTimeFormat);
123    cc.setRecent("dateFormats", dateFormat, maxRecent);
124    cc.setRecent("dateTimeFormats", dateTimeFormat, maxRecent);
125
126    int numDecimals = Values.getInt(request.getParameter("decimals"), 2);
127    FormatterSettings.setNumDecimals(sc, numDecimals);
128   
129    // Plugins tab
130    sc.setUserClientSetting("plugins.sendmessage", Values.getString(request.getParameter("sendmessage"), "0"));
131    sc.setUserClientSetting("plugins.removejob", Values.getString(request.getParameter("removejob"), "0"));
132   
133    // Recent items tab
134    int newMaxUsed = Values.getInt(request.getParameter("maxUsed"), 4);
135    sc.setUserClientSetting("appearance.recent", Integer.toString(newMaxUsed));
136    sc.setSessionSetting("appearance.recent", newMaxUsed);
137    int newMaxViewed = Values.getInt(request.getParameter("maxViewed"), 6);
138    sc.setUserClientSetting("menu.mostRecent.maxViewed", Integer.toString(newMaxViewed));
139    sc.setUserClientSetting("menu.mostRecent.loadNames", Values.getString(request.getParameter("loadNames"), "0"));
140
141    String[] stickyItems = request.getParameterValues("sticky_items");
142    sc.setUserClientSetting("menu.mostRecent", 
143      stickyItems == null ? "" : Values.getString(Arrays.asList(stickyItems), ":", true));
144   
145    message = "Preferences saved";
146  }
147  else if ("ReloadPermissions".equals(cmd))
148  {
149    sc.reloadPermissions();
150    sc.reloadSettings(true, false);
151    sc.setSessionSetting("menu.standard.html", null);
152    message = "Permissions reloaded";
153  }
154}
155finally
156{
157  if (dc != null) dc.close();
158}
159response.sendRedirect(root + "common/close_popup.jsp?ID="+ID+"&refresh_opener=1&&message="+HTML.urlEncode(message));
160%>
161
Note: See TracBrowser for help on using the repository browser.