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

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

     返回值：无

 作者：
      
修改注释：      
NO.1      
姓名        
时间
修改说明
*********************************************************/    
require("../../inc/header.inc");

$max_menu = 4;
$db=$omc_db;
$sysconf_table="sysConf";
global $pubConn;
//echo "<br>old_sysTypeNo=$old_sysTypeNo";
$type_no = $_POST['type_no'];

//$sysTypeNo	= $_REQUEST['sysTypeNo'];

if(isset($sysTypeNo) && $type_no != 'new')
{
	$netModeSelect_sql = "select networkMode from OMC_PUB.sysConf where sysTypeNo=$sysTypeNo";
	echo "$netModeSelect_sql";
	$res=@mysqli_query($pubConn,$netModeSelect_sql);
	$num=@mysqli_num_rows($res);
	//echo "num=111$num";
	if($num == 0)
		return "--";
	
	$row_netMode=mysqli_fetch_array($res);
	$netMode=$row_netMode[0];
}

/**************************************删除一个系统类型***********************************************/
if($_POST['delete']){
	$del_sql = "DELETE FROM $sysconf_table WHERE sysTypeNo='$_POST[sysTypeNo]'";
	$del_result = mysqli_query($pubConn,$del_sql);
	//----------------
	//插入日志
	insertLog("Delete the sysTypeNo=$sysTypeNo");
	//------------
	if($del_result){
		echo "<font color=\"#0000ff\">$strDeleteSuccess</font>";
       	 }else{
		echo "<font color=\"#ff0000\">$strDeleteFailure</font>";
         }
} //end if($delete) 


