2
/* $Id: ods.php 9000 2006-04-28 10:46:13Z nijel $ */
3
// vim: expandtab sw=4 ts=4 sts=4:
6
* Set of functions used to build CSV dumps of tables
9
if (isset($plugin_list)) {
10
$plugin_list['ods'] = array(
11
'text' => 'strOpenDocumentSpreadsheet',
13
'mime_type' => 'application/vnd.oasis.opendocument.spreadsheet',
16
array('type' => 'text', 'name' => 'null', 'text' => 'strReplaceNULLBy'),
17
array('type' => 'bool', 'name' => 'columns', 'text' => 'strPutColNames'),
18
array('type' => 'hidden', 'name' => 'data'),
20
'options_text' => 'strOpenDocumentSpreadsheetOptions',
24
$GLOBALS['ods_buffer'] = '';
25
require_once('./libraries/opendocument.lib.php');
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
$GLOBALS['ods_buffer'] .= '</office:spreadsheet>'
48
. '</office:document-content>';
49
if (!PMA_exportOutputHandler(PMA_createOpenDocument('application/vnd.oasis.opendocument.spreadsheet', $GLOBALS['ods_buffer']))) {
56
* Outputs export header
58
* @return bool Whether it suceeded
62
function PMA_exportHeader() {
63
$GLOBALS['ods_buffer'] .= '<?xml version="1.0" encoding="' . $GLOBALS['charset'] . '"?' . '>'
64
. '<office:document-content '. $GLOBALS['OpenDocumentNS'] . 'office:version="1.0">'
66
. '<office:spreadsheet>';
71
* Outputs database header
73
* @param string Database name
75
* @return bool Whether it suceeded
79
function PMA_exportDBHeader($db) {
84
* Outputs database footer
86
* @param string Database name
88
* @return bool Whether it suceeded
92
function PMA_exportDBFooter($db) {
97
* Outputs create database database
99
* @param string Database name
101
* @return bool Whether it suceeded
105
function PMA_exportDBCreate($db) {
110
* Outputs the content of a table in CSV format
112
* @param string the database name
113
* @param string the table name
114
* @param string the end of line sequence
115
* @param string the url to go back in case of error
116
* @param string SQL query for obtaining data
118
* @return bool Whether it suceeded
122
function PMA_exportData($db, $table, $crlf, $error_url, $sql_query) {
125
// Gets the data from the database
126
$result = PMA_DBI_query($sql_query, null, PMA_DBI_QUERY_UNBUFFERED);
127
$fields_cnt = PMA_DBI_num_fields($result);
128
$fields_meta = PMA_DBI_get_fields_meta($result);
129
$field_flags = array();
130
for ($j = 0; $j < $fields_cnt; $j++) {
131
$field_flags[$j] = PMA_DBI_field_flags($result, $j);
134
$GLOBALS['ods_buffer'] .= '<table:table table:name="' . htmlspecialchars($table) . '">';
136
// If required, get fields name at the first line
137
if (isset($GLOBALS[$what . '_columns'])) {
138
$GLOBALS['ods_buffer'] .= '<table:table-row>';
139
for ($i = 0; $i < $fields_cnt; $i++) {
140
$GLOBALS['ods_buffer'] .= '<table:table-cell office:value-type="string">'
141
. '<text:p>' . htmlspecialchars(stripslashes(PMA_DBI_field_name($result, $i))) . '</text:p>'
142
. '</table:table-cell>';
144
$GLOBALS['ods_buffer'] .= '</table:table-row>';
148
while ($row = PMA_DBI_fetch_row($result)) {
149
$GLOBALS['ods_buffer'] .= '<table:table-row>';
150
for ($j = 0; $j < $fields_cnt; $j++) {
151
if (!isset($row[$j]) || is_null($row[$j])) {
152
$GLOBALS['ods_buffer'] .= '<table:table-cell office:value-type="string">'
153
. '<text:p>' . htmlspecialchars($GLOBALS[$what . '_null']) . '</text:p>'
154
. '</table:table-cell>';
155
// ignore binary field
156
// Note: with mysqli, under MySQL 4.1.3, we get the flag
157
// "binary" for those field types (I don't know why)
158
} elseif (stristr($field_flags[$j], 'BINARY')
159
&& isset($GLOBALS['sql_hex_for_binary'])
160
&& $fields_meta[$j]->type != 'datetime'
161
&& $fields_meta[$j]->type != 'date'
162
&& $fields_meta[$j]->type != 'time'
163
&& $fields_meta[$j]->type != 'timestamp'
165
$GLOBALS['ods_buffer'] .= '<table:table-cell office:value-type="string">'
166
. '<text:p></text:p>'
167
. '</table:table-cell>';
168
} elseif ($fields_meta[$j]->numeric && $fields_meta[$j]->type != 'timestamp' && ! $fields_meta[$j]->blob) {
169
$GLOBALS['ods_buffer'] .= '<table:table-cell office:value-type="float" office:value="' . $row[$j] . '" >'
170
. '<text:p>' . htmlspecialchars($row[$j]) . '</text:p>'
171
. '</table:table-cell>';
173
$GLOBALS['ods_buffer'] .= '<table:table-cell office:value-type="string">'
174
. '<text:p>' . htmlspecialchars($row[$j]) . '</text:p>'
175
. '</table:table-cell>';
178
$GLOBALS['ods_buffer'] .= '</table:table-row>';
180
PMA_DBI_free_result($result);
182
$GLOBALS['ods_buffer'] .= '</table:table>';