2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * Set of functions used to build CSV dumps of tables
8 if (! defined('PHPMYADMIN')) {
15 if (isset($plugin_list)) {
16 $plugin_list['htmlexcel'] = array(
17 'text' => 'strHTMLExcel',
19 'mime_type' => 'application/vnd.ms-excel',
22 array('type' => 'text', 'name' => 'null', 'text' => 'strReplaceNULLBy'),
23 array('type' => 'bool', 'name' => 'columns', 'text' => 'strPutColNames'),
24 array('type' => 'hidden', 'name' => 'data'),
26 'options_text' => 'strOptions',
33 * @param string Text of comment
35 * @return bool Whether it suceeded
37 function PMA_exportComment($text) {
42 * Outputs export footer
44 * @return bool Whether it suceeded
48 function PMA_exportFooter() {
49 if (!PMA_exportOutputHandler('
61 * Outputs export header
63 * @return bool Whether it suceeded
67 function PMA_exportHeader() {
68 global $charset, $charset_of_file;
69 if (!PMA_exportOutputHandler('
70 <html xmlns:o="urn:schemas-microsoft-com:office:office"
71 xmlns:x="urn:schemas-microsoft-com:office:excel"
72 xmlns="http://www.w3.org/TR/REC-html40">
74 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
77 <meta http-equiv="Content-type" content="text/html;charset=' . (isset($charset_of_file) ?
$charset_of_file : $charset) .'" />
78 <style id="Classeur1_16681_Styles">
84 <div id="Classeur1_16681" align=center x:publishsource="Excel">
86 <table x:str border=0 cellpadding=0 cellspacing=0 width=100% style="border-collapse: collapse">
95 * Outputs database header
97 * @param string Database name
99 * @return bool Whether it suceeded
103 function PMA_exportDBHeader($db) {
108 * Outputs database footer
110 * @param string Database name
112 * @return bool Whether it suceeded
116 function PMA_exportDBFooter($db) {
121 * Outputs create database database
123 * @param string Database name
125 * @return bool Whether it suceeded
129 function PMA_exportDBCreate($db) {
134 * Outputs the content of a table in CSV format
136 * @param string the database name
137 * @param string the table name
138 * @param string the end of line sequence
139 * @param string the url to go back in case of error
140 * @param string SQL query for obtaining data
142 * @return bool Whether it suceeded
146 function PMA_exportData($db, $table, $crlf, $error_url, $sql_query) {
149 // Gets the data from the database
150 $result = PMA_DBI_query($sql_query, null, PMA_DBI_QUERY_UNBUFFERED
);
151 $fields_cnt = PMA_DBI_num_fields($result);
153 // If required, get fields name at the first line
154 if (isset($GLOBALS[$what . '_columns'])) {
155 $schema_insert = '<tr>';
156 for ($i = 0; $i < $fields_cnt; $i++
) {
157 $schema_insert .= '<td class=xl2216681 nowrap><b>' . htmlspecialchars(stripslashes(PMA_DBI_field_name($result, $i))) . '</b></td>';
159 $schema_insert .= '</tr>';
160 if (!PMA_exportOutputHandler($schema_insert)) {
165 $fields_meta = PMA_DBI_get_fields_meta($result);
168 while ($row = PMA_DBI_fetch_row($result)) {
169 $schema_insert = '<tr>';
170 for ($j = 0; $j < $fields_cnt; $j++
) {
171 if (!isset($row[$j]) ||
is_null($row[$j])) {
172 $value = $GLOBALS[$what . '_null'];
173 } elseif ($row[$j] == '0' ||
$row[$j] != '') {
178 $schema_insert .= '<td class=xl2216681 nowrap';
179 if ('1' == $fields_meta[$j]->numeric) {
180 $schema_insert .= ' x:num ';
182 $schema_insert .= '>' . htmlspecialchars($value) . '</td>';
184 $schema_insert .= '</tr>';
185 if (!PMA_exportOutputHandler($schema_insert)) {
189 PMA_DBI_free_result($result);