Project

General

Profile

Download (37.4 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
function schedulecmp($a, $b) {
41
	return strcmp($a['name'], $b['name']);
42
}
43

    
44
function schedule_sort(){
45
        global $g, $config;
46

    
47
        if (!is_array($config['schedules']['schedule']))
48
                return;
49

    
50
        usort($config['schedules']['schedule'], "schedulecmp");
51
}
52

    
53
$pgtitle = array("Firewall","Schedules","Edit");
54
require("guiconfig.inc");
55

    
56
$starttimehr = 00;
57
$starttimemin = 00;
58

    
59
$stoptimehr = 23;
60
$stoptimemin = 59;
61

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

    
65
if (!is_array($config['schedules']['schedule']))
66
	$config['schedules']['schedule'] = array();
67

    
68
schedule_sort();
69
$a_schedules = &$config['schedules']['schedule'];
70

    
71

    
72
$id = $_GET['id'];
73
if (isset($_POST['id']))
74
	$id = $_POST['id'];
75

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

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

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

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

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

    
200
}
201
include("head.inc");
202

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

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

    
213

    
214

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

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

    
334
function update_month(){
335
	var indexNum = document.forms[0].monthsel.selectedIndex;
336
	var selected = document.forms[0].monthsel.options[indexNum].text;
337

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

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

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

    
372

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

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

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

    
639

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

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

    
665
function clearDescr(){
666
	document.getElementById("timerangedescr").value = "";
667
}
668

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

    
724
function removeRownoprompt(el) {
725
    var cel;
726
    while (el && el.nodeName.toLowerCase() != "tr")
727
	    el = el.parentNode;
728

    
729
    if (el && el.parentNode) {
730
	cel = el.getElementsByTagName("td").item(0);
731
	el.parentNode.removeChild(el);
732
    }
733
}
734

    
735

    
736
function removeRow(el) {
737
	var check = confirm ("Do you really want to delete this time range?");
738
	if (check){
739
	    var cel;
740
	    while (el && el.nodeName.toLowerCase() != "tr")
741
		    el = el.parentNode;
742
	
743
	    if (el && el.parentNode) {
744
		cel = el.getElementsByTagName("td").item(0);
745
		el.parentNode.removeChild(el);
746
	    }
747
	}
748
}
749

    
750
</script>
751
EOD;
752
?>
753

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

    
756

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

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