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

Last change on this file since 7112 was 7112, checked in by Nicklas Nordborg, 6 years ago

References #1995: Add extension point for selecting start page

Added configuration setting in the BASE -> Preferences dialog for selecting the start page.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 8.1 KB
Line 
1<%-- $Id: submit_user.jsp 7112 2016-03-16 07:37:52Z nicklas $
2  ------------------------------------------------------------------
3  Copyright (C) 2005 Nicklas Nordborg
4  Copyright (C) 2006 Jari Häkkinen, Nicklas Nordborg
5  Copyright (C) 2007 Johan Enell, Nicklas Nordborg, Martin Svensson
6
7  This file is part of BASE - BioArray Software Environment.
8  Available at http://base.thep.lu.se/
9
10  BASE is free software; you can redistribute it and/or
11  modify it under the terms of the GNU General Public License
12  as published by the Free Software Foundation; either version 3
13  of the License, or (at your option) any later version.
14
15  BASE is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  GNU General Public License for more details.
19
20  You should have received a copy of the GNU General Public License
21  along with BASE. If not, see <http://www.gnu.org/licenses/>.
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 pageEncoding="UTF-8" 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.core.ExtendedProperty"
40  import="net.sf.basedb.core.ExtendedProperties"
41  import="net.sf.basedb.util.EmailUtil"
42  import="net.sf.basedb.clients.web.Base"
43  import="net.sf.basedb.clients.web.WebException"
44  import="net.sf.basedb.clients.web.util.HTML"
45  import="net.sf.basedb.util.Values"
46  import="net.sf.basedb.util.formatter.Formatter"
47  import="net.sf.basedb.clients.web.formatter.FormatterSettings"
48  import="net.sf.basedb.clients.web.formatter.FormatterFactory"
49  import="java.util.Arrays"
50  import="java.util.List"
51%>
52<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
53<%
54SessionControl sc = Base.getExistingSessionControl(pageContext, true);
55String ID = sc.getId();
56String cmd = request.getParameter("cmd");
57String message = "";
58String root = request.getContextPath()+"/";
59
60DbControl dc = sc.newDbControl();
61try
62{
63  if ("SaveSettings".equals(cmd))
64  {
65    String email = Values.getStringOrNull(request.getParameter("email"));
66    if (email != null && !HTML.isValidEmail(email))
67    {
68      throw new WebException("popup", "Invalid email address",
69        "The email address {1} is not a valid email address.",
70        HTML.encodeTags(email)
71      );
72    }
73    User user = (User)sc.getSessionSetting("user");
74    dc.reattachItem(user, false);
75
76    // Contact information tab
77    user.setEmail(email);
78    if (EmailUtil.isEnabled())
79    {
80      user.setSendMessagesAsEmail(email != null && Values.getBoolean(request.getParameter("sendMessagesAsEmail")));
81    }
82    user.setOrganisation(Values.getStringOrNull(request.getParameter("organisation")));
83    user.setAddress(Values.getStringOrNull(request.getParameter("address")));
84    user.setPhone(Values.getStringOrNull(request.getParameter("phone")));
85    user.setFax(Values.getStringOrNull(request.getParameter("fax")));
86    user.setUrl(Values.getStringOrNull(request.getParameter("url")));
87
88    // Password tab
89    String password = Values.getStringOrNull(request.getParameter("password"));
90    if (password != null) user.setPassword(password);
91
92    // Other settings tab
93    user.setDescription(Values.getStringOrNull(request.getParameter("description")));
94
95    // Extended properties
96    List<ExtendedProperty> extendedProperties = ExtendedProperties.getProperties("UserData");
97    if (extendedProperties != null)
98    {
99      for (ExtendedProperty ep : extendedProperties)
100      {
101        if (ep.isRestrictedEdit()) continue;
102        String name = ep.getName();
103        Formatter formatter = FormatterFactory.getExtendedPropertyFormatter(sc, ep);
104        Object value = formatter.parseString(Values.getStringOrNull(request.getParameter("ep."+name)));
105        user.setExtended(name, value);
106      }
107    }
108
109    dc.commit();
110    sc.setSessionSetting("user", null);
111    message = "Information saved";
112  }
113  else if ("SavePreferences".equals(cmd))
114  {
115    int newScale = Values.getInt(request.getParameter("scale"), 100);
116    sc.setUserClientSetting("appearance.scale", Integer.toString(newScale));
117    sc.setUserClientSetting("appearance.fontsize", Values.getString(request.getParameter("fontsize"), "size_m.css"));
118    sc.setSessionSetting("appearance.scale", new Float(newScale / 100.0));
119    sc.setUserClientSetting("text.long", request.getParameter("longTexts"));
120    ItemContext cc = sc.getCurrentContext(Item.USERCLIENTSETTING);
121    int maxRecent = Base.getMaxRecent(sc);
122 
123    String toolbar = request.getParameter("toolbar");
124    boolean hasImages = true;
125    boolean hasText = true;
126    if ("text".equals(toolbar))
127    {
128      hasImages = false;
129    }
130    else if ("images".equals(toolbar))
131    {
132      hasText = false;
133    }
134    sc.setUserClientSetting("toolbar.images", hasImages ? "1" : "0");
135    sc.setUserClientSetting("toolbar.text", hasText ? "1" : "0");
136    String minColor = Values.getString(request.getParameter("mincolor"), "0000FF");
137    String midColor = Values.getString(request.getParameter("midcolor"), "FFFFFF");
138    String maxColor = Values.getString(request.getParameter("maxcolor"), "FFFF00");
139    sc.setUserClientSetting("ratiocolor.min", minColor);
140    sc.setUserClientSetting("ratiocolor.mid", midColor);
141    sc.setUserClientSetting("ratiocolor.max", maxColor);
142    cc.setRecent("colors", minColor + "," + midColor + "," + maxColor, maxRecent);
143   
144    String dateFormat = request.getParameter("date_format");
145    String dateTimeFormat = request.getParameter("datetime_format");
146    FormatterSettings.setDateFormat(sc, dateFormat);
147    FormatterSettings.setDateTimeFormat(sc, dateTimeFormat);
148    cc.setRecent("dateFormats", dateFormat, maxRecent);
149    cc.setRecent("dateTimeFormats", dateTimeFormat, maxRecent);
150
151    int numDecimals = Values.getInt(request.getParameter("decimals"), 2);
152    FormatterSettings.setNumDecimals(sc, numDecimals);
153   
154    sc.setUserClientSetting("dialogs.remember-positions", Values.getBoolean(request.getParameter("remember_positions")) ? "1" : "0");
155   
156    sc.setUserClientSetting("start-page-id", Values.getStringOrNull(request.getParameter("start_page")));
157   
158    // Plugins tab
159    sc.setUserClientSetting("plugins.sendmessage", Values.getString(request.getParameter("sendmessage"), "0"));
160    sc.setUserClientSetting("plugins.removejob", Values.getString(request.getParameter("removejob"), "0"));
161    sc.setUserClientSetting("plugins.showWarnings", Values.getString(request.getParameter("show_warnings"), "0"));
162   
163    // Recent items tab
164    int newMaxUsed = Values.getInt(request.getParameter("maxUsed"), 4);
165    sc.setUserClientSetting("appearance.recent", Integer.toString(newMaxUsed));
166    sc.setSessionSetting("appearance.recent", newMaxUsed);
167    int newMaxViewed = Values.getInt(request.getParameter("maxViewed"), 6);
168    sc.setUserClientSetting("menu.mostRecent.maxViewed", Integer.toString(newMaxViewed));
169    sc.setUserClientSetting("menu.mostRecent.loadNames", Values.getString(request.getParameter("loadNames"), "0"));
170
171    String[] stickyItems = request.getParameterValues("sticky_items");
172    sc.setUserClientSetting("menu.mostRecent", 
173      stickyItems == null ? "" : Values.getString(Arrays.asList(stickyItems), ":", true));
174   
175    message = "Preferences saved";
176  }
177  else if ("ReloadPermissions".equals(cmd))
178  {
179    sc.reloadPermissions();
180    sc.reloadSettings(true, false);
181    sc.setSessionSetting("menu.standard.html", null);
182    message = "Permissions reloaded";
183  }
184  else if ("ResetFilters".equals(cmd))
185  {
186    boolean inDatabase = Values.getBoolean(request.getParameter("database"));
187    String itemType = Values.getStringOrNull(request.getParameter("item_type"));
188    Item item = itemType == null ? null : Item.valueOf(itemType);
189    int numDeleted = sc.deleteCurrentContexts(item, true, inDatabase);
190    message = numDeleted + " list settings deleted";
191  }
192  else
193  {
194    throw new WebException("popup", "Invalid command", "The command {1} is not recognised as a valid command.", cmd);
195  }
196}
197finally
198{
199  if (dc != null) dc.close();
200}
201response.sendRedirect(root + "common/close_popup.jsp?ID="+ID+"&refresh_opener=1&&message="+HTML.urlEncode(message));
202%>
203
Note: See TracBrowser for help on using the repository browser.