<?php

include "process.php";

function DisplayDetails () {
	
	global $self;

	global $DisplayOrder;
	global $TypeOrder;
	global $ListNOption;
	global $TopNOption;
	global $IPStatOption;
	global $IPStatOrder;
	global $LimitScale;
	global $WinSizeLabels;
	global $OutputFormatOption;

	$tright   = UNIX2DISPLAY($_SESSION['tright']);
	$tleft	  = UNIX2DISPLAY($_SESSION['tleft']);
	$profile  = $_SESSION['profile'];

	if ( !isset($_SESSION['channels'])  ) {
		$_SESSION['channels'] = array();
	}
	$channels = $_SESSION['channels'];

	if ( ! isset($_SESSION['proto']) ) 
		$_SESSION['proto'] = 'any';

	if ( ! isset($_SESSION['type']) ) 
		$_SESSION['type'] = 'flows';

	print "<h3>Profile: $profile</h3>\n";

	if ( ! isset($_SESSION['tend']) ) {
		$_SESSION['tend']   = $_SESSION['profileinfo']['tend'];
		$_SESSION['tstart'] = $_SESSION['tend'] - 86400;
		if ( $_SESSION['tstart'] < $_SESSION['profileinfo']['tstart'] )
			$_SESSION['tstart']   = $_SESSION['profileinfo']['start'];
		$_SESSION['tleft']  = ($_SESSION['tstart'] + $_SESSION['tend'])/2;
		$_SESSION['tright'] = $_SESSION['tleft'] + 300;
	}

	if ( ! isset($_SESSION['wsize']) ) 
		$_SESSION['wsize'] = 2;


	$_tmp = array();
	for ( $i=0; $i<count($channels); $i++ ) {
		if ( $_SESSION['src'][$i] == 1 ) 
			$_tmp[] = $channels[$i];
	}
	$_SESSION['graph_sources'] = count($_tmp) == 0 ? '@EMPTY' : implode(":", $_tmp);


?>
	<table style='font-size:14px;font-weight:bold'>
	<tr>
<?php
	for ( $i=1; $i < count($DisplayOrder); $i++ ) {
		$label = $DisplayOrder[$i];
		if ( $label == $_SESSION['proto'] )
			$label = 'any';

		print "<td>";
		print $label;
		print "</td>\n";
	}
	print "<td style='font-size:14px;font-weight:bold'>Profileinfo:</td>\n";	// Empty right element
	print "</tr><tr>\n";

	for ( $i=1; $i < count($DisplayOrder); $i++ ) {
		$label = $DisplayOrder[$i];
		if ( $label == $_SESSION['proto'] )
			$label = 'any';
		print "<td>\n";
		$arg = implode ( " ", array( $_SESSION['profile'], $_SESSION['graph_sources'], $label, 
			$_SESSION['type'], $_SESSION['profileinfo']['tstart'], $_SESSION['tstart'], 
			$_SESSION['tend'], $_SESSION['tleft'], $_SESSION['tright'], 288, 100, 1, 
			$_SESSION['logscale'], $_SESSION['linegraph']));
		$arg = urlencode($arg);
		print "<a href='$self?proto=$label'> " .  
			"<img src=rrdgraph.php?prog=0&arg=$arg border='0' width='165' height='81' alt='$label'></a>\n";
		print "</td>\n";
	}
	print "<td style='vertical-align: bottom;'>\n";
	$str = strftime("%b %d %Y - %H:%M", $_SESSION['profileinfo']['tstart']);

	$expire = $_SESSION['profileinfo']['expire'];
	if ( $expire == 0 ) {
		$expire = 'never';
	} else {
		$d = (int)($expire / 24 );
		$h = $expire % 24;
		$d_ext = $d == 1 ? '' : 's';
		$h_ext = $h == 1 ? '' : 's';
		if ( $d ) {
			$expire = "$d day${d_ext} $h hour{$h_ext}";
		} else {
			$expire = "$h hour${h_ext}";
		}
	}

	$maxsize = ScaleBytes($_SESSION['profileinfo']['maxsize'], 1);
	if ( $maxsize == 0 )
		$maxsize = 'unlimited';
	print "<table style='font-size:12px;font-weight:bold'>\n";
	$type = $_SESSION['refresh'] ? 'continuous' : 'history';
	print "<tr><td>Type:</td><td>$type</td></tr>";
	print "<tr><td>Max:</td><td>$maxsize</td></tr>";
	print "<tr><td>Exp:</td><td>$expire</td></tr>";
	print "<tr><td>Start:</td><td>$str</td></tr>\n";
	$str = strftime("%b %d %Y - %H:%M", $_SESSION['profileinfo']['tend']);
	print "<tr><td>End:</td><td>$str</td></tr>\n";
	print "</table>\n";

	print "</td>\n";

	$arg = implode ( " ", array( $_SESSION['profile'], $_SESSION['graph_sources'], 
			$_SESSION['proto'], $_SESSION['type'], $_SESSION['profileinfo']['tstart'], 
			$_SESSION['tstart'], $_SESSION['tend'], $_SESSION['tleft'], $_SESSION['tright'], 
			576, 200, 0, $_SESSION['logscale'], $_SESSION['linegraph']));
	$arg = urlencode($arg);

?>
	</tr>
	<tr>
		<td colspan='4'>
			<? print "<a href='$self?coord='> " .  "<img src=rrdgraph.php?prog=0&arg=$arg ISMAP border='0' alt='main-graph'></a>\n"; ?>
		</td>
		<td style="vertical-align: bottom;"> 
				<table style="margin-bottom:1pt">
				<tr>
					<td><span style='font-size:14px;font-weight:bold;margin-bottom:1pt'>
							t<SUB>start</SUB>
						</span>
					</td>
					<td>
						<form action="<? echo $self;?>" method="POST">
						<input type="text" name="tleft" value="<?echo $tleft; ?>" SIZE="16" MAXLENGTH="16" style='font-size:10px;'>
						</form>
					</td>
				</tr><tr>
					<td><span style='font-size:14px;font-weight:bold;margin-bottom:1pt'>
							t<SUB>end</SUB>
						</span>
					</td>
					<td>
						<form action="<? echo $self;?>" method="POST">
						<input type="text" name="tright" value="<?echo $tright; ?>" SIZE="16" MAXLENGTH="16" style='font-size:10px;'>
						</form>
					</td>
				</tr><tr><td></td>
					<td>
						<form action="<? echo $self;?>" method="POST">
						<input name="adjust" value="Reset Timeslot" type="submit" style='font-size:8px;'>
						</form>
					</td>
				</tr>
				</table>

		<table style='font-size:14px;font-weight:bold'>
<?php
	for ( $i=1; $i < count($TypeOrder); $i++ ) {
		$label = $TypeOrder[$i];
		if ( $label == $_SESSION['type'] )
			$label = 'flows';
		// Make first letter uppercase of label to print
		$printlabel = strtoupper($label[0]).substr($label,1);
		print "<tr><td>$printlabel</td></tr>\n";
		print "<tr><td>\n";
		$arg = implode ( " ", array( $_SESSION['profile'], $_SESSION['graph_sources'], 
				$_SESSION['proto'], $label, $_SESSION['profileinfo']['tstart'], 
				$_SESSION['tstart'], $_SESSION['tend'], $_SESSION['tleft'], 
				$_SESSION['tright'], 288, 100, 1, $_SESSION['logscale'], $_SESSION['linegraph']));
		$arg = urlencode($arg);
		print "<a href='$self?type=$label'> " .  "<img src=rrdgraph.php?prog=0&arg=$arg border='0' width='165' height='81' alt='$label'></a>";
		print "</td></tr>\n";
	}

?>
		</table>
		</td>
	</tr>
	<tr>

	<td colspan='4'>
		<table border="0" style='width: 100%;margin:0pt'>
		<tr>
		<td>
			<form action="<? echo $self;?>" method="POST">
			Select&nbsp;
			<select name='mselect' onchange='this.form.submit();' size=1>
<?php
			if ( array_key_exists('rightmark', $_SESSION ) && ($_SESSION['rightmark'] == 1) ) {
				print "<option value='0'>left\n";
				print "<option value='1' selected>right\n";
			} else {
				print "<option value='0' selected>left\n";
				print "<option value='1'>right\n";
			}
?>
			</select>&nbsp;Mark
			</form>
		</td>

		<td style="text-align: right;">
			<form action="<? echo $self;?>" method="POST">
			Display:&nbsp;
			<select name='wsize' onchange='this.form.submit();' size=1>
<?php
			for ( $i = 0; $i < count($WinSizeLabels); $i++ ) {
				if ( $i == $_SESSION['wsize'] )
					print "<option value='$i' selected>" . $WinSizeLabels[$i] . "\n";
				else
					print "<option value='$i'>" . $WinSizeLabels[$i] . "\n";
			}
			$status = $_SESSION['tright'] == $_SESSION['tleft'] ? '' : 'disabled';

?>
			</select>
			<input name="adjust" value="<<" type="submit">&nbsp;
			<input name="adjust" value="<" type="submit">&nbsp;
			<input name="adjust" value="|" type="submit">&nbsp;
			<input name="adjust" value="^" type="submit" <?echo $status; ?>>&nbsp;
			<input name="adjust" value=">" type="submit">&nbsp;
			<input name="adjust" value=">>" type="submit">&nbsp;
			<input name="adjust" value=">|" type="submit">
			</form>
		</td>
		</tr>
		</table>
	</td> <td>
		<form action="<? echo $self;?>" method="POST">
			<table>
			<tr>
				<td>
		<input type="radio" onClick='this.form.submit();' name="logscale" value="0"
		<? if ( $_SESSION['logscale'] == 0 ) print "checked"; ?> >Lin Scale
		<br>
		<input type="radio" onClick='this.form.submit();' name="logscale" value="1"
		<? if ( $_SESSION['logscale'] == 1 ) print "checked"; ?> >Log Scale

				</td>
				<td>
		<input type="radio" onClick='this.form.submit();' name="linegraph" value="0"
		<? if ( $_SESSION['linegraph'] == 0 ) print "checked"; ?> >Stacked Graph
		<br>
		<input type="radio" onClick='this.form.submit();' name="linegraph" value="1"
		<? if ( $_SESSION['linegraph'] == 1 ) print "checked"; ?> >Line Graph

				</td>
			</tr>
			</table>

		</form>
	</td>
	</tr><tr>
		<td colspan='4'></td>
		<td></td>
	</tr>
	</table>
<?php
	if ( $_SESSION['tleft'] == $_SESSION['tright'] ) {
		$tslot = "timeslot " . strftime("%b %d %Y - %H:%M", $_SESSION['tleft']);
	} else {
		$tslot = "timeslot " . strftime("%b %d %Y - %H:%M", $_SESSION['tleft']) . 
			" - " . strftime("%b %d %Y - %H:%M", $_SESSION['tright']);
	}
?>
	<br><b>Statistics <?echo $tslot;?></b>
	<form action="<? echo $self;?>" method="POST">
	<input type="hidden" name="srctrigger" value="src">
	<table style='font-size:14px;font-weight:bold'>
               <tr bgcolor='#6699cc' align='center'>
			<td>Source:</td>
			<td>Flows:</td>
                       <td colspan='5'>Packets:</td>
                       <td colspan='5'>Traffic:</td>
               </tr>
               <tr bgcolor='#dee7ec'>
                       <td>&nbsp;</td>
                       <td>&nbsp;</td>
                       <td>all:</td>
			<td>tcp:</td>
			<td>udp:</td>
			<td>icmp:</td>
			<td>other:</td>
                       <td>all:</td>
			<td>tcp:</td>
			<td>udp:</td>
			<td>icmp:</td>
			<td>other:</td>
		</tr>

<?php	
	# For easy testing, if a source is available in the current selected profile
	# create the tmp array _profilesources
	$_tmparray = explode(':', $_SESSION['profileinfo']['sourcelist']);
	foreach ( $_tmparray as $source ) {
		$_profilesources[$source] = 1;
	}

	for( $i=0; $i<count($channels); $i++ ) {
		$source = $channels[$i];
		print "<tr>\n";
		if ( !array_key_exists($source, $_profilesources ) ) {
			# source does not exists in profile
			print "<td align=left><input type='checkbox' name='$source' value='$source' disabled>$source &nbsp</td>\n";
			print "<td colspan='11' >Source not available in profile!</td>";

		} else {
			# source exists in profile
			$statinfo = ReadStat($source);
			$rateval = 1;
			if ( $_SESSION['ratescale'] == 1 ) {
				$rateval = $_SESSION['tright'] - $_SESSION['tleft'] + 300;
			}
			if ( $_SESSION['src'][$i] == 1 ) {
				print "<td align=left><input type='checkbox' name='$source' value='$source' onClick='this.form.submit();' checked>$source &nbsp</td>\n";
				$cellcolour = "bgcolor='#CCCCCC'";
			} else {
				print "<td align=left><input type='checkbox' name='$source' value='$source' onClick='this.form.submit();'>$source &nbsp</td>\n";
				$cellcolour = '';
			}
	
			if ( count($statinfo) > 0 ) {
				$_val = ScaleValue($statinfo[1], $rateval);
				print "<td $cellcolour align=right>$_val&nbsp;</td>";
				for ( $j=6; $j<16; $j++) {
					if ( $j < 11 ) {
						$_val = ScaleValue($statinfo[$j], $rateval);
						print "<td $cellcolour align=right>$_val&nbsp;</td>";
					} else {
						$traffic = ScaleBytes($statinfo[$j], $rateval);
						print "<td $cellcolour align=right>${traffic}&nbsp;</td>";
					}
				}
			} else {
				print "<td colspan='11' $cellcolour >No Data available!</td>";
			}
		}
		print "</tr>\n";
	}

?>		
		<tr><td>
		<INPUT TYPE="submit" NAME="MultipleSources" Value="All">
		<INPUT TYPE="submit" NAME="MultipleSources" Value="None">
		</td>
		<td colspan='11' style='text-align: right;'>
		Display:
		<input type="radio" onClick='this.form.submit();' name="ratescale" value="0"
		<? if ( $_SESSION['ratescale'] == 0 ) print "checked"; ?> >Sum
		<input type="radio" onClick='this.form.submit();' name="ratescale" value="1"
		<? if ( $_SESSION['ratescale'] == 1 ) print "checked"; ?> >Rate
		</td></tr>
<?php
	print "</table>\n";
	print "</form>\n";

?>
	<h3>Netflow Processing</h3>

<SCRIPT LANGUAGE="JavaScript">

function ClearForm (form) {
	form.filter.value        = "";
	form.aggregate.checked   = 0;
	form.timesorted.checked  = 0;
	form.longoutput1.checked = 0;
	form.listN.selectedIndex = 0;
<?php
	for($i=0; $i<count($channels); $i++ ) {
		print "form.SourceSelector.options[$i].selected = false;\n";
	}
?>
	form.topN.selectedIndex  	  = 0;
	form.limitoutput.checked      = 0;
	form.limitwhat.selectedIndex  = 0;
	form.limithow.selectedIndex   = 0;
	form.limitsize.value          = "0";
	form.limitscale.selectedIndex = 0;
	form.flowstat.checked     	  = 0;
	form.IPv6_long.checked 	  	  = 0;
	form.ipstat.checked 		  = 0;
	form.stattype.selectedIndex   = 0;
	// form.aggr_1.checked 		  = 1;
	// form.aggr_2.checked 		  = 1;
	// form.aggr_3.checked 		  = 1;
	// form.aggr_4.checked 		  = 1;

}

function SelectAllSources (form) {
<?php
	for($i=0; $i<count($channels); $i++ ) {
		print "form.SourceSelector.options[$i].selected = true;\n";
	}
?>

}
</SCRIPT>

<form action="<? echo $self;?>" method="POST">
<TABLE border="0" style='font-size:14px;font-weight:bold'>

<TR><!-- Row: 1 -->
	<TD>Source:</TD>
	<TD>Filter:</TD>
	<TD>Show:</TD>
</TR>

<TR><!-- Row: 2 -->
	<TD style='vertical-align:top;'>
		<SELECT name="srcselector[]" id=SourceSelector size="6" style="width: 100%" multiple>
<?php
				
			if ( array_key_exists('p_sources', $_SESSION ) ) {
				for($i=0; $i<count($channels); $i++ ) {
					$checked = $_SESSION['p_sources'][$i] == 1 ? 'selected' : '';
					if ( array_key_exists($channels[$i], $_profilesources ) )
						# add source only if it exists in the profile
						print "<OPTION value='$i' $checked>" . $channels[$i] . "</OPTION>";
				}
			} else {
				for($i=0; $i<count($channels); $i++ ) {
					if ( array_key_exists($channels[$i], $_profilesources ) )
						# add source only if it exists in the profile
						print "<OPTION value='$i'>" . $channels[$i] . "</OPTION>";
				}
			}
			
?>
		</SELECT><br>
		<INPUT TYPE="button" NAME="JSbutton2" Value="All Sources" onClick="SelectAllSources(this.form)">
	</TD>
	<TD style='vertical-align:top;'>
		<? $_tmp = array_key_exists('p_filter', $_SESSION) ? $_SESSION['p_filter'] : ''; ?>
		<TEXTAREA name="filter" rows="4" cols="50" wrap="virtual" ><?echo $_tmp;?></TEXTAREA><br>and
		<select name="defaultfilter" size="1">
<?php
			print "<option value='-1' label='none'>&lt;none&gt;</option>\n";
			if ( array_key_exists('defaultfilters', $_SESSION ) ) {
				if ( array_key_exists('p_defaultfilter', $_SESSION ) ) {
					for($i=0; $i<count($_SESSION['defaultfilters']); $i++ ) {
						$checked = $_SESSION['p_defaultfilter'] == $i ? 'selected' : '';
						print "<OPTION value='$i' $checked>" . $_SESSION['defaultfilters'][$i] . "</OPTION>";
					}
				} else {
					for($i=0; $i<count($_SESSION['defaultfilters']); $i++ ) {
						print "<OPTION value='$i' " . $_SESSION['defaultfilters'][$i] . "</OPTION>";
					}

				}
			}
?>
		</select>
	</TD>
	<TD style='vertical-align:top;'>
 		<table border='0'style='font-size:14px;font-weight:bold'>
			<tr>
				<td style='vertical-align:top;'>List: First</td>
				<td>
					<select name="listN" size="1">
<?php
					if ( array_key_exists('p_listN', $_SESSION ) ) {
						for($i=0; $i<count($ListNOption); $i++ ) {
							$checked = $_SESSION['p_listN'] == $i ? 'selected' : '';
							print "<OPTION value='$i' $checked>" . $ListNOption[$i] . "</OPTION>";
						}
					} else {
						for($i=0; $i<count($ListNOption); $i++ ) {
							print "<OPTION value='$i'>" . $ListNOption[$i] . "</OPTION>";
						}
					}
					$checked = array_key_exists('p_aggregate', $_SESSION ) && 
									$_SESSION['p_aggregate'] == 1 ?  'checked' : '';
?>
					</select> Flows<br>
					<input type="checkbox" name="aggregate" value="1" <?echo $checked;?>>&nbsp;aggregated.<br>
<?php
					$checked = array_key_exists('p_timesorted', $_SESSION ) && 
									$_SESSION['p_timesorted'] == 1 ?  'checked' : '';

?>
					<input type="checkbox" name="timesorted" value="1" <?echo $checked;?>>&nbsp;time sorted.<br>
					output format&nbsp;
<?php
					$format = array_key_exists('p_output_format1', $_SESSION ) &&
									$_SESSION['p_output_format1'] >= 0 && $_SESSION['p_output_format1'] < 3 ?
									$_SESSION['p_output_format1'] : 0;

					for($i=0; $i<count($OutputFormatOption); $i++ ) {
						if ( $i == $format ) 
							$checked = 'checked';
						else
							$checked = '';
						print "<input type='radio' name='output_format1' value='$i' $checked>" . $OutputFormatOption[$i] . "\n";
					}

					$checked = array_key_exists('p_IPv6_long1', $_SESSION ) && 
									$_SESSION['p_IPv6_long1'] == 1 ?  'checked' : '';

?>
					&nbsp;/&nbsp;<input type="checkbox" name="IPv6_long1" value="1" <?echo $checked;?>>&nbsp;IPv6 long&nbsp;<br>

				</td>
				<td style='vertical-align:bottom;'><input type="submit" name="dolist" value="process" size="1"></td>
			</tr>
			<tr>
				<td style='vertical-align:top;'>Stat: Top</td>
				<td> 
					<select name="topN" size="1">
<?php
					if ( array_key_exists('p_topN', $_SESSION ) ) {
						for($i=0; $i<count($TopNOption); $i++ ) {
							$checked = $_SESSION['p_topN'] == $i ? 'selected' : '';
							print "<OPTION value='$i' $checked>" . $TopNOption[$i] . "</OPTION>";
						}
					} else {
						for($i=0; $i<count($TopNOption); $i++ ) {
							print "<OPTION value='$i'>" . $TopNOption[$i] . "</OPTION>";
						}
					}
					$checked = array_key_exists('p_limitoutput', $_SESSION ) && 
									$_SESSION['p_limitoutput'] == 1 ?  'checked' : '';
?>
					</select><br>
<?php
/*
					Aggregate:
					<input type="checkbox" name="aggr_1" value="1" <?echo $checked;?>>&nbsp;SRC IP&nbsp;
					<input type="checkbox" name="aggr_2" value="1" <?echo $checked;?>>&nbsp;SRC Port&nbsp;
					<input type="checkbox" name="aggr_3" value="1" <?echo $checked;?>>&nbsp;DST IP&nbsp;
					<input type="checkbox" name="aggr_4" value="1" <?echo $checked;?>>&nbsp;DST Port&nbsp;
					<br>
*/
?>
					<input type="checkbox" name="limitoutput" value="1" size="1" <?echo $checked;?>>&nbsp;Limit&nbsp;
					<select name="limitwhat" size="1">
<?php
					if ( array_key_exists('p_limitwhat', $_SESSION ) ) {
						if ( $_SESSION['p_limitwhat'] == 0 ) {
							print "<OPTION value='0'>Packets</OPTION>\n";
							print "<OPTION value='1'>Traffic</OPTION>\n";
						} else {
							print "<OPTION value='0'>Packets</OPTION>\n";
							print "<OPTION value='1' selected>Traffic</OPTION>\n";
						}
					} else {
						print "<OPTION value='0'>Packets</OPTION>\n";
						print "<OPTION value='1'>Traffic</OPTION>\n";
					}
?>
					</select>
					<select name="limithow" size="1">
<?php
					if ( array_key_exists('p_limithow', $_SESSION ) ) {
						if ( $_SESSION['p_limithow'] == 0 ) {
							print "<OPTION value='0'>&gt;</OPTION>\n";
							print "<OPTION value='1'>&lt;</OPTION>\n";
						} else {
							print "<OPTION value='0'>&gt;</OPTION>\n";
							print "<OPTION value='1' selected>&lt;</OPTION>\n";
						}
					} else {
						print "<OPTION value='0'>&gt;</OPTION>\n";
						print "<OPTION value='1'>&lt;</OPTION>\n";
					}
?>
					</select>
<?php
					$_tmp = array_key_exists('p_limitsize', $_SESSION ) ? $_SESSION['p_limitsize'] : 0;
?>
					<input type="text" name="limitsize" value="<?echo $_tmp; ?>" SIZE="8" MAXLENGTH="8">
					<select name="limitscale" size="1">
<?php
					$_tmp = array_key_exists('p_limitscale', $_SESSION ) ? $_SESSION['p_limitscale'] : 0;
					for ( $i=0; $i<count($LimitScale); $i++ ) {
						$checked = $_tmp == $i ? 'selected' : '';
						print "<OPTION value='$i' $checked>$LimitScale[$i]</OPTION>\n";
					}
?>
					</select>
					<br>





<?php
					$checked = array_key_exists('p_flowstat', $_SESSION ) && 
									$_SESSION['p_flowstat'] == 1 ?  'checked' : '';
?>
					<input type="checkbox" name="flowstat" value="1" size="1" <?echo $checked;?>>&nbsp;Flows
<?php
					print "order by&nbsp;";
					print "<select name='floworder' size='1'>\n";
					if ( array_key_exists('p_floworder', $_SESSION ) ) {
						for($i=0; $i<count($IPStatOrder); $i++ ) {
							$checked = $_SESSION['p_floworder'] == $i ? 'selected' : '';
							print "<OPTION value='$i' $checked>" . $IPStatOrder[$i] . "</OPTION>";
						}
					} else {
						for($i=0; $i<count($IPStatOrder); $i++ ) {
							print "<OPTION value='$i'>" . $IPStatOrder[$i] . "</OPTION>";
						}
					}
?>
					</select>
					<br>

					output format&nbsp;
<?php					
					$format = array_key_exists('p_output_format2', $_SESSION ) &&
									$_SESSION['p_output_format2'] >= 0 && $_SESSION['p_output_format2'] < 3 ?
									$_SESSION['p_output_format2'] : 0;

					for($i=0; $i<count($OutputFormatOption); $i++ ) {
						if ( $i == $format ) 
							$checked = 'checked';
						else
							$checked = '';
						print "<input type='radio' name='output_format2' value='$i' $checked>" . $OutputFormatOption[$i] . "\n";
					}

					$checked = array_key_exists('p_IPv6_long2', $_SESSION ) && 
									$_SESSION['p_IPv6_long2'] == 1 ?  'checked' : '';

?>
					&nbsp;/&nbsp;<input type="checkbox" name="IPv6_long2" value="1" <?echo $checked;?>>&nbsp;IPv6 long&nbsp;<br>
<?php
					$checked = array_key_exists('p_ipstat', $_SESSION ) && 
									$_SESSION['p_ipstat'] == 1 ?  'checked' : '';
?>
					<input type="checkbox" name="ipstat" value="1" size="1" <?echo $checked;?>>
					<select name="stattype" size="1">
					<br>
<?php
					if ( array_key_exists('p_stattype', $_SESSION ) ) {
						for($i=0; $i<count($IPStatOption); $i++ ) {
							$checked = $_SESSION['p_stattype'] == $i ? 'selected' : '';
							print "<OPTION value='$i' $checked>" . $IPStatOption[$i] . "</OPTION>";
						}
					} else {
						for($i=0; $i<count($IPStatOption); $i++ ) {
							print "<OPTION value='$i'>" . $IPStatOption[$i] . "</OPTION>";
						}
					}
					print "</select>\n";
					print "order by&nbsp;";
					print "<select name='statorder' size='1'>\n";
					if ( array_key_exists('p_statorder', $_SESSION ) ) {
						for($i=0; $i<count($IPStatOrder); $i++ ) {
							$checked = $_SESSION['p_statorder'] == $i ? 'selected' : '';
							print "<OPTION value='$i' $checked>" . $IPStatOrder[$i] . "</OPTION>";
						}
					} else {
						for($i=0; $i<count($IPStatOrder); $i++ ) {
							print "<OPTION value='$i'>" . $IPStatOrder[$i] . "</OPTION>";
						}
					}
?>
					</select>
					<br>

				</td>
				<td style='vertical-align:bottom;'>
					<input type="submit" name="dostat" value="process" size="1" >
				</td>
			</tr>
			<tr>
				<td></td>
				<td></td>
				<td>
					<INPUT TYPE="button" NAME="JSbutton1" Value="Clear Form" onClick="ClearForm(this.form)">
				</td>
			</tr>
		</table>
 	</TD>
</TR>
</TABLE>
</form>

<?php

	if ( array_key_exists('process', $_SESSION ) ) {
		unset($_SESSION['process']);

		$run = CompileCommand();
		print "<pre>\n";
		// passthru($run, $ret);
		nfsend_query("nfdump args=$run", 1);
		print "</pre>\n";
	}

/*
	print "<pre>\n";
	print_r($_SESSION);
	print_r($_POST);
	print "</pre>\n";
*/
	return;

} # End of DisplayDetails

?>
