Project

General

Profile

Download (36.9 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
##|+PRIV
34
##|*IDENT=page-firewall-schedules-edit
35
##|*NAME=Firewall: Schedules: Edit page
36
##|*DESCR=Allow access to the 'Firewall: Schedules: Edit' page.
37
##|*MATCH=firewall_schedule_edit.php*
38
##|-PRIV
39

    
40

    
41
$pgtitle = array("Firewall","Schedules","Edit");
42
require("guiconfig.inc");
43

    
44
$starttimehr = 00;
45
$starttimemin = 00;
46

    
47
$stoptimehr = 23;
48
$stoptimemin = 59;
49

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

    
53
if (!is_array($config['schedules']['schedule']))
54
	$config['schedules']['schedule'] = array();
55

    
56
schedule_sort();
57
$a_schedules = &$config['schedules']['schedule'];
58

    
59

    
60
$id = $_GET['id'];
61
if (isset($_POST['id']))
62
	$id = $_POST['id'];
63

    
64
if (isset($id) && $a_schedules[$id]) {
65
	$pconfig['name'] = $a_schedules[$id]['name'];
66
	$pconfig['descr'] = html_entity_decode($a_schedules[$id]['descr']);
67
	$pconfig['timerange'] = $a_schedules[$id]['timerange'];
68
	$getSchedule = true;
69
}
70

    
71
if ($_POST) {
72
	
73
	if(strtolower($_POST['name']) == "lan")
74
		$input_errors[] = "Schedule may not be named LAN.";
75
	if(strtolower($_POST['name']) == "wan")
76
		$input_errors[] = "Schedule may not be named WAN.";
77
	if(strtolower($_POST['name']) == "")
78
		$input_errors[] = "Schedule name cannot be blank.";
79

    
80
	$x = is_validaliasname($_POST['name']);
81
	if (!isset($x)) {
82
		$input_errors[] = "Reserved word used for schedule name.";
83
	} else {
84
		if (is_validaliasname($_POST['name']) == false)
85
			$input_errors[] = "The schedule name may only consist of the characters a-z, A-Z, 0-9";
86
	}
87
	
88
	/* check for name conflicts */
89
	foreach ($a_schedules as $schedule) {
90
		if (isset($id) && ($a_schedules[$id]) && ($a_schedules[$id] === $schedule))
91
			continue;
92

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

    
181
}
182
include("head.inc");
183

    
184
/* put your custom HTML head content here        */
185
/* using some of the $pfSenseHead function calls */
186
$jscriptstr = <<<EOD
187
<script type="text/javascript">
188

    
189
var daysSelected = "";
190
var month_array = ['January','February','March','April','May','June','July','August','September','October','November','December'];
191
var day_array = ['Mon','Tues','Wed','Thur','Fri','Sat','Sun'];
192
var schCounter = 0;
193

    
194

    
195

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

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

    
315
function update_month(){
316
	var indexNum = document.forms[0].monthsel.selectedIndex;
317
	var selected = document.forms[0].monthsel.options[indexNum].text;
318

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

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

    
343
function processEntries(){
344
	var tempstr, starttimehour, starttimemin, stoptimehour, stoptimemin, errors = "";
345
	var passedValidiation = true;
346
	
347
	//get time specified
348
	starttimehour = parseInt(document.getElementById("starttimehour").value);
349
	starttimemin = parseInt(document.getElementById("starttimemin").value);
350
	stoptimehour = parseInt(document.getElementById("stoptimehour").value);
351
	stoptimemin = parseInt(document.getElementById("stoptimemin").value);
352

    
353

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

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

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

    
620

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

    
639
function clearTime(){
640
	document.getElementById("starttimehour").value = $starttimehr;
641
	document.getElementById("starttimemin").value = $starttimemin;
642
	document.getElementById("stoptimehour").value = $stoptimehr;
643
	document.getElementById("stoptimemin").value = $stoptimemin;
644
}
645

    
646
function clearDescr(){
647
	document.getElementById("timerangedescr").value = "";
648
}
649

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

    
705
function removeRownoprompt(el) {
706
    var cel;
707
    while (el && el.nodeName.toLowerCase() != "tr")
708
	    el = el.parentNode;
709

    
710
    if (el && el.parentNode) {
711
	cel = el.getElementsByTagName("td").item(0);
712
	el.parentNode.removeChild(el);
713
    }
714
}
715

    
716

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

    
731
</script>
732
EOD;
733
?>
734

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

    
737

    
738
<?php include("fbegin.inc");	echo $jscriptstr; ?>
739
<?php if ($input_errors) print_input_errors($input_errors); ?>
740
<div id="inputerrors"></div>
741

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