<?php

/*********************************************************      

 程序说明:         

    功能说明:所有已知系统列表



    调用关系:调用: connectdb.inc，inc/header.inc     

              被调用:      

 

    变量说明:$device_table;

              $language_type是公共变量在config.inc文件定义



     返回值:无



 作者:   

      

修改注释:      

NO.1      

姓名:            

时间:      

修改说明:      

*********************************************************/    

require("../../inc/header.inc");
?>
<body leftmargin="15" rightmargin="10" onload="javascript:adjust_frame('down');" onresize="javascript:adjust_frame('down');" style="overflow:hidden;overflow-x:hidden;overflow-y:hidden;">

<?php
adjust_head_frame("down");
adjust_title_head_frame("down");
adjust_title_tail_frame("down");

adjust_content_head_frame("down");	
echo "<br>";

global $pubConn;
$DEBUG = 0;
$mode = $_REQUEST['mode'];
$sysTypeNo = $_REQUEST['sysTypeNo'];
$save = $_POST['save'];

if($DEBUG) echo "<br>mode=$mode";



$sysConfTable = 'OMC_PUB.sysConf';

$sysInfoTable = 'OMC_PUB.sysInfo';

$sysInfoDefTable = 'OMC_PUB.sysInfoDef';

$pubDb			='OMC_PUB';





$netIdDefArr=array(array('0', "international network"),	

				   array('1', "international network spare"),

				   array('2', "national network"),

				   array('3', "national network spare")

					);



if($DEBUG) echo "<br>sysId=$sysId";

if(isset($sysId) && strlen($sysId) > 5){

	$sysIdArr = explode('_',$sysId);

	$sysTypeNo	= $sysIdArr[0];

	$sysNo		= $sysIdArr[1];

	$subSysNo	= $sysIdArr[2];

	if($DEBUG) echo "<br>sysTypeNo=$sysTypeNo";

	if($DEBUG) echo "<br>sysNo=$sysNo";

	if($DEBUG) echo "<br>subSysNo=$subSysNo";

}



if($sysTypeNo == '500' && isset($bssId)){

	if($DEBUG) echo "<br>Process BSS's return......";

	if(isset($errorInfo)){

		echo "<font color=red size=3><br>Error:$errorInfo</font>";

		if($mode == 'delete'){

			$delSql = "DELETE FROM $sysInfoTable

						WHERE sysTypeNo='$sysTypeNo' AND sysNo = '$sysNo'

							AND subSysNo = '$subSysNo'	AND ip = '$ip'

						";

			if($DEBUG) echo "<br>delSql = $delSql";

			mysqli_query($pubConn,$delSql);

			//echo "<br><font size=3 color=blue>Delete BSS$bssId OK</font>";

			//if(!$DEBUG) echo " <meta http-equiv=\"refresh\" content=\"2; url=./systemList_down.php\"> ";

			//exit();

		}

		exit();

	}else{

		if($mode == 'add'){

			$addSql = "REPLACE INTO $sysInfoTable (sysTypeNo,sysNo,subSysNo,isRemote,netId,DPC,ip,baseStat,sysAlias,updateTime )

			VALUES('$sysTypeNo','$sysNo','$subSysNo','$isRemote','$netId','$DPC','$ip','1','$sysAlias',CURRENT_TIMESTAMP)

							";

			if($DEBUG) echo "<br>addSql = $addSql";

			$result = mysqli_query($pubConn,$addSql);

			echo mysqli_error($pubConn);

			

			echo "<br><font size=3 color=blue>Create BSS$bssId OK</font>";

			$mode = 'edit';

		}elseif($mode == 'delete'){

			$delSql = "DELETE FROM $sysInfoTable

						WHERE sysTypeNo='$sysTypeNo' AND sysNo = '$sysNo'

							AND subSysNo = '$subSysNo'	AND ip = '$ip'

						";

			if($DEBUG) echo "<br>delSql = $delSql";

			mysqli_query($pubConn,$delSql);

			echo "<br><font size=3 color=blue>Delete BSS$bssId OK</font>";

			if(!$DEBUG) echo " <meta http-equiv=\"refresh\" content=\"2; url=./systemList_down.php\"> ";

			exit();

		}else{

			echo "Error:Unknown mode($mode)";

			exit();

		}

	}

}



