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

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

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

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

    
189

    
190

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

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

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

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

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

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

    
348

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

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

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

    
615

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

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

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

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

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

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

    
711

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

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

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

    
732

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

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

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

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

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