Project

General

Profile

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