<?php
namespace app\hsycms\controller;
use think\Controller;
use app\hsycms\controller\Base;
use sy\DbManage;
use sy\Backup;

class Database extends Base
{
	public $root; 	//备份目录
	public function __construct(){
		parent::__construct();
		$this->root = ROOT_PATH . 'public/backup/';		
		$this->assign("root",$this->root);
	}
	
	
	//数据库备份
	public function backup(){
	   $type=input("at");
       $name=input("name");	
	   $sql= new Backup();  	   
       $db= new DbManage();
       switch ($type)
        {
        case "backup": //备份		  
		  $db->backup();		 
		  break;     	
        default: //获取数据库文件列表
			$list = $sql->dataList();	
			$this->assign("list",$list);   
            return $this->fetch(); 
          
        }
	}
	
	//还原备份
	public function importsql(){
	   $type=input("at");
       $name=input("name");	
	   $sql= new Backup();  	   
       $db= new DbManage();	  
       switch ($type)
        {        
        default: //获取备份文件列表			
			$list = scandir($this->root);
			array_splice($list, 0, 2); //array_splice删除数组并索引重组			
			$this->assign("list",$list);   
            return $this->fetch(); 
          
        }
	}
	
}