<?php
{
	require("../../element/sub_inc/commfunc.php");
	require("../../element/sub_inc/lib.inc");
	require("../../account/pubSubsMng/sendComm.inc");
	require("pubPath.inc");
}
?>
<STYLE TYPE="text/css" MEDIA="screen, print, projection">
<!--
  .inner   {align: right;
  			width: 40px }
-->
</STYLE>

<?php
$helpId = isset($helpId)?$helpId:'5.1.6';
$ThisPage="$strMaintenance&nbsp;>&nbsp;$strBackupRestore&nbsp;>&nbsp;"."Download&Upload";
$DEBUG = 0;
$pubDb = "OMC_PUB";
set_time_limit(3600);
$strNoInput = "No file input!";

function MsgBox($str)
{
	echo "<script language=\"javascript\">";
	echo "alert(\"$str\");";
	echo "history.go(-1)";
	echo "</script>";
}//end MsgBox

function createParamCVS($path,$tbNameArr)
{
	$pubDb = "OMC_PUB";
	global $pubConn;
	for($i=0; $i<sizeof($tbNameArr); $i++)
	{
		$tableName = $tbNameArr[$i];
		$filePath = $path . $tableName.".csv";
		if (is_file($filePath))
			unlink($filePath);
		$csvFileUpdateSql="	SELECT * 
				INTO OUTFILE '{$filePath}' 
				FIELDS TERMINATED BY ',' 
				LINES TERMINATED BY '\n' 
				FROM $tableName 
			";		
		$csvFileUpdateResult = mysqli_query($pubConn ,$csvFileUpdateSql);
		echo mysqli_error($pubConn);		
	}
}//end createParamCVS
function getSubsData($sysId,$dataTypeNo)
{
	$pubDb				= 'OMC_PUB';
	$sysSubsConfTable	= 'OMC_PUB.sysSubsConf';
	$systemConfTable	= 'OMC_PUB.sysConf';

	$sysIdArr			= explode('_',$sysId);
	$sysTypeNo			= $sysIdArr[0];
	$sysNo				= $sysIdArr[1];
	$subSysNo			= $sysIdArr[2];
	$nLoadIndexComm		= 5;
	$commType 			= $nLoadIndexComm;
	$objDb				= 'OBJ_'.$sysTypeNo;
	$objDbConn = mysqli_connect($OMC_server[0]['host'],$OMC_server[0]['user'],$OMC_server[0]['password'],$objDb);	

	if($sysTypeNo==390){
		$getConfSql="SELECT sysTypeName,dataTypeNo,indexFieldName,subsDataTable,tmpDataTable  
					FROM $sysSubsConfTable,$systemConfTable 
					WHERE $sysSubsConfTable.sysTypeNo='$sysTypeNo' 
					AND $systemConfTable.sysTypeNo='$sysTypeNo'
					AND $sysSubsConfTable.dataTypeNo='$dataTypeNo'
					AND $sysSubsConfTable.sysNo='$sysNo'
					";
	}else{
		$getConfSql="SELECT sysTypeName,dataTypeNo,indexFieldName,subsDataTable,tmpDataTable  
					FROM $sysSubsConfTable,$systemConfTable 
					WHERE $sysSubsConfTable.sysTypeNo='$sysTypeNo' 
					AND $systemConfTable.sysTypeNo='$sysTypeNo'
					AND $sysSubsConfTable.dataTypeNo='$dataTypeNo' 
					";
	}
	$getConfResult=mysqli_query($objDbConn,$getConfSql);
	echo mysqli_error($objDbConn);
	$getConfRows=mysqli_fetch_array($getConfResult);
	$sysTypeName	=$getConfRows[sysTypeName];
	$indexFieldName	=$getConfRows[indexFieldName];
	$srcDataTable	=$getConfRows[subsDataTable];
	$tmpDataTable	=$getConfRows[tmpDataTable];
	
	$clearDataSql="DELETE FROM $srcDataTable";
	mysqli_query($objDbConn,$clearDataSql);
	$clearDataSql="DELETE FROM $tmpDataTable";
	mysqli_query($objDbConn,$clearDataSql);
	
	$commIdStr = subsCommSend($sysId,$dataTypeNo,"","All",$commType);
	$rtn = commScan($commIdStr);	
	return $rtn;
}
function commScan($commIdStr)
{
	$nReadComm		= 1;
	$nChangeComm	= 2;
	$nCreateComm	= 3;
	$nDeleteComm	= 4;
	$nLoadIndexComm	= 5;
	$nReplaceIndexComm=6;
	//commState's value
	$nProcFail		= 0;
	$nWaitProc		= 1;
	$nInProc		= 2;
	$nOutProc		= 3;

	$pubDb		= 'OMC_PUB';
	$commTable	= 'subscriberComm';
	$sysConfTable ='sysConf';
	if($commNum <= 0){
		$commArr = explode('-',$commIdStr);
		$commNum = sizeof($commArr);
	}
	$maxOverTime = $commNum * 5 + 10; //根据子系统个数和对每个子系统操作的最大延时（5秒）来决定
	$maxWaitTime = $commNum * 2;
	$maxStopTime = $commNum * 5 + 10;
	$maxOfCommId = 50000; //设定命令表的最大值	
	//echo "<br>(isFinish != 0) || (waitTime >= maxWaitTime) || (stopTime > maxStopTime)";
	while(1) {
		echo "<img border=\"0\" src=\"../../images/arrow.gif\" width=\"10\" height=\"10\">";
		flush();
		//echo "<br>($isFinish != 0) || ($waitTime >= $maxWaitTime) || ($stopTime > $maxStopTime)";
		if(($isFinish != 0) || ($waitTime >= $maxWaitTime) || ($stopTime > $maxStopTime)){ 
			if($commId >= $maxOfCommId){ //初始化命令表
				//先删除表
				$dropSql = "DROP TABLE $commTable ";
				mysqli_query($pubConn,$dropSql);
				//再建一个结构相同的新表
				$createSql="CREATE TABLE subscriberComm (
					   commId smallint(5) unsigned NOT NULL auto_increment,
					   commType tinyint(1) DEFAULT '0' NOT NULL,
					   dataTypeNo tinyint(4) DEFAULT '0' NOT NULL,
					   sysTypeNo smallint(5) unsigned DEFAULT '0' NOT NULL,
					   sysNo smallint(5) unsigned DEFAULT '0' NOT NULL,
					   subSysNo smallint(5) unsigned DEFAULT '0' NOT NULL,
					   indexValueList varchar(255) NOT NULL,
					   fieldNameList tinytext NOT NULL,
					   paramType tinyint(4) DEFAULT '0' NOT NULL,
					   commState tinyint(3) unsigned DEFAULT '0' NOT NULL,
					   totalNum smallint(5) unsigned DEFAULT '0' NOT NULL,
					   finishNum smallint(5) unsigned DEFAULT '0' NOT NULL,
					   sendTime datetime DEFAULT '0000-00-00 00:00:00' NOT NULL,
					   bgnTime datetime DEFAULT '0000-00-00 00:00:00' NOT NULL,
					   endTime datetime DEFAULT '0000-00-00 00:00:00' NOT NULL,
					   remark varchar(200) binary NOT NULL,
					   PRIMARY KEY (commId),
					   KEY sysTypeNo (sysTypeNo),
					   KEY sysNo (sysNo),
					   KEY subSysNo (subSysNo),
					   KEY bufferKey (indexValueList)
					)
					";
				mysqli_query($pubConn,$createSql);
			}else{
				//删除命令表的相关命令
				$commArr = explode('-',$commIdStr);
				for($i=0;$i<sizeof($commArr);$i++){
					if(strlen($commArr[$i]) <=0){ 
						continue;
					}
					$deleteSql = "DELETE FROM $commTable WHERE commId='$commArr[$i]'";
					if($DEBUG) echo "<br>deleteSql = $deleteSql";
					mysqli_query($pubConn,$deleteSql);
					echo mysqli_error($pubConn);
				}
			}
	
			// 重定向返回指定页
			if($isFinish != 0){
				if($isFinish > 0){
					echo "<b><font size=3 color=blue>Finished!!</font></b>";
					if($commType == $nLoadIndexComm){
						sleep(8);//等8秒，这样数据库插入才能完全完成
					}
					return 1;
				}elseif($isFinish == -1){
					echo "<b><font size=3 color=black>Failed in some system!!</font></b>";
					flush();
					return 0;
				}else{
					echo "<b><font size=3 color=red>Failed!!</font></b>";
					flush();
					return 0;
				}
			}elseif($usedTime >= $maxOverTime && $stopTime == 1){
				echo "<b><font size=3 color=red>Stoped!!</font></b>";
				flush();
				return 0;
			}else{ //$usedTime >= $maxOverTime
			  	echo "<b><font size=3 color=red>Timeout!!</font></b>";
				flush();
				return 0;
			}
		}//end of if($isFinish....)

		//显示命令执行状态
		//----------------------------- 
		$okNum	 = 0;
		$failNum = 0;
		$commNum = 0;
		$commArr = explode('-',$commIdStr);
		$thisTimeFinishNumStr = '';
		$lastTimeFinishNumArr = explode('-',$lastTimeFinishNumStr);
		for($i=0;$i<sizeof($commArr);$i++){
			if(strlen($commArr[$i]) <=0){ continue;}
			$commNum++;
			$commSql = "SELECT * FROM $commTable WHERE commId= $commArr[$i]";
			if($DEBUG) echo "<br>get command = $commSql";
			$commResult = mysqli_query($pubConn,$commSql);
			if(mysqli_num_rows($commResult) <= 0){
				echo "<br>Can not find this command's info in datebase";
				exit();
			}
			$commRows	= @mysqli_fetch_array($commResult);
			$sysTypeNo	= $commRows[sysTypeNo];
			$sysNo		= $commRows[sysNo];
			$subSysNo	= $commRows[subSysNo];
			$commType	= $commRows[commType];
			$paramType	= $commRows[paramType];
			$objId		= $commRows[objId];
			$commState	= $commRows[commState];
			$indexValueList = $commRows[indexValueList];
			$fieldNameList	= $commRows[fieldNameList];
			$remark = $commRows[remark];

			switch($commState){
				case 0: //process failed
					$failNum++;
					echo "<b><font size=2 color=red> $commRows[remark] </font></b>";
					flush();
					return 0;
					//break;
				case 1: //wait process
					$waitTime++;
					break;
				case 2: //in process
					$waitTime = 0;
					//只要有一个命令的完成数在增长，就认为该组命令在运行，否则认为命令处理超时
					if($DEBUG) echo "====> {$commRows[finishNum]} > {$lastTimeFinishNumArr[$i]}";
					if($commRows[finishNum] > $lastTimeFinishNumArr[$i]){
						$stopTime = 0;
					}else{
						$stopTime++;
					}
					$thisTimeFinishNumStr .=$commRows[finishNum].'-';
					break;
				case 3: //process finished
					$okNum++;
					break;
				default:
					echo "<font size=3>Unknown Command State</font>";
					flush();
					exit();
			}
		}//end of for($i=0;$i<sizeof($commArr);$i++)
		
		if($DEBUG) echo"<br>$commNum =?= $finishNum";
		if($commNum == $okNum){
			$isFinish = 1;
		}elseif($failNum > 0 && $okNum > 0){
			$isFinish = -1;
		}elseif($commNum == $failNum){
			$isFinish = -2;
		}else{
			$isFinish = 0;
		}
	
		if($DEBUG) echo"<br>lastTimeFinishNumStr=$lastTimeFinishNumStr";
		if($DEBUG) echo"<br>thisTimeFinishNumStr=$thisTimeFinishNumStr";
		$lastTimeFinishNumStr = $thisTimeFinishNumStr;
		//刷新返回
		//--------------
		$usedTime++; //总时间
		sleep(5);
	}//end while
}
function createSubsCVS($path,$subsTlbName,$sysId)
{
	$pubDb = "OMC_PUB";
	$filePath = $path . "$subsTlbName.$sysId.csv";
	if (is_file($filePath))
		unlink($filePath);
	$csvFileUpdateSql="	SELECT * 
			INTO OUTFILE '{$filePath}' 
			FIELDS TERMINATED BY ',' 
			LINES TERMINATED BY '\n' 
			FROM $subsTlbName limit 0,5000
		";		
	//echo "<br>csvFileUpdateSql= $csvFileUpdateSql";
	$csvFileUpdateResult = mysqli_query($pubConn ,$csvFileUpdateSql);
	echo mysqli_error($pubConn);		
}//end createSubsCVS

