Project

General

Profile

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