<?php
//
// Created on: 25 Dec 2001
// Usage: data_upload.php?[language="eng|gb"]
//                        &bssid=0
// 
// Function: Upload BSC parameters to OMC progressively
//
//
// curr_step 0: Display a confirm dialogue
// curr_step 2: Upload the updated  parameters from BSC to OMC
//
//
?>
<?php
$debug=1;

include("nocache.inc");
include("header.inc");
include("login_parm.inc");
//include("ip2name.inc");
//include("read_bssdist.inc");
include("data_upload.inc");
include("upload.inc");


if (!isset($language))
	$language="eng";
if (!isset($curr_step))
	$curr_step=0;
$parameter="${language}namearray";

$db = mysql_connect($hostname, $username, $password);
mysql_select_db($dbname,$db);
?>
<HTML>
<HEAD>

<SCRIPT Language="JavaScript" type="text/javascript">
<!--
	function refresh_screen()
	{
		if (document.myForm.reload_it.value == 1)
		{
			window.location.href =
				"data_upload.php?language=<?=$language?>&bssid=<?=$bssid?>&curr_step=<?=($curr_step+1)?>";
		}
		return;
	}	
//-->
</SCRIPT>

</HEAD>

<?php

/*******************************************************
 Display Text in each Step
 *******************************************************/
$steps = Array(
	1 => ${$parameter}[step1],
	2 => ${$parameter}[step2],
	3 => ${$parameter}[step3]
);


echo "<BODY onLoad='refresh_screen();'>\n";
echo "<font size=+2 color=blue>{${$parameter}[header]}</font><HR>\n";

if ($curr_step == 0)
{
	echo "{${$parameter}[confirm_qu]}<BR>\n";
	echo "<FORM name=myForm>\n";
	echo "<INPUT type=button value={${$parameter}[confirm]} onClick='javascript:location.href=\"data_upload.php?language=$language&bssid=$bssid&curr_step=1\"'>\n";
	echo "<INPUT type=button value={${$parameter}[back]} onClick='javascript:location.href=\"modifyBssParam.php?language=$language&bssid=$bssid\"'>\n";
	echo "<INPUT type=hidden name=reload_it value=0>\n";
	echo "</FORM>\n";
}
else
{
	/*****************************************
 	 * Display pre-defined text
 	 *****************************************/
	for ($i=1; $i<$curr_step; $i++)
	{
		echo $steps[$i] . " ... {${$parameter}[done]}<BR>\n";
		flush();
	}

	echo $steps[$curr_step] . "<BR>\n";
	flush();
	$retval=-1;
	switch ($curr_step)
	{
		case 1: $retval = upload_parameters($db,$bssid,$debug);
				flush();
				sleep(2);
			break;
		default:
			break;
	}
}


/*****************************************
 * Stop refreshing when all tasks finished
 *****************************************/
if ($curr_step >= sizeof($steps))
{
	echo "<FORM name=myForm>\n";
	echo "<HR><INPUT type=button value={${$parameter}[back]} onClick='javascript:location.href=\"modifyBssParam.php?language=$language&bssid=$bssid\"'>\n";
	echo "<INPUT type=hidden name=reload_it value=0>\n";
	echo "</FORM>\n";
}
else if ($curr_step > 0)
{
	if ($retval == 0)
	{
		echo "<FORM name=myForm>\n";
		echo "<INPUT type=hidden name=reload_it value=1>\n";
		echo "</FORM>\n";
	}
	else /* Failed */
	{
		echo "<font size=+1 color=red> ... {${$parameter}[uploadfail]} </font><BR>\n";
		echo "<FORM name=myForm>\n";
		echo "<HR><INPUT type=button value={${$parameter}[back]} onClick='javascript:location.href=\"modifyBssParam.php?language=$language&bssid=$bssid\"'>\n";
		echo "<INPUT type=hidden name=reload_it value=0>\n";
		echo "</FORM>\n";
	}
}
?>

</BODY>
</HTML>
