<?php   
if( !(isset($pathtoroot) && $pathtoroot) )
{
  $path=dirname(realpath(__FILE__));
  if(strlen($path))
  {
    /* determine the OS type for path parsing */
    $pos = strpos($path,":");
    if ($pos === false)
    {
      $gOS_TYPE="unix";
      $pathchar = "/";
    }
    else
    {
      $gOS_TYPE="win";
      $pathchar="\\";
    }
    $p = $path.$pathchar;
    /*Start looking for the root flag file */
    if( !isset($pathtoroot) ) $pathtoroot = '';
    while(!strlen($pathtoroot) && strlen($p))
    {
      $sub = substr($p,strlen($pathchar)*-1);
      if($sub==$pathchar)
      {
        $filename = $p."root.flg";
      }
      else
        $filename = $p.$pathchar."root.flg";
      if(file_exists($filename))
      {
        $pathtoroot = $p;
      }
      else
      {
        $parent = realpath($p.$pathchar."..".$pathchar);
	if($parent!=$p)
	{
	  $p = $parent;
	}
	else
	  $p = "";
      }
    }
    if( !(isset($pathtoroot) && $pathtoroot) )
      $pathtoroot = ".".$pathchar;
  }
  else
  {
    $pathtoroot = ".".$pathchar;
  }
}

$sub = substr($pathtoroot,strlen($pathchar)*-1);
if($sub!=$pathchar)
{
  $pathtoroot = $pathtoroot.$pathchar;
}

require_once($pathtoroot."kernel/startup.php");
$rootURL="http://".ThisDomain().$objConfig->Get("Site_Path");
$admin = $objConfig->Get("AdminDirectory");
if(!strlen($admin))
    $admin = "admin";    
$adminURL = $rootURL.$admin;
$localURL=$rootURL."kernel/";
$imagesURL = $rootURL."admin/images";
//admin only util
$pathtolocal = $pathtoroot."kernel/";
require_once ($pathtoroot."admin/include/elements.php");
require_once ($pathtoroot."kernel/admin/include/navmenu.php");
require_once ($pathtolocal."admin/include/navmenu.php");
require_once($pathtoroot."admin/toolbar.php");
//Set Section

$section = "in-portal:restore";
//Set Environment Variable
$envar = "env=" . BuildEnv();   
$sec = $objSections->GetSection($section);
$objCatToolBar = new clsToolBar();
$formaction = $rootURL."admin/backup/restore3.php?".$envar;
$formaction = "restore3.php?".$envar;
$restoreexit = $rootURL."admin/backup/restore4.php?".$envar;
$conn = &GetADODBConnection();


$totalfiles =   $objSession->GetVariable("restore_files_num");
$filepath = $objConfig->Get("Backup_Path");

if (true)
{	
   if($en_prev>-1)
  {
    $MouseOver="swap('moveleft','toolbar/tool_prev_f2.gif');";
    $MouseOut="swap('moveleft', 'toolbar/tool_prev.gif');";
    $onClick= $sec->Get("onclick");
    $var="?env=".BuildEnv();
    $link=$PHP_SELF.$var;
    $objCatToolBar->Add("moveleft",admin_language("la_ToolTip_Previous")." ".admin_language("la_Text_Step"),$link,$MouseOver,$MouseOut,"","tool_prev.gif");
  }
  else
  {
    $MouseOver="swap('moveleft','toolbar/tool_prev_f2.gif');";
    $MouseOut="swap('moveleft', 'toolbar/tool_prev.gif');";
    $var="?env=".BuildEnv();
    $link=$rootURL."admin/backup/restore1.php".$var;
    
    $objCatToolBar->Add("moveleft",admin_language("la_ToolTip_Previous")." ".admin_language("la_Text_Step"),$link,$MouseOver,$MouseOut,"","tool_prev.gif");
  }  
  
  	$MouseOver="if (document.restore2.backupdate.value) swap('moveright','toolbar/tool_next_f2.gif');";
    $MouseOut="if (document.restore2.backupdate.value) swap('moveright', 'toolbar/tool_next.gif');";  
    $var="?env=".BuildEnv();

    $onClick="restore_submit('restore2','$formaction');";
    $link="#";
    $objCatToolBar->Add("moveright",admin_language("la_ToolTip_Next")." ".admin_language("la_Text_Step"),$link,$MouseOver,$MouseOut,$onClick,"tool_next_f3.gif");

}
//$link2=$rootURL."admin/backup/restore3.php".$var;
//$onClick="document.location= '$link2';";
//$onClick="restore_submit('restore2','$formaction');";
//$MouseOver="swap('img_edit','toolbar/tool_edit_f2.gif');";
//$MouseOut="swap('img_edit', 'toolbar/tool_edit.gif');";
//$objCatToolBar->Add("img_edit","la_ToolTip_Restore","#", $MouseOver,$MouseOut,$onClick,
//                    "tool_edit.gif");

$link3=$rootURL."admin/backup/restore2.php".$var;


$objCatToolBar->Add("img_del","la_ToolTip_Delete","#", "swap('img_del','toolbar/tool_delete_f2.gif');",
                    "swap('img_del', 'toolbar/tool_delete.gif');","restore_delete();",
                    "tool_delete.gif");


int_header($objCatToolBar,NULL,$title);

//phpinfo(INFO_VARIABLES);

function getDirList ($dirName) 
{  
    global $objSession;
    $filedates = array();
    $d = dir($dirName); 

    while($entry = $d->read()) 
    { 
        if ($entry != "." && $entry != "..") 
        { 
            if (!is_dir($dirName."/".$entry) && eregi("dump",$entry)) 
            { 
                $shortversion=chopchop($entry);     
                $filedate[]=$shortversion;

            } 
        }  
    } 
    $d->close(); 
    rsort($filedate);

    return $filedate;

} 
function chopchop ($filename)
{
	 $p = pathinfo($filename);
	 $ext = $p["extension"];
     $filename;
     $filename= ereg_replace("dump","",$filename);
     $filename= ereg_replace($ext,"",$filename);
     return $filename;
}

?>
<TABLE CELLPADDING=0 CELLSPACING=0 class="tableborder" width="100%">
<?php   int_subsection_title(admin_language("la_Prompt_Restore_Filechoose"));   ?>
<TBODY>
 <tr BGCOLOR="#e0e0da">
   <td WIDTH="100%" CLASS="navar">
     <img height="15" src="<?php echo $imagesURL; ?>/arrow.gif" width="15" align="middle" border="0">
     <span class="NAV_CURRENT_ITEM"><?php echo admin_language("la_Prompt_Backup_Date"); ?></span>
   </td>
 </TR>
</TBODY>
</TABLE>
<TABLE CELLPADDING=0 CELLSPACING=0 class="tableborder" width="100%">
<TBODY>
<FORM NAME="restore2" ID="restore2" method="POST" action="<?php echo $adminURL."/backup/restore2.php?".$envar; ?>">
<?php
        $datearray=getDirList($filepath);
        foreach($datearray as $key => $value)
        {
          echo "<TR ". int_table_color_ret().">";
          $onClick =  "swap('moveright', 'toolbar/tool_next.gif');";

          echo "<TD valign=\"top\"><span class=\"text\"><input type=radio NAME=\"backupdate\" onclick=\"$onClick\" VALUE=\"".$value."\" >";
          echo date("F j, Y, g:i a",$value)."</TD>";
        }   
        
?>
    <input TYPE="hidden" NAME="Action" VALUE="">
</FORM>
</TABLE>
<?php
int_footer();
?>