2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * Set of functions used to build CSV dumps of tables
12 if (isset($plugin_list)) {
13 $plugin_list['htmlexcel'] = array(
14 'text' => 'strHTMLExcel',
16 'mime_type' => 'application/vnd.ms-excel',
19 array('type' => 'text', 'name' => 'null', 'text' => 'strReplaceNULLBy'),
20 array('type' => 'bool', 'name' => 'columns', 'text' => 'strPutColNames'),
21 array('type' => 'hidden', 'name' => 'data'),
23 'options_text' => 'strOptions',
30 * @param string Text of comment
32 * @return bool Whether it suceeded
34 function PMA_exportComment($text) {
39 * Outputs export footer
41 * @return bool Whether it suceeded
45 function PMA_exportFooter() {
46 if (!PMA_exportOutputHandler('
58 * Outputs export header
60 * @return bool Whether it suceeded
64 function PMA_exportHeader() {
65 global $charset, $charset_of_file;
66 if (!PMA_exportOutputHandler('
67 <html xmlns:o="urn:schemas-microsoft-com:office:office"
68 xmlns:x="urn:schemas-microsoft-com:office:excel"
69 xmlns="http://www.w3.org/TR/REC-html40">
71 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
74 <meta http-equiv="Content-type" content="text/html;charset=' . (isset($charset_of_file) ?
$charset_of_file : $charset) .'" />
75 <style id="Classeur1_16681_Styles">
81 <div id="Classeur1_16681" align=center x:publishsource="Excel">
83 <table x:str border=0 cellpadding=0 cellspacing=0 width=100% style="border-collapse: collapse">
92 * Outputs database header
94 * @param string Database name
96 * @return bool Whether it suceeded
100 function PMA_exportDBHeader($db) {
105 * Outputs database footer
107 * @param string Database name
109 * @return bool Whether it suceeded
113 function PMA_exportDBFooter($db) {
118 * Outputs create database database
120 * @param string Database name
122 * @return bool Whether it suceeded
126 function PMA_exportDBCreate($db) {
131 * Outputs the content of a table in CSV format
133 * @param string the database name
134 * @param string the table name
135 * @param string the end of line sequence
136 * @param string the url to go back in case of error
137 * @param string SQL query for obtaining data
139 * @return bool Whether it suceeded
143 function PMA_exportData($db, $table, $crlf, $error_url, $sql_query) {
146 // Gets the data from the database
147 $result = PMA_DBI_query($sql_query, null, PMA_DBI_QUERY_UNBUFFERED
);
148 $fields_cnt = PMA_DBI_num_fields($result);
150 // If required, get fields name at the first line
151 if (isset($GLOBALS[$what . '_columns'])) {
152 $schema_insert = '<tr>';
153 for ($i = 0; $i < $fields_cnt; $i++
) {
154 $schema_insert .= '<td class=xl2216681 nowrap><b>' . htmlspecialchars(stripslashes(PMA_DBI_field_name($result, $i))) . '</b></td>';
156 $schema_insert .= '</tr>';
157 if (!PMA_exportOutputHandler($schema_insert)) {
163 while ($row = PMA_DBI_fetch_row($result)) {
164 $schema_insert = '<tr>';
165 for ($j = 0; $j < $fields_cnt; $j++
) {
166 if (!isset($row[$j]) ||
is_null($row[$j])) {
167 $value = $GLOBALS[$what . '_null'];
168 } elseif ($row[$j] == '0' ||
$row[$j] != '') {
173 $schema_insert .= '<td class=xl2216681 nowrap>' . htmlspecialchars($value) . '</td>';
175 $schema_insert .= '</tr>';
176 if (!PMA_exportOutputHandler($schema_insert)) {
180 PMA_DBI_free_result($result);