8d347a33 |
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 %> |
1fe415e0 |
9 | <h3>Invalid username</h3> |
8d347a33 |
10 | <% else switch Init.userNameToId ($"name") of |
11 | SOME _ => %> |
1fe415e0 |
12 | <h3>Username already in use</h3> |
8d347a33 |
13 | <% | NONE => |
5146e435 |
14 | val ap = Web.stoi ($"app"); |
8d347a33 |
15 | val bal = |
16 | (case $"bal" of |
17 | "" => Balance.addBalance ($"name") |
18 | | s => Web.stoi s); |
19 | |
892e3ea1 |
20 | val id = Init.addUser ($"name", $"rname", bal, ap, 1); |
4b8df0b1 |
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 |
31b85852 |
31 | if not (Pref.subscribe ("hcoop-announce", $"name" ^ Init.emailSuffix)) then |
1fe415e0 |
32 | %><h3>Error subscribing to hcoop-announce</h3><% |
4b8df0b1 |
33 | end |
cee714e2 |
34 | end; |
35 | |
36 | if $"nomail" = "" then |
37 | App.welcome ap |
38 | end |
39 | |
40 | %><h3>Member added</h3> |
8d347a33 |
41 | <% end |
42 | end |
43 | elseif $"mod" <> "" then |
44 | showNormal := false; |
45 | val user = Init.lookupUser (Web.stoi ($"mod")) %> |
1fe415e0 |
46 | <h3>Modify member record</h3> |
8d347a33 |
47 | |
add44c00 |
48 | <form action="users" method="post"> |
8d347a33 |
49 | <input type="hidden" name="id" value="<% $"mod" %>"> |
1fe415e0 |
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"> |
8d347a33 |
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")} %> |
1fe415e0 |
65 | <h3>Member record saved.</h3> |
8d347a33 |
66 | |
67 | <% elseif $"del" <> "" then |
68 | showNormal := false; |
69 | val user = Init.lookupUser (Web.stoi ($"del")) %> |
1fe415e0 |
70 | <h3>Are you sure you want to delete member <a href="user?id=<% #id user %>"><% #name user %></a>?</h3> |
8d347a33 |
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")) %> |
1fe415e0 |
76 | <h3><% #name user %> deleted!</h3> |
8d347a33 |
77 | |
5146e435 |
78 | <% elseif $"cmd" = "grandfather" then |
79 | Init.grandfatherUsers() |
1fe415e0 |
80 | %><h3>Grandfathered</h3> |
5146e435 |
81 | |
ef48ed9e |
82 | <% elseif $"cmd" = "addform" then |
83 | showNormal := false %> |
1fe415e0 |
84 | <h3>New member</h3> |
8d347a33 |
85 | |
add44c00 |
86 | <form action="users" method="post"> |
1fe415e0 |
87 | <table class="blanks"> |
88 | <tr> <td>Name:</td> <td><input name="name"></td> </tr> |
89 | <tr> <td>Real name:</td> <td><input name="rname"></td> </tr> |
90 | <tr> <td>Funded by:</td> <td><select name="bal"> |
8d347a33 |
91 | <option value="">A new balance</option> |
92 | <% foreach bal in Balance.listBalances () do %> |
93 | <option value="<% #id bal %>"><% Web.html (#name bal) %></option> |
94 | <% end %> |
95 | </select></td></tr> |
1fe415e0 |
96 | <tr> <td>Initial transaction amount:</td> <td><input name="amount"></td> </tr> |
97 | <tr> <td>Initial transaction description:</td> <td><input name="descr"></td> </tr> |
98 | <tr> <td><input type="checkbox" name="subscribe" checked></td> <td>Subscribe to hcoop-announce</td> </tr> |
99 | <tr> <td>Groups:</td> <td><select name="grp" size="5" multiple> |
8d347a33 |
100 | <% foreach group in Group.listGroups () do %> |
f98251aa |
101 | <option value="<% #id group %>"<% if #name group = "paying" then %> selected<% end %>><% Web.html (#name group) %></option> |
8d347a33 |
102 | <% end %> |
103 | </select></td></tr> |
104 | <tr> <td><input type="submit" name="cmd" value="Create"></td> </tr> |
105 | </table> |
106 | </form> |
107 | |
da3f3cbc |
108 | <% elseif $"cmd" = "unmigrated" then |
109 | showNormal := false; |
270da709 |
110 | ref negative = 0; |
da3f3cbc |
111 | val users = Init.unmigratedUsers () %> |
112 | |
113 | <h3>Unmigrated members (<% length users %>)</h3> |
114 | |
115 | <table> |
116 | <% foreach user in users do %> |
270da709 |
117 | <tr> <td><a href="user?id=<% #id user %>"><% Web.html (#name user) %></a></td> |
da3f3cbc |
118 | <% val bal = Balance.lookupBalance (#bal user); |
270da709 |
119 | if Balance.isNegative bal then |
120 | negative := negative + 1 |
121 | end %> |
122 | <td><% #amount bal %></td><td> |
123 | <%if #name bal <> #name user then %> |
124 | <i><% Web.html (#name bal) %></i> |
da3f3cbc |
125 | <% end %> |
270da709 |
126 | </td> </tr> |
da3f3cbc |
127 | <% end %> |
128 | </table> |
129 | |
270da709 |
130 | <p><% negative %> have negative balances.</p> |
131 | |
9fe97917 |
132 | <% elseif $"cmd" = "diff" then |
133 | showNormal := false; |
134 | |
135 | val against = (case $"against" of |
136 | "" => Init.usersInAfs () |
137 | | x => String.tokens Char.isSpace x); |
138 | |
139 | val diff = Init.usersDiff (Init.listUsernames (), against) %> |
140 | |
141 | <h3>User diff</h3> |
142 | |
143 | <h4>Only on the portal:</h4> |
144 | <ul> |
145 | <% foreach user in #onlyInFirst diff do %> |
146 | <li> <a href="user?id=<% valOf (Init.userNameToId user) %>"><% Web.html user %></a></li> |
147 | <% end %> |
148 | </ul> |
149 | |
150 | <h4>Only in AFS:</h4> |
151 | <ul> |
152 | <% foreach user in #onlyInSecond diff do %> |
153 | <li> <% Web.html user %></li> |
154 | <% end %> |
155 | </ul> |
156 | |
ef48ed9e |
157 | <% end %> |
158 | |
159 | <% if showNormal then %> |
160 | |
161 | <a href="users?cmd=addform">Add a user manually</a><br> |
162 | |
1fe415e0 |
163 | <h3>Manage current members</h3> |
8d347a33 |
164 | |
165 | <table> |
166 | <% foreach user in Init.listUsers () do %> |
167 | <tr> <td><a href="user?id=<% #id user %>"><% Web.html (#name user) %></a></td> <td> |
168 | <% val bal = Balance.lookupBalance (#bal user); |
169 | if #name bal <> #name user then %> |
170 | <i><% Web.html (#name bal) %></i> |
171 | <% end %> |
172 | </td><td><a href="users?mod=<% #id user %>">[Modify]</a> <a href="users?del=<% #id user %>">[Delete]</a></td> </tr> |
173 | <% end %> |
174 | </table> |
175 | |
5146e435 |
176 | <br><a href="users?cmd=grandfather">Grandfather old users to have applications</a><br> |
da3f3cbc |
177 | <a href="users?cmd=unmigrated">Who hasn't migrated yet?</a><br> |
9fe97917 |
178 | <a href="users?cmd=diff">How does the set of users in AFS compare with the set of active portal users?</a><br> |
5146e435 |
179 | |
8d347a33 |
180 | <% end %> |
181 | |
182 | <% @footer [] %> |