Project

General

Profile

Download (38.8 KB) Statistics
| Branch: | Tag: | Revision:
1 615b27bc Scott Dale
<?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 7ac5a4cb Scott Ullrich
/*
33
	pfSense_MODULE:	schedules
34
*/
35 615b27bc Scott Dale
36 6b07c15a Matthew Grooms
##|+PRIV
37
##|*IDENT=page-firewall-schedules-edit
38
##|*NAME=Firewall: Schedules: Edit page
39
##|*DESCR=Allow access to the 'Firewall: Schedules: Edit' page.
40
##|*MATCH=firewall_schedule_edit.php*
41
##|-PRIV
42
43 4b141b9a Ermal Lu?i
function schedulecmp($a, $b) {
44
	return strcmp($a['name'], $b['name']);
45
}
46
47 0d64af59 Ermal Lu?i
function schedule_sort(){
48
        global $g, $config;
49
50
        if (!is_array($config['schedules']['schedule']))
51
                return;
52
53
        usort($config['schedules']['schedule'], "schedulecmp");
54
}
55 6b07c15a Matthew Grooms
56 615b27bc Scott Dale
require("guiconfig.inc");
57 7a927e67 Scott Ullrich
require_once("functions.inc");
58
require_once("filter.inc");
59
require_once("shaper.inc");
60 615b27bc Scott Dale
61 b5d84594 Carlos Eduardo Ramos
$pgtitle = array(gettext("Firewall"),gettext("Schedules"),gettext("Edit"));
62
63 615b27bc Scott Dale
$starttimehr = 00;
64
$starttimemin = 00;
65
66 bd080157 Scott Dale
$stoptimehr = 23;
67
$stoptimemin = 59;
68 615b27bc Scott Dale
69 5d8a530e Rafael Lucas
$dayArray = array (gettext('Mon'),gettext('Tues'),gettext('Wed'),gettext('Thur'),gettext('Fri'),gettext('Sat'),gettext('Sun'));
70
$monthArray = array (gettext('January'),gettext('February'),gettext('March'),gettext('April'),gettext('May'),gettext('June'),gettext('July'),gettext('August'),gettext('September'),gettext('October'),gettext('November'),gettext('December'));
71 615b27bc Scott Dale
72
if (!is_array($config['schedules']['schedule']))
73
	$config['schedules']['schedule'] = array();
74
75
$a_schedules = &$config['schedules']['schedule'];
76
77 273c8b1c Scott Dale
78 615b27bc Scott Dale
$id = $_GET['id'];
79
if (isset($_POST['id']))
80
	$id = $_POST['id'];
81
82
if (isset($id) && $a_schedules[$id]) {
83
	$pconfig['name'] = $a_schedules[$id]['name'];
84
	$pconfig['descr'] = html_entity_decode($a_schedules[$id]['descr']);
85
	$pconfig['timerange'] = $a_schedules[$id]['timerange'];
86 60120e37 Ermal Lu?i
	$pconfig['schedlabel'] = $a_schedules[$id]['schedlabel'];
87 615b27bc Scott Dale
	$getSchedule = true;
88
}
89
90
if ($_POST) {
91
	
92
	if(strtolower($_POST['name']) == "lan")
93 5d8a530e Rafael Lucas
		$input_errors[] = gettext("Schedule may not be named LAN.");
94 615b27bc Scott Dale
	if(strtolower($_POST['name']) == "wan")
95 5d8a530e Rafael Lucas
		$input_errors[] = gettext("Schedule may not be named WAN.");
96 273c8b1c Scott Dale
	if(strtolower($_POST['name']) == "")
97 5d8a530e Rafael Lucas
		$input_errors[] = gettext("Schedule name cannot be blank.");
98 615b27bc Scott Dale
99
	$x = is_validaliasname($_POST['name']);
100
	if (!isset($x)) {
101 5d8a530e Rafael Lucas
		$input_errors[] = gettext("Reserved word used for schedule name.");
102 615b27bc Scott Dale
	} else {
103
		if (is_validaliasname($_POST['name']) == false)
104 5d8a530e Rafael Lucas
			$input_errors[] = gettext("The schedule name may only consist of the characters a-z, A-Z, 0-9");
105 615b27bc Scott Dale
	}
106
	
107
	/* check for name conflicts */
108
	foreach ($a_schedules as $schedule) {
109
		if (isset($id) && ($a_schedules[$id]) && ($a_schedules[$id] === $schedule))
110
			continue;
111
112
		if ($schedule['name'] == $_POST['name']) {
113 5d8a530e Rafael Lucas
			$input_errors[] = gettext("A Schedule with this name already exists.");
114 615b27bc Scott Dale
			break;
115
		}
116
	}
117 273c8b1c Scott Dale
	$schedule = array();
118
	
119
	$schedule['name'] = $_POST['name'];
120
	$schedule['descr'] = htmlentities($_POST['descr'], ENT_QUOTES, 'UTF-8');	
121
	
122 e56fcb71 Scott Dale
	$timerangeFound = false;
123 615b27bc Scott Dale
	for ($x=0; $x<99; $x++){
124
		if($_POST['schedule' . $x]) {
125 e56fcb71 Scott Dale
			$timerangeFound = true;
126 273c8b1c Scott Dale
			$timeparts = array();
127
			$firstprint = false;
128
			$timestr = $_POST['schedule' . $x];
129
			$timehourstr = $_POST['starttime' . $x];
130
			$timehourstr .= "-";
131
			$timehourstr .= $_POST['stoptime' . $x];
132
			$timedescrstr = htmlentities($_POST['timedescr' . $x], ENT_QUOTES, 'UTF-8'); 
133
			$dashpos = strpos($timestr, '-');
134
			if ($dashpos === false)
135
			{
136 fdb29c8a Scott Dale
				$timeparts['position'] = $timestr;
137 273c8b1c Scott Dale
			}
138
			else
139
			{
140
				$tempindarray = array();
141
				$monthstr = "";
142
				$daystr = "";
143
				$tempindarray = explode(",", $timestr);
144
				foreach ($tempindarray as $currentselection)
145
				{
146
					if ($currentselection){
147
						if ($firstprint)
148
						{
149
							$monthstr .= ",";
150
							$daystr .= ",";						
151
						}
152
						$tempstr = "";
153
						$monthpos = strpos($currentselection, "m");
154
						$daypos = strpos($currentselection, "d");
155
						$monthstr .= substr($currentselection, $monthpos+1, $daypos-$monthpos-1);
156 6a6d2f63 Scott Dale
						$daystr .=  substr($currentselection, $daypos+1);			
157 273c8b1c Scott Dale
						$firstprint = true;
158
					}
159
				}
160
				$timeparts['month'] = $monthstr;
161
				$timeparts['day'] = $daystr;
162
			}			
163
			$timeparts['hour'] = $timehourstr;
164
			$timeparts['rangedescr'] = $timedescrstr;
165
			$schedule['timerange'][$x] = $timeparts;
166 615b27bc Scott Dale
		}
167
	}
168
	
169 e56fcb71 Scott Dale
	if (!$timerangeFound)
170 5d8a530e Rafael Lucas
		$input_errors[] = gettext("The schedule must have at least one time range configured.");
171 615b27bc Scott Dale
		
172
	if (!$input_errors) {		
173
		
174 60120e37 Ermal Lu?i
		if (!empty($pconfig['schedlabel']))
175
			$schedule['schedlabel'] = $pconfig['schedlabel'];
176
		else
177
			$schedule['schedlabel'] = uniqid();
178
179 273c8b1c Scott Dale
		if (isset($id) && $a_schedules[$id]){
180 615b27bc Scott Dale
			$a_schedules[$id] = $schedule;
181 273c8b1c Scott Dale
		}
182
		else{
183 615b27bc Scott Dale
			$a_schedules[] = $schedule;
184 273c8b1c Scott Dale
		}
185 0e3aa71c Erik Fonnesbeck
		schedule_sort();
186 3a343d73 jim-p
		if (write_config())
187
			filter_configure();
188
189 4f65a1d5 Vinicius Coque
		header("Location: firewall_schedule.php");
190 615b27bc Scott Dale
		exit;
191
		
192
	}
193
	//we received input errors, copy data to prevent retype
194
	else
195
	{
196 101fd849 Scott Dale
		if (!$_POST['schedule0'])
197
			$getSchedule = false;
198
		else
199
			$getSchedule = true;
200 273c8b1c Scott Dale
		$pconfig['name'] = $schedule['name'];
201
		$pconfig['descr'] = $schedule['descr'];
202 615b27bc Scott Dale
		$pconfig['timerange'] = $schedule['timerange'];
203
	}	
204
205
}
206
include("head.inc");
207
208
/* put your custom HTML head content here        */
209
/* using some of the $pfSenseHead function calls */
210
$jscriptstr = <<<EOD
211
<script type="text/javascript">
212 95f133d2 Colin Fleming
//<![CDATA[
213 615b27bc Scott Dale
var daysSelected = "";
214
var month_array = ['January','February','March','April','May','June','July','August','September','October','November','December'];
215 6a6d2f63 Scott Dale
var day_array = ['Mon','Tues','Wed','Thur','Fri','Sat','Sun'];
216 615b27bc Scott Dale
var schCounter = 0;
217
218 273c8b1c Scott Dale
219
220 615b27bc Scott Dale
function repeatExistingDays(){
221
	var tempstr, tempstrdaypos, week, daypos, dayposdone = "";
222
	
223
	var dayarray = daysSelected.split(",");
224
	for (i=0; i<=dayarray.length; i++){
225
		tempstr = dayarray[i];
226
		tempstrdaypos = tempstr.search("p");
227
		week = tempstr.substring(1,tempstrdaypos);
228
		week = parseInt(week);
229
		dashpos = tempstr.search("-");		
230
		daypos = tempstr.substring(tempstrdaypos+1, dashpos);
231
		daypos = parseInt(daypos);
232
		
233
		daydone = dayposdone.search(daypos);
234
		tempstr = 'w' + week + 'p' + daypos;
235
		daycell = eval('document.getElementById(tempstr)');
236
		if (daydone == "-1"){
237 a0c0e8ae Colin Fleming
			if (daycell.style.backgroundColor == "#F08080")  // lightcoral
238 615b27bc Scott Dale
				daytogglerepeating(week,daypos,true);
239
			else
240
				daytogglerepeating(week,daypos,false);
241
			dayposdone += daypos + ",";
242
		}
243
	}	
244
}
245
246
function daytogglerepeating(week,daypos,bExists){
247
	var tempstr, daycell, dayoriginal = "";
248
	for (j=1; j<=53; j++)
249
	{						
250
		tempstr = 'w' + j + 'p' + daypos;
251
		daycell = eval('document.getElementById(tempstr)');
252
		dayoriginalpos =  daysSelected.indexOf(tempstr);
253
		
254
		//if bExists set to true, means cell is already select it
255
		//unselect it and remove original day from daysSelected string		
256
	
257
		if (daycell != null)
258
		{
259
			if (bExists){	
260 a0c0e8ae Colin Fleming
				daycell.style.backgroundColor = "#FFFFFF";  // white
261 615b27bc Scott Dale
			}
262
			else
263
			{
264 a0c0e8ae Colin Fleming
				daycell.style.backgroundColor = "#F08080";  // lightcoral		
265 615b27bc Scott Dale
			}	
266
	
267
			if (dayoriginalpos != "-1")
268
			{						
269
				dayoriginalend = daysSelected.indexOf(',', dayoriginalpos);
270
				tempstr = daysSelected.substring(dayoriginalpos, dayoriginalend+1);
271
				daysSelected = daysSelected.replace(tempstr, "");
272
				
273
			}				
274
		}			
275
	}	
276
}
277
	
