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 = "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
	if (!$_POST['schedule0'])
81
		$input_errors[] = "The schedule must have at least one time range configured.";
82
	
83
	
84
	/* check for name conflicts */
85
	foreach ($a_schedules as $schedule) {
86
		if (isset($id) && ($a_schedules[$id]) && ($a_schedules[$id] === $schedule))
87
			continue;
88

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

    
175
}
176
include("head.inc");
177

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

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

    
188

    
189

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

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

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

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

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

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

    
347

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

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

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

    
614

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

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

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

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

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

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

    
710

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

    
725
</script>
726
EOD;
727
?>
728

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

    
731

    
732
<?php include("fbegin.inc");	echo $jscriptstr; ?>
733

    
734
<p class="pgtitle"><?=$pgtitle?></p>
735

    
736
<?php if ($input_errors) print_input_errors($input_errors); ?>
737
<div id="inputerrors"></div>
738

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

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