function getBssIp (&$bssIpArr)
{
	$bssDb = "BssOmcDb";
	$bssTable = "OMCR_BSSTABLE";
	$selSql = "select ip,bssid from $bssTable";
	$bssResult = mysqli_query($pubConn,$selSql);
	while($bssRow = mysqli_fetch_array($bssResult))
	{
		$ip = $bssRow[ip];
		if(strlen($ip)< 7) continue;
		$bssIpArr[] = $ip;
	}
}//end getBssIp

function getBssDb($bssDbPath,$bssIpAddr)
{
	$fileArr = array('abis.db',	'bscadmin.db',	'calltrc.db',	'sysmon.db',
					'aifadmin.db',	'BssGb.db',	'frmgr.db',	'trkadmin.db');
	$remoteDir = "/hd0/iw07_00.010/compile/cfg/";
	$ftpCon=@ftp_connect($bssIpAddr);
	if($ftpCon < 0){
		echo "<font color=\"#FF0000\">BSS's ip is error or connect $bssIpAddr Failed!</font>";
		flush();
		return 0;
	}
	if(!@ftp_login($ftpCon,'','')){
		echo "<font color=\"#FF0000\">BSS's ip is error or login $bssIpAddr Failed!</font>";
		@ftp_close($ftpCon);
		flush();
		return 0;
	}
	if(!@ftp_chdir($ftpCon, $remoteDir)){
		echo "<font color=\"#FF0000\">Change dir error!</font>";
		@ftp_close($ftpCon);
		flush();
		return 0;
	}
	$localDir = $bssDbPath . $bssIpAddr . '/';
	mkdir($localDir, 0777);
	for($i=0; $i< sizeof($fileArr); $i++) {
		$file = $fileArr[$i];
		$remoteFile=$remoteDir.$file;
		$localFile=$localDir.$file;
		if (!@ftp_get($ftpCon, $localFile, $remoteFile, FTP_BINARY)) {
			flush();
			echo "<font color=\"#FF0000\">Get file error!</font>";
			@ftp_close($ftpCon);
			return 0;
		}
	}//end for
	
	@ftp_close($ftpCon);
	return 1;		
}//end get BssDb
?>
<body leftmargin=12 topmargin=5>
<?php
echo "<table border=\"0\" width=\"100%\">";
echo "<tr>";
echo "<td width=\"50%\">";
echo "$ThisPage";
echo "</td>";
echo "<td width=\"50%\" align=\"right\" title=\"Help\">";
showHelp($helpId);
echo "</td>";
echo "</tr>";
echo "</table>";
?>

