<?php
/*********************************************************      
 程序说明:         
    功能说明:本程序实现对设备别名表的初始化，根据该设备类型的最大系统和子系统个数，进行初始化。

    调用关系:调用: connectdb.inc,lib.inc     
             被调用:    
 
    变量说明:

    返回值:无

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

$DEBUG = 0;
$sysDb='OMC_PUB';


/*
if($sureDoIt != 'Yes'){
	if($sureDoIt == 'No'){
		
	}
	echo "";
	echo "<form action=\"sql.php\" method=\"post\">";
	echo "Are you sure to init $sysTypeName 's alarm?";
	echo "<input type="hidden" name="sysTypeName" value="$sysTypeName">";
    echo "<input type="hidden" name="maxSysNum" value="$maxSysNum">";
	echo "<input type="hidden" name="maxSubSysNum" value="$maxSubSysNum">";
 
	echo "<input type="Submit" name="$sureDoIt" value="Yes">";
    echo "<input type="Submit" name="$sureDoIt" value="No">";
    echo "</form>";
	exit();
}
*/


echo "<br><font size=3><b>It's need some minutes,Please wait...</b><br>";
if($initAll > 0){
	$clearSql = "DELETE FROM sysInfoDef ";
}else{
	$clearSql = "DELETE FROM sysInfoDef WHERE sysTypeNo = '$sysTypeNo'";
}
if($DEBUG) echo "<br>clearSql=$clearSql";
mysqli_query($pubConn,$clearSql);
echo mysqli_error($pubConn);
if($initAll > 0){
	$getSysConfSql = "SELECT sysTypeNo,maxSysNum,maxSubSysNum 
			FROM sysConf 
			";
}else{
	$getSysConfSql = "SELECT sysTypeNo,maxSysNum,maxSubSysNum 
			FROM sysConf 
			WHERE sysTypeNo= '$sysTypeNo'
			";
}
if($DEBUG) echo "<br>getSysConfSql=$getSysConfSql";
$sysConfResult=mysqli_query($pubConn,$getSysConfSql);
echo mysqli_error($pubConn);

$k=0;
while($sysConfRows = mysqli_fetch_array($sysConfResult)){
	$sysTypeNo		= $sysConfRows[sysTypeNo];
	$maxSysNum		= $sysConfRows[maxSysNum];
	$maxSubSysNum	= $sysConfRows[maxSubSysNum];
	if($DEBUG) echo "<br>sysTypeNo=$sysTypeNo";
	if($DEBUG) echo "<br>maxSysNum=$maxSysNum";
	if($DEBUG) echo "<br>maxSubSysNum=$maxSubSysNum";
	for($i=0;$i<$maxSysNum;$i++){
		for($j=0;$j<$maxSubSysNum;$j++){
			$insertSql = "REPLACE sysInfoDef 
				(sysTypeNo,sysNo,subSysNo,ip,sysAlias) 
				VALUES
				('$sysTypeNo','$i','$j','','')
				";
			if($DEBUG) echo "<br>insertSql=$insertSql";
			mysqli_query($pubConn,$insertSql);
			echo mysqli_error($pubConn);
		}
	}
	if($initAll > 0){
		if(($k % 10) == 0){
			print(">>");
			flush();
		}
	}else{
		print(">>");
		flush();
	}
	$k++;
}
if($initAll > 0){
	echo "<br>All Alias initialized!</font>";
}else{
	echo "<br>$sysTypeName 's Alias initialized!!</font>";
}

?>