/*****************************添加,保存一个系统*****************************/
if($_POST['save']){
	$sysTypeNo	= $_POST['sysTypeNo'];
	$old_sysTypeNo=$_POST['old_sysTypeNo'];
	$type_no = $_POST['type_no'];
	if($type_no == 'new' )//插入一个新类型
	{  
		$jud_sql="SELECT COUNT(*) FROM $sysconf_table=sysConf WHERE sysTypeNo='$sysTypeNo'";
		$jud_res=mysqli_query($pubConn,$jud_sql);
		$jud_row=mysqli_fetch_array($jud_res);
		if(!$jud_row[0])
		{
		  $save_sql = "REPLACE INTO $sysconf_table 
			(sysTypeNo,maxSubSysNum, maxMsgLen, maxE1Num, snmpPort, snmpHead, snmpCommunity, snmpInstanceBgn, remark, sysTypeName , maxSysNum, ledOffset, needInstall, needUninstall, needParamConf, needMuliObj, needGlobalSysParam, needGlobalSubSysParam, needSubSysParam, needHeartBeat,needCDR,needCSTA,needFlow,needSubscriberConf,platHeart) 
		     VALUES 
		     ('$sysTypeNo','$_POST[maxSubSysNum]', '$_POST[maxMsgLen]', '$_POST[maxE1Num]','$_POST[snmpPort]', '$_POST[snmpHead]','$_POST[snmpCommunity]', '$_POST[snmpInstanceBgn]', '$_POST[remark]', '$_POST[sysTypeName]', '$_POST[maxSysNum]', '$_POST[ledOffset]', '$_POST[needInstall]', '$_POST[needUninstall]', '$_POST[needParamConf]', '$_POST[needMuliObj]', '$_POST[needGlobalSysParam]', '$_POST[needGlobalSubSysParam]', '$_POST[needSubSysParam]', '$_POST[needHeartBeat]','$_POST[needCDR]','$_POST[needCSTA]','$_POST[needFlow]','$_POST[needSubscriberConf]','$_POST[platHeart]') 
		    ";
		}
		else
		{
			echo "<br>Type no always is used!";
		}
	}
	elseif(isset($sysTypeNo))//修改已有类型
	{  
		if(isset($old_sysTypeNo) && $old_sysTypeNo!='new')
		{
			$chg_type=$old_sysTypeNo;
		}
		else
		{
			$chg_type=$sysTypeNo;
		}
		$save_sql = "
			UPDATE $sysconf_table 
			SET 
			sysTypeNo	= '$sysTypeNo',
			sysTypeName  = '$_POST[sysTypeName]',
			maxSysNum = '$_POST[maxSysNum]',
			maxSubSysNum  = '$_POST[maxSubSysNum]',
			maxE1Num	  = '$_POST[maxE1Num]',
			maxMsgLen	  = '$_POST[maxMsgLen]',
			snmpPort		= '$_POST[snmpPort]',
			snmpHead		= '$_POST[snmpHead]',
			snmpCommunity	= '$_POST[snmpCommunity]',
			snmpInstanceBgn = '$_POST[snmpInstanceBgn]',
			remark = '$_POST[remark]',
			ledOffset = '$_POST[ledOffset]',
			needInstall = '$_POST[needInstall]',
			needUninstall = '$_POST[needUninstall]',
			needParamConf = '$_POST[needParamConf]',
			needMuliObj = '$_POST[needMuliObj]',
			needGlobalSysParam = '$_POST[needGlobalSysParam]', 
			needGlobalSubSysParam = '$_POST[needGlobalSubSysParam]', 
			needSubSysParam = '$_POST[needSubSysParam]',			
			needHeartBeat = '$_POST[needHeartBeat]',
			needCDR	= '$_POST[needCDR]',
			needCSTA = '$_POST[needCSTA]',
			needFlow = '$_POST[needFlow]',
			needSubscriberConf = '$_POST[needSubscriberConf]',
			platHeart = '$_POST[platHeart]',
			otherModuleSendHeart = '$_POST[otherModuleSendHeart]'
			
			WHERE  sysTypeNo='$chg_type'
			";
	}
	//echo "<br>$save_sql";
	//echo "<br>index: $otherModuleSendHeart";
	$save_result = mysqli_query($pubConn,$save_sql);
	echo mysqli_error($pubConn);
	//------------插入日志------------
	insertLog("Update sysTypeNo($sysTypeNo)'s define");
	//------------
	//echo "$save_sql";
	if($save_result > 0){
		echo "<br><font color=\"#0000ff\" >$strSaveSuccess</font>";
    }else{
		echo mysqli_error($pubConn);
		echo "<br><font color=\"#ff0000\">$strSaveFailure</font>";
    }
	
} //end if($save) 

?>
<body bgcolor=#efefef>

<script type="text/javascript">  
function goto()      
 {      
    var base_url,url_add,url;      
    base_url='<?php echo"$PHP_SELF";?>?sysTypeNo=';
    url_add=document.dp_define.type_no.value;      
    url=base_url+url_add;
    window.location=url;      
 }      
</script>
<form method="POST" name=dp_define 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="2">
      <p align="center"><b><?php echo "$strSystemConfiguration"; ?></b></p>
     </td>
    </tr>
    

   <tr>    
     <td width="40%"><?php echo "$strExistedSystem"; ?>
    </td>
    <td width="60%">
           
          
