Project

General

Profile

Download (36.7 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
$pgtitle = array("Firewall","Schedules","Edit");
34
require("guiconfig.inc");
35

    
36
$starttimehr = 00;
37
$starttimemin = 00;
38

    
39
$stoptimehr = 23;
40
$stoptimemin = 59;
41

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

    
45
if (!is_array($config['schedules']['schedule']))
46
	$config['schedules']['schedule'] = array();
47

    
48
schedule_sort();
49
$a_schedules = &$config['schedules']['schedule'];
50

    
51

    
52
$id = $_GET['id'];
53
if (isset($_POST['id']))
54
	$id = $_POST['id'];
55

    
56
if (isset($id) && $a_schedules[$id]) {
57
	$pconfig['name'] = $a_schedules[$id]['name'];
58
	$pconfig['descr'] = html_entity_decode($a_schedules[$id]['descr']);
59
	$pconfig['timerange'] = $a_schedules[$id]['timerange'];
60
	$getSchedule = true;
61
}
62

    
63
if ($_POST) {
64
	
65
	if(strtolower($_POST['name']) == "lan")
66
		$input_errors[] = "Schedule may not be named LAN.";
67
	if(strtolower($_POST['name']) == "wan")
68
		$input_errors[] = "Schedule may not be named WAN.";
69
	if(strtolower($_POST['name']) == "")
70
		$input_errors[] = "Schedule name cannot be blank.";
71

    
72
	$x = is_validaliasname($_POST['name']);
73
	if (!isset($x)) {
74
		$input_errors[] = "Reserved word used for schedule name.";
75
	} else {
76
		if (is_validaliasname($_POST['name']) == false)
77
			$input_errors[] = "The schedule name may only consist of the characters a-z, A-Z, 0-9";
78
	}
79
	
80
	/* check for name conflicts */
81
	foreach ($a_schedules as $schedule) {
82
		if (isset($id) && ($a_schedules[$id]) && ($a_schedules[$id] === $schedule))
83
			continue;
84

    
85
		if ($schedule['name'] == $_POST['name']) {
86
			$input_errors[] = "A Schedule with this name already exists.";
87
			break;
88
		}
89
	}
90
	$schedule = array();
91
	
92
	$schedule['name'] = $_POST['name'];
93
	$schedule['descr'] = htmlentities($_POST['descr'], ENT_QUOTES, 'UTF-8');	
94
	
95
	$timerangeFound = false;
96
	for ($x=0; $x<99; $x++){
97
		if($_POST['schedule' . $x]) {
98
			$timerangeFound = true;
99
			$timeparts = array();
100
			$firstprint = false;
101
			$timestr = $_POST['schedule' . $x];
102
			$timehourstr = $_POST['starttime' . $x];
103
			$timehourstr .= "-";
104
			$timehourstr .= $_POST['stoptime' . $x];
105
			$timedescrstr = htmlentities($_POST['timedescr' . $x], ENT_QUOTES, 'UTF-8'); 
106
			$dashpos = strpos($timestr, '-');
107
			if ($dashpos === false)
108
			{
109
				$timeparts['position'] = $timestr;
110
			}
111
			else
112
			{
113
				$tempindarray = array();
114
				$monthstr = "";
115
				$daystr = "";
116
				$tempindarray = explode(",", $timestr);
117
				foreach ($tempindarray as $currentselection)
118
				{
119
					if ($currentselection){
120
						if ($firstprint)
121
						{
122
							$monthstr .= ",";
123
							$daystr .= ",";						
124
						}
125
						$tempstr = "";
126
						$monthpos = strpos($currentselection, "m");
127
						$daypos = strpos($currentselection, "d");
128
						$monthstr .= substr($currentselection, $monthpos+1, $daypos-$monthpos-1);
129
						$daystr .=  substr($currentselection, $daypos+1);			
130
						$firstprint = true;
131
					}
132
				}
133
				$timeparts['month'] = $monthstr;
134
				$timeparts['day'] = $daystr;
135
			}			
136
			$timeparts['hour'] = $timehourstr;
137
			$timeparts['rangedescr'] = $timedescrstr;
138
			$schedule['timerange'][$x] = $timeparts;
139
		}
140
	}
141
	
142
	if (!$timerangeFound)
143
		$input_errors[] = "The schedule must have at least one time range configured.";
144
		
145
	if (!$input_errors) {		
146
		
147
		if (isset($id) && $a_schedules[$id]){
148
			$a_schedules[$id] = $schedule;
149
		}
150
		else{
151
			$a_schedules[] = $schedule;
152
		}
153
		write_config();
154
		
155
		filter_configure();
156
			
157
		header("Location: firewall_schedule.php");
158
		exit;
159
		
160
	}
161
	//we received input errors, copy data to prevent retype
162
	else
163
	{
164
		if (!$_POST['schedule0'])
165
			$getSchedule = false;
166
		else
167
			$getSchedule = true;
168
		$pconfig['name'] = $schedule['name'];
169
		$pconfig['descr'] = $schedule['descr'];
170
		$pconfig['timerange'] = $schedule['timerange'];
171
	}	
172

    
173
}
174
include("head.inc");
175

    
176
/* put your custom HTML head content here        */
177
/* using some of the $pfSenseHead function calls */
178
$jscriptstr = <<<EOD
179
<script type="text/javascript">
180

    
181
var daysSelected = "";
182
var month_array = ['January','February','March','April','May','June','July','August','September','October','November','December'];
183
var day_array = ['Mon','Tues','Wed','Thur','Fri','Sat','Sun'];
184
var schCounter = 0;
185

    
186

    
187

    
188
function repeatExistingDays(){
189
	var tempstr, tempstrdaypos, week, daypos, dayposdone = "";
190
	
191
	var dayarray = daysSelected.split(",");
192
	for (i=0; i<=dayarray.length; i++){
193
		tempstr = dayarray[i];
194
		tempstrdaypos = tempstr.search("p");
195
		week = tempstr.substring(1,tempstrdaypos);
196
		week = parseInt(week);
197
		dashpos = tempstr.search("-");		
198
		daypos = tempstr.substring(tempstrdaypos+1, dashpos);
199
		daypos = parseInt(daypos);
200
		
201
		daydone = dayposdone.search(daypos);
202
		tempstr = 'w' + week + 'p' + daypos;
203
		daycell = eval('document.getElementById(tempstr)');
204
		if (daydone == "-1"){
205
			if (daycell.style.backgroundColor == "lightcoral")
206
				daytogglerepeating(week,daypos,true);
207
			else
208
				daytogglerepeating(week,daypos,false);
209
			dayposdone += daypos + ",";
210
		}
211
	}	
212
}
213

    
214
function daytogglerepeating(week,daypos,bExists){
215
	var tempstr, daycell, dayoriginal = "";
216
	for (j=1; j<=53; j++)
217
	{						
218
		tempstr = 'w' + j + 'p' + daypos;
219
		daycell = eval('document.getElementById(tempstr)');
220
		dayoriginalpos =  daysSelected.indexOf(tempstr);
221
		
222
		//if bExists set to true, means cell is already select it
223
		//unselect it and remove original day from daysSelected string		
224
	
225
		if (daycell != null)
226
		{
227
			if (bExists){	
228
				daycell.style.backgroundColor = "WHITE";
229
			}
230
			else
231
			{
232
				daycell.style.backgroundColor = "lightcoral";		
233
			}	
234
	
235
			if (dayoriginalpos != "-1")
236
			{						
237
				dayoriginalend = daysSelected.indexOf(',', dayoriginalpos);
238
				tempstr = daysSelected.substring(dayoriginalpos, dayoriginalend+1);
239
				daysSelected = daysSelected.replace(tempstr, "");
240
				
241
			}				
242
		}			
243
	}	
244
}
245
	
246
function daytoggle(id) {
247
	var runrepeat, tempstr = "";
248
	var bFoundValid = false;
249
	
250
	iddashpos = id.search("-");
251
	var tempstrdaypos = id.search("p");
252
	var week = id.substring(1,tempstrdaypos);
253
	week = parseInt(week);
254
	
255
	if (iddashpos == "-1")
256
	{
257
		idmod = id;
258
		runrepeat = true;
259
		var daypos = id.substr(tempstrdaypos+1);	
260
	}
261
	else
262
	{		
263
		idmod = id.substring(0,iddashpos);
264
		var daypos = id.substring(tempstrdaypos+1,iddashpos);
265
	}
266
	
267
	daypos = parseInt(daypos);
268
	
269
	while (!bFoundValid){
270
		var daycell = document.getElementById(idmod);		
271
	
272
		if (daycell != null){
273
			if (daycell.style.backgroundColor == "RED"){
274
				daycell.style.backgroundColor = "WHITE";
275
				str = id + ",";
276
				daysSelected = daysSelected.replace(str, "");
277
			}
278
			else if (daycell.style.backgroundColor == "lightcoral")
279
			{
280
				daytogglerepeating(week,daypos,true);
281
			}
282
			else //color is white cell
283
			{
284
				if (!runrepeat)
285
				{
286
					daycell.style.backgroundColor = "RED";
287
				}
288
				else
289
				{
290
					daycell.style.backgroundColor = "lightcoral";
291
					daytogglerepeating(week,daypos,false);								
292
				}
293
				daysSelected += id + ",";
294
			}
295
			bFoundValid = true;
296
		}
297
		else
298
		{
299
			//we found an invalid cell when column was clicked, move up to the next week
300
			week++;
301
			tempstr = "w" + week + "p" + daypos;
302
			idmod = tempstr;			
303
		}
304
	}
305
}
306

    
307
function update_month(){
308
	var indexNum = document.forms[0].monthsel.selectedIndex;
309
	var selected = document.forms[0].monthsel.options[indexNum].text;
310

    
311
	for (i=0; i<=11; i++){
312
		option = document.forms[0].monthsel.options[i].text;
313
		document.popupMonthLayer = eval('document.getElementById (option)');
314
		
315
		if(selected == option) {
316
			document.popupMonthLayer.style.display="block";
317
		}
318
		else
319
			document.popupMonthLayer.style.display="none";
320
	}
321
}
322

    
323
function checkForRanges(){
324
	if (daysSelected != "")
325
	{
326
		alert("You have not saved the specified time range. Please click 'Add Time' button to save the time range.");
327
		return false;
328
	}
329
	else
330
	{
331
		return true;
332
	}
333
}
334

    
335
function processEntries(){
336
	var tempstr, starttimehour, starttimemin, stoptimehour, stoptimemin, errors = "";
337
	var passedValidiation = true;
338
	
339
	//get time specified
340
	starttimehour = parseInt(document.getElementById("starttimehour").value);
341
	starttimemin = parseInt(document.getElementById("starttimemin").value);
342
	stoptimehour = parseInt(document.getElementById("stoptimehour").value);
343
	stoptimemin = parseInt(document.getElementById("stoptimemin").value);
344

    
345

    
346
	//do time checks	
347
	if (starttimehour > stoptimehour)
348
	{
349
		errors = "Error: Start Hour cannot be greater than Stop Hour.";
350
		passedValidiation = false;
351
		
352
	}
353
	else if (starttimehour == stoptimehour)
354
	{
355
		if (starttimemin > stoptimemin){
356
			errors = "Error: Start Minute cannot be greater than Stop Minute.";
357
			passedValidiation = false;
358
		}
359
	}	
360
		
361
	if (passedValidiation){
362
		addTimeRange();
363
	}
364
	else {
365
		if (errors != "")
366
			alert(errors);
367
	}
368
}
369

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

    
569
function insertElements(tempFriendlyTime, starttimehour, starttimemin, stoptimehour, stoptimemin, tempdescr, tempTime, tempID){
570
	
571
		//add it to the schedule list
572
		d = document;
573
		tbody = d.getElementById("scheduletable").getElementsByTagName("tbody").item(0);
574
		tr = d.createElement("tr");
575
		td = d.createElement("td");
576
		td.innerHTML= "<span class='vexpl'>" + tempFriendlyTime + "</span>";
577
		tr.appendChild(td);	
578
			
579
		td = d.createElement("td");
580
		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 + "'>";
581
		tr.appendChild(td);
582
		
583
		td = d.createElement("td");
584
		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 + "'>";
585
		tr.appendChild(td);
586
		
587
		td = d.createElement("td");
588
		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 + "'>";
589
		tr.appendChild(td);
590
		
591
		td = d.createElement("td");
592
		td.innerHTML = "<input type='image' src='/themes/" + theme + "/images/icons/icon_e.gif' onclick='editRow(\"" + tempTime + "\",this); return false;' value='Edit'>";
593
		tr.appendChild(td);
594
			
595
		td = d.createElement("td");
596
		td.innerHTML = "<input type='image' src='/themes/" + theme + "/images/icons/icon_x.gif' onclick='removeRow(this); return false;' value='Delete'>";
597
		tr.appendChild(td);
598
		
599
		td = d.createElement("td");		
600
		td.innerHTML="<input type='hidden' id='schedule" + schCounter + "' name='schedule" + schCounter + "' value='" + tempID + "'>";		
601
		tr.appendChild(td);
602
		tbody.appendChild(tr);
603
		
604
		schCounter++;
605
		
606
		//reset calendar and time and descr
607
		clearCalendar();
608
		clearTime();
609
		clearDescr();
610
}
611

    
612

    
613
function clearCalendar(){
614
	var tempstr, daycell = "";
615
	//clear days selected
616
	daysSelected = "";
617
	//loop through all 52 weeks
618
	for (j=1; j<=53; j++)
619
	{
620
		//loop through all 7 days
621
		for (k=1; k<8; k++){
622
			tempstr = 'w' + j + 'p' + k;
623
			daycell = eval('document.getElementById(tempstr)');
624
			if (daycell != null){
625
				daycell.style.backgroundColor = "WHITE";	
626
			}	
627
		}
628
	}	
629
}
630

    
631
function clearTime(){
632
	document.getElementById("starttimehour").value = $starttimehr;
633
	document.getElementById("starttimemin").value = $starttimemin;
634
	document.getElementById("stoptimehour").value = $stoptimehr;
635
	document.getElementById("stoptimemin").value = $stoptimemin;
636
}
637

    
638
function clearDescr(){
639
	document.getElementById("timerangedescr").value = "";
640
}
641

    
642
function editRow(incTime, el) {
643
	var check = checkForRanges();
644
	
645
	if (check){  
646
		
647
		//reset calendar and time
648
		clearCalendar();
649
		clearTime();
650
		
651
		var starttimehour, descr, days, tempstr, starttimemin, hours, stoptimehour, stoptimemin = ""; 
652
		
653
		tempArray = incTime.split ("||");
654
		
655
		days = tempArray[0];
656
		hours = tempArray[1];
657
		descr = tempArray[2];
658
		
659
		var tempdayArray = days.split(",");
660
		var temphourArray = hours.split("-");
661
		tempstr = temphourArray[0];
662
		var temphourArray2 = tempstr.split(":");
663
	
664
		document.getElementById("starttimehour").value = temphourArray2[0];
665
		document.getElementById("starttimemin").value = temphourArray2[1];	
666
		
667
		tempstr = temphourArray[1];
668
		temphourArray2 = tempstr.split(":");
669
		
670
		document.getElementById("stoptimehour").value = temphourArray2[0];
671
		document.getElementById("stoptimemin").value = temphourArray2[1];
672
		
673
		document.getElementById("timerangedescr").value = descr;
674
	
675
		//toggle the appropriate days
676
		for (i=0; i<tempdayArray.length; i++)
677
		{
678
			if (tempdayArray[i]){
679
				var tempweekstr = tempdayArray[i];
680
				dashpos = tempweekstr.search("-");			
681
						
682
				if (dashpos == "-1")
683
				{
684
					tempstr = "w2p" + tempdayArray[i];
685
				}
686
				else
687
				{
688
					tempstr = tempdayArray[i];
689
				}
690
				daytoggle(tempstr);
691
			}
692
		}
693
		removeRownoprompt(el);
694
	}
695
}
696

    
697
function removeRownoprompt(el) {
698
    var cel;
699
    while (el && el.nodeName.toLowerCase() != "tr")
700
	    el = el.parentNode;
701

    
702
    if (el && el.parentNode) {
703
	cel = el.getElementsByTagName("td").item(0);
704
	el.parentNode.removeChild(el);
705
    }
706
}
707

    
708

    
709
function removeRow(el) {
710
	var check = confirm ("Do you really want to delete this time range?");
711
	if (check){
712
	    var cel;
713
	    while (el && el.nodeName.toLowerCase() != "tr")
714
		    el = el.parentNode;
715
	
716
	    if (el && el.parentNode) {
717
		cel = el.getElementsByTagName("td").item(0);
718
		el.parentNode.removeChild(el);
719
	    }
720
	}
721
}
722

    
723
</script>
724
EOD;
725
?>
726

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

    
729

    
730
<?php include("fbegin.inc");	echo $jscriptstr; ?>
731
<?php if ($input_errors) print_input_errors($input_errors); ?>
732
<div id="inputerrors"></div>
733

    
734
<form action="firewall_schedule_edit.php" method="post" name="iform" id="iform">
735
	<table width="100%" border="0" cellpadding="0" cellspacing="0">
736
        <tr>
737
          <td>
738
			  <table width="100%" border="0" cellpadding="6" cellspacing="0">
739
               	<tr>
740
				  <td width="15%" valign="top" class="vncellreq">Schedule Name</td>
741
				  <td width="85%" class="vtable">
742
				  <?php if(is_schedule_inuse($pconfig['name']) == true): ?>
743
				  			<input name="name" type="hidden" id="name" size="40"  value="<?=htmlspecialchars($pconfig['name']);?>" />
744
						  <?php echo $pconfig['name']; ?>
745
						      <p>
746
						        <span class="vexpl">NOTE: This schedule is in use so the name may not be modified!</span>
747
						      </p>
748
				<?php else: ?>
749
				  <input name="name" type="text" id="name" size="40" maxlength="40" class="formfld unknown" value="<?=htmlspecialchars($pconfig['name']);?>"><br>
750
				      	<span class="vexpl">
751
     					   The name of the alias may only consist of the characters a-z, A-Z and 0-9
752
      					</span>
753
      			<?php endif; ?>   					
754
				  </td>
755
				</tr>
756
				<tr>
757
					<td width="15%" valign="top" class="vncell">Description</td>
758
					<td width="85%" class="vtable"><input name="descr" type="text" id="descr" size="40" maxlength="40" class="formfld unknown" value="<?=htmlspecialchars($pconfig['descr']);?>"><br>
759
 						<span class="vexpl">
760
				        	You may enter a description here for your reference (not parsed).
761
				      	</span>
762
				  
763
					</td>
764
				</tr>
765
				<tr>
766
				</tr>
767
			    <tr>
768
				  <td width="15%" valign="top" class="vncellreq">Month</td>
769
				  <td width="85%" class="vtable">
770
                    <select name="monthsel" class="formselect" id="monthsel" onchange="update_month();">
771
                    	<?php 
772
                    	$monthcounter = date("n");
773
                    	$monthlimit = $monthcounter + 12;
774
                    	$yearcounter = date("Y");
775
                    	for ($k=0; $k<12; $k++){?>	             
776
                    		<option value="<?php echo $monthcounter;?>"><?php echo date("F y", mktime(0, 0, 0, date($monthcounter), 1, date($yearcounter)));?></option>
777
                          <?php        	
778
                          if ($monthcounter == 12)
779
							{
780
								$monthcounter = 1;
781
								$yearcounter++;
782
							}
783
							else
784
							{
785
								$monthcounter++;
786
							}	
787
						} ?>      	
788
                    </select><br><br>
789
            		<?php
790
            		$firstmonth = TRUE;
791
            		$monthcounter = date("n");
792
            		$yearcounter = date("Y");
793
            		for ($k=0; $k<12; $k++){
794
						$firstdayofmonth = date("w", mktime(0, 0, 0, date($monthcounter), 1, date($yearcounter)));
795
						if ($firstdayofmonth == 0)
796
							$firstdayofmonth = 7;
797
							
798
						$daycounter = 1;
799
						//number of day in month
800
						$numberofdays = date("t", mktime(0, 0, 0, date($monthcounter), 1, date($yearcounter)));
801
						$firstdayprinted = FALSE;
802
						$lasttr = FALSE;
803
						$positioncounter = 1;//7 for Sun, 1 for Mon, 2 for Tues, etc						
804
						?>	
805
	                        <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";?>">    	
806
		                   	<TABLE BORDER=1 CELLSPACING=1 CELLPADDING=1 id="calTable" class="tabcont">
807
								<TR><TD COLSPAN="7" ALIGN=center class="listbg"><B><font color="white"><?php echo date("F Y", mktime(0, 0, 0, date($monthcounter), 1, date($yearcounter)));?></B></TD>
808
								</TR>							
809
								<TR>																
810
									<TD ALIGN=center class="listhdrr" style="cursor: pointer;" onClick="daytoggle('w1p1');"><u><b>Mon</b></u></TD>
811
									<TD ALIGN=center class="listhdrr" style="cursor: pointer;" onClick="daytoggle('w1p2');"><u><b>Tue</b></u></TD>
812
									<TD ALIGN=center class="listhdrr" style="cursor: pointer;" onClick="daytoggle('w1p3');"><u><b>Wed</b></u></TD>
813
									<TD ALIGN=center class="listhdrr" style="cursor: pointer;" onClick="daytoggle('w1p4');"><u><b>Thu</b></u></TD>
814
									<TD ALIGN=center class="listhdrr" style="cursor: pointer;" onClick="daytoggle('w1p5');"><u><b>Fri</b></u></TD>
815
									<TD ALIGN=center class="listhdrr" style="cursor: pointer;" onClick="daytoggle('w1p6');"><u><b>Sat</b></u></TD>
816
									<TD ALIGN=center class="listhdrr" style="cursor: pointer;" onClick="daytoggle('w1p7');"><u><b>Sun</b></u></TD>
817
								</TR>
818
								<?php			
819
								$firstmonth = FALSE;				
820
								while ($daycounter<=$numberofdays){
821
									$weekcounter =  date("W", mktime(0, 0, 0, date($monthcounter), date($daycounter), date($yearcounter)));
822
									$weekcounter = ltrim($weekcounter, "0");
823
									if ($positioncounter == 1)
824
									{
825
										echo "<tr>";
826
									}											
827
									if ($firstdayofmonth == $positioncounter){?>
828
										<TD ALIGN=center style="cursor: pointer;" class="listr" id="w<?=$weekcounter;?>p<?=$positioncounter;?>" onClick="daytoggle('w<?=$weekcounter;?>p<?=$positioncounter;?>-m<?=$monthcounter;?>d<?=$daycounter;?>');">
829
										<?php echo $daycounter;
830
										$daycounter++;
831
										$firstdayprinted = TRUE;
832
										echo "</td>";
833
									}
834
									elseif ($firstdayprinted == TRUE && $daycounter <= $numberofdays){?>
835
										<TD ALIGN=center style="cursor: pointer;" class="listr" id="w<?=$weekcounter;?>p<?=$positioncounter;?>" onClick="daytoggle('w<?=$weekcounter;?>p<?=$positioncounter;?>-m<?=$monthcounter;?>d<?=$daycounter;?>');">
836
										<?php echo $daycounter;
837
										$daycounter++;
838
										echo "</td>";
839
									}
840
									else
841
									{
842
										echo "<td align=center class=\"listr\"></td>";
843
									}
844
									
845
									if ($positioncounter ==7){
846
										$positioncounter = 1;
847
										echo "</tr>";
848
									}
849
									else{
850
										$positioncounter++;
851
									}
852
								
853
								}//end while loop?>	
854
							</TABLE>
855
							</div>
856
					<?php 
857
						
858
						if ($monthcounter == 12)
859
						{
860
							$monthcounter = 1;
861
							$yearcounter++;
862
						}
863
						else
864
						{
865
							$monthcounter++;
866
						}					
867
					} //end for loop
868
					?>
869
							<br/>
870
					Click individual date to select that date only. Click the appropriate weekday Header to select all occurences of that weekday.
871
	                 </td>
872
				</tr>
873
				<tr>
874
				  <td width="15%" valign="top" class="vncellreq">Time</td>
875
				  <td width="85%" class="vtable">
876
				  	<table cellspacing=2 class="tabcont">
877
				  		<tr>
878
				  			<td class="listhdrr" align="center">Start Time</td><td></td><td class="listhdrr" align="center">Stop Time</td>
879
				  		</tr>
880
				  		<tr>
881
				  			<td>
882
				  				<select name="starttimehour" class="formselect" id="starttimehour">
883
				  					<?php 
884
				  						for ($i=0; $i<24; $i++)
885
				  						{				  							
886
				  							echo "<option value=\"$i\">";
887
				  							echo $i;
888
				  							echo "</option>";
889
				  						}
890
				  					?>
891
				  				</select>&nbsp;Hr&nbsp;&nbsp;
892
				  				<select name="starttimemin" class="formselect" id="starttimemin">
893
				  					<option value="00">00</option>
894
				  					<option value="15">15</option>
895
				  					<option value="30">30</option>
896
				  					<option value="45">45</option>
897
				  					<option value="59">59</option>
898
				  				</select>&nbsp;Min
899
				  			</td>
900
				  			<td></td>
901
				  			<td>
902
				  				<select name="stoptimehour" class="formselect" id="stoptimehour">
903
				  				<?php 
904
				  						for ($i=0; $i<24; $i++)
905
				  						{
906
				  							if ($i==23)
907
				  								$selected = "SELECTED";
908
				  							else
909
				  								$selected = "";
910
				  								
911
				  							echo "<option value=\"$i\" $selected>";
912
				  							echo $i;
913
				  							echo "</option>";
914
				  						}
915
				  					?>
916
				  				</select>&nbsp;Hr&nbsp;&nbsp;
917
				  				<select name="stoptimemin" class="formselect" id="stoptimemin">
918
				  					<option value="00">00</option>
919
				  					<option value="15">15</option>
920
				  					<option value="30">30</option>
921
				  					<option value="45">45</option>
922
				  					<option value="59" SELECTED>59</option>
923
				  				</select>&nbsp;Min
924
				  			</td>
925
				  		</tr>
926
				  	</table><br>
927
                    Select the time range for the day(s) selected on the Month(s) above. A full day is 0:00-23:59.
928
					</td>
929
				</tr>
930
				<tr>
931
					<td width="15%" valign="top" class="vncell">Time Range Description</td>
932
					<td width="85%" class="vtable"><input name="timerangedescr" type="text" class="formfld unknown" id="timerangedescr" size="40" maxlength="40"><br>
933
 						<span class="vexpl">
934
				        	You may enter a description here for your reference (not parsed).
935
				      	</span>     
936
				      </td>					
937
				</tr>
938
				<tr>
939
				  <td width="22%" valign="top">&nbsp;</td>
940
				  <td width="78%">
941
				  	<input type="button" value="Add Time"  class="formbtn"  onclick="javascript:processEntries();">&nbsp;&nbsp;&nbsp;
942
				  	<input type="button" value="Clear Selection" class="formbtn" onclick="javascript:clearCalendar(); clearTime(); clearDescr();">
943
                    </td>
944
				</tr>
945
				<tr>
946
				  <td width="15%" valign="top" class="vtable"></td>
947
				  <td width="85%" class="vtable">
948
                    </td>
949
				</tr>
950

    
951
				<tr>
952
					<td width="15%" valign="top" class="vncellreq">Configured Ranges</td>
953
					<td width="85%">
954
						<table id="scheduletable">
955
							<tbody>
956
								<tr>
957
									<TD  ALIGN=center class="listbg" width="35%"><font color="white">Day(s)</td>
958
									<TD  ALIGN=center class="listbg" width="12%"><font color="white">Start Time</td>
959
									<TD  ALIGN=center class="listbg" width="11%"><font color="white">Stop Time</td>
960
									<TD  ALIGN=center class="listbg" width="42%"><font color="white">Description</td>
961
								</tr>
962
								<?php
963
								if ($getSchedule){
964
									$counter = 0;
965
																		
966
									foreach($pconfig['timerange'] as $timerange) {
967
										$tempFriendlyTime = "";
968
										$tempID = "";
969
										if ($timerange){
970
											$dayFriendly = "";
971
											$tempFriendlyTime = "";
972
											$timedescr = $timerange['rangedescr'];			
973
												
974
											//get hours
975
											$temptimerange = $timerange['hour'];
976
											$temptimeseparator = strrpos($temptimerange, "-");
977
											
978
											$starttime = substr ($temptimerange, 0, $temptimeseparator); 
979
											$stoptime = substr ($temptimerange, $temptimeseparator+1); 
980
											$currentDay = "";
981
											$firstDay = "";
982
											$nextDay = "";
983
											$foundEnd = false;
984
											$firstDayFound = false;
985
											$firstPrint = false;	
986
											$firstprint2 = false;
987
											
988
											if ($timerange['month']){
989
												$tempmontharray = explode(",", $timerange['month']);
990
												$tempdayarray = explode(",",$timerange['day']);
991
												$arraycounter = 0;
992
												foreach ($tempmontharray as $monthtmp){
993
													$month = $tempmontharray[$arraycounter];
994
													$day = $tempdayarray[$arraycounter];
995
													$daypos = date("w", mktime(0, 0, 0, date($month), date($day), date("Y")));
996
													//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.
997
													if ($daypos == 0){
998
														$daypos = 7;
999
													}									
1000
													$weeknumber = date("W", mktime(0, 0, 0, date($month), date($day), date("Y")));
1001
													$weeknumber = ltrim($weeknumber, "0");		
1002
																										
1003
													if ($firstPrint)
1004
													{
1005
														$tempID .= ",";
1006
													}
1007
													$tempID .= "w" . $weeknumber . "p" . $daypos . "-m" .  $month . "d" . $day;
1008
													$firstPrint = true;
1009
													
1010
													if (!$firstDayFound)
1011
													{
1012
														$firstDay = $day;
1013
														$firstmonth = $month;
1014
														$firstDayFound = true;
1015
													}
1016
														
1017
													$currentDay = $day;
1018
													$nextDay = $tempdayarray[$arraycounter+1];
1019
													$currentDay++;
1020
													if (($currentDay != $nextDay) || ($tempmontharray[$arraycounter] != $tempmontharray[$arraycounter+1])){
1021
														if ($firstprint2)
1022
															$tempFriendlyTime .= ", ";
1023
														$currentDay--;
1024
														if ($currentDay != $firstDay)
1025
															$tempFriendlyTime .= $monthArray[$firstmonth-1] . " " . $firstDay . " - " . $currentDay ;
1026
														else
1027
															$tempFriendlyTime .=  $monthArray[$month-1] . " " . $day;
1028
														$firstDayFound = false;	
1029
														$firstprint2 = true;
1030
													}													
1031
													$arraycounter++;			
1032
												}																						
1033
												
1034
											}
1035
											else
1036
											{
1037
												$dayFriendly = $timerange['position'];
1038
												$tempID = $dayFriendly;
1039
											}											
1040
											
1041
											$tempTime = $tempID . "||" . $starttime . "-" . $stoptime . "||" . $timedescr;
1042
									
1043
											//following code makes the days friendly appearing, IE instead of Mon, Tues, Wed it will show Mon - Wed
1044
											$foundEnd = false;
1045
											$firstDayFound = false;
1046
											$firstprint = false;
1047
											$tempFriendlyDayArray = explode(",", $dayFriendly);
1048
											$currentDay = "";
1049
											$firstDay = "";
1050
											$nextDay = "";
1051
											$i = 0;
1052
											if (!$timerange['month']){										
1053
												foreach ($tempFriendlyDayArray as $day){
1054
													if ($day != ""){
1055
														if (!$firstDayFound)
1056
														{
1057
															$firstDay = $tempFriendlyDayArray[$i];
1058
															$firstDayFound = true;
1059
														}
1060
														$currentDay =$tempFriendlyDayArray[$i];
1061
														//get next day
1062
														$nextDay = $tempFriendlyDayArray[$i+1];
1063
														$currentDay++;					
1064
														if ($currentDay != $nextDay){
1065
															if ($firstprint)
1066
																$tempFriendlyTime .= ", ";
1067
															$currentDay--;
1068
															if ($currentDay != $firstDay)
1069
																$tempFriendlyTime .= $dayArray[$firstDay-1] . " - " . $dayArray[$currentDay-1];
1070
															else
1071
																$tempFriendlyTime .= $dayArray[$firstDay-1];
1072
															$firstDayFound = false;	
1073
															$firstprint = true;			
1074
														}
1075
														$i++;
1076
													}
1077
												}		
1078
											}	
1079
												
1080
																																													
1081
									?>
1082
						          <tr>
1083
						          	<td>
1084
						          		<span class="vexpl"><?php echo $tempFriendlyTime; ?><span>
1085
						          	</td>
1086
									<td>
1087
						              <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; ?>'>
1088
							        </td>
1089
						            <td>
1090
						              <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; ?>'> 
1091
							        </td>
1092
							        <td>
1093
							        	<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; ?>'>
1094
							        </td>
1095
							        <td>
1096
							        	<input type='image' src='/themes/<?php echo $g['theme']; ?>/images/icons/icon_e.gif' onclick='editRow("<?php echo $tempTime; ?>",this); return false;' value='Edit'>
1097
							        </td>
1098
							        <td>
1099
							        	<input type='image' src='/themes/<?php echo $g['theme']; ?>/images/icons/icon_x.gif' onclick='removeRow(this); return false;' value='Delete'>
1100
							        </td>
1101
							        <td>
1102
							        	<input type='hidden' id='schedule<?php echo $counter; ?>' name='schedule<?php echo $counter; ?>' value='<?php echo $tempID; ?>'>
1103
							        </td>
1104
						          </tr>
1105
									<?php
1106
						        $counter++;
1107
									}//end if						
1108
						        } // end foreach	
1109
								}//end if							
1110
								?>
1111
							</tdody>	
1112
						</table>				
1113
					</td>
1114
				</tr>
1115
			 	<tr>
1116
				    <td width="15%" valign="top">&nbsp;</td>
1117
				    <td width="85%">
1118
				      <input id="submit" name="submit" type="submit" onclick="return checkForRanges();" class="formbtn" value="Save" />
1119
				      <input id="cancelbutton" name="cancelbutton" type="button" class="formbtn" value="Cancel" onclick="history.back()" />
1120
				      <?php if (isset($id) && $a_schedules[$id]): ?>
1121
				      <input name="id" type="hidden" value="<?=$id;?>" />
1122
				      <?php endif; ?>
1123
				    </td>
1124
			  	</tr>
1125
			 </table>
1126
		
1127
</td></tr></table></form>
1128
<?php include("fend.inc"); ?>
1129
</body>
1130
</html>
(54-54/186)