<?php
{//get allSysArr
	$allPlatArr = array(
		array('typeNo' => 111, 'name' => 'PLAT'),
		array('typeNo' => 222, 'name' => 'PLAT'),
		array('typeNo' => 223, 'name' => 'PLAT'),
		array('typeNo' => 225, 'name' => 'PLAT')
	);
	
	$selSql = " select * from OMC_PUB.elementExistConf where existFlag=1 and elementTypeNo!=0 order by elementNo";
	$exitRes = mysqli_query($pubConn,$selSql);
	while($exitRows = mysqli_fetch_array($exitRes))
	{
		$typeNo = $exitRows[elementTypeNo];
		if($typeNo==320)
		{
			$typeNo=322;
			$tmpAllSysArr[] = array('typeNo' => 325,	'name' => 'VLR');
		}
		$name = $exitRows[elementName];
		$tmpAllSysArr[] = array('typeNo' => $typeNo,	'name' => $name);
	}
	for($i=0; $i<sizeof($allPlatArr); $i++)
	{
		$tmpAllSysArr[] = $allPlatArr[$i];
	}
	
	$j=0;
	for($i=0; $i<sizeof($tmpAllSysArr); $i++)
	{
		$curSys = $tmpAllSysArr[$i][typeNo];
		$selSql = "select sysNo,subSysNo from OMC_PUB.sysInfo where sysTypeNo=$curSys";
		$result = mysqli_query($pubConn,$selSql);
		$rowNum = mysqli_num_rows($result);
		if($rowNum<=0) continue;
		if($curSys < 300 && $curSys != 225)
		{
			$lastSysNo=-1;
			while($rows = mysqli_fetch_array($result))
			{
				$sysNo=$rows[sysNo];
				$subSysNo = $rows[subSysNo];
				if($curSys > 200 && $sysNo==0) continue;
				
				$sysId = $curSys."_".$sysNo."_99";
				$slcsysId=-1;
				$tlbNo = $sysNo;
				if($curSys==222 || $curSys==223) {
					if(($sysNo==8 || $sysNo==11)) {
						$sysId = $curSys . '_' . $sysNo . '_' . $subSysNo;
					}
					else if($sysNo==9) {
						$sysId = $curSys . '_99_99';
						$slcsysId = $curSys . '_' . $sysNo . '_' . $subSysNo;
						$tlbNo = 99;
					}
				}
				if($curSys==111)
				{
					$slcsysId = $curSys."_".$sysNo."_".$subSysNo;
				}
				$oidsysArr[]= array('oid'=>'2',		'sysid'=> $sysId,	'selectsysid'=> $slcsysId);
				if($sysNo != $lastSysNo)
					$tbNameArr[] = "OBJ_".$curSys.".param_".$tlbNo;
				$lastSysNo=$sysNo;
			}
		}
		if($curSys > 300 || $curSys==225)
		{
			$slcsysId = -1;
			$sysId = $curSys."_99_99";
			$oidsysArr[]= array('oid'=>'2',		'sysid'=> $sysId,	'selectsysid'=> $slcsysId);
			$tbNameArr[] = "OBJ_".$curSys.".param_99";
		}
		$allSysArr[$j] = $tmpAllSysArr[$i];
		$allSysArr[$j][oidsysArr]=$oidsysArr;
		$allSysArr[$j][tbNameArr]=$tbNameArr;
		$j++;
		unset($oidsysArr);
		unset($tbNameArr);
	}
}//end get allSysArr.

