cert.mlt: Update with new instructions
[hcoop/zz_old/portal.git] / users.mlt
CommitLineData
8d347a33 1<% Group.requireGroupNum 0;
2
3@header [("title", ["Member management"])];
4
5ref showNormal = true;
6
7if $"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
34 end %>
1fe415e0 35 <h3>Member added</h3>
8d347a33 36<% end
37 end
38elseif $"mod" <> "" then
39 showNormal := false;
40 val user = Init.lookupUser (Web.stoi ($"mod")) %>
1fe415e0 41<h3>Modify member record</h3>
8d347a33 42
add44c00 43<form action="users" method="post">
8d347a33 44<input type="hidden" name="id" value="<% $"mod" %>">
1fe415e0 45<table class="blanks">
46<tr> <td>Name:</td> <td><input name="name" value="<% #name user %>"></td> </tr>
47<tr> <td>Real name:</td> <td><input name="rname" value="<% #rname user %>"></td> </tr>
48<tr> <td>Funded by:</td> <td><select name="bal">
8d347a33 49<% foreach bal in Balance.listBalances () do %>
50 <option value="<% #id bal %>"<% if #bal user = #id bal then %> selected <% end %>><% Web.html (#name bal) %></option>
51<% end %>
52</select></td></tr>
53<tr> <td><input type="submit" name="cmd" value="Save"></td> </tr>
54</table>
55</form>
56
57<% elseif $"cmd" = "Save" then
58 val user = Init.lookupUser (Web.stoi ($"id"));
59 Init.modUser {user with name = $"name", bal = Web.stoi ($"bal")} %>
1fe415e0 60 <h3>Member record saved.</h3>
8d347a33 61
62<% elseif $"del" <> "" then
63 showNormal := false;
64 val user = Init.lookupUser (Web.stoi ($"del")) %>
1fe415e0 65 <h3>Are you sure you want to delete member <a href="user?id=<% #id user %>"><% #name user %></a>?</h3>
8d347a33 66 <a href="users?del2=<% $"del" %>">Yes, delete <% #name user %>!</a>
67
68<% elseif $"del2" <> "" then
69 val user = Init.lookupUser (Web.stoi ($"del2"));
70 Init.deleteUser (Web.stoi ($"del2")) %>
1fe415e0 71 <h3><% #name user %> deleted!</h3>
8d347a33 72
5146e435 73<% elseif $"cmd" = "grandfather" then
74 Init.grandfatherUsers()
1fe415e0 75 %><h3>Grandfathered</h3>
5146e435 76
ef48ed9e 77<% elseif $"cmd" = "addform" then
78 showNormal := false %>
1fe415e0 79<h3>New member</h3>
8d347a33 80
add44c00 81<form action="users" method="post">
1fe415e0 82<table class="blanks">
83<tr> <td>Name:</td> <td><input name="name"></td> </tr>
84<tr> <td>Real name:</td> <td><input name="rname"></td> </tr>
85<tr> <td>Funded by:</td> <td><select name="bal">
8d347a33 86 <option value="">A new balance</option>
87<% foreach bal in Balance.listBalances () do %>
88 <option value="<% #id bal %>"><% Web.html (#name bal) %></option>
89<% end %>
90</select></td></tr>
1fe415e0 91<tr> <td>Initial transaction amount:</td> <td><input name="amount"></td> </tr>
92<tr> <td>Initial transaction description:</td> <td><input name="descr"></td> </tr>
93<tr> <td><input type="checkbox" name="subscribe" checked></td> <td>Subscribe to hcoop-announce</td> </tr>
94<tr> <td>Groups:</td> <td><select name="grp" size="5" multiple>
8d347a33 95<% foreach group in Group.listGroups () do %>
f98251aa 96 <option value="<% #id group %>"<% if #name group = "paying" then %> selected<% end %>><% Web.html (#name group) %></option>
8d347a33 97<% end %>
98</select></td></tr>
99<tr> <td><input type="submit" name="cmd" value="Create"></td> </tr>
100</table>
101</form>
102
da3f3cbc 103<% elseif $"cmd" = "unmigrated" then
104 showNormal := false;
270da709 105 ref negative = 0;
da3f3cbc 106 val users = Init.unmigratedUsers () %>
107
108<h3>Unmigrated members (<% length users %>)</h3>
109
110<table>
111<% foreach user in users do %>
270da709 112 <tr> <td><a href="user?id=<% #id user %>"><% Web.html (#name user) %></a></td>
da3f3cbc 113<% val bal = Balance.lookupBalance (#bal user);
270da709 114if Balance.isNegative bal then
115 negative := negative + 1
116end %>
117<td><% #amount bal %></td><td>
118<%if #name bal <> #name user then %>
119 <i><% Web.html (#name bal) %></i>
da3f3cbc 120<% end %>
270da709 121</td> </tr>
da3f3cbc 122<% end %>
123</table>
124
270da709 125<p><% negative %> have negative balances.</p>
126
9fe97917 127<% elseif $"cmd" = "diff" then
128 showNormal := false;
129
130 val against = (case $"against" of
131 "" => Init.usersInAfs ()
132 | x => String.tokens Char.isSpace x);
133
134 val diff = Init.usersDiff (Init.listUsernames (), against) %>
135
136<h3>User diff</h3>
137
138<h4>Only on the portal:</h4>
139<ul>
140<% foreach user in #onlyInFirst diff do %>
141 <li> <a href="user?id=<% valOf (Init.userNameToId user) %>"><% Web.html user %></a></li>
142<% end %>
143</ul>
144
145<h4>Only in AFS:</h4>
146<ul>
147<% foreach user in #onlyInSecond diff do %>
148 <li> <% Web.html user %></li>
149<% end %>
150</ul>
151
ef48ed9e 152<% end %>
153
154<% if showNormal then %>
155
156<a href="users?cmd=addform">Add a user manually</a><br>
157
1fe415e0 158<h3>Manage current members</h3>
8d347a33 159
160<table>
161<% foreach user in Init.listUsers () do %>
162 <tr> <td><a href="user?id=<% #id user %>"><% Web.html (#name user) %></a></td> <td>
163<% val bal = Balance.lookupBalance (#bal user);
164if #name bal <> #name user then %>
165<i><% Web.html (#name bal) %></i>
166<% end %>
167 </td><td><a href="users?mod=<% #id user %>">[Modify]</a> <a href="users?del=<% #id user %>">[Delete]</a></td> </tr>
168<% end %>
169</table>
170
5146e435 171<br><a href="users?cmd=grandfather">Grandfather old users to have applications</a><br>
da3f3cbc 172<a href="users?cmd=unmigrated">Who hasn't migrated yet?</a><br>
9fe97917 173<a href="users?cmd=diff">How does the set of users in AFS compare with the set of active portal users?</a><br>
5146e435 174
8d347a33 175<% end %>
176
177<% @footer [] %>