cvsimport
[hcoop/zz_old/portal.git] / users.mlt
index 23ebfa4..6a6dfc8 100644 (file)
--- a/users.mlt
+++ b/users.mlt
@@ -6,10 +6,10 @@ ref showNormal = true;
 
 if $"cmd" = "Create" then
        if not (Init.validUsername ($"name")) then %>
-               <h3><b>Invalid username</b></h3>
+               <h3>Invalid username</h3>
        <% else switch Init.userNameToId ($"name") of
                  SOME _ => %>
-                       <h3><b>Username already in use</b></h3>
+                       <h3>Username already in use</h3>
 <%             | NONE =>
                        val ap = Web.stoi ($"app");
                        val bal =
@@ -17,7 +17,7 @@ if $"cmd" = "Create" then
                                          "" => Balance.addBalance ($"name")
                                        | s => Web.stoi s);
 
-                       val id = Init.addUser ($"name", $"rname", bal, ap);
+                       val id = Init.addUser ($"name", $"rname", bal, ap, 1);
                        Group.addToGroups (id, map Web.stoi (Web.getMultiParam "grp"));
 
                        if $"amount" <> "" then
@@ -28,24 +28,29 @@ if $"cmd" = "Create" then
                        end;
 
                        if $"subscribe" = "on" then
-                               if not (Pref.subscribe ("hcoop-announce", $"name" ^ "@hcoop.net")) then
-                                       %><h3><b>Error subscribing to hcoop-announce</b></h3><%
+                               if not (Pref.subscribe ("hcoop-announce", $"name" ^ Init.emailSuffix)) then
+                                       %><h3>Error subscribing to hcoop-announce</h3><%
                                end
-                       end %>
-                       <h3><b>Member added</b></h3>
+                       end;
+
+                       if $"nomail" = "" then
+                               App.welcome ap
+                       end
+
+                       %><h3>Member added</h3>
 <%             end
        end
 elseif $"mod" <> "" then
        showNormal := false;
        val user = Init.lookupUser (Web.stoi ($"mod")) %>
-<h3><b>Modify member record</b></h3>
+<h3>Modify member record</h3>
 
-<form action="users">
+<form action="users" method="post">
 <input type="hidden" name="id" value="<% $"mod" %>">
-<table>
-<tr> <td align="right"><b>Name</b>:</td> <td><input name="name" value="<% #name user %>"></td> </tr>
-<tr> <td align="right"><b>Real name</b>:</td> <td><input name="rname" value="<% #rname user %>"></td> </tr>
-<tr> <td align="right" valign="top"><b>Funded by</b>:</td> <td><select name="bal">
+<table class="blanks">
+<tr> <td>Name:</td> <td><input name="name" value="<% #name user %>"></td> </tr>
+<tr> <td>Real name:</td> <td><input name="rname" value="<% #rname user %>"></td> </tr>
+<tr> <td>Funded by:</td> <td><select name="bal">
 <% foreach bal in Balance.listBalances () do %>
        <option value="<% #id bal %>"<% if #bal user = #id bal then %> selected <% end %>><% Web.html (#name bal) %></option>
 <% end %>
@@ -57,42 +62,58 @@ elseif $"mod" <> "" then
 <% elseif $"cmd" = "Save" then
        val user = Init.lookupUser (Web.stoi ($"id"));
        Init.modUser {user with name = $"name", bal = Web.stoi ($"bal")} %>
-       <h3><b>Member record saved.</b></h3>
+       <h3>Member record saved.</h3>
 
 <% elseif $"del" <> "" then
        showNormal := false;
        val user = Init.lookupUser (Web.stoi ($"del")) %>
-       <h3><b>Are you sure you want to delete member <a href="user?id=<% #id user %>"><% #name user %></a>?</b></h3>
+       <h3>Are you sure you want to delete member <a href="user?id=<% #id user %>"><% #name user %></a>?</h3>
        <a href="users?del2=<% $"del" %>">Yes, delete <% #name user %>!</a>
 
 <% elseif $"del2" <> "" then
        val user = Init.lookupUser (Web.stoi ($"del2"));
        Init.deleteUser (Web.stoi ($"del2")) %>
-       <h3><b><% #name user %> deleted!</b></h3>
+       <h3><% #name user %> deleted!</h3>
 
-<% elseif $"cmd" = "grandfather" then
+<% elseif $"retire" <> "" then
+       showNormal := false;
+       val user = Init.lookupUser (Web.stoi ($"retire")) %>
+       <h3>Are you sure you want to retire member <a href="user?id=<% #id user %>"><% #name user %></a>?</h3>
+       <a href="users?retire2=<% $"retire" %>">Yes, retire <% #name user %>!</a>
+
+<% elseif $"retire2" <> "" then
+        val usr = Web.stoi ($"retire2");
+       val user = Init.lookupUser usr;
+       switch (Group.groupNameToId "paying", Group.groupNameToId "retired") of
+         (SOME paying, SOME retired) =>
+               Group.removeFromGroup {usr = usr, grp = paying};
+               Group.addToGroup {usr = usr, grp = retired} %>
+               <h3><% #name user %> retired!</h3><%
+       | _ => %><h3>Couldn't find "paying" or "retired" group by name!</h3><%
+       end
+
+elseif $"cmd" = "grandfather" then
        Init.grandfatherUsers()
