cvsimport
[hcoop/zz_old/portal.git] / groups.mlt
1 <% Group.requireGroupNum 0;
2
3 @header [("title", ["Group management"])];
4
5 ref showNormal = true;
6
7 if $"cmd" = "Create" then
8 if not (Group.validGroupName ($"name")) then %>
9 <h3>Invalid group name</h3>
10 <% else switch Group.groupNameToId ($"name") of
11 SOME _ => %>
12 <h3>Group name already in use</h3>
13 <% | NONE =>
14 val id = Group.addGroup ($"name") %>
15 <h3>Group added</h3>
16 <% end
17 end
18 elseif $"mod" <> "" then
19 showNormal := false;
20 val group = Group.lookupGroup (Web.stoi ($"mod")) %>
21 <h3>Modify group record</h3>
22
23 <form action="groups" method="post">
24 <input type="hidden" name="id" value="<% $"mod" %>">
25 <table class="blanks">
26 <tr> <td>Name:</td> <td><input name="name" value="<% #name group %>"></td> </tr>
27 <tr> <td><input type="submit" name="cmd" value="Save"></td> </tr>
28 </table>
29 </form>
30
31 <% elseif $"cmd" = "Save" then
32 val group = Group.lookupGroup (Web.stoi ($"id"));
33 Group.modGroup {group with name = $"name"} %>
34 <h3>Group record saved.</h3>
35
36 <% elseif $"del" <> "" then
37 showNormal := false;
38 val group = Group.lookupGroup (Web.stoi ($"del")) %>
39 <h3>Are you sure you want to delete group <% #name group %>?</h3>
40 <a href="groups?del2=<% $"del" %>">Yes, delete <% #name group %>!</a>
41
42 <% elseif $"del2" <> "" then
43 val group = Group.lookupGroup (Web.stoi ($"del2"));
44 Group.deleteGroup (Web.stoi ($"del2")) %>
45 <h3><% #name group %> deleted!</h3>
46
47 <% elseif $"cmd" = "Grant" then
48 Group.addToGroup {usr = Web.stoi ($"usr"), grp = Web.stoi ($"grp")} %>
49 <h3>Membership granted.</h3>
50
51 <% elseif $"revoke" <> "" then
52 Group.removeFromGroup {usr = Web.stoi ($"revoke"), grp = Web.stoi ($"grp")} %>
53 <h3>Membership revoked.</h3>
54
55 <% end %>
56
57 <% if showNormal then %>
58
59 <h3>Create group</h3>
60
61 <form action="groups" method="post">
62 <table class="blanks">
63 <tr> <td>Name:</td> <td><input name="name"></td> </tr>
64 <tr> <td><input type="submit" name="cmd" value="Create"></td> </tr>
65 </table>
66 </form>
67
68 <h3>Grant membership</h3>
69
70 <form action="groups" method="post">
71 <table class="blanks">
72 <tr> <td>Group:</td> <td><select name="grp">
73 <% foreach group in Group.listGroups () do %>
74 <option value="<% #id group %>"><% Web.html (#name group) %></option>
75 <% end %>
76 </select></td> </tr>
77 <tr> <td>Member:</td> <td><select name="usr">
78 <% foreach user in Init.listUsers () do %>
79 <option value="<% #id user %>"><% Web.html (#name user) %></option>
80 <% end %>
81 </select></td> </tr>
82 <tr> <td><input type="submit" name="cmd" value="Grant"></td> </tr>
83 </table>
84 </form>
85
86 <h3>Manage current groups</h3>
87
88 <table>
89 <% foreach group in Group.listGroups () do %>
90 <tr> <td><% Web.html (#name group) %></td> <td></td> <td><a href="groups?mod=<% #id group %>">[Modify]</a> <a href="groups?del=<% #id group %>">[Delete]</a></td> </tr>
91 <% foreach user in Group.groupMembers (#id group) do %>
92 <tr> <td></td> <td><a href="user?id=<% #id user %>"><% Web.html (#name user) %></a></td> <td><a href="groups?revoke=<% #id user %>&grp=<% #id group %>">[Revoke]</a></td> </tr>
93 <% end
94 end %>
95 </table>
96
97 <% end %>
98
99 <% @footer [] %>