Commit | Line | Data |
---|---|---|
208e2cbc AC |
1 | <% Group.requireGroupNum 0; |
2 | ||
3 | @header [("title", ["Member management"])]; | |
4 | ||
5 | ref showNormal = true; | |
6 | ||
7 | if $"cmd" = "Create" then | |
8 | if not (Init.validUsername ($"name")) then %> | |
b6dd1aaf | 9 | <h3>Invalid username</h3> |
208e2cbc AC |
10 | <% else switch Init.userNameToId ($"name") of |
11 | SOME _ => %> | |
b6dd1aaf | 12 | <h3>Username already in use</h3> |
208e2cbc | 13 | <% | NONE => |
f3f3ad24 | 14 | val ap = Web.stoi ($"app"); |
208e2cbc AC |
15 | val bal = |
16 | (case $"bal" of | |
17 | "" => Balance.addBalance ($"name") | |
18 | | s => Web.stoi s); | |
19 | ||
aaa50197 | 20 | val id = Init.addUser ($"name", $"rname", bal, ap, 1); |
98a5f121 AC |
21 | Group.addToGroups (id, map Web.stoi (Web.getMultiParam "grp")); |
22 | ||
23 | if $"amount" <> "" then | |
24 | val amount = Web.stor ($"amount"); | |
25 | val trn = Money.addTransaction ($"descr", amount, Init.dateString ()); | |
26 | Money.addCharge {trn = trn, usr = id, amount = amount}; | |
27 | Money.applyCharges trn | |
28 | end; | |
29 | ||
96bd398e AC |
30 | App.add ap; |
31 | ||
98a5f121 | 32 | if $"subscribe" = "on" then |
e84acecc | 33 | if not (Pref.subscribe ("hcoop-announce", $"name" ^ Init.emailSuffix)) then |
b6dd1aaf | 34 | %><h3>Error subscribing to hcoop-announce</h3><% |
98a5f121 | 35 | end |
688bf30c AC |
36 | end; |
37 | ||
38 | if $"nomail" = "" then | |
39 | App.welcome ap | |
40 | end | |
41 | ||
42 | %><h3>Member added</h3> | |
208e2cbc AC |
43 | <% end |
44 | end | |
45 | elseif $"mod" <> "" then | |
46 | showNormal := false; | |
47 | val user = Init.lookupUser (Web.stoi ($"mod")) %> | |
b6dd1aaf | 48 | <h3>Modify member record</h3> |
208e2cbc | 49 | |
a4ccdb5e | 50 | <form action="users" method="post"> |
208e2cbc | 51 | <input type="hidden" name="id" value="<% $"mod" %>"> |
b6dd1aaf AC |
52 | <table class="blanks"> |
53 | <tr> <td>Name:</td> <td><input name="name" value="<% #name user %>"></td> </tr> | |
54 | <tr> <td>Real name:</td> <td><input name="rname" value="<% #rname user %>"></td> </tr> | |
55 | <tr> <td>Funded by:</td> <td><select name="bal"> | |
208e2cbc AC |
56 | <% foreach bal in Balance.listBalances () do %> |
57 | <option value="<% #id bal %>"<% if #bal user = #id bal then %> selected <% end %>><% Web.html (#name bal) %></option> | |
58 | <% end %> | |
59 | </select></td></tr> | |
60 | <tr> <td><input type="submit" name="cmd" value="Save"></td> </tr> | |
61 | </table> | |
62 | </form> | |
63 | ||
64 | <% elseif $"cmd" = "Save" then | |
65 | val user = Init.lookupUser (Web.stoi ($"id")); | |
66 | Init.modUser {user with name = $"name", bal = Web.stoi ($"bal")} %> | |
b6dd1aaf | 67 | <h3>Member record saved.</h3> |
208e2cbc AC |
68 | |
69 | <% elseif $"del" <> "" then | |
70 | showNormal := false; | |
71 | val user = Init.lookupUser (Web.stoi ($"del")) %> | |
b6dd1aaf | 72 | <h3>Are you sure you want to delete member <a href="user?id=<% #id user %>"><% #name user %></a>?</h3> |
208e2cbc AC |
73 | <a href="users?del2=<% $"del" %>">Yes, delete <% #name user %>!</a> |
74 | ||
75 | <% elseif $"del2" <> "" then | |
76 | val user = Init.lookupUser (Web.stoi ($"del2")); | |
77 | Init.deleteUser (Web.stoi ($"del2")) %> | |
b6dd1aaf | 78 | <h3><% #name user %> deleted!</h3> |
208e2cbc | 79 | |
c4c9e770 AC |
80 | <% elseif $"retire" <> "" then |
81 | showNormal := false; | |
82 | val user = Init.lookupUser (Web.stoi ($"retire")) %> | |
83 | <h3>Are you sure you want to retire member <a href="user?id=<% #id user %>"><% #name user %></a>?</h3> | |
84 | <a href="users?retire2=<% $"retire" %>">Yes, retire <% #name user %>!</a> | |
85 | ||
86 | <% elseif $"retire2" <> "" then | |
87 | val usr = Web.stoi ($"retire2"); | |
88 | val user = Init.lookupUser usr; | |
89 | switch (Group.groupNameToId "paying", Group.groupNameToId "retired") of | |
90 | (SOME paying, SOME retired) => | |
91 | Group.removeFromGroup {usr = usr, grp = paying}; | |
92 | Group.addToGroup {usr = usr, grp = retired} %> | |
93 | <h3><% #name user %> retired!</h3><% | |
94 | | _ => %><h3>Couldn't find "paying" or "retired" group by name!</h3><% | |
95 | end | |
96 | ||
3b54a666 | 97 | elseif $"cmd" = "addform" then |
9095d20e | 98 | showNormal := false %> |
b6dd1aaf | 99 | <h3>New member</h3> |
208e2cbc | 100 | |
a4ccdb5e | 101 | <form action="users" method="post"> |
b6dd1aaf AC |
102 | <table class="blanks"> |
103 | <tr> <td>Name:</td> <td><input name="name"></td> </tr> | |
104 | <tr> <td>Real name:</td> <td><input name="rname"></td> </tr> | |
105 | <tr> <td>Funded by:</td> <td><select name="bal"> | |
208e2cbc AC |
106 | <option value="">A new balance</option> |
107 | <% foreach bal in Balance.listBalances () do %> | |
108 | <option value="<% #id bal %>"><% Web.html (#name bal) %></option> | |
109 | <% end %> | |
110 | </select></td></tr> | |
b6dd1aaf AC |
111 | <tr> <td>Initial transaction amount:</td> <td><input name="amount"></td> </tr> |
112 | <tr> <td>Initial transaction description:</td> <td><input name="descr"></td> </tr> | |
113 | <tr> <td><input type="checkbox" name="subscribe" checked></td> <td>Subscribe to hcoop-announce</td> </tr> | |
114 | <tr> <td>Groups:</td> <td><select name="grp" size="5" multiple> | |
208e2cbc | 115 | <% foreach group in Group.listGroups () do %> |
9bda1e7f | 116 | <option value="<% #id group %>"<% if #name group = "paying" then %> selected<% end %>><% Web.html (#name group) %></option> |
208e2cbc AC |
117 | <% end %> |
118 | </select></td></tr> | |
119 | <tr> <td><input type="submit" name="cmd" value="Create"></td> </tr> | |
120 | </table> | |
121 | </form> | |
122 | ||
59eb5381 AC |
123 | <% elseif $"cmd" = "diff" then |
124 | showNormal := false; | |
125 | ||
126 | val against = (case $"against" of | |
127 | "" => Init.usersInAfs () | |
128 | | x => String.tokens Char.isSpace x); | |
129 | ||
130 | val diff = Init.usersDiff (Init.listUsernames (), against) %> | |
131 | ||
132 | <h3>User diff</h3> | |
133 | ||
134 | <h4>Only on the portal:</h4> | |
135 | <ul> | |
136 | <% foreach user in #onlyInFirst diff do %> | |
137 | <li> <a href="user?id=<% valOf (Init.userNameToId user) %>"><% Web.html user %></a></li> | |
138 | <% end %> | |
139 | </ul> | |
140 | ||
141 | <h4>Only in AFS:</h4> | |
142 | <ul> | |
143 | <% foreach user in #onlyInSecond diff do %> | |
144 | <li> <% Web.html user %></li> | |
145 | <% end %> | |
146 | </ul> | |
147 | ||
9095d20e AC |
148 | <% end %> |
149 | ||
150 | <% if showNormal then %> | |
151 | ||
152 | <a href="users?cmd=addform">Add a user manually</a><br> | |
3b54a666 CE |
153 | <% if $"showretired" = "1" then %> |
154 | <a href="users?showretired=0">Hide Retired Members</a><br> | |
155 | <% else %> | |
156 | <a href="users?showretired=1">Show Retired Members</a><br> | |
157 | <% end %> | |
9095d20e | 158 | |
b6dd1aaf | 159 | <h3>Manage current members</h3> |
208e2cbc | 160 | |
92855ded | 161 | <table class="data"> |
3b54a666 CE |
162 | <% foreach user in List.filter (fn u => ($"showretired" = "1") or not (Group.userInGroupName (#id u, "retired"))) (Init.listUsers ()) do %> |
163 | <tr> | |
164 | <td><a href="user?id=<% #id user %>"><% Web.html (#name user) %></a></td> | |
165 | <td> | |
208e2cbc AC |
166 | <% val bal = Balance.lookupBalance (#bal user); |
167 | if #name bal <> #name user then %> | |
168 | <i><% Web.html (#name bal) %></i> | |
169 | <% end %> | |
3b54a666 CE |
170 | </td> |
171 | <td><a href="users?mod=<% #id user %>">[Modify]</a> <a href="users?del=<% #id user %>">[Delete]</a> | |
172 | <a href="users?retire=<% #id user %>">[Retire]</a></td> | |
173 | </tr> | |
208e2cbc AC |
174 | <% end %> |
175 | </table> | |
176 | ||
3b54a666 | 177 | <br> |
59eb5381 | 178 | <a href="users?cmd=diff">How does the set of users in AFS compare with the set of active portal users?</a><br> |
f3f3ad24 | 179 | |
208e2cbc AC |
180 | <% end %> |
181 | ||
182 | <% @footer [] %> |