if(isset($save) && $save != '-1'){

	if($sysTypeNo == '500' && $mode=='add'){

		$sysId= $sysTypeNo.'_'.$sysNo.'_'.$subSysNo;

		$addBssUrl="../../bssomc/bsstable.php?mode=add&sysId=$sysId&ip=$ip&remark=$sysAlias&language=$language";

		echo " <meta http-equiv=\"refresh\" content=\"0; url=$addBssUrl\"> ";

		exit();

	}

	if($mode=='add'){

			$addSql = "REPLACE INTO $sysInfoTable (sysTypeNo,sysNo,subSysNo,isRemote,netId,DPC,ip,baseStat,sysAlias,updateTime )

			VALUES('$sysTypeNo','$sysNo','$subSysNo','$isRemote','$netId','$DPC','$ip','1','$sysAlias',CURRENT_TIMESTAMP)

						";

		if($DEBUG) echo "<br>addSql = $addSql";

		$result = mysqli_query($pubConn,$addSql);

		echo mysqli_error($pubConn);

		

		$sysId=$sysTypeNo.'_'.$sysNo.'_'.$subSysNo;

		$mode = 'edit';

	}else{

		$sysIdArr = explode('_',$sysId);

		$sysTypeNo	= $sysIdArr[0];

		$sysNo		= $sysIdArr[1];

		$subSysNo	= $sysIdArr[2];

		$saveSql = "UPDATE $sysInfoTable SET isRemote='$isRemote',netId='$netId',DPC='$DPC',ip ='$ip',

					baseStat='$baseStat',sysAlias='$sysAlias',updateTime = CURRENT_TIMESTAMP

					WHERE sysTypeNo='$sysTypeNo'

						AND sysNo = '$sysNo'

						AND subSysNo = '$subSysNo'

					";

		if($DEBUG) echo "<br>saveSql = $saveSql";

		$result = mysqli_query($pubConn,$saveSql);

		echo mysqli_error($pubConn);

	}

	if($result > 0){

		echo "<br>OK!";

	}else{

		echo "<br>Error!";

	}

	if(!$DEBUG) echo " <meta http-equiv=\"refresh\" content=\"1; url=./systemList_down.php\"> ";

	exit();

}elseif($mode =='delete'){

	$sysIdArr = explode('_',$sysId);

	$sysTypeNo	= $sysIdArr[0];

	$sysNo		= $sysIdArr[1];

	$subSysNo	= $sysIdArr[2];



	if($sureDel == 'Yes'){

		if($sysTypeNo == '500'){

			echo " <meta http-equiv=\"refresh\" content=\"0; url=../../bssomc/dropbss.php?mode=delete&sysId=$sysId&ip=$ip&language=$language\"> ";

			exit();

		}else{

			$delSql = "DELETE FROM $sysInfoTable

						WHERE sysTypeNo='$sysTypeNo' AND sysNo = '$sysNo'

							AND subSysNo = '$subSysNo'	AND ip = '$ip'

						";

			if($DEBUG) echo "<br>delSql = $delSql";

			mysqli_query($pubConn,$delSql);

			echo "<br><font size=3 color=blue>Delete ok</font>";

			echo " <meta http-equiv=\"refresh\" content=\"1; url=./systemList_down.php\"> ";

		}

		exit();

	}elseif($sureDel == 'No'){

		echo "<br><font size=3 color=blue>Delete Canceled</font>";

		$mode='edit';

	}else{

		echo "<font size=3 color=black>Are you sure to delete system information of <font size=3 color=blue>$sysName </font>?</font>";

		echo "<form method=\"POST\" name=\"confForm\" action=\"$PHP_SELF\">";

		echo "<input type=\"submit\" name=\"sureDel\" value=\"Yes\">";

		echo "<input type=\"submit\" name=\"sureDel\" value=\"No\">";

		echo "<input type=\"hidden\" name=\"mode\" value=\"delete\">";

		echo "<input type=\"hidden\" name=\"sysId\" value=\"$sysId\">";

		echo "<input type=\"hidden\" name=\"ip\" value=\"$ip\">";

		echo "</form>";

		exit();

	}

}



