2.11.1.2 release
[phpmyadmin/arisferyanto.git] / libraries / export / ods.php
blob09ba8250599e4c267e393a52914afe84562c8b75
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Set of functions used to build CSV dumps of tables
6 * @version $Id$
7 */
9 /**
12 if (isset($plugin_list)) {
13 $plugin_list['ods'] = array(
14 'text' => 'strOpenDocumentSpreadsheet',
15 'extension' => 'ods',
16 'mime_type' => 'application/vnd.oasis.opendocument.spreadsheet',
17 'force_file' => true,
18 'options' => array(
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',
25 } else {
27 $GLOBALS['ods_buffer'] = '';
28 require_once './libraries/opendocument.lib.php';
30 /**
31 * Outputs comment
33 * @param string Text of comment
35 * @return bool Whether it suceeded
37 function PMA_exportComment($text) {
38 return TRUE;
41 /**
42 * Outputs export footer
44 * @return bool Whether it suceeded
46 * @access public
48 function PMA_exportFooter() {
49 $GLOBALS['ods_buffer'] .= '</office:spreadsheet>'
50 . '</office:body>'
51 . '</office:document-content>';
52 if (!PMA_exportOutputHandler(PMA_createOpenDocument('application/vnd.oasis.opendocument.spreadsheet', $GLOBALS['ods_buffer']))) {
53 return FALSE;
55 return TRUE;
58 /**
59 * Outputs export header
61 * @return bool Whether it suceeded
63 * @access public
65 function PMA_exportHeader() {
66 $GLOBALS['ods_buffer'] .= '<?xml version="1.0" encoding="' . $GLOBALS['charset'] . '"?' . '>'
67 . '<office:document-content '. $GLOBALS['OpenDocumentNS'] . 'office:version="1.0">'
68 . '<office:body>'
69 . '<office:spreadsheet>';
70 return TRUE;
73 /**
74 * Outputs database header
76 * @param string Database name
78 * @return bool Whether it suceeded
80 * @access public
82 function PMA_exportDBHeader($db) {
83 return TRUE;
86 /**
87 * Outputs database footer
89 * @param string Database name
91 * @return bool Whether it suceeded
93 * @access public
95 function PMA_exportDBFooter($db) {
96 return TRUE;
99 /**
100 * Outputs create database database
102 * @param string Database name
104 * @return bool Whether it suceeded
106 * @access public
108 function PMA_exportDBCreate($db) {
109 return TRUE;
113 * Outputs the content of a table in CSV format
115 * @param string the database name
116 * @param string the table name
117 * @param string the end of line sequence
118 * @param string the url to go back in case of error
119 * @param string SQL query for obtaining data
121 * @return bool Whether it suceeded
123 * @access public
125 function PMA_exportData($db, $table, $crlf, $error_url, $sql_query) {
126 global $what;
128 // Gets the data from the database
129 $result = PMA_DBI_query($sql_query, null, PMA_DBI_QUERY_UNBUFFERED);
130 $fields_cnt = PMA_DBI_num_fields($result);
131 $fields_meta = PMA_DBI_get_fields_meta($result);
132 $field_flags = array();
133 for ($j = 0; $j < $fields_cnt; $j++) {
134 $field_flags[$j] = PMA_DBI_field_flags($result, $j);
137 $GLOBALS['ods_buffer'] .= '<table:table table:name="' . htmlspecialchars($table) . '">';
139 // If required, get fields name at the first line
140 if (isset($GLOBALS[$what . '_columns'])) {
141 $GLOBALS['ods_buffer'] .= '<table:table-row>';
142 for ($i = 0; $i < $fields_cnt; $i++) {
143 $GLOBALS['ods_buffer'] .= '<table:table-cell office:value-type="string">'
144 . '<text:p>' . htmlspecialchars(stripslashes(PMA_DBI_field_name($result, $i))) . '</text:p>'
145 . '</table:table-cell>';
146 } // end for
147 $GLOBALS['ods_buffer'] .= '</table:table-row>';
148 } // end if
150 // Format the data
151 while ($row = PMA_DBI_fetch_row($result)) {
152 $GLOBALS['ods_buffer'] .= '<table:table-row>';
153 for ($j = 0; $j < $fields_cnt; $j++) {
154 if (!isset($row[$j]) || is_null($row[$j])) {
155 $GLOBALS['ods_buffer'] .= '<table:table-cell office:value-type="string">'
156 . '<text:p>' . htmlspecialchars($GLOBALS[$what . '_null']) . '</text:p>'
157 . '</table:table-cell>';
158 // ignore BLOB
159 } elseif (stristr($field_flags[$j], 'BINARY')
160 && $fields_meta[$j]->blob) {
161 $GLOBALS['ods_buffer'] .= '<table:table-cell office:value-type="string">'
162 . '<text:p></text:p>'
163 . '</table:table-cell>';
164 } elseif ($fields_meta[$j]->numeric && $fields_meta[$j]->type != 'timestamp' && ! $fields_meta[$j]->blob) {
165 $GLOBALS['ods_buffer'] .= '<table:table-cell office:value-type="float" office:value="' . $row[$j] . '" >'
166 . '<text:p>' . htmlspecialchars($row[$j]) . '</text:p>'
167 . '</table:table-cell>';
168 } else {
169 $GLOBALS['ods_buffer'] .= '<table:table-cell office:value-type="string">'
170 . '<text:p>' . htmlspecialchars($row[$j]) . '</text:p>'
171 . '</table:table-cell>';
173 } // end for
174 $GLOBALS['ods_buffer'] .= '</table:table-row>';
175 } // end while
176 PMA_DBI_free_result($result);
178 $GLOBALS['ods_buffer'] .= '</table:table>';
180 return TRUE;