<?php
//Include the head file
require("../../inc/header.inc");
require("../generalCsta/function.inc");
?>

<script language="JavaScript">
function refresh_page()
{
	
	var sysTypeNo=document.myform.sysTypeNo.value;
	var down_date_from=document.myform.sel_date_from.value;
	var keyOne=document.myform.keyOne.value;	
	var keyTwo=document.myform.keyTwo.value;
	
	var urll='<?php echo"$PHP_SELF";?>?sysTypeNo='+sysTypeNo+'&sel_date_from='+down_date_from+'&keyOne='+keyOne+'&keyTwo='+keyTwo;
	window.location.href=urll;
}

function openFieldConf(sysTypeNo)
{
	URL="./csta_field.php?sysTypeNo="+sysTypeNo;
	var setWindow = open(URL, 'newWin', 'toolbar=no,directories=no,menubar=no,scrollbars=yes,resizable=yes,status=yes,width=400,height=350');
	setWindow.focus();
}
</script>

<base target="detail_csta_down">
<body leftmargin="15" rightmargin="10" onload="javascript:adjust_frame('up');" onresize="javascript:adjust_frame('up');" style="overflow:hidden;overflow-x:hidden;overflow-y:hidden;">
<form action="detail_csta_down.php" method="post" name="myform">

<?php
$sysTypeNo=$_REQUEST['sysTypeNo'];
$generalConf=parse_ini_file("general.conf",true);
$cstaConf=GetCstaConf($sysTypeNo);
if(0)
{
	echo "<pre>";
	print_r($generalConf);
	echo "</pre>";
}
	adjust_head_frame("up");
	adjust_title_head_frame("up");
	echo "<table id=\"table_up\" border=0 width=\"100%\">";
	echo "<tr>";
	echo "<td width=80% align=\"left\">";
	echo "{$generalConf[$sysTypeNo][PageTitle]}";
	echo "</td>";
	echo "<td align=\"right\">";
	if(isset($generalConf[HelpID][$sysTypeNo][$page_id]))
		showHelp($generalConf[HelpID][$sysTypeNo][$page_id]);
	echo "</td>";
	echo "</tr>";
	echo "<tr>";
	echo "<td align=\"left\">";
	
	//select day
	for($i=0;$i<$generalConf[MaxDay];$i++)
	{
		$startDay[]=date("Y-m-d",mktime(0,0,0,date("m"),date("d")-$i,date("Y")));
	}
	echo "Date <select name=\"sel_date_from\">";
	for($i=0;$i<$generalConf[MaxDay];$i++)
	{
		if($i==$sel_date_from)
			echo "<option selected value=$i>{$startDay[$i]}</option>";			
		else
			echo "<option value=$i>{$startDay[$i]}</option>";
	}
	echo "</select>&nbsp;";
	
	
	//KeyOne selection
	if(!isset($keyOne))
		$keyOne=-1;
	$keyonenum=sizeof($generalConf[KeyOneName][$sysTypeNo]);
	echo "Type <select name=\"keyOne\" onchange=\"javascript:refresh_page();\">";
	if($keyOne==-1)
		echo "<option selected value=\"-1\">All</option>";
	else
		echo "<option value=\"-1\">All</option>";
	for($i=0;$i<$keyonenum;$i++)
	{
		if(strcmp($generalConf[KeyOneName][$sysTypeNo][$i],"none"))
		{
			if($keyOne == $i)
				echo "<option selected value=\"$i\">{$generalConf[KeyOneName][$sysTypeNo][$i]}</option>";
			else
				echo "<option value=\"$i\">{$generalConf[KeyOneName][$sysTypeNo][$i]}</option>";
		}
	}
	echo "</select>&nbsp;";
	
	//KeyTwo selection
	if(!isset($keyTwo))
		$keyTwo=-1;
	$hideFlag=0;
	if($keyOne == -1)
	{
		$hideFlag=0;
	}
	else
	{
		for($i=0;$i<$cstaConf[DataObjectCount];$i++)
		{
			$doConf=$cstaConf[DataObject][$i];
			if($keyOne >= $doConf[KeyOneStart] && $keyOne <= $doConf[KeyOneEnd])
				break;
		}
	}
	if($i == $cstaConf[DataObjectCount])
		$hideFlag=1;
	else
	{
		if($doConf[KeyFieldCount] == 2)
			$hideFlag=0;
		else
			$hideFlag=1;
	}

	echo "<span ";
	if($hideFlag == 1)
		echo " style=\"display:none;\" ";
	echo ">";
	echo "TG <select name=\"keyTwo\">";
	if($keyTwo==-1)
		echo "<option selected value=\"-1\">All</option>";
	else
		echo "<option value=\"-1\">All</option>";
	if($hideFlag == 0)
	{
		for($i=$doConf[KeyTwoStart];$i<=$doConf[KeyTwoEnd];$i++)
		{
			if($keyTwo == $i)
				echo "<option selected value=\"$i\">{$i}</option>";
			else
				echo "<option value=\"$i\">{$i}</option>";
		}
	}
	echo "</select>&nbsp;";
	echo "</span>";
	
	if($hideFlag == 1)
		echo "<input type=\"hidden\" name=\"keyTwo\" value=\"-1\">";
	
	//search button
	echo "<span onClick=\"javascript:myform.submit()\" style=\"cursor:hand\">";
	echo "<IMG align=absBottom border=0 src=\"../../images/search.gif\">$strSearch";
	echo "</span>";

	echo "</td>";
	echo "<td align=\"right\">";
	
	//Config the field
	echo "<span onClick=\"javascript:openFieldConf('$sysTypeNo');\" style=\"cursor:hand\">";
	echo "<img  border=0 src=\"../../images/list.gif\" width=16 height=16>";
	echo "</span>&nbsp;&nbsp;&nbsp;&nbsp;";
	
	?>
<span onClick="window.print();" style="cursor:hand">
	<img  border=0 src="../../images/printer.gif" width="16" height="16">
</span>

<?php
		
	echo "</td>";
	echo "</tr>";
	echo "</table>";
	
	echo "<input type=\"hidden\" name=\"sysTypeNo\" value=\"$sysTypeNo\">";
	
	echo "</form>";
adjust_title_tail_frame("up");
adjust_content_head_frame("up");
adjust_content_tail_frame("up");

echo "</form>";
?>
