new language: uzbek (cyrillic and latin)
[phpmyadmin/crack.git] / libraries / export / ods.php
blob37e3c0837770b73edda2fa13ac49091bc215cd33
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Set of functions used to build OpenDocument Spreadsheet dumps of tables
6 * @package phpMyAdmin-Export-ODS
7 * @version $Id$
8 */
9 if (! defined('PHPMYADMIN')) {
10 exit;
13 /**
16 if (isset($plugin_list)) {
17 $plugin_list['ods'] = array(
18 'text' => 'strOpenDocumentSpreadsheet',
19 'extension' => 'ods',
20 'mime_type' => 'application/vnd.oasis.opendocument.spreadsheet',
21 'force_file' => true,
22 'options' => array(
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',
29 } else {
31 $GLOBALS['ods_buffer'] = '';
32 require_once './libraries/opendocument.lib.php';
34 /**
35 * Outputs comment
37 * @param string Text of comment
39 * @return bool Whether it suceeded
41 function PMA_exportComment($text) {
42 return TRUE;
45 /**
46 * Outputs export footer
48 * @return bool Whether it suceeded
50 * @access public
52 function PMA_exportFooter() {
53 $GLOBALS['ods_buffer'] .= '</office:spreadsheet>'
54 . '</office:body>'
55 . '</office:document-content>';
56 if (!PMA_exportOutputHandler(PMA_createOpenDocument('application/vnd.oasis.opendocument.spreadsheet', $GLOBALS['ods_buffer']))) {
57 return FALSE;
59 return TRUE;
62 /**
63 * Outputs export header
65 * @return bool Whether it suceeded
67 * @access public
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">'
72 . '<office:body>'
73 . '<office:spreadsheet>';
74 return TRUE;
77 /**
78 * Outputs database header
80 * @param string Database name
82 * @return bool Whether it suceeded
84 * @access public
86 function PMA_exportDBHeader($db) {
87 return TRUE;
90 /**
91 * Outputs database footer
93 * @param string Database name
95 * @return bool Whether it suceeded
97 * @access public
99 function PMA_exportDBFooter($db) {
100 return TRUE;
104 * Outputs create database database
106 * @param string Database name
108 * @return bool Whether it suceeded
110 * @access public
112 function PMA_exportDBCreate($db) {
113 return TRUE;
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
127 * @access public
129 function PMA_exportData($db, $table, $crlf, $error_url, $sql_query) {
130 global $what;
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>';
150 } // end for
151 $GLOBALS['ods_buffer'] .= '</table:table-row>';
152 } // end if
154 // Format the data
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>';
162 // ignore BLOB
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>';
172 } else {
173 $GLOBALS['ods_buffer'] .= '<table:table-cell office:value-type="string">'
174 . '<text:p>' . htmlspecialchars($row[$j]) . '</text:p>'
175 . '</table:table-cell>';
177 } // end for
178 $GLOBALS['ods_buffer'] .= '</table:table-row>';
179 } // end while
180 PMA_DBI_free_result($result);
182 $GLOBALS['ods_buffer'] .= '</table:table>';
184 return TRUE;