278
function daytoggle(id) {
279
	var runrepeat, tempstr = "";
280
	var bFoundValid = false;
281
	
282
	iddashpos = id.search("-");
283
	var tempstrdaypos = id.search("p");
284
	var week = id.substring(1,tempstrdaypos);
285
	week = parseInt(week);
286
	
287
	if (iddashpos == "-1")
288
	{
289
		idmod = id;
290
		runrepeat = true;
291
		var daypos = id.substr(tempstrdaypos+1);	
292
	}
293
	else
294
	{		
295
		idmod = id.substring(0,iddashpos);
296
		var daypos = id.substring(tempstrdaypos+1,iddashpos);
297
	}
298
	
299
	daypos = parseInt(daypos);
300
	
301
	while (!bFoundValid){
302
		var daycell = document.getElementById(idmod);		
303
	
304
		if (daycell != null){
305 a0c0e8ae Colin Fleming
			if (daycell.style.backgroundColor == "#FF0000"){  // red
306
				daycell.style.backgroundColor = "#FFFFFF";  // white
307 615b27bc Scott Dale
				str = id + ",";
308
				daysSelected = daysSelected.replace(str, "");
309
			}
310 a0c0e8ae Colin Fleming
			else if (daycell.style.backgroundColor == "#F08080")  // lightcoral
311 615b27bc Scott Dale
			{
312
				daytogglerepeating(week,daypos,true);
313
			}
314
			else //color is white cell
315
			{
316
				if (!runrepeat)
317
				{
318 a0c0e8ae Colin Fleming
					daycell.style.backgroundColor = "#FF0000";  // red
319 615b27bc Scott Dale
				}
320
				else
321
				{
322 a0c0e8ae Colin Fleming
					daycell.style.backgroundColor = "#F08080";  // lightcoral
323 615b27bc Scott Dale
					daytogglerepeating(week,daypos,false);								
324
				}
325
				daysSelected += id + ",";
326
			}
327
			bFoundValid = true;
328
		}
329
		else
330
		{
331
			//we found an invalid cell when column was clicked, move up to the next week
332
			week++;
333
			tempstr = "w" + week + "p" + daypos;
334
			idmod = tempstr;			
335
		}
336
	}
337
}
338
339
function update_month(){
340
	var indexNum = document.forms[0].monthsel.selectedIndex;
341
	var selected = document.forms[0].monthsel.options[indexNum].text;
342
343
	for (i=0; i<=11; i++){
344
		option = document.forms[0].monthsel.options[i].text;
345
		document.popupMonthLayer = eval('document.getElementById (option)');
346
		
347
		if(selected == option) {
348
			document.popupMonthLayer.style.display="block";
349
		}
350
		else
351
			document.popupMonthLayer.style.display="none";
352
	}
353
}
354
355 101fd849 Scott Dale
function checkForRanges(){
356
	if (daysSelected != "")
357
	{
358 636a69e6 Scott Dale
		alert("You have not saved the specified time range. Please click 'Add Time' button to save the time range.");
359 615b27bc Scott Dale
		return false;
360 101fd849 Scott Dale
	}
361 615b27bc Scott Dale
	else
362 101fd849 Scott Dale
	{
363 615b27bc Scott Dale
		return true;
364 101fd849 Scott Dale
	}
365 615b27bc Scott Dale
}
366
367
function processEntries(){
368
	var tempstr, starttimehour, starttimemin, stoptimehour, stoptimemin, errors = "";
369
	var passedValidiation = true;
370
	
371
	//get time specified
372
	starttimehour = parseInt(document.getElementById("starttimehour").value);
373
	starttimemin = parseInt(document.getElementById("starttimemin").value);
374
	stoptimehour = parseInt(document.getElementById("stoptimehour").value);
375
	stoptimemin = parseInt(document.getElementById("stoptimemin").value);
376
377 273c8b1c Scott Dale
378 615b27bc Scott Dale
	//do time checks	
379
	if (starttimehour > stoptimehour)
380
	{
381
		errors = "Error: Start Hour cannot be greater than Stop Hour.";
382
		passedValidiation = false;
383 273c8b1c Scott Dale
		
384 615b27bc Scott Dale
	}
385 273c8b1c Scott Dale
	else if (starttimehour == stoptimehour)
386 615b27bc Scott Dale
	{
387
		if (starttimemin > stoptimemin){
388
			errors = "Error: Start Minute cannot be greater than Stop Minute.";
389
			passedValidiation = false;
390
		}
391
	}	
392 273c8b1c Scott Dale
		
393 615b27bc Scott Dale
	if (passedValidiation){
394
		addTimeRange();
395
	}
396 273c8b1c Scott Dale
	else {
397
		if (errors != "")
398
			alert(errors);
399
	}
400 615b27bc Scott Dale
}
401
402
function addTimeRange(){
403
	var tempdayarray = daysSelected.split(",");
404 273c8b1c Scott Dale
	var tempstr, tempFriendlyDay, starttimehour, starttimemin, stoptimehour, nrtempFriendlyTime, rtempFriendlyTime, nrtempID, rtempID = "";
405 1a4f3123 Scott Dale
	var stoptimemin, timeRange, tempstrdaypos, week, daypos, day, month, dashpos, nrtempTime, rtempTime, monthstr, daystr = "";
406 273c8b1c Scott Dale
	rtempFriendlyTime = "";
407
	nrtempFriendlyTime = "";
408
	nrtempID = "";
409
	rtempID = "";
410
	nrtempTime = "";
411
	rtempTime = "";
412 615b27bc Scott Dale
	tempdayarray.sort();	
413 273c8b1c Scott Dale
	rtempFriendlyDay = "";
414 1a4f3123 Scott Dale
	monthstr = "";
415
	daystr = "";
416 615b27bc Scott Dale
	
417
	//check for existing entries
418
	var findCurrentCounter;
419
	for (u=0; u<99; u++){
420
		findCurrentCounter = document.getElementById("schedule" + u);
421
		if (!findCurrentCounter)
422
		{
423
			schCounter = u;
424
			break;
425
		}
426
	}
427 273c8b1c Scott Dale
		
428 615b27bc Scott Dale
	if (daysSelected != ""){
429
		//get days selected
430
		for (i=0; i<tempdayarray.length; i++)
431
		{
432
			tempstr = tempdayarray[i];
433
			if (tempstr != "")
434
			{			
435
				tempstrdaypos = tempstr.search("p");
436
				week = tempstr.substring(1,tempstrdaypos);
437
				week = parseInt(week);
438
				dashpos = tempstr.search("-");			
439
				
440
				if (dashpos != "-1")
441 273c8b1c Scott Dale
				{	
442
					var nonrepeatingfound = true;
443 615b27bc Scott Dale
					daypos = tempstr.substring(tempstrdaypos+1, dashpos);
444
					daypos = parseInt(daypos);	
445
					monthpos = tempstr.search("m");	
446
					tempstrdaypos = tempstr.search("d");
447
					month = tempstr.substring(monthpos+1, tempstrdaypos);
448
					month = parseInt(month);
449
					day = tempstr.substring(tempstrdaypos+1);
450
					day = parseInt(day);
451 1a4f3123 Scott Dale
					monthstr += month + ",";
452
					daystr += day + ",";
453 273c8b1c Scott Dale
					nrtempID += tempstr + ",";
454 615b27bc Scott Dale
				}
455
				else
456
				{	
457 273c8b1c Scott Dale
					var repeatingfound = true;
458 615b27bc Scott Dale
					daypos = tempstr.substr(tempstrdaypos+1);
459
					daypos = parseInt(daypos);	
460 273c8b1c Scott Dale
					rtempFriendlyDay += daypos + ",";
461
					rtempID += daypos + ",";					
462 615b27bc Scott Dale
				}		
463
			}				
464
		}	
465
		
466 1a4f3123 Scott Dale
		//code below spits out friendly look format for nonrepeating schedules
467 615b27bc Scott Dale
		var foundEnd = false;
468
		var firstDayFound = false;
469
		var firstprint = false;
470 1a4f3123 Scott Dale
		var tempFriendlyMonthArray = monthstr.split(",");
471
		var tempFriendlyDayArray = daystr.split(",");
472
		var currentDay, firstDay, nextDay, currentMonth, nextMonth, firstDay, firstMonth = "";
473
		for (k=0; k<tempFriendlyMonthArray.length; k++){
474
			tempstr = tempFriendlyMonthArray[k];
475
			if (tempstr != ""){
476
				if (!firstDayFound)
477
				{
478
					firstDay = tempFriendlyDayArray[k];
479
					firstDay = parseInt(firstDay);
480
					firstMonth = tempFriendlyMonthArray[k];
481
					firstMonth = parseInt(firstMonth);
482
					firstDayFound = true;
483
				}
484
				currentDay = tempFriendlyDayArray[k];
485
				currentDay = parseInt(currentDay);
486
				//get next day
487
				nextDay = tempFriendlyDayArray[k+1];
488
				nextDay = parseInt(nextDay);
489
				//get next month
490
				
491
				currentDay++;						
492
				if ((currentDay != nextDay) || (tempFriendlyMonthArray[k] != tempFriendlyMonthArray[k+1])){
493
					if (firstprint)
494
						nrtempFriendlyTime += ", ";
495
					currentDay--;
496
					if (currentDay != firstDay)
497
						nrtempFriendlyTime += month_array[firstMonth-1] + " " + firstDay + "-" + currentDay;
498
					else
499
						nrtempFriendlyTime += month_array[firstMonth-1] + " " + currentDay; 
500
					firstDayFound = false;	
501
					firstprint = true;			
502
				}
503
			}			
504
		}		
505
		
506
		//code below spits out friendly look format for repeating schedules
507
		foundEnd = false;
508
		firstDayFound = false;
509
		firstprint = false;
510
		tempFriendlyDayArray = rtempFriendlyDay.split(",");
511 273c8b1c Scott Dale
		tempFriendlyDayArray.sort();
512 1a4f3123 Scott Dale
		currentDay, firstDay, nextDay = "";
513 615b27bc Scott Dale
		for (k=0; k<tempFriendlyDayArray.length; k++){
514
			tempstr = tempFriendlyDayArray[k];
515
			if (tempstr != ""){
516
				if (!firstDayFound)
517
				{
518
					firstDay = tempFriendlyDayArray[k];
519
					firstDay = parseInt(firstDay);
520
					firstDayFound = true;
521
				}
522
				currentDay = tempFriendlyDayArray[k];
523
				currentDay = parseInt(currentDay);
524
				//get next day
525
				nextDay = tempFriendlyDayArray[k+1];
526
				nextDay = parseInt(nextDay);
527
				currentDay++;					
528
				if (currentDay != nextDay){
529
					if (firstprint)
530 273c8b1c Scott Dale
						rtempFriendlyTime += ", ";
531 615b27bc Scott Dale
					currentDay--;
532
					if (currentDay != firstDay)
533 6a6d2f63 Scott Dale
						rtempFriendlyTime += day_array[firstDay-1] + " - " + day_array[currentDay-1];
534 615b27bc Scott Dale
					else
535 6a6d2f63 Scott Dale
						rtempFriendlyTime += day_array[firstDay-1];
536 615b27bc Scott Dale
					firstDayFound = false;	
537
					firstprint = true;			
538
				}
539
			}
540
		}			
541
		
542 273c8b1c Scott Dale
		//sort the tempID
543
		var tempsortArray = rtempID.split(",");
544
		var isFirstdone = false;
545
		tempsortArray.sort();
546
		//clear tempID
547
		rtempID = "";
548
		for (t=0; t<tempsortArray.length; t++)
549
		{
550
			if (tempsortArray[t] != ""){
551
				if (!isFirstdone){
552
					rtempID += tempsortArray[t];
553
					isFirstdone = true;
554
				}
555
				else
556
					rtempID += "," + tempsortArray[t];
557
			}
558
		} 
559
		
560 615b27bc Scott Dale
		 
561
		//get time specified
562 101fd849 Scott Dale
		starttimehour =  document.getElementById("starttimehour").value
563 615b27bc Scott Dale
		starttimemin = document.getElementById("starttimemin").value;
564
		stoptimehour = document.getElementById("stoptimehour").value;
565
		stoptimemin = document.getElementById("stoptimemin").value;
566
		
567
		timeRange = "||" + starttimehour + ":";
568
		timeRange += starttimemin + "-";
569
		timeRange += stoptimehour + ":";	
570 273c8b1c Scott Dale
		timeRange += stoptimemin;		
571
				
572 615b27bc Scott Dale
		//get description for time range
573 273c8b1c Scott Dale
		var tempdescr = document.getElementById("timerangedescr").value		
574
		
575
		if (nonrepeatingfound){
576
			nrtempTime += nrtempID;
577
			//add time ranges
578
			nrtempTime += timeRange;			
579
			//add description
580
			nrtempTime += "||" + tempdescr;
581
			insertElements(nrtempFriendlyTime, starttimehour, starttimemin, stoptimehour, stoptimemin, tempdescr, nrtempTime, nrtempID);
582
		}
583 615b27bc Scott Dale
		
584 273c8b1c Scott Dale
		if (repeatingfound){
585
			rtempTime += rtempID;
586
			//add time ranges
587
			rtempTime += timeRange;
588
			//add description
589
			rtempTime += "||" + tempdescr;
590
			insertElements(rtempFriendlyTime, starttimehour, starttimemin, stoptimehour, stoptimemin, tempdescr, rtempTime, rtempID);
591
		}
592 615b27bc Scott Dale
		
593 273c8b1c Scott Dale
	}
594
	else
595
	{
596
		//no days were selected, alert user
597
		alert ("You must select at least 1 day before adding time");
598
	}
599
}
600
601
function insertElements(tempFriendlyTime, starttimehour, starttimemin, stoptimehour, stoptimemin, tempdescr, tempTime, tempID){
602
	
603 615b27bc Scott Dale
		//add it to the schedule list
604
		d = document;
605
		tbody = d.getElementById("scheduletable").getElementsByTagName("tbody").item(0);
606
		tr = d.createElement("tr");
607
		td = d.createElement("td");
608 34be89d1 Colin Fleming
		td.innerHTML= "<span class='vexpl'>" + tempFriendlyTime + "<\/span>";
609 615b27bc Scott Dale
		tr.appendChild(td);	
610
			
611
		td = d.createElement("td");
612 95f133d2 Colin Fleming
		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 + "' />";
613 615b27bc Scott Dale
		tr.appendChild(td);
614
		
615
		td = d.createElement("td");
616 95f133d2 Colin Fleming
		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 + "' />";
617 615b27bc Scott Dale
		tr.appendChild(td);
618
		
619
		td = d.createElement("td");
620 95f133d2 Colin Fleming
		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 + "' />";
621 615b27bc Scott Dale
		tr.appendChild(td);
622
		
623
		td = d.createElement("td");
624 34be89d1 Colin Fleming
		td.innerHTML = "<a onclick='editRow(\"" + tempTime + "\",this); return false;' href='#'><img border='0' src='/themes/" + theme + "/images/icons/icon_e.gif' alt='edit' /></\a>";
625 615b27bc Scott Dale
		tr.appendChild(td);
626
			
627
		td = d.createElement("td");
628 34be89d1 Colin Fleming
		td.innerHTML = "<a onclick='removeRow(this); return false;' href='#'><img border='0' src='/themes/" + theme + "/images/icons/icon_x.gif' alt='remove' /></\a>";
629 615b27bc Scott Dale
		tr.appendChild(td);
630
		
631
		td = d.createElement("td");		
632 95f133d2 Colin Fleming
		td.innerHTML="<input type='hidden' id='schedule" + schCounter + "' name='schedule" + schCounter + "' value='" + tempID + "' />";		
633 615b27bc Scott Dale
		tr.appendChild(td);
634
		tbody.appendChild(tr);
635
		
636
		schCounter++;
637
		
638
		//reset calendar and time and descr
639
		clearCalendar();
640
		clearTime();
641
		clearDescr();
642
}
643
644
645
function clearCalendar(){
646
	var tempstr, daycell = "";
647
	//clear days selected
648
	daysSelected = "";
649
	//loop through all 52 weeks
650
	for (j=1; j<=53; j++)
651
	{
652
		//loop through all 7 days
653 6a6d2f63 Scott Dale
		for (k=1; k<8; k++){
654 615b27bc Scott Dale
			tempstr = 'w' + j + 'p' + k;
655
			daycell = eval('document.getElementById(tempstr)');
656
			if (daycell != null){
657 a0c0e8ae Colin Fleming
				daycell.style.backgroundColor = "#FFFFFF";  // white	
658 615b27bc Scott Dale
			}	
659
		}
660
	}	
661
}
662
663
function clearTime(){
664
	document.getElementById("starttimehour").value = $starttimehr;
665
	document.getElementById("starttimemin").value = $starttimemin;
666
	document.getElementById("stoptimehour").value = $stoptimehr;
667
	document.getElementById("stoptimemin").value = $stoptimemin;
668
}
669
670
function clearDescr(){
671
	document.getElementById("timerangedescr").value = "";
672
}
673
674 636a69e6 Scott Dale
function editRow(incTime, el) {
675
	var check = checkForRanges();
676 615b27bc Scott Dale
	
677 636a69e6 Scott Dale
	if (check){  
678
		
679
		//reset calendar and time
680
		clearCalendar();
681
		clearTime();
682
		
683
		var starttimehour, descr, days, tempstr, starttimemin, hours, stoptimehour, stoptimemin = ""; 
684
		
685
		tempArray = incTime.split ("||");
686
		
687
		days = tempArray[0];
688
		hours = tempArray[1];
689
		descr = tempArray[2];
690
		
691
		var tempdayArray = days.split(",");
692
		var temphourArray = hours.split("-");
693
		tempstr = temphourArray[0];
694
		var temphourArray2 = tempstr.split(":");
695 615b27bc Scott Dale
	
696 636a69e6 Scott Dale
		document.getElementById("starttimehour").value = temphourArray2[0];
697
		document.getElementById("starttimemin").value = temphourArray2[1];	
698
		
699
		tempstr = temphourArray[1];
700
		temphourArray2 = tempstr.split(":");
701
		
702
		document.getElementById("stoptimehour").value = temphourArray2[0];
703
		document.getElementById("stoptimemin").value = temphourArray2[1];
704
		
705
		document.getElementById("timerangedescr").value = descr;
706 615b27bc Scott Dale
	
707 636a69e6 Scott Dale
		//toggle the appropriate days
708
		for (i=0; i<tempdayArray.length; i++)
709
		{
710
			if (tempdayArray[i]){
711
				var tempweekstr = tempdayArray[i];
712
				dashpos = tempweekstr.search("-");			
713
						
714
				if (dashpos == "-1")
715
				{
716
					tempstr = "w2p" + tempdayArray[i];
717
				}
718
				else
719
				{
720
					tempstr = tempdayArray[i];
721
				}
722
				daytoggle(tempstr);
723 273c8b1c Scott Dale
			}
724 615b27bc Scott Dale
		}
725 636a69e6 Scott Dale
		removeRownoprompt(el);
726 615b27bc Scott Dale
	}
727
}
728
729 636a69e6 Scott Dale
function removeRownoprompt(el) {
730 615b27bc Scott Dale
    var cel;
731
    while (el && el.nodeName.toLowerCase() != "tr")
732
	    el = el.parentNode;
733
734
    if (el && el.parentNode) {
735
	cel = el.getElementsByTagName("td").item(0);
736
	el.parentNode.removeChild(el);
737
    }
738
}
739
740 636a69e6 Scott Dale
741
function removeRow(el) {
742
	var check = confirm ("Do you really want to delete this time range?");
743
	if (check){
744
	    var cel;
745
	    while (el && el.nodeName.toLowerCase() != "tr")
746
		    el = el.parentNode;
747
	
748
	    if (el && el.parentNode) {
749
		cel = el.getElementsByTagName("td").item(0);
750
		el.parentNode.removeChild(el);
751
	    }
752
	}
753
}
754 95f133d2 Colin Fleming
//]]>
755 615b27bc Scott Dale
</script>
756
EOD;
757
?>
758
759
<body link="#0000CC" vlink="#0000CC" alink="#0000CC" onload="<?= $jsevents["body"]["onload"] ?>">
760
761
762
<?php include("fbegin.inc");	echo $jscriptstr; ?>
763
<?php if ($input_errors) print_input_errors($input_errors); ?>
764
<div id="inputerrors"></div>
765
766
<form action="firewall_schedule_edit.php" method="post" name="iform" id="iform">
767 34be89d1 Colin Fleming
	<table width="100%" border="0" cellpadding="0" cellspacing="0" summary="firewall schedule">