<?php  
$sysTypeNo=$_REQUEST['sysTypeNo'];
if(isset($sysTypeNo) && $sysTypeNo != 'new'){   
	$sel_sql		= " SELECT * FROM $sysconf_table WHERE sysTypeNo = '$sysTypeNo' ";
	$result			= mysqli_query($pubConn,$sel_sql);
	$sel_rows		= mysqli_fetch_array($result);
	$sysTypeNo		= $sel_rows['sysTypeNo'];
	$sysTypeName	= $sel_rows['sysTypeName'];
	$maxSysNum		= $sel_rows['maxSysNum'];
	$maxSubSysNum	= $sel_rows['maxSubSysNum'];
	$maxE1Num		= $sel_rows['maxE1Num'];
	$maxMsgLen		= $sel_rows['maxMsgLen'];
	$snmpPort		= $sel_rows['snmpPort'];
	$snmpHead		= $sel_rows['snmpHead'];
	$snmpCommunity  = $sel_rows['snmpCommunity'];
	$snmpInstanceBgn= $sel_rows['snmpInstanceBgn'];
	$remark			= $sel_rows['remark'];
	$ledOffset		= $sel_rows['ledOffset'];
	$needInstall	= $sel_rows['needInstall'];
	$needUninstall	= $sel_rows['needUninstall'];
	$needParamConf	= $sel_rows['needParamConf'];
	$needMuliObj	= $sel_rows['needMuliObj'];
	$needGlobalSysParam		= $sel_rows['needGlobalSysParam'];
	$needGlobalSubSysParam	= $sel_rows['needGlobalSubSysParam'];
	$needSubSysParam 		= $sel_rows['needSubSysParam'];
	$needHeartBeat	= $sel_rows['needHeartBeat'];
	$needCDR		= $sel_rows['needCDR'];
	$needCSTA		= $sel_rows['needCSTA'];
	$needFlow		= $sel_rows['needFlow'];
	$needSubscriberConf = $sel_rows['needSubscriberConf'];
	$platHeart		= $sel_rows['platHeart'];
	$otherModuleSendHeart = $sel_rows['otherModuleSendHeart'];
}	
$type_sql		= " SELECT * FROM $sysconf_table ORDER BY sysTypeNo ";
$type_result	= mysqli_query($pubConn,$type_sql);
$type_rows		= mysqli_fetch_array($type_result);

$platHeart = isset($platHeart)?$platHeart:'9';

