Fix for the Open in New Window in Patient/Client->Patients search gui, take 2.
[openemr.git] / phpmyadmin / libraries / export / ods.php
blob51cf28eca760516a10baea45a45f6f5dc485d244
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 */
8 if (! defined('PHPMYADMIN')) {
9 exit;
12 /**
15 if (isset($plugin_list)) {
16 $plugin_list['ods'] = array(
17 'text' => 'strOpenDocumentSpreadsheet',
18 'extension' => 'ods',
19 'mime_type' => 'application/vnd.oasis.opendocument.spreadsheet',
20 'force_file' => true,
21 'options' => array(
22 array('type' => 'text', 'name' => 'null', 'text' => 'strReplaceNULLBy'),
23 array('type' => 'bool', 'name' => 'columns', 'text' => 'strPutColNames'),
24 array('type' => 'hidden', 'name' => 'data'),
26 'options_text' => 'strOptions',
28 } else {
30 $GLOBALS['ods_buffer'] = '';
31 require_once './libraries/opendocument.lib.php';
33 /**
34 * Outputs comment
36 * @param string Text of comment
38 * @return bool Whether it suceeded
40 function PMA_exportComment($text) {
41 return TRUE;
44 /**
45 * Outputs export footer
47 * @return bool Whether it suceeded
49 * @access public
51 function PMA_exportFooter() {
52 $GLOBALS['ods_buffer'] .= '</office:spreadsheet>'
53 . '</office:body>'
54 . '</office:document-content>';
55 if (!PMA_exportOutputHandler(PMA_createOpenDocument('application/vnd.oasis.opendocument.spreadsheet', $GLOBALS['ods_buffer']))) {
56 return FALSE;
58 return TRUE;
61 /**
62 * Outputs export header
64 * @return bool Whether it suceeded
66 * @access public
68 function PMA_exportHeader() {
69 $GLOBALS['ods_buffer'] .= '<?xml version="1.0" encoding="' . $GLOBALS['charset'] . '"?' . '>'
70 . '<office:document-content '. $GLOBALS['OpenDocumentNS'] . 'office:version="1.0">'
71 . '<office:body>'
72 . '<office:spreadsheet>';
73 return TRUE;
76 /**
77 * Outputs database header
79 * @param string Database name
81 * @return bool Whether it suceeded
83 * @access public
85 function PMA_exportDBHeader($db) {
86 return TRUE;
89 /**
90 * Outputs database footer
92 * @param string Database name
94 * @return bool Whether it suceeded
96 * @access public
98 function PMA_exportDBFooter($db) {
99 return TRUE;
103 * Outputs create database database
105 * @param string Database name
107 * @return bool Whether it suceeded
109 * @access public
111 function PMA_exportDBCreate($db) {
112 return TRUE;
116 * Outputs the content of a table in CSV format
118 * @param string the database name
119 * @param string the table name
120 * @param string the end of line sequence
121 * @param string the url to go back in case of error
122 * @param string SQL query for obtaining data
124 * @return bool Whether it suceeded
126 * @access public
128 function PMA_exportData($db, $table, $crlf, $error_url, $sql_query) {
129 global $what;
131 // Gets the data from the database
132 $result = PMA_DBI_query($sql_query, null, PMA_DBI_QUERY_UNBUFFERED);
133 $fields_cnt = PMA_DBI_num_fields($result);
134 $fields_meta = PMA_DBI_get_fields_meta($result);
135 $field_flags = array();
136 for ($j = 0; $j < $fields_cnt; $j++) {
137 $field_flags[$j] = PMA_DBI_field_flags($result, $j);
140 $GLOBALS['ods_buffer'] .= '<table:table table:name="' . htmlspecialchars($table) . '">';
142 // If required, get fields name at the first line
143 if (isset($GLOBALS[$what . '_columns'])) {
144 $GLOBALS['ods_buffer'] .= '<table:table-row>';
145 for ($i = 0; $i < $fields_cnt; $i++) {
146 $GLOBALS['ods_buffer'] .= '<table:table-cell office:value-type="string">'
147 . '<text:p>' . htmlspecialchars(stripslashes(PMA_DBI_field_name($result, $i))) . '</text:p>'
148 . '</table:table-cell>';
149 } // end for
150 $GLOBALS['ods_buffer'] .= '</table:table-row>';
151 } // end if
153 // Format the data
154 while ($row = PMA_DBI_fetch_row($result)) {
155 $GLOBALS['ods_buffer'] .= '<table:table-row>';
156 for ($j = 0; $j < $fields_cnt; $j++) {
157 if (!isset($row[$j]) || is_null($row[$j])) {
158 $GLOBALS['ods_buffer'] .= '<table:table-cell office:value-type="string">'
159 . '<text:p>' . htmlspecialchars($GLOBALS[$what . '_null']) . '</text:p>'
160 . '</table:table-cell>';
161 // ignore BLOB
162 } elseif (stristr($field_flags[$j], 'BINARY')
163 && $fields_meta[$j]->blob) {
164 $GLOBALS['ods_buffer'] .= '<table:table-cell office:value-type="string">'
165 . '<text:p></text:p>'
166 . '</table:table-cell>';
167 } elseif ($fields_meta[$j]->numeric && $fields_meta[$j]->type != 'timestamp' && ! $fields_meta[$j]->blob) {
168 $GLOBALS['ods_buffer'] .= '<table:table-cell office:value-type="float" office:value="' . $row[$j] . '" >'
169 . '<text:p>' . htmlspecialchars($row[$j]) . '</text:p>'
170 . '</table:table-cell>';
171 } else {
172 $GLOBALS['ods_buffer'] .= '<table:table-cell office:value-type="string">'
173 . '<text:p>' . htmlspecialchars($row[$j]) . '</text:p>'
174 . '</table:table-cell>';
176 } // end for
177 $GLOBALS['ods_buffer'] .= '</table:table-row>';
178 } // end while
179 PMA_DBI_free_result($result);
181 $GLOBALS['ods_buffer'] .= '</table:table>';
183 return TRUE;