if(isset($sysId)){

	$sysIdArr = explode('_',$sysId);

	$sysTypeNo	= $sysIdArr[0];

	$sysNo		= $sysIdArr[1];

	$subSysNo	= $sysIdArr[2];

}



if($mode == 'edit'){

	$sysListSql = "SELECT sysTypeName,$sysInfoTable.sysTypeNo,sysNo,subSysNo,isRemote,netId,DPC,ip,baseStat,sysAlias,updateTime

					FROM $sysConfTable,$sysInfoTable 

					WHERE $sysConfTable.sysTypeNo = $sysInfoTable.sysTypeNo

						AND $sysInfoTable.sysTypeNo='$sysTypeNo'

						AND $sysInfoTable.sysNo = '$sysNo'

						AND $sysInfoTable.subSysNo = '$subSysNo'

						AND $sysInfoTable.ip = '$ip'

					ORDER BY $sysInfoTable.sysTypeNo,sysNo,subSysNo,updateTime";

	if($DEBUG) echo "<br><br>sysListSql = $sysListSql";

	$sysListResult = mysqli_query($pubConn,$sysListSql);

	echo mysqli_error($pubConn);

	$sysListRows= @mysqli_fetch_array($sysListResult);

	$isRemote	= $sysListRows[isRemote];

	$netId		= $sysListRows[netId];

	$DPC		= $sysListRows[DPC];

}

?>

<script LANGUAGE="JavaScript">  

function selectSysType(){      

	var base_url,url_add,url; 

	base_url='<?php echo"$PHP_SELF";?>?mode=add&sysTypeNo=';

	url_add=document.confForm.sysTypeNo.options[document.confForm.sysTypeNo.selectedIndex].value;      
	url=base_url+url_add;

	window.location=url;

}   

</script>

<form method="POST" name=confForm action="<?php echo"$PHP_SELF";?>" >

<table  border="1" width="100%" cellpadding="2" cellspacing="0"  bordercolor="#666666" bordercolordark="#FFFFFF" bgcolor="#FFFFFF" > 

 <tr bgcolor="#E6E6E6">    

	<td width="100%" colspan="6" align="center">

		<font size=3><b><?php echo "System Information"; ?></b></font>

	</td>

  </tr>

<?php

echo "<tr bgcolor=#E6E6E6>";

echo "<td  width=\"25%\">system Name</td>";

echo "<td>";


if($mode == 'add'){

	echo "<nobr>";

	echo "system Type";

	echo "<select size=\"1\" name=\"sysTypeNo\" onChange=\"javascript:selectSysType()\">";

	//显示选择设备类型下拉菜单

	$sysTypeSql ="SELECT sysTypeNo,sysTypeName,maxSysNum,maxSubSysNum 

				FROM $sysConfTable 

				WHERE needInstall > '0' 

				ORDER BY sysTypeNo

				";

	if($DEBUG) echo "<br>$sysTypeSql";

	$sysTypeResult = mysqli_query($pubConn,$sysTypeSql);

	$sysTypeRows = @mysqli_fetch_array($sysTypeResult);
	if(!isset($sysTypeNo)){
		$sysTypeNo=$sysTypeRows[sysTypeNo];
	}

	do{

		echo "<option value=\"$sysTypeRows[sysTypeNo]\" ";

		if(isset($sysTypeNo)&& $sysTypeRows[sysTypeNo] == $sysTypeNo){

			echo"selected";

			$maxSysNum = $sysTypeRows[maxSysNum];

			$maxSubSysNum = $sysTypeRows[maxSubSysNum];

			$sysTypeName = $sysTypeRows[sysTypeName];

		}

		echo ">";

		echo "$sysTypeRows[sysTypeName]";

		echo "</option>";

	}while($sysTypeRows = mysqli_fetch_array($sysTypeResult));

	echo "</select>";

	//显示选择系统编号下拉菜单

	echo "sysNo:";

	echo "<select size=\"1\" name=\"sysNo\">";
	if($sysTypeNo >= 222 && $sysTypeNo <= 225){
		for($i=0;$i<sizeof($PlatTypeDefArr);$i++){
			echo "<option value=\"$i\">$i [{$PlatTypeDefArr[$i][remark]}]</option>";
		}
	}else{
		
	for($i=0;$i<$maxSysNum;$i++){
			
		echo "<option value=\"$i\">$i</option>";
		}

	}

	echo "</select>";

	

	//显示选择子系统编号下拉菜单

	echo "subSysNo:";

	echo "<select size=\"1\" name=\"subSysNo\">";

	for($i=0;$i<$maxSubSysNum;$i++){

		echo "<option value=\"$i\">$i</option>";

	}

	echo "</select>";

	echo "</nobr>";

}else{

	echo "<nobr>";

	$sysName = $sysListRows[sysTypeName].'_'.$sysListRows[sysNo].'_'.$sysListRows[subSysNo];

	echo "$sysName <input type=\"hidden\" name=\"sysName\" value=\"$sysName\">";

	echo "</nobr>";

}

