Project

General

Profile

Download (37.1 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
	$pconfig['schedlabel'] = $a_schedules[$id]['schedlabel'];
69
	$getSchedule = true;
70
}
71

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

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

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

    
161
		if (isset($id) && $a_schedules[$id]){
162
			$a_schedules[$id] = $schedule;
163
		}
164
		else{
165
			$a_schedules[] = $schedule;
166
		}
167
		write_config();
168
		
169
		filter_configure();
170
			
171
		header("Location: firewall_schedule.php");
172
		exit;
173
		
174
	}
175
	//we received input errors, copy data to prevent retype
176
	else
177
	{
178
		if (!$_POST['schedule0'])
179
			$getSchedule = false;
180
		else
181
			$getSchedule = true;
182
		$pconfig['name'] = $schedule['name'];
183
		$pconfig['descr'] = $schedule['descr'];
184
		$pconfig['timerange'] = $schedule['timerange'];
185
	}	
186

    
187
}
188
include("head.inc");
189

    
190
/* put your custom HTML head content here        */
191
/* using some of the $pfSenseHead function calls */
192
$jscriptstr = <<<EOD
193
<script type="text/javascript">
194

    
195
var daysSelected = "";
196
var month_array = ['January','February','March','April','May','June','July','August','September','October','November','December'];
197
var day_array = ['Mon','Tues','Wed','Thur','Fri','Sat','Sun'];
198
var schCounter = 0;
199

    
200

    
201

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

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

    
321
function update_month(){
322
	var indexNum = document.forms[0].monthsel.selectedIndex;
323
	var selected = document.forms[0].monthsel.options[indexNum].text;
324

    
325
	for (i=0; i<=11; i++){
326
		option = document.forms[0].monthsel.options[i].text;
327
		document.popupMonthLayer = eval('document.getElementById (option)');
328
		
329
		if(selected == option) {
330
			document.popupMonthLayer.style.display="block";
331
		}
332
		else
333
			document.popupMonthLayer.style.display="none";
334
	}
335
}
336

    
337
function checkForRanges(){
338
	if (daysSelected != "")
339
	{
340
		alert("You have not saved the specified time range. Please click 'Add Time' button to save the time range.");
341
		return false;
342
	}
343
	else
344
	{
345
		return true;
346
	}
347
}
348

    
349
function processEntries(){
350
	var tempstr, starttimehour, starttimemin, stoptimehour, stoptimemin, errors = "";
351
	var passedValidiation = true;
352
	
353
	//get time specified
354
	starttimehour = parseInt(document.getElementById("starttimehour").value);
355
	starttimemin = parseInt(document.getElementById("starttimemin").value);
356
	stoptimehour = parseInt(document.getElementById("stoptimehour").value);
357
	stoptimemin = parseInt(document.getElementById("stoptimemin").value);
358

    
359

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

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

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

    
626

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

    
645
function clearTime(){
646
	document.getElementById("starttimehour").value = $starttimehr;
647
	document.getElementById("starttimemin").value = $starttimemin;
648
	document.getElementById("stoptimehour").value = $stoptimehr;
649
	document.getElementById("stoptimemin").value = $stoptimemin;
650
}
651

    
652
function clearDescr(){
653
	document.getElementById("timerangedescr").value = "";
654
}
655

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

    
711
function removeRownoprompt(el) {
712
    var cel;
713
    while (el && el.nodeName.toLowerCase() != "tr")
714
	    el = el.parentNode;
715

    
716
    if (el && el.parentNode) {
717
	cel = el.getElementsByTagName("td").item(0);
718
	el.parentNode.removeChild(el);
719
    }
720
}
721

    
722

    
723
function removeRow(el) {
724
	var check = confirm ("Do you really want to delete this time range?");
725
	if (check){
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
</script>
738
EOD;
739
?>
740

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

    
743

    
744
<?php include("fbegin.inc");	echo $jscriptstr; ?>
745
<?php if ($input_errors) print_input_errors($input_errors); ?>
746
<div id="inputerrors"></div>
747

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