<?php
# Subroutine: adm_backup.php called by Admin.php
# Xinfeng Chen, 2002.12.19

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");
require_once('core/base_array_file.php');
require_once('core/class_board_list.php');

#--- Generate board selection ---
$oBrdLst=new CBoardList;
$oBrdLst->load();
$blsize=$oBrdLst->itemcount();

$brdSelection='<SELECT name=f_bid>';
$dir=opendir('./style');
for($i=0; $i<$blsize; $i++){
 $oBrdLst->moveTo($i);
 $brdSelection.="<option value='$oBrdLst->id'>$oBrdLst->name(ID=$oBrdLst->id)</option>";
}
$brdSelection.='</SELECT>';

#--- Print backup form ---
page_header();

print <<<EOT
<h1>论坛数据备份</h1>
<p>备份单个论坛数据、用户信息、或所有论坛数据。每次备份生成一个备份文件，存放于论坛数据目录下的 backup 子目录下，管理员可使用 FTP 工具下载或删除。</p>
<form action=admin.php method=post>
<input type=hidden name=cmd value="backup_submit">
<table width=90% border=0 cellspacing=1 cellpadding=3 align=center class=forumLine>
<tr>
 <th align="center" class="thHead">选择需备份论坛数据</th>
</tr>
<tr>
 <td align="left" class="row1"><input type="radio" name=f_scope value='ALL' checked>
备份所有论坛数据(包括论坛数据、用户信息、系统数据).<br>
 <input type="radio" name=f_scope value='USER'>
只备份用户信息.<br>
 <input type="radio" name=f_scope value='BOARD'>
只备份指定论坛数据. 选择要备份的论坛: $brdSelection </td>
</tr>
<tr>
 <td class="row3" align="center">
 <input type=submit value=" 执行备份 " name="submit"></td>
</tr>
</table>
</form>
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>
</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>
</tr>
EOT;
  }
 }
 closedir($dir);
}

print "</TABLE>";

page_footer();

?>