//显示选择参数类型下拉菜单
echo " <select size=\"1\" name=\"type_no\" onChange=\"javascript:goto()\">";
echo "<option value=\"new\">----------------------NEW--------------------</option>";
$no=0;
do{
	$len=strlen($type_rows[sysTypeNo]);
	$existSysTypeNoArr[$no++]=$type_rows[sysTypeNo];//arwean add 2006-8-14 12:23
	if($len==3)
	{
		$level_0=substr($type_rows[sysTypeNo],0,1);
		$level_1=substr($type_rows[sysTypeNo],1,1);
		$level_2=substr($type_rows[sysTypeNo],2,1);
	}
	elseif($len==2)
	{
		$level_0=0;
		$level_1=substr($type_rows[sysTypeNo],0,1);
		$level_2=substr($type_rows[sysTypeNo],1,1);
	}
	else
	{
		$level_0=0;
		$level_1=0;
		$level_2=substr($type_rows[sysTypeNo],0,1);
	}
	echo "<option value=\"$type_rows[sysTypeNo]\" ";
	if($type_rows[sysTypeNo] == $sel_rows[sysTypeNo] && isset($type_rows[sysTypeNo]))
	{
		echo "selected";
	}
	echo ">";
	if($level_2)
		echo "&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp|-- $level_0.$level_1.$level_2&nbsp&nbsp $type_rows[sysTypeName] ";
	elseif($level_1)
		echo "&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp|-- $level_0.$level_1&nbsp&nbsp $type_rows[sysTypeName] ";
	else
		echo "&nbsp&nbsp&nbsp&nbsp|-- $level_0&nbsp&nbsp $type_rows[sysTypeName] ";
	echo"</option>";
}while($type_rows = @mysqli_fetch_array($type_result));
?>
     </select>
     </td>
     </tr>
    <tr bgcolor="#E6E6E6">
    <td width="40%"><?php echo "$strSysTypeNo";?></td>
    <td width="60%">
	<select size="1" name="sysTypeNo">
	<?php  
	for($j=0; $j<1000; $j++)
	{
		if(($sysTypeNo != $j || !isset($sysTypeNo)) && in_array($j, $existSysTypeNoArr))
			continue;
		if($j == $sysTypeNo)
		{
			echo "<option value=\"$j\" selected>$j</option>";
		}
		else
		{
			echo "<option value=\"$j\" >$j</option>";
		}
	}
	?>
    </select>
    </td>
    </tr>
    <tr>
    <td width="40%"><?php echo "$strTypeName";?></td>
    <td width="60%"><input name="sysTypeName" maxlength="10" size="10" value="<?php echo $sysTypeName; ?>">
    </td>
    </tr>
    <tr bgcolor="#E6E6E6">
    <td width="40%"><?php echo "$strMaxSystemNum"; ?></td>
    <td width="60%">
	<select size="1" name="maxSysNum">
	<?php  
	for($j=0; $j<256; $j++)
	{
		if($j == $maxSysNum)
		{
			echo "<option value=\"$j\" selected>$j</option>";
		}
		else
		{
			echo "<option value=\"$j\" >$j</option>";
		}
	}
	?>
    </select>
    </td>
    </tr>
    <tr>    
    <td width="40%"><?php echo "$strMaxSubsystemNum"; ?></td>
	<td>
	<select name="maxSubSysNum">
	<?php  
	for($j=0; $j<256; $j++)
	{
		if($j == $maxSubSysNum)
		{
			echo "<option value=\"$j\" selected>$j</option>";
		}
		else
		{
			echo "<option value=\"$j\" >$j</option>";
		}
	}
	?>
	</select>
	</td>
	</tr>

    <tr bgcolor="#E6E6E6">    
    <td width="40%"><?php echo "$strMaxE1Num"; ?></td>
    <td width="60%">
	<select name="maxE1Num">
	<?php  
	for($j=0; $j<257; $j++)
	{
		if($j == $maxE1Num)
		{
			echo "<option value=\"$j\" selected>$j</option>";
		}
		else
		{
			echo "<option value=\"$j\" >$j</option>";
		}
	}
	?>
	</select>
    </td></tr>


    <tr>
    <td width="40%"><?php echo "$strMaxMessageLength"; ?></td>
    <td width="60%">
	<input name="maxMsgLen" value="<?php echo $maxMsgLen; ?>" maxlength="6" size="6">
    </td></tr>

    <tr bgcolor="#E6E6E6">
    <td width="40%"><?php echo "SNMP port"; ?></td>
    <td width="60%">
	<?php 
	if(strlen($snmpPort) < 1){
		$snmpPort='4957';
	}
	?>
    <input name="snmpPort" value="<?php echo $snmpPort; ?>" maxlength="4" size="8">
	</td>
	</tr>

    <tr bgcolor="#E6E6E6">
    <td width="40%"><?php echo "$strSNMPHead"; ?></td>
    <td width="60%">
    <input name="snmpHead" value="<?php echo $snmpHead; ?>" maxlength="30" size="30">
	</td>
	</tr>
    
	<tr>
    <td width="40%"><?php echo "SNMP community"; ?></td>
    <td width="60%">     
	<select name="snmpCommunity">
	<?php  
	if($snmpCommunity=='private')
	{
		echo "<option value=\"public\">public</option>";
		echo "<option value=\"private\" selected>private</option>";
	}
	else
	{
		echo "<option value=\"public\" selected>public</option>";
		echo "<option value=\"private\">private</option>";
	}
	?>
	</select>
    </td>
    </tr>
    <tr bgcolor="#E6E6E6">
    <td width="40%"><?php echo "SNMP begin instance"; ?></td>
    <td width="60%">     
	<select name="snmpInstanceBgn">
	<?php  
	if($snmpInstanceBgn==0)
	{
		echo "<option value=0 selected>0</option>";
		echo "<option value=1>1</option>";
	}
	else
	{
		echo "<option value=0>0</option>";
		echo "<option value=1 selected>1</option>";
	}
	?>
	</select>
    </td>
    </tr>
	
	<tr bgcolor="#E6E6E6">
    <td width="40%"><?php echo "Support Bind Multi-Object In One PDU"; ?></td>
    <td width="60%">     
	<select name="needMuliObj">
	<?php  
	if($needMuliObj==1)
	{
		echo "<option value=1 selected>Y</option>";
		echo "<option value=0>N</option>";
	}
	else
	{
		echo "<option value=1>Y</option>";
		echo "<option value=0 selected>N</option>";
	}
	?>
	</select>
    </td>
    </tr>

     <tr>    
     <td width="40%"><?php echo "$strRemark"; ?></td>
     <td width="60%"><input type="text" name="remark" size="20" maxlength="40" value="<?php echo "$remark";?>"  ></td>
     </tr>

	 <tr bgcolor="#E6E6E6">
     <td width="40%"><?php echo "$strLedOffset"; ?></td>
     <td width="60%">	
	 <input type="text" name="ledOffset" size="10" value="<?php echo "$ledOffset";?>" >
	</td>
    </tr>
    <tr>
    <td width="40%"><?php echo "$strNeedInstall"; ?></td>
    <td width="60%">     
	<select name="needInstall">
	<?php  
	if($needInstall==1)
	{
		echo "<option value=1 selected>Y</option>";
		echo "<option value=0>N</option>";
	}
	else
	{
		echo "<option value=1>Y</option>";
		echo "<option value=0 selected>N</option>";
	}
	?>
	</select>
    </td>
    </tr>
    <tr bgcolor="#E6E6E6">
    <td width="40%"><?php echo "$strNeedUninstall"; ?></td>
    <td width="60%">     
	<select name="needUninstall">
	<?php  
	if($needUninstall==1)
	{
		echo "<option value=1 selected>Y</option>";
		echo "<option value=0>N</option>";
	}
	else
	{
		echo "<option value=1>Y</option>";
		echo "<option value=0 selected>N</option>";
	}
	?>
	</select>
    </td>
    </tr>

    <tr>
    <td width="40%"><?php echo "$strNeedParamConf"; ?></td>
    <td width="60%">     
	<select name="needParamConf">
	<?php  
	if($needParamConf==1)
	{
		echo "<option value=1 selected>Y</option>";
		echo "<option value=0>N</option>";
	}
	else
	{
		echo "<option value=1>Y</option>";
		echo "<option value=0 selected>N</option>";
	}
	?>
	</select>
    </td>
    </tr>
    <tr>
    <td width="40%"><?php echo "Need System Public Parameter"; ?></td>
    <td width="60%">     
	<select name="needGlobalSysParam">
	<?php  
	if($needGlobalSysParam==1)
	{
		echo "<option value=1 selected>Y</option>";
		echo "<option value=0>N</option>";
	}
	else
	{
		echo "<option value=1>Y</option>";
		echo "<option value=0 selected>N</option>";
	}
	?>
	</select>
    </td>
    </tr>


    <tr bgcolor="#E6E6E6">
    <td width="40%"><?php echo "Need Subsystem Public Parameter"; ?></td>
    <td width="60%">     
	<select name="needGlobalSubSysParam">
	<?php  
	if($needGlobalSubSysParam==1)
	{
		echo "<option value=1 selected>Y</option>";
		echo "<option value=0>N</option>";
	}
	else
	{
		echo "<option value=1>Y</option>";
		echo "<option value=0 selected>N</option>";
	}
	?>
	</select>
    </td>
    </tr>

    <tr>
    <td width="40%"><?php echo "Need Subsystem (private) Parameter"; ?></td>
    <td width="60%">     
	<select name="needSubSysParam">
	<?php  
	if($needSubSysParam==1)
	{
		echo "<option value=1 selected>Y</option>";
		echo "<option value=0>N</option>";
	}
	else
	{
		echo "<option value=1>Y</option>";
		echo "<option value=0 selected>N</option>";
	}
	?>
	</select>
    </td>
    </tr>



    <tr bgcolor="#E6E6E6">
    <td width="40%"><?php echo "$strNeedHeartBeat"; ?></td>
    <td width="60%">     
	<select name="needHeartBeat">
	<?php  
	if($needHeartBeat==1)
	{
		echo "<option value=1 selected>Y</option>";
		echo "<option value=0>N</option>";
	}
	else
	{
		echo "<option value=1>Y</option>";
		echo "<option value=0 selected>N</option>";
	}
	?>
	</select>
    </td>
    </tr>
    <tr>
    <td width="40%"><?php echo "$strNeedCDR"; ?></td>
    <td width="60%">     
	<select name="needCDR">
	<?php  
	if($needCDR==1)
	{
		echo "<option value=1 selected>Y</option>";
		echo "<option value=0>N</option>";
	}
	else
	{
		echo "<option value=1>Y</option>";
		echo "<option value=0 selected>N</option>";
	}
	?>
	</select>
    </td>
    </tr>
    <tr bgcolor="#E6E6E6">
    <td width="40%"><?php echo "$strNeedCSTA"; ?></td>
    <td width="60%">     
	<select name="needCSTA">
	<?php  
	if($needCSTA==1)
	{
		echo "<option value=1 selected>Y</option>";
		echo "<option value=0>N</option>";
	}
	else
	{
		echo "<option value=1>Y</option>";
		echo "<option value=0 selected>N</option>";
	}
	?>
	</select>
    </td>
    </tr>
    <tr>
    <td width="40%"><?php echo "$strNeedFlow"; ?></td>
    <td width="60%">     
	<select name="needFlow">
	<?php  
	if($needFlow==1)
	{
		echo "<option value=1 selected>Y</option>";
		echo "<option value=0>N</option>";
	}
	else
	{
		echo "<option value=1>Y</option>";
		echo "<option value=0 selected>N</option>";
	}
	?>
	</select>
    </td>
    </tr>
    <tr bgcolor="#E6E6E6">
    <td width="40%"><?php echo "$strNeedSubscriberConf"; ?></td>
    <td width="60%">     
	<select name="needSubscriberConf">
	<?php  
	if($needSubscriberConf ==1)
	{
		echo "<option value=1 selected>Y</option>";
		echo "<option value=0>N</option>";
	}
	else
	{
		echo "<option value=1>Y</option>";
		echo "<option value=0 selected>N</option>";
	}
	?>
	</select>
    </td>
    </tr>
    <tr bgcolor="#E6E6E6">
    <td width="40%"><?php echo "Send platform heartbeat"; ?></td>
    <td width="60%">     
	<?php
	$len=count($PlatTypeDefArr);
	echo "<select name=\"platHeart\">";
	echo "<option value=\"99\">None</option>";
	for($i=0;$i<$len;$i++)
	{
		if($platHeart == $i)
		{
			echo "<option value=\"$i\" selected>{$PlatTypeDefArr[$i][remark]}</option>";
		}
		else
		{
			echo "<option value=\"$i\">{$PlatTypeDefArr[$i][remark]}</option>";
		}
	}
	?>
	</select>
    </td>
    </tr>

    <tr bgcolor="#E6E6E6">
    <td width="40%"><?php echo "current module's heart beat agent"; ?></td>
    <td width="60%">     
	<?php
	$len=count($PlatTypeDefArr);
	echo "<select name=\"otherModuleSendHeart\">";
	echo "<option value=\"99\">None</option>";
	for($i=0;$i<$len;$i++)
	{
		$PlatTypeDefArr_sysTypeNo = $PlatTypeDefArr[$i][sysTypeNo];
		if($otherModuleSendHeart == $PlatTypeDefArr_sysTypeNo)
		{
			echo "<option value=\"$PlatTypeDefArr_sysTypeNo\" selected>{$PlatTypeDefArr[$i][remark]}</option>";
		}
		else
		{
			echo "<option value=\"$PlatTypeDefArr_sysTypeNo\">{$PlatTypeDefArr[$i][remark]}</option>";
		}
	}
	?>
	</select>
    </td>
    </tr>

    </table>

	 <input type="hidden" value="<?php echo "$sysTypeNo"; ?>" name="old_sysTypeNo">
  <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>                 
               
</body>                
                
</html>                
