1 | <%-- $Id: edit_user.jsp 5767 2011-09-28 07:31:39Z nicklas $ |
---|
2 | ------------------------------------------------------------------ |
---|
3 | Copyright (C) 2005 Nicklas Nordborg |
---|
4 | Copyright (C) 2006 Jari Häkkinen, Nicklas Nordborg, Martin Svensson |
---|
5 | Copyright (C) 2007 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 | |
---|
25 | @author Nicklas |
---|
26 | @version 2.0 |
---|
27 | --%> |
---|
28 | <%@ page pageEncoding="UTF-8" session="false" |
---|
29 | import="net.sf.basedb.core.SessionControl" |
---|
30 | import="net.sf.basedb.core.DbControl" |
---|
31 | import="net.sf.basedb.core.SystemItems" |
---|
32 | import="net.sf.basedb.core.Item" |
---|
33 | import="net.sf.basedb.core.Type" |
---|
34 | import="net.sf.basedb.core.ItemContext" |
---|
35 | import="net.sf.basedb.core.Permission" |
---|
36 | import="net.sf.basedb.core.Group" |
---|
37 | import="net.sf.basedb.core.User" |
---|
38 | import="net.sf.basedb.core.Quota" |
---|
39 | import="net.sf.basedb.core.Role" |
---|
40 | import="net.sf.basedb.core.Directory" |
---|
41 | import="net.sf.basedb.core.ExtendedProperties" |
---|
42 | import="net.sf.basedb.core.ExtendedProperty" |
---|
43 | import="net.sf.basedb.core.QuotaType" |
---|
44 | import="net.sf.basedb.core.Location" |
---|
45 | import="net.sf.basedb.core.Include" |
---|
46 | import="net.sf.basedb.core.ItemQuery" |
---|
47 | import="net.sf.basedb.core.ItemResultList" |
---|
48 | import="net.sf.basedb.core.PermissionDeniedException" |
---|
49 | import="net.sf.basedb.core.query.Orders" |
---|
50 | import="net.sf.basedb.core.query.Hql" |
---|
51 | import="net.sf.basedb.core.query.Restrictions" |
---|
52 | import="net.sf.basedb.core.query.Expressions" |
---|
53 | import="net.sf.basedb.clients.web.Base" |
---|
54 | import="net.sf.basedb.clients.web.util.HTML" |
---|
55 | import="net.sf.basedb.util.Values" |
---|
56 | import="net.sf.basedb.util.formatter.Formatter" |
---|
57 | import="net.sf.basedb.clients.web.formatter.FormatterFactory" |
---|
58 | import="net.sf.basedb.clients.web.formatter.FormatterSettings" |
---|
59 | import="net.sf.basedb.core.plugin.GuiContext" |
---|
60 | import="net.sf.basedb.clients.web.extensions.ExtensionsControl" |
---|
61 | import="net.sf.basedb.clients.web.extensions.JspContext" |
---|
62 | import="net.sf.basedb.clients.web.extensions.edit.EditUtil" |
---|
63 | import="net.sf.basedb.util.extensions.ExtensionsInvoker" |
---|
64 | import="java.util.Date" |
---|
65 | import="java.util.List" |
---|
66 | %> |
---|
67 | <%@ taglib prefix="base" uri="/WEB-INF/base.tld" %> |
---|
68 | <%@ taglib prefix="t" uri="/WEB-INF/tab.tld" %> |
---|
69 | <% |
---|
70 | final Item itemType = Item.USER; |
---|
71 | final SessionControl sc = Base.getExistingSessionControl(pageContext, true); |
---|
72 | final ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, null); |
---|
73 | final int itemId = cc.getId(); |
---|
74 | final String ID = sc.getId(); |
---|
75 | final float scale = Base.getScale(sc); |
---|
76 | final DbControl dc = sc.newDbControl(); |
---|
77 | try |
---|
78 | { |
---|
79 | String title = null; |
---|
80 | User user = null; |
---|
81 | |
---|
82 | List<ExtendedProperty> extendedProperties = ExtendedProperties.getProperties("UserData"); |
---|
83 | |
---|
84 | final QuotaType total = QuotaType.getById(dc, SystemItems.getId(QuotaType.TOTAL)); |
---|
85 | Quota currentQuota = null; |
---|
86 | Group currentQuotaGroup = null; |
---|
87 | Directory homeDirectory = null; |
---|
88 | |
---|
89 | // Query to retrieve group membership |
---|
90 | ItemQuery<Group> groupQuery = null; |
---|
91 | // Query to retrieve role membership |
---|
92 | ItemQuery<Role> roleQuery = null; |
---|
93 | |
---|
94 | if (itemId == 0) |
---|
95 | { |
---|
96 | title = "Create user"; |
---|
97 | cc.removeObject("item"); |
---|
98 | if (cc.getPropertyFilter("quota.name") != null) |
---|
99 | { |
---|
100 | currentQuota = Base.getFirstMatching(dc, Quota.getQuery(), "name", cc.getPropertyFilter("quota.name")); |
---|
101 | } |
---|
102 | else |
---|
103 | { |
---|
104 | currentQuota = Quota.getById(dc, SystemItems.getId(Quota.DEFAULT)); |
---|
105 | } |
---|
106 | if (cc.getPropertyFilter("quotaGroup.name") != null) |
---|
107 | { |
---|
108 | currentQuotaGroup = Base.getFirstMatching(dc, Group.getQuery(), "name", cc.getPropertyFilter("quotaGroup.name")); |
---|
109 | } |
---|
110 | |
---|
111 | groupQuery = Group.getQuery(); |
---|
112 | groupQuery.restrict( |
---|
113 | Restrictions.eq( |
---|
114 | Hql.property("default"), |
---|
115 | Expressions.parameter("isDefault", true, Type.BOOLEAN) |
---|
116 | ) |
---|
117 | ); |
---|
118 | groupQuery.order(Orders.asc(Hql.property("name"))); |
---|
119 | roleQuery = Role.getQuery(); |
---|
120 | roleQuery.restrict( |
---|
121 | Restrictions.eq( |
---|
122 | Hql.property("default"), |
---|
123 | Expressions.parameter("isDefault", true, Type.BOOLEAN) |
---|
124 | ) |
---|
125 | ); |
---|
126 | roleQuery.order(Orders.asc(Hql.property("name"))); |
---|
127 | |
---|
128 | } |
---|
129 | else |
---|
130 | { |
---|
131 | user = User.getById(dc, itemId); |
---|
132 | cc.setObject("item", user); |
---|
133 | title = "Edit user -- " + HTML.encodeTags(user.getName()); |
---|
134 | |
---|
135 | try |
---|
136 | { |
---|
137 | currentQuota = user.getQuota(); |
---|
138 | } |
---|
139 | catch (PermissionDeniedException ex) |
---|
140 | {} |
---|
141 | try |
---|
142 | { |
---|
143 | currentQuotaGroup = user.getQuotaGroup(); |
---|
144 | } |
---|
145 | catch (PermissionDeniedException ex) |
---|
146 | {} |
---|
147 | try |
---|
148 | { |
---|
149 | homeDirectory = user.getHomeDirectory(); |
---|
150 | } |
---|
151 | catch (PermissionDeniedException ex) |
---|
152 | {} |
---|
153 | |
---|
154 | groupQuery = user.getGroups(); |
---|
155 | groupQuery.include(Include.ALL); |
---|
156 | groupQuery.order(Orders.asc(Hql.property("name"))); |
---|
157 | roleQuery = user.getRoles(); |
---|
158 | roleQuery.include(Include.ALL); |
---|
159 | roleQuery.order(Orders.asc(Hql.property("name"))); |
---|
160 | } |
---|
161 | if (user != null && !user.hasPermission(Permission.WRITE)) |
---|
162 | { |
---|
163 | throw new PermissionDeniedException(Permission.WRITE, itemType.toString()); |
---|
164 | } |
---|
165 | |
---|
166 | final boolean readQuota = sc.hasPermission(Permission.READ, Item.QUOTA); |
---|
167 | final boolean useQuota = sc.hasPermission(Permission.USE, Item.QUOTA); |
---|
168 | final boolean createDirectories = sc.hasPermission(Permission.CREATE, Item.DIRECTORY); |
---|
169 | final boolean readDirectories = sc.hasPermission(Permission.READ, Item.DIRECTORY); |
---|
170 | final boolean readGroups = sc.hasPermission(Permission.READ, Item.GROUP); |
---|
171 | final boolean useGroups = sc.hasPermission(Permission.USE, Item.GROUP); |
---|
172 | final boolean writeGroups = sc.hasPermission(Permission.WRITE, Item.GROUP); |
---|
173 | final boolean writeRoles = sc.hasPermission(Permission.WRITE, Item.ROLE); |
---|
174 | final boolean writeMembership = writeGroups && writeRoles; |
---|
175 | |
---|
176 | // Query to retrieve quota |
---|
177 | final ItemQuery<Quota> quotaQuery = Quota.getQuery(); |
---|
178 | quotaQuery.include(Include.ALL); |
---|
179 | quotaQuery.order(Orders.asc(Hql.property("name"))); |
---|
180 | quotaQuery.setCacheResult(true); |
---|
181 | |
---|
182 | // Query to retrieve quota groups |
---|
183 | final ItemQuery<Group> quotaGroupQuery = Group.getQuery(); |
---|
184 | quotaGroupQuery.include(Include.ALL); |
---|
185 | quotaGroupQuery.order(Orders.asc(Hql.property("name"))); |
---|
186 | quotaGroupQuery.restrict(Restrictions.neq(Hql.property("quota"), null)); |
---|
187 | quotaGroupQuery.setCacheResult(true); |
---|
188 | |
---|
189 | // Query to retrieve home directories |
---|
190 | final ItemQuery<Directory> directoryQuery = Directory.getQuery(); |
---|
191 | directoryQuery.include(Include.ALL); |
---|
192 | directoryQuery.order(Orders.asc(Hql.property("name"))); |
---|
193 | directoryQuery.restrict( |
---|
194 | Restrictions.eq( |
---|
195 | Hql.property("parent"), |
---|
196 | Expressions.integer(SystemItems.getId(Directory.HOME)) |
---|
197 | ) |
---|
198 | ); |
---|
199 | directoryQuery.setCacheResult(true); |
---|
200 | |
---|
201 | final String clazz = "class=\"text\""; |
---|
202 | final String requiredClazz = "class=\"text required\""; |
---|
203 | Formatter<Date> dateFormatter = FormatterFactory.getDateFormatter(sc); |
---|
204 | String dateFormat = FormatterSettings.getDateFormat(sc); |
---|
205 | String jsDateFormat = HTML.javaScriptEncode(dateFormat); |
---|
206 | String htmlDateFormat = HTML.encodeTags(dateFormat); |
---|
207 | Formatter<Date> dateTimeFormatter = FormatterFactory.getDateTimeFormatter(sc); |
---|
208 | String dateTimeFormat = FormatterSettings.getDateTimeFormat(sc); |
---|
209 | String jsDateTimeFormat = HTML.javaScriptEncode(dateTimeFormat); |
---|
210 | String htmlDateTimeFormat = HTML.encodeTags(dateTimeFormat); |
---|
211 | JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, GuiContext.item(itemType), user); |
---|
212 | ExtensionsInvoker invoker = EditUtil.useEditExtensions(jspContext); |
---|
213 | %> |
---|
214 | <base:page type="popup" title="<%=title%>"> |
---|
215 | <base:head scripts="tabcontrol.js,linkitems.js" styles="tabcontrol.css"> |
---|
216 | <ext:scripts context="<%=jspContext%>" /> |
---|
217 | <ext:stylesheets context="<%=jspContext%>" /> |
---|
218 | <script language="JavaScript"> |
---|
219 | // Validate the "User" tab |
---|
220 | function validateUser() |
---|
221 | { |
---|
222 | var frm = document.forms['user']; |
---|
223 | if (Main.trimString(frm.name.value) == '') |
---|
224 | { |
---|
225 | alert('You must enter a name for the user.'); |
---|
226 | frm.name.focus(); |
---|
227 | return false; |
---|
228 | } |
---|
229 | else if (Main.trimString(frm.login.value) == '') |
---|
230 | { |
---|
231 | alert('You must enter a login for the user.'); |
---|
232 | frm.login.focus(); |
---|
233 | return false; |
---|
234 | } |
---|
235 | else if (frm.new_password.value != frm.retype_password.value) |
---|
236 | { |
---|
237 | frm.retype_password.focus(); |
---|
238 | alert('The two passwords do not match!'); |
---|
239 | return false; |
---|
240 | } |
---|
241 | <% |
---|
242 | if (itemId == 0) |
---|
243 | { |
---|
244 | %> |
---|
245 | else if (Main.trimString(frm.new_password.value) == '') |
---|
246 | { |
---|
247 | alert('You must enter a password for the user.'); |
---|
248 | frm.new_password.focus(); |
---|
249 | return false; |
---|
250 | } |
---|
251 | <% |
---|
252 | } |
---|
253 | %> |
---|
254 | return true; |
---|
255 | } |
---|
256 | |
---|
257 | // Validate the "Extended properties" tab |
---|
258 | function validateExtendedProperties() |
---|
259 | { |
---|
260 | var frm = document.forms['user']; |
---|
261 | var field; |
---|
262 | <% |
---|
263 | if (extendedProperties != null) |
---|
264 | { |
---|
265 | for (ExtendedProperty ep : extendedProperties) |
---|
266 | { |
---|
267 | Type type = ep.getType(); |
---|
268 | String name = ep.getName(); |
---|
269 | %> |
---|
270 | field = frm['<%=name%>']; |
---|
271 | <% |
---|
272 | if (type == Type.DATE) |
---|
273 | { |
---|
274 | %> |
---|
275 | if (field.value != '' && !Dates.isDate(field.value, '<%=jsDateFormat%>')) |
---|
276 | { |
---|
277 | alert("'"+field.value+"' is not a valid date for '<%=HTML.javaScriptEncode(ep.getTitle())%>'"); |
---|
278 | field.focus(); |
---|
279 | return false; |
---|
280 | } |
---|
281 | <% |
---|
282 | } |
---|
283 | else if (type == Type.TIMESTAMP) |
---|
284 | { |
---|
285 | %> |
---|
286 | if (field.value != '' && !Dates.isDate(field.value, '<%=jsDateTimeFormat%>')) |
---|
287 | { |
---|
288 | alert("'"+field.value+"' is not a valid timestamp for '<%=HTML.javaScriptEncode(ep.getTitle())%>'"); |
---|
289 | field.focus(); |
---|
290 | return false; |
---|
291 | } |
---|
292 | <% |
---|
293 | } |
---|
294 | if (!ep.isNullable()) |
---|
295 | { |
---|
296 | if (type == Type.BOOLEAN) |
---|
297 | { |
---|
298 | %> |
---|
299 | if (Forms.getCheckedRadio(field) == null) |
---|
300 | { |
---|
301 | alert("You must select a value for '<%=HTML.javaScriptEncode(ep.getTitle())%>'"); |
---|
302 | field.focus(); |
---|
303 | return false; |
---|
304 | } |
---|
305 | <% |
---|
306 | } |
---|
307 | else |
---|
308 | { |
---|
309 | %> |
---|
310 | if (Main.trimString(field.value) == '') |
---|
311 | { |
---|
312 | alert("You must enter a value for '<%=HTML.javaScriptEncode(ep.getTitle())%>'."); |
---|
313 | field.focus(); |
---|
314 | return false; |
---|
315 | } |
---|
316 | <% |
---|
317 | } |
---|
318 | } |
---|
319 | } |
---|
320 | } |
---|
321 | %> |
---|
322 | return true; |
---|
323 | } |
---|
324 | |
---|
325 | // Validate the "Contact information" tab |
---|
326 | function validateContact() |
---|
327 | { |
---|
328 | return true; |
---|
329 | } |
---|
330 | |
---|
331 | // Validate the "Membership" tab |
---|
332 | function validateMembership() |
---|
333 | { |
---|
334 | return true; |
---|
335 | } |
---|
336 | |
---|
337 | // Submit the form |
---|
338 | function saveSettings() |
---|
339 | { |
---|
340 | var frm = document.forms['user']; |
---|
341 | if (TabControl.validateActiveTab('settings')) |
---|
342 | { |
---|
343 | frm.addRoles.value = Link.getActionIds(1, 'R').join(','); |
---|
344 | frm.removeRoles.value = Link.getActionIds(-1, 'R').join(','); |
---|
345 | frm.addGroups.value = Link.getActionIds(1, 'G').join(','); |
---|
346 | frm.removeGroups.value = Link.getActionIds(-1, 'G').join(','); |
---|
347 | frm.submit(); |
---|
348 | } |
---|
349 | } |
---|
350 | |
---|
351 | function init() |
---|
352 | { |
---|
353 | <% |
---|
354 | if (user == null) |
---|
355 | { |
---|
356 | %> |
---|
357 | var frm = document.forms['user']; |
---|
358 | frm.name.focus(); |
---|
359 | frm.name.select(); |
---|
360 | <% |
---|
361 | } |
---|
362 | %> |
---|
363 | initMembership(); |
---|
364 | } |
---|
365 | function initMembership() |
---|
366 | { |
---|
367 | var members = document.forms['user'].membership; |
---|
368 | Link.addNewSection(members, new Section('G', 'Groups')); |
---|
369 | <% |
---|
370 | if (groupQuery != null) |
---|
371 | { |
---|
372 | ItemResultList<Group> groups = groupQuery.list(dc); |
---|
373 | for (Group group : groups) |
---|
374 | { |
---|
375 | %> |
---|
376 | Link.addNewItem(members, new Item('G', <%=group.getId()%>, '<%=HTML.javaScriptEncode(group.getName())%>')); |
---|
377 | <% |
---|
378 | } |
---|
379 | } |
---|
380 | %> |
---|
381 | Link.addNewSection(members, new Section('R', 'Roles')); |
---|
382 | <% |
---|
383 | if (roleQuery != null) |
---|
384 | { |
---|
385 | ItemResultList<Role> roles = roleQuery.list(dc); |
---|
386 | for (Role role : roles) |
---|
387 | { |
---|
388 | %> |
---|
389 | Link.addNewItem(members, new Item('R', <%=role.getId()%>, '<%=HTML.javaScriptEncode(role.getName())%>')); |
---|
390 | <% |
---|
391 | } |
---|
392 | } |
---|
393 | %> |
---|
394 | } |
---|
395 | function addRolesOnClick() |
---|
396 | { |
---|
397 | var roles = Link.getListIds(document.forms['user'].membership, 'R'); |
---|
398 | var url = '../roles/index.jsp?ID=<%=ID%>&cmd=UpdateContext&mode=selectmultiple&callback=addRoleCallback'; |
---|
399 | url += '&exclude='+roles.join(','); |
---|
400 | Main.openPopup(url, 'AddRoles', 1000, 700); |
---|
401 | } |
---|
402 | function addRoleCallback(roleId, name) |
---|
403 | { |
---|
404 | var item = Link.getItem('R', roleId); |
---|
405 | if (!item) item = new Item('R', roleId, name); |
---|
406 | Link.addItem(document.forms['user'].membership, item); |
---|
407 | } |
---|
408 | function addGroupsOnClick() |
---|
409 | { |
---|
410 | var groups = Link.getListIds(document.forms['user'].membership, 'G'); |
---|
411 | var url = '../groups/index.jsp?ID=<%=ID%>&cmd=UpdateContext&mode=selectmultiple&callback=addGroupCallback'; |
---|
412 | url += '&exclude='+groups.join(','); |
---|
413 | Main.openPopup(url, 'AddGroups', 1000, 700); |
---|
414 | } |
---|
415 | function addGroupCallback(groupId, name) |
---|
416 | { |
---|
417 | var item = Link.getItem('G', groupId); |
---|
418 | if (!item) item = new Item('G', groupId, name); |
---|
419 | Link.addItem(document.forms['user'].membership, item); |
---|
420 | } |
---|
421 | function removeOnClick() |
---|
422 | { |
---|
423 | Link.removeSelected(document.forms['user'].membership); |
---|
424 | } |
---|
425 | |
---|
426 | </script> |
---|
427 | </base:head> |
---|
428 | <base:body onload="init()"> |
---|
429 | <p> |
---|
430 | <form action="index.jsp?ID=<%=ID%>" method="post" name="user" onsubmit="return false;"> |
---|
431 | <input type="hidden" name="cmd" value="UpdateItem"> |
---|
432 | |
---|
433 | <h3 class="docked"><%=title%> <base:help tabcontrol="settings" /></h3> |
---|
434 | <t:tabcontrol id="settings" contentstyle="<%="height: "+(int)(scale*300)+"px;"%>" |
---|
435 | position="bottom" remember="<%=user != null%>" |
---|
436 | extensions="<%=invoker%>"> |
---|
437 | <t:tab id="info" title="User" validate="validateUser()" helpid="user.edit"> |
---|
438 | <table class="form" cellspacing=0> |
---|
439 | <tr> |
---|
440 | <td class="prompt">Name</td> |
---|
441 | <td colspan="2"><input <%=requiredClazz%> type="text" name="name" |
---|
442 | value="<%=HTML.encodeTags(user == null ? Values.getString(cc.getPropertyValue("name"), "New user") : user.getName())%>" |
---|
443 | size="40" maxlength="<%=User.MAX_NAME_LENGTH%>"></td> |
---|
444 | </tr> |
---|
445 | |
---|
446 | <tr> |
---|
447 | <td class="prompt">Login</td> |
---|
448 | <td colspan="2"><input <%=requiredClazz%> type="text" name="login" |
---|
449 | value="<%=HTML.encodeTags(user == null ? cc.getPropertyValue("login") : user.getLogin())%>" |
---|
450 | size="40" maxlength="<%=User.MAX_LOGIN_LENGTH%>"></td> |
---|
451 | </tr> |
---|
452 | <tr> |
---|
453 | <td class="prompt">External ID</td> |
---|
454 | <td colspan="2"><input <%=clazz%> type="text" name="external_id" |
---|
455 | value="<%=HTML.encodeTags(user == null ? cc.getPropertyValue("externalId") : user.getExternalId())%>" |
---|
456 | size="40" maxlength="<%=User.MAX_EXTERNAL_ID_LENGTH%>"></td> |
---|
457 | </tr> |
---|
458 | <tr> |
---|
459 | <td class="prompt">New password</td> |
---|
460 | <td colspan="2"><input <%=itemId == 0 ? requiredClazz : clazz%> type="password" name="new_password" value="" size="30" maxlength="30"></td> |
---|
461 | </tr> |
---|
462 | <tr> |
---|
463 | <td class="prompt">Retype password</td> |
---|
464 | <td colspan="2"><input <%=itemId == 0 ? requiredClazz : clazz%> type="password" name="retype_password" value="" size="30" maxlength="30"></td> |
---|
465 | </tr> |
---|
466 | <tr valign="top"> |
---|
467 | <td class="prompt">Quota</td> |
---|
468 | <td colspan="2"> |
---|
469 | <select name="quota_id" <%=!useQuota ? "disabled readonly class=\"disabled\"" : "class=\"required\""%>> |
---|
470 | <% |
---|
471 | if (!readQuota) |
---|
472 | { |
---|
473 | %> |
---|
474 | <option value="-1">- denied - |
---|
475 | <% |
---|
476 | } |
---|
477 | ItemResultList<Quota> quotas = quotaQuery.list(dc); |
---|
478 | for (Quota quota : quotas) |
---|
479 | { |
---|
480 | boolean current = quota.equals(currentQuota); |
---|
481 | if (!current && quota.isRemoved()) continue; |
---|
482 | int id = quota.getId(); |
---|
483 | long totalBytes = quota.getQuotaValue(total, Location.PRIMARY); |
---|
484 | String fTotal = totalBytes == Quota.UNLIMITED ? "unlimited" : Values.formatBytes(totalBytes); |
---|
485 | %> |
---|
486 | <option |
---|
487 | value="<%=current && user != null ? -id : id%>" |
---|
488 | <%=current ? "selected" : ""%> |
---|
489 | ><%=HTML.encodeTags(quota.getName())%> (<%=fTotal%> total) |
---|
490 | <% |
---|
491 | } |
---|
492 | %> |
---|
493 | </td> |
---|
494 | </tr> |
---|
495 | <tr valign="top"> |
---|
496 | <td class="prompt">Quota group</td> |
---|
497 | <td colspan="2"> |
---|
498 | <select name="quotagroup_id" <%=!useGroups ? "disabled readonly class=\"disabled\"" : ""%>> |
---|
499 | <% |
---|
500 | if (!readGroups) |
---|
501 | { |
---|
502 | %> |
---|
503 | <option value="-1">- denied - |
---|
504 | <% |
---|
505 | } |
---|
506 | else |
---|
507 | { |
---|
508 | %> |
---|
509 | <option value="0">- none - |
---|
510 | <% |
---|
511 | ItemResultList<Group> quotaGroups = quotaGroupQuery.list(dc); |
---|
512 | for (Group quotaGroup : quotaGroups) |
---|
513 | { |
---|
514 | boolean current = quotaGroup.equals(currentQuotaGroup); |
---|
515 | if (!current && quotaGroup.isRemoved()) continue; |
---|
516 | int id = quotaGroup.getId(); |
---|
517 | Quota quota = quotaGroup.getQuota(); |
---|
518 | long totalBytes = quota.getQuotaValue(total, Location.PRIMARY); |
---|
519 | String fTotal = totalBytes == Quota.UNLIMITED ? "unlimited" : Values.formatBytes(totalBytes); |
---|
520 | %> |
---|
521 | <option |
---|
522 | value="<%=current && user != null ? -id : id %>" |
---|
523 | <%=current ? "selected" : ""%> |
---|
524 | ><%=HTML.encodeTags(quotaGroup.getName())%> (<%=fTotal%> total) |
---|
525 | <% |
---|
526 | } |
---|
527 | } |
---|
528 | %> |
---|
529 | </td> |
---|
530 | </tr> |
---|
531 | <tr valign="top"> |
---|
532 | <td class="prompt">Home directory</td> |
---|
533 | <td colspan="2"> |
---|
534 | <select name="homedirectory_id" <%=!readDirectories ? "disabled readonly class=\"disabled\"" : ""%>> |
---|
535 | <% |
---|
536 | if (!readDirectories) |
---|
537 | { |
---|
538 | %> |
---|
539 | <option value="-1">- denied - |
---|
540 | <% |
---|
541 | } |
---|
542 | else |
---|
543 | { |
---|
544 | %> |
---|
545 | <option value="0">- none - |
---|
546 | <% |
---|
547 | if (createDirectories && user == null) |
---|
548 | { |
---|
549 | %> |
---|
550 | <option value="new">- create new (empty) - |
---|
551 | <option value="template" selected>- create new from template - |
---|
552 | <% |
---|
553 | } |
---|
554 | ItemResultList<Directory> directories = directoryQuery.list(dc); |
---|
555 | for (Directory d : directories) |
---|
556 | { |
---|
557 | int id = d.getId(); |
---|
558 | boolean current = d.equals(homeDirectory); |
---|
559 | if (!current && d.isRemoved()) continue; |
---|
560 | %> |
---|
561 | <option |
---|
562 | value="<%=current && user != null ? -id : id%>" |
---|
563 | <%=current ? "selected" : ""%> |
---|
564 | ><%=HTML.encodeTags(d.getName())%> |
---|
565 | <% |
---|
566 | } |
---|
567 | } |
---|
568 | %> |
---|
569 | </td> |
---|
570 | </tr> |
---|
571 | <tr> |
---|
572 | <td class="prompt">Expiration date</td> |
---|
573 | <td> |
---|
574 | <input <%=clazz%> type="text" name="expiration_date" |
---|
575 | value="<%=HTML.encodeTags(dateFormatter.format( |
---|
576 | user == null ? (Date)cc.getPropertyObject("expirationDate") : user.getExpirationDate()) |
---|
577 | )%>" |
---|
578 | size="20" maxlength="20" title="Enter date in format: <%=htmlDateFormat%>"> |
---|
579 | </td> |
---|
580 | <td> |
---|
581 | <base:button |
---|
582 | onclick="<%="Dates.selectDate('Expiration date', 'user', 'expiration_date', null, '"+jsDateFormat + "')"%>" |
---|
583 | image="calendar.png" |
---|
584 | title="Calendar…" |
---|
585 | tooltip="Select a date from a calendar" |
---|
586 | /> |
---|
587 | </td> |
---|
588 | </tr> |
---|
589 | <tr> |
---|
590 | <td class="prompt">Multi-user account</td> |
---|
591 | <td colspan="2"><input type="checkbox" name="multiuser_account" value="1" |
---|
592 | <%=(user != null && user.isMultiuserAccount()) || |
---|
593 | (user == null && Values.getBoolean(cc.getPropertyValue("multiuserAccount"))) ? "checked" : ""%>></td> |
---|
594 | </tr> |
---|
595 | <tr> |
---|
596 | <td class="prompt">Disabled</td> |
---|
597 | <td colspan="2"><input type="checkbox" name="disabled" value="1" |
---|
598 | <%=(user != null && user.isDisabled()) || |
---|
599 | (user == null && Values.getBoolean(cc.getPropertyValue("disabled"))) ? "checked" : ""%>></td> |
---|
600 | </tr> |
---|
601 | |
---|
602 | </table> |
---|
603 | <div align=right> <i><base:icon image="required.gif" /> = required information</i></div> |
---|
604 | </t:tab> |
---|
605 | |
---|
606 | <t:tab id="contact" title="Contact information" |
---|
607 | tooltip="Email, adress, organisation, etc." validate="validateContact()" helpid="user.edit.contact"> |
---|
608 | <table class="form" cellspacing=0> |
---|
609 | <tr> |
---|
610 | <td class="prompt">Email</td> |
---|
611 | <td><input <%=clazz%> type="text" name="email" |
---|
612 | value="<%=HTML.encodeTags(user == null ? cc.getPropertyValue("email") : user.getEmail())%>" |
---|
613 | size="40" maxlength="<%=User.MAX_EMAIL_LENGTH%>"></td> |
---|
614 | </tr> |
---|
615 | <tr> |
---|
616 | <td class="prompt">Organisation</td> |
---|
617 | <td><input <%=clazz%> type="text" name="organisation" |
---|
618 | value="<%=HTML.encodeTags(user == null ? cc.getPropertyValue("organisation") : user.getOrganisation())%>" |
---|
619 | size="40" maxlength="<%=User.MAX_ORGANISATION_LENGTH%>"></td> |
---|
620 | </tr> |
---|
621 | <tr valign="top"> |
---|
622 | <td class="prompt">Address</td> |
---|
623 | <td> |
---|
624 | <textarea <%=clazz%> rows="4" cols="40" name="address" |
---|
625 | wrap="off"><%=HTML.encodeTags(user == null ? cc.getPropertyValue("address") : user.getAddress())%></textarea> |
---|
626 | <a href="javascript:Main.zoom('Address', 'user', 'address')" title="Edit in larger window"><base:icon image="zoom.gif" /></a> |
---|
627 | </td> |
---|
628 | </tr> |
---|
629 | <tr> |
---|
630 | <td class="prompt">Phone</td> |
---|
631 | <td><input <%=clazz%> type="text" name="phone" |
---|
632 | value="<%=HTML.encodeTags(user == null ? cc.getPropertyValue("phone") : user.getPhone())%>" |
---|
633 | size="40" maxlength="<%=User.MAX_PHONE_LENGTH%>"></td> |
---|
634 | </tr> |
---|
635 | <tr> |
---|
636 | <td class="prompt">Fax</td> |
---|
637 | <td><input <%=clazz%> type="text" name="fax" |
---|
638 | value="<%=HTML.encodeTags(user == null ? cc.getPropertyValue("fax") : user.getFax())%>" |
---|
639 | size="40" maxlength="<%=User.MAX_FAX_LENGTH%>"></td> |
---|
640 | </tr> |
---|
641 | <tr> |
---|
642 | <td class="prompt">Url</td> |
---|
643 | <td><input <%=clazz%> type="text" name="url" |
---|
644 | value="<%=HTML.encodeTags(user == null ? cc.getPropertyValue("url") : user.getUrl())%>" |
---|
645 | size="40" maxlength="<%=User.MAX_URL_LENGTH%>"></td> |
---|
646 | </tr> |
---|
647 | <tr valign="top"> |
---|
648 | <td class="prompt">Description</td> |
---|
649 | <td nowrap> |
---|
650 | <textarea <%=clazz%> rows="4" cols="40" name="description" |
---|
651 | wrap="virtual"><%=HTML.encodeTags(user == null ? cc.getPropertyValue("description") : user.getDescription())%></textarea> |
---|
652 | <a href="javascript:Main.zoom('Description', 'user', 'description')" title="Edit in larger window"><base:icon image="zoom.gif" /></a> |
---|
653 | </td> |
---|
654 | </tr> |
---|
655 | </table> |
---|
656 | </t:tab> |
---|
657 | <% |
---|
658 | if (extendedProperties != null) |
---|
659 | { |
---|
660 | %> |
---|
661 | <t:tab id="extended" title="Additional info" |
---|
662 | validate="validateExtendedProperties()" helpid="user.edit.additional"> |
---|
663 | <table class="form" cellspacing="0"> |
---|
664 | <% |
---|
665 | for (ExtendedProperty ep : ExtendedProperties.getProperties("UserData")) |
---|
666 | { |
---|
667 | String name = ep.getName(); |
---|
668 | Type type = ep.getType(); |
---|
669 | boolean required = !ep.isNullable(); |
---|
670 | Object value = user == null ? cc.getPropertyValue(name) : user.getExtended(name); |
---|
671 | String theClazz = required ? requiredClazz : clazz; |
---|
672 | %> |
---|
673 | <tr valign="top"> |
---|
674 | <td class="prompt"><%=HTML.encodeTags(ep.getTitle())%></td> |
---|
675 | <td> |
---|
676 | <% |
---|
677 | if (type == Type.INT || type == Type.LONG) |
---|
678 | { |
---|
679 | %> |
---|
680 | <input <%=theClazz%> type="text" name="<%=name%>" |
---|
681 | value="<%=value == null ? "" : value%>" |
---|
682 | size="20" maxlength="20" onkeypress="return Numbers.integerOnly(event)" |
---|
683 | > |
---|
684 | <% |
---|
685 | } |
---|
686 | else if (type == Type.FLOAT || type == Type.DOUBLE) |
---|
687 | { |
---|
688 | %> |
---|
689 | <input <%=theClazz%> type="text" name="<%=name%>" |
---|
690 | value="<%=value == null ? "" : value%>" |
---|
691 | size="20" maxlength="20" onkeypress="return Numbers.numberOnly(event)" |
---|
692 | > |
---|
693 | <% |
---|
694 | } |
---|
695 | else if (type == Type.STRING) |
---|
696 | { |
---|
697 | %> |
---|
698 | <input <%=theClazz%> type="text" name="<%=name%>" |
---|
699 | value="<%=HTML.encodeTags((String)value)%>" |
---|
700 | size="40" maxlength="<%=ep.getLength()%>" |
---|
701 | > |
---|
702 | <% |
---|
703 | } |
---|
704 | else if (type == Type.TEXT) |
---|
705 | { |
---|
706 | %> |
---|
707 | <textarea <%=theClazz%> name="<%=name%>" rows="6" cols="40" |
---|
708 | ><%=HTML.encodeTags((String)value)%></textarea> |
---|
709 | <a href="javascript:Main.zoom( |
---|
710 | '<%=HTML.javaScriptEncode(ep.getTitle())%>', |
---|
711 | 'user', '<%=name%>')" |
---|
712 | title="Edit in larger window"><base:icon image="zoom.gif" /></a> |
---|
713 | <% |
---|
714 | } |
---|
715 | else if (type == Type.BOOLEAN) |
---|
716 | { |
---|
717 | Boolean b = (Boolean)value; |
---|
718 | if (!required) |
---|
719 | { |
---|
720 | %> |
---|
721 | <input type="radio" name="<%=name%>" value="" |
---|
722 | <%=b == null ? "checked" : ""%> |
---|
723 | ><i>- not specified -</i><br> |
---|
724 | <% |
---|
725 | } |
---|
726 | %> |
---|
727 | <input type="radio" name="<%=name%>" value="true" |
---|
728 | <%=b != null && b == true ? "checked" : ""%> |
---|
729 | >true<br> |
---|
730 | <input type="radio" name="<%=name%>" value="false" |
---|
731 | <%=b != null && b == false ? "checked" : ""%> |
---|
732 | >false |
---|
733 | <% |
---|
734 | } |
---|
735 | else if (type == Type.DATE) |
---|
736 | { |
---|
737 | %> |
---|
738 | <table> |
---|
739 | <tr> |
---|
740 | <td> |
---|
741 | <input <%=theClazz%> type="text" name="<%=name%>" |
---|
742 | value="<%=dateFormatter.format((Date)value)%>" |
---|
743 | size="20" maxlength="20" title="Enter date in format: <%=htmlDateFormat%>" |
---|
744 | > |
---|
745 | </td> |
---|
746 | <td> |
---|
747 | <base:button |
---|
748 | onclick="<%="Dates.selectDate('"+HTML.javaScriptEncode(ep.getTitle())+"', 'user', '"+name+"', null, '"+jsDateFormat +"')"%>" |
---|
749 | image="calendar.png" |
---|
750 | title="Calendar…" |
---|
751 | tooltip="Select a date from a calendar" |
---|
752 | /> |
---|
753 | </td> |
---|
754 | </tr> |
---|
755 | </table> |
---|
756 | <% |
---|
757 | } |
---|
758 | else if (type == Type.TIMESTAMP) |
---|
759 | { |
---|
760 | %> |
---|
761 | <table> |
---|
762 | <tr> |
---|
763 | <td> |
---|
764 | <input <%=theClazz%> type="text" name="<%=name%>" |
---|
765 | value="<%=dateTimeFormatter.format((Date)value)%>" |
---|
766 | size="20" maxlength="20" title="Enter timestamp in format: <%=htmlDateTimeFormat%>" |
---|
767 | > |
---|
768 | </td> |
---|
769 | <td> |
---|
770 | <base:button |
---|
771 | onclick="<%="Dates.selectDateTime('"+HTML.javaScriptEncode(ep.getTitle())+"', 'user', '"+name+"', null, '"+jsDateTimeFormat +"')"%>" |
---|
772 | image="calendar.png" |
---|
773 | title="Calendar…" |
---|
774 | tooltip="Select a timestamp from a calendar" |
---|
775 | /> |
---|
776 | </td> |
---|
777 | </tr> |
---|
778 | </table> |
---|
779 | <% |
---|
780 | } |
---|
781 | %> |
---|
782 | </td> |
---|
783 | </tr> |
---|
784 | <% |
---|
785 | } |
---|
786 | %> |
---|
787 | </table> |
---|
788 | </t:tab> |
---|
789 | <% |
---|
790 | } |
---|
791 | %> |
---|
792 | <t:tab id="members" title="Membership" tooltip="Manage group and role membership" |
---|
793 | validate="validateMembership()" helpid="user.edit.membership"> |
---|
794 | <table > |
---|
795 | <tr valign="top"> |
---|
796 | <td> |
---|
797 | <b>Member in</b><br> |
---|
798 | <select name="membership" size="15" multiple <%=!writeMembership ? "disabled readonly class=\"disabled\"" : ""%> style="width: 15em;"> |
---|
799 | </select> |
---|
800 | <input type="hidden" name="removeGroups" value=""> |
---|
801 | <input type="hidden" name="addGroups" value=""> |
---|
802 | <input type="hidden" name="removeRoles" value=""> |
---|
803 | <input type="hidden" name="addRoles" value=""> |
---|
804 | </td> |
---|
805 | <td> |
---|
806 | <br> |
---|
807 | <table width="150"> |
---|
808 | <tr><td><base:button |
---|
809 | clazz="leftaligned buttonclass" |
---|
810 | onclick="addGroupsOnClick()" |
---|
811 | title="Add groups…" |
---|
812 | tooltip="Add groups to this user" |
---|
813 | disabled="<%=!writeMembership %>" |
---|
814 | /></td></tr> |
---|
815 | <tr><td><base:button |
---|
816 | clazz="leftaligned buttonclass" |
---|
817 | onclick="addRolesOnClick()" |
---|
818 | title="Add roles…" |
---|
819 | tooltip="Add roles to this user" |
---|
820 | disabled="<%=!writeMembership %>" |
---|
821 | /></td></tr> |
---|
822 | <tr><td><base:button |
---|
823 | clazz="leftaligned buttonclass" |
---|
824 | onclick="removeOnClick()" |
---|
825 | title="Remove" |
---|
826 | tooltip="Remove the user from the selected items" |
---|
827 | disabled="<%=!writeMembership%>" |
---|
828 | /></td></tr> |
---|
829 | </table> |
---|
830 | </td> |
---|
831 | </tr> |
---|
832 | </table> |
---|
833 | |
---|
834 | </t:tab> |
---|
835 | </t:tabcontrol> |
---|
836 | |
---|
837 | <table align="center"> |
---|
838 | <tr> |
---|
839 | <td width="50%"><base:button onclick="saveSettings()" title="Save" /></td> |
---|
840 | <td width="50%"><base:button onclick="window.close()" title="Cancel" /></td> |
---|
841 | </tr> |
---|
842 | </table> |
---|
843 | </form> |
---|
844 | </base:body> |
---|
845 | </base:page> |
---|
846 | <% |
---|
847 | } |
---|
848 | finally |
---|
849 | { |
---|
850 | if (dc != null) dc.close(); |
---|
851 | } |
---|
852 | %> |
---|