<?php

function stats($caption,$myprogress,$totalnum)
{
    global $rootURL, $CancelURL, $admin;
    
    if($totalnum>0)
    {
      $pct=round(($myprogress/ $totalnum)*100);
    }
    else
    	$pct = 100;
    
    $o .='					<td>
						<img src="images/icon_install.gif" width="46" height="46" alt="" align="absmiddle">&nbsp;<span class="admintitle">'.$caption.'</span><br><br>
				'.section_header('Step 2 - '.$caption.' - '.$pct.'%', true).'			
			      <table border=0 cellpadding=0 cellspacing=0 width="100%" class="toolbar">
			      	<tr>
								<td><img src="images/toolbar/tool_cancel.gif" id="img_Cancel" width="32" height="32" border="0" alt="Next Category" onMouseOut="swap(\'img_Cancel\', \'toolbar/tool_cancel.gif\');" onMouseOver="swap(\'img_Cancel\',\'toolbar/tool_cancel_f2.gif\');" onClick="history.go(-1);"></td>
								<!--<td><img src="images/toolbar/tool_divider.gif" width="4" height="32" border="0"><br></td>-->
								<td width="100%">&nbsp;</td>
							</tr>
						</table>
						<!-- toolbar button \\-->
						
						<table width="100%" border="0" cellspacing="0" cellpadding="0" class="tableborder">
	            <tr valign="top">
	            	<td width="60%" bgcolor="#F0F0F0"><table width="100%" height="100%" border="0" cellspacing="0" cellpadding="4">';
    
    echo "\n";   
    
    $o .= "				            <tr class=\"table_color2\">				              
				              <td ALIGN=\"center\"><br>
<TABLE CLASS=\"tableborder_full\" width=\"75%\">
    <TR border=1><TD bgcolor=\"#507F15\" width=\"".$pct."%\">&nbsp;</TD>";
    $comp_pct = 100-$pct;
    $o .= "  <TD bgcolor=#FFFFFF width=\"".$comp_pct."%\"></TD></TR>";
    $o .= "  </TABLE><BR /><input type=button VALUE=\"Cancel\" CLASS=\"button\" ONCLICK=\"document.location='".$CancelURL."';\">
				              </td>
				            </tr></table></td>";
    
    //$o .= "<!--<tr><td  class=\"tabletitle\" STYLE=\"border: 1px solid #000000;\" bgcolor=\"#333333\">".$caption."-".$pct."%</td></tr>-->";
    //$o .= "<TR><TD  align=\"middle\" bgcolor=\"#F0F0F0\"><br />"; 
    //$o .= "  <TABLE CLASS=\"tableborder_full\" width=\"75%\">";
    //$o .="  <TR border=1><TD bgcolor=\"#507F15\" width=\"".$pct."%\">&nbsp;</TD>";
    //$comp_pct = 100-$pct;
    //$o .= "  <TD bgcolor=#FFFFFF width=\"".$comp_pct."%\"></TD></TR>";
    //$o .= "  </TABLE>";
    //$o .= "  <BR /><input type=button VALUE=\"Cancel\" CLASS=\"button\" ONCLICK=\"document.location='".$CancelURL."';\">";
    echo $o."\n";
    //echo "</TD></TR></TABLE></td>";
}

function reload($url)
{
	print "<script language=\"javascript\">" ;
	print "setTimeout(\"document.location='$url';\",40);";
	print " </script>";
	//echo "<A HREF=\"$url\">Next </A>";
}

$TotalSize = filesize($backupfile);

$MaxLines = 200;

$PageTitle = "Restore In Progress";
$CancelURL =   $rootURL ."admin/install.php";

stats($PageTitle,$FileOffset,$TotalSize);

if($FileOffset < $TotalSize)
{
  $FileOffset = RunRestoreFile($ado,$backupfile,$FileOffset,$MaxLines);
  if($FileOffset>-1)
  {
    	if ($_POST['next_step']) {
    		$next_step = $_POST['next_step'];
    	}
    	else if ($_GET['next_step']) {
    		$next_step = $_GET['next_step'];
    	}  
    	//$next_step--;	
  	if($FileOffset ==0)
  	  $FileOffset = $TotalSize;
  	$backupfile = SuperStrip($backupfile);
    $url = $_SERVER['PHP_SELF']."?Offset=$FileOffset&File=$backupfile&state=restore_run&next_step=$next_step&install_type=$install_type&show_prev=1";
  }
  else 
  {  	
  	switch($FileOffset)
  	{
  		case -1:
  			$error =  prompt_language("la_restore_file_error");
  		break;
  		case -2:
  			$error = prompt_language("la_restore_read_error");
  		break;
  		default:
  			$error = "(".$FileOffset.") ".prompt_language("la_restore_unknown_error");
  		break;
  	}
  	echo $error;
  	die();  		
  }  
}
else {
    	if ($_POST['next_step']) {
    		$next_step = $_POST['next_step'];
    	}
    	else if ($_GET['next_step']) {
    		$next_step = $_GET['next_step'];
    	}
    		
  $url = $_SERVER['PHP_SELF']."?state=finish&next_step=$next_step&install_type=$install_type";
}

reload($url);

?>        
<!--<br>
<p class="error"><?php echo $restore_error; ?></p> -->