2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * Set of functions used to build OpenDocument Spreadsheet dumps of tables
6 * @package phpMyAdmin-Export-ODS
9 if (! defined('PHPMYADMIN')) {
16 if (isset($plugin_list)) {
17 $plugin_list['ods'] = array(
18 'text' => 'strOpenDocumentSpreadsheet',
20 'mime_type' => 'application/vnd.oasis.opendocument.spreadsheet',
23 array('type' => 'text', 'name' => 'null', 'text' => 'strReplaceNULLBy'),
24 array('type' => 'bool', 'name' => 'columns', 'text' => 'strPutColNames'),
25 array('type' => 'hidden', 'name' => 'data'),
27 'options_text' => 'strOptions',
31 $GLOBALS['ods_buffer'] = '';
32 require_once './libraries/opendocument.lib.php';
37 * @param string Text of comment
39 * @return bool Whether it suceeded
41 function PMA_exportComment($text) {
46 * Outputs export footer
48 * @return bool Whether it suceeded
52 function PMA_exportFooter() {
53 $GLOBALS['ods_buffer'] .= '</office:spreadsheet>'
55 . '</office:document-content>';
56 if (!PMA_exportOutputHandler(PMA_createOpenDocument('application/vnd.oasis.opendocument.spreadsheet', $GLOBALS['ods_buffer']))) {
63 * Outputs export header
65 * @return bool Whether it suceeded
69 function PMA_exportHeader() {
70 $GLOBALS['ods_buffer'] .= '<?xml version="1.0" encoding="' . $GLOBALS['charset'] . '"?' . '>'
71 . '<office:document-content '. $GLOBALS['OpenDocumentNS'] . 'office:version="1.0">'
73 . '<office:spreadsheet>';
78 * Outputs database header
80 * @param string Database name
82 * @return bool Whether it suceeded
86 function PMA_exportDBHeader($db) {
91 * Outputs database footer
93 * @param string Database name
95 * @return bool Whether it suceeded
99 function PMA_exportDBFooter($db) {
104 * Outputs create database database
106 * @param string Database name
108 * @return bool Whether it suceeded
112 function PMA_exportDBCreate($db) {
117 * Outputs the content of a table in CSV format
119 * @param string the database name
120 * @param string the table name
121 * @param string the end of line sequence
122 * @param string the url to go back in case of error
123 * @param string SQL query for obtaining data
125 * @return bool Whether it suceeded
129 function PMA_exportData($db, $table, $crlf, $error_url, $sql_query) {
132 // Gets the data from the database
133 $result = PMA_DBI_query($sql_query, null, PMA_DBI_QUERY_UNBUFFERED
);
134 $fields_cnt = PMA_DBI_num_fields($result);
135 $fields_meta = PMA_DBI_get_fields_meta($result);
136 $field_flags = array();
137 for ($j = 0; $j < $fields_cnt; $j++
) {
138 $field_flags[$j] = PMA_DBI_field_flags($result, $j);
141 $GLOBALS['ods_buffer'] .= '<table:table table:name="' . htmlspecialchars($table) . '">';
143 // If required, get fields name at the first line
144 if (isset($GLOBALS[$what . '_columns'])) {
145 $GLOBALS['ods_buffer'] .= '<table:table-row>';
146 for ($i = 0; $i < $fields_cnt; $i++
) {
147 $GLOBALS['ods_buffer'] .= '<table:table-cell office:value-type="string">'
148 . '<text:p>' . htmlspecialchars(stripslashes(PMA_DBI_field_name($result, $i))) . '</text:p>'
149 . '</table:table-cell>';
151 $GLOBALS['ods_buffer'] .= '</table:table-row>';
155 while ($row = PMA_DBI_fetch_row($result)) {
156 $GLOBALS['ods_buffer'] .= '<table:table-row>';
157 for ($j = 0; $j < $fields_cnt; $j++
) {
158 if (!isset($row[$j]) ||
is_null($row[$j])) {
159 $GLOBALS['ods_buffer'] .= '<table:table-cell office:value-type="string">'
160 . '<text:p>' . htmlspecialchars($GLOBALS[$what . '_null']) . '</text:p>'
161 . '</table:table-cell>';
163 } elseif (stristr($field_flags[$j], 'BINARY')
164 && $fields_meta[$j]->blob
) {
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>';