{//get subsDbArr.
	$tmpdbArr = array(
		array('typeNo' => '330'),	//HLR
		//array('typeNo' => '325'),	//VLR
		//array('typeNo' => '360'),	//PPS
		array('typeNo' => '340'),	//AUC
		//array('typeNo' => '380'),	//EIR
		array('typeNo' => '370'),	//MNP
		array('typeNo' => '390')//must be the last one.
	);
	for($i=0; $i< sizeof($tmpdbArr); $i++)
	{
		$tmpTypeNo = $tmpdbArr[$i][typeNo]; 
		if($tmpTypeNo==325)$tmpTypeNo=320;
		$selSql = " select * from OMC_PUB.elementExistConf where existFlag=1 and elementTypeNo=$tmpTypeNo";
		$exitRes = mysqli_query($pubConn,$selSql);
		if($exitRow=mysqli_fetch_array($exitRes))
		{
			$tmpsubsDbArr[] = $tmpdbArr[$i];
		}
	}
	for($i=0; $i<sizeof($tmpsubsDbArr); $i++) {
		$sysTypeNo=$tmpsubsDbArr[$i][typeNo];
		$slcSysTypeNo = $sysTypeNo;
		if($sysType==325)$slcSysTypeNo=320;
		$infoSelSql = "SELECT sysNo,subSysNo FROM OMC_PUB.sysInfo WHERE sysTypeNo='$slcSysTypeNo' 
						ORDER BY baseStat DESC,updateTime DESC,sysNo,subSysNo";	
		$infoResult = mysqli_query($pubConn,$infoSelSql);
		if(mysqli_num_rows($infoResult) > 0){
			if($sysTypeNo==390){
				$j=$i;
				while($infoRows = mysqli_fetch_array($infoResult))
				{
					$sysNo		= $infoRows[sysNo];
					$subSysNo	= $infoRows[subSysNo];
					$sysId = $sysTypeNo.'_'.$sysNo.'_'.$subSysNo;
					$subsTlb = "VMS_DB.subscriberData_" . $sysNo;
					$subsDbArr[$j][typeNo] = $sysTypeNo;
					$subsDbArr[$j][sysId] = $sysId;
					$subsDbArr[$j][name]  = 'VMS';
					$subsDbArr[$j][subsTlb] = $subsTlb;
					$j++;
				}
			} else {
				$sysSubsConfTable	='OMC_PUB.sysSubsConf';
				$systemConfTable	= 'OMC_PUB.sysConf';
				$getConfSql="SELECT sysTypeName,dataTypeNo,indexFieldName,subsDataTable,tmpDataTable  
						FROM $sysSubsConfTable,$systemConfTable 
						WHERE $sysSubsConfTable.sysTypeNo='$sysTypeNo' 
						AND $systemConfTable.sysTypeNo='$sysTypeNo'
						AND $sysSubsConfTable.dataTypeNo='$dataTypeNo' 
						";
				$getConfResult=mysqli_query($pubConn,$getConfSql);
				echo mysqli_error($pubConn);
				$getConfRows=mysqli_fetch_array($getConfResult);
				$sysTypeName	=$getConfRows[sysTypeName];
				//$indexFieldName	=$getConfRows[indexFieldName];
				$subsTlb	=$getConfRows[subsDataTable];
				//$tmpDataTable	=$getConfRows[tmpDataTable];
				
				$infoRows = mysqli_fetch_array($infoResult);
				
				$sysNo		= $infoRows[sysNo];
				$subSysNo	= $infoRows[subSysNo];
				$sysId 		= $sysTypeNo.'_'.$sysNo.'_'.$subSysNo;
				
				$subsDbArr[$i][typeNo] = $sysTypeNo;
				$subsDbArr[$i][sysId] = $sysId;
				$subsDbArr[$i][name]  = $sysTypeName;
				$subsDbArr[$i][subsTlb] = $subsTlb;
			}
		}
		
	}
}//end get subsDbArr.