768 3ea901d8 Scott Ullrich
		<tr>
769 5d8a530e Rafael Lucas
			<td colspan="2" valign="top" class="listtopic"><?=gettext("Schedule information");?></td>
770 3ea901d8 Scott Ullrich
		</tr>	
771 615b27bc Scott Dale
        <tr>
772
          <td>
773 34be89d1 Colin Fleming
			  <table width="100%" border="0" cellpadding="6" cellspacing="0" summary="main area">
774 615b27bc Scott Dale
               	<tr>
775 5d8a530e Rafael Lucas
				  <td width="15%" valign="top" class="vncellreq"><?=gettext("Schedule Name");?></td>
776 615b27bc Scott Dale
				  <td width="85%" class="vtable">
777 636a69e6 Scott Dale
				  <?php if(is_schedule_inuse($pconfig['name']) == true): ?>
778
				  			<input name="name" type="hidden" id="name" size="40"  value="<?=htmlspecialchars($pconfig['name']);?>" />
779
						  <?php echo $pconfig['name']; ?>
780
						      <p>
781 5d8a530e Rafael Lucas
						        <span class="vexpl"><?=gettext("NOTE: This schedule is in use so the name may not be modified!");?></span>
782 636a69e6 Scott Dale
						      </p>
783
				<?php else: ?>
