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 | ||
30 | if $"subscribe" = "on" then | |
e84acecc | 31 | if not (Pref.subscribe ("hcoop-announce", $"name" ^ Init.emailSuffix)) then |
b6dd1aaf | 32 | %><h3>Error subscribing to hcoop-announce</h3><% |
98a5f121 | 33 | end |
688bf30c AC |
34 | end; |
35 | ||
36 | if $"nomail" = "" then | |
37 | App.welcome ap | |
38 | end | |
39 | ||
40 | %><h3>Member added</h3> | |
208e2cbc AC |
41 | <% end |
42 | end | |
43 | elseif $"mod" <> "" then | |
44 | showNormal := false; | |
45 | val user = Init.lookupUser (Web.stoi ($"mod")) %> | |
b6dd1aaf | 46 | <h3>Modify member record</h3> |
208e2cbc | 47 | |
a4ccdb5e | 48 | <form action="users" method="post"> |
208e2cbc | 49 | <input type="hidden" name="id" value="<% $"mod" %>"> |
b6dd1aaf AC |
50 | <table class="blanks"> |
51 | <tr> <td>Name:</td> <td><input name="name" value="<% #name user %>"></td> </tr> | |
52 | <tr> <td>Real name:</td> <td><input name="rname" value="<% #rname user %>"></td> </tr> | |
53 | <tr> <td>Funded by:</td> <td><select name="bal"> | |
208e2cbc AC |
54 | <% foreach bal in Balance.listBalances () do %> |
55 | <option value="<% #id bal %>"<% if #bal user = #id bal then %> selected <% end %>><% Web.html (#name bal) %></option> | |
56 | <% end %> | |
57 | </select></td></tr> | |
58 | <tr> <td><input type="submit" name="cmd" value="Save"></td> </tr> | |
59 | </table> | |
60 | </form> | |
61 | ||
62 | <% elseif $"cmd" = "Save" then | |
63 | val user = Init.lookupUser (Web.stoi ($"id")); | |
64 | Init.modUser {user with name = $"name", bal = Web.stoi ($"bal")} %> | |
b6dd1aaf | 65 | <h3>Member record saved.</h3> |
208e2cbc AC |
66 | |
67 | <% elseif $"del" <> "" then | |
68 | showNormal := false; | |
69 | val user = Init.lookupUser (Web.stoi ($"del")) %> | |
b6dd1aaf | 70 | <h3>Are you sure you want to delete member <a href="user?id=<% #id user %>"><% #name user %></a>?</h3> |
208e2cbc AC |
71 | <a href="users?del2=<% $"del" %>">Yes, delete <% #name user %>!</a> |
72 | ||
73 | <% elseif $"del2" <> "" then | |
74 | val user = Init.lookupUser (Web.stoi ($"del2")); | |
75 | Init.deleteUser (Web.stoi ($"del2")) %> | |
b6dd1aaf | 76 | <h3><% #name user %> deleted!</h3> |
208e2cbc | 77 | |
c4c9e770 AC |
78 | <% elseif $"retire" <> "" then |
79 | showNormal := false; | |
80 | val user = Init.lookupUser (Web.stoi ($"retire")) %> | |
81 | <h3>Are you sure you want to retire member <a href="user?id=<% #id user %>"><% #name user %></a>?</h3> | |
82 | <a href="users?retire2=<% $"retire" %>">Yes, retire <% #name user %>!</a> | |
83 | ||
84 | <% elseif $"retire2" <> "" then | |
85 | val usr = Web.stoi ($"retire2"); | |
86 | val user = Init.lookupUser usr; | |
87 | switch (Group.groupNameToId "paying", Group.groupNameToId "retired") of | |
88 | (SOME paying, SOME retired) => | |
89 | Group.removeFromGroup {usr = usr, grp = paying}; | |
90 | Group.addToGroup {usr = usr, grp = retired} %> | |
91 | <h3><% #name user %> retired!</h3><% | |
92 | | _ => %><h3>Couldn't find "paying" or "retired" group by name!</h3><% | |
93 | end | |
94 | ||
95 | elseif $"cmd" = "grandfather" then | |
f3f3ad24 | 96 | Init.grandfatherUsers() |
b6dd1aaf | 97 | %><h3>Grandfathered</h3> |
f3f3ad24 | 98 | |
9095d20e AC |
99 | <% elseif $"cmd" = "addform" then |
100 | showNormal := false %> | |
b6dd1aaf | 101 | <h3>New member</h3> |
208e2cbc | 102 | |
a4ccdb5e | 103 | <form action="users" method="post"> |
b6dd1aaf AC |
104 | <table class="blanks"> |
105 | <tr> <td>Name:</td> <td><input name="name"></td> </tr> | |
106 | <tr> <td>Real name:</td> <td><input name="rname"></td> </tr> | |
107 | <tr> <td>Funded by:</td> <td><select name="bal"> | |
208e2cbc AC |
108 | <option value="">A new balance</option> |
109 | <% foreach bal in Balance.listBalances () do %> | |
110 | <option value="<% #id bal %>"><% Web.html (#name bal) %></option> | |
111 | <% end %> | |
112 | </select></td></tr> | |
b6dd1aaf AC |
113 | <tr> <td>Initial transaction amount:</td> <td><input name="amount"></td> </tr> |
114 | <tr> <td>Initial transaction description:</td> <td><input name="descr"></td> </tr> | |
115 | <tr> <td><input type="checkbox" name="subscribe" checked></td> <td>Subscribe to hcoop-announce</td> </tr> | |
116 | <tr> <td>Groups:</td> <td><select name="grp" size="5" multiple> | |
208e2cbc | 117 | <% foreach group in Group.listGroups () do %> |
9bda1e7f | 118 | <option value="<% #id group %>"<% if #name group = "paying" then %> selected<% end %>><% Web.html (#name group) %></option> |
208e2cbc AC |
119 | <% end %> |
120 | </select></td></tr> | |
121 | <tr> <td><input type="submit" name="cmd" value="Create"></td> </tr> | |
122 | </table> | |
123 | </form> | |
124 | ||
60754922 AC |
125 | <% elseif $"cmd" = "unmigrated" then |
126 | showNormal := false; | |
0dd4d4cb | 127 | ref negative = 0; |
60754922 AC |
128 | val users = Init.unmigratedUsers () %> |
129 | ||
130 | <h3>Unmigrated members (<% length users %>)</h3> | |
131 | ||
132 | <table> | |
133 | <% foreach user in users do %> | |
0dd4d4cb | 134 | <tr> <td><a href="user?id=<% #id user %>"><% Web.html (#name user) %></a></td> |
60754922 | 135 | <% val bal = Balance.lookupBalance (#bal user); |
0dd4d4cb AC |
136 | if Balance.isNegative bal then |
137 | negative := negative + 1 | |
138 | end %> | |
139 | <td><% #amount bal %></td><td> | |
140 | <%if #name bal <> #name user then %> | |
141 | <i><% Web.html (#name bal) %></i> | |
60754922 | 142 | <% end %> |
0dd4d4cb | 143 | </td> </tr> |
60754922 AC |
144 | <% end %> |
145 | </table> | |
146 | ||
0dd4d4cb AC |
147 | <p><% negative %> have negative balances.</p> |
148 | ||
59eb5381 AC |
149 | <% elseif $"cmd" = "diff" then |
150 | showNormal := false; | |
151 | ||
152 | val against = (case $"against" of | |
153 | "" => Init.usersInAfs () | |
154 | | x => String.tokens Char.isSpace x); | |
155 | ||
156 | val diff = Init.usersDiff (Init.listUsernames (), against) %> | |
157 | ||
158 | <h3>User diff</h3> | |
159 | ||
160 | <h4>Only on the portal:</h4> | |
161 | <ul> | |
162 | <% foreach user in #onlyInFirst diff do %> | |
163 | <li> <a href="user?id=<% valOf (Init.userNameToId user) %>"><% Web.html user %></a></li> | |
164 | <% end %> | |
165 | </ul> | |
166 | ||
167 | <h4>Only in AFS:</h4> | |
168 | <ul> | |
169 | <% foreach user in #onlyInSecond diff do %> | |
170 | <li> <% Web.html user %></li> | |
171 | <% end %> | |
172 | </ul> | |
173 | ||
9095d20e AC |
174 | <% end %> |
175 | ||
176 | <% if showNormal then %> | |
177 | ||
178 | <a href="users?cmd=addform">Add a user manually</a><br> | |
179 | ||
b6dd1aaf | 180 | <h3>Manage current members</h3> |
208e2cbc AC |
181 | |
182 | <table> | |
183 | <% foreach user in Init.listUsers () do %> | |
184 | <tr> <td><a href="user?id=<% #id user %>"><% Web.html (#name user) %></a></td> <td> | |
185 | <% val bal = Balance.lookupBalance (#bal user); | |
186 | if #name bal <> #name user then %> | |
187 | <i><% Web.html (#name bal) %></i> | |
188 | <% end %> | |
c4c9e770 AC |
189 | </td><td><a href="users?mod=<% #id user %>">[Modify]</a> <a href="users?del=<% #id user %>">[Delete]</a> |
190 | <a href="users?retire=<% #id user %>">[Retire]</a></td> </tr> | |
208e2cbc AC |
191 | <% end %> |
192 | </table> | |
193 | ||
f3f3ad24 | 194 | <br><a href="users?cmd=grandfather">Grandfather old users to have applications</a><br> |
60754922 | 195 | <a href="users?cmd=unmigrated">Who hasn't migrated yet?</a><br> |
59eb5381 | 196 | <a href="users?cmd=diff">How does the set of users in AFS compare with the set of active portal users?</a><br> |
f3f3ad24 | 197 | |
208e2cbc AC |
198 | <% end %> |
199 | ||
200 | <% @footer [] %> |