<?php
/*********************************************************      
 程序说明：         
    功能说明：本程序定义系统配置信息

    调用关系：调用:header.inc     
              被调用:      
 
    变量说明：

     返回值：无

 作者：   
      
修改注释：      
NO.1      
姓名        
时间
修改说明
*********************************************************/    
require("../../inc/header.inc");
?>
<body onload="javascript:adjust();" onresize="javascript:adjust();" leftmargin="15" style="overflow:hidden;overflow-x:hidden;overflow-y:hidden;">

<?php
adjust_head();
adjust_title_head();
echo "<table id=\"table_up\" border=\"0\" width=\"100%\">";
	echo "<tr>";
		echo "<td width=\"50%\">";
		echo "Template > CSTA Configuration";
		echo "</td>";
		echo "<td width=\"50%\" align=\"right\" title=\"Help\">";
		//showHelp($helpId);
		echo "</td>";
	echo "</tr>";
echo "</table>";
adjust_title_tail();
adjust_content_head();
echo "<br>";
$max_menu = 4;
$db=$csta_db;
$sysTypeNo=isset($sysTypeNo)?$sysTypeNo:'310';
$selObjIndex=isset($selObjIndex)?$selObjIndex:'new';
$sysType=omc_sys_code2type($sysTypeNo);
$detailTable=omc_table_name($sysType,'csta-q');
$sumTable=omc_table_name($sysType,'csta-h');


/**************************************删除一个系统类型***********************************************/
if($delete){
	$delSql = "DELETE FROM $cstadefine_table WHERE sysTypeNo='$sysTypeNo' AND objIndex='$selObjIndex'";
	$delRes = mysqli_query($pubConn,$delSql);
	//----------------
	//插入日志
	insertLog($delSql,0,6);
	//------------
	if($delRes){
		echo "<font color=\"#0000ff\">$strDeleteSuccess</font>";
     }else{
		echo "<font color=\"#ff0000\">$strDeleteFailure</font>";
     }
}//end if($delete) 


/*****************************添加,保存一个类型*****************************/
if($save){
	if($selObjIndex == 'new')//插入一个新配置
	{
		//判断新添加的配置是否存在
		$judIndexSql = " SELECT COUNT(*) FROM $cstadefine_table WHERE sysTypeNo='$sysTypeNo' AND objIndex ='$objIndex' ";
		$judIndexRes = @mysqli_query($pubConn,$judIndexSql);
		$judIndexRow = @mysqli_fetch_array($judIndexRes);
		echo mysqli_error($pubConn);
		if($judIndexRow[0])
		{
			echo "<br><font color=\"#FF0000\">Component always is existed!</font>";
			$noReplate='1';
		}
	}

	$replaceSql=" REPLACE INTO $cstadefine_table VALUES('$isEnable','$sysTypeNo','$objIndex','$oid','$useAgent','$detailTable','$sumTable','$hasSubSys','$sumUp','$checkTime','$isFullRow','$cstaType','$width','$id1Start','$id1End','$id1Offset','$id1Field','$id2Start','$id2End','$id2Offset','$id2Field','$mesField','$csvPath') ";
	echo "<br>replaceSql=$replaceSql";
	if(!$noReplate)
	{
		$errorstr=mysqli_error($pubConn);
		$replaceRes = @mysqli_query($pubConn,$replaceSql);
		echo "save failed, $errorstr"; //mysqli_error($pubConn);
		$selObjIndex=$objIndex;
	}
	//------------插入日志------------
	insertLog($replaceSql,0,6);
	//------------
	if($replaceRes > 0){
		echo "<br><font color=\"#0000ff\" >$strSaveSuccess</font>";
    }else{
		echo "<br><font color=\"#ff0000\">$strSaveFailure</font>";
    }
} //end if($save) 
?>


<script LANGUAGE="JavaScript">  
function selType()      
 {      
    var base_url,sysTypeNo,url;      
    base_url='<?php echo"$PHP_SELF";?>?sysTypeNo=';
    sysTypeNo=document.selectform.sysTypeNo.value;   
    url=base_url+sysTypeNo;
    window.location=url;      
 }      