784 95f133d2 Colin Fleming
				  <input name="name" type="text" id="name" size="40" maxlength="40" class="formfld unknown" value="<?=htmlspecialchars($pconfig['name']);?>" /><br/>
785 615b27bc Scott Dale
				      	<span class="vexpl">
786 5d8a530e Rafael Lucas
     					   <?=gettext("The name of the alias may only consist of the characters a-z, A-Z and 0-9");?>
787 636a69e6 Scott Dale
      					</span>
788
      			<?php endif; ?>   					
789 615b27bc Scott Dale
				  </td>
790
				</tr>
791
				<tr>
792 5d8a530e Rafael Lucas
					<td width="15%" valign="top" class="vncell"><?=gettext("Description");?></td>
793 95f133d2 Colin Fleming
					<td width="85%" class="vtable"><input name="descr" type="text" id="descr" size="40" maxlength="40" class="formfld unknown" value="<?=htmlspecialchars($pconfig['descr']);?>" /><br/>
794 615b27bc Scott Dale
 						<span class="vexpl">
795 5d8a530e Rafael Lucas
				        	<?=gettext("You may enter a description here for your reference (not parsed).");?>
796 636a69e6 Scott Dale
				      	</span>
797
				  
798
					</td>
799 615b27bc Scott Dale
				</tr>
