Project

General

Profile

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