function selIndex()      
 {      
    var base_url,sysTypeNo,selObjIndex,url;      
    base_url='<?php echo"$PHP_SELF";?>?sysTypeNo=';
    sysTypeNo=document.selectform.sysTypeNo.value;   
	selObjIndex=document.selectform.selObjIndex.value;
    url=base_url+sysTypeNo+"&selObjIndex="+selObjIndex;
    window.location=url;      
 }   
 
function hideIt(term, thisCk)
{
	var flag;
	if(thisCk.checked==true)
		flag=1;
	else
		flag=0;
	whichEl = document.getElementById(term);
	if(flag==1)
		whichEl.style.display = "";
	if(flag==0)
		whichEl.style.display = "none";
}   
</script>
<?php 
//echo "\n<script language=\"javascript\" src=\"../../inc/expand.js\" > </script>";  
?>
<form method="POST" name=selectform action="<?php echo"$PHP_SELF";?>" >
  <table  border="1" width="100%" cellpadding="2" cellspacing="0"  bordercolor="#666666" bordercolordark="#FFFFFF" bgcolor="#FFFFFF" > 
<?php  
echo "<tr bgcolor=\"#E6E6E6\">";    
echo "<td width=\"100%\" colspan=\"2\">";
echo "<p align=\"center\"><b>$strCSTAConfiguration</b></p></td></tr>";
echo "<tr>";    
echo "<td width=\"20%\">$strSystemType</td>";
echo "<td width=\"80%\">";


$typeSql		= " SELECT sysTypeNo,sysTypeName FROM $sysconf_table WHERE needCSTA = '1' OR needFlow =
					'1' ORDER BY sysTypeNo ";
$typeRes		= @mysqli_query($pubConn,$typeSql);
$typeRow		= @mysqli_fetch_array($typeRes);
echo mysqli_error($pubConn);

$indexSql		= " SELECT * FROM $cstadefine_table WHERE sysTypeNo = '$sysTypeNo' ORDER BY objIndex ";
$indexRes		= @mysqli_query($pubConn,$indexSql);
$indexRow		= @mysqli_fetch_array($indexRes);
echo mysqli_error($pubConn);

if($selObjIndex!='new')
{
	$confSql		= " SELECT * FROM $cstadefine_table WHERE sysTypeNo = '$sysTypeNo' AND objIndex = '$selObjIndex'";
	$confRes		= @mysqli_query($pubConn,$confSql);
	$confRow		= @mysqli_fetch_array($confRes);
	echo mysqli_error($pubConn);
	$objIndex		= $confRow[objIndex];
	$oid			= $confRow[oid];
	$csvPath		= $confRow[csvPath];
	$isEnable		= $confRow[isEnable];
	$useAgent		= $confRow[useAgent];
	$hasSubSys 		= $confRow[hasSubSys];
	$sumUp 			= $confRow[sumUp];
	$checkTime 		= $confRow[checkTime];
	$isFullRow  	= $confRow[isFullRow];
	$cstaType 		= $confRow[cstaType];
	$width			= $confRow[width];
	$id1Start 		= $confRow[id1Start];
	$id1End 		= $confRow[id1End];
	$id1Offset 		= $confRow[id1Offset];
	$id1Field 		= $confRow[id1Field];
	$id2Start 		= $confRow[id2Start];
	$id2End 		= $confRow[id2End];
	$id2Offset 		= $confRow[id2Offset];
	$id2Field 		= $confRow[id2Field];
	$mesField  		= $confRow[fieldList];
}

echo "<select size=\"1\" name=\"sysTypeNo\" onChange=\"javascript:selType()\">";
do
{
	if($sysTypeNo == $typeRow[sysTypeNo])
		echo "<option value=\"$typeRow[sysTypeNo]\" selected>$typeRow[sysTypeName]</option>";
	else
		echo "<option value=\"$typeRow[sysTypeNo]\">$typeRow[sysTypeName]</option>";
}while($typeRow = @mysqli_fetch_array($typeRes));
echo "</select></td></tr>";