if(1)//get parameters from devices
{
	echo "<font color=\"#0000FF\"><br><b>Getting parameter data from devices ... </b></font>";
	flush();
	for($i=0; $i<sizeof($allSysArr); $i++)
	{
		$oidsysArr=$allSysArr[$i][oidsysArr];
		$sysName = $allSysArr[$i][name];
		if($sysName !== $oldName){
			echo "<br>&nbsp;&nbsp;&nbsp;&nbsp;<font color=\"#0000FF\">[&nbsp;<span class=\"inner\">$sysName</span>&nbsp;]</font>&nbsp;&nbsp;";
			flush();
		}
		GetParam($oidsysArr,0,0);
		$oldName = $sysName;
	}
}//end get parameters from devices

if(file_exists($archivePath))
	exec("rm -rf $archivePath");

if(1)//create parameters' cvs files
{
	echo "<br>";
	echo "<font color=\"#0000FF\"><br><b>Creating parameter tables ... </b></font>";
	exec("mkdir $paremerPath -p");
	exec("chmod -R 777 $paremerPath");
	for($i=0; $i<sizeof($allSysArr); $i++)
	{
		$curSys = $allSysArr[$i][typeNo];
		$sysName = $allSysArr[$i][name];
		if($sysName !== $oldName) {
			echo "<br>&nbsp;&nbsp;&nbsp;&nbsp;<font color=\"#0000FF\">[&nbsp;<span class=\"inner\">$sysName</span>&nbsp;]&nbsp;&nbsp;...&nbsp;&nbsp;</font>";
			flush();
		}
		$tbNameArr = $allSysArr[$i][tbNameArr];
		createParamCVS($paremerPath,$tbNameArr);
		if($sysName !== $oldName) {
			echo "<font color=\"#0000FF\"><b>Finished.</b></font>";
			flush();
		}
		$oldName = $sysName;
	}
}//end create parameters' cvs files

