Project

General

Profile

Download (37.5 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
	firewall_schedule_edit.php
4
	Copyright (C) 2004 Scott Ullrich
5
	All rights reserved.
6

    
7
	originially 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
$pgtitle = array("Firewall","Schedules","Edit");
57
require("guiconfig.inc");
58

    
59
$starttimehr = 00;
60
$starttimemin = 00;
61

    
62
$stoptimehr = 23;
63
$stoptimemin = 59;
64

    
65
$dayArray = array ('Mon','Tues','Wed','Thur','Fri','Sat','Sun');
66
$monthArray = array ('January','February','March','April','May','June','July','August','September','October','November','December');
67

    
68
if (!is_array($config['schedules']['schedule']))
69
	$config['schedules']['schedule'] = array();
70

    
71
schedule_sort();
72
$a_schedules = &$config['schedules']['schedule'];
73

    
74

    
75
$id = $_GET['id'];
76
if (isset($_POST['id']))
77
	$id = $_POST['id'];
78

    
79
if (isset($id) && $a_schedules[$id]) {
80
	$pconfig['name'] = $a_schedules[$id]['name'];
81
	$pconfig['descr'] = html_entity_decode($a_schedules[$id]['descr']);
82
	$pconfig['timerange'] = $a_schedules[$id]['timerange'];
83
	$pconfig['schedlabel'] = $a_schedules[$id]['schedlabel'];
84
	$getSchedule = true;
85
}
86

    
87
if ($_POST) {
88
	
89
	if(strtolower($_POST['name']) == "lan")
90
		$input_errors[] = "Schedule may not be named LAN.";
91
	if(strtolower($_POST['name']) == "wan")
92
		$input_errors[] = "Schedule may not be named WAN.";
93
	if(strtolower($_POST['name']) == "")
94
		$input_errors[] = "Schedule name cannot be blank.";
95

    
96
	$x = is_validaliasname($_POST['name']);
97
	if (!isset($x)) {
98
		$input_errors[] = "Reserved word used for schedule name.";
99
	} else {
100
		if (is_validaliasname($_POST['name']) == false)
101
			$input_errors[] = "The schedule name may only consist of the characters a-z, A-Z, 0-9";
102
	}
103
	
104
	/* check for name conflicts */
105
	foreach ($a_schedules as $schedule) {
106
		if (isset($id) && ($a_schedules[$id]) && ($a_schedules[$id] === $schedule))
107
			continue;
108

    
109
		if ($schedule['name'] == $_POST['name']) {
110
			$input_errors[] = "A Schedule with this name already exists.";
111
			break;
112
		}
113
	}
114
	$schedule = array();
115
	
116
	$schedule['name'] = $_POST['name'];
117
	$schedule['descr'] = htmlentities($_POST['descr'], ENT_QUOTES, 'UTF-8');	
118
	
119
	$timerangeFound = false;
120
	for ($x=0; $x<99; $x++){
121
		if($_POST['schedule' . $x]) {
122
			$timerangeFound = true;
123
			$timeparts = array();
124
			$firstprint = false;
125
			$timestr = $_POST['schedule' . $x];
126
			$timehourstr = $_POST['starttime' . $x];
127
			$timehourstr .= "-";
128
			$timehourstr .= $_POST['stoptime' . $x];
129
			$timedescrstr = htmlentities($_POST['timedescr' . $x], ENT_QUOTES, 'UTF-8'); 
130
			$dashpos = strpos($timestr, '-');
131
			if ($dashpos === false)
132
			{
133
				$timeparts['position'] = $timestr;
134
			}
135
			else
136
			{
137
				$tempindarray = array();
138
				$monthstr = "";
139
				$daystr = "";
140
				$tempindarray = explode(",", $timestr);
141
				foreach ($tempindarray as $currentselection)
142
				{
143
					if ($currentselection){
144
						if ($firstprint)
145
						{
146
							$monthstr .= ",";
147
							$daystr .= ",";						
148
						}
149
						$tempstr = "";
150
						$monthpos = strpos($currentselection, "m");
151
						$daypos = strpos($currentselection, "d");
152
						$monthstr .= substr($currentselection, $monthpos+1, $daypos-$monthpos-1);
153
						$daystr .=  substr($currentselection, $daypos+1);			
154
						$firstprint = true;
155
					}
156
				}
157
				$timeparts['month'] = $monthstr;
158
				$timeparts['day'] = $daystr;
159
			}			
160
			$timeparts['hour'] = $timehourstr;
161
			$timeparts['rangedescr'] = $timedescrstr;
162
			$schedule['timerange'][$x] = $timeparts;
163
		}
164
	}
165
	
166
	if (!$timerangeFound)
167
		$input_errors[] = "The schedule must have at least one time range configured.";
168
		
169
	if (!$input_errors) {		
170
		
171
		if (!empty($pconfig['schedlabel']))
172
			$schedule['schedlabel'] = $pconfig['schedlabel'];
173
		else
174
			$schedule['schedlabel'] = uniqid();
175

    
176
		schedule_sort();
177
		if (isset($id) && $a_schedules[$id]){
178
			$a_schedules[$id] = $schedule;
179
		}
180
		else{
181
			$a_schedules[] = $schedule;
182
		}
183
		write_config();
184
		
185
		filter_configure();
186
			
187
		header("Location: firewall_schedule.php");
188
		exit;
189
		
190
	}
191
	//we received input errors, copy data to prevent retype
192
	else
193
	{
194
		if (!$_POST['schedule0'])
195
			$getSchedule = false;
196
		else
197
			$getSchedule = true;
198
		$pconfig['name'] = $schedule['name'];
199
		$pconfig['descr'] = $schedule['descr'];
200
		$pconfig['timerange'] = $schedule['timerange'];
201
	}	
202

    
203
}
204
include("head.inc");
205

    
206
/* put your custom HTML head content here        */
207
/* using some of the $pfSenseHead function calls */
208
$jscriptstr = <<<EOD
209
<script type="text/javascript">
210

    
211
var daysSelected = "";
212
var month_array = ['January','February','March','April','May','June','July','August','September','October','November','December'];
213
var day_array = ['Mon','Tues','Wed','Thur','Fri','Sat','Sun'];
214
var schCounter = 0;
215

    
216

    
217

    
218
function repeatExistingDays(){
219
	var tempstr, tempstrdaypos, week, daypos, dayposdone = "";
220
	
221
	var dayarray = daysSelected.split(",");
222
	for (i=0; i<=dayarray.length; i++){
223
		tempstr = dayarray[i];
224
		tempstrdaypos = tempstr.search("p");
225
		week = tempstr.substring(1,tempstrdaypos);
226
		week = parseInt(week);
227
		dashpos = tempstr.search("-");		
228
		daypos = tempstr.substring(tempstrdaypos+1, dashpos);
229
		daypos = parseInt(daypos);
230
		
231
		daydone = dayposdone.search(daypos);
232
		tempstr = 'w' + week + 'p' + daypos;
233
		daycell = eval('document.getElementById(tempstr)');
234
		if (daydone == "-1"){
235
			if (daycell.style.backgroundColor == "lightcoral")
236
				daytogglerepeating(week,daypos,true);
237
			else
238
				daytogglerepeating(week,daypos,false);
239
			dayposdone += daypos + ",";
240
		}
241
	}	
242
}
243

    
244
function daytogglerepeating(week,daypos,bExists){
245
	var tempstr, daycell, dayoriginal = "";
246
	for (j=1; j<=53; j++)
247
	{						
248
		tempstr = 'w' + j + 'p' + daypos;
249
		daycell = eval('document.getElementById(tempstr)');
250
		dayoriginalpos =  daysSelected.indexOf(tempstr);
251
		
252
		//if bExists set to true, means cell is already select it
253
		//unselect it and remove original day from daysSelected string		
254
	
255
		if (daycell != null)
256
		{
257
			if (bExists){	
258
				daycell.style.backgroundColor = "WHITE";
259
			}
260
			else
261
			{
262
				daycell.style.backgroundColor = "lightcoral";		
263
			}	
264
	
265
			if (dayoriginalpos != "-1")
266
			{						
267
				dayoriginalend = daysSelected.indexOf(',', dayoriginalpos);
268
				tempstr = daysSelected.substring(dayoriginalpos, dayoriginalend+1);
269
				daysSelected = daysSelected.replace(tempstr, "");
270
				
271
			}				
272
		}			
273
	}	
274
}
275
	
276
function daytoggle(id) {
277
	var runrepeat, tempstr = "";
278
	var bFoundValid = false;
279
	
280
	iddashpos = id.search("-");
281
	var tempstrdaypos = id.search("p");
282
	var week = id.substring(1,tempstrdaypos);
283
	week = parseInt(week);
284
	
285
	if (iddashpos == "-1")
286
	{
287
		idmod = id;
288
		runrepeat = true;
289
		var daypos = id.substr(tempstrdaypos+1);	
290
	}
291
	else
292
	{		
293
		idmod = id.substring(0,iddashpos);
294
		var daypos = id.substring(tempstrdaypos+1,iddashpos);
295
	}
296
	
297
	daypos = parseInt(daypos);
298
	
299
	while (!bFoundValid){
300
		var daycell = document.getElementById(idmod);		
301
	
302
		if (daycell != null){
303
			if (daycell.style.backgroundColor == "RED"){
304
				daycell.style.backgroundColor = "WHITE";
305
				str = id + ",";
306
				daysSelected = daysSelected.replace(str, "");
307
			}
308
			else if (daycell.style.backgroundColor == "lightcoral")
309
			{
310
				daytogglerepeating(week,daypos,true);
311
			}
312
			else //color is white cell
313
			{
314
				if (!runrepeat)
315
				{
316
					daycell.style.backgroundColor = "RED";
317
				}
318
				else
319
				{
320
					daycell.style.backgroundColor = "lightcoral";
321
					daytogglerepeating(week,daypos,false);								
322
				}
323
				daysSelected += id + ",";
324
			}
325
			bFoundValid = true;
326
		}
327
		else
328
		{
329
			//we found an invalid cell when column was clicked, move up to the next week
330
			week++;
331
			tempstr = "w" + week + "p" + daypos;
332
			idmod = tempstr;			
333
		}
334
	}
335
}
336

    
337
function update_month(){
338
	var indexNum = document.forms[0].monthsel.selectedIndex;
339
	var selected = document.forms[0].monthsel.options[indexNum].text;
340

    
341
	for (i=0; i<=11; i++){
342
		option = document.forms[0].monthsel.options[i].text;
343
		document.popupMonthLayer = eval('document.getElementById (option)');
344
		
345
		if(selected == option) {
346
			document.popupMonthLayer.style.display="block";
347
		}
348
		else
349
			document.popupMonthLayer.style.display="none";
350
	}
351
}
352

    
353
function checkForRanges(){
354
	if (daysSelected != "")
355
	{
356
		alert("You have not saved the specified time range. Please click 'Add Time' button to save the time range.");
357
		return false;
358
	}
359
	else
360
	{
361
		return true;
362
	}
363
}
364

    
365
function processEntries(){
366
	var tempstr, starttimehour, starttimemin, stoptimehour, stoptimemin, errors = "";
367
	var passedValidiation = true;
368
	
369
	//get time specified
370
	starttimehour = parseInt(document.getElementById("starttimehour").value);
371
	starttimemin = parseInt(document.getElementById("starttimemin").value);
372
	stoptimehour = parseInt(document.getElementById("stoptimehour").value);
373
	stoptimemin = parseInt(document.getElementById("stoptimemin").value);
374

    
375

    
376
	//do time checks	
377
	if (starttimehour > stoptimehour)
378
	{
379
		errors = "Error: Start Hour cannot be greater than Stop Hour.";
380
		passedValidiation = false;
381
		
382
	}
383
	else if (starttimehour == stoptimehour)
384
	{
385
		if (starttimemin > stoptimemin){
386
			errors = "Error: Start Minute cannot be greater than Stop Minute.";
387
			passedValidiation = false;
388
		}
389
	}	
390
		
391
	if (passedValidiation){
392
		addTimeRange();
393
	}
394
	else {
395
		if (errors != "")
396
			alert(errors);
397
	}
398
}
399

    
400
function addTimeRange(){
401
	var tempdayarray = daysSelected.split(",");
402
	var tempstr, tempFriendlyDay, starttimehour, starttimemin, stoptimehour, nrtempFriendlyTime, rtempFriendlyTime, nrtempID, rtempID = "";
403
	var stoptimemin, timeRange, tempstrdaypos, week, daypos, day, month, dashpos, nrtempTime, rtempTime, monthstr, daystr = "";
404
	rtempFriendlyTime = "";
405
	nrtempFriendlyTime = "";
406
	nrtempID = "";
407
	rtempID = "";
408
	nrtempTime = "";
409
	rtempTime = "";
410
	tempdayarray.sort();	
411
	rtempFriendlyDay = "";
412
	monthstr = "";
413
	daystr = "";
414
	
415
	//check for existing entries
416
	var findCurrentCounter;
417
	for (u=0; u<99; u++){
418
		findCurrentCounter = document.getElementById("schedule" + u);
419
		if (!findCurrentCounter)
420
		{
421
			schCounter = u;
422
			break;
423
		}
424
	}
425
		
426
	if (daysSelected != ""){
427
		//get days selected
428
		for (i=0; i<tempdayarray.length; i++)
429
		{
430
			tempstr = tempdayarray[i];
431
			if (tempstr != "")
432
			{			
433
				tempstrdaypos = tempstr.search("p");
434
				week = tempstr.substring(1,tempstrdaypos);
435
				week = parseInt(week);
436
				dashpos = tempstr.search("-");			
437
				
438
				if (dashpos != "-1")
439
				{	
440
					var nonrepeatingfound = true;
441
					daypos = tempstr.substring(tempstrdaypos+1, dashpos);
442
					daypos = parseInt(daypos);	
443
					monthpos = tempstr.search("m");	
444
					tempstrdaypos = tempstr.search("d");
445
					month = tempstr.substring(monthpos+1, tempstrdaypos);
446
					month = parseInt(month);
447
					day = tempstr.substring(tempstrdaypos+1);
448
					day = parseInt(day);
449
					monthstr += month + ",";
450
					daystr += day + ",";
451
					nrtempID += tempstr + ",";
452
				}
453
				else
454
				{	
455
					var repeatingfound = true;
456
					daypos = tempstr.substr(tempstrdaypos+1);
457
					daypos = parseInt(daypos);	
458
					rtempFriendlyDay += daypos + ",";
459
					rtempID += daypos + ",";					
460
				}		
461
			}				
462
		}	
463
		
464
		//code below spits out friendly look format for nonrepeating schedules
465
		var foundEnd = false;
466
		var firstDayFound = false;
467
		var firstprint = false;
468
		var tempFriendlyMonthArray = monthstr.split(",");
469
		var tempFriendlyDayArray = daystr.split(",");
470
		var currentDay, firstDay, nextDay, currentMonth, nextMonth, firstDay, firstMonth = "";
471
		for (k=0; k<tempFriendlyMonthArray.length; k++){
472
			tempstr = tempFriendlyMonthArray[k];
473
			if (tempstr != ""){
474
				if (!firstDayFound)
475
				{
476
					firstDay = tempFriendlyDayArray[k];
477
					firstDay = parseInt(firstDay);
478
					firstMonth = tempFriendlyMonthArray[k];
479
					firstMonth = parseInt(firstMonth);
480
					firstDayFound = true;
481
				}
482
				currentDay = tempFriendlyDayArray[k];
483
				currentDay = parseInt(currentDay);
484
				//get next day
485
				nextDay = tempFriendlyDayArray[k+1];
486
				nextDay = parseInt(nextDay);
487
				//get next month
488
				
489
				currentDay++;						
490
				if ((currentDay != nextDay) || (tempFriendlyMonthArray[k] != tempFriendlyMonthArray[k+1])){
491
					if (firstprint)
492
						nrtempFriendlyTime += ", ";
493
					currentDay--;
494
					if (currentDay != firstDay)
495
						nrtempFriendlyTime += month_array[firstMonth-1] + " " + firstDay + "-" + currentDay;
496
					else
497
						nrtempFriendlyTime += month_array[firstMonth-1] + " " + currentDay; 
498
					firstDayFound = false;	
499
					firstprint = true;			
500
				}
501
			}			
502
		}		
503
		
504
		//code below spits out friendly look format for repeating schedules
505
		foundEnd = false;
506
		firstDayFound = false;
507
		firstprint = false;
508
		tempFriendlyDayArray = rtempFriendlyDay.split(",");
509
		tempFriendlyDayArray.sort();
510
		currentDay, firstDay, nextDay = "";
511
		for (k=0; k<tempFriendlyDayArray.length; k++){
512
			tempstr = tempFriendlyDayArray[k];
513
			if (tempstr != ""){
514
				if (!firstDayFound)
515
				{
516
					firstDay = tempFriendlyDayArray[k];
517
					firstDay = parseInt(firstDay);
518
					firstDayFound = true;
519
				}
520
				currentDay = tempFriendlyDayArray[k];
521
				currentDay = parseInt(currentDay);
522
				//get next day
523
				nextDay = tempFriendlyDayArray[k+1];
524
				nextDay = parseInt(nextDay);
525
				currentDay++;					
526
				if (currentDay != nextDay){
527
					if (firstprint)
528
						rtempFriendlyTime += ", ";
529
					currentDay--;
530
					if (currentDay != firstDay)
531
						rtempFriendlyTime += day_array[firstDay-1] + " - " + day_array[currentDay-1];
532
					else
533
						rtempFriendlyTime += day_array[firstDay-1];
534
					firstDayFound = false;	
535
					firstprint = true;			
536
				}
537
			}
538
		}			
539
		
540
		//sort the tempID
541
		var tempsortArray = rtempID.split(",");
542
		var isFirstdone = false;
543
		tempsortArray.sort();
544
		//clear tempID
545
		rtempID = "";
546
		for (t=0; t<tempsortArray.length; t++)
547
		{
548
			if (tempsortArray[t] != ""){
549
				if (!isFirstdone){
550
					rtempID += tempsortArray[t];
551
					isFirstdone = true;
552
				}
553
				else
554
					rtempID += "," + tempsortArray[t];
555
			}
556
		} 
557
		
558
		 
559
		//get time specified
560
		starttimehour =  document.getElementById("starttimehour").value
561
		starttimemin = document.getElementById("starttimemin").value;
562
		stoptimehour = document.getElementById("stoptimehour").value;
563
		stoptimemin = document.getElementById("stoptimemin").value;
564
		
565
		timeRange = "||" + starttimehour + ":";
566
		timeRange += starttimemin + "-";
567
		timeRange += stoptimehour + ":";	
568
		timeRange += stoptimemin;		
569
				
570
		//get description for time range
571
		var tempdescr = document.getElementById("timerangedescr").value		
572
		
573
		if (nonrepeatingfound){
574
			nrtempTime += nrtempID;
575
			//add time ranges
576
			nrtempTime += timeRange;			
577
			//add description
578
			nrtempTime += "||" + tempdescr;
579
			insertElements(nrtempFriendlyTime, starttimehour, starttimemin, stoptimehour, stoptimemin, tempdescr, nrtempTime, nrtempID);
580
		}
581
		
582
		if (repeatingfound){
583
			rtempTime += rtempID;
584
			//add time ranges
585
			rtempTime += timeRange;
586
			//add description
587
			rtempTime += "||" + tempdescr;
588
			insertElements(rtempFriendlyTime, starttimehour, starttimemin, stoptimehour, stoptimemin, tempdescr, rtempTime, rtempID);
589
		}
590
		
591
	}
592
	else
593
	{
594
		//no days were selected, alert user
595
		alert ("You must select at least 1 day before adding time");
596
	}
597
}
598

    
599
function insertElements(tempFriendlyTime, starttimehour, starttimemin, stoptimehour, stoptimemin, tempdescr, tempTime, tempID){
600
	
601
		//add it to the schedule list
602
		d = document;
603
		tbody = d.getElementById("scheduletable").getElementsByTagName("tbody").item(0);
604
		tr = d.createElement("tr");
605
		td = d.createElement("td");
606
		td.innerHTML= "<span class='vexpl'>" + tempFriendlyTime + "</span>";
607
		tr.appendChild(td);	
608
			
609
		td = d.createElement("td");
610
		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 + "'>";
611
		tr.appendChild(td);
612
		
613
		td = d.createElement("td");
614
		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 + "'>";
615
		tr.appendChild(td);
616
		
617
		td = d.createElement("td");
618
		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 + "'>";
619
		tr.appendChild(td);
620
		
621
		td = d.createElement("td");
622
		td.innerHTML = "<input type='image' src='/themes/" + theme + "/images/icons/icon_e.gif' onclick='editRow(\"" + tempTime + "\",this); return false;' value='Edit'>";
623
		tr.appendChild(td);
624
			
625
		td = d.createElement("td");
626
		td.innerHTML = "<input type='image' src='/themes/" + theme + "/images/icons/icon_x.gif' onclick='removeRow(this); return false;' value='Delete'>";
627
		tr.appendChild(td);
628
		
629
		td = d.createElement("td");		
630
		td.innerHTML="<input type='hidden' id='schedule" + schCounter + "' name='schedule" + schCounter + "' value='" + tempID + "'>";		
631
		tr.appendChild(td);
632
		tbody.appendChild(tr);
633
		
634
		schCounter++;
635
		
636
		//reset calendar and time and descr
637
		clearCalendar();
638
		clearTime();
639
		clearDescr();
640
}
641

    
642

    
643
function clearCalendar(){
644
	var tempstr, daycell = "";
645
	//clear days selected
646
	daysSelected = "";
647
	//loop through all 52 weeks
648
	for (j=1; j<=53; j++)
649
	{
650
		//loop through all 7 days
651
		for (k=1; k<8; k++){
652
			tempstr = 'w' + j + 'p' + k;
653
			daycell = eval('document.getElementById(tempstr)');
654
			if (daycell != null){
655
				daycell.style.backgroundColor = "WHITE";	
656
			}	
657
		}
658
	}	
659
}
660

    
661
function clearTime(){
662
	document.getElementById("starttimehour").value = $starttimehr;
663
	document.getElementById("starttimemin").value = $starttimemin;
664
	document.getElementById("stoptimehour").value = $stoptimehr;
665
	document.getElementById("stoptimemin").value = $stoptimemin;
666
}
667

    
668
function clearDescr(){
669
	document.getElementById("timerangedescr").value = "";
670
}
671

    
672
function editRow(incTime, el) {
673
	var check = checkForRanges();
674
	
675
	if (check){  
676
		
677
		//reset calendar and time
678
		clearCalendar();
679
		clearTime();
680
		
681
		var starttimehour, descr, days, tempstr, starttimemin, hours, stoptimehour, stoptimemin = ""; 
682
		
683
		tempArray = incTime.split ("||");
684
		
685
		days = tempArray[0];
686
		hours = tempArray[1];
687
		descr = tempArray[2];
688
		
689
		var tempdayArray = days.split(",");
690
		var temphourArray = hours.split("-");
691
		tempstr = temphourArray[0];
692
		var temphourArray2 = tempstr.split(":");
693
	
694
		document.getElementById("starttimehour").value = temphourArray2[0];
695
		document.getElementById("starttimemin").value = temphourArray2[1];	
696
		
697
		tempstr = temphourArray[1];
698
		temphourArray2 = tempstr.split(":");
699
		
700
		document.getElementById("stoptimehour").value = temphourArray2[0];
701
		document.getElementById("stoptimemin").value = temphourArray2[1];
702
		
703
		document.getElementById("timerangedescr").value = descr;
704
	
705
		//toggle the appropriate days
706
		for (i=0; i<tempdayArray.length; i++)
707
		{
708
			if (tempdayArray[i]){
709
				var tempweekstr = tempdayArray[i];
710
				dashpos = tempweekstr.search("-");			
711
						
712
				if (dashpos == "-1")
713
				{
714
					tempstr = "w2p" + tempdayArray[i];
715
				}
716
				else
717
				{
718
					tempstr = tempdayArray[i];
719
				}
720
				daytoggle(tempstr);
721
			}
722
		}
723
		removeRownoprompt(el);
724
	}
725
}
726

    
727
function removeRownoprompt(el) {
728
    var cel;
729
    while (el && el.nodeName.toLowerCase() != "tr")
730
	    el = el.parentNode;
731

    
732
    if (el && el.parentNode) {
733
	cel = el.getElementsByTagName("td").item(0);
734
	el.parentNode.removeChild(el);
735
    }
736
}
737

    
738

    
739
function removeRow(el) {
740
	var check = confirm ("Do you really want to delete this time range?");
741
	if (check){
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
</script>
754
EOD;
755
?>
756

    
757
<body link="#0000CC" vlink="#0000CC" alink="#0000CC" onload="<?= $jsevents["body"]["onload"] ?>">
758

    
759

    
760
<?php include("fbegin.inc");	echo $jscriptstr; ?>
761
<?php if ($input_errors) print_input_errors($input_errors); ?>
762
<div id="inputerrors"></div>
763

    
764
<form action="firewall_schedule_edit.php" method="post" name="iform" id="iform">
765
	<table width="100%" border="0" cellpadding="0" cellspacing="0">
766
		<tr>
767
			<td colspan="2" valign="top" class="listtopic">Schedule information</td>
768
		</tr>	
769
        <tr>
770
          <td>
771
			  <table width="100%" border="0" cellpadding="6" cellspacing="0">
772
               	<tr>
773
				  <td width="15%" valign="top" class="vncellreq">Schedule Name</td>
774
				  <td width="85%" class="vtable">
775
				  <?php if(is_schedule_inuse($pconfig['name']) == true): ?>
776
				  			<input name="name" type="hidden" id="name" size="40"  value="<?=htmlspecialchars($pconfig['name']);?>" />
777
						  <?php echo $pconfig['name']; ?>
778
						      <p>
779
						        <span class="vexpl">NOTE: This schedule is in use so the name may not be modified!</span>
780
						      </p>
781
				<?php else: ?>
782
				  <input name="name" type="text" id="name" size="40" maxlength="40" class="formfld unknown" value="<?=htmlspecialchars($pconfig['name']);?>"><br>
783
				      	<span class="vexpl">
784
     					   The name of the alias may only consist of the characters a-z, A-Z and 0-9
785
      					</span>
786
      			<?php endif; ?>   					
787
				  </td>
788
				</tr>
789
				<tr>
790
					<td width="15%" valign="top" class="vncell">Description</td>
791
					<td width="85%" class="vtable"><input name="descr" type="text" id="descr" size="40" maxlength="40" class="formfld unknown" value="<?=htmlspecialchars($pconfig['descr']);?>"><br>
792
 						<span class="vexpl">
793
				        	You may enter a description here for your reference (not parsed).
794
				      	</span>
795
				  
796
					</td>
797
				</tr>
798
				<tr>
799
				</tr>
800
			    <tr>
801
				  <td width="15%" valign="top" class="vncellreq">Month</td>
802
				  <td width="85%" class="vtable">
803
                    <select name="monthsel" class="formselect" id="monthsel" onchange="update_month();">
804
                    	<?php 
805
                    	$monthcounter = date("n");
806
                    	$monthlimit = $monthcounter + 12;
807
                    	$yearcounter = date("Y");
808
                    	for ($k=0; $k<12; $k++){?>	             
809
                    		<option value="<?php echo $monthcounter;?>"><?php echo date("F y", mktime(0, 0, 0, date($monthcounter), 1, date($yearcounter)));?></option>
810
                          <?php        	
811
                          if ($monthcounter == 12)
812
							{
813
								$monthcounter = 1;
814
								$yearcounter++;
815
							}
816
							else
817
							{
818
								$monthcounter++;
819
							}	
820
						} ?>      	
821
                    </select><br><br>
822
            		<?php
823
            		$firstmonth = TRUE;
824
            		$monthcounter = date("n");
825
            		$yearcounter = date("Y");
826
            		for ($k=0; $k<12; $k++){
827
						$firstdayofmonth = date("w", mktime(0, 0, 0, date($monthcounter), 1, date($yearcounter)));
828
						if ($firstdayofmonth == 0)
829
							$firstdayofmonth = 7;
830
							
831
						$daycounter = 1;
832
						//number of day in month
833
						$numberofdays = date("t", mktime(0, 0, 0, date($monthcounter), 1, date($yearcounter)));
834
						$firstdayprinted = FALSE;
835
						$lasttr = FALSE;
836
						$positioncounter = 1;//7 for Sun, 1 for Mon, 2 for Tues, etc						
837
						?>	
838
	                        <div id="<?php echo date("F y",mktime(0, 0, 0, date($monthcounter), 1, date($yearcounter)));?>" z-index:-1000; style="position:relative; display:<?php if($firstmonth)echo "block";else echo "none";?>">    	
839
		                   	<TABLE BORDER=1 CELLSPACING=1 CELLPADDING=1 id="calTable" class="tabcont">
840
								<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>
841
								</TR>							
842
								<TR>																
843
									<TD ALIGN=center class="listhdrr" style="cursor: pointer;" onClick="daytoggle('w1p1');"><u><b>Mon</b></u></TD>
844
									<TD ALIGN=center class="listhdrr" style="cursor: pointer;" onClick="daytoggle('w1p2');"><u><b>Tue</b></u></TD>
845
									<TD ALIGN=center class="listhdrr" style="cursor: pointer;" onClick="daytoggle('w1p3');"><u><b>Wed</b></u></TD>
846
									<TD ALIGN=center class="listhdrr" style="cursor: pointer;" onClick="daytoggle('w1p4');"><u><b>Thu</b></u></TD>
847
									<TD ALIGN=center class="listhdrr" style="cursor: pointer;" onClick="daytoggle('w1p5');"><u><b>Fri</b></u></TD>
848
									<TD ALIGN=center class="listhdrr" style="cursor: pointer;" onClick="daytoggle('w1p6');"><u><b>Sat</b></u></TD>
849
									<TD ALIGN=center class="listhdrr" style="cursor: pointer;" onClick="daytoggle('w1p7');"><u><b>Sun</b></u></TD>
850
								</TR>
851
								<?php			
852
								$firstmonth = FALSE;				
853
								while ($daycounter<=$numberofdays){
854
									$weekcounter =  date("W", mktime(0, 0, 0, date($monthcounter), date($daycounter), date($yearcounter)));
855
									$weekcounter = ltrim($weekcounter, "0");
856
									if ($positioncounter == 1)
857
									{
858
										echo "<tr>";
859
									}											
860
									if ($firstdayofmonth == $positioncounter){?>
861
										<TD ALIGN=center style="cursor: pointer;" class="listr" id="w<?=$weekcounter;?>p<?=$positioncounter;?>" onClick="daytoggle('w<?=$weekcounter;?>p<?=$positioncounter;?>-m<?=$monthcounter;?>d<?=$daycounter;?>');">
862
										<?php echo $daycounter;
863
										$daycounter++;
864
										$firstdayprinted = TRUE;
865
										echo "</td>";
866
									}
867
									elseif ($firstdayprinted == TRUE && $daycounter <= $numberofdays){?>
868
										<TD ALIGN=center style="cursor: pointer;" class="listr" id="w<?=$weekcounter;?>p<?=$positioncounter;?>" onClick="daytoggle('w<?=$weekcounter;?>p<?=$positioncounter;?>-m<?=$monthcounter;?>d<?=$daycounter;?>');">
869
										<?php echo $daycounter;
870
										$daycounter++;
871
										echo "</td>";
872
									}
873
									else
874
									{
875
										echo "<td align=center class=\"listr\"></td>";
876
									}
877
									
878
									if ($positioncounter ==7){
879
										$positioncounter = 1;
880
										echo "</tr>";
881
									}
882
									else{
883
										$positioncounter++;
884
									}
885
								
886
								}//end while loop?>	
887
							</TABLE>
888
							</div>
889
					<?php 
890
						
891
						if ($monthcounter == 12)
892
						{
893
							$monthcounter = 1;
894
							$yearcounter++;
895
						}
896
						else
897
						{
898
							$monthcounter++;
899
						}					
900
					} //end for loop
901
					?>
902
							<br/>
903
					Click individual date to select that date only. Click the appropriate weekday Header to select all occurences of that weekday.
904
	                 </td>
905
				</tr>
906
				<tr>
907
				  <td width="15%" valign="top" class="vncellreq">Time</td>
908
				  <td width="85%" class="vtable">
909
				  	<table cellspacing=2 class="tabcont">
910
				  		<tr>
911
				  			<td class="listhdrr" align="center">Start Time</td><td></td><td class="listhdrr" align="center">Stop Time</td>
912
				  		</tr>
913
				  		<tr>
914
				  			<td>
915
				  				<select name="starttimehour" class="formselect" id="starttimehour">
916
				  					<?php 
917
				  						for ($i=0; $i<24; $i++)
918
				  						{				  							
919
				  							echo "<option value=\"$i\">";
920
				  							echo $i;
921
				  							echo "</option>";
922
				  						}
923
				  					?>
924
				  				</select>&nbsp;Hr&nbsp;&nbsp;
925
				  				<select name="starttimemin" class="formselect" id="starttimemin">
926
				  					<option value="00">00</option>
927
				  					<option value="15">15</option>
928
				  					<option value="30">30</option>
929
				  					<option value="45">45</option>
930
				  					<option value="59">59</option>
931
				  				</select>&nbsp;Min
932
				  			</td>
933
				  			<td></td>
934
				  			<td>
935
				  				<select name="stoptimehour" class="formselect" id="stoptimehour">
936
				  				<?php 
937
				  						for ($i=0; $i<24; $i++)
938
				  						{
939
				  							if ($i==23)
940
				  								$selected = "SELECTED";
941
				  							else
942
				  								$selected = "";
943
				  								
944
				  							echo "<option value=\"$i\" $selected>";
945
				  							echo $i;
946
				  							echo "</option>";
947
				  						}
948
				  					?>
949
				  				</select>&nbsp;Hr&nbsp;&nbsp;
950
				  				<select name="stoptimemin" class="formselect" id="stoptimemin">
951
				  					<option value="00">00</option>
952
				  					<option value="15">15</option>
953
				  					<option value="30">30</option>
954
				  					<option value="45">45</option>
955
				  					<option value="59" SELECTED>59</option>
956
				  				</select>&nbsp;Min
957
				  			</td>
958
				  		</tr>
959
				  	</table><br>
960
                    Select the time range for the day(s) selected on the Month(s) above. A full day is 0:00-23:59.
961
					</td>
962
				</tr>
963
				<tr>
964
					<td width="15%" valign="top" class="vncell">Time Range Description</td>
965
					<td width="85%" class="vtable"><input name="timerangedescr" type="text" class="formfld unknown" id="timerangedescr" size="40" maxlength="40"><br>
966
 						<span class="vexpl">
967
				        	You may enter a description here for your reference (not parsed).
968
				      	</span>     
969
				      </td>					
970
				</tr>
971
				<tr>
972
				  <td width="22%" valign="top">&nbsp;</td>
973
				  <td width="78%">
974
				  	<input type="button" value="Add Time"  class="formbtn"  onclick="javascript:processEntries();">&nbsp;&nbsp;&nbsp;
975
				  	<input type="button" value="Clear Selection" class="formbtn" onclick="javascript:clearCalendar(); clearTime(); clearDescr();">
976
                    </td>
977
				</tr>
978
				<tr>
979
				  <td width="15%" valign="top" class="vtable"></td>
980
				  <td width="85%" class="vtable">
981
                    </td>
982
				</tr>
983
				<tr>
984
					<td colspan="2" valign="top" class="listtopic">Schedule repeat</td>
985
				</tr>	
986
				<tr>
987
					<td width="15%" valign="top" class="vncellreq">Configured Ranges</td>
988
					<td width="85%">
989
						<table id="scheduletable">
990
							<tbody>
991
								<tr>
992
									<TD ALIGN="center" class="listbg" width="35%">Day(s)</td>
993
									<TD ALIGN="center" class="listbg" width="12%">Start Time</td>
994
									<TD ALIGN="center" class="listbg" width="11%">Stop Time</td>
995
									<TD ALIGN="center" class="listbg" width="42%">Description</td>
996
								</tr>
997
								<?php
998
								if ($getSchedule){
999
									$counter = 0;
1000
																		
1001
									foreach($pconfig['timerange'] as $timerange) {
1002
										$tempFriendlyTime = "";
1003
										$tempID = "";
1004
										if ($timerange){
1005
											$dayFriendly = "";
1006
											$tempFriendlyTime = "";
1007
											$timedescr = $timerange['rangedescr'];			
1008
												
1009
											//get hours
1010
											$temptimerange = $timerange['hour'];
1011
											$temptimeseparator = strrpos($temptimerange, "-");
1012
											
1013
											$starttime = substr ($temptimerange, 0, $temptimeseparator); 
1014
											$stoptime = substr ($temptimerange, $temptimeseparator+1); 
1015
											$currentDay = "";
1016
											$firstDay = "";
1017
											$nextDay = "";
1018
											$foundEnd = false;
1019
											$firstDayFound = false;
1020
											$firstPrint = false;	
1021
											$firstprint2 = false;
1022
											
1023
											if ($timerange['month']){
1024
												$tempmontharray = explode(",", $timerange['month']);
1025
												$tempdayarray = explode(",",$timerange['day']);
1026
												$arraycounter = 0;
1027
												foreach ($tempmontharray as $monthtmp){
1028
													$month = $tempmontharray[$arraycounter];
1029
													$day = $tempdayarray[$arraycounter];
1030
													$daypos = date("w", mktime(0, 0, 0, date($month), date($day), date("Y")));
1031
													//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.
1032
													if ($daypos == 0){
1033
														$daypos = 7;
1034
													}									
1035
													$weeknumber = date("W", mktime(0, 0, 0, date($month), date($day), date("Y")));
1036
													$weeknumber = ltrim($weeknumber, "0");		
1037
																										
1038
													if ($firstPrint)
1039
													{
1040
														$tempID .= ",";
1041
													}
1042
													$tempID .= "w" . $weeknumber . "p" . $daypos . "-m" .  $month . "d" . $day;
1043
													$firstPrint = true;
1044
													
1045
													if (!$firstDayFound)
1046
													{
1047
														$firstDay = $day;
1048
														$firstmonth = $month;
1049
														$firstDayFound = true;
1050
													}
1051
														
1052
													$currentDay = $day;
1053
													$nextDay = $tempdayarray[$arraycounter+1];
1054
													$currentDay++;
1055
													if (($currentDay != $nextDay) || ($tempmontharray[$arraycounter] != $tempmontharray[$arraycounter+1])){
1056
														if ($firstprint2)
1057
															$tempFriendlyTime .= ", ";
1058
														$currentDay--;
1059
														if ($currentDay != $firstDay)
1060
															$tempFriendlyTime .= $monthArray[$firstmonth-1] . " " . $firstDay . " - " . $currentDay ;
1061
														else
1062
															$tempFriendlyTime .=  $monthArray[$month-1] . " " . $day;
1063
														$firstDayFound = false;	
1064
														$firstprint2 = true;
1065
													}													
1066
													$arraycounter++;			
1067
												}																						
1068
												
1069
											}
1070
											else
1071
											{
1072
												$dayFriendly = $timerange['position'];
1073
												$tempID = $dayFriendly;
1074
											}											
1075
											
1076
											$tempTime = $tempID . "||" . $starttime . "-" . $stoptime . "||" . $timedescr;
1077
									
1078
											//following code makes the days friendly appearing, IE instead of Mon, Tues, Wed it will show Mon - Wed
1079
											$foundEnd = false;
1080
											$firstDayFound = false;
1081
											$firstprint = false;
1082
											$tempFriendlyDayArray = explode(",", $dayFriendly);
1083
											$currentDay = "";
1084
											$firstDay = "";
1085
											$nextDay = "";
1086
											$i = 0;
1087
											if (!$timerange['month']){										
1088
												foreach ($tempFriendlyDayArray as $day){
1089
													if ($day != ""){
1090
														if (!$firstDayFound)
1091
														{
1092
															$firstDay = $tempFriendlyDayArray[$i];
1093
															$firstDayFound = true;
1094
														}
1095
														$currentDay =$tempFriendlyDayArray[$i];
1096
														//get next day
1097
														$nextDay = $tempFriendlyDayArray[$i+1];
1098
														$currentDay++;					
1099
														if ($currentDay != $nextDay){
1100
															if ($firstprint)
1101
																$tempFriendlyTime .= ", ";
1102
															$currentDay--;
1103
															if ($currentDay != $firstDay)
1104
																$tempFriendlyTime .= $dayArray[$firstDay-1] . " - " . $dayArray[$currentDay-1];
1105
															else
1106
																$tempFriendlyTime .= $dayArray[$firstDay-1];
1107
															$firstDayFound = false;	
1108
															$firstprint = true;			
1109
														}
1110
														$i++;
1111
													}
1112
												}		
1113
											}	
1114
												
1115
																																													
1116
									?>
1117
						          <tr>
1118
						          	<td>
1119
						          		<span class="vexpl"><?php echo $tempFriendlyTime; ?><span>
1120
						          	</td>
1121
									<td>
1122
						              <input type='text' 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; ?>'>
1123
							        </td>
1124
						            <td>
1125
						              <input type='text' 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; ?>'> 
1126
							        </td>
1127
							        <td>
1128
							        	<input type='text' 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; ?>'>
1129
							        </td>
1130
							        <td>
1131
							        	<input type='image' src='/themes/<?php echo $g['theme']; ?>/images/icons/icon_e.gif' onclick='editRow("<?php echo $tempTime; ?>",this); return false;' value='Edit'>
1132
							        </td>
1133
							        <td>
1134
							        	<input type='image' src='/themes/<?php echo $g['theme']; ?>/images/icons/icon_x.gif' onclick='removeRow(this); return false;' value='Delete'>
1135
							        </td>
1136
							        <td>
1137
							        	<input type='hidden' id='schedule<?php echo $counter; ?>' name='schedule<?php echo $counter; ?>' value='<?php echo $tempID; ?>'>
1138
							        </td>
1139
						          </tr>
1140
									<?php
1141
						        $counter++;
1142
									}//end if						
1143
						        } // end foreach	
1144
								}//end if							
1145
								?>
1146
							</tdody>	
1147
						</table>				
1148
					</td>
1149
				</tr>
1150
			 	<tr>
1151
				    <td width="15%" valign="top">&nbsp;</td>
1152
				    <td width="85%">
1153
				      <input id="submit" name="submit" type="submit" onclick="return checkForRanges();" class="formbtn" value="Save" />
1154
				      <input id="cancelbutton" name="cancelbutton" type="button" class="formbtn" value="Cancel" onclick="history.back()" />
1155
				      <?php if (isset($id) && $a_schedules[$id]): ?>
1156
				      <input name="id" type="hidden" value="<?=$id;?>" />
1157
				      <?php endif; ?>
1158
				    </td>
1159
			  	</tr>
1160
			 </table>
1161
		
1162
</td></tr></table></form>
1163
<?php include("fend.inc"); ?>
1164
</body>
1165
</html>
(59-59/215)