Column sorting fixes, thanks to Tony550
[tomato.git] / release / src / router / www / admin-sched.asp
blobed4c420eaccd32864f3b4518fede33a93bca6f27
1 <!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.0//EN'>
2 <!--
3 Tomato GUI
4 Copyright (C) 2006-2010 Jonathan Zarate
5 http://www.polarcloud.com/tomato/
7 For use with Tomato Firmware only.
8 No part of this file may be used without permission.
9 -->
10 <html>
11 <head>
12 <meta http-equiv='content-type' content='text/html;charset=utf-8'>
13 <meta name='robots' content='noindex,nofollow'>
14 <title>[<% ident(); %>] Scheduler</title>
15 <link rel='stylesheet' type='text/css' href='tomato.css'>
16 <link rel='stylesheet' type='text/css' href='color.css'>
17 <script type='text/javascript' src='tomato.js'></script>
19 <!-- / / / -->
21 <style type='text/css'>
22 textarea {
23 width: 98%;
24 height: 10em;
26 .empty {
27 height: 2em;
29 </style>
31 <script type='text/javascript' src='debug.js'></script>
33 <script type='text/javascript'>
35 // <% nvram("sch_rboot,sch_rcon,sch_c1,sch_c1_cmd,sch_c2,sch_c2_cmd,sch_c3,sch_c3_cmd"); %>
37 var dowNames = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
38 var dowLow = ['sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat'];
39 var scheds = []
41 tm = [];
42 for (i = 0; i < 1440; i += 15) {
43 tm.push([i, timeString(i)]);
46 tm.push(
47 [-1, 'Every minute'], [-3, 'Every 3 minutes'], [-5, 'Every 5 minutes'], [-15, 'Every 15 minutes'], [-30, 'Every 30 minutes'],
48 [-60, 'Every hour'], [-(12 * 60), 'Every 12 hours'], [-(24 * 60), 'Every 24 hours'],
49 ['e', 'Every...']);
51 /* REMOVE-BEGIN
53 sch_* = en,time,days
55 REMOVE-END */
57 function makeSched(key, custom)
59 var s, v, w, a, t, i;
60 var oe;
62 scheds.push(key);
64 s = nvram['sch_' + key] || '';
65 if ((v = s.match(/^(0|1),(-?\d+),(\d+)$/)) == null) {
66 v = custom ? ['', 0, -30, 0] : ['', 0, 0, 0];
68 w = v[3] * 1;
69 if (w <= 0) w = 0xFF;
71 key = key + '_';
73 if (custom) {
74 t = tm;
76 else {
77 t = [];
78 for (i = 0; i < tm.length; ++i) {
79 if ((tm[i][0] >= 0) || (tm[i][0] <= -60) || (tm[i][0] == 'e')) t.push(tm[i]);
83 oe = 1;
84 for (i = 0; i < t.length; ++i) {
85 if (v[2] == t[i][0]) {
86 oe = 0;
87 break;
91 a = [
92 { title: 'Enabled', name: key + 'enabled', type: 'checkbox', value: v[1] == '1' },
93 { title: 'Time', multi: [
94 { name: key + 'time', type: 'select', options: t, value: oe ? 'e' : v[2] },
95 { name: key + 'every', type: 'text', maxlen: 10, size: 10, value: (v[2] < 0) ? -v[2] : 30,
96 prefix: ' ', suffix: ' <small id="_' + key + 'mins"><i>minutes</i></small>' } ] },
97 { title: 'Days', multi: [
98 { name: key + 'sun', type: 'checkbox', suffix: ' Sun &nbsp; ', value: w & 1 },
99 { name: key + 'mon', type: 'checkbox', suffix: ' Mon &nbsp; ', value: w & 2 },
100 { name: key + 'tue', type: 'checkbox', suffix: ' Tue &nbsp; ', value: w & 4 },
101 { name: key + 'wed', type: 'checkbox', suffix: ' Wed &nbsp; ', value: w & 8 },
102 { name: key + 'thu', type: 'checkbox', suffix: ' Thu &nbsp; ', value: w & 16 },
103 { name: key + 'fri', type: 'checkbox', suffix: ' Fri &nbsp; ', value: w & 32 },
104 { name: key + 'sat', type: 'checkbox', suffix: ' Sat &nbsp; &nbsp;', value: w & 64 },
105 { name: key + 'everyday', type: 'checkbox', suffix: ' Everyday', value: (w & 0x7F) == 0x7F } ] }
108 if (custom) {
109 a.push({ title: 'Command', name: 'sch_' + key + 'cmd', type: 'textarea', value: nvram['sch_' + key + 'cmd' ] });
112 createFieldTable('', a);
115 function verifySched(focused, quiet, key)
117 var e, f, i, n, b;
118 var eTime, eEvery, eEveryday, eCmd;
120 key = '_' + key + '_';
122 eTime = E(key + 'time');
123 eEvery = E(key + 'every');
124 eEvery.style.visibility = E(key + 'mins').style.visibility = (eTime.value == 'e') ? 'visible' : 'hidden';
126 eCmd = E('_sch' + key + 'cmd');
127 eEveryday = E(key + 'everyday');
129 if (E(key + 'enabled').checked) {
130 eEveryday.disabled = 0;
131 eTime.disabled = 0;
132 eEvery.disabled = 0;
133 if (eCmd) eCmd.disabled = 0;
135 if (focused == eEveryday) {
136 for (i = 0; i < 7; ++i) {
137 f = E(key + dowLow[i]);
138 f.disabled = 0;
139 f.checked = eEveryday.checked;
142 else {
143 n = 0;
144 for (i = 0; i < 7; ++i) {
145 f = E(key + dowLow[i]);
146 f.disabled = 0;
147 if (f.checked) ++n;
149 eEveryday.checked = (n == 7);
152 if ((eTime.value == 'e') && (!v_mins(eEvery, quiet, eCmd ? 1 : 60, 60 * 24 * 60))) return 0;
154 if ((eCmd) && (!v_length(eCmd, quiet, quiet ? 0 : 1, 2048))) return 0;
156 else {
157 eEveryday.disabled = 1;
158 eTime.disabled = 1;
159 eEvery.disabled = 1;
160 for (i = 0; i < 7; ++i) {
161 E(key + dowLow[i]).disabled = 1;
163 if (eCmd) eCmd.disabled = 1;
166 if (eCmd) {
167 if ((eCmd.value.length) || (!eTime.disabled)) {
168 elem.removeClass(eCmd, 'empty');
170 else {
171 elem.addClass(eCmd, 'empty');
175 return 1;
178 function verifyFields(focused, quiet)
180 for (var i = 0; i < scheds.length; ++i) {
181 if (!verifySched(focused, quiet, scheds[i])) return 0;
183 return 1;
186 function saveSched(fom, key)
188 var s, i, n, k, en, e;
190 k = '_' + key + '_';
192 en = E(k + 'enabled').checked;
193 s = en ? '1' : '0';
194 s += ',';
196 e = E(k + 'time').value;
197 if (e == 'e') s += -(E(k + 'every').value * 1);
198 else s += e;
200 n = 0;
201 for (i = 0; i < 7; ++i) {
202 if (E(k + dowLow[i]).checked) n |= (1 << i);
204 if (n == 0) {
205 n = 0x7F;
206 e = E(k + 'everyday');
207 e.checked = 1;
208 verifySched(e, key);
211 e = fom['sch_' + key];
212 e.value = s + ',' + n;
215 function save()
217 var fom, i
219 if (!verifyFields(null, false)) return;
221 fom = E('_fom');
222 for (i = 0; i < scheds.length; ++i) {
223 saveSched(fom, scheds[i]);
226 form.submit(fom, 1);
229 function init()
231 verifyFields(null, 1);
232 E('content').style.visibility = 'visible';
234 </script>
235 </head>
236 <body onload='init()'>
237 <form name='_fom' id='_fom' method='post' action='tomato.cgi'>
238 <table id='container' cellspacing=0>
239 <tr><td colspan=2 id='header'>
240 <div class='title'>Tomato</div>
241 <div class='version'>Version <% version() %></div>
242 </td></tr>
243 <tr id='body'><td id='navi'><script type='text/javascript'>navi()</script></td>
244 <td id='content' style='visibility:hidden'>
245 <div id='ident'><% ident(); %></div>
247 <!-- / / / -->
249 <input type='hidden' name='_nextpage' value='admin-sched.asp'>
250 <input type='hidden' name='_service' value='sched-restart'>
251 <input type='hidden' name='sch_rboot' value=''>
252 <input type='hidden' name='sch_rcon' value=''>
253 <input type='hidden' name='sch_c1' value=''>
254 <input type='hidden' name='sch_c2' value=''>
255 <input type='hidden' name='sch_c3' value=''>
257 <div class='section-title'>Reboot</div>
258 <div class='section'>
259 <script type='text/javascript'>
260 makeSched('rboot');
261 </script>
262 </div>
264 <div class='section-title'>Reconnect</div>
265 <div class='section'>
266 <script type='text/javascript'>
267 makeSched('rcon');
268 </script>
269 </div>
271 <div class='section-title'>Custom 1</div>
272 <div class='section'>
273 <script type='text/javascript'>
274 makeSched('c1', 1);
275 </script>
276 </div>
278 <div class='section-title'>Custom 2</div>
279 <div class='section'>
280 <script type='text/javascript'>
281 makeSched('c2', 1);
282 </script>
283 </div>
285 <div class='section-title'>Custom 3</div>
286 <div class='section'>
287 <script type='text/javascript'>
288 makeSched('c3', 1);
289 </script>
290 </div>
292 <!-- / / / -->
294 </td></tr>
295 <tr><td id='footer' colspan=2>
296 <span id='footer-msg'></span>
297 <input type='button' value='Save' id='save-button' onclick='save()'>
298 <input type='button' value='Cancel' id='cancel-button' onclick='javascript:reloadPage();'>
299 </td></tr>
300 </table>
301 <br><br>
302 </form>
303 </body>
304 </html>