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 AC |
33 | end |
34 | end %> | |
b6dd1aaf | 35 | <h3>Member added</h3> |
208e2cbc AC |
36 | <% end |
37 | end | |
38 | elseif $"mod" <> "" then | |
39 | showNormal := false; | |
40 | val user = Init.lookupUser (Web.stoi ($"mod")) %> | |
b6dd1aaf | 41 | <h3>Modify member record</h3> |
208e2cbc | 42 | |
a4ccdb5e | 43 | <form action="users" method="post"> |
208e2cbc | 44 | <input type="hidden" name="id" value="<% $"mod" %>"> |
b6dd1aaf AC |
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"> | |
208e2cbc AC |
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")} %> | |
b6dd1aaf | 60 | <h3>Member record saved.</h3> |
208e2cbc AC |
61 | |
62 | <% elseif $"del" <> "" then | |
63 | showNormal := false; | |
64 | val user = Init.lookupUser (Web.stoi ($"del")) %> | |
b6dd1aaf | 65 | <h3>Are you sure you want to delete member <a href="user?id=<% #id user %>"><% #name user %></a>?</h3> |
208e2cbc AC |
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")) %> | |
b6dd1aaf | 71 | <h3><% #name user %> deleted!</h3> |
208e2cbc | 72 | |
f3f3ad24 AC |
73 | <% elseif $"cmd" = "grandfather" then |
74 | Init.grandfatherUsers() | |
b6dd1aaf | 75 | %><h3>Grandfathered</h3> |
f3f3ad24 | 76 | |
208e2cbc AC |
77 | <% end %> |
78 | ||
79 | <% if showNormal then %> | |
b6dd1aaf | 80 | <h3>New member</h3> |
208e2cbc | 81 | |
a4ccdb5e | 82 | <form action="users" method="post"> |
b6dd1aaf AC |
83 | <table class="blanks"> |
84 | <tr> <td>Name:</td> <td><input name="name"></td> </tr> | |
85 | <tr> <td>Real name:</td> <td><input name="rname"></td> </tr> | |
86 | <tr> <td>Funded by:</td> <td><select name="bal"> | |
208e2cbc AC |
87 | <option value="">A new balance</option> |
88 | <% foreach bal in Balance.listBalances () do %> | |
89 | <option value="<% #id bal %>"><% Web.html (#name bal) %></option> | |
90 | <% end %> | |
91 | </select></td></tr> | |
b6dd1aaf AC |
92 | <tr> <td>Initial transaction amount:</td> <td><input name="amount"></td> </tr> |
93 | <tr> <td>Initial transaction description:</td> <td><input name="descr"></td> </tr> | |
94 | <tr> <td><input type="checkbox" name="subscribe" checked></td> <td>Subscribe to hcoop-announce</td> </tr> | |
95 | <tr> <td>Groups:</td> <td><select name="grp" size="5" multiple> | |
208e2cbc | 96 | <% foreach group in Group.listGroups () do %> |
9bda1e7f | 97 | <option value="<% #id group %>"<% if #name group = "paying" then %> selected<% end %>><% Web.html (#name group) %></option> |
208e2cbc AC |
98 | <% end %> |
99 | </select></td></tr> | |
100 | <tr> <td><input type="submit" name="cmd" value="Create"></td> </tr> | |
101 | </table> | |
102 | </form> | |
103 | ||
b6dd1aaf | 104 | <h3>Manage current members</h3> |
208e2cbc AC |
105 | |
106 | <table> | |
107 | <% foreach user in Init.listUsers () do %> | |
108 | <tr> <td><a href="user?id=<% #id user %>"><% Web.html (#name user) %></a></td> <td> | |
109 | <% val bal = Balance.lookupBalance (#bal user); | |
110 | if #name bal <> #name user then %> | |
111 | <i><% Web.html (#name bal) %></i> | |
112 | <% end %> | |
113 | </td><td><a href="users?mod=<% #id user %>">[Modify]</a> <a href="users?del=<% #id user %>">[Delete]</a></td> </tr> | |
114 | <% end %> | |
115 | </table> | |
116 | ||
f3f3ad24 AC |
117 | <br><a href="users?cmd=grandfather">Grandfather old users to have applications</a><br> |
118 | ||
208e2cbc AC |
119 | <% end %> |
120 | ||
121 | <% @footer [] %> |