コード例 #1
0
ファイル: csv_city.php プロジェクト: seans888/Bgy-Project
    init_var($_POST['btn_submit']);
    if ($_POST['btn_cancel']) {
        log_action('Pressed cancel button');
        redirect("listview_city.php");
    }
    if ($_POST['btn_submit']) {
        log_action('Pressed submit button');
        require 'subclasses/city.php';
        $dbh_city = new city();
        if ($message == "") {
            log_action('Exported table data to CSV');
            $timestamp = date('Y-m-d');
            $token = generate_token(0, 'fs');
            $csv_name = $token . $_SESSION['user'] . '_city_' . $timestamp . '.csv';
            $filename = TMP_DIRECTORY . '/' . $csv_name;
            $csv_contents = $dbh_city->export_to_csv();
            $csv_file = fopen($filename, "wb");
            fwrite($csv_file, $csv_contents);
            fclose($csv_file);
            chmod($filename, 0755);
            $csv_name = urlencode($csv_name);
            $message = 'CSV file successfully generated: <a href="/' . BASE_DIRECTORY . '/download_generic.php?filename=' . $csv_name . '">Download the CSV file.</a>';
            $message_type = 'system';
        }
    }
}
require 'subclasses/city_html.php';
$html = new city_html();
$html->draw_header('CSV Exporter: City', $message, $message_type);
echo '<div class="container">';
echo '<fieldset class="container_invisible">';