800 95f133d2 Colin Fleming
				<!-- tr>
801
				</tr -->
802 615b27bc Scott Dale
			    <tr>
803 5d8a530e Rafael Lucas
				  <td width="15%" valign="top" class="vncellreq"><?=gettext("Month");?></td>
804 615b27bc Scott Dale
				  <td width="85%" class="vtable">
805
                    <select name="monthsel" class="formselect" id="monthsel" onchange="update_month();">
806
                    	<?php 
807
                    	$monthcounter = date("n");
808
                    	$monthlimit = $monthcounter + 12;
809 6a6d2f63 Scott Dale
                    	$yearcounter = date("Y");
810 273c8b1c Scott Dale
                    	for ($k=0; $k<12; $k++){?>	             
811 242a9331 Colin Fleming
                    		<option value="<?php echo $monthcounter;?>"><?php echo date("F_y", mktime(0, 0, 0, date($monthcounter), 1, date($yearcounter)));?></option>
812 273c8b1c Scott Dale
                          <?php        	
813
                          if ($monthcounter == 12)
814
							{
815
								$monthcounter = 1;
816 6a6d2f63 Scott Dale
								$yearcounter++;
817 273c8b1c Scott Dale
							}
818
							else
819
							{
820
								$monthcounter++;
821
							}	
822
						} ?>      	