echo "<tr>";    
echo "<td width=\"20%\">$strExistedIndex</td>";
echo "<td width=\"80%\">";
echo "<select size=\"1\" name=\"selObjIndex\" onChange=\"javascript:selIndex()\">";
echo "<option value='new'>NEW</option>";
do
{
	if($selObjIndex == $indexRow[objIndex] && isset($indexRow[objIndex]))
		echo "<option value=\"$indexRow[objIndex]\" selected>$indexRow[objIndex]</option>";
	elseif(isset($indexRow[objIndex]))
		echo "<option value=\"$indexRow[objIndex]\">$indexRow[objIndex]</option>";
}while($indexRow = @mysqli_fetch_array($indexRes));
echo "</select></td></tr>";

echo "<tr bgcolor=\"#E6E6E6\">";
echo "<td width=\"20%\">Index</td>";
echo "<td width=\"80%\">";
echo "<select name=\"objIndex\">";
for($i=0;$i<10;$i++)
{
	if($i==$objIndex){
		echo "<option value=\"$i\" selected>$i</option>";
	}else{
		echo "<option value=\"$i\">$i</option>";
	}
}
echo "</select>";
echo "</td>";
echo "</tr>";

echo "<tr bgcolor=\"#E6E6E6\">";
echo "<td width=\"20%\">OID</td>";
echo "<td width=\"80%\">";
echo "<input type=text size=\"40\" name=\"oid\" value=\"$oid\">";
echo "</td>";
echo "</tr>";    

echo "<tr bgcolor=\"#E6E6E6\">";
echo "<td width=\"20%\">CSV path</td>";
echo "<td width=\"80%\">";
echo "<input type=text size=\"40\" name=\"csvPath\" value=\"$csvPath\">";
echo "</td>";
echo "</tr>";    

echo "<tr>";    
echo "<td width=\"20%\">$strEnable </td>";
echo "<td width=\"80%\">";
if($isEnable==1)
{
     echo "Yes<input type=radio value=\"1\" name=\"isEnable\" checked> ";
     echo "No<input type=radio value=\"0\" name=\"isEnable\">";
}
else
{
     echo "Yes<input type=radio value=\"1\" name=\"isEnable\"> ";
     echo "No<input type=radio value=\"0\" name=\"isEnable\" checked>";
}
echo "</td>";
echo "</tr>";    

echo "<tr>";    
echo "<td width=\"20%\">$strUseAgent </td>";
echo "<td width=\"80%\">";
if($useAgent==1)
{
     echo "Yes<input type=radio value=\"1\" name=\"useAgent\" checked> ";
     echo "No<input type=radio value=\"0\" name=\"useAgent\">";
}
else
{
     echo "Yes<input type=radio value=\"1\" name=\"useAgent\"> ";
     echo "No<input type=radio value=\"0\" name=\"useAgent\" checked>";
}
echo "</td>";
echo "</tr>";    


echo "<tr>";    
echo "<td width=\"20%\">$strHasSubSys</td>";
echo "<td width=\"80%\">";
if($hasSubSys==1)
{
     echo "Yes<input type=radio value=\"1\" name=\"hasSubSys\" checked> ";
     echo "No<input type=radio value=\"0\" name=\"hasSubSys\">";
}
else
{
     echo "Yes<input type=radio value=\"1\" name=\"hasSubSys\"> ";
     echo "No<input type=radio value=\"0\" name=\"hasSubSys\" checked>";
}
echo "</td>";
echo "</tr>";    

echo "<tr>";
echo "<td width=\"20%\">$strNeedSumUp</td>";
echo "<td width=\"80%\">";
if($sumUp==1)
{
     echo "Yes<input type=radio value=\"1\" name=\"sumUp\" checked> ";
     echo "No<input type=radio value=\"0\" name=\"sumUp\">";
}
else
{
     echo "Yes<input type=radio value=\"1\" name=\"sumUp\"> ";
     echo "No<input type=radio value=\"0\" name=\"sumUp\" checked>";
}
echo "</td>";
echo "</tr>";    

echo "<tr>";
echo "<td width=\"20%\">$strNeedCheckTime</td>";
echo "<td width=\"80%\">";
if($checkTime==1)
{
     echo "Yes<input type=radio value=\"1\" name=\"checkTime\" checked> ";
     echo "No<input type=radio value=\"0\" name=\"checkTime\">";
}
else
{
     echo "Yes<input type=radio value=\"1\" name=\"checkTime\"> ";
     echo "No<input type=radio value=\"0\" name=\"checkTime\" checked>";
}
echo "</td>";
echo "</tr>";    

