<?php
/*********************************************************      
 程序说明：         
    功能说明：cns configuration

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

     返回值：无

 作者：  
      
修改注释：      
NO.1      
姓名：            
时间：      
修改说明：      
*********************************************************/  
require("../../inc/header.inc");
$DEBUG = 0;
//echo "<br>mode=$mode";
$dbName = "OMC_PUB";
$tbName = "centralMapInfo";

$objTypeArr=array(
			array('num' => '0',  'remark' => 'Line',		'color' => '#FF0000'),
			array('num' => '1',  'remark' => 'Level_1',		'color' => '#FF0000'),
			array('num' => '2',  'remark' => 'Level_2',		'color' => '#0000FF'),
			array('num' => '3',  'remark' => 'Level_3',		'color' => '#0000FF'),
);

if($save){
	if($mode == 'addNode' || $mode == 'addEdge'){
		$udtSql = " REPLACE $tbName SET keyName = '$keyName', ip = '$ip', objTypeNo = '$objTypeNo',  fromNodeNo = '$fromNodeNo', toNodeNo = '$toNodeNo', pointX = '$pointX', pointY = '$pointY', remark = '$remark', keyNo = '$keyNo'";
	}else{
		$udtSql = " UPDATE $tbName SET keyName = '$keyName', ip = '$ip', objTypeNo = '$objTypeNo',  fromNodeNo = '$fromNodeNo', toNodeNo = '$toNodeNo', pointX = '$pointX', pointY = '$pointY', remark = '$remark'  WHERE keyNo = '$keyNo'";
	}
	//echo "<br>udtSql=$udtSql";
	$udtRes = mysqli_query($pubConn, $udtSql);
	if($udtRes){
		echo "<br>Save ok.";
	}else{
		echo "<br>Save failure.";
	}
}elseif($delete){
	$delSql = " DELETE FROM $tbName WHERE keyNo = '$keyNo' ";
	$delRes = mysqli_query($pubConn, $delSql);
	if($delRes){
		echo "<br>Delete ok.";
	}else{
		echo "<br>Delete failure.";
	}
}

if($mode == 'addNode' || $mode == 'addEdge'){
	$allSql = "SELECT keyNo FROM $tbName ";
	$allRes = @mysqli_query($pubConn, $allSql);
	$allRow = @mysqli_fetch_array($allRes);
	$keyNum = 0;
	do{
		$keyArr[$keyNum] = $allRow[keyNo];
		$keyNum++;
	}while($allRow = @mysqli_fetch_array($allRes));
}

