format $crlf = which_crlf(); /** * Ensure zipped formats are associated with the download feature */ if (empty($asfile) && (!empty($gzip) || !empty($bzip))) { $asfile = 1; } /** * Send headers depending on whether the user choosen to download a dump file * or not */ // No download if (empty($asfile)) { $cfgServer_backup = $cfgServer; include('./header.inc.php3'); $cfgServer = $cfgServer_backup; unset($cfgServer_backup); echo '
' . "\n"; echo '
' . "\n";
} // end if

// Download
else {
    // Defines filename and extension
    if (!isset($table)) {
        $filename = $db;
    } else {
        $filename = $table;
    }
    if (isset($bzip) && $bzip == 'bzip') {
        $ext = 'bz2';
    } else if (isset($gzip) && $gzip == 'gzip') {
        $ext = 'gz';
    } else if ($what == 'csv') {
        $ext = 'csv';
    } else {
        $ext = 'sql';
    }

    // Send headers
    header('Content-Type: application/octetstream');
    header('Content-Disposition: filename="' . $filename . '.' . $ext . '"');
    header('Pragma: no-cache');
    header('Expires: 0');
} // end download


/**
 * Builds the dump
 */
// Gets the number of tables if a dump of a database has been required
if (!isset($table)) {
    $tables     = mysql_list_tables($db);
    $num_tables = @mysql_numrows($tables);
} else {
    $num_tables = 1;
    $single     = TRUE;
}

// No table -> error message
if ($num_tables == 0) {
    echo '# ' . $strNoTablesFound;
}
// At least on table -> do the work
else {
    // No csv format -> add some comments at the top
    if ($what != 'csv') {
        $dump_buffer       .= '# phpMyAdmin MySQL-Dump' . $crlf
                           .  '# version ' . PHPMYADMIN_VERSION . $crlf
                           .  '# http://phpwizard.net/phpMyAdmin/' . $crlf
                           .  '# http://phpmyadmin.sourceforge.net/ (download page)' . $crlf
                           .  '#' . $crlf
                           .  '# ' . $strHost . ': ' . $cfgServer['host'];
        if (!empty($cfgServer['port'])) {
            $dump_buffer   .= ':' . $cfgServer['port'];
        }
        $formatted_db_name = (isset($use_backquotes))
                           ? backquote($db)
                           : '\'' . $db . '\'';
        $dump_buffer       .= $crlf
                           .  '# ' . $strGenTime . ': ' . date('F j, Y, g:i a') . $crlf
                           .  '# ' . $strServerVersion . ': ' . MYSQL_MAJOR_VERSION . '.' . MYSQL_MINOR_VERSION . $crlf
                           .  '# ' . $strPHPVersion . ': ' . phpversion() . $crlf
                           .  '# ' . $strDatabase . ': ' . $formatted_db_name . $crlf;

        $i = 0;
        if (isset($table_select)) {
            $tmp_select = implode($table_select, '|');
            $tmp_select = '|' . $tmp_select . '|';
        }
        while ($i < $num_tables) {
            if (!isset($single)) {
                $table = mysql_tablename($tables, $i);
            }
            if (isset($tmp_select) && is_int(strpos($tmp_select, '|' . $table . '|')) == FALSE) {
                $i++;
            } else {
                $formatted_table_name = (isset($use_backquotes))
                                      ? backquote($table)
                                      : '\'' . $table . '\'';
                // If only datas, no need to displays table name
                if ($what != 'dataonly') {
                    $dump_buffer.= '# --------------------------------------------------------' . $crlf
                                .  $crlf . '#' . $crlf
                                .  '# ' . $strTableStructure . ' ' . $formatted_table_name . $crlf
                                .  '#' . $crlf . $crlf
                                .  get_table_def($db, $table, $crlf) . ';' . $crlf;
                }
                // At least data
                if (($what == 'data') || ($what == 'dataonly')) {
                    $dump_buffer .= $crlf . '#' . $crlf
                                 .  '# ' . $strDumpingData . ' ' . $formatted_table_name . $crlf
                                 .  '#' . $crlf .$crlf;
                    $tmp_buffer  = '';
                    if (!isset($limit_from) || !isset($limit_to)) {
                        $limit_from = $limit_to = 0;
                    }
                    get_table_content($db, $table, $limit_from, $limit_to, 'my_handler');
                    $dump_buffer .= $tmp_buffer;
                } // end if
                $i++;
            } // end if-else
        } // end while

        // Don't remove, it makes easier to select & copy frombrowser - staybyte
        $dump_buffer .= $crlf;
    } // end 'no csv' case

    // 'csv' case
    else {
        $tmp_buffer = '';
        get_table_csv($db, $table, $limit_from, $limit_to, $separator, 'my_csvhandler');
        $dump_buffer .= $tmp_buffer;
    } // end 'csv case
} // end building the dump


/**
 * "Displays" the dump...
 */
// 1. as a bzipped file
if (isset($bzip) && $bzip == 'bzip') {
    if (@function_exists('bzcompress')) {
        echo bzcompress($dump_buffer);
    } 
}
// 2. as a gzipped file
else if (isset($gzip) && $gzip == 'gzip') {
    if ($gzip == 'gzip' && @function_exists('gzencode')) {
        // without the optional parameter level because it bug
        echo gzencode($dump_buffer);
    }
}
// 3. on screen
else {
    echo $dump_buffer;
}


/**
 * Close the html tags and add the footers in dump is displayed on screen
 */
if (empty($asfile)) {
    echo '    
' . "\n"; echo '
' . "\n"; echo "\n"; include('./footer.inc.php3'); } // end if ?>