source: trunk/www/common/share/submit_share.jsp @ 5136

Last change on this file since 5136 was 5136, checked in by Nicklas Nordborg, 13 years ago

Merged patch release 2.13.1 to the trunk.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 4.7 KB
Line 
1<%-- $Id: submit_share.jsp 5136 2009-10-15 06:33:07Z nicklas $
2  ------------------------------------------------------------------
3  Copyright (C) 2005 Nicklas Nordborg
4  Copyright (C) 2006 Jari Häkkinen, Nicklas Nordborg
5
6  This file is part of BASE - BioArray Software Environment.
7  Available at http://base.thep.lu.se/
8
9  BASE is free software; you can redistribute it and/or
10  modify it under the terms of the GNU General Public License
11  as published by the Free Software Foundation; either version 3
12  of the License, or (at your option) any later version.
13
14  BASE is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  GNU General Public License for more details.
18
19  You should have received a copy of the GNU General Public License
20  along with BASE. If not, see <http://www.gnu.org/licenses/>.
21  ------------------------------------------------------------------
22
23  Configure the order and visibility of columns in a table of items.
24  This page will use the TableColumn.getTableColumns(item) to retreive the
25  list of all available columns for that item type and
26  getSession().getSetting(item+".columns") to retreive a comma-separated
27  list of the current order of visible columns.
28
29  @param item The type of items in the table
30  @param cmd
31    - Save: To save the settings
32    - otherwise: A configuration dialouge is displayed
33  @param columns Only used if cmd=Save. Contains a comma-separated list
34    of column ID:s which is saved to a user-client setting.
35
36  @author Nicklas
37  @version 2.0
38--%>
39<%@ page session="false"
40  import="net.sf.basedb.core.SessionControl"
41  import="net.sf.basedb.core.DbControl"
42  import="net.sf.basedb.core.Item"
43  import="net.sf.basedb.core.Permission"
44  import="net.sf.basedb.core.MultiPermissions"
45  import="net.sf.basedb.core.ItemContext"
46  import="net.sf.basedb.core.User"
47  import="net.sf.basedb.core.Group"
48  import="net.sf.basedb.core.Project"
49  import="net.sf.basedb.clients.web.Base"
50  import="net.sf.basedb.clients.web.PermissionUtil"
51  import="net.sf.basedb.clients.web.WebException"
52  import="net.sf.basedb.util.Values"
53  import="net.sf.basedb.clients.web.util.HTML"
54  import="java.util.Arrays"
55  import="java.util.Set"
56%>
57<%
58final SessionControl sc = Base.getExistingSessionControl(pageContext, true);
59final String ID = sc.getId();
60final Item itemType = Item.valueOf(request.getParameter("item_type"));
61final String subContext = Values.getString(request.getParameter("subcontext"), "");
62final String cmd = request.getParameter("cmd");
63final String root = request.getContextPath()+"/";
64
65String forward = null;
66String message = null;
67final DbControl dc = sc.newDbControl();
68try
69{
70  if ("Save".equals(cmd))
71  {
72    ItemContext cc = sc.getCurrentContext(itemType, subContext);
73    MultiPermissions mp = (MultiPermissions)cc.getObject("MultiPermissions");
74    boolean recursive = Values.getBoolean(request.getParameter("recursive"));
75   
76    String[] modifiedUsers = Values.getString(request.getParameter("modifiedUsers")).split(",");
77    for (int i = 0; i < modifiedUsers.length; ++i)
78    {
79      int userId = Values.getInt(modifiedUsers[i], -1);
80      if (userId != -1) 
81      {
82        Set<Permission> permissions = PermissionUtil.getPermissions(Values.getInt(request.getParameter("U"+userId), 0));
83        mp.setPermissions(User.getById(dc, userId), permissions);
84      }
85    }
86   
87    String[] modifiedGroups = Values.getString(request.getParameter("modifiedGroups")).split(",");
88    for (int i = 0; i < modifiedGroups.length; ++i)
89    {
90      int groupId = Values.getInt(modifiedGroups[i], -1);
91      if (groupId != -1) 
92      {
93        Set<Permission> permissions = PermissionUtil.getPermissions(Values.getInt(request.getParameter("G"+groupId), 0));
94        mp.setPermissions(Group.getById(dc, groupId), permissions);
95      }
96    }
97 
98    String[] modifiedProjects = Values.getString(request.getParameter("modifiedProjects")).split(",");
99    for (int i = 0; i < modifiedProjects.length; ++i)
100    {
101      int projectId = Values.getInt(modifiedProjects[i], -1);
102      if (projectId != -1) 
103      {
104        Set<Permission> permissions = PermissionUtil.getPermissions(Values.getInt(request.getParameter("P"+projectId), 0));
105        mp.setPermissions(Project.getById(dc, projectId), permissions);
106      }
107    }
108    mp.updateKeys(dc, recursive);
109    sc.reloadPermissions();
110    dc.commit();
111    cc.removeObject("MultiPermissions");
112    message = "Items shared";
113  }
114  else
115  {
116    throw new WebException("popup", "Invalid command", "The command {1} is not recognised as a valid command.", cmd);
117  }
118}
119finally
120{
121  if (dc != null) dc.close();
122}
123
124if (forward != null)
125{
126  pageContext.forward(forward);
127}
128else if (message == null)
129{
130  response.sendRedirect(root + "common/close_popup.jsp?refresh_opener=1&wait=0");
131}
132else
133{
134  response.sendRedirect(root + "common/close_popup.jsp?refresh_opener=1&message="+HTML.urlEncode(message));
135}
136%>
Note: See TracBrowser for help on using the repository browser.