if($mode == 'addEdge' || $mode == 'editEdge'){
	$nodeSql = "SELECT keyNo,keyName FROM $tbName WHERE objTypeNo  > 0 ";
	if($DEBUG) echo "<br>nodeSql=$nodeSql";
	$nodeRes = mysqli_query($pubConn,$nodeSql);
	$nodeRow = mysqli_fetch_array($nodeRes);
	$nodeNum = 0;
	do{
		$nodeArr[$nodeNum][0] = $nodeRow[keyNo];
		$nodeArr[$nodeNum][1] = $nodeRow[keyName];
		$nodeNum++;
	}mysqli_fetch_array(
while($nodeRow = mysql_fetch_array($nodeRes));
}

if($mode == 'editNode' || $mode == 'editEdge'){
	$selSql = "SELECT keyName,ip,status,objTypeNo,fromNodeNo,toNodeNo,pointX,pointY,remark FROM $tbName WHERE keyNo = '$keyNo' ";
	$selRes = mysqli_fetch_array(Name,$selSql);
	$selRow = mysql_fetch_array($selRes);
	if($DEBUG) echo "<br>selSql=$selSql";
	$keyName = $selRow[keyName];
	$ip = $selRow[ip];
	$status = $selRow[status];
	$objTypeNo = $selRow[objTypeNo];
	$fromNodeNo = $selRow[fromNodeNo];
	$toNodeNo = $selRow[toNodeNo];
	$pointX = $selRow[pointX];
	$pointY = $selRow[pointY];
	$remark = $selRow[remark];
}
?>
<form method="POST" name=confForm action="<?php echo"$PHP_SELF";?>" >
<?php
$tableHeader="<table  border=\"1\" width=\"600\" cellpadding=\"2\" cellspacing=\"0\"  bordercolor=\"#666666\" bordercolordark=\"#FFFFFF\" bgcolor=\"#FFFFFF\" > ";
echo "$tableHeader";
?>

 <tr>    
	<td width="100%" colspan="2" align="left" height="18">
		<font size=3><b><?php echo "CNS Information"; ?></b></font>
	</td>
  </tr>

<?php
echo "<tr height=\"18\">";
echo "<td  width=\"20%\" bgcolor=#E6E6E6>keyNo</td>";
if($mode == 'addNode' || $mode == 'addEdge'){
	echo "<td  width=\"80%\">";
	echo "<select style=\"font-family: Verdana; font-size: 8pt\" size=\"1\" name=\"keyNo\" id=\"keyNo\">";
	for($i=1;$i<100;$i++){
		$doFlag = 0;
		for($j=0;$j<$keyNum;$j++){
			echo "<br>$i == $keyArr[$j]";
			if($i == $keyArr[$j]){
				$doFlag = 1;
				break;
			}
		}
		if(!$doFlag){
			echo "<option value=\"$i\">$i</option>";
		}
	}
	echo "</select>";
	echo "</td>";
}else{
	echo "<td  width=\"80%\">$keyNo&nbsp;</td>";
}
echo "</tr>";

echo "<tr height=\"18\">";
echo "<td  width=\"20%\" bgcolor=#E6E6E6>keyName</td>";
echo "<td  width=\"80%\"><input type=\"input\" size=\"10\" name=\"keyName\" value=\"$keyName\"></td>";
echo "</tr>";

echo "<tr height=\"18\">";
echo "<td  width=\"20%\" bgcolor=#E6E6E6>IP</td>";
echo "<td  width=\"80%\"><input type=\"input\" size=\"10\" name=\"ip\" value=\"$ip\"></td>";
echo "</tr>";

if($mode == 'addNode' || $mode == 'editNode'){
	echo "<tr height=\"18\">";
	echo "<td  width=\"20%\" bgcolor=#E6E6E6>objTypeNo</td>";
	echo "<td  width=\"80%\">";
	echo "<select style=\"font-family: Verdana; font-size: 8pt\" size=\"1\" name=\"objTypeNo\" id=\"objTypeNo\">";
	for($i=1;$i<4;$i++)
	{
		if($objTypeNo == $i)
			echo "<option value=\"$i\" selected>{$objTypeArr[$i][remark]}</option>";
			else
			echo "<option value=\"$i\">{$objTypeArr[$i][remark]}</option>";
	}
	echo "</select>";
	//<input type=\"input\" size=\"10\" value=\"$objTypeNo\">
	echo "</td>";
	echo "</tr>";
}else{
	//echo "<input type=\"hidden\" name=\"objTypeNo\" value=\"$keyNo\">";
}

if($mode == 'addNode' || $mode == 'editNode'){
	echo "<tr height=\"18\">";
	echo "<td  width=\"20%\" bgcolor=#E6E6E6>pointX</td>";
	echo "<td  width=\"80%\"><input type=\"input\" size=\"10\" name=\"pointX\"  value=\"$pointX\"></td>";
	echo "</tr>";
	
	echo "<tr height=\"18\">";
	echo "<td  width=\"20%\" bgcolor=#E6E6E6>pointY</td>";
	echo "<td  width=\"80%\"><input type=\"input\" size=\"10\" name=\"pointY\"  value=\"$pointY\"></td>";
	echo "</tr>";
}else{

	echo "<tr height=\"18\">";
	echo "<td  width=\"20%\" bgcolor=#E6E6E6>fromNodeNo</td>";
	echo "<td  width=\"80%\">";
	echo "<select style=\"font-family: Verdana; font-size: 8pt\" size=\"1\" name=\"fromNodeNo\" id=\"fromNodeNo\">";
	for($i=0;$i<$nodeNum;$i++){
		if($fromNodeNo == $nodeArr[$i][0]){
			echo "<option value=\"{$nodeArr[$i][0]}\" selected>{$nodeArr[$i][1]}</option>";
		}else{
			echo "<option value=\"{$nodeArr[$i][0]}\">{$nodeArr[$i][1]}</option>";
		}
	}
	echo "</select>";
	echo "</td>";
	echo "</tr>";

	echo "<tr height=\"18\">";
	echo "<td  width=\"20%\" bgcolor=#E6E6E6>toNodeNo</td>";
	echo "<td  width=\"80%\">";
	echo "<select style=\"font-family: Verdana; font-size: 8pt\" size=\"1\" name=\"toNodeNo\" id=\"toNodeNo\">";
	for($i=0;$i<$nodeNum;$i++){
		if($toNodeNo == $nodeArr[$i][0]){
			echo "<option value=\"{$nodeArr[$i][0]}\" selected>{$nodeArr[$i][1]}</option>";
		}else{
			echo "<option value=\"{$nodeArr[$i][0]}\">{$nodeArr[$i][1]}</option>";
		}
	}
	echo "</select>";
	echo "</td>";
	echo "</tr>";
}

echo "<tr height=\"18\">";
echo "<td  width=\"20%\" bgcolor=#E6E6E6>Remark</td>";
echo "<td  width=\"80%\"><input type=\"input\" size=\"10\" name=\"remark\" value=\"$remark\"></td>";
echo "</tr>";
echo "</table>";
echo "<br>";
echo "<input type=\"submit\" name=\"save\" value=\"Save\">";
echo "&nbsp;&nbsp;";
echo "<input type=\"reset\" name=\"Reset\" value =\"Reset\">";
if($mode == 'editNode' || $mode == 'editEdge'){
	echo "&nbsp;&nbsp;";	
	echo "<input type=\"submit\" name=\"delete\" value=\"Delete\">&nbsp;&nbsp;";
}

if($mode != 'addNode' && $mode != 'addEdge'){
	echo "<input type=\"hidden\" name=\"keyNo\" value=\"$keyNo\">";
}

echo "<input type=\"hidden\" name=\"mode\" value=\"$mode\">";
echo "</form>";



?>