/Web/Maintenance/phpMyAdmin/libraries/export/csv.php
0,0 → 1,183
<?php
/* $Id: csv.php,v 2.9 2006/01/17 17:03:02 cybot_tm Exp $ */
// vim: expandtab sw=4 ts=4 sts=4:
 
/**
* Set of functions used to build CSV dumps of tables
*/
 
/**
* Outputs comment
*
* @param string Text of comment
*
* @return bool Whether it suceeded
*/
function PMA_exportComment($text) {
return TRUE;
}
 
/**
* Outputs export footer
*
* @return bool Whether it suceeded
*
* @access public
*/
function PMA_exportFooter() {
return TRUE;
}
 
/**
* Outputs export header
*
* @return bool Whether it suceeded
*
* @access public
*/
function PMA_exportHeader() {
global $what;
global $add_character;
global $export_separator;
global $enclosed;
global $escaped;
 
// Here we just prepare some values for export
if ($what == 'excel') {
$add_character = "\015\012";
$export_separator = isset($GLOBALS['excel_edition']) && $GLOBALS['excel_edition'] == 'mac' ? ';' : ',';
$enclosed = '"';
$escaped = '"';
if (isset($GLOBALS['showexcelnames']) && $GLOBALS['showexcelnames'] == 'yes') {
$GLOBALS['showcsvnames'] = 'yes';
}
} else {
if (empty($add_character)) {
$add_character = $GLOBALS['crlf'];
} else {
$add_character = str_replace('\\r', "\015", $add_character);
$add_character = str_replace('\\n', "\012", $add_character);
$add_character = str_replace('\\t', "\011", $add_character);
} // end if
$export_separator = str_replace('\\t', "\011", $export_separator);
}
return TRUE;
}
 
/**
* Outputs database header
*
* @param string Database name
*
* @return bool Whether it suceeded
*
* @access public
*/
function PMA_exportDBHeader($db) {
return TRUE;
}
 
/**
* Outputs database footer
*
* @param string Database name
*
* @return bool Whether it suceeded
*
* @access public
*/
function PMA_exportDBFooter($db) {
return TRUE;
}
 
/**
* Outputs create database database
*
* @param string Database name
*
* @return bool Whether it suceeded
*
* @access public
*/
function PMA_exportDBCreate($db) {
return TRUE;
}
 
/**
* Outputs the content of a table in CSV format
*
* @param string the database name
* @param string the table name
* @param string the end of line sequence
* @param string the url to go back in case of error
* @param string SQL query for obtaining data
*
* @return bool Whether it suceeded
*
* @access public
*/
function PMA_exportData($db, $table, $crlf, $error_url, $sql_query) {
global $what;
global $add_character;
global $export_separator;
global $enclosed;
global $escaped;
 
// Gets the data from the database
$result = PMA_DBI_query($sql_query, null, PMA_DBI_QUERY_UNBUFFERED);
$fields_cnt = PMA_DBI_num_fields($result);
 
// If required, get fields name at the first line
if (isset($GLOBALS['showcsvnames']) && $GLOBALS['showcsvnames'] == 'yes') {
$schema_insert = '';
for ($i = 0; $i < $fields_cnt; $i++) {
if ($enclosed == '') {
$schema_insert .= stripslashes(PMA_DBI_field_name($result, $i));
} else {
$schema_insert .= $enclosed
. str_replace($enclosed, $escaped . $enclosed, stripslashes(PMA_DBI_field_name($result, $i)))
. $enclosed;
}
$schema_insert .= $export_separator;
} // end for
$schema_insert =trim(substr($schema_insert, 0, -1));
if (!PMA_exportOutputHandler($schema_insert . $add_character)) {
return FALSE;
}
} // end if
 
// Format the data
while ($row = PMA_DBI_fetch_row($result)) {
$schema_insert = '';
for ($j = 0; $j < $fields_cnt; $j++) {
if (!isset($row[$j]) || is_null($row[$j])) {
$schema_insert .= $GLOBALS[$what . '_replace_null'];
} elseif ($row[$j] == '0' || $row[$j] != '') {
// loic1 : always enclose fields
if ($what == 'excel') {
$row[$j] = ereg_replace("\015(\012)?", "\012", $row[$j]);
}
if ($enclosed == '') {
$schema_insert .= $row[$j];
} else {
$schema_insert .= $enclosed
. str_replace($enclosed, $escaped . $enclosed, $row[$j])
. $enclosed;
}
} else {
$schema_insert .= '';
}
if ($j < $fields_cnt-1) {
$schema_insert .= $export_separator;
}
} // end for
 
if (!PMA_exportOutputHandler($schema_insert . $add_character)) {
return FALSE;
}
} // end while
PMA_DBI_free_result($result);
 
return TRUE;
} // end of the 'PMA_getTableCsv()' function
?>
/Web/Maintenance/phpMyAdmin/libraries/export/htmlexcel.php
0,0 → 1,166
<?php
/* $Id: htmlexcel.php,v 1.2.2.1 2006/03/16 13:30:39 nijel Exp $ */
// vim: expandtab sw=4 ts=4 sts=4:
 
/**
* Set of functions used to build CSV dumps of tables
*/
 
/**
* Outputs comment
*
* @param string Text of comment
*
* @return bool Whether it suceeded
*/
function PMA_exportComment($text) {
return TRUE;
}
 