if(1) //get Subscriber data from devices
{
	echo "<br>";
	echo "<font color=\"#0000FF\"><br><b>Getting subscribers data from devices ... </b></font>";
	flush();
	for($i=0; $i<sizeof($subsDbArr); $i++)
	{
		$sysId   = $subsDbArr[$i][sysId];
		$dataTypeNo = 0;
		$sysName = $subsDbArr[$i][name];
		if($sysName !== $oldName){
			echo "<br>&nbsp;&nbsp;&nbsp;&nbsp;<font color=\"#0000FF\">[&nbsp;<span class=\"inner\">$sysName</span>&nbsp;]</font>&nbsp;&nbsp;";
			flush();
		}
		getSubsData($sysId,$dataTypeNo);
		$oldName = $sysName;
	}
}//end get subscriber data from devices.
//exit;
if(1)//create subscribers' cvs files
{
	exec("mkdir $subsPath -p");
	exec("chmod -R 777 $subsPath");
	echo "<font color=\"#0000FF\"><br><b>Creating subscriber tables ... </b></font>";
	for($i=0; $i< sizeof($subsDbArr); $i++)
	{
		$subsTlbName = $subsDbArr[$i][subsTlb];
		$sysId = $subsDbArr[$i][sysId];
		$sysName = $subsDbArr[$i][name];
		if($sysName !== $oldName) {
			echo "<br>&nbsp;&nbsp;&nbsp;&nbsp;<font color=\"#0000FF\">[&nbsp;<span class=\"inner\">$sysName</span>&nbsp;]&nbsp;&nbsp;...&nbsp;&nbsp;</font>";
			flush();
		}
		
		createSubsCVS($subsPath,$subsTlbName,$sysId);
		if($sysName !== $oldName) {
			echo "<font color=\"#0000FF\"><b>Finished.</b></font>";
			flush();
		}
		$oldName = $sysName;
	}//end subscribers table.
}//end create subscribers cvs files.

