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
30 if $"subscribe" = "on" then
31 if not (Pref.subscribe ("hcoop-announce", $"name" ^ Init.emailSuffix)) then
32 %><h3>Error subscribing to hcoop-announce</h3><%
38 elseif $"mod" <> "" then
40 val user = Init.lookupUser (Web.stoi ($"mod")) %>
41 <h3>Modify member record</h3>
43 <form action="users" method="post">
44 <input type="hidden" name="id" value="<% $"mod" %>">
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">
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>
53 <tr> <td><input type="submit" name="cmd" value="Save"></td> </tr>
57 <% elseif $"cmd" = "Save" then
58 val user = Init.lookupUser (Web.stoi ($"id"));
59 Init.modUser {user with name = $"name", bal = Web.stoi ($"bal")} %>
60 <h3>Member record saved.</h3>
62 <% elseif $"del" <> "" then
64 val user = Init.lookupUser (Web.stoi ($"del")) %>
65 <h3>Are you sure you want to delete member <a href="user?id=<% #id user %>"><% #name user %></a>?</h3>
66 <a href="users?del2=<% $"del" %>">Yes, delete <% #name user %>!</a>
68 <% elseif $"del2" <> "" then
69 val user = Init.lookupUser (Web.stoi ($"del2"));
70 Init.deleteUser (Web.stoi ($"del2")) %>
71 <h3><% #name user %> deleted!</h3>
73 <% elseif $"cmd" = "grandfather" then
74 Init.grandfatherUsers()
75 %><h3>Grandfathered</h3>
77 <% elseif $"cmd" = "addform" then
78 showNormal := false %>
81 <form action="users" method="post">
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">
86 <option value="">A new balance</option>
87 <% foreach bal in Balance.listBalances () do %>
88 <option value="<% #id bal %>"><% Web.html (#name bal) %></option>
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>
95 <% foreach group in Group.listGroups () do %>
96 <option value="<% #id group %>"<% if #name group = "paying" then %> selected<% end %>><% Web.html (#name group) %></option>
99 <tr> <td><input type="submit" name="cmd" value="Create"></td> </tr>
105 <% if showNormal then %>
107 <a href="users?cmd=addform">Add a user manually</a><br>
109 <h3>Manage current members</h3>
112 <% foreach user in Init.listUsers () do %>
113 <tr> <td><a href="user?id=<% #id user %>"><% Web.html (#name user) %></a></td> <td>
114 <% val bal = Balance.lookupBalance (#bal user);
115 if #name bal <> #name user then %>
116 <i><% Web.html (#name bal) %></i>
118 </td><td><a href="users?mod=<% #id user %>">[Modify]</a> <a href="users?del=<% #id user %>">[Delete]</a></td> </tr>
122 <br><a href="users?cmd=grandfather">Grandfather old users to have applications</a><br>