<?php 

//禁止直接访问
!defined('IN_SYSTEM') && exit('Access Denied');

//一键备份
//是否提交
if($AdminLogin->IsPost(array('DbmanageInputKey'), 'backup')){
	//来路判断
	if($AdminLogin->CheckHttpReferer(WEB_URL.'/admin/index.php?location=dbmanage') == true){
		//验证方法
		$AdminLogin->CheckPostFun = array(
				'DbmanageInputKey' => array(array('ToUtf8', 'trimall', 'DeleteHtml', 'strip_tags'), array('CheckNull', 'CheckPostInputKey'))
		);
		//验证数据
		if($AdminLogin->CheckPostValue()){
			//过滤后的用户提交的数据
			$UserPostValue = $AdminLogin->Post;
			//判断InputKey
			if($AdminLogin->CheckValue($UserPostValue['DbmanageInputKey'], $_SESSION['DbmanageInputKey'])){
				//实例化文件操作类
				$File = new File();
				//新的文件夹名称
				$newdirname = date("YmdHis").'_'.generate_rand_string(10);
				//新建文件夹
				if($File->CreateDirs("data/backup/".$newdirname)){
					//要备份的数据库
					$BackupDB = new DBManage ($DbHostAddress, $DbUserName, $DbPassword, $DbName, 'utf8' );
					//执行备份操作
					if($BackupDB->backup(null, SITE_DIR.'data/backup/'.$newdirname."/", 2000) !== false){
						$AdminShowMessage = AdminShowMessage('数据备份成功！', WEB_URL.'/admin/index.php?location=dbmanage', 1);
					}
					else{
						$AdminShowMessage = AdminShowMessage('备份失败！请检查原因！', WEB_URL.'/admin/index.php?location=dbmanage', 0, '#F00');
					}	
				}
				else{
					$AdminShowMessage = AdminShowMessage('备份文件夹创建失败！', WEB_URL.'/admin/index.php?location=dbmanage', 0, '#F00');	//文件夹创建失败
				}				
			}
			else{
				$AdminShowMessage = AdminShowMessage('来路不正确！', WEB_URL.'/admin/index.php?location=dbmanage', 0, '#F00');	//InputKey不正确
			}			
		}
		else{
			$AdminShowMessage = AdminShowMessage('非法提交！', WEB_URL.'/admin/index.php?location=dbmanage', 0, '#F00');	//验证不通过
		}		
	}
	else{
		$AdminShowMessage = AdminShowMessage('来路不正确！', WEB_URL.'/admin/index.php?location=dbmanage', 0, '#F00');	//来路不正确
	}
	//销毁inputkey确保只能使用一次
	$_SESSION['DbmanageInputKey'] = '';	
}	
//删除文件
//是否提交
elseif($AdminLogin->IsPost(array('del', 'DbmanageInputKey'), 'del_sel')){
	//来路判断
	if($AdminLogin->CheckHttpReferer(WEB_URL.'/admin/index.php?location=dbmanage') == true){
		//验证方法
		$AdminLogin->CheckPostFun = array(
				'del' => array(array('ToUtf8', 'trimall', 'DeleteHtml', 'strip_tags'), array('CheckNull', 'CheckDbBackfile')),
				'DbmanageInputKey' => array(array('ToUtf8', 'trimall', 'DeleteHtml', 'strip_tags'), array('CheckNull', 'CheckPostInputKey'))
		);
		//验证数据
		if($AdminLogin->CheckPostValue()){
			//过滤后的用户提交的数据
			$UserPostValue = $AdminLogin->Post;
			//判断InputKey
			if($AdminLogin->CheckValue($UserPostValue['DbmanageInputKey'], $_SESSION['DbmanageInputKey'])){
				//实例化文件操作类
				$File = new File();
				$return = true;
				foreach($UserPostValue['del'] as $v){
					if($v !== 'IsPost' && $v !== 'SelALLBox'){
						if($File->delDirAndFile('data/backup/'.$v.'/', true) == 1){
							$return = true;
						}
						else{
							$return = false;
						}
					}
				}
				if($return == true){
					$AdminShowMessage = AdminShowMessage('选中的文件删除成功！', WEB_URL.'/admin/index.php?location=dbmanage', 1);
				}
				else{
					$AdminShowMessage = AdminShowMessage('删除失败！', WEB_URL.'/admin/index.php?location=dbmanage', 0, '#F00');
				}
			}
			else{
				$AdminShowMessage = AdminShowMessage('来路不正确！', WEB_URL.'/admin/index.php?location=dbmanage', 0, '#F00');	//InputKey不正确
			}
		}
		else{
			$AdminShowMessage = AdminShowMessage('非法提交！', WEB_URL.'/admin/index.php?location=dbmanage', 0, '#F00');	//验证不通过
		}
	}
	else{
		$AdminShowMessage = AdminShowMessage('来路不正确！', WEB_URL.'/admin/index.php?location=dbmanage', 0, '#F00');	//来路不正确
	}
	//销毁inputkey确保只能使用一次
	$_SESSION['DbmanageInputKey'] = '';	
}
else{
	$AdminShowMessage = AdminShowMessage('提交失败！', WEB_URL.'/admin/index.php?location=dbmanage', 0, '#F00');	//表单未提交
}
?>