$selSql = " select * from OMC_PUB.elementExistConf where existFlag=1 and elementTypeNo=500";
$exitRes = mysqli_query($pubConn,$selSql);
if($exitRows = mysqli_fetch_array($exitRes))//get bss data
{
	echo "<br>";
	echo "<font color=\"#0000FF\"><br><b>Getting BSS data ... </b></font>";
	flush();
	
	exec("mkdir $bssOmcTlbPath -p");
	exec("chmod -R 777 $bssOmcTlbPath");
	$tbNameArr = array('BssOmcDb.OMCR_BSSTABLE');
	echo "<br>&nbsp;&nbsp;&nbsp;&nbsp;<font color=\"#0000FF\"><b>Creating parameter tables ... </b></font>";
	createParamCVS($bssOmcTlbPath,$tbNameArr);
	echo "<font color=\"#0000FF\"><b>Finished.</b></font>";
	
	//get bss db.
	exec("mkdir $bssDbPath -p");
	exec("chmod -R 777 $bssDbPath");
	chdir($bssDbPath);
	getBssIp ($bssIpArr);
	for($i=0; $i<sizeof($bssIpArr); $i++) {
		echo "<br>&nbsp;&nbsp;&nbsp;&nbsp;<font color=\"#0000FF\"><b>Getting $bssIpArr[$i] dbs ... <b></font>";
		flush();
		if(getBssDb($bssDbPath,$bssIpArr[$i])){
			echo "<font color=\"#0000FF\"><b>Finished.</b></font>";
			flush();
		}
	}
}//end get bss database.

if(1)//compress files
{
	echo "<br>";
	echo "<font color=\"#0000FF\"><br><b>Compressing files ... <b></font>";
	flush();
	
	if (is_dir($tgzPath))
	{
		exec("rm -rf $tgzPath");
	}
	chdir($archivePath);
	exec("tar zcvf $tgzName *");
	
	exec("mkdir $tgzPath -p");
	exec("chmod -R 777 $tgzPath");
	
	exec("mv $tgzName $tgzPath");
	exec("rm -rf $subsDir $paramDir $bssDir");
	echo "<font color=\"#0000FF\"><b>Finished.</b></font>";
	flush();
}//end compress files.

//exit;
echo "<script language=\"javascript\">";
	echo "window.location=\"downAndUploadAll.php\"";
echo "</script>";
?>
</body>
</html>
