1
|
<?php
|
2
|
/*
|
3
|
firewall_schedule_edit.php
|
4
|
Copyright (C) 2004 Scott Ullrich
|
5
|
All rights reserved.
|
6
|
|
7
|
originally part of m0n0wall (http://m0n0.ch/wall)
|
8
|
Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
|
9
|
All rights reserved.
|
10
|
|
11
|
Redistribution and use in source and binary forms, with or without
|
12
|
modification, are permitted provided that the following conditions are met:
|
13
|
|
14
|
1. Redistributions of source code must retain the above copyright notice,
|
15
|
this list of conditions and the following disclaimer.
|
16
|
|
17
|
2. Redistributions in binary form must reproduce the above copyright
|
18
|
notice, this list of conditions and the following disclaimer in the
|
19
|
documentation and/or other materials provided with the distribution.
|
20
|
|
21
|
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
22
|
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
23
|
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
24
|
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
25
|
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
26
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
27
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
28
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
29
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
30
|
POSSIBILITY OF SUCH DAMAGE.
|
31
|
*/
|
32
|
/*
|
33
|
pfSense_MODULE: schedules
|
34
|
*/
|
35
|
|
36
|
##|+PRIV
|
37
|
##|*IDENT=page-firewall-schedules-edit
|
38
|
##|*NAME=Firewall: Schedules: Edit page
|
39
|
##|*DESCR=Allow access to the 'Firewall: Schedules: Edit' page.
|
40
|
##|*MATCH=firewall_schedule_edit.php*
|
41
|
##|-PRIV
|
42
|
|
43
|
function schedulecmp($a, $b) {
|
44
|
return strcmp($a['name'], $b['name']);
|
45
|
}
|
46
|
|
47
|
function schedule_sort(){
|
48
|
global $g, $config;
|
49
|
|
50
|
if (!is_array($config['schedules']['schedule']))
|
51
|
return;
|
52
|
|
53
|
usort($config['schedules']['schedule'], "schedulecmp");
|
54
|
}
|
55
|
|
56
|
require("guiconfig.inc");
|
57
|
require_once("functions.inc");
|
58
|
require_once("filter.inc");
|
59
|
require_once("shaper.inc");
|
60
|
|
61
|
$pgtitle = array(gettext("Firewall"),gettext("Schedules"),gettext("Edit"));
|
62
|
|
63
|
$referer = (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/firewall_schedule.php');
|
64
|
|
65
|
$dayArray = array (gettext('Mon'),gettext('Tues'),gettext('Wed'),gettext('Thur'),gettext('Fri'),gettext('Sat'),gettext('Sun'));
|
66
|
$monthArray = array (gettext('January'),gettext('February'),gettext('March'),gettext('April'),gettext('May'),gettext('June'),gettext('July'),gettext('August'),gettext('September'),gettext('October'),gettext('November'),gettext('December'));
|
67
|
|
68
|
if (!is_array($config['schedules']['schedule']))
|
69
|
$config['schedules']['schedule'] = array();
|
70
|
|
71
|
$a_schedules = &$config['schedules']['schedule'];
|
72
|
|
73
|
if (is_numericint($_GET['id']))
|
74
|
$id = $_GET['id'];
|
75
|
if (isset($_POST['id']) && is_numericint($_POST['id']))
|
76
|
$id = $_POST['id'];
|
77
|
|
78
|
if (isset($id) && $a_schedules[$id]) {
|
79
|
$pconfig['name'] = $a_schedules[$id]['name'];
|
80
|
$pconfig['descr'] = html_entity_decode($a_schedules[$id]['descr']);
|
81
|
$pconfig['timerange'] = $a_schedules[$id]['timerange'];
|
82
|
$pconfig['schedlabel'] = $a_schedules[$id]['schedlabel'];
|
83
|
$getSchedule = true;
|
84
|
}
|
85
|
|
86
|
if ($_POST) {
|
87
|
|
88
|
if(strtolower($_POST['name']) == "lan")
|
89
|
$input_errors[] = gettext("Schedule may not be named LAN.");
|
90
|
if(strtolower($_POST['name']) == "wan")
|
91
|
$input_errors[] = gettext("Schedule may not be named WAN.");
|
92
|
if(strtolower($_POST['name']) == "")
|
93
|
$input_errors[] = gettext("Schedule name cannot be blank.");
|
94
|
|
95
|
$x = is_validaliasname($_POST['name']);
|
96
|
if (!isset($x)) {
|
97
|
$input_errors[] = gettext("Reserved word used for schedule name.");
|
98
|
} else {
|
99
|
if (is_validaliasname($_POST['name']) == false)
|
100
|
$input_errors[] = gettext("The schedule name may only consist of the characters a-z, A-Z, 0-9");
|
101
|
}
|
102
|
|
103
|
/* check for name conflicts */
|
104
|
foreach ($a_schedules as $schedule) {
|
105
|
if (isset($id) && ($a_schedules[$id]) && ($a_schedules[$id] === $schedule))
|
106
|
continue;
|
107
|
|
108
|
if ($schedule['name'] == $_POST['name']) {
|
109
|
$input_errors[] = gettext("A Schedule with this name already exists.");
|
110
|
break;
|
111
|
}
|
112
|
}
|
113
|
$schedule = array();
|
114
|
|
115
|
$schedule['name'] = $_POST['name'];
|
116
|
$schedule['descr'] = htmlentities($_POST['descr'], ENT_QUOTES, 'UTF-8');
|
117
|
|
118
|
$timerangeFound = false;
|
119
|
for ($x=0; $x<99; $x++){
|
120
|
if($_POST['schedule' . $x]) {
|
121
|
if (!preg_match('/^[0-9]+:[0-9]+$/', $_POST['starttime' . $x])) {
|
122
|
$input_errors[] = sprintf(gettext("Invalid start time - '%s'"), $_POST['starttime' . $x]);
|
123
|
continue;
|
124
|
}
|
125
|
if (!preg_match('/^[0-9]+:[0-9]+$/', $_POST['stoptime' . $x])) {
|
126
|
$input_errors[] = sprintf(gettext("Invalid stop time - '%s'"), $_POST['stoptime' . $x]);
|
127
|
continue;
|
128
|
}
|
129
|
$timerangeFound = true;
|
130
|
$timeparts = array();
|
131
|
$firstprint = false;
|
132
|
$timestr = $_POST['schedule' . $x];
|
133
|
$timehourstr = $_POST['starttime' . $x];
|
134
|
$timehourstr .= "-";
|
135
|
$timehourstr .= $_POST['stoptime' . $x];
|
136
|
$timedescrstr = htmlentities($_POST['timedescr' . $x], ENT_QUOTES, 'UTF-8');
|
137
|
$dashpos = strpos($timestr, '-');
|
138
|
if ($dashpos === false)
|
139
|
{
|
140
|
$timeparts['position'] = $timestr;
|
141
|
}
|
142
|
else
|
143
|
{
|
144
|
$tempindarray = array();
|
145
|
$monthstr = "";
|
146
|
$daystr = "";
|
147
|
$tempindarray = explode(",", $timestr);
|
148
|
foreach ($tempindarray as $currentselection)
|
149
|
{
|
150
|
if ($currentselection){
|
151
|
if ($firstprint)
|
152
|
{
|
153
|
$monthstr .= ",";
|
154
|
$daystr .= ",";
|
155
|
}
|
156
|
$tempstr = "";
|
157
|
$monthpos = strpos($currentselection, "m");
|
158
|
$daypos = strpos($currentselection, "d");
|
159
|
$monthstr .= substr($currentselection, $monthpos+1, $daypos-$monthpos-1);
|
160
|
$daystr .= substr($currentselection, $daypos+1);
|
161
|
$firstprint = true;
|
162
|
}
|
163
|
}
|
164
|
$timeparts['month'] = $monthstr;
|
165
|
$timeparts['day'] = $daystr;
|
166
|
}
|
167
|
$timeparts['hour'] = $timehourstr;
|
168
|
$timeparts['rangedescr'] = $timedescrstr;
|
169
|
$schedule['timerange'][$x] = $timeparts;
|
170
|
}
|
171
|
}
|
172
|
|
173
|
if (!$timerangeFound)
|
174
|
$input_errors[] = gettext("The schedule must have at least one time range configured.");
|
175
|
|
176
|
if (!$input_errors) {
|
177
|
|
178
|
if (!empty($pconfig['schedlabel']))
|
179
|
$schedule['schedlabel'] = $pconfig['schedlabel'];
|
180
|
else
|
181
|
$schedule['schedlabel'] = uniqid();
|
182
|
|
183
|
if (isset($id) && $a_schedules[$id]){
|
184
|
$a_schedules[$id] = $schedule;
|
185
|
}
|
186
|
else{
|
187
|
$a_schedules[] = $schedule;
|
188
|
}
|
189
|
schedule_sort();
|
190
|
if (write_config())
|
191
|
filter_configure();
|
192
|
|
193
|
header("Location: firewall_schedule.php");
|
194
|
exit;
|
195
|
|
196
|
}
|
197
|
//we received input errors, copy data to prevent retype
|
198
|
else
|
199
|
{
|
200
|
if (!$_POST['schedule0'])
|
201
|
$getSchedule = false;
|
202
|
else
|
203
|
$getSchedule = true;
|
204
|
$pconfig['name'] = $schedule['name'];
|
205
|
$pconfig['descr'] = $schedule['descr'];
|
206
|
$pconfig['timerange'] = $schedule['timerange'];
|
207
|
}
|
208
|
|
209
|
}
|
210
|
include("head.inc");
|
211
|
|
212
|
/* put your custom HTML head content here */
|
213
|
/* using some of the $pfSenseHead function calls */
|
214
|
$jscriptstr = <<<EOD
|
215
|
<script type="text/javascript">
|
216
|
//<![CDATA[
|
217
|
var daysSelected = "";
|
218
|
var month_array = ['January','February','March','April','May','June','July','August','September','October','November','December'];
|
219
|
var day_array = ['Mon','Tues','Wed','Thur','Fri','Sat','Sun'];
|
220
|
var schCounter = 0;
|
221
|
|
222
|
function rgb2hex(rgb) {
|
223
|
var parts = rgb.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/);
|
224
|
if (parts == null)
|
225
|
return;
|
226
|
function hex(x) {
|
227
|
return ("0" + parseInt(x).toString(16)).slice(-2);
|
228
|
}
|
229
|
return ("#" + hex(parts[1]) + hex(parts[2]) + hex(parts[3])).toUpperCase();
|
230
|
}
|
231
|
|
232
|
function repeatExistingDays(){
|
233
|
var tempstr, tempstrdaypos, week, daypos, dayposdone = "";
|
234
|
|
235
|
var dayarray = daysSelected.split(",");
|
236
|
for (i=0; i<=dayarray.length; i++){
|
237
|
tempstr = dayarray[i];
|
238
|
tempstrdaypos = tempstr.search("p");
|
239
|
week = tempstr.substring(1,tempstrdaypos);
|
240
|
week = parseInt(week);
|
241
|
dashpos = tempstr.search("-");
|
242
|
daypos = tempstr.substring(tempstrdaypos+1, dashpos);
|
243
|
daypos = parseInt(daypos);
|
244
|
|
245
|
daydone = dayposdone.search(daypos);
|
246
|
tempstr = 'w' + week + 'p' + daypos;
|
247
|
daycell = eval('document.getElementById(tempstr)');
|
248
|
if (daydone == "-1"){
|
249
|
if (rgb2hex(daycell.style.backgroundColor) == "#F08080") // lightcoral
|
250
|
daytogglerepeating(week,daypos,true);
|
251
|
else
|
252
|
daytogglerepeating(week,daypos,false);
|
253
|
dayposdone += daypos + ",";
|
254
|
}
|
255
|
}
|
256
|
}
|
257
|
|
258
|
function daytogglerepeating(week,daypos,bExists){
|
259
|
var tempstr, daycell, dayoriginal = "";
|
260
|
for (j=1; j<=53; j++)
|
261
|
{
|
262
|
tempstr = 'w' + j + 'p' + daypos;
|
263
|
daycell = eval('document.getElementById(tempstr)');
|
264
|
dayoriginalpos = daysSelected.indexOf(tempstr);
|
265
|
|
266
|
//if bExists set to true, means cell is already select it
|
267
|
//unselect it and remove original day from daysSelected string
|
268
|
|
269
|
if (daycell != null)
|
270
|
{
|
271
|
if (bExists){
|
272
|
daycell.style.backgroundColor = "#FFFFFF"; // white
|
273
|
}
|
274
|
else
|
275
|
{
|
276
|
daycell.style.backgroundColor = "#F08080"; // lightcoral
|
277
|
}
|
278
|
|
279
|
if (dayoriginalpos != "-1")
|
280
|
{
|
281
|
dayoriginalend = daysSelected.indexOf(',', dayoriginalpos);
|
282
|
tempstr = daysSelected.substring(dayoriginalpos, dayoriginalend+1);
|
283
|
daysSelected = daysSelected.replace(tempstr, "");
|
284
|
|
285
|
}
|
286
|
}
|
287
|
}
|
288
|
}
|
289
|
|
290
|
function daytoggle(id) {
|
291
|
var runrepeat, tempstr = "";
|
292
|
var bFoundValid = false;
|
293
|
|
294
|
iddashpos = id.search("-");
|
295
|
var tempstrdaypos = id.search("p");
|
296
|
var week = id.substring(1,tempstrdaypos);
|
297
|
week = parseInt(week);
|
298
|
|
299
|
if (iddashpos == "-1")
|
300
|
{
|
301
|
idmod = id;
|
302
|
runrepeat = true;
|
303
|
var daypos = id.substr(tempstrdaypos+1);
|
304
|
}
|
305
|
else
|
306
|
{
|
307
|
idmod = id.substring(0,iddashpos);
|
308
|
var daypos = id.substring(tempstrdaypos+1,iddashpos);
|
309
|
}
|
310
|
|
311
|
daypos = parseInt(daypos);
|
312
|
|
313
|
while (!bFoundValid){
|
314
|
var daycell = document.getElementById(idmod);
|
315
|
|
316
|
if (daycell != null){
|
317
|
if (rgb2hex(daycell.style.backgroundColor) == "#FF0000"){ // red
|
318
|
daycell.style.backgroundColor = "#FFFFFF"; // white
|
319
|
str = id + ",";
|
320
|
daysSelected = daysSelected.replace(str, "");
|
321
|
}
|
322
|
else if (rgb2hex(daycell.style.backgroundColor) == "#F08080") // lightcoral
|
323
|
{
|
324
|
daytogglerepeating(week,daypos,true);
|
325
|
}
|
326
|
else //color is white cell
|
327
|
{
|
328
|
if (!runrepeat)
|
329
|
{
|
330
|
daycell.style.backgroundColor = "#FF0000"; // red
|
331
|
}
|
332
|
else
|
333
|
{
|
334
|
daycell.style.backgroundColor = "#F08080"; // lightcoral
|
335
|
daytogglerepeating(week,daypos,false);
|
336
|
}
|
337
|
daysSelected += id + ",";
|
338
|
}
|
339
|
bFoundValid = true;
|
340
|
}
|
341
|
else
|
342
|
{
|
343
|
//we found an invalid cell when column was clicked, move up to the next week
|
344
|
week++;
|
345
|
tempstr = "w" + week + "p" + daypos;
|
346
|
idmod = tempstr;
|
347
|
}
|
348
|
}
|
349
|
}
|
350
|
|
351
|
function update_month(){
|
352
|
var indexNum = document.forms[0].monthsel.selectedIndex;
|
353
|
var selected = document.forms[0].monthsel.options[indexNum].text;
|
354
|
|
355
|
for (i=0; i<=11; i++){
|
356
|
option = document.forms[0].monthsel.options[i].text;
|
357
|
document.popupMonthLayer = eval('document.getElementById (option)');
|
358
|
|
359
|
if(selected == option) {
|
360
|
document.popupMonthLayer.style.display="block";
|
361
|
}
|
362
|
else
|
363
|
document.popupMonthLayer.style.display="none";
|
364
|
}
|
365
|
}
|
366
|
|
367
|
function checkForRanges(){
|
368
|
if (daysSelected != "")
|
369
|
{
|
370
|
alert("You have not saved the specified time range. Please click 'Add Time' button to save the time range.");
|
371
|
return false;
|
372
|
}
|
373
|
else
|
374
|
{
|
375
|
return true;
|
376
|
}
|
377
|
}
|
378
|
|
379
|
function processEntries(){
|
380
|
var tempstr, starttimehour, starttimemin, stoptimehour, stoptimemin, errors = "";
|
381
|
var passedValidiation = true;
|
382
|
|
383
|
//get time specified
|
384
|
starttimehour = parseInt(document.getElementById("starttimehour").value);
|
385
|
starttimemin = parseInt(document.getElementById("starttimemin").value);
|
386
|
stoptimehour = parseInt(document.getElementById("stoptimehour").value);
|
387
|
stoptimemin = parseInt(document.getElementById("stoptimemin").value);
|
388
|
|
389
|
|
390
|
//do time checks
|
391
|
if (starttimehour > stoptimehour)
|
392
|
{
|
393
|
errors = "Error: Start Hour cannot be greater than Stop Hour.";
|
394
|
passedValidiation = false;
|
395
|
|
396
|
}
|
397
|
else if (starttimehour == stoptimehour)
|
398
|
{
|
399
|
if (starttimemin > stoptimemin){
|
400
|
errors = "Error: Start Minute cannot be greater than Stop Minute.";
|
401
|
passedValidiation = false;
|
402
|
}
|
403
|
}
|
404
|
|
405
|
if (passedValidiation){
|
406
|
addTimeRange();
|
407
|
}
|
408
|
else {
|
409
|
if (errors != "")
|
410
|
alert(errors);
|
411
|
}
|
412
|
}
|
413
|
|
414
|
function addTimeRange(){
|
415
|
var tempdayarray = daysSelected.split(",");
|
416
|
var tempstr, tempFriendlyDay, starttimehour, starttimemin, stoptimehour, nrtempFriendlyTime, rtempFriendlyTime, nrtempID, rtempID = "";
|
417
|
var stoptimemin, timeRange, tempstrdaypos, week, daypos, day, month, dashpos, nrtempTime, rtempTime, monthstr, daystr = "";
|
418
|
rtempFriendlyTime = "";
|
419
|
nrtempFriendlyTime = "";
|
420
|
nrtempID = "";
|
421
|
rtempID = "";
|
422
|
nrtempTime = "";
|
423
|
rtempTime = "";
|
424
|
tempdayarray.sort();
|
425
|
rtempFriendlyDay = "";
|
426
|
monthstr = "";
|
427
|
daystr = "";
|
428
|
|
429
|
//check for existing entries
|
430
|
var findCurrentCounter;
|
431
|
for (u=0; u<99; u++){
|
432
|
findCurrentCounter = document.getElementById("schedule" + u);
|
433
|
if (!findCurrentCounter)
|
434
|
{
|
435
|
schCounter = u;
|
436
|
break;
|
437
|
}
|
438
|
}
|
439
|
|
440
|
if (daysSelected != ""){
|
441
|
//get days selected
|
442
|
for (i=0; i<tempdayarray.length; i++)
|
443
|
{
|
444
|
tempstr = tempdayarray[i];
|
445
|
if (tempstr != "")
|
446
|
{
|
447
|
tempstrdaypos = tempstr.search("p");
|
448
|
week = tempstr.substring(1,tempstrdaypos);
|
449
|
week = parseInt(week);
|
450
|
dashpos = tempstr.search("-");
|
451
|
|
452
|
if (dashpos != "-1")
|
453
|
{
|
454
|
var nonrepeatingfound = true;
|
455
|
daypos = tempstr.substring(tempstrdaypos+1, dashpos);
|
456
|
daypos = parseInt(daypos);
|
457
|
monthpos = tempstr.search("m");
|
458
|
tempstrdaypos = tempstr.search("d");
|
459
|
month = tempstr.substring(monthpos+1, tempstrdaypos);
|
460
|
month = parseInt(month);
|
461
|
day = tempstr.substring(tempstrdaypos+1);
|
462
|
day = parseInt(day);
|
463
|
monthstr += month + ",";
|
464
|
daystr += day + ",";
|
465
|
nrtempID += tempstr + ",";
|
466
|
}
|
467
|
else
|
468
|
{
|
469
|
var repeatingfound = true;
|
470
|
daypos = tempstr.substr(tempstrdaypos+1);
|
471
|
daypos = parseInt(daypos);
|
472
|
rtempFriendlyDay += daypos + ",";
|
473
|
rtempID += daypos + ",";
|
474
|
}
|
475
|
}
|
476
|
}
|
477
|
|
478
|
//code below spits out friendly look format for nonrepeating schedules
|
479
|
var foundEnd = false;
|
480
|
var firstDayFound = false;
|
481
|
var firstprint = false;
|
482
|
var tempFriendlyMonthArray = monthstr.split(",");
|
483
|
var tempFriendlyDayArray = daystr.split(",");
|
484
|
var currentDay, firstDay, nextDay, currentMonth, nextMonth, firstDay, firstMonth = "";
|
485
|
for (k=0; k<tempFriendlyMonthArray.length; k++){
|
486
|
tempstr = tempFriendlyMonthArray[k];
|
487
|
if (tempstr != ""){
|
488
|
if (!firstDayFound)
|
489
|
{
|
490
|
firstDay = tempFriendlyDayArray[k];
|
491
|
firstDay = parseInt(firstDay);
|
492
|
firstMonth = tempFriendlyMonthArray[k];
|
493
|
firstMonth = parseInt(firstMonth);
|
494
|
firstDayFound = true;
|
495
|
}
|
496
|
currentDay = tempFriendlyDayArray[k];
|
497
|
currentDay = parseInt(currentDay);
|
498
|
//get next day
|
499
|
nextDay = tempFriendlyDayArray[k+1];
|
500
|
nextDay = parseInt(nextDay);
|
501
|
//get next month
|
502
|
|
503
|
currentDay++;
|
504
|
if ((currentDay != nextDay) || (tempFriendlyMonthArray[k] != tempFriendlyMonthArray[k+1])){
|
505
|
if (firstprint)
|
506
|
nrtempFriendlyTime += ", ";
|
507
|
currentDay--;
|
508
|
if (currentDay != firstDay)
|
509
|
nrtempFriendlyTime += month_array[firstMonth-1] + " " + firstDay + "-" + currentDay;
|
510
|
else
|
511
|
nrtempFriendlyTime += month_array[firstMonth-1] + " " + currentDay;
|
512
|
firstDayFound = false;
|
513
|
firstprint = true;
|
514
|
}
|
515
|
}
|
516
|
}
|
517
|
|
518
|
//code below spits out friendly look format for repeating schedules
|
519
|
foundEnd = false;
|
520
|
firstDayFound = false;
|
521
|
firstprint = false;
|
522
|
tempFriendlyDayArray = rtempFriendlyDay.split(",");
|
523
|
tempFriendlyDayArray.sort();
|
524
|
currentDay, firstDay, nextDay = "";
|
525
|
for (k=0; k<tempFriendlyDayArray.length; k++){
|
526
|
tempstr = tempFriendlyDayArray[k];
|
527
|
if (tempstr != ""){
|
528
|
if (!firstDayFound)
|
529
|
{
|
530
|
firstDay = tempFriendlyDayArray[k];
|
531
|
firstDay = parseInt(firstDay);
|
532
|
firstDayFound = true;
|
533
|
}
|
534
|
currentDay = tempFriendlyDayArray[k];
|
535
|
currentDay = parseInt(currentDay);
|
536
|
//get next day
|
537
|
nextDay = tempFriendlyDayArray[k+1];
|
538
|
nextDay = parseInt(nextDay);
|
539
|
currentDay++;
|
540
|
if (currentDay != nextDay){
|
541
|
if (firstprint)
|
542
|
rtempFriendlyTime += ", ";
|
543
|
currentDay--;
|
544
|
if (currentDay != firstDay)
|
545
|
rtempFriendlyTime += day_array[firstDay-1] + " - " + day_array[currentDay-1];
|
546
|
else
|
547
|
rtempFriendlyTime += day_array[firstDay-1];
|
548
|
firstDayFound = false;
|
549
|
firstprint = true;
|
550
|
}
|
551
|
}
|
552
|
}
|
553
|
|
554
|
//sort the tempID
|
555
|
var tempsortArray = rtempID.split(",");
|
556
|
var isFirstdone = false;
|
557
|
tempsortArray.sort();
|
558
|
//clear tempID
|
559
|
rtempID = "";
|
560
|
for (t=0; t<tempsortArray.length; t++)
|
561
|
{
|
562
|
if (tempsortArray[t] != ""){
|
563
|
if (!isFirstdone){
|
564
|
rtempID += tempsortArray[t];
|
565
|
isFirstdone = true;
|
566
|
}
|
567
|
else
|
568
|
rtempID += "," + tempsortArray[t];
|
569
|
}
|
570
|
}
|
571
|
|
572
|
|
573
|
//get time specified
|
574
|
starttimehour = document.getElementById("starttimehour").value
|
575
|
starttimemin = document.getElementById("starttimemin").value;
|
576
|
stoptimehour = document.getElementById("stoptimehour").value;
|
577
|
stoptimemin = document.getElementById("stoptimemin").value;
|
578
|
|
579
|
timeRange = "||" + starttimehour + ":";
|
580
|
timeRange += starttimemin + "-";
|
581
|
timeRange += stoptimehour + ":";
|
582
|
timeRange += stoptimemin;
|
583
|
|
584
|
//get description for time range
|
585
|
var tempdescr = document.getElementById("timerangedescr").value
|
586
|
|
587
|
if (nonrepeatingfound){
|
588
|
nrtempTime += nrtempID;
|
589
|
//add time ranges
|
590
|
nrtempTime += timeRange;
|
591
|
//add description
|
592
|
nrtempTime += "||" + tempdescr;
|
593
|
insertElements(nrtempFriendlyTime, starttimehour, starttimemin, stoptimehour, stoptimemin, tempdescr, nrtempTime, nrtempID);
|
594
|
}
|
595
|
|
596
|
if (repeatingfound){
|
597
|
rtempTime += rtempID;
|
598
|
//add time ranges
|
599
|
rtempTime += timeRange;
|
600
|
//add description
|
601
|
rtempTime += "||" + tempdescr;
|
602
|
insertElements(rtempFriendlyTime, starttimehour, starttimemin, stoptimehour, stoptimemin, tempdescr, rtempTime, rtempID);
|
603
|
}
|
604
|
|
605
|
}
|
606
|
else
|
607
|
{
|
608
|
//no days were selected, alert user
|
609
|
alert ("You must select at least 1 day before adding time");
|
610
|
}
|
611
|
}
|
612
|
|
613
|
function insertElements(tempFriendlyTime, starttimehour, starttimemin, stoptimehour, stoptimemin, tempdescr, tempTime, tempID){
|
614
|
|
615
|
//add it to the schedule list
|
616
|
d = document;
|
617
|
tbody = d.getElementById("scheduletable").getElementsByTagName("tbody").item(0);
|
618
|
tr = d.createElement("tr");
|
619
|
td = d.createElement("td");
|
620
|
td.innerHTML= "<span class='vexpl'>" + tempFriendlyTime + "<\/span>";
|
621
|
tr.appendChild(td);
|
622
|
|
623
|
td = d.createElement("td");
|
624
|
td.innerHTML="<input type='text' readonly class='vexpl' name='starttime" + schCounter + "' id='starttime" + schCounter + "' style=' word-wrap:break-word; width:100%; border:0px solid;' value='" + starttimehour + ":" + starttimemin + "' />";
|
625
|
tr.appendChild(td);
|
626
|
|
627
|
td = d.createElement("td");
|
628
|
td.innerHTML="<input type='text' readonly class='vexpl' name='stoptime" + schCounter + "' id='stoptime" + schCounter + "' style=' word-wrap:break-word; width:100%; border:0px solid;' value='" + stoptimehour + ":" + stoptimemin + "' />";
|
629
|
tr.appendChild(td);
|
630
|
|
631
|
td = d.createElement("td");
|
632
|
td.innerHTML="<input type='text' readonly class='vexpl' name='timedescr" + schCounter + "' id='timedescr" + schCounter + "' style=' word-wrap:break-word; width:100%; border:0px solid;' value='" + tempdescr + "' />";
|
633
|
tr.appendChild(td);
|
634
|
|
635
|
td = d.createElement("td");
|
636
|
td.innerHTML = "<a onclick='editRow(\"" + tempTime + "\",this); return false;' href='#'><img border='0' src='/themes/" + theme + "/images/icons/icon_e.gif' alt='edit' /></\a>";
|
637
|
tr.appendChild(td);
|
638
|
|
639
|
td = d.createElement("td");
|
640
|
td.innerHTML = "<a onclick='removeRow(this); return false;' href='#'><img border='0' src='/themes/" + theme + "/images/icons/icon_x.gif' alt='remove' /></\a>";
|
641
|
tr.appendChild(td);
|
642
|
|
643
|
td = d.createElement("td");
|
644
|
td.innerHTML="<input type='hidden' id='schedule" + schCounter + "' name='schedule" + schCounter + "' value='" + tempID + "' />";
|
645
|
tr.appendChild(td);
|
646
|
tbody.appendChild(tr);
|
647
|
|
648
|
schCounter++;
|
649
|
|
650
|
//reset calendar and time and descr
|
651
|
clearCalendar();
|
652
|
clearTime();
|
653
|
clearDescr();
|
654
|
}
|
655
|
|
656
|
|
657
|
function clearCalendar(){
|
658
|
var tempstr, daycell = "";
|
659
|
//clear days selected
|
660
|
daysSelected = "";
|
661
|
//loop through all 52 weeks
|
662
|
for (j=1; j<=53; j++)
|
663
|
{
|
664
|
//loop through all 7 days
|
665
|
for (k=1; k<8; k++){
|
666
|
tempstr = 'w' + j + 'p' + k;
|
667
|
daycell = eval('document.getElementById(tempstr)');
|
668
|
if (daycell != null){
|
669
|
daycell.style.backgroundColor = "#FFFFFF"; // white
|
670
|
}
|
671
|
}
|
672
|
}
|
673
|
}
|
674
|
|
675
|
function clearTime(){
|
676
|
document.getElementById("starttimehour").value = "0";
|
677
|
document.getElementById("starttimemin").value = "00";
|
678
|
document.getElementById("stoptimehour").value = "23";
|
679
|
document.getElementById("stoptimemin").value = "59";
|
680
|
}
|
681
|
|
682
|
function clearDescr(){
|
683
|
document.getElementById("timerangedescr").value = "";
|
684
|
}
|
685
|
|
686
|
function editRow(incTime, el) {
|
687
|
var check = checkForRanges();
|
688
|
|
689
|
if (check){
|
690
|
|
691
|
//reset calendar and time
|
692
|
clearCalendar();
|
693
|
clearTime();
|
694
|
|
695
|
var starttimehour, descr, days, tempstr, starttimemin, hours, stoptimehour, stoptimemin = "";
|
696
|
|
697
|
tempArray = incTime.split ("||");
|
698
|
|
699
|
days = tempArray[0];
|
700
|
hours = tempArray[1];
|
701
|
descr = tempArray[2];
|
702
|
|
703
|
var tempdayArray = days.split(",");
|
704
|
var temphourArray = hours.split("-");
|
705
|
tempstr = temphourArray[0];
|
706
|
var temphourArray2 = tempstr.split(":");
|
707
|
|
708
|
document.getElementById("starttimehour").value = temphourArray2[0];
|
709
|
document.getElementById("starttimemin").value = temphourArray2[1];
|
710
|
|
711
|
tempstr = temphourArray[1];
|
712
|
temphourArray2 = tempstr.split(":");
|
713
|
|
714
|
document.getElementById("stoptimehour").value = temphourArray2[0];
|
715
|
document.getElementById("stoptimemin").value = temphourArray2[1];
|
716
|
|
717
|
document.getElementById("timerangedescr").value = descr;
|
718
|
|
719
|
//toggle the appropriate days
|
720
|
for (i=0; i<tempdayArray.length; i++)
|
721
|
{
|
722
|
if (tempdayArray[i]){
|
723
|
var tempweekstr = tempdayArray[i];
|
724
|
dashpos = tempweekstr.search("-");
|
725
|
|
726
|
if (dashpos == "-1")
|
727
|
{
|
728
|
tempstr = "w2p" + tempdayArray[i];
|
729
|
}
|
730
|
else
|
731
|
{
|
732
|
tempstr = tempdayArray[i];
|
733
|
}
|
734
|
daytoggle(tempstr);
|
735
|
}
|
736
|
}
|
737
|
removeRownoprompt(el);
|
738
|
}
|
739
|
}
|
740
|
|
741
|
function removeRownoprompt(el) {
|
742
|
var cel;
|
743
|
while (el && el.nodeName.toLowerCase() != "tr")
|
744
|
el = el.parentNode;
|
745
|
|
746
|
if (el && el.parentNode) {
|
747
|
cel = el.getElementsByTagName("td").item(0);
|
748
|
el.parentNode.removeChild(el);
|
749
|
}
|
750
|
}
|
751
|
|
752
|
|
753
|
function removeRow(el) {
|
754
|
var check = confirm ("Do you really want to delete this time range?");
|
755
|
if (check){
|
756
|
var cel;
|
757
|
while (el && el.nodeName.toLowerCase() != "tr")
|
758
|
el = el.parentNode;
|
759
|
|
760
|
if (el && el.parentNode) {
|
761
|
cel = el.getElementsByTagName("td").item(0);
|
762
|
el.parentNode.removeChild(el);
|
763
|
}
|
764
|
}
|
765
|
}
|
766
|
//]]>
|
767
|
</script>
|
768
|
EOD;
|
769
|
?>
|
770
|
|
771
|
<body link="#0000CC" vlink="#0000CC" alink="#0000CC" onload="<?= $jsevents["body"]["onload"] ?>">
|
772
|
|
773
|
|
774
|
<?php include("fbegin.inc"); echo $jscriptstr; ?>
|
775
|
<?php if ($input_errors) print_input_errors($input_errors); ?>
|
776
|
<div id="inputerrors"></div>
|
777
|
|
778
|
<form action="firewall_schedule_edit.php" method="post" name="iform" id="iform">
|
779
|
<table width="100%" border="0" cellpadding="0" cellspacing="0" summary="firewall schedule">
|
780
|
<tr>
|
781
|
<td colspan="2" valign="top" class="listtopic"><?=gettext("Schedule information");?></td>
|
782
|
</tr>
|
783
|
<tr>
|
784
|
<td>
|
785
|
<table width="100%" border="0" cellpadding="6" cellspacing="0" summary="main area">
|
786
|
<tr>
|
787
|
<td width="15%" valign="top" class="vncellreq"><?=gettext("Schedule Name");?></td>
|
788
|
<td width="85%" class="vtable">
|
789
|
<?php if(is_schedule_inuse($pconfig['name']) == true): ?>
|
790
|
<input name="name" type="hidden" id="name" size="40" value="<?=htmlspecialchars($pconfig['name']);?>" />
|
791
|
<?php echo $pconfig['name']; ?>
|
792
|
<p>
|
793
|
<span class="vexpl"><?=gettext("NOTE: This schedule is in use so the name may not be modified!");?></span>
|
794
|
</p>
|
795
|
<?php else: ?>
|
796
|
<input name="name" type="text" id="name" size="40" maxlength="40" class="formfld unknown" value="<?=htmlspecialchars($pconfig['name']);?>" /><br />
|
797
|
<span class="vexpl">
|
798
|
<?=gettext("The name of the alias may only consist of the characters a-z, A-Z and 0-9");?>
|
799
|
</span>
|
800
|
<?php endif; ?>
|
801
|
</td>
|
802
|
</tr>
|
803
|
<tr>
|
804
|
<td width="15%" valign="top" class="vncell"><?=gettext("Description");?></td>
|
805
|
<td width="85%" class="vtable"><input name="descr" type="text" id="descr" size="40" maxlength="40" class="formfld unknown" value="<?=htmlspecialchars($pconfig['descr']);?>" /><br />
|
806
|
<span class="vexpl">
|
807
|
<?=gettext("You may enter a description here for your reference (not parsed).");?>
|
808
|
</span>
|
809
|
|
810
|
</td>
|
811
|
</tr>
|
812
|
<!-- tr>
|
813
|
</tr -->
|
814
|
<tr>
|
815
|
<td width="15%" valign="top" class="vncellreq"><?=gettext("Month");?></td>
|
816
|
<td width="85%" class="vtable">
|
817
|
<select name="monthsel" class="formselect" id="monthsel" onchange="update_month();">
|
818
|
<?php
|
819
|
$monthcounter = date("n");
|
820
|
$monthlimit = $monthcounter + 12;
|
821
|
$yearcounter = date("Y");
|
822
|
for ($k=0; $k<12; $k++){?>
|
823
|
<option value="<?php echo $monthcounter;?>"><?php echo date("F_y", mktime(0, 0, 0, date($monthcounter), 1, date($yearcounter)));?></option>
|
824
|
<?php
|
825
|
if ($monthcounter == 12)
|
826
|
{
|
827
|
$monthcounter = 1;
|
828
|
$yearcounter++;
|
829
|
}
|
830
|
else
|
831
|
{
|
832
|
$monthcounter++;
|
833
|
}
|
834
|
} ?>
|
835
|
</select><br /><br />
|
836
|
<?php
|
837
|
$firstmonth = TRUE;
|
838
|
$monthcounter = date("n");
|
839
|
$yearcounter = date("Y");
|
840
|
for ($k=0; $k<12; $k++){
|
841
|
$firstdayofmonth = date("w", mktime(0, 0, 0, date($monthcounter), 1, date($yearcounter)));
|
842
|
if ($firstdayofmonth == 0)
|
843
|
$firstdayofmonth = 7;
|
844
|
|
845
|
$daycounter = 1;
|
846
|
//number of day in month
|
847
|
$numberofdays = date("t", mktime(0, 0, 0, date($monthcounter), 1, date($yearcounter)));
|
848
|
$firstdayprinted = FALSE;
|
849
|
$lasttr = FALSE;
|
850
|
$positioncounter = 1;//7 for Sun, 1 for Mon, 2 for Tues, etc
|
851
|
?>
|
852
|
<div id="<?php echo date("F_y",mktime(0, 0, 0, date($monthcounter), 1, date($yearcounter)));?>" style=" position:relative; display:<?php if($firstmonth)echo "block";else echo "none";?>">
|
853
|
<table border="1" cellspacing="1" cellpadding="1" id="calTable<?=$monthcounter . $yearcounter;?>" class="tabcont" summary="month">
|
854
|
<tr><td colspan="7" align="center" class="listbg"><b><?php echo date("F_Y", mktime(0, 0, 0, date($monthcounter), 1, date($yearcounter)));?></b></td>
|
855
|
</tr>
|
856
|
<tr>
|
857
|
<td align="center" class="listhdrr" style="cursor: pointer;" onclick="daytoggle('w1p1');"><u><b><?=gettext("Mon");?></b></u></td>
|
858
|
<td align="center" class="listhdrr" style="cursor: pointer;" onclick="daytoggle('w1p2');"><u><b><?=gettext("Tue");?></b></u></td>
|
859
|
<td align="center" class="listhdrr" style="cursor: pointer;" onclick="daytoggle('w1p3');"><u><b><?=gettext("Wed");?></b></u></td>
|
860
|
<td align="center" class="listhdrr" style="cursor: pointer;" onclick="daytoggle('w1p4');"><u><b><?=gettext("Thu");?></b></u></td>
|
861
|
<td align="center" class="listhdrr" style="cursor: pointer;" onclick="daytoggle('w1p5');"><u><b><?=gettext("Fri");?></b></u></td>
|
862
|
<td align="center" class="listhdrr" style="cursor: pointer;" onclick="daytoggle('w1p6');"><u><b><?=gettext("Sat");?></b></u></td>
|
863
|
<td align="center" class="listhdrr" style="cursor: pointer;" onclick="daytoggle('w1p7');"><u><b><?=gettext("Sun");?></b></u></td>
|
864
|
</tr>
|
865
|
<?php
|
866
|
$firstmonth = FALSE;
|
867
|
while ($daycounter<=$numberofdays){
|
868
|
$weekcounter = date("W", mktime(0, 0, 0, date($monthcounter), date($daycounter), date($yearcounter)));
|
869
|
$weekcounter = ltrim($weekcounter, "0");
|
870
|
if ($positioncounter == 1)
|
871
|
{
|
872
|
echo "<tr>";
|
873
|
}
|
874
|
if ($firstdayofmonth == $positioncounter){?>
|
875
|
<td align="center" style="cursor: pointer;" class="listr" id="w<?=$weekcounter;?>p<?=$positioncounter;?>" onclick="daytoggle('w<?=$weekcounter;?>p<?=$positioncounter;?>-m<?=$monthcounter;?>d<?=$daycounter;?>');">
|
876
|
<?php echo $daycounter;
|
877
|
$daycounter++;
|
878
|
$firstdayprinted = TRUE;
|
879
|
echo "</td>";
|
880
|
}
|
881
|
elseif ($firstdayprinted == TRUE && $daycounter <= $numberofdays){?>
|
882
|
<td align="center" style="cursor: pointer;" class="listr" id="w<?=$weekcounter;?>p<?=$positioncounter;?>" onclick="daytoggle('w<?=$weekcounter;?>p<?=$positioncounter;?>-m<?=$monthcounter;?>d<?=$daycounter;?>');">
|
883
|
<?php echo $daycounter;
|
884
|
$daycounter++;
|
885
|
echo "</td>";
|
886
|
}
|
887
|
else
|
888
|
{
|
889
|
echo "<td align=\"center\" class=\"listr\"></td>";
|
890
|
}
|
891
|
|
892
|
if ($positioncounter == 7 || $daycounter > $numberofdays){
|
893
|
$positioncounter = 1;
|
894
|
echo "</tr>";
|
895
|
}
|
896
|
else{
|
897
|
$positioncounter++;
|
898
|
}
|
899
|
|
900
|
}//end while loop?>
|
901
|
</table>
|
902
|
</div>
|
903
|
<?php
|
904
|
|
905
|
if ($monthcounter == 12)
|
906
|
{
|
907
|
$monthcounter = 1;
|
908
|
$yearcounter++;
|
909
|
}
|
910
|
else
|
911
|
{
|
912
|
$monthcounter++;
|
913
|
}
|
914
|
} //end for loop
|
915
|
?>
|
916
|
<br />
|
917
|
<?=gettext("Click individual date to select that date only. Click the appropriate weekday Header to select all occurrences of that weekday.");?>
|
918
|
</td>
|
919
|
</tr>
|
920
|
<tr>
|
921
|
<td width="15%" valign="top" class="vncellreq"><?=gettext("Time");?></td>
|
922
|
<td width="85%" class="vtable">
|
923
|
<table cellspacing="2" class="tabcont" summary="time">
|
924
|
<tr>
|
925
|
<td class="listhdrr" align="center"><?=gettext("Start Time");?></td><td></td><td class="listhdrr" align="center"><?=gettext("Stop Time");?></td>
|
926
|
</tr>
|
927
|
<tr>
|
928
|
<td>
|
929
|
<select name="starttimehour" class="formselect" id="starttimehour">
|
930
|
<?php
|
931
|
for ($i=0; $i<24; $i++)
|
932
|
{
|
933
|
echo "<option value=\"$i\">";
|
934
|
echo $i;
|
935
|
echo "</option>";
|
936
|
}
|
937
|
?>
|
938
|
</select> <?=gettext("Hr"); ?>
|
939
|
<select name="starttimemin" class="formselect" id="starttimemin">
|
940
|
<option value="00">00</option>
|
941
|
<option value="15">15</option>
|
942
|
<option value="30">30</option>
|
943
|
<option value="45">45</option>
|
944
|
<option value="59">59</option>
|
945
|
</select> <?=gettext("Min"); ?>
|
946
|
</td>
|
947
|
<td></td>
|
948
|
<td>
|
949
|
<select name="stoptimehour" class="formselect" id="stoptimehour">
|
950
|
<?php
|
951
|
for ($i=0; $i<24; $i++)
|
952
|
{
|
953
|
if ($i==23)
|
954
|
$selected = "selected=\"selected\"";
|
955
|
else
|
956
|
$selected = "";
|
957
|
|
958
|
echo "<option value=\"$i\" $selected>";
|
959
|
echo $i;
|
960
|
echo "</option>";
|
961
|
}
|
962
|
?>
|
963
|
</select> <?=gettext("Hr");?>
|
964
|
<select name="stoptimemin" class="formselect" id="stoptimemin">
|
965
|
<option value="00">00</option>
|
966
|
<option value="15">15</option>
|
967
|
<option value="30">30</option>
|
968
|
<option value="45">45</option>
|
969
|
<option value="59" selected="selected">59</option>
|
970
|
</select> <?=gettext("Min");?>
|
971
|
</td>
|
972
|
</tr>
|
973
|
</table><br />
|
974
|
<?=gettext("Select the time range for the day(s) selected on the Month(s) above. A full day is 0:00-23:59.")?>
|
975
|
</td>
|
976
|
</tr>
|
977
|
<tr>
|
978
|
<td width="15%" valign="top" class="vncell"><?=gettext("Time Range Description")?></td>
|
979
|
<td width="85%" class="vtable"><input name="timerangedescr" type="text" class="formfld unknown" id="timerangedescr" size="40" maxlength="40" /><br />
|
980
|
<span class="vexpl">
|
981
|
<?=gettext("You may enter a description here for your reference (not parsed).")?>
|
982
|
</span>
|
983
|
</td>
|
984
|
</tr>
|
985
|
<tr>
|
986
|
<td width="22%" valign="top"> </td>
|
987
|
<td width="78%">
|
988
|
<input type="button" value="<?=gettext("Add Time");?>" class="formbtn" onclick="javascript:processEntries();" />
|
989
|
<input type="button" value="<?=gettext("Clear Selection");?>" class="formbtn" onclick="javascript:clearCalendar(); clearTime(); clearDescr();" />
|
990
|
</td>
|
991
|
</tr>
|
992
|
<tr>
|
993
|
<td width="15%" valign="top" class="vtable"></td>
|
994
|
<td width="85%" class="vtable">
|
995
|
</td>
|
996
|
</tr>
|
997
|
<tr>
|
998
|
<td colspan="2" valign="top" class="listtopic"><?=gettext("Schedule repeat");?></td>
|
999
|
</tr>
|
1000
|
<tr>
|
1001
|
<td width="15%" valign="top" class="vncellreq"><?=gettext("Configured Ranges");?></td>
|
1002
|
<td width="85%">
|
1003
|
<table id="scheduletable" summary="range">
|
1004
|
<tbody>
|
1005
|
<tr>
|
1006
|
<td align="center" class="listbg" width="35%"><?=gettext("Day(s)");?></td>
|
1007
|
<td align="center" class="listbg" width="12%"><?=gettext("Start Time");?></td>
|
1008
|
<td align="center" class="listbg" width="11%"><?=gettext("Stop Time");?></td>
|
1009
|
<td align="center" class="listbg" width="42%"><?=gettext("Description");?></td>
|
1010
|
</tr>
|
1011
|
<?php
|
1012
|
if ($getSchedule){
|
1013
|
$counter = 0;
|
1014
|
|
1015
|
foreach($pconfig['timerange'] as $timerange) {
|
1016
|
$tempFriendlyTime = "";
|
1017
|
$tempID = "";
|
1018
|
if ($timerange){
|
1019
|
$dayFriendly = "";
|
1020
|
$tempFriendlyTime = "";
|
1021
|
$timedescr = $timerange['rangedescr'];
|
1022
|
|
1023
|
//get hours
|
1024
|
$temptimerange = $timerange['hour'];
|
1025
|
$temptimeseparator = strrpos($temptimerange, "-");
|
1026
|
|
1027
|
$starttime = substr ($temptimerange, 0, $temptimeseparator);
|
1028
|
$stoptime = substr ($temptimerange, $temptimeseparator+1);
|
1029
|
$currentDay = "";
|
1030
|
$firstDay = "";
|
1031
|
$nextDay = "";
|
1032
|
$foundEnd = false;
|
1033
|
$firstDayFound = false;
|
1034
|
$firstPrint = false;
|
1035
|
$firstprint2 = false;
|
1036
|
|
1037
|
if ($timerange['month']){
|
1038
|
$tempmontharray = explode(",", $timerange['month']);
|
1039
|
$tempdayarray = explode(",",$timerange['day']);
|
1040
|
$arraycounter = 0;
|
1041
|
foreach ($tempmontharray as $monthtmp){
|
1042
|
$month = $tempmontharray[$arraycounter];
|
1043
|
$day = $tempdayarray[$arraycounter];
|
1044
|
$daypos = date("w", mktime(0, 0, 0, date($month), date($day), date("Y")));
|
1045
|
//if sunday, set position to 7 to get correct week number. This is due to php limitations on ISO-8601. When we move to php5.1 we can change this.
|
1046
|
if ($daypos == 0){
|
1047
|
$daypos = 7;
|
1048
|
}
|
1049
|
$weeknumber = date("W", mktime(0, 0, 0, date($month), date($day), date("Y")));
|
1050
|
$weeknumber = ltrim($weeknumber, "0");
|
1051
|
|
1052
|
if ($firstPrint)
|
1053
|
{
|
1054
|
$tempID .= ",";
|
1055
|
}
|
1056
|
$tempID .= "w" . $weeknumber . "p" . $daypos . "-m" . $month . "d" . $day;
|
1057
|
$firstPrint = true;
|
1058
|
|
1059
|
if (!$firstDayFound)
|
1060
|
{
|
1061
|
$firstDay = $day;
|
1062
|
$firstmonth = $month;
|
1063
|
$firstDayFound = true;
|
1064
|
}
|
1065
|
|
1066
|
$currentDay = $day;
|
1067
|
$nextDay = $tempdayarray[$arraycounter+1];
|
1068
|
$currentDay++;
|
1069
|
if (($currentDay != $nextDay) || ($tempmontharray[$arraycounter] != $tempmontharray[$arraycounter+1])){
|
1070
|
if ($firstprint2)
|
1071
|
$tempFriendlyTime .= ", ";
|
1072
|
$currentDay--;
|
1073
|
if ($currentDay != $firstDay)
|
1074
|
$tempFriendlyTime .= $monthArray[$firstmonth-1] . " " . $firstDay . " - " . $currentDay ;
|
1075
|
else
|
1076
|
$tempFriendlyTime .= $monthArray[$month-1] . " " . $day;
|
1077
|
$firstDayFound = false;
|
1078
|
$firstprint2 = true;
|
1079
|
}
|
1080
|
$arraycounter++;
|
1081
|
}
|
1082
|
|
1083
|
}
|
1084
|
else
|
1085
|
{
|
1086
|
$dayFriendly = $timerange['position'];
|
1087
|
$tempID = $dayFriendly;
|
1088
|
}
|
1089
|
|
1090
|
$tempTime = $tempID . "||" . $starttime . "-" . $stoptime . "||" . $timedescr;
|
1091
|
|
1092
|
//following code makes the days friendly appearing, IE instead of Mon, Tues, Wed it will show Mon - Wed
|
1093
|
$foundEnd = false;
|
1094
|
$firstDayFound = false;
|
1095
|
$firstprint = false;
|
1096
|
$tempFriendlyDayArray = explode(",", $dayFriendly);
|
1097
|
$currentDay = "";
|
1098
|
$firstDay = "";
|
1099
|
$nextDay = "";
|
1100
|
$i = 0;
|
1101
|
if (!$timerange['month']){
|
1102
|
foreach ($tempFriendlyDayArray as $day){
|
1103
|
if ($day != ""){
|
1104
|
if (!$firstDayFound)
|
1105
|
{
|
1106
|
$firstDay = $tempFriendlyDayArray[$i];
|
1107
|
$firstDayFound = true;
|
1108
|
}
|
1109
|
$currentDay =$tempFriendlyDayArray[$i];
|
1110
|
//get next day
|
1111
|
$nextDay = $tempFriendlyDayArray[$i+1];
|
1112
|
$currentDay++;
|
1113
|
if ($currentDay != $nextDay){
|
1114
|
if ($firstprint)
|
1115
|
$tempFriendlyTime .= ", ";
|
1116
|
$currentDay--;
|
1117
|
if ($currentDay != $firstDay)
|
1118
|
$tempFriendlyTime .= $dayArray[$firstDay-1] . " - " . $dayArray[$currentDay-1];
|
1119
|
else
|
1120
|
$tempFriendlyTime .= $dayArray[$firstDay-1];
|
1121
|
$firstDayFound = false;
|
1122
|
$firstprint = true;
|
1123
|
}
|
1124
|
$i++;
|
1125
|
}
|
1126
|
}
|
1127
|
}
|
1128
|
|
1129
|
|
1130
|
?>
|
1131
|
<tr>
|
1132
|
<td>
|
1133
|
<span class="vexpl"><?php echo $tempFriendlyTime; ?></span>
|
1134
|
</td>
|
1135
|
<td>
|
1136
|
<input type='text' readonly='readonly' class='vexpl' name='starttime<?php echo $counter; ?>' id='starttime<?php echo $counter; ?>' style=' word-wrap:break-word; width:100%; border:0px solid;' value='<?php echo $starttime; ?>' />
|
1137
|
</td>
|
1138
|
<td>
|
1139
|
<input type='text' readonly='readonly' class='vexpl' name='stoptime<?php echo $counter; ?>' id='stoptime<?php echo $counter; ?>' style=' word-wrap:break-word; width:100%; border:0px solid;' value='<?php echo $stoptime; ?>' />
|
1140
|
</td>
|
1141
|
<td>
|
1142
|
<input type='text' readonly='readonly' class='vexpl' name='timedescr<?php echo $counter; ?>' id='timedescr<?php echo $counter; ?>' style=' word-wrap:break-word; width:100%; border:0px solid;' value='<?php echo $timedescr; ?>' />
|
1143
|
</td>
|
1144
|
<td>
|
1145
|
<a onclick='editRow("<?php echo $tempTime; ?>",this); return false;' href='#'><img border='0' src='/themes/<?php echo $g['theme']; ?>/images/icons/icon_e.gif' alt='edit' /></a>
|
1146
|
</td>
|
1147
|
<td>
|
1148
|
<a onclick='removeRow(this); return false;' href='#'><img border='0' src='/themes/<?php echo $g['theme']; ?>/images/icons/icon_x.gif' alt='remove' /></a>
|
1149
|
</td>
|
1150
|
<td>
|
1151
|
<input type='hidden' id='schedule<?php echo $counter; ?>' name='schedule<?php echo $counter; ?>' value='<?php echo $tempID; ?>' />
|
1152
|
</td>
|
1153
|
</tr>
|
1154
|
<?php
|
1155
|
$counter++;
|
1156
|
}//end if
|
1157
|
} // end foreach
|
1158
|
}//end if
|
1159
|
?>
|
1160
|
</tbody>
|
1161
|
</table>
|
1162
|
</td>
|
1163
|
</tr>
|
1164
|
<tr>
|
1165
|
<td width="15%" valign="top"> </td>
|
1166
|
<td width="85%">
|
1167
|
<input id="submit" name="submit" type="submit" onclick="return checkForRanges();" class="formbtn" value="<?=gettext("Save"); ?>" />
|
1168
|
<input type="button" class="formbtn" value="<?=gettext("Cancel");?>" onclick="window.location.href='<?=$referer;?>'" />
|
1169
|
<?php if (isset($id) && $a_schedules[$id]): ?>
|
1170
|
<input name="id" type="hidden" value="<?=htmlspecialchars($id);?>" />
|
1171
|
<?php endif; ?>
|
1172
|
</td>
|
1173
|
</tr>
|
1174
|
</table>
|
1175
|
|
1176
|
</td></tr></table></form>
|
1177
|
<?php include("fend.inc"); ?>
|
1178
|
</body>
|
1179
|
</html>
|