echo "</td></tr>";

$baseStatArr=array(array('1',"Normal"),array('0',"False"));

//do{

	echo "<tr>";

	//===isRemote===

	echo "<td>Network Type</td><td> ";

	echo "<select size=\"1\" name=\"isRemote\">";

	if(isset($isRemote) && $isRemote == '1'){

		echo "<option value=\"0\" >Ethernet</option>";

		echo "<option value=\"1\" selected>SS7(E1)</option>";

	}else{

		echo "<option value=\"0\" selected>Ethernet</option>";

		echo "<option value=\"1\" >SS7(E1)</option>";

	}

	echo "</select></td>";

	echo "</tr>";

	//===netId===

	echo "<tr>";

	echo "<td>Net ID:</td>";

	echo "<td><select size=\"1\" name=\"netId\">";

	for($i=0;$i<sizeof($netIdDefArr);$i++){

		//echo "{$netIdDefArr[$i][0]}= {$netIdDefArr[$i][1]}";

		if($netIdDefArr[$i][0] == $netId){

			echo "<option value=\"{$netIdDefArr[$i][0]}\" selected>{$netIdDefArr[$i][1]}</option>";

		}else{

			echo "<option value=\"{$netIdDefArr[$i][0]}\" >{$netIdDefArr[$i][1]}</option>";

		}

	}

	echo "</select></td>";

	//===DPC===

	echo "<tr><td>DPC: </td>";

	echo "<td><input type=\"text\" name=\"DPC\" value=\"$DPC\" length=\"15\"></td>";

	echo "</tr>";

	//===ip==

	echo "<tr><td><nobr>IP:</td>";

	if(isset($ip)){

		echo "<td><input type=\"text\" name=\"ip\" value=\"$ip\" length=\"15\"></td>";

	}else{

		echo "<td><input type=\"text\" name=\"ip\" value=\"$sysListRows[ip]\" length=\"15\"></td>";

	}

	echo "</tr>";

//}while($sysId != 'add' && $sysListRows=@mysql_fetch_array($sysListResult));

echo "<tr>";

echo "<td>baseStatus:</td> ";

echo "<td><select size=\"1\" name=\"baseStat\">";

for($i=0;$i<sizeof($baseStatArr);$i++){

	if($baseStatArr[$i][0] == $sysListRows[baseStat]){

		echo "<option value=\"{$baseStatArr[$i][0]}\" selected>{$baseStatArr[$i][1]}</option>";

	}else{

		echo "<option value=\"{$baseStatArr[$i][0]}\" >{$baseStatArr[$i][1]}</option>";

	}

}

echo "</select></td>";

echo "</tr><tr>";

echo "<td>updateTime:</td><td>&nbsp; $sysListRows[updateTime]</td>";

echo "</tr><tr>";

echo "<td>Alias:</td>";

echo "<td colspan=\"2\"><input type=\"text\" name=\"sysAlias\" value=\"$sysListRows[sysAlias]\" length=\"25\" maxlength=\"20\"></td>";



echo "</tr>";

echo "</table>";

echo "&nbsp;&nbsp;";

echo "<input type=\"submit\" name=\"save\" value=\"Save\">&nbsp;&nbsp;";

echo "<input type=\"hidden\" name=\"sysId\" value=\"$sysId\">";

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

echo "</FROM>";
adjust_content_tail("down");
?>