823 95f133d2 Colin Fleming
                    </select><br/><br/>
824 615b27bc Scott Dale
            		<?php
825
            		$firstmonth = TRUE;
826
            		$monthcounter = date("n");
827 6a6d2f63 Scott Dale
            		$yearcounter = date("Y");
828 273c8b1c Scott Dale
            		for ($k=0; $k<12; $k++){
829 6a6d2f63 Scott Dale
						$firstdayofmonth = date("w", mktime(0, 0, 0, date($monthcounter), 1, date($yearcounter)));
830
						if ($firstdayofmonth == 0)
831
							$firstdayofmonth = 7;
832
							
833 273c8b1c Scott Dale
						$daycounter = 1;
834
						//number of day in month
835 6a6d2f63 Scott Dale
						$numberofdays = date("t", mktime(0, 0, 0, date($monthcounter), 1, date($yearcounter)));
836 615b27bc Scott Dale
						$firstdayprinted = FALSE;
837
						$lasttr = FALSE;
838 6a6d2f63 Scott Dale
						$positioncounter = 1;//7 for Sun, 1 for Mon, 2 for Tues, etc						
839 615b27bc Scott Dale
						?>	
840 242a9331 Colin Fleming
	                        <div id="<?php echo date("F_y",mktime(0, 0, 0, date($monthcounter), 1, date($yearcounter)));?>" style=" position:relative; display:<?php if($firstmonth)echo "block";else echo "none";?>">    	
841
		                   	<table border="1" cellspacing="1" cellpadding="1" id="calTable<?=$monthcounter . $yearcounter;?>" class="tabcont" summary="month">
842
								<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>
843 95f133d2 Colin Fleming
								</tr>
844
								<tr>	
845
									<td align="center" class="listhdrr" style="cursor: pointer;" onclick="daytoggle('w1p1');"><u><b><?=gettext("Mon");?></b></u></td>
846
									<td align="center" class="listhdrr" style="cursor: pointer;" onclick="daytoggle('w1p2');"><u><b><?=gettext("Tue");?></b></u></td>
847
									<td align="center" class="listhdrr" style="cursor: pointer;" onclick="daytoggle('w1p3');"><u><b><?=gettext("Wed");?></b></u></td>
848
									<td align="center" class="listhdrr" style="cursor: pointer;" onclick="daytoggle('w1p4');"><u><b><?=gettext("Thu");?></b></u></td>
849
									<td align="center" class="listhdrr" style="cursor: pointer;" onclick="daytoggle('w1p5');"><u><b><?=gettext("Fri");?></b></u></td>
850
									<td align="center" class="listhdrr" style="cursor: pointer;" onclick="daytoggle('w1p6');"><u><b><?=gettext("Sat");?></b></u></td>
851
									<td align="center" class="listhdrr" style="cursor: pointer;" onclick="daytoggle('w1p7');"><u><b><?=gettext("Sun");?></b></u></td>
852
								</tr>
853 615b27bc Scott Dale
								<?php			
854
								$firstmonth = FALSE;				
855 273c8b1c Scott Dale
								while ($daycounter<=$numberofdays){
856 6a6d2f63 Scott Dale
									$weekcounter =  date("W", mktime(0, 0, 0, date($monthcounter), date($daycounter), date($yearcounter)));
857
									$weekcounter = ltrim($weekcounter, "0");
858
									if ($positioncounter == 1)
859 615b27bc Scott Dale
									{
860
										echo "<tr>";
861
									}											
862 273c8b1c Scott Dale
									if ($firstdayofmonth == $positioncounter){?>
863 95f133d2 Colin Fleming
										<td align="center" style="cursor: pointer;" class="listr" id="w<?=$weekcounter;?>p<?=$positioncounter;?>" onclick="daytoggle('w<?=$weekcounter;?>p<?=$positioncounter;?>-m<?=$monthcounter;?>d<?=$daycounter;?>');">
864 615b27bc Scott Dale
										<?php echo $daycounter;
865
										$daycounter++;
866
										$firstdayprinted = TRUE;
867
										echo "</td>";
868
									}
869
									elseif ($firstdayprinted == TRUE && $daycounter <= $numberofdays){?>
870 95f133d2 Colin Fleming
										<td align="center" style="cursor: pointer;" class="listr" id="w<?=$weekcounter;?>p<?=$positioncounter;?>" onclick="daytoggle('w<?=$weekcounter;?>p<?=$positioncounter;?>-m<?=$monthcounter;?>d<?=$daycounter;?>');">
871 615b27bc Scott Dale
										<?php echo $daycounter;
872
										$daycounter++;
873
										echo "</td>";
874
									}
875
									else
876
									{
877 95f133d2 Colin Fleming
										echo "<td align=\"center\" class=\"listr\"></td>";
878 615b27bc Scott Dale
									}
879
									
880 242a9331 Colin Fleming
									if ($positioncounter == 7 || $daycounter > $numberofdays){
881 6a6d2f63 Scott Dale
										$positioncounter = 1;
882 615b27bc Scott Dale
										echo "</tr>";
883
									}
884
									else{
885 273c8b1c Scott Dale
										$positioncounter++;
886 6a6d2f63 Scott Dale
									}
887
								
888 273c8b1c Scott Dale
								}//end while loop?>	
889 95f133d2 Colin Fleming
							</table>
890 615b27bc Scott Dale
							</div>
891 273c8b1c Scott Dale
					<?php 
892
						
893
						if ($monthcounter == 12)
894
						{
895
							$monthcounter = 1;
896 6a6d2f63 Scott Dale
							$yearcounter++;
897 273c8b1c Scott Dale
						}
898
						else
899
						{
900
							$monthcounter++;
901
						}					
902
					} //end for loop
903 615b27bc Scott Dale
					?>
904
							<br/>
905 4f65a1d5 Vinicius Coque
					<?=gettext("Click individual date to select that date only. Click the appropriate weekday Header to select all occurences of that weekday.");?>
906 615b27bc Scott Dale
	                 </td>
907
				</tr>
908
				<tr>
909 5d8a530e Rafael Lucas
				  <td width="15%" valign="top" class="vncellreq"><?=gettext("Time");?></td>
910 615b27bc Scott Dale
				  <td width="85%" class="vtable">
911 34be89d1 Colin Fleming
				  	<table cellspacing="2" class="tabcont" summary="time">
912 615b27bc Scott Dale
				  		<tr>
913 5d8a530e Rafael Lucas
				  			<td class="listhdrr" align="center"><?=gettext("Start Time");?></td><td></td><td class="listhdrr" align="center"><?=gettext("Stop Time");?></td>
