<?php 
require("session_check.php");	

	//语言包引入
	$d_langpackage=new datalp;
	
	$filedb=array();
	$handle=opendir('../doc');
	while($file = readdir($handle)){
		if(eregi("^isns_",$file) && eregi("\.sql$",$file)){
			$strlen=eregi("^isns_",$file) ? 16 + strlen("isns_") : 19;
			$fp=fopen("../doc/$file",'rb');
			$bakinfo=fread($fp,200);
			fclose($fp);
			$detail=explode("\n",$bakinfo);
	 		$bk['name']=$file;
			$bk['version']=substr($detail[1],10);
			$bk['time']=substr($detail[2],8);
			$bk['pre']=substr($file,0,$strlen);
			$bk['num']=substr($file,$strlen,strrpos($file,'.')-$strlen);
			$filedb[]=$bk;
		}
	}
	//导入备份文件
	$operation	= get_argg('operation');
	if($operation=='bakin'){
		$dbo = new dbex;
		dbtarget('w',$dbServs);
		
		$pre	=get_argg('pre');
		bakindata($dbo,'../doc/'.$pre.'_1.sql');
		echo "<script language='javascript'> alert('$d_langpackage->d_lead_suc'); location.href='database.save.php'; </script>";
	}
	//删除备份文件
	$fid=get_argg('fid');
	if($fid){
		$file_pre=$fid."_1.sql";
		delfile('../doc/'.$file_pre);
		echo "$d_langpackage->d_del_suc";exit;
	}
function delfile($filename,$check=1){
	@chmod ($filename, 0777);
	return @unlink($filename);
}
function bakindata($dbo,$filename) {
	$sql=file($filename);
	$query='';
	$num=0;
	foreach($sql as $key => $value){
		$value=trim($value);
		if(eregi("\;$",$value)){
			$query.=$value;
			$dbo->exeUpdate($query);
			$query='';
		} else{
			$query.=$value;
		}
	}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="css/right.css">
<title></title>
</head>
<script language='javascript'>
function create_xmlhttp()
{
	if(window.ActiveXObject){
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}else{
		xmlhttp=new XMLHttpRequest();
	}
}
function del_file(file_id)
{
	 create_xmlhttp();
	 xmlhttp.open("GET","database.recover.php?fid="+file_id,true);
	 xmlhttp.onreadystatechange=function(){
		 if(xmlhttp.readyState==4&&xmlhttp.status==200){
		 	var return_str=xmlhttp.responseText;
			var	return_text=return_str.replace(/[\s\n\r]/g,"");
		 	window.document.getElementById("operate_"+file_id).innerHTML=return_text;
		 	window.document.getElementById("d_operate_"+file_id).innerHTML='';
	 	 }
	 }
	 xmlhttp.send(null);
}
</script>
<body>
  <form action="?operation=post" method="post">
  <div class="container">
	<div class="rs_head"><?php echo $d_langpackage->d_db_cback?></div>
</div>
    <TABLE class="main main_left">
      <tr>
        <th style="width:60px;"><?php echo $d_langpackage->d_db_id?></th>
        <th><?php echo $d_langpackage->d_file_name?></th>
        <th><?php echo $d_langpackage->d_edition?></th>
        <th><?php echo $d_langpackage->d_backup_time?></th>
        <th><?php echo $d_langpackage->d_sub_volume?></th>
        <th width='15%'><?php echo $d_langpackage->d_lead?></th>
        <th style="width:60px;"><?php echo $d_langpackage->d_del?></th>
      </tr>
      <?php foreach($filedb as $n=>$file){?>
      <tr>
      	
        <td><?php echo $n+1;?></td>
        <td><?php echo $file['name'];?></td>
        <td><?php echo $file['version'];?></td>
        <td><?php echo $file['time'];?></td>
        <td><?php echo $file['num'];?></td>
        <td>
        	<div id=operate_<?php echo $file['pre'];?>>
        		<a href="?operation=bakin&pre=<?php echo $file['pre']?>" onclick='return confirm("<?php echo $d_langpackage->d_lead_con?>");'><?php echo $d_langpackage->d_lead?></a>
       		</div>
        </td>
        <td>
        	<div id=d_operate_<?php echo $file['pre'];?>>
	        	<a href='javascript:del_file(<?php echo "\"".$file['pre']."\"";?>);' title="<?php echo $d_langpackage->d_del?>" alt="<?php echo $d_langpackage->d_del?>" onclick='return confirm("<?php echo $d_langpackage->d_del_con?>");'><img src='images/del.png' /></a>
        	</div>
        </td>
      </tr> 
      <?php }?>
    </table>
  </form>
</body>
</html>