echo "<tr>";
echo "<td width=\"20%\">$strIsFullRow</td>";
echo "<td width=\"80%\">";
if($isFullRow==1)
{
     echo "Yes<input type=radio value=\"1\" name=\"isFullRow\" checked> ";
     echo "No<input type=radio value=\"0\" name=\"isFullRow\">";
}
else
{
     echo "Yes<input type=radio value=\"1\" name=\"isFullRow\"> ";
     echo "No<input type=radio value=\"0\" name=\"isFullRow\" checked>";
}
echo "</td>";
echo "</tr>";    

echo "<tr bgcolor=\"#E6E6E6\">";
echo "<td width=\"20%\">$strCSTAType</td>";
echo "<td width=\"80%\">";
echo "<select name=\"cstaType\">";
if($cstaType==0)
{
	echo "<option value=\"0\" selected>$strIDFixedness</option>";
	echo "<option value=\"1\">$strOneIDChange</option>";
	echo "<option value=\"2\">$strTwoIDChange</option>";
}
elseif($cstaType==1)
{
	echo "<option value=\"0\">$strIDFixedness</option>";
	echo "<option value=\"1\" selected>$strOneIDChange</option>";
	echo "<option value=\"2\">$strTwoIDChange</option>";
}
else
{
	echo "<option value=\"0\">$strIDFixedness</option>";
	echo "<option value=\"1\">$strOneIDChange</option>";
	echo "<option value=\"2\" selected>$strTwoIDChange</option>";
}
echo "</select>";
echo "</td>";
echo "</tr>";    

echo "<tr bgcolor=\"#E6E6E6\">";
echo "<td width=\"20%\">$strWidth</td>";
echo "<td width=\"80%\">";
echo "<select name=\"width\">";
if($width==4)
{
	echo "<option value=\"2\">2</option>";
	echo "<option value=\"4\" selected>4</option>";
}
else
{	
	echo "<option value=\"2\" selected>2</option>";
	echo "<option value=\"4\">4</option>";
}
echo "</select>";
echo "</td>";
echo "</tr>";    

echo "<tr>";
echo "<td width=\"20%\">$strID1StartNum</td>";
echo "<td width=\"80%\">";
echo "<select name=\"id1Start\">";
for($i=0;$i<257;$i++)
{
	if($id1Start==$i){
		echo "<option value=\"$i\" selected>$i</option>";
	}else{
		echo "<option value=\"$i\">$i</option>";
	}
}
echo "</select>";
echo "</td>";
echo "</tr>";    

echo "<tr>";    
echo "<td width=\"20%\">$strID1EndNum</td>";
echo "<td width=\"80%\">";
echo "<select name=\"id1End\">";
for($i=0;$i<257;$i++)
{
	if($id1End==$i){
		echo "<option value=\"$i\" selected>$i</option>";
	}else{
		echo "<option value=\"$i\">$i</option>";
	}
}
echo "</select>";
echo "</td>";
echo "</tr>";    

echo "<tr>";
echo "<td width=\"20%\">$strID1Offset</td>";
echo "<td width=\"80%\">";
echo "<select name=\"id1Offset\">";
for($i=-50;$i<50;$i++)
{
	if($id1Offset==$i){
		echo "<option value=\"$i\" selected>$i</option>";
	}else{
		echo "<option value=\"$i\">$i</option>";
	}
}
echo "</select>";
echo "</td>";
echo "</tr>";    

echo "<tr>";    
echo "<td width=\"20%\">$strID1Field</td>";
echo "<td width=\"80%\">";
echo "<select name=\"id1Field\">";
echo "<option value=\"\">--</option>";
$fieldList = mysql_list_fields($db,$detailTable);
$fieldsNum = @mysql_num_fields($fieldList);
echo mysqli_error($pubConn);
for($i=0; $i<$fieldsNum; $i++){
	$FieldName = @mysql_field_name($fieldList, $i);
	echo mysqli_error($pubConn);
	if($id1Field == $FieldName){
		echo "<option value=\"$FieldName\" selected>$FieldName</option>";
	}else{
		echo "<option value=\"$FieldName\" >$FieldName</option>";
	}
}
echo "</select>";
echo "</td>";
echo "</tr>";    

