<?php
# Subroutine: adm_restore.php called by Admin.php
# Xinfeng Chen, 2002.12.20

require_once('bin/config.php');
require_once('admin/adm.inc');

#--- Validate dministrator ---
include('admin/adm_validate.php');
if(!$adm_validated){jumpTo('admin.php?cmd=logon'); exit;}

#--- Start Processing ---
require_once('core/class_forum_base.php');
CForumBase::setFileBase("$filepath");

#--- Print restore selection page ---
page_header();

print <<<EOT
<h1>论坛数据还原</h1>
<p>要还原论坛数据，请确认论坛数据目录存在(可使用setup.php程序重建)，并确认备份文件放置于论坛数据目录的 backup 子目录下。选择需要使用的备份文件，进行数据还原操作。</p>
EOT;

#--- Display existed backup files ---
$backupPath=CForumBase::getDirPath('BACKUP');

print <<<EOT
<TABLE width="90%" align="center" class="forumline">
<tr>
 <th>已有备份文件</th>
 <th>文件大小</th>
 <th>备份时间</th>
 <th>执行用户</th>
 <th>备份策略</th>
 <th>论坛ID</th>
 <th>还原</th>
</tr>
EOT;

if(file_exists($backupPath) && is_dir($backupPath)){
 $dir=opendir($backupPath);
 while ($file=readdir($dir)){
  $fname="$backupPath/$file";
  if(is_file($fname)){
   $fsize=ceil(filesize($fname)/1024);
   $fp=fopen($fname,'rb');
   $head=fread($fp,64);
   fclose($fp);
   list($tag,$bscope,$bid,$bts,$buser)=
    explode('|',$head);
   $btime=strftime("%Y-%m-%d %H:%M:%S",$bts);
   if($bscope != 'BOARD'){$bid='';}

   print <<<EOT
<tr>
 <td class="row1">$file</td>
 <td class="row2" align=right>{$fsize}K</td>
 <td class="row1">$btime</td>
 <td class="row2" align=center>$buser</td>
 <td class="row1" align=center>$bscope</td>
 <td class="row2">$bid</td>
 <td class="row1"><a href=?cmd=restore_confirm&file=$file>还原</a></td>
</tr>
EOT;
  }
 }
 closedir($dir);
}

print "</TABLE>";

page_footer();

?>