if (isset($_POST['export'])) {
    header('Content-Type: text/sql');
    header('Content-Disposition: attachment; filename="' . $_POST['filename'] . '.' . $_POST['export_type'] . '";');
    if (isset($_POST['tables'])) {
        $tables = $_POST['tables'];
    } else {
        $tables = array();
        $tables[0] = $_POST['single_table'];
    }
    $drop = isset($_POST['drop']);
    $structure = isset($_POST['structure']);
    $data = isset($_POST['data']);
    $transaction = isset($_POST['transaction']);
    $comments = isset($_POST['comments']);
    $db = new Database($databases[$_SESSION[COOKIENAME . 'currentDB']]);
    echo $db->export($tables, $drop, $structure, $data, $transaction, $comments);
    exit;
}
//user is importing a file
if (isset($_POST['import'])) {
    $data = file_get_contents($_FILES["file"]["tmp_name"]);
    $db = new Database($databases[$_SESSION[COOKIENAME . 'currentDB']]);
    $importSuccess = $db->import($data);
}
// here begins the HTML.
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv='Content-Type' content='text/html; charset=UTF-8' />
<title><?php 
Example #2
0
                    }
                }
            }
            //echo $update;
            break;
        case "create":
            //检查权限
            $func = 'system-backup-add';
            System::check_func($func, FALSE);
            $name = getgpc('name');
            if (!$name) {
                System::redirect($jump, "备份名称不能为空!");
            } elseif (!preg_match('/^[^\\/\\\\?!\\*]+$/', $name)) {
                System::redirect($jump, "备份名称中有非法字符!");
            } else {
                $stat = Database::export($name, getgpc('prefix'), getgpc('option'));
                if ($stat) {
                    //写入日志
                    System::insert_event($func, time(), time(), "数据备份:" . $name . ".sql");
                    echo '<div id="state">恭喜!成功备份数据库,共有 ' . $stat . ' 条记录。</div>';
                } else {
                    echo '<div id="state" class="failure">抱歉!备份数据库失败。</div>';
                }
            }
            break;
    }
    //关闭数据库
    System::connect();
}
?>