/**
* Outputs export footer
*
* @return bool Whether it suceeded
*
* @access public
*/
function PMA_exportFooter() {
if (!PMA_exportOutputHandler('
</table>
</div>
</body>
</html>
')) {
return FALSE;
}
return TRUE;
}
 
/**
* Outputs export header
*
* @return bool Whether it suceeded
*
* @access public
*/
function PMA_exportHeader() {
global $charset, $charset_of_file;
if (!PMA_exportOutputHandler('
<html xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:x="urn:schemas-microsoft-com:office:excel"
xmlns="http://www.w3.org/TR/REC-html40">
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-type" content="text/html;charset=<?php echo isset($charset_of_file) ? $charset_of_file : $charset; ?>" />
<style id="Classeur1_16681_Styles">
</style>
 
</head>
<body>
 
<div id="Classeur1_16681" align=center x:publishsource="Excel">
 
<table x:str border=0 cellpadding=0 cellspacing=0 width=100% style="border-collapse: collapse">
')) {
return FALSE;
}
 
return TRUE;
}
 
/**
* Outputs database header
*
* @param string Database name
*
* @return bool Whether it suceeded
*
* @access public
*/
function PMA_exportDBHeader($db) {
return TRUE;
}
 
/**
* Outputs database footer
*
* @param string Database name
*
* @return bool Whether it suceeded
*
* @access public
*/
function PMA_exportDBFooter($db) {
return TRUE;
}
 
/**
* Outputs create database database
*
* @param string Database name
*
* @return bool Whether it suceeded
*
* @access public
*/
function PMA_exportDBCreate($db) {
return TRUE;
}
 
/**
* Outputs the content of a table in CSV format
*
* @param string the database name
* @param string the table name
* @param string the end of line sequence
* @param string the url to go back in case of error
* @param string SQL query for obtaining data
*
* @return bool Whether it suceeded
*
* @access public
*/
function PMA_exportData($db, $table, $crlf, $error_url, $sql_query) {
global $what;
 
// Gets the data from the database
$result = PMA_DBI_query($sql_query, null, PMA_DBI_QUERY_UNBUFFERED);
$fields_cnt = PMA_DBI_num_fields($result);
 
// If required, get fields name at the first line
if (isset($GLOBALS[$what . '_shownames']) && $GLOBALS[$what . '_shownames'] == 'yes') {
$schema_insert = '<tr>';
for ($i = 0; $i < $fields_cnt; $i++) {
$schema_insert .= '<td class=xl2216681 nowrap><b>' . htmlspecialchars(stripslashes(PMA_DBI_field_name($result, $i))) . '</b></td>';
} // end for
$schema_insert .= '</tr>';
if (!PMA_exportOutputHandler($schema_insert)) {
return FALSE;
}
} // end if
 
// Format the data
while ($row = PMA_DBI_fetch_row($result)) {
$schema_insert = '<tr>';
for ($j = 0; $j < $fields_cnt; $j++) {
if (!isset($row[$j]) || is_null($row[$j])) {
$value = $GLOBALS[$what . '_replace_null'];
} elseif ($row[$j] == '0' || $row[$j] != '') {
$value = $row[$j];
} else {
$value = '';
}
$schema_insert .= '<td class=xl2216681 nowrap>' . htmlspecialchars($value) . '</td>';
} // end for
$schema_insert .= '</tr>';
if (!PMA_exportOutputHandler($schema_insert)) {
return FALSE;
}
} // end while
PMA_DBI_free_result($result);
 
return TRUE;
}
?>
/Web/Maintenance/phpMyAdmin/libraries/export/htmlword.php
0,0 → 1,323
<?php
/* $Id: htmlword.php,v 1.7 2006/01/19 15:39:29 cybot_tm Exp $ */
// vim: expandtab sw=4 ts=4 sts=4:
 
/**
* Set of functions used to build CSV dumps of tables
*/
 
/**
* Outputs comment
*
* @param string Text of comment
*
* @return bool Whether it suceeded
*/
function PMA_exportComment($text) {
return TRUE;
}
 
/**
* Outputs export footer
*
* @return bool Whether it suceeded
*
* @access public
*/
function PMA_exportFooter() {
return PMA_exportOutputHandler('</body></html>');
}
 
/**
* Outputs export header
*
* @return bool Whether it suceeded
*
* @access public
*/
function PMA_exportHeader() {
global $charset, $charset_of_file;
return PMA_exportOutputHandler('<html xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:x="urn:schemas-microsoft-com:office:word"
xmlns="http://www.w3.org/TR/REC-html40">
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-type" content="text/html;charset=' . ( isset($charset_of_file) ? $charset_of_file : $charset ) .'" />
</head>
<body>');
}
 
/**
* Outputs database header
*
* @param string Database name
*
* @return bool Whether it suceeded
*
* @access public
*/
function PMA_exportDBHeader($db) {
return PMA_exportOutputHandler('<h1>' . $GLOBALS['strDatabase'] . ' ' . $db . '</h1>');
}
 
/**
* Outputs database footer
*
* @param string Database name
*
* @return bool Whether it suceeded
*
* @access public
*/
function PMA_exportDBFooter($db) {
return TRUE;
}
 
/**
* Outputs create database database
*
* @param string Database name
*
* @return bool Whether it suceeded
*
* @access public
*/
function PMA_exportDBCreate($db) {
return TRUE;
}
 
/**
* Outputs the content of a table in CSV format
*
* @param string the database name
* @param string the table name
* @param string the end of line sequence
* @param string the url to go back in case of error
* @param string SQL query for obtaining data
*
* @return bool Whether it suceeded
*
* @access public
*/
function PMA_exportData($db, $table, $crlf, $error_url, $sql_query)
{
global $what;
 
if (!PMA_exportOutputHandler('<h2>' . $GLOBALS['strDumpingData'] . ' ' . $table . '</h2>')) {
return FALSE;
}
if (!PMA_exportOutputHandler('<table class="width100" cellspacing="1">')) {
return FALSE;
}
 
// Gets the data from the database
$result = PMA_DBI_query($sql_query, null, PMA_DBI_QUERY_UNBUFFERED);
$fields_cnt = PMA_DBI_num_fields($result);
 
// If required, get fields name at the first line
if (isset($GLOBALS[$what . '_shownames']) && $GLOBALS[$what . '_shownames'] == 'yes') {
$schema_insert = '<tr class="print-category">';
for ($i = 0; $i < $fields_cnt; $i++) {
$schema_insert .= '<td class="print"><b>' . htmlspecialchars(stripslashes(PMA_DBI_field_name($result, $i))) . '</b></td>';
} // end for
$schema_insert .= '</tr>';
if (!PMA_exportOutputHandler($schema_insert)) {
return FALSE;
}
} // end if
 
// Format the data
while ($row = PMA_DBI_fetch_row($result)) {
$schema_insert = '<tr class="print-category">';
for ($j = 0; $j < $fields_cnt; $j++) {
if (!isset($row[$j]) || is_null($row[$j])) {
$value = $GLOBALS[$what . '_replace_null'];
} elseif ($row[$j] == '0' || $row[$j] != '') {
$value = $row[$j];
} else {
$value = '';
}
$schema_insert .= '<td class="print">' . htmlspecialchars($value) . '</td>';
} // end for
$schema_insert .= '</tr>';
if (!PMA_exportOutputHandler($schema_insert)) {
return FALSE;
}
} // end while
PMA_DBI_free_result($result);
if (!PMA_exportOutputHandler('</table>')) {
return FALSE;
}
 
return TRUE;
}
 
function PMA_exportStructure($db, $table, $crlf, $error_url, $do_relation = false, $do_comments = false, $do_mime = false, $dates = false)
{
global $cfgRelation;
 
if (!PMA_exportOutputHandler('<h2>' . $GLOBALS['strTableStructure'] . ' ' .$table . '</h2>')) {
return FALSE;
}
 
/**
* Get the unique keys in the table
*/
$keys_query = 'SHOW KEYS FROM ' . PMA_backquote($table) . ' FROM '. PMA_backquote($db);
$keys_result = PMA_DBI_query($keys_query);
$unique_keys = array();
while ($key = PMA_DBI_fetch_assoc($keys_result)) {
if ($key['Non_unique'] == 0) {
$unique_keys[] = $key['Column_name'];
}
}
PMA_DBI_free_result($keys_result);
 
/**
* Gets fields properties
*/
PMA_DBI_select_db($db);
$local_query = 'SHOW FIELDS FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table);
$result = PMA_DBI_query($local_query);
$fields_cnt = PMA_DBI_num_rows($result);
 
// Check if we can use Relations (Mike Beck)
if ($do_relation && !empty($cfgRelation['relation'])) {
// Find which tables are related with the current one and write it in
// an array
$res_rel = PMA_getForeigners($db, $table);
 
if ($res_rel && count($res_rel) > 0) {
$have_rel = TRUE;
} else {
$have_rel = FALSE;
}
} else {
$have_rel = FALSE;
} // end if
 
/**
* Displays the table structure
*/
if (!PMA_exportOutputHandler('<table class="width100" cellspacing="1">')) {
return FALSE;
}
 
$columns_cnt = 4;
if ($do_relation && $have_rel) {
$columns_cnt++;
}
if ($do_comments && $cfgRelation['commwork']) {
$columns_cnt++;
}
if ($do_mime && $cfgRelation['mimework']) {
$columns_cnt++;
}
 
$schema_insert = '<tr class="print-category">';
$schema_insert .= '<th class="print">' . htmlspecialchars($GLOBALS['strField']) . '</th>';
$schema_insert .= '<td class="print"><b>' . htmlspecialchars($GLOBALS['strType']) . '</b></td>';
$schema_insert .= '<td class="print"><b>' . htmlspecialchars($GLOBALS['strNull']) . '</b></td>';
$schema_insert .= '<td class="print"><b>' . htmlspecialchars($GLOBALS['strDefault']) . '</b></td>';
if ($do_relation && $have_rel) {
$schema_insert .= '<td class="print"><b>' . htmlspecialchars($GLOBALS['strLinksTo']) . '</b></td>';
}
if ($do_comments && ($cfgRelation['commwork'] || PMA_MYSQL_INT_VERSION >= 40100)) {
$schema_insert .= '<td class="print"><b>' . htmlspecialchars($GLOBALS['strComments']) . '</b></td>';
$comments = PMA_getComments($db, $table);
}
if ($do_mime && $cfgRelation['mimework']) {
$schema_insert .= '<td class="print"><b>' . htmlspecialchars('MIME') . '</b></td>';
$mime_map = PMA_getMIME($db, $table, true);
}
$schema_insert .= '</tr>';
 
if (!PMA_exportOutputHandler($schema_insert)) {
return FALSE;
}
 
while ($row = PMA_DBI_fetch_assoc($result)) {
 
$schema_insert = '<tr class="print-category">';
$type = $row['Type'];
// reformat mysql query output - staybyte - 9. June 2001
// loic1: set or enum types: slashes single quotes inside options
if (eregi('^(set|enum)\((.+)\)$', $type, $tmp)) {
$tmp[2] = substr(ereg_replace('([^,])\'\'', '\\1\\\'', ',' . $tmp[2]), 1);
$type = $tmp[1] . '(' . str_replace(',', ', ', $tmp[2]) . ')';
$type_nowrap = '';
 
$binary = 0;
$unsigned = 0;
$zerofill = 0;
} else {
$type_nowrap = ' nowrap="nowrap"';
$type = eregi_replace('BINARY', '', $type);
$type = eregi_replace('ZEROFILL', '', $type);
$type = eregi_replace('UNSIGNED', '', $type);
if (empty($type)) {
$type = '&nbsp;';
}
 
$binary = eregi('BINARY', $row['Type']);
$unsigned = eregi('UNSIGNED', $row['Type']);
$zerofill = eregi('ZEROFILL', $row['Type']);
}
$strAttribute = '&nbsp;';
if ($binary) {
$strAttribute = 'BINARY';
}
if ($unsigned) {
$strAttribute = 'UNSIGNED';
}
if ($zerofill) {
$strAttribute = 'UNSIGNED ZEROFILL';
}
if (!isset($row['Default'])) {
if ($row['Null'] != '') {
$row['Default'] = 'NULL';
}
} else {
$row['Default'] = $row['Default'];
}
 
$fmt_pre = '';
$fmt_post = '';
if (in_array($row['Field'], $unique_keys)) {
$fmt_pre = '<b>' . $fmt_pre;
$fmt_post = $fmt_post . '</b>';
}
if ($row['Key']=='PRI') {
$fmt_pre = '<i>' . $fmt_pre;
$fmt_post = $fmt_post . '</i>';
}
$schema_insert .= '<td class="print">' . $fmt_pre . htmlspecialchars($row['Field']) . $fmt_post . '</td>';
$schema_insert .= '<td class="print">' . htmlspecialchars($type) . '</td>';
$schema_insert .= '<td class="print">' . htmlspecialchars($row['Null'] == '' ? $GLOBALS['strNo'] : $GLOBALS['strYes']) . '</td>';
$schema_insert .= '<td class="print">' . htmlspecialchars(isset($row['Default']) ? $row['Default'] : '') . '</td>';
 
$field_name = $row['Field'];
 
if ($do_relation && $have_rel) {
$schema_insert .= '<td class="print">' . (isset($res_rel[$field_name]) ? htmlspecialchars($res_rel[$field_name]['foreign_table'] . ' (' . $res_rel[$field_name]['foreign_field'] . ')') : '') . '</td>';
}
if ($do_comments && $cfgRelation['commwork']) {
$schema_insert .= '<td class="print">' . ( isset($comments[$field_name]) ? htmlspecialchars($comments[$field_name]) : '') . '</td>';
}
if ($do_mime && $cfgRelation['mimework']) {
$schema_insert .= '<td class="print">' . ( isset($mime_map[$field_name]) ? htmlspecialchars(str_replace('_', '/', $mime_map[$field_name]['mimetype'])) : '') . '</td>';
}
 
$schema_insert .= '</tr>';
 
if (!PMA_exportOutputHandler($schema_insert)) {
return FALSE;
}
} // end while
PMA_DBI_free_result($result);
 
return PMA_exportOutputHandler('</table>');
}
?>
/Web/Maintenance/phpMyAdmin/libraries/export/latex.php
0,0 → 1,417
<?php
/* $Id: latex.php,v 2.16 2006/01/19 15:39:29 cybot_tm Exp $ */
// vim: expandtab sw=4 ts=4 sts=4:
 
/**
* Set of functions used to build dumps of tables
*/
 
/**
* Escapes some special characters for use in TeX/LaTeX
*
* @param string the string to convert
*
* @return string the converted string with escape codes
*
* @access private
*/
function PMA_texEscape($string) {
$escape = array('$', '%', '{', '}', '&', '#', '_', '^');
$cnt_escape = count($escape);
for ($k=0; $k < $cnt_escape; $k++) {
$string = str_replace($escape[$k], '\\' . $escape[$k], $string);
}
return $string;
}
 
/**
* Outputs comment
*
* @param string Text of comment
*
* @return bool Whether it suceeded
*/
function PMA_exportComment($text) {
return PMA_exportOutputHandler('% ' . $text . $GLOBALS['crlf']);
}
 
/**
* Outputs export footer
*
* @return bool Whether it suceeded
*
* @access public
*/
function PMA_exportFooter() {
return TRUE;
}
 
/**
* Outputs export header
*
* @return bool Whether it suceeded
*
* @access public
*/
function PMA_exportHeader() {
global $crlf;
global $cfg;
 
$head = '% phpMyAdmin LaTeX Dump' . $crlf
. '% version ' . PMA_VERSION . $crlf
. '% http://www.phpmyadmin.net' . $crlf
. '%' . $crlf
. '% ' . $GLOBALS['strHost'] . ': ' . $cfg['Server']['host'];
if (!empty($cfg['Server']['port'])) {
$head .= ':' . $cfg['Server']['port'];
}
$head .= $crlf
. '% ' . $GLOBALS['strGenTime'] . ': ' . PMA_localisedDate() . $crlf
. '% ' . $GLOBALS['strServerVersion'] . ': ' . substr(PMA_MYSQL_INT_VERSION, 0, 1) . '.' . (int) substr(PMA_MYSQL_INT_VERSION, 1, 2) . '.' . (int) substr(PMA_MYSQL_INT_VERSION, 3) . $crlf
. '% ' . $GLOBALS['strPHPVersion'] . ': ' . phpversion() . $crlf;
return PMA_exportOutputHandler($head);
}
 
/**
* Outputs database header
*
* @param string Database name
*
* @return bool Whether it suceeded
*
* @access public
*/
function PMA_exportDBHeader($db) {
global $crlf;
$head = '% ' . $crlf
. '% ' . $GLOBALS['strDatabase'] . ': ' . (isset($GLOBALS['use_backquotes']) ? PMA_backquote($db) : '\'' . $db . '\''). $crlf
. '% ' . $crlf;
return PMA_exportOutputHandler($head);
}
 
/**
* Outputs database footer
*
* @param string Database name
*
* @return bool Whether it suceeded
*
* @access public
*/
function PMA_exportDBFooter($db) {
return TRUE;
}
 
/**
* Outputs create database database
*
* @param string Database name
*
* @return bool Whether it suceeded
*
* @access public
*/
function PMA_exportDBCreate($db) {
return TRUE;
}
 
/**
* Outputs the content of a table in LaTeX table/sideways table environment
*
* @param string the database name
* @param string the table name
* @param string the end of line sequence
* @param string the url to go back in case of error
* @param string SQL query for obtaining data
*
* @return bool Whether it suceeded
*
* @access public
*/
function PMA_exportData($db, $table, $crlf, $error_url, $sql_query) {
$result = PMA_DBI_try_query($sql_query, null, PMA_DBI_QUERY_UNBUFFERED);
 
$columns_cnt = PMA_DBI_num_fields($result);
for ($i = 0; $i < $columns_cnt; $i++) {
$columns[$i] = PMA_DBI_field_name($result, $i);
}
unset($i);
 
$buffer = $crlf . '%' . $crlf . '% ' . $GLOBALS['strData'] . ': ' . $table . $crlf . '%' . $crlf
. ' \\begin{longtable}{|';
 
for ($index=0;$index<$columns_cnt;$index++) {
$buffer .= 'l|';
}
$buffer .= '} ' . $crlf ;
 
$buffer .= ' \\hline \\endhead \\hline \\endfoot \\hline ' . $crlf;
if (isset($GLOBALS['latex_caption'])) {
$buffer .= ' \\caption{' . str_replace('__TABLE__', PMA_texEscape($table), $GLOBALS['latex_data_caption'])
. '} \\label{' . str_replace('__TABLE__', $table, $GLOBALS['latex_data_label']) . '} \\\\';
}
if (!PMA_exportOutputHandler($buffer)) {
return FALSE;
}
 
// show column names
if (isset($GLOBALS['latex_showcolumns'])) {
$buffer = '\\hline ';
for ($i = 0; $i < $columns_cnt; $i++) {
$buffer .= '\\multicolumn{1}{|c|}{\\textbf{' . PMA_texEscape(stripslashes($columns[$i])) . '}} & ';
}
 
$buffer = substr($buffer, 0, -2) . '\\\\ \\hline \hline ';
if (!PMA_exportOutputHandler($buffer . ' \\endfirsthead ' . $crlf)) {
return FALSE;
}
if (isset($GLOBALS['latex_caption'])) {
if (!PMA_exportOutputHandler('\\caption{' . str_replace('__TABLE__', PMA_texEscape($table), $GLOBALS['latex_data_continued_caption']) . '} \\\\ ')) return FALSE;
}
if (!PMA_exportOutputHandler($buffer . '\\endhead \\endfoot' . $crlf)) {
return FALSE;
}
} else {
if (!PMA_exportOutputHandler('\\\\ \hline')) {
return FALSE;
}
}
 
// print the whole table
while ($record = PMA_DBI_fetch_assoc($result)) {
 
$buffer = '';
// print each row
for ($i = 0; $i < $columns_cnt; $i++) {
if ( isset($record[$columns[$i]]) && (!function_exists('is_null') || !is_null($record[$columns[$i]]))) {
$column_value = PMA_texEscape(stripslashes($record[$columns[$i]]));
} else {
$column_value = $GLOBALS['latex_replace_null'];
}
 
// last column ... no need for & character
if ($i == ($columns_cnt - 1)) {
$buffer .= $column_value;
} else {
$buffer .= $column_value . " & ";
}
}
$buffer .= ' \\\\ \\hline ' . $crlf;
if (!PMA_exportOutputHandler($buffer)) {
return FALSE;
}
}
 
$buffer = ' \\end{longtable}' . $crlf;
if (!PMA_exportOutputHandler($buffer)) {
return FALSE;
}
 
PMA_DBI_free_result($result);
return TRUE;
 
} // end getTableLaTeX
 
/**
* Returns $table's structure as LaTeX
*
* @param string the database name
* @param string the table name
* @param string the end of line sequence
* @param string the url to go back in case of error
* @param boolean whether to include relation comments
* @param boolean whether to include column comments
* @param boolean whether to include mime comments
*
* @return bool Whether it suceeded
*
* @access public
*/
// @@@ $strTableStructure
function PMA_exportStructure($db, $table, $crlf, $error_url, $do_relation = false, $do_comments = false, $do_mime = false, $dates = false)
{
global $cfgRelation;
 
/**
* Get the unique keys in the table
*/
$keys_query = 'SHOW KEYS FROM ' . PMA_backquote($table) . ' FROM '. PMA_backquote($db);
$keys_result = PMA_DBI_query($keys_query);
$unique_keys = array();
while ($key = PMA_DBI_fetch_assoc($keys_result)) {
if ($key['Non_unique'] == 0) {
$unique_keys[] = $key['Column_name'];
}
}
PMA_DBI_free_result($keys_result);
/**
* Gets fields properties
*/
PMA_DBI_select_db($db);
$local_query = 'SHOW FIELDS FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table);
$result = PMA_DBI_query($local_query);
$fields_cnt = PMA_DBI_num_rows($result);
 
// Check if we can use Relations (Mike Beck)
if ($do_relation && !empty($cfgRelation['relation'])) {
// Find which tables are related with the current one and write it in
// an array
$res_rel = PMA_getForeigners($db, $table);
 
if ($res_rel && count($res_rel) > 0) {
$have_rel = TRUE;
} else {
$have_rel = FALSE;
}
} else {
$have_rel = FALSE;
} // end if
 
/**
* Displays the table structure
*/
$buffer = $crlf . '%' . $crlf . '% ' . $GLOBALS['strStructure'] . ': ' . $table . $crlf . '%' . $crlf
. ' \\begin{longtable}{';
if (!PMA_exportOutputHandler($buffer)) {
return FALSE;
}
 
$columns_cnt = 4;
$alignment = '|l|c|c|c|';
if ($do_relation && $have_rel) {
$columns_cnt++;
$alignment .= 'l|';
}
if ($do_comments && $cfgRelation['commwork']) {
$columns_cnt++;
$alignment .= 'l|';
}
if ($do_mime && $cfgRelation['mimework']) {
$columns_cnt++;
$alignment .='l|';
}
$buffer = $alignment . '} ' . $crlf ;
 
$header = ' \\hline ';
$header .= '\\multicolumn{1}{|c|}{\\textbf{' . $GLOBALS['strField'] . '}} & \\multicolumn{1}{|c|}{\\textbf{' . $GLOBALS['strType'] . '}} & \\multicolumn{1}{|c|}{\\textbf{' . $GLOBALS['strNull'] . '}} & \\multicolumn{1}{|c|}{\\textbf{' . $GLOBALS['strDefault'] . '}}';
if ($do_relation && $have_rel) {
$header .= ' & \\multicolumn{1}{|c|}{\\textbf{' . $GLOBALS['strLinksTo'] . '}}';
}
if ($do_comments && ($cfgRelation['commwork'] || PMA_MYSQL_INT_VERSION >= 40100)) {
$header .= ' & \\multicolumn{1}{|c|}{\\textbf{' . $GLOBALS['strComments'] . '}}';
$comments = PMA_getComments($db, $table);
}
if ($do_mime && $cfgRelation['mimework']) {
$header .= ' & \\multicolumn{1}{|c|}{\\textbf{MIME}}';
$mime_map = PMA_getMIME($db, $table, true);
}
 
$local_buffer = PMA_texEscape($table);
 
// Table caption for first page and label
if (isset($GLOBALS['latex_caption'])) {
$buffer .= ' \\caption{'. str_replace('__TABLE__', PMA_texEscape($table), $GLOBALS['latex_structure_caption'])
. '} \\label{' . str_replace('__TABLE__', $table, $GLOBALS['latex_structure_label'])
. '} \\\\' . $crlf;
}
$buffer .= $header . ' \\\\ \\hline \\hline' . $crlf . '\\endfirsthead' . $crlf;
// Table caption on next pages
if (isset($GLOBALS['latex_caption'])) {
$buffer .= ' \\caption{'. str_replace('__TABLE__', PMA_texEscape($table), $GLOBALS['latex_structure_continued_caption'])
. '} \\\\ ' . $crlf;
}
$buffer .= $header . ' \\\\ \\hline \\hline \\endhead \\endfoot ';
 
if (!PMA_exportOutputHandler($buffer)) {
return FALSE;
}
 
while ($row = PMA_DBI_fetch_assoc($result)) {
 
$type = $row['Type'];
// reformat mysql query output - staybyte - 9. June 2001
// loic1: set or enum types: slashes single quotes inside options
if (eregi('^(set|enum)\((.+)\)$', $type, $tmp)) {
$tmp[2] = substr(ereg_replace('([^,])\'\'', '\\1\\\'', ',' . $tmp[2]), 1);
$type = $tmp[1] . '(' . str_replace(',', ', ', $tmp[2]) . ')';
$type_nowrap = '';
 
$binary = 0;
$unsigned = 0;
$zerofill = 0;
} else {
$type_nowrap = ' nowrap="nowrap"';
$type = eregi_replace('BINARY', '', $type);
$type = eregi_replace('ZEROFILL', '', $type);
$type = eregi_replace('UNSIGNED', '', $type);
if (empty($type)) {
$type = '&nbsp;';
}
 
$binary = eregi('BINARY', $row['Type']);
$unsigned = eregi('UNSIGNED', $row['Type']);
$zerofill = eregi('ZEROFILL', $row['Type']);
}
$strAttribute = '&nbsp;';
if ($binary) {
$strAttribute = 'BINARY';
}
if ($unsigned) {
$strAttribute = 'UNSIGNED';
}
if ($zerofill) {
$strAttribute = 'UNSIGNED ZEROFILL';
}
if (!isset($row['Default'])) {
if ($row['Null'] != '') {
$row['Default'] = 'NULL';
}
} else {
$row['Default'] = $row['Default'];
}
 
$field_name = $row['Field'];
 
$local_buffer = $field_name . "\000" . $type . "\000" . (($row['Null'] == '') ? $GLOBALS['strNo'] : $GLOBALS['strYes']) . "\000" . (isset($row['Default']) ? $row['Default'] : '');
 
if ($do_relation && $have_rel) {
$local_buffer .= "\000";
if (isset($res_rel[$field_name])) {
$local_buffer .= $res_rel[$field_name]['foreign_table'] . ' (' . $res_rel[$field_name]['foreign_field'] . ')';
}
}
if ($do_comments && $cfgRelation['commwork']) {
$local_buffer .= "\000";
if (isset($comments[$field_name])) {
$local_buffer .= $comments[$field_name];
}
}
if ($do_mime && $cfgRelation['mimework']) {
$local_buffer .= "\000";
if (isset($mime_map[$field_name])) {
$local_buffer .= str_replace('_', '/', $mime_map[$field_name]['mimetype']);
}
}
$local_buffer = PMA_texEscape($local_buffer);
if ($row['Key']=='PRI') {
$pos=strpos($local_buffer, "\000");
$local_buffer = '\\textit{' . substr($local_buffer, 0, $pos) . '}' . substr($local_buffer, $pos);
}
if (in_array($field_name, $unique_keys)) {
$pos=strpos($local_buffer, "\000");
$local_buffer = '\\textbf{' . substr($local_buffer, 0, $pos) . '}' . substr($local_buffer, $pos);
}
$buffer = str_replace("\000", ' & ', $local_buffer);
$buffer .= ' \\\\ \\hline ' . $crlf;
 
if (!PMA_exportOutputHandler($buffer)) {
return FALSE;
}
} // end while
PMA_DBI_free_result($result);
 
$buffer = ' \\end{longtable}' . $crlf;
return PMA_exportOutputHandler($buffer);
} // end of the 'PMA_getTableStructureLaTeX()' function
?>
/Web/Maintenance/phpMyAdmin/libraries/export/pdf.php
0,0 → 1,402
<?php
/* $Id: pdf.php,v 1.3 2006/01/17 17:03:02 cybot_tm Exp $ */
// vim: expandtab sw=4 ts=4 sts=4:
 
/**
* Produce a PDF report (export) from a query
*/
 
 
define('FPDF_FONTPATH', './libraries/fpdf/font/');
//if ($charset == 'utf-8') {
define('PMA_PDF_FONT', 'FreeSans');
require_once('./libraries/fpdf/ufpdf.php');
class PMA_FPDF extends UFPDF
{
};
//} else {
// define('PMA_PDF_FONT', 'Arial');
// require_once('./libraries/fpdf/fpdf.php');
// class PMA_FPDF extends FPDF {
// };
//}
 
 
// Adapted from a LGPL script by Philip Clarke
 
class PMA_PDF extends PMA_FPDF
{
var $tablewidths;
var $headerset;
var $footerset;
 
// overloading of a fpdf function:
function _beginpage($orientation)
{
$this->page++;
// solved the problem of overwriting a page, if it already exists
if (!isset($this->pages[$this->page])) {
$this->pages[$this->page] = '';
}
$this->state = 2;
$this->x = $this->lMargin;
$this->y = $this->tMargin;
$this->lasth = 0;
$this->FontFamily = '';
//Page orientation
if (!$orientation) {
$orientation = $this->DefOrientation;
} else {
$orientation = strtoupper($orientation{0});
if ($orientation != $this->DefOrientation) {
$this->OrientationChanges[$this->page] = true;
}
}
if ($orientation != $this->CurOrientation) {
//Change orientation
if ($orientation == 'P') {
$this->wPt = $this->fwPt;
$this->hPt = $this->fhPt;
$this->w = $this->fw;
$this->h = $this->fh;
} else {
$this->wPt = $this->fhPt;
$this->hPt = $this->fwPt;
$this->w = $this->fh;
$this->h = $this->fw;
}
$this->PageBreakTrigger = $this->h - $this->bMargin;
$this->CurOrientation = $orientation;
}
}
 
function Header()
{
global $maxY;
 
// Check if header for this page already exists
if (!isset($this->headerset[$this->page])) {
$fullwidth = 0;
foreach ($this->tablewidths as $width) {
$fullwidth += $width;
}
$this->SetY(($this->tMargin) - ($this->FontSizePt/$this->k)*2);
$this->cellFontSize = $this->FontSizePt ;
$this->SetFont(PMA_PDF_FONT, '', ($this->titleFontSize ? $this->titleFontSize : $this->FontSizePt));
$this->Cell(0, $this->FontSizePt, $this->titleText, 0, 1, 'C');
$l = ($this->lMargin);
$this->SetFont(PMA_PDF_FONT, '', $this->cellFontSize);
foreach ($this->colTitles as $col => $txt) {
$this->SetXY($l, ($this->tMargin));
$this->MultiCell($this->tablewidths[$col], $this->FontSizePt, $txt);
$l += $this->tablewidths[$col] ;
$maxY = ($maxY < $this->getY()) ? $this->getY() : $maxY ;
}
$this->SetXY($this->lMargin, $this->tMargin);
$this->setFillColor(200, 200, 200);
$l = ($this->lMargin);
foreach ($this->colTitles as $col => $txt) {
$this->SetXY($l, $this->tMargin);
$this->cell($this->tablewidths[$col], $maxY-($this->tMargin), '', 1, 0, 'L', 1);
$this->SetXY($l, $this->tMargin);
$this->MultiCell($this->tablewidths[$col], $this->FontSizePt, $txt, 0, 'C');
$l += $this->tablewidths[$col];
}
$this->setFillColor(255, 255, 255);
// set headerset
$this->headerset[$this->page] = 1;
}
 
$this->SetY($maxY);
}
 
function Footer()
{
// Check if footer for this page already exists
if (!isset($this->footerset[$this->page])) {
$this->SetY(-15);
//Page number
$this->Cell(0, 10, $GLOBALS['strPageNumber'] .' '.$this->PageNo() .'/{nb}', 'T', 0, 'C');
 
// set footerset
$this->footerset[$this->page] = 1;
}
}
 
function morepagestable($lineheight=8)
{
// some things to set and 'remember'
$l = $this->lMargin;
$startheight = $h = $this->GetY();
$startpage = $currpage = $this->page;
 
// calculate the whole width
$fullwidth = 0;
foreach ($this->tablewidths as $width) {
$fullwidth += $width;
}
 
// Now let's start to write the table
$row = 0;
$tmpheight = array();
$maxpage = 0;
 
while ($data = PMA_DBI_fetch_row($this->results)) {
$this->page = $currpage;
// write the horizontal borders
$this->Line($l, $h, $fullwidth+$l, $h);
// write the content and remember the height of the highest col
foreach ($data as $col => $txt) {
$this->page = $currpage;
$this->SetXY($l, $h);
$this->MultiCell($this->tablewidths[$col], $lineheight, $txt, 0, $this->colAlign[$col]);
 
$l += $this->tablewidths[$col];
 
if (!isset($tmpheight[$row.'-'.$this->page])) {
$tmpheight[$row.'-'.$this->page] = 0;
}
if ($tmpheight[$row.'-'.$this->page] < $this->GetY()) {
$tmpheight[$row.'-'.$this->page] = $this->GetY();
}
if ($this->page > $maxpage) {
$maxpage = $this->page;
}
unset($data[$col]);
}
 
// get the height we were in the last used page
$h = $tmpheight[$row.'-'.$maxpage];
// set the "pointer" to the left margin
$l = $this->lMargin;
// set the $currpage to the last page
$currpage = $maxpage;
unset($data[$row]);
$row++;
}
// draw the borders
// we start adding a horizontal line on the last page
$this->page = $maxpage;
$this->Line($l, $h, $fullwidth+$l, $h);
// now we start at the top of the document and walk down
for ($i = $startpage; $i <= $maxpage; $i++) {
$this->page = $i;
$l = $this->lMargin;
$t = ($i == $startpage) ? $startheight : $this->tMargin;
$lh = ($i == $maxpage) ? $h : $this->h-$this->bMargin;
$this->Line($l, $t, $l, $lh);
foreach ($this->tablewidths as $width) {
$l += $width;
$this->Line($l, $t, $l, $lh);
}
}
// set it to the last page, if not it'll cause some problems
$this->page = $maxpage;
}
 
 
function mysql_report($query, $attr = array())
{
foreach ($attr as $key => $val){
$this->$key = $val ;
}
 
// Pass 1 for column widths
// TODO: force here a LIMIT to speed up pass 1 ?
$this->results = PMA_DBI_query($query, null, PMA_DBI_QUERY_UNBUFFERED);
$this->numFields = PMA_DBI_num_fields($this->results);
$this->fields = PMA_DBI_get_fields_meta($this->results);
 
// if column widths not set
if (!isset($this->tablewidths)){
 
// starting col width
$this->sColWidth = ($this->w - $this->lMargin - $this->rMargin) / $this->numFields;
 
// loop through results header and set initial col widths/ titles/ alignment
// if a col title is less than the starting col width / reduce that column size
for ($i=0; $i < $this->numFields; $i++){
$stringWidth = $this->getstringwidth($this->fields[$i]->name) + 6 ;
// set any column titles less than the start width to the column title width
if (($stringWidth) < $this->sColWidth){
$colFits[$i] = $stringWidth ;
}
$this->colTitles[$i] = $this->fields[$i]->name;
switch ($this->fields[$i]->type){
case 'int':
$this->colAlign[$i] = 'R';
break;
default:
$this->colAlign[$i] = 'L';
}
}
 
// loop through the data, any column whose contents is bigger i
// that the col size is resized
while ($row = PMA_DBI_fetch_row($this->results)) {
foreach ($colFits as $key => $val) {
$stringWidth = $this->getstringwidth($row[$key]) + 6 ;
if ($stringWidth > $this->sColWidth) {
// any col where row is bigger than the start width is now discarded
unset($colFits[$key]);
} else {
// if text is not bigger than the current column width setting enlarge the column
if ($stringWidth > $val) {
$colFits[$key] = ($stringWidth) ;
}
}
}
}
 
$totAlreadyFitted = 0;
foreach ($colFits as $key => $val){
// set fitted columns to smallest size
$this->tablewidths[$key] = $val;
// to work out how much (if any) space has been freed up
$totAlreadyFitted += $val;
}
 
$surplus = (sizeof($colFits) * $this->sColWidth) - $totAlreadyFitted;
for ($i=0; $i < $this->numFields; $i++) {
if (!in_array($i, array_keys($colFits))) {
$this->tablewidths[$i] = $this->sColWidth + ($surplus / ($this->numFields - sizeof($colFits)));
}
}
 
ksort($this->tablewidths);
 
}
 
PMA_DBI_free_result($this->results);
 
// Pass 2
 
$this->results = PMA_DBI_query($query, null, PMA_DBI_QUERY_UNBUFFERED);
$this->Open();
$this->setY($this->tMargin);
$this->AddPage();
$this->morepagestable($this->FontSizePt);
PMA_DBI_free_result($this->results);
 
} // end of mysql_report function
 
} // end of PMA_PDF class
 
/**
* Outputs comment
*
* @param string Text of comment
*
* @return bool Whether it suceeded
*/
function PMA_exportComment($text)
{
return TRUE;
}
 
/**
* Outputs export footer
*
* @return bool Whether it suceeded
*
* @access public
*/
function PMA_exportFooter()
{
return TRUE;
}
 
/**
* Outputs export header
*
* @return bool Whether it suceeded
*
* @access public
*/
function PMA_exportHeader()
{
return TRUE;
}
 
/**
* Outputs database header
*
* @param string Database name
*
* @return bool Whether it suceeded
*
* @access public
*/
function PMA_exportDBHeader($db)
{
return TRUE;
}
 
/**
* Outputs database footer
*
* @param string Database name
*
* @return bool Whether it suceeded
*
* @access public
*/
function PMA_exportDBFooter($db)
{
return TRUE;
}
 
/**
* Outputs create database database
*
* @param string Database name
*
* @return bool Whether it suceeded
*
* @access public
*/
function PMA_exportDBCreate($db)
{
return TRUE;
}
 
/**
* Outputs the content of a table in PDF format
*
* @param string the database name
* @param string the table name
* @param string the end of line sequence
* @param string the url to go back in case of error
* @param string SQL query for obtaining data
*
* @return bool Whether it suceeded
*
* @access public
*/
function PMA_exportData($db, $table, $crlf, $error_url, $sql_query)
{
global $what;
global $pdf_report_title;
 
// TODO: user-defined page orientation, paper size
$pdf = new PMA_PDF('L', 'pt', 'A3');
 
$pdf->AddFont('FreeSans', '', 'FreeSans.php');
$pdf->AddFont('FreeSans', 'B', 'FreeSansBold.php');
$pdf->SetFont(PMA_PDF_FONT, '', 11.5);
$pdf->AliasNbPages();
$attr=array('titleFontSize' => 18, 'titleText' => $pdf_report_title);
$pdf->mysql_report($sql_query, $attr);
 
// instead of $pdf->Output():
if ($pdf->state < 3) {
$pdf->Close();
}
if (!PMA_exportOutputHandler($pdf->buffer)) {
return FALSE;
}
 
return TRUE;
} // end of the 'PMA_exportData()' function
?>
/Web/Maintenance/phpMyAdmin/libraries/export/sql.php
0,0 → 1,654
<?php
/* $Id: sql.php,v 2.53.2.1 2006/05/05 09:20:37 nijel Exp $ */
// vim: expandtab sw=4 ts=4 sts=4:
/**
* Set of functions used to build SQL dumps of tables
*/
 
/**
* Marker for comments, -- is needed for ANSI SQL.
*/
$GLOBALS['comment_marker'] = '-- ';
 
/**
* Avoids undefined variables, use NULL so isset() returns false
*/
if ( ! isset( $use_backquotes ) ) {
$use_backquotes = null;
}
 
/**
* Outputs comment
*
* @param string Text of comment
*
* @return bool Whether it suceeded
*/
function PMA_exportComment($text)
{
return PMA_exportOutputHandler($GLOBALS['comment_marker'] . $text . $GLOBALS['crlf']);
}
 
/**
* Outputs export footer
*
* @return bool Whether it suceeded
*
* @access public
*/
function PMA_exportFooter()
{
global $crlf;
 
$foot = '';
 
if (isset($GLOBALS['disable_fk'])) {
$foot .= $crlf . 'SET FOREIGN_KEY_CHECKS=1;' . $crlf;
}
 
if (isset($GLOBALS['use_transaction'])) {
$foot .= $crlf . 'COMMIT;' . $crlf;
}
 
return PMA_exportOutputHandler($foot);
}
 
/**
* Outputs export header
*
* @return bool Whether it suceeded
*
* @access public
*/
function PMA_exportHeader()
{
global $crlf;
global $cfg;
 
if (PMA_MYSQL_INT_VERSION >= 40100 && isset($GLOBALS['sql_compat']) && $GLOBALS['sql_compat'] != 'NONE') {
PMA_DBI_try_query('SET SQL_MODE="' . $GLOBALS['sql_compat'] . '"');
}
 
$head = $GLOBALS['comment_marker'] . 'phpMyAdmin SQL Dump' . $crlf
. $GLOBALS['comment_marker'] . 'version ' . PMA_VERSION . $crlf
. $GLOBALS['comment_marker'] . 'http://www.phpmyadmin.net' . $crlf
. $GLOBALS['comment_marker'] . $crlf
. $GLOBALS['comment_marker'] . $GLOBALS['strHost'] . ': ' . $cfg['Server']['host'];
if (!empty($cfg['Server']['port'])) {
$head .= ':' . $cfg['Server']['port'];
}
$head .= $crlf
. $GLOBALS['comment_marker'] . $GLOBALS['strGenTime'] . ': ' . PMA_localisedDate() . $crlf
. $GLOBALS['comment_marker'] . $GLOBALS['strServerVersion'] . ': ' . substr(PMA_MYSQL_INT_VERSION, 0, 1) . '.' . (int) substr(PMA_MYSQL_INT_VERSION, 1, 2) . '.' . (int) substr(PMA_MYSQL_INT_VERSION, 3) . $crlf
. $GLOBALS['comment_marker'] . $GLOBALS['strPHPVersion'] . ': ' . phpversion() . $crlf;
 
if (isset($GLOBALS['header_comment']) && !empty($GLOBALS['header_comment'])) {
$lines = explode('\n', $GLOBALS['header_comment']);
$head .= $GLOBALS['comment_marker'] . $crlf
. $GLOBALS['comment_marker'] . implode($crlf . $GLOBALS['comment_marker'], $lines) . $crlf
. $GLOBALS['comment_marker'] . $crlf;
}
 
if (isset($GLOBALS['disable_fk'])) {
$head .= $crlf . 'SET FOREIGN_KEY_CHECKS=0;' . $crlf;
}
 
if (isset($GLOBALS['use_transaction'])) {
$head .= $crlf .'SET AUTOCOMMIT=0;' . $crlf
. 'START TRANSACTION;' . $crlf . $crlf;
}
 
return PMA_exportOutputHandler($head);
}
 
/**
* Outputs create database database
*
* @param string Database name
*
* @return bool Whether it suceeded
*
* @access public
*/
function PMA_exportDBCreate($db)
{
global $crlf;
if (isset($GLOBALS['drop_database'])) {
if (!PMA_exportOutputHandler('DROP DATABASE ' . (isset($GLOBALS['use_backquotes']) ? PMA_backquote($db) : $db) . ';' . $crlf)) {
return FALSE;
}
}
$create_query = 'CREATE DATABASE ' . (isset($GLOBALS['use_backquotes']) ? PMA_backquote($db) : $db);
if (PMA_MYSQL_INT_VERSION >= 40101) {
$collation = PMA_getDbCollation($db);
if (strpos($collation, '_')) {
$create_query .= ' DEFAULT CHARACTER SET ' . substr($collation, 0, strpos($collation, '_')) . ' COLLATE ' . $collation;
} else {
$create_query .= ' DEFAULT CHARACTER SET ' . $collation;
}
}
$create_query .= ';' . $crlf;
if (!PMA_exportOutputHandler($create_query)) {
return FALSE;
}
if (isset($GLOBALS['use_backquotes']) && PMA_MYSQL_INT_VERSION >= 40100 && isset($GLOBALS['sql_compat']) && $GLOBALS['sql_compat'] == 'NONE') {
return PMA_exportOutputHandler('USE ' . PMA_backquote($db) . ';' . $crlf);
}
return PMA_exportOutputHandler('USE ' . $db . ';' . $crlf);
}
 
/**
* Outputs database header
*
* @param string Database name
*
* @return bool Whether it suceeded
*
* @access public
*/
function PMA_exportDBHeader($db)
{
global $crlf;
$head = $GLOBALS['comment_marker'] . $crlf
. $GLOBALS['comment_marker'] . $GLOBALS['strDatabase'] . ': ' . (isset($GLOBALS['use_backquotes']) ? PMA_backquote($db) : '\'' . $db . '\''). $crlf
. $GLOBALS['comment_marker'] . $crlf;
return PMA_exportOutputHandler($head);
}
 
/**
* Outputs database footer
*
* @param string Database name
*
* @return bool Whether it suceeded
*
* @access public
*/
function PMA_exportDBFooter($db)
{
$result = TRUE;
if (isset($GLOBALS['sql_constraints'])) {
$result = PMA_exportOutputHandler($GLOBALS['sql_constraints']);
unset($GLOBALS['sql_constraints']);
}
return $result;
}
 
/**
* Returns $table's CREATE definition
*
* @param string the database name
* @param string the table name
* @param string the end of line sequence
* @param string the url to go back in case of error
* @param boolean whether to include creation/update/check dates
*
* @return string resulting schema
*
* @global boolean whether to add 'drop' statements or not
* @global boolean whether to use backquotes to allow the use of special
* characters in database, table and fields names or not
*
* @access public
*/
function PMA_getTableDef($db, $table, $crlf, $error_url, $show_dates = false)
{
global $drop;
global $use_backquotes;
global $cfgRelation;
global $sql_constraints;
 
$schema_create = '';
$auto_increment = '';
$new_crlf = $crlf;
 
// need to use PMA_DBI_QUERY_STORE with PMA_DBI_num_rows() in mysqli
$result = PMA_DBI_query('SHOW TABLE STATUS FROM ' . PMA_backquote($db) . ' LIKE \'' . PMA_sqlAddslashes($table) . '\'', null, PMA_DBI_QUERY_STORE);
if ($result != FALSE) {
if (PMA_DBI_num_rows($result) > 0) {
$tmpres = PMA_DBI_fetch_assoc($result);
if (isset($GLOBALS['sql_auto_increment']) && !empty($tmpres['Auto_increment'])) {
$auto_increment .= ' AUTO_INCREMENT=' . $tmpres['Auto_increment'] . ' ';
}
 
if ($show_dates && isset($tmpres['Create_time']) && !empty($tmpres['Create_time'])) {
$schema_create .= $GLOBALS['comment_marker'] . $GLOBALS['strStatCreateTime'] . ': ' . PMA_localisedDate(strtotime($tmpres['Create_time'])) . $crlf;
$new_crlf = $GLOBALS['comment_marker'] . $crlf . $crlf;
}
 
if ($show_dates && isset($tmpres['Update_time']) && !empty($tmpres['Update_time'])) {
$schema_create .= $GLOBALS['comment_marker'] . $GLOBALS['strStatUpdateTime'] . ': ' . PMA_localisedDate(strtotime($tmpres['Update_time'])) . $crlf;
$new_crlf = $GLOBALS['comment_marker'] . $crlf . $crlf;
}
 
if ($show_dates && isset($tmpres['Check_time']) && !empty($tmpres['Check_time'])) {
$schema_create .= $GLOBALS['comment_marker'] . $GLOBALS['strStatCheckTime'] . ': ' . PMA_localisedDate(strtotime($tmpres['Check_time'])) . $crlf;
$new_crlf = $GLOBALS['comment_marker'] . $crlf . $crlf;
}
}
PMA_DBI_free_result($result);
}
 
$schema_create .= $new_crlf;
 
if (!empty($drop)) {
$schema_create .= 'DROP TABLE IF EXISTS ' . PMA_backquote($table, $use_backquotes) . ';' . $crlf;
}
 
// Steve Alberty's patch for complete table dump,
// Whether to quote table and fields names or not
if ($use_backquotes) {
PMA_DBI_query('SET SQL_QUOTE_SHOW_CREATE = 1');
} else {
PMA_DBI_query('SET SQL_QUOTE_SHOW_CREATE = 0');
}
 
$result = PMA_DBI_query('SHOW CREATE TABLE ' . PMA_backquote($db) . '.' . PMA_backquote($table), null, PMA_DBI_QUERY_UNBUFFERED);
if ($result != FALSE && ($row = PMA_DBI_fetch_row($result))) {
$create_query = $row[1];
unset($row);
 
// Convert end of line chars to one that we want (note that MySQL doesn't return query it will accept in all cases)
if (strpos($create_query, "(\r\n ")) {
$create_query = str_replace("\r\n", $crlf, $create_query);
} elseif (strpos($create_query, "(\n ")) {
$create_query = str_replace("\n", $crlf, $create_query);
} elseif (strpos($create_query, "(\r ")) {
$create_query = str_replace("\r", $crlf, $create_query);
}
 
// Should we use IF NOT EXISTS?
if (isset($GLOBALS['if_not_exists'])) {
$create_query = preg_replace('/^CREATE TABLE/', 'CREATE TABLE IF NOT EXISTS', $create_query);
}
 
// are there any constraints to cut out?
if (preg_match('@CONSTRAINT|FOREIGN[\s]+KEY@', $create_query)) {
 
// Split the query into lines, so we can easily handle it. We know lines are separated by $crlf (done few lines above).
$sql_lines = explode($crlf, $create_query);
$sql_count = count($sql_lines);
 
// lets find first line with constraints
for ($i = 0; $i < $sql_count; $i++) {
if (preg_match('@^[\s]*(CONSTRAINT|FOREIGN[\s]+KEY)@', $sql_lines[$i])) {
break;
}
}
 
// If we really found a constraint
if ($i != $sql_count) {
 
// remove , from the end of create statement
$sql_lines[$i - 1] = preg_replace('@,$@', '', $sql_lines[$i - 1]);
 
// prepare variable for constraints
if (!isset($sql_constraints)) {
if (isset($GLOBALS['no_constraints_comments'])) {
$sql_constraints = '';
} else {
$sql_constraints = $crlf . $GLOBALS['comment_marker'] .
$crlf . $GLOBALS['comment_marker'] . $GLOBALS['strConstraintsForDumped'] .
$crlf . $GLOBALS['comment_marker'] . $crlf;
}
}
 
// comments for current table
if (!isset($GLOBALS['no_constraints_comments'])) {
$sql_constraints .= $crlf . $GLOBALS['comment_marker'] .
$crlf . $GLOBALS['comment_marker'] . $GLOBALS['strConstraintsForTable'] . ' ' . PMA_backquote($table) .
$crlf . $GLOBALS['comment_marker'] . $crlf;
}
 
// let's do the work
$sql_constraints .= 'ALTER TABLE ' . PMA_backquote($table) . $crlf;
 
$first = TRUE;
for ($j = $i; $j < $sql_count; $j++) {
if (preg_match('@CONSTRAINT|FOREIGN[\s]+KEY@', $sql_lines[$j])) {
if (!$first) {
$sql_constraints .= $crlf;
}
if (strpos($sql_lines[$j], 'CONSTRAINT') === FALSE) {
$sql_constraints .= preg_replace('/(FOREIGN[\s]+KEY)/', 'ADD \1', $sql_lines[$j]);
} else {
$sql_constraints .= preg_replace('/(CONSTRAINT)/', 'ADD \1', $sql_lines[$j]);
}
$first = FALSE;
} else {
break;
}
}
$sql_constraints .= ';' . $crlf;
$create_query = implode($crlf, array_slice($sql_lines, 0, $i)) . $crlf . implode($crlf, array_slice($sql_lines, $j, $sql_count - 1));
unset($sql_lines);
}
}
$schema_create .= $create_query;
}
 
$schema_create .= $auto_increment;
 
PMA_DBI_free_result($result);
return $schema_create;
} // end of the 'PMA_getTableDef()' function
 
 
/**
* Returns $table's comments, relations etc.
*
* @param string the database name
* @param string the table name
* @param string the end of line sequence
* @param boolean whether to include relation comments
* @param boolean whether to include column comments
* @param boolean whether to include mime comments
*
* @return string resulting comments
*
* @access public
*/
function PMA_getTableComments($db, $table, $crlf, $do_relation = false, $do_comments = false, $do_mime = false)
{
global $cfgRelation;
global $use_backquotes;
global $sql_constraints;
 
$schema_create = '';
 
// triggered only for MySQL < 4.1.x (pmadb-style comments)
if ($do_comments && $cfgRelation['commwork']) {
if (!($comments_map = PMA_getComments($db, $table))) {
unset($comments_map);
}
}
 
// Check if we can use Relations (Mike Beck)
if ($do_relation && !empty($cfgRelation['relation'])) {
// Find which tables are related with the current one and write it in
// an array
$res_rel = PMA_getForeigners($db, $table);
 
if ($res_rel && count($res_rel) > 0) {
$have_rel = TRUE;
} else {
$have_rel = FALSE;
}
} else {
$have_rel = FALSE;
} // end if
 
if ($do_mime && $cfgRelation['mimework']) {
if (!($mime_map = PMA_getMIME($db, $table, true))) {
unset($mime_map);
}
}
 
if (isset($comments_map) && count($comments_map) > 0) {
$schema_create .= $crlf . $GLOBALS['comment_marker'] . $crlf
. $GLOBALS['comment_marker'] . $GLOBALS['strCommentsForTable']. ' ' . PMA_backquote($table, $use_backquotes) . ':' . $crlf;
foreach ($comments_map AS $comment_field => $comment) {
$schema_create .= $GLOBALS['comment_marker'] . ' ' . PMA_backquote($comment_field, $use_backquotes) . $crlf
. $GLOBALS['comment_marker'] . ' ' . PMA_backquote($comment, $use_backquotes) . $crlf;
}
$schema_create .= $GLOBALS['comment_marker'] . $crlf;
}
 
if (isset($mime_map) && count($mime_map) > 0) {
$schema_create .= $crlf . $GLOBALS['comment_marker'] . $crlf
. $GLOBALS['comment_marker'] . $GLOBALS['strMIMETypesForTable']. ' ' . PMA_backquote($table, $use_backquotes) . ':' . $crlf;
@reset($mime_map);
foreach ($mime_map AS $mime_field => $mime) {
$schema_create .= $GLOBALS['comment_marker'] . ' ' . PMA_backquote($mime_field, $use_backquotes) . $crlf
. $GLOBALS['comment_marker'] . ' ' . PMA_backquote($mime['mimetype'], $use_backquotes) . $crlf;
}
$schema_create .= $GLOBALS['comment_marker'] . $crlf;
}
 
if ($have_rel) {
$schema_create .= $crlf . $GLOBALS['comment_marker'] . $crlf
. $GLOBALS['comment_marker'] . $GLOBALS['strRelationsForTable']. ' ' . PMA_backquote($table, $use_backquotes) . ':' . $crlf;
foreach ($res_rel AS $rel_field => $rel) {
$schema_create .= $GLOBALS['comment_marker'] . ' ' . PMA_backquote($rel_field, $use_backquotes) . $crlf
. $GLOBALS['comment_marker'] . ' ' . PMA_backquote($rel['foreign_table'], $use_backquotes)
. ' -> ' . PMA_backquote($rel['foreign_field'], $use_backquotes) . $crlf;
}
$schema_create .= $GLOBALS['comment_marker'] . $crlf;
}
 
return $schema_create;
 
} // end of the 'PMA_getTableComments()' function
 
/**
* Outputs table's structure
*
* @param string the database name
* @param string the table name
* @param string the end of line sequence
* @param string the url to go back in case of error
* @param boolean whether to include relation comments
* @param boolean whether to include column comments
* @param boolean whether to include mime comments
*
* @return bool Whether it suceeded
*
* @access public
*/
function PMA_exportStructure($db, $table, $crlf, $error_url, $relation = FALSE, $comments = FALSE, $mime = FALSE, $dates = FALSE)
{
$formatted_table_name = (isset($GLOBALS['use_backquotes']))
? PMA_backquote($table)
: '\'' . $table . '\'';
$dump = $crlf
. $GLOBALS['comment_marker'] . '--------------------------------------------------------' . $crlf
. $crlf . $GLOBALS['comment_marker'] . $crlf
. $GLOBALS['comment_marker'] . $GLOBALS['strTableStructure'] . ' ' . $formatted_table_name . $crlf
. $GLOBALS['comment_marker'] . $crlf
. PMA_getTableDef($db, $table, $crlf, $error_url, $dates) . ';' . $crlf
. PMA_getTableComments($db, $table, $crlf, $relation, $comments, $mime);
 
 
return PMA_exportOutputHandler($dump);
}
 
/**
* Dispatches between the versions of 'getTableContent' to use depending
* on the php version
*
* @param string the database name
* @param string the table name
* @param string the end of line sequence
* @param string the url to go back in case of error
* @param string SQL query for obtaining data
*
* @return bool Whether it suceeded
*
* @global boolean whether to use backquotes to allow the use of special
* characters in database, table and fields names or not
* @global integer the number of records
* @global integer the current record position
*
* @access public
*
* @see PMA_getTableContentFast(), PMA_getTableContentOld()
*
* @author staybyte
*/
function PMA_exportData($db, $table, $crlf, $error_url, $sql_query)
{
global $use_backquotes;
global $rows_cnt;
global $current_row;
 
$formatted_table_name = (isset($GLOBALS['use_backquotes']))
? PMA_backquote($table)
: '\'' . $table . '\'';
$head = $crlf
. $GLOBALS['comment_marker'] . $crlf
. $GLOBALS['comment_marker'] . $GLOBALS['strDumpingData'] . ' ' . $formatted_table_name . $crlf
. $GLOBALS['comment_marker'] . $crlf .$crlf;
 
if (!PMA_exportOutputHandler($head)) {
return FALSE;
}
 
$buffer = '';
 
// analyze the query to get the true column names, not the aliases
// (this fixes an undefined index, also if Complete inserts
// are used, we did not get the true column name in case of aliases)
$analyzed_sql = PMA_SQP_analyze(PMA_SQP_parse($sql_query));
 
$result = PMA_DBI_query($sql_query, null, PMA_DBI_QUERY_UNBUFFERED);
if ($result != FALSE) {
$fields_cnt = PMA_DBI_num_fields($result);
 
// Get field information
$fields_meta = PMA_DBI_get_fields_meta($result);
$field_flags = array();
for ($j = 0; $j < $fields_cnt; $j++) {
$field_flags[$j] = PMA_DBI_field_flags($result, $j);
}
 
for ($j = 0; $j < $fields_cnt; $j++) {
if (isset($analyzed_sql[0]['select_expr'][$j]['column'])) {
$field_set[$j] = PMA_backquote($analyzed_sql[0]['select_expr'][$j]['column'], $use_backquotes);
} else {
$field_set[$j] = PMA_backquote($fields_meta[$j]->name, $use_backquotes);
}
}
 
if (isset($GLOBALS['sql_type']) && $GLOBALS['sql_type'] == 'update') {
// update
$schema_insert = 'UPDATE ';
if (isset($GLOBALS['sql_ignore'])) {
$schema_insert .= 'IGNORE ';
}
$schema_insert .= PMA_backquote($table, $use_backquotes) . ' SET ';
unset($GLOBALS['extended_ins']);
} else {
// insert or replace
if (isset($GLOBALS['sql_type']) && $GLOBALS['sql_type'] == 'replace') {
$sql_command = 'REPLACE';
} else {
$sql_command = 'INSERT';
}
 
// delayed inserts?
if (isset($GLOBALS['delayed'])) {
$insert_delayed = ' DELAYED';
} else {
$insert_delayed = '';
}
 
// insert ignore?
if (isset($GLOBALS['sql_type']) && $GLOBALS['sql_type'] == 'insert' && isset($GLOBALS['sql_ignore'])) {
$insert_delayed .= ' IGNORE';
}
 
// scheme for inserting fields
if (isset($GLOBALS['showcolumns'])) {
$fields = implode(', ', $field_set);
$schema_insert = $sql_command . $insert_delayed .' INTO ' . PMA_backquote($table, $use_backquotes)
. ' (' . $fields . ') VALUES ';
} else {
$schema_insert = $sql_command . $insert_delayed .' INTO ' . PMA_backquote($table, $use_backquotes)
. ' VALUES ';
}
}
 
$search = array("\x00", "\x0a", "\x0d", "\x1a"); //\x08\\x09, not required
$replace = array('\0', '\n', '\r', '\Z');
$current_row = 0;
$query_size = 0;
$separator = isset($GLOBALS['extended_ins']) ? ',' : ';';
 
while ($row = PMA_DBI_fetch_row($result)) {
$current_row++;
for ($j = 0; $j < $fields_cnt; $j++) {
// NULL
if (!isset($row[$j]) || is_null($row[$j])) {
$values[] = 'NULL';
// a number
// timestamp is numeric on some MySQL 4.1, BLOBs are sometimes numeric
} elseif ($fields_meta[$j]->numeric && $fields_meta[$j]->type != 'timestamp'
&& ! $fields_meta[$j]->blob) {
$values[] = $row[$j];
// a binary field
// Note: with mysqli, under MySQL 4.1.3, we get the flag
// "binary" for those field types (I don't know why)
} elseif (stristr($field_flags[$j], 'BINARY')
&& isset($GLOBALS['hexforbinary'])
&& $fields_meta[$j]->type != 'datetime'
&& $fields_meta[$j]->type != 'date'
&& $fields_meta[$j]->type != 'time'
&& $fields_meta[$j]->type != 'timestamp'
) {
// empty blobs need to be different, but '0' is also empty :-(
if (empty($row[$j]) && $row[$j] != '0') {
$values[] = '\'\'';
} else {
$values[] = '0x' . bin2hex($row[$j]);
}
// something else -> treat as a string
} else {
$values[] = '\'' . str_replace($search, $replace, PMA_sqlAddslashes($row[$j])) . '\'';
} // end if
} // end for
 
// should we make update?
if (isset($GLOBALS['sql_type']) && $GLOBALS['sql_type'] == 'update') {
 
$insert_line = $schema_insert;
for ($i = 0; $i < $fields_cnt; $i++) {
if ($i > 0) {
$insert_line .= ', ';
}
$insert_line .= $field_set[$i] . ' = ' . $values[$i];
}
 
$insert_line .= ' WHERE ' . PMA_getUvaCondition($result, $fields_cnt, $fields_meta, $row);
 
} else {
 
// Extended inserts case
if (isset($GLOBALS['extended_ins'])) {
if ($current_row == 1) {
$insert_line = $schema_insert . '(' . implode(', ', $values) . ')';
} else {
$insert_line = '(' . implode(', ', $values) . ')';
if (isset($GLOBALS['max_query_size']) && $GLOBALS['max_query_size'] > 0 && $query_size + strlen($insert_line) > $GLOBALS['max_query_size']) {
if (!PMA_exportOutputHandler(';' . $crlf)) {
return FALSE;
}
$query_size = 0;
$current_row = 1;
$insert_line = $schema_insert . $insert_line;
}
}
$query_size += strlen($insert_line);
}
// Other inserts case
else {
$insert_line = $schema_insert . '(' . implode(', ', $values) . ')';
}
}
unset($values);
 
if (!PMA_exportOutputHandler(($current_row == 1 ? '' : $separator . $crlf) . $insert_line)) {
return FALSE;
}
 
} // end while
if ($current_row > 0) {
if (!PMA_exportOutputHandler(';' . $crlf)) {
return FALSE;
}
}
} // end if ($result != FALSE)
PMA_DBI_free_result($result);
 
return TRUE;
} // end of the 'PMA_exportData()' function
?>
/Web/Maintenance/phpMyAdmin/libraries/export/xls.php
0,0 → 1,165
<?php
/* $Id: xls.php,v 2.1 2006/01/17 17:03:02 cybot_tm Exp $ */
// vim: expandtab sw=4 ts=4 sts=4:
 
require_once('Spreadsheet/Excel/Writer.php');
 
/**
* Set of functions used to build MS Excel dumps of tables
*/
 
/**
* Outputs comment
*
* @param string Text of comment
*
* @return bool Whether it suceeded
*/
function PMA_exportComment($text)
{
return TRUE;
}
 
/**
* Outputs export footer
*
* @return bool Whether it suceeded
*
* @access public
*/
function PMA_exportFooter()
{
global $workbook;
global $tmp_filename;
 
$res = $workbook->close();
if (PEAR::isError($res)) {
echo $res->getMessage();
return FALSE;
}
if (!PMA_exportOutputHandler(file_get_contents($tmp_filename))) {
return FALSE;
}
unlink($tmp_filename);
 
return TRUE;
}
 
/**
* Outputs export header
*
* @return bool Whether it suceeded
*
* @access public
*/
function PMA_exportHeader()
{
global $workbook;
global $tmp_filename;
 
if (empty($GLOBALS['cfg']['TempDir'])) {
return FALSE;
}
$tmp_filename = tempnam(realpath($GLOBALS['cfg']['TempDir']), 'pma_xls_');
$workbook = new Spreadsheet_Excel_Writer($tmp_filename);
 
return TRUE;
}
 
/**
* Outputs database header
*
* @param string Database name
*
* @return bool Whether it suceeded
*
* @access public
*/
function PMA_exportDBHeader($db)
{
return TRUE;
}
 
/**
* Outputs database footer
*
* @param string Database name
*
* @return bool Whether it suceeded
*
* @access public
*/
function PMA_exportDBFooter($db)
{
return TRUE;
}
 
/**
* Outputs create database database
*
* @param string Database name
*
* @return bool Whether it suceeded
*
* @access public
*/
function PMA_exportDBCreate($db)
{
return TRUE;
}
 
/**
* Outputs the content of a table in CSV format
*
* @param string the database name
* @param string the table name
* @param string the end of line sequence
* @param string the url to go back in case of error
* @param string SQL query for obtaining data
*
* @return bool Whether it suceeded
*
* @access public
*/
function PMA_exportData($db, $table, $crlf, $error_url, $sql_query)
{
global $what;
global $workbook;
 
$worksheet =& $workbook->addWorksheet($table);
$workbook->setTempDir(realpath($GLOBALS['cfg']['TempDir']));
 
// Gets the data from the database
$result = PMA_DBI_query($sql_query, null, PMA_DBI_QUERY_UNBUFFERED);
$fields_cnt = PMA_DBI_num_fields($result);
$col = 0;
 
// If required, get fields name at the first line
if (isset($GLOBALS['xls_shownames']) && $GLOBALS['xls_shownames'] == 'yes') {
$schema_insert = '';
for ($i = 0; $i < $fields_cnt; $i++) {
$worksheet->write(0, $i, stripslashes(PMA_DBI_field_name($result, $i)));
} // end for
$col++;
} // end if
 
// Format the data
while ($row = PMA_DBI_fetch_row($result)) {
$schema_insert = '';
for ($j = 0; $j < $fields_cnt; $j++) {
if (!isset($row[$j]) || is_null($row[$j])) {
$worksheet->write($col, $j, $GLOBALS['xls_replace_null']);
} elseif ($row[$j] == '0' || $row[$j] != '') {
// FIXME: we should somehow handle character set here!
$worksheet->write($col, $j, $row[$j]);
} else {
$worksheet->write($col, $j, '');
}
} // end for
$col++;
} // end while
PMA_DBI_free_result($result);
 
return TRUE;
}
?>
/Web/Maintenance/phpMyAdmin/libraries/export/xml.php
0,0 → 1,158
<?php
/* $Id: xml.php,v 2.8 2006/01/17 17:03:02 cybot_tm Exp $ */
// vim: expandtab sw=4 ts=4 sts=4:
 
/**
* Set of functions used to build XML dumps of tables
*/
 
/**
* Outputs comment
*
* @param string Text of comment
*
* @return bool Whether it suceeded
*/
function PMA_exportComment($text) {
return PMA_exportOutputHandler('<!-- ' . $text . ' -->' . $GLOBALS['crlf']);
}
 
/**
* Outputs export footer
*
* @return bool Whether it suceeded
*
* @access public
*/
function PMA_exportFooter() {
return TRUE;
}
 
/**
* Outputs export header
*
* @return bool Whether it suceeded
*
* @access public
*/
function PMA_exportHeader() {
global $crlf;
global $cfg;
 
if ($GLOBALS['output_charset_conversion']) {
$charset = $GLOBALS['charset_of_file'];
} else {
$charset = $GLOBALS['charset'];
}
 
$head = '<?xml version="1.0" encoding="' . $charset . '" ?>' . $crlf
. '<!--' . $crlf
. '-' . $crlf
. '- phpMyAdmin XML Dump' . $crlf
. '- version ' . PMA_VERSION . $crlf
. '- http://www.phpmyadmin.net' . $crlf
. '-' . $crlf
. '- ' . $GLOBALS['strHost'] . ': ' . $cfg['Server']['host'];
if (!empty($cfg['Server']['port'])) {
$head .= ':' . $cfg['Server']['port'];
}
$head .= $crlf
. '- ' . $GLOBALS['strGenTime'] . ': ' . PMA_localisedDate() . $crlf
. '- ' . $GLOBALS['strServerVersion'] . ': ' . substr(PMA_MYSQL_INT_VERSION, 0, 1) . '.' . (int) substr(PMA_MYSQL_INT_VERSION, 1, 2) . '.' . (int) substr(PMA_MYSQL_INT_VERSION, 3) . $crlf
. '- ' . $GLOBALS['strPHPVersion'] . ': ' . phpversion() . $crlf
. '-->' . $crlf . $crlf;
return PMA_exportOutputHandler($head);
}
 
/**
* Outputs database header
*
* @param string Database name
*
* @return bool Whether it suceeded
*
* @access public
*/
function PMA_exportDBHeader($db) {
global $crlf;
$head = '<!--' . $crlf
. '- ' . $GLOBALS['strDatabase'] . ': ' . (isset($GLOBALS['use_backquotes']) ? PMA_backquote($db) : '\'' . $db . '\''). $crlf
. '-->' . $crlf
. '<' . $db . '>' . $crlf;
return PMA_exportOutputHandler($head);
}
 
/**
* Outputs database footer
*
* @param string Database name
*
* @return bool Whether it suceeded
*
* @access public
*/
function PMA_exportDBFooter($db) {
global $crlf;
return PMA_exportOutputHandler('</' . $db . '>' . $crlf);
}
 
/**
* Outputs create database database
*
* @param string Database name
*
* @return bool Whether it suceeded
*
* @access public
*/
function PMA_exportDBCreate($db) {
return TRUE;
}
 
 
/**
* Outputs the content of a table
*
* @param string the database name
* @param string the table name
* @param string the end of line sequence
* @param string the url to go back in case of error
* @param string SQL query for obtaining data
*
* @return bool Whether it suceeded
*
* @access public
*/
function PMA_exportData($db, $table, $crlf, $error_url, $sql_query) {
$result = PMA_DBI_query($sql_query, null, PMA_DBI_QUERY_UNBUFFERED);
 
$columns_cnt = PMA_DBI_num_fields($result);
for ($i = 0; $i < $columns_cnt; $i++) {
$columns[$i] = stripslashes(PMA_DBI_field_name($result, $i));
}
unset($i);
 
$buffer = ' <!-- ' . $GLOBALS['strTable'] . ' ' . $table . ' -->' . $crlf;
if (!PMA_exportOutputHandler($buffer)) {
return FALSE;
}
 
while ($record = PMA_DBI_fetch_row($result)) {
$buffer = ' <' . $table . '>' . $crlf;
for ($i = 0; $i < $columns_cnt; $i++) {
if ( isset($record[$i]) && !is_null($record[$i])) {
$buffer .= ' <' . $columns[$i] . '>' . htmlspecialchars($record[$i])
. '</' . $columns[$i] . '>' . $crlf;
}
}
$buffer .= ' </' . $table . '>' . $crlf;
 
if (!PMA_exportOutputHandler($buffer)) {
return FALSE;
}
}
PMA_DBI_free_result($result);
 
return TRUE;
} // end of the 'PMA_getTableXML()' function
?>