914 615b27bc Scott Dale
				  		</tr>
915
				  		<tr>
916
				  			<td>
917 b5c78501 Seth Mos
				  				<select name="starttimehour" class="formselect" id="starttimehour">
918 101fd849 Scott Dale
				  					<?php 
919
				  						for ($i=0; $i<24; $i++)
920
				  						{				  							
921
				  							echo "<option value=\"$i\">";
922
				  							echo $i;
923
				  							echo "</option>";
924
				  						}
925
				  					?>
926 64b919ef Carlos Eduardo Ramos
				  				</select>&nbsp;<?=gettext("Hr"); ?>&nbsp;&nbsp;
927 b5c78501 Seth Mos
				  				<select name="starttimemin" class="formselect" id="starttimemin">
928 b9f7b277 Scott Ullrich
				  					<option value="00">00</option>
929 101fd849 Scott Dale
				  					<option value="15">15</option>
930
				  					<option value="30">30</option>
931
				  					<option value="45">45</option>
932 ee3f99f1 Scott Ullrich
				  					<option value="59">59</option>
933 64b919ef Carlos Eduardo Ramos
				  				</select>&nbsp;<?=gettext("Min"); ?>
934 615b27bc Scott Dale
				  			</td>
935
				  			<td></td>
936
				  			<td>
937 b5c78501 Seth Mos
				  				<select name="stoptimehour" class="formselect" id="stoptimehour">
938 101fd849 Scott Dale
				  				<?php 
939
				  						for ($i=0; $i<24; $i++)
940
				  						{
941
				  							if ($i==23)
942 95f133d2 Colin Fleming
				  								$selected = "selected=\"selected\"";
943 101fd849 Scott Dale
				  							else
944
				  								$selected = "";
945
				  								
946
				  							echo "<option value=\"$i\" $selected>";
947
				  							echo $i;
948
				  							echo "</option>";
949
				  						}
950
				  					?>
951 4f65a1d5 Vinicius Coque
				  				</select>&nbsp;<?=gettext("Hr");?>&nbsp;&nbsp;
952 b5c78501 Seth Mos
				  				<select name="stoptimemin" class="formselect" id="stoptimemin">
953 2a113ca9 Scott Dale
				  					<option value="00">00</option>
954 101fd849 Scott Dale
				  					<option value="15">15</option>
955
				  					<option value="30">30</option>
956
				  					<option value="45">45</option>
957 95f133d2 Colin Fleming
				  					<option value="59" selected="selected">59</option>
958 4f65a1d5 Vinicius Coque
				  				</select>&nbsp;<?=gettext("Min");?>
959 615b27bc Scott Dale
				  			</td>
960
				  		</tr>
961 95f133d2 Colin Fleming
				  	</table><br/>
962 5d8a530e Rafael Lucas
                   <?=gettext("Select the time range for the day(s) selected on the Month(s) above. A full day is 0:00-23:59.")?>
963 615b27bc Scott Dale
					</td>
964
				</tr>
965
				<tr>
966 5d8a530e Rafael Lucas
					<td width="15%" valign="top" class="vncell"><?=gettext("Time Range Description")?></td>
967 95f133d2 Colin Fleming
					<td width="85%" class="vtable"><input name="timerangedescr" type="text" class="formfld unknown" id="timerangedescr" size="40" maxlength="40" /><br/>
968 615b27bc Scott Dale
 						<span class="vexpl">
969 5d8a530e Rafael Lucas
				        	<?=gettext("You may enter a description here for your reference (not parsed).")?>
970 615b27bc Scott Dale
				      	</span>     
971
				      </td>					
972
				</tr>
973
				<tr>
974
				  <td width="22%" valign="top">&nbsp;</td>
975
				  <td width="78%">
976 95f133d2 Colin Fleming
				  	<input type="button" value="<?=gettext("Add Time");?>"  class="formbtn"  onclick="javascript:processEntries();" />&nbsp;&nbsp;&nbsp;
977
				  	<input type="button" value="<?=gettext("Clear Selection");?>" class="formbtn" onclick="javascript:clearCalendar(); clearTime(); clearDescr();" />
978 615b27bc Scott Dale
                    </td>
979
				</tr>
980
				<tr>
981
				  <td width="15%" valign="top" class="vtable"></td>
982
				  <td width="85%" class="vtable">
983
                    </td>
984
				</tr>
985 3ea901d8 Scott Ullrich
				<tr>
986 5d8a530e Rafael Lucas
					<td colspan="2" valign="top" class="listtopic"><?=gettext("Schedule repeat");?></td>
987 3ea901d8 Scott Ullrich
				</tr>	
988 615b27bc Scott Dale
				<tr>
989 5d8a530e Rafael Lucas
					<td width="15%" valign="top" class="vncellreq"><?=gettext("Configured Ranges");?></td>
990 615b27bc Scott Dale
					<td width="85%">
991 34be89d1 Colin Fleming
						<table id="scheduletable" summary="range">
992 615b27bc Scott Dale
							<tbody>
993
								<tr>
994 95f133d2 Colin Fleming
									<td align="center" class="listbg" width="35%"><?=gettext("Day(s)");?></td>
995
									<td align="center" class="listbg" width="12%"><?=gettext("Start Time");?></td>
996
									<td align="center" class="listbg" width="11%"><?=gettext("Stop Time");?></td>
997
									<td align="center" class="listbg" width="42%"><?=gettext("Description");?></td>
998 615b27bc Scott Dale
								</tr>
999
								<?php
