7347efe8 |
1 | <% @header [("title", ["Disk quota change requests"])]; |
2 | |
3 | val admin = Group.inGroupName "server"; |
4 | |
5 | if $"new" <> "" then |
6 | ref url = "?cmd=request&msg=" ^ Web.urlEncode ($"msg"); |
7 | ref changed = false; |
8 | val uname = Init.getUserName (); |
9 | |
10 | %>Are you sure you want to request these quota changes? |
11 | <ul><% |
12 | |
13 | foreach vol in Quotas.getQuotas uname do |
14 | val requested = Web.stoi ($(#vol vol)); |
15 | url := url ^ "&" ^ #vol vol ^ "=" ^ Int.toString requested; |
16 | if requested <> #quota vol then |
17 | changed := true; |
18 | %><li> Change quota for <% #vol vol %> from <% #quota vol %> to <% requested %>.</li><% |
19 | end |
20 | end; |
21 | |
22 | %></ul><% |
23 | if changed then %> |
24 | <a href="<% url %>">Yes, I'm sure!</a> |
25 | <% else %> |
26 | Hm, no changes! |
27 | <% end |
28 | elseif $"cmd" = "request" then |
29 | ref cmds = ""; |
30 | val uname = Init.getUserName (); |
31 | |
32 | foreach vol in Quotas.getQuotas uname do |
33 | val requested = Web.stoi ($(#vol vol)); |
34 | if requested <> #quota vol then |
35 | cmds := cmds ^ "fs sq " ^ Quotas.path (#vol vol) ^ " " ^ Int.toString requested |
36 | ^ "\n# Current quota: " ^ Int.toString (#quota vol) ^ "\n" |
37 | end |
38 | end; |
39 | |
40 | val id = Quota.add (Init.getUserId (), cmds, $"msg"); |
41 | if not (Quota.notifyNew id) then |
42 | %><h3>Error sending e-mail notification</h3><% |
43 | end |
44 | %><h3>Request added</h3><% |
45 | |
46 | elseif $"cmd" = "open" then |
47 | %><h3>Open requests</h3> |
48 | <a href="?cmd=list">List all requests</a><% |
49 | |
50 | foreach (name, req) in Quota.listOpen () do %> |
51 | <br><hr><br> |
52 | <table class="blanks"> |
53 | <tr> <td>By:</td> <td><a href="user?id=<% #usr req %>"><% name %></a></td> </tr> |
54 | <tr> <td>Time:</td> <td><% #stamp req %></td> </tr> |
55 | <tr> <td>Request:</td> <td><% Web.htmlNl (#data req) %></td> </tr> |
56 | <tr> <td>Reason:</td> <td><% Web.html (#msg req) %></td> </tr> |
57 | </table> |
58 | |
59 | <% if admin then %> |
60 | <br> |
61 | <a href="?mod=<% #id req %>">[Modify]</a> |
62 | <a href="?del=<% #id req %>">[Delete]</a><br> |
63 | <% end %> |
64 | |
65 | <% end |
66 | |
67 | elseif $"cmd" = "list" then |
68 | %><h3>All requests</h3><% |
69 | |
70 | foreach (name, req) in Quota.list () do %> |
71 | <br><hr><br> |
72 | <table class="blanks"> |
73 | <tr> <td>By:</td> <td><a href="user?id=<% #usr req %>"><% name %></a></td> </tr> |
74 | <tr> <td>Time:</td> <td><% #stamp req %></td> </tr> |
75 | <tr> <td>Request:</td> <td><% Web.htmlNl (#data req) %></td> </tr> |
76 | <tr> <td>Reason:</td> <td><% Web.html (#msg req) %></td> </tr> |
77 | </table> |
78 | |
79 | <% if admin then %> |
80 | <br> |
81 | <a href="?mod=<% #id req %>">[Modify]</a> |
82 | <a href="?del=<% #id req %>">[Delete]</a> |
83 | <% end %> |
84 | |
85 | <% end |
86 | |
87 | elseif $"mod" <> "" then |
88 | Group.requireGroupName "server"; |
89 | val id = Web.stoi ($"mod"); |
90 | val req = Quota.lookup id; |
91 | val user = Init.lookupUser (#usr req) %> |
92 | <h3>Handle request</h3> |
93 | |
94 | <form method="post"> |
95 | <input type="hidden" name="save" value="<% id %>"> |
96 | <table class="blanks"> |
97 | <tr> <td>Requestor:</td> <td><a href="user?id=<% #usr req %>"><% #name user %></a></td> </tr> |
98 | <tr> <td>Time:</td> <td><% #stamp req %></td> </tr> |
99 | <tr> <td>Status:</td> <td><select name="status"> |
100 | <option value="0"<% if #status req = Quota.NEW then %> selected<% end %>>New</option> |
101 | <option value="1"<% if #status req = Quota.INSTALLED then %> selected<% end %>>Installed</option> |
102 | <option value="2"<% if #status req = Quota.REJECTED then %> selected<% end %>>Rejected</option> |
103 | </select></td> </tr> |
104 | <tr> <td>Request:</td> <td><input name="req" size="60" value="<% Web.html (#data req) %>"></td> </tr> |
105 | <tr> <td>Message:</td> <td><textarea name="msg" rows="10" cols="80" wrap="soft"><% Web.html (#msg req) %></textarea></td> </tr> |
106 | <tr> <td><input type="submit" value="Save"></td> </tr> |
107 | </table> |
108 | </form> |
109 | |
110 | <% elseif $"save" <> "" then |
111 | Group.requireGroupName "server"; |
112 | val id = Web.stoi ($"save"); |
113 | val req = Quota.lookup id; |
114 | val oldStatus = #status req; |
115 | val newStatus = Quota.statusFromInt (Web.stoi ($"status")); |
116 | Quota.modify {req with data = $"req", msg = $"msg", status = newStatus}; |
117 | if oldStatus <> newStatus then |
118 | if not (Quota.notifyMod (oldStatus, newStatus, Init.getUserName(), id)) then |
119 | %><h3>Error sending e-mail notification</h3><% |
120 | end |
121 | end |
122 | %><h3>Request modified</h3> |
123 | Back to: <a href="?cmd=open">open requests</a>, <a href="?cmd=list">all requests</a> |
124 | |
125 | <% elseif $"del" <> "" then |
126 | Group.requireGroupName "server"; |
127 | val id = Web.stoi ($"del"); |
128 | val req = Quota.lookup id; |
129 | val user = Init.lookupUser (#usr req) |
130 | %><h3>Are you sure you want to delete request by <% #name user %> for <tt><% #data req %></tt>?</h3> |
131 | <a href="?del2=<% id %>">Yes, I'm sure!</a> |
132 | |
133 | <% elseif $"del2" <> "" then |
134 | Group.requireGroupName "server"; |
135 | val id = Web.stoi ($"del2"); |
136 | Quota.delete id |
137 | %><h3>Request deleted</b><h3> |
138 | Back to: <a href="?cmd=open">open requests</a>, <a href="?cmd=list">all requests</a> |
139 | |
140 | <% else %> |
141 | |
142 | <h3>Request a disk quota change</h3> |
143 | |
144 | <form method="post"> |
145 | |
146 | <table> |
147 | <tr> <th>Volume</th> <th>Used (kB)</th> <th>Quota now (kB)</th> <th>Requested quota (kB)</th> </tr> |
148 | <% foreach vol in Quotas.getQuotas (Init.getUserName ()) do %> |
149 | <tr> <td><% #vol vol %></td> <td><% #used vol %></td> <td><% #quota vol %></td> |
150 | <td><input name="<% #vol vol %>" value="<% #quota vol %>"></td> </tr> |
151 | <% end %> |
152 | </table> |
153 | |
154 | <input type="hidden" name="new" value="1"> |
155 | <table class="blanks"> |
156 | <tr> <td>Additional comments:</td> <td><textarea name="msg" rows="5" cols="80" wrap="soft"></textarea></td> </tr> |
157 | <tr> <td><input type="submit" value="Request"></td> </tr> |
158 | </table> |
159 | </form> |
160 | |
161 | <% end %> |
162 | |
163 | <% @footer[] %> |