1 <% Group.requireGroupNum 0;
3 @header [("title", ["Member management"])];
7 if $"cmd" = "Create" then
8 if not (Init.validUsername ($"name")) then %>
9 <h3>Invalid username</h3>
10 <% else switch Init.userNameToId ($"name") of
12 <h3>Username already in use</h3>
14 val ap = Web.stoi ($"app");
17 "" => Balance.addBalance ($"name")
20 val id = Init.addUser ($"name", $"rname", bal, ap, 1);
21 Group.addToGroups (id, map Web.stoi (Web.getMultiParam "grp"));
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
32 if $"subscribe" = "on" then
33 if not (Pref.subscribe ("hcoop-announce", $"name" ^ Init.emailSuffix)) then
34 %><h3>Error subscribing to hcoop-announce</h3><%
38 if $"nomail" = "" then
42 %><h3>Member added</h3>
45 elseif $"mod" <> "" then
47 val user = Init.lookupUser (Web.stoi ($"mod")) %>
48 <h3>Modify member record</h3>
50 <form action="users" method="post">
51 <input type="hidden" name="id" value="<% $"mod" %>">
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">
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>
60 <tr> <td><input type="submit" name="cmd" value="Save"></td> </tr>
64 <% elseif $"cmd" = "Save" then
65 val user = Init.lookupUser (Web.stoi ($"id"));
66 Init.modUser {user with name = $"name", bal = Web.stoi ($"bal")} %>
67 <h3>Member record saved.</h3>
69 <% elseif $"del" <> "" then
71 val user = Init.lookupUser (Web.stoi ($"del")) %>
72 <h3>Are you sure you want to delete member <a href="user?id=<% #id user %>"><% #name user %></a>?</h3>
73 <a href="users?del2=<% $"del" %>">Yes, delete <% #name user %>!</a>
75 <% elseif $"del2" <> "" then
76 val user = Init.lookupUser (Web.stoi ($"del2"));
77 Init.deleteUser (Web.stoi ($"del2")) %>
78 <h3><% #name user %> deleted!</h3>
80 <% elseif $"retire" <> "" then
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>
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><%
97 elseif $"cmd" = "grandfather" then
98 Init.grandfatherUsers()
99 %><h3>Grandfathered</h3>
101 <% elseif $"cmd" = "addform" then
102 showNormal := false %>
105 <form action="users" method="post">
106 <table class="blanks">
107 <tr> <td>Name:</td> <td><input name="name"></td> </tr>
108 <tr> <td>Real name:</td> <td><input name="rname"></td> </tr>
109 <tr> <td>Funded by:</td> <td><select name="bal">
110 <option value="">A new balance</option>
111 <% foreach bal in Balance.listBalances () do %>
112 <option value="<% #id bal %>"><% Web.html (#name bal) %></option>
115 <tr> <td>Initial transaction amount:</td> <td><input name="amount"></td> </tr>
116 <tr> <td>Initial transaction description:</td> <td><input name="descr"></td> </tr>
117 <tr> <td><input type="checkbox" name="subscribe" checked></td> <td>Subscribe to hcoop-announce</td> </tr>
118 <tr> <td>Groups:</td> <td><select name="grp" size="5" multiple>
119 <% foreach group in Group.listGroups () do %>
120 <option value="<% #id group %>"<% if #name group = "paying" then %> selected<% end %>><% Web.html (#name group) %></option>
123 <tr> <td><input type="submit" name="cmd" value="Create"></td> </tr>
127 <% elseif $"cmd" = "unmigrated" then
130 val users = Init.unmigratedUsers () %>
132 <h3>Unmigrated members (<% length users %>)</h3>
135 <% foreach user in users do %>
136 <tr> <td><a href="user?id=<% #id user %>"><% Web.html (#name user) %></a></td>
137 <% val bal = Balance.lookupBalance (#bal user);
138 if Balance.isNegative bal then
139 negative := negative + 1
141 <td><% #amount bal %></td><td>
142 <%if #name bal <> #name user then %>
143 <i><% Web.html (#name bal) %></i>
149 <p><% negative %> have negative balances.</p>
151 <% elseif $"cmd" = "diff" then
154 val against = (case $"against" of
155 "" => Init.usersInAfs ()
156 | x => String.tokens Char.isSpace x);
158 val diff = Init.usersDiff (Init.listUsernames (), against) %>
162 <h4>Only on the portal:</h4>
164 <% foreach user in #onlyInFirst diff do %>
165 <li> <a href="user?id=<% valOf (Init.userNameToId user) %>"><% Web.html user %></a></li>
169 <h4>Only in AFS:</h4>
171 <% foreach user in #onlyInSecond diff do %>
172 <li> <% Web.html user %></li>
178 <% if showNormal then %>
180 <a href="users?cmd=addform">Add a user manually</a><br>
182 <h3>Manage current members</h3>
185 <% foreach user in Init.listUsers () do %>
186 <tr> <td><a href="user?id=<% #id user %>"><% Web.html (#name user) %></a></td> <td>
187 <% val bal = Balance.lookupBalance (#bal user);
188 if #name bal <> #name user then %>
189 <i><% Web.html (#name bal) %></i>
191 </td><td><a href="users?mod=<% #id user %>">[Modify]</a> <a href="users?del=<% #id user %>">[Delete]</a>
192 <a href="users?retire=<% #id user %>">[Retire]</a></td> </tr>
196 <br><a href="users?cmd=grandfather">Grandfather old users to have applications</a><br>
197 <a href="users?cmd=unmigrated">Who hasn't migrated yet?</a><br>
198 <a href="users?cmd=diff">How does the set of users in AFS compare with the set of active portal users?</a><br>