1000
								if ($getSchedule){
1001
									$counter = 0;
1002 273c8b1c Scott Dale
																		
1003
									foreach($pconfig['timerange'] as $timerange) {
1004 615b27bc Scott Dale
										$tempFriendlyTime = "";
1005 273c8b1c Scott Dale
										$tempID = "";
1006 615b27bc Scott Dale
										if ($timerange){
1007 273c8b1c Scott Dale
											$dayFriendly = "";
1008
											$tempFriendlyTime = "";
1009 2a113ca9 Scott Dale
											$timedescr = $timerange['rangedescr'];			
1010 273c8b1c Scott Dale
												
1011
											//get hours
1012
											$temptimerange = $timerange['hour'];
1013 615b27bc Scott Dale
											$temptimeseparator = strrpos($temptimerange, "-");
1014
											
1015
											$starttime = substr ($temptimerange, 0, $temptimeseparator); 
1016
											$stoptime = substr ($temptimerange, $temptimeseparator+1); 
1017 1a4f3123 Scott Dale
											$currentDay = "";
1018
											$firstDay = "";
1019
											$nextDay = "";
1020
											$foundEnd = false;
1021
											$firstDayFound = false;
1022
											$firstPrint = false;	
1023
											$firstprint2 = false;
1024
											
1025 273c8b1c Scott Dale
											if ($timerange['month']){
1026
												$tempmontharray = explode(",", $timerange['month']);
1027
												$tempdayarray = explode(",",$timerange['day']);
1028
												$arraycounter = 0;
1029
												foreach ($tempmontharray as $monthtmp){
1030
													$month = $tempmontharray[$arraycounter];
1031
													$day = $tempdayarray[$arraycounter];
1032
													$daypos = date("w", mktime(0, 0, 0, date($month), date($day), date("Y")));
1033 6a6d2f63 Scott Dale
													//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.
1034 1a4f3123 Scott Dale
													if ($daypos == 0){
1035
														$daypos = 7;
1036
													}									
1037 6a6d2f63 Scott Dale
													$weeknumber = date("W", mktime(0, 0, 0, date($month), date($day), date("Y")));
1038 1a4f3123 Scott Dale
													$weeknumber = ltrim($weeknumber, "0");		
1039
																										
1040 6a6d2f63 Scott Dale
													if ($firstPrint)
1041 273c8b1c Scott Dale
													{
1042
														$tempID .= ",";
1043 615b27bc Scott Dale
													}
1044 6a6d2f63 Scott Dale
													$tempID .= "w" . $weeknumber . "p" . $daypos . "-m" .  $month . "d" . $day;
1045
													$firstPrint = true;
1046 1a4f3123 Scott Dale
													
1047
													if (!$firstDayFound)
1048
													{
1049
														$firstDay = $day;
1050
														$firstmonth = $month;
1051
														$firstDayFound = true;
1052
													}
1053
														
1054
													$currentDay = $day;
1055
													$nextDay = $tempdayarray[$arraycounter+1];
1056
													$currentDay++;
1057
													if (($currentDay != $nextDay) || ($tempmontharray[$arraycounter] != $tempmontharray[$arraycounter+1])){
1058
														if ($firstprint2)
1059
															$tempFriendlyTime .= ", ";
1060
														$currentDay--;
1061
														if ($currentDay != $firstDay)
1062
															$tempFriendlyTime .= $monthArray[$firstmonth-1] . " " . $firstDay . " - " . $currentDay ;
1063
														else
1064
															$tempFriendlyTime .=  $monthArray[$month-1] . " " . $day;
1065
														$firstDayFound = false;	
1066
														$firstprint2 = true;
1067
													}													
1068
													$arraycounter++;			
1069
												}																						
1070
												
1071 615b27bc Scott Dale
											}
1072 273c8b1c Scott Dale
											else
1073
											{
1074 fdb29c8a Scott Dale
												$dayFriendly = $timerange['position'];
1075 273c8b1c Scott Dale
												$tempID = $dayFriendly;
1076
											}											
1077 615b27bc Scott Dale
											
1078 273c8b1c Scott Dale
											$tempTime = $tempID . "||" . $starttime . "-" . $stoptime . "||" . $timedescr;
1079
									
1080
											//following code makes the days friendly appearing, IE instead of Mon, Tues, Wed it will show Mon - Wed
1081
											$foundEnd = false;
1082
											$firstDayFound = false;
1083
											$firstprint = false;
1084
											$tempFriendlyDayArray = explode(",", $dayFriendly);
1085
											$currentDay = "";
1086
											$firstDay = "";
1087
											$nextDay = "";
1088
											$i = 0;
1089
											if (!$timerange['month']){										
1090 615b27bc Scott Dale
												foreach ($tempFriendlyDayArray as $day){
1091
													if ($day != ""){
1092
														if (!$firstDayFound)
1093
														{
1094
															$firstDay = $tempFriendlyDayArray[$i];
1095
															$firstDayFound = true;
1096
														}
1097
														$currentDay =$tempFriendlyDayArray[$i];
1098
														//get next day
1099
														$nextDay = $tempFriendlyDayArray[$i+1];
1100
														$currentDay++;					
1101
														if ($currentDay != $nextDay){
1102
															if ($firstprint)
1103
																$tempFriendlyTime .= ", ";
1104
															$currentDay--;
1105
															if ($currentDay != $firstDay)
1106 6a6d2f63 Scott Dale
																$tempFriendlyTime .= $dayArray[$firstDay-1] . " - " . $dayArray[$currentDay-1];
1107 615b27bc Scott Dale
															else
1108 6a6d2f63 Scott Dale
																$tempFriendlyTime .= $dayArray[$firstDay-1];
1109 615b27bc Scott Dale
															$firstDayFound = false;	
1110
															$firstprint = true;			
1111
														}
1112
														$i++;
1113
													}
1114 273c8b1c Scott Dale
												}		
1115
											}	
1116 615b27bc Scott Dale
												
1117
																																													
1118
									?>
1119
						          <tr>
1120
						          	<td>
1121 34be89d1 Colin Fleming
						          		<span class="vexpl"><?php echo $tempFriendlyTime; ?></span>
1122 615b27bc Scott Dale
						          	</td>
1123
									<td>
1124 34be89d1 Colin Fleming
						              <input type='text' readonly='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; ?>' />
1125 615b27bc Scott Dale
							        </td>
1126
						            <td>
1127 34be89d1 Colin Fleming
						              <input type='text' readonly='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; ?>' /> 
1128 615b27bc Scott Dale
							        </td>
1129
							        <td>
1130 34be89d1 Colin Fleming
							        	<input type='text' readonly='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; ?>' />
1131 615b27bc Scott Dale
							        </td>
1132
							        <td>
1133 34be89d1 Colin Fleming
							        	<a onclick='editRow("<?php echo $tempTime; ?>",this); return false;' href='#'><img border='0' src='/themes/<?php echo $g['theme']; ?>/images/icons/icon_e.gif' alt='edit' /></a>
1134 615b27bc Scott Dale
							        </td>
1135
							        <td>
1136 34be89d1 Colin Fleming
							        	<a onclick='removeRow(this); return false;' href='#'><img border='0' src='/themes/<?php echo $g['theme']; ?>/images/icons/icon_x.gif' alt='remove' /></a>
1137 615b27bc Scott Dale
							        </td>
1138
							        <td>
1139 95f133d2 Colin Fleming
							        	<input type='hidden' id='schedule<?php echo $counter; ?>' name='schedule<?php echo $counter; ?>' value='<?php echo $tempID; ?>' />
1140 615b27bc Scott Dale
							        </td>
1141
						          </tr>
1142
									<?php
1143
						        $counter++;
1144
									}//end if						
1145
						        } // end foreach	
1146
								}//end if							
1147
								?>
1148 95f133d2 Colin Fleming
							</tbody>	
1149 615b27bc Scott Dale
						</table>				
1150
					</td>
1151
				</tr>
1152
			 	<tr>
1153
				    <td width="15%" valign="top">&nbsp;</td>
1154
				    <td width="85%">
1155 64b919ef Carlos Eduardo Ramos
				      <input id="submit" name="submit" type="submit" onclick="return checkForRanges();" class="formbtn" value="<?=gettext("Save"); ?>" />
1156
				      <input id="cancelbutton" name="cancelbutton" type="button" class="formbtn" value="<?=gettext("Cancel"); ?>" onclick="history.back()" />
1157 615b27bc Scott Dale
				      <?php if (isset($id) && $a_schedules[$id]): ?>
1158 225a2f0b Scott Ullrich
				      <input name="id" type="hidden" value="<?=htmlspecialchars($id);?>" />
1159 615b27bc Scott Dale
				      <?php endif; ?>
1160
				    </td>
1161
			  	</tr>
1162
			 </table>
1163
		
1164
</td></tr></table></form>
1165
<?php include("fend.inc"); ?>
1166
</body>
1167 95f133d2 Colin Fleming
</html>