-       %><h3><b>Grandfathered</b></h3>
+       %><h3>Grandfathered</h3>
 
-<% end %>
+<% elseif $"cmd" = "addform" then
+        showNormal := false %>        
+<h3>New member</h3>
 
-<% if showNormal then %>
-<h3><b>New member</b></h3>
-
-<form action="users">
-<table>
-<tr> <td align="right"><b>Name</b>:</td> <td><input name="name"></td> </tr>
-<tr> <td align="right"><b>Real name</b>:</td> <td><input name="rname"></td> </tr>
-<tr> <td align="right" valign="top"><b>Funded by</b>:</td> <td><select name="bal">
+<form action="users" method="post">
+<table class="blanks">
+<tr> <td>Name:</td> <td><input name="name"></td> </tr>
+<tr> <td>Real name:</td> <td><input name="rname"></td> </tr>
+<tr> <td>Funded by:</td> <td><select name="bal">
        <option value="">A new balance</option>
 <% foreach bal in Balance.listBalances () do %>
        <option value="<% #id bal %>"><% Web.html (#name bal) %></option>
 <% end %>
 </select></td></tr>
-<tr> <td align="right"><b>Initial transaction amount</b>:</td> <td><input name="amount"></td> </tr>
-<tr> <td align="right"><b>Initial transaction description</b>:</td> <td><input name="descr"></td> </tr>
-<tr> <td align="right"><input type="checkbox" name="subscribe" checked></td> <td>Subscribe to hcoop-announce</td> </tr>
-<tr> <td align="right"><b>Groups</b>:</td> <td><select name="grp" size="5" multiple>
+<tr> <td>Initial transaction amount:</td> <td><input name="amount"></td> </tr>
+<tr> <td>Initial transaction description:</td> <td><input name="descr"></td> </tr>
+<tr> <td><input type="checkbox" name="subscribe" checked></td> <td>Subscribe to hcoop-announce</td> </tr>
+<tr> <td>Groups:</td> <td><select name="grp" size="5" multiple>
 <% foreach group in Group.listGroups () do %>
        <option value="<% #id group %>"<% if #name group = "paying" then %> selected<% end %>><% Web.html (#name group) %></option>
 <% end %>
@@ -101,7 +122,62 @@ elseif $"mod" <> "" then
 </table>
 </form>
 
-<h3><b>Manage current members</b></h3>
+<% elseif $"cmd" = "unmigrated" then
+   showNormal := false;
+   ref negative = 0;
+   val users = Init.unmigratedUsers () %>
+
+<h3>Unmigrated members (<% length users %>)</h3>
+
+<table>
+<% foreach user in users do %>
+       <tr> <td><a href="user?id=<% #id user %>"><% Web.html (#name user) %></a></td>
+<% val bal = Balance.lookupBalance (#bal user);
+if Balance.isNegative bal then
+   negative := negative + 1
+end %>
+<td><% #amount bal %></td><td>
+<%if #name bal <> #name user then %>
+ <i><% Web.html (#name bal) %></i>
+<% end %>
+</td> </tr>
+<% end %>
+</table>
+
+<p><% negative %> have negative balances.</p>
+
+<% elseif $"cmd" = "diff" then
+   showNormal := false;
+
+   val against = (case $"against" of
+                              "" => Init.usersInAfs ()
+                    | x => String.tokens Char.isSpace x);
+
+   val diff = Init.usersDiff (Init.listUsernames (), against) %>
+
+<h3>User diff</h3>
+
+<h4>Only on the portal:</h4>
+<ul>
+<% foreach user in #onlyInFirst diff do %>
+   <li> <a href="user?id=<% valOf (Init.userNameToId user) %>"><% Web.html user %></a></li>
+<% end %>
+</ul>
+
+<h4>Only in AFS:</h4>
+<ul>
+<% foreach user in #onlyInSecond diff do %>
+   <li> <% Web.html user %></li>
+<% end %>
+</ul>
+
+<% end %>
+
+<% if showNormal then %>
+
+<a href="users?cmd=addform">Add a user manually</a><br>
+
+<h3>Manage current members</h3>
 
 <table>
 <% foreach user in Init.listUsers () do %>
@@ -110,11 +186,14 @@ elseif $"mod" <> "" then
 if #name bal <> #name user then %>
 <i><% Web.html (#name bal) %></i>
 <% end %>
-       </td><td><a href="users?mod=<% #id user %>">[Modify]</a> <a href="users?del=<% #id user %>">[Delete]</a></td> </tr>
+       </td><td><a href="users?mod=<% #id user %>">[Modify]</a> <a href="users?del=<% #id user %>">[Delete]</a>
+       <a href="users?retire=<% #id user %>">[Retire]</a></td> </tr>
 <% end %>
 </table>
 
 <br><a href="users?cmd=grandfather">Grandfather old users to have applications</a><br>
+<a href="users?cmd=unmigrated">Who hasn't migrated yet?</a><br>
+<a href="users?cmd=diff">How does the set of users in AFS compare with the set of active portal users?</a><br>
 
 <% end %>