Project

General

Profile

Download (37.5 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 schedule_sort(){
41
        global $g, $config;
42

    
43
        if (!is_array($config['schedules']['schedule']))
44
                return;
45

    
46
        function schedulecmp($a, $b) {
47
                return strcmp($a['name'], $b['name']);
48
        }
49

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

    
52
}
53

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

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

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

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

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

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

    
72

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

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

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

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

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

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

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

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

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

    
214

    
215

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

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

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

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

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

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

    
373

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

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

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

    
640

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

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

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

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

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

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

    
736

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

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

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

    
757

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

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