<?
	include ("../common.php");

/*
	$sysop = mysql_fetch_object(db_query("SELECT account, password FROM user WHERE account='sysop'"));
	if ( !$sysop || ($sysop->account != $USER_ACCOUNT) || ($sysop->password != $USER_PASSWORD) )
	{
		echo $msgNoPermission;
		exit;
	}
*/

	// load c:\XMS\xmsync.ini

	$fp = fopen("$APP_ROOT/xmsync.ini", "r");
	if (!fp)
	{
		echo "File load error: xmsync.ini";
		exit;
	}

	$s = fgets($fp);
	fclose($fp);
	if (!$s)
	{
		echo "File read error: xmsync.ini";
		exit;
	}

	$bkupdir = $s;

	// step 1 : restore mySQL

	$cmd = "$APP_ROOT/mysql/bin/mysql.exe -u root -pezlms $PHP_ROOT < $bkupdir/www/xms-bkup.sql";
	$ans1 = exec($cmd, $rx, $rc);

	// step 2 : restore XML RPC

	$path = "$WEB_ROOT/xmlrpc_service9"
	$path_old = $path . '.old';
	system("rm -fr $path_old");
	rename($path, $path_old);
	$path = strtr($path, "/", "\\");
	$cmd = "$SystemRoot/xmsync.exe -d restore2.log $bkupdir\\www\\xmlrpc $path";
	$ans2 = exec($cmd, $rx, $rc);

	// step 3 : restore XMS data

	$path = "$WEB_ROOT/$PHP_ROOT/data9"
	$path_old = $path . '.old';
	system("rm -fr $path_old");
	rename($path, $path_old);
	$path = strtr($path, "/", "\\");
	$cmd = "$SystemRoot/xmsync.exe -d restore1.log $bkupdir\\www\\xms\\data $path";
	$ans3 = exec($cmd, $rx, $rc);

?>