Quota requests
[hcoop/zz_old/portal.git] / quota.mlt
diff --git a/quota.mlt b/quota.mlt
new file mode 100644 (file)
index 0000000..a10311c
--- /dev/null
+++ b/quota.mlt
@@ -0,0 +1,163 @@
+<% @header [("title", ["Disk quota change requests"])];
+
+val admin = Group.inGroupName "server";
+
+if $"new" <> "" then
+        ref url = "?cmd=request&msg=" ^ Web.urlEncode ($"msg");
+       ref changed = false;
+       val uname = Init.getUserName ();
+
+       %>Are you sure you want to request these quota changes?
+       <ul><%
+
+       foreach vol in Quotas.getQuotas uname do
+               val requested = Web.stoi ($(#vol vol));
+               url := url ^ "&" ^ #vol vol ^ "=" ^ Int.toString requested;
+               if requested <> #quota vol then
+                  changed := true;
+                  %><li> Change quota for <% #vol vol %> from <% #quota vol %> to <% requested %>.</li><%
+               end
+       end;
+
+       %></ul><%
+       if changed then %>
+          <a href="<% url %>">Yes, I'm sure!</a>
+       <% else %>
+          Hm, no changes!
+       <% end
+elseif $"cmd" = "request" then
+        ref cmds = "";
+       val uname = Init.getUserName ();
+
+       foreach vol in Quotas.getQuotas uname do
+               val requested = Web.stoi ($(#vol vol));
+               if requested <> #quota vol then
+                  cmds := cmds ^ "fs sq " ^ Quotas.path (#vol vol) ^ " " ^ Int.toString requested
+                       ^ "\n# Current quota: " ^ Int.toString (#quota vol) ^ "\n"
+               end
+       end;
+
+       val id = Quota.add (Init.getUserId (), cmds, $"msg");
+       if not (Quota.notifyNew id) then
+               %><h3>Error sending e-mail notification</h3><%
+       end
+       %><h3>Request added</h3><%
+
+elseif $"cmd" = "open" then
+       %><h3>Open requests</h3>
+       <a href="?cmd=list">List all requests</a><%
+
+       foreach (name, req) in Quota.listOpen () do %>
+<br><hr><br>
+<table class="blanks">
+<tr> <td>By:</td> <td><a href="user?id=<% #usr req %>"><% name %></a></td> </tr>
+<tr> <td>Time:</td> <td><% #stamp req %></td> </tr>
+<tr> <td>Request:</td> <td><% Web.htmlNl (#data req) %></td> </tr>
+<tr> <td>Reason:</td> <td><% Web.html (#msg req) %></td> </tr>
+</table>
+
+<% if admin then %>
+       <br>
+       <a href="?mod=<% #id req %>">[Modify]</a>
+       <a href="?del=<% #id req %>">[Delete]</a><br>
+<% end %>
+
+<%     end
+
+elseif $"cmd" = "list" then
+       %><h3>All requests</h3><%
+
+       foreach (name, req) in Quota.list () do %>
+<br><hr><br>
+<table class="blanks">
+<tr> <td>By:</td> <td><a href="user?id=<% #usr req %>"><% name %></a></td> </tr>
+<tr> <td>Time:</td> <td><% #stamp req %></td> </tr>
+<tr> <td>Request:</td> <td><% Web.htmlNl (#data req) %></td> </tr>
+<tr> <td>Reason:</td> <td><% Web.html (#msg req) %></td> </tr>
+</table>
+
+<% if admin then %>
+       <br>
+       <a href="?mod=<% #id req %>">[Modify]</a>
+       <a href="?del=<% #id req %>">[Delete]</a>
+<% end %>
+
+<%     end
+
+elseif $"mod" <> "" then
+       Group.requireGroupName "server";
+       val id = Web.stoi ($"mod");
+       val req = Quota.lookup id;
+       val user = Init.lookupUser (#usr req) %>
+<h3>Handle request</h3>
+
+<form method="post">
+<input type="hidden" name="save" value="<% id %>">
+<table class="blanks">
+<tr> <td>Requestor:</td> <td><a href="user?id=<% #usr req %>"><% #name user %></a></td> </tr>
+<tr> <td>Time:</td> <td><% #stamp req %></td> </tr>
+<tr> <td>Status:</td> <td><select name="status">
+       <option value="0"<% if #status req = Quota.NEW then %> selected<% end %>>New</option>
+       <option value="1"<% if #status req = Quota.INSTALLED then %> selected<% end %>>Installed</option>
+       <option value="2"<% if #status req = Quota.REJECTED then %> selected<% end %>>Rejected</option>
+</select></td> </tr>
+<tr> <td>Request:</td> <td><input name="req" size="60" value="<% Web.html (#data req) %>"></td> </tr>
+<tr> <td>Message:</td> <td><textarea name="msg" rows="10" cols="80" wrap="soft"><% Web.html (#msg req) %></textarea></td> </tr>
+<tr> <td><input type="submit" value="Save"></td> </tr>
+</table>
+</form>
+
+<% elseif $"save" <> "" then
+       Group.requireGroupName "server";
+       val id = Web.stoi ($"save");
+       val req = Quota.lookup id;
+       val oldStatus = #status req;
+       val newStatus = Quota.statusFromInt (Web.stoi ($"status"));
+       Quota.modify {req with data = $"req", msg = $"msg", status = newStatus};
+       if oldStatus <> newStatus then
+               if not (Quota.notifyMod (oldStatus, newStatus, Init.getUserName(), id)) then
+                       %><h3>Error sending e-mail notification</h3><%
+               end
+       end
+       %><h3>Request modified</h3>
+       Back to: <a href="?cmd=open">open requests</a>, <a href="?cmd=list">all requests</a>
+
+<% elseif $"del" <> "" then
+       Group.requireGroupName "server";
+       val id = Web.stoi ($"del");
+       val req = Quota.lookup id;
+       val user = Init.lookupUser (#usr req)
+       %><h3>Are you sure you want to delete request by <% #name user %> for <tt><% #data req %></tt>?</h3>
+       <a href="?del2=<% id %>">Yes, I'm sure!</a>
+
+<% elseif $"del2" <> "" then
+       Group.requireGroupName "server";
+       val id = Web.stoi ($"del2");
+       Quota.delete id
+       %><h3>Request deleted</b><h3>
+       Back to: <a href="?cmd=open">open requests</a>, <a href="?cmd=list">all requests</a>
+
+<% else %>
+
+<h3>Request a disk quota change</h3>
+
+<form method="post">
+
+<table>
+<tr> <th>Volume</th> <th>Used (kB)</th> <th>Quota now (kB)</th> <th>Requested quota (kB)</th> </tr>
+<% foreach vol in Quotas.getQuotas (Init.getUserName ()) do %>
+   <tr> <td><% #vol vol %></td> <td><% #used vol %></td> <td><% #quota vol %></td>
+   <td><input name="<% #vol vol %>" value="<% #quota vol %>"></td> </tr>
+<% end %>
+</table>
+
+<input type="hidden" name="new" value="1">
+<table class="blanks">
+<tr> <td>Additional comments:</td> <td><textarea name="msg" rows="5" cols="80" wrap="soft"></textarea></td> </tr>
+<tr> <td><input type="submit" value="Request"></td> </tr>
+</table>
+</form>
+
+<% end %>
+
+<% @footer[] %>