echo "<tr bgcolor=\"#E6E6E6\">";
echo "<td width=\"20%\">$strID2StartNum</td>";
echo "<td width=\"80%\">";
echo "<select name=\"id2Start\">";
for($i=0;$i<257;$i++)
{
	if($id2Start==$i){
		echo "<option value=\"$i\" selected>$i</option>";
	}else{
		echo "<option value=\"$i\">$i</option>";
	}
}
echo "</select>";
echo "</td>";
echo "</tr>";    

echo "<tr bgcolor=\"#E6E6E6\">";
echo "<td width=\"20%\">$strID2EndNum</td>";
echo "<td width=\"80%\">";
echo "<select name=\"id2End\">";
for($i=0;$i<257;$i++)
{
	if($id2End==$i){
		echo "<option value=\"$i\" selected>$i</option>";
	}else{
		echo "<option value=\"$i\">$i</option>";
	}
}
echo "</select>";
echo "</td>";
echo "</tr>";    

echo "<tr bgcolor=\"#E6E6E6\">";
echo "<td width=\"20%\">$strID2Offset</td>";
echo "<td width=\"80%\">";
echo "<select name=\"id2Offset\">";
for($i=-50;$i<50;$i++)
{
	if($id2Offset==$i){
		echo "<option value=\"$i\" selected>$i</option>";
	}else{
		echo "<option value=\"$i\">$i</option>";
	}
}
echo "</select>";
echo "</td>";
echo "</tr>";    

echo "<tr bgcolor=\"#E6E6E6\">";
echo "<td width=\"20%\">$strID2Field</td>";
echo "<td width=\"80%\">";
echo "<select name=\"id2Field\">";
echo "<option value=\"\">--</option>";
$fieldList = mysql_list_fields($db,$detailTable);
$fieldsNum = @mysql_num_fields($fieldList);
echo mysqli_error($pubConn);
$allField='';
for($i=0; $i<$fieldsNum; $i++){
	$FieldName = @mysql_field_name($fieldList, $i);
	if($i==0){
		$allField=$FieldName;
	}else{
		$allField=$allField.",".$FieldName;
	}
	echo mysqli_error($pubConn);
	if($id2Field == $FieldName){
		echo "<option value=\"$FieldName\" selected>$FieldName</option>";
	}else{
		echo "<option value=\"$FieldName\" >$FieldName</option>";
	}
}
echo "</select>";
echo "</td>";
echo "</tr>";


echo "<tr>";
echo "<td width=\"20%\">$strMessageField</td>";
echo "<td width=\"80%\">";
echo "<textarea rows=\"5\" cols=\"45\" name=\"mesField\">$mesField</textarea>";
echo "<input type=\"checkbox\" name=\"showField\" value=\"ON\" onclick=\"hideIt('KB1Child',this);\">";
echo "$strFieldList";
echo "</td>";
echo "</tr>";
echo "</table>";

echo "<DIV class=child id=KB1Child style=\"display:none\">";
echo "<table  border=\"1\" width=\"100%\" cellpadding=\"2\" cellspacing=\"0\"  bordercolor=\"#666666\" bordercolordark=\"#FFFFFF\" bgcolor=\"#FFFFFF\">";
echo "<tr bgcolor=\"#E6E6E6\">";
echo "<td width=\"20%\">$strFieldList</td>";
echo "<td width=\"80%\">";
echo "<textarea rows=\"5\" cols=\"45\" name=\"fieldList\">$allField</textarea>";
echo "</td>";
echo "</tr>";
echo "</table>";
echo "</DIV>";
?>
<p><input type="submit" value="<?php echo "$strSave"; ?>" name="save"> 
<input type="reset" value="<?php echo "$strCancel"; ?>" name="reset"> 
<input type="submit" value="<?php echo "$strDeleteMode"; ?>" name="delete">
</p>                
</form>
<?php
adjust_content_tail();     
?>
</body>                
</html>

