Project

General

Profile

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