/phpmyadmin/libraries/export/ods.php

https://github.com/md-tech/openemr · PHP · 187 lines · 97 code · 16 blank · 74 comment · 16 complexity · 878675c0ba0d8ec87a230976264cc905 MD5 · raw file

  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * Set of functions used to build CSV dumps of tables
  5. *
  6. * @version $Id$
  7. */
  8. if (! defined('PHPMYADMIN')) {
  9. exit;
  10. }
  11. /**
  12. *
  13. */
  14. if (isset($plugin_list)) {
  15. $plugin_list['ods'] = array(
  16. 'text' => 'strOpenDocumentSpreadsheet',
  17. 'extension' => 'ods',
  18. 'mime_type' => 'application/vnd.oasis.opendocument.spreadsheet',
  19. 'force_file' => true,
  20. 'options' => array(
  21. array('type' => 'text', 'name' => 'null', 'text' => 'strReplaceNULLBy'),
  22. array('type' => 'bool', 'name' => 'columns', 'text' => 'strPutColNames'),
  23. array('type' => 'hidden', 'name' => 'data'),
  24. ),
  25. 'options_text' => 'strOptions',
  26. );
  27. } else {
  28. $GLOBALS['ods_buffer'] = '';
  29. require_once './libraries/opendocument.lib.php';
  30. /**
  31. * Outputs comment
  32. *
  33. * @param string Text of comment
  34. *
  35. * @return bool Whether it suceeded
  36. */
  37. function PMA_exportComment($text) {
  38. return TRUE;
  39. }
  40. /**
  41. * Outputs export footer
  42. *
  43. * @return bool Whether it suceeded
  44. *
  45. * @access public
  46. */
  47. function PMA_exportFooter() {
  48. $GLOBALS['ods_buffer'] .= '</office:spreadsheet>'
  49. . '</office:body>'
  50. . '</office:document-content>';
  51. if (!PMA_exportOutputHandler(PMA_createOpenDocument('application/vnd.oasis.opendocument.spreadsheet', $GLOBALS['ods_buffer']))) {
  52. return FALSE;
  53. }
  54. return TRUE;
  55. }
  56. /**
  57. * Outputs export header
  58. *
  59. * @return bool Whether it suceeded
  60. *
  61. * @access public
  62. */
  63. function PMA_exportHeader() {
  64. $GLOBALS['ods_buffer'] .= '<?xml version="1.0" encoding="' . $GLOBALS['charset'] . '"?' . '>'
  65. . '<office:document-content '. $GLOBALS['OpenDocumentNS'] . 'office:version="1.0">'
  66. . '<office:body>'
  67. . '<office:spreadsheet>';
  68. return TRUE;
  69. }
  70. /**
  71. * Outputs database header
  72. *
  73. * @param string Database name
  74. *
  75. * @return bool Whether it suceeded
  76. *
  77. * @access public
  78. */
  79. function PMA_exportDBHeader($db) {
  80. return TRUE;
  81. }
  82. /**
  83. * Outputs database footer
  84. *
  85. * @param string Database name
  86. *
  87. * @return bool Whether it suceeded
  88. *
  89. * @access public
  90. */
  91. function PMA_exportDBFooter($db) {
  92. return TRUE;
  93. }
  94. /**
  95. * Outputs create database database
  96. *
  97. * @param string Database name
  98. *
  99. * @return bool Whether it suceeded
  100. *
  101. * @access public
  102. */
  103. function PMA_exportDBCreate($db) {
  104. return TRUE;
  105. }
  106. /**
  107. * Outputs the content of a table in CSV format
  108. *
  109. * @param string the database name
  110. * @param string the table name
  111. * @param string the end of line sequence
  112. * @param string the url to go back in case of error
  113. * @param string SQL query for obtaining data
  114. *
  115. * @return bool Whether it suceeded
  116. *
  117. * @access public
  118. */
  119. function PMA_exportData($db, $table, $crlf, $error_url, $sql_query) {
  120. global $what;
  121. // Gets the data from the database
  122. $result = PMA_DBI_query($sql_query, null, PMA_DBI_QUERY_UNBUFFERED);
  123. $fields_cnt = PMA_DBI_num_fields($result);
  124. $fields_meta = PMA_DBI_get_fields_meta($result);
  125. $field_flags = array();
  126. for ($j = 0; $j < $fields_cnt; $j++) {
  127. $field_flags[$j] = PMA_DBI_field_flags($result, $j);
  128. }
  129. $GLOBALS['ods_buffer'] .= '<table:table table:name="' . htmlspecialchars($table) . '">';
  130. // If required, get fields name at the first line
  131. if (isset($GLOBALS[$what . '_columns'])) {
  132. $GLOBALS['ods_buffer'] .= '<table:table-row>';
  133. for ($i = 0; $i < $fields_cnt; $i++) {
  134. $GLOBALS['ods_buffer'] .= '<table:table-cell office:value-type="string">'
  135. . '<text:p>' . htmlspecialchars(stripslashes(PMA_DBI_field_name($result, $i))) . '</text:p>'
  136. . '</table:table-cell>';
  137. } // end for
  138. $GLOBALS['ods_buffer'] .= '</table:table-row>';
  139. } // end if
  140. // Format the data
  141. while ($row = PMA_DBI_fetch_row($result)) {
  142. $GLOBALS['ods_buffer'] .= '<table:table-row>';
  143. for ($j = 0; $j < $fields_cnt; $j++) {
  144. if (!isset($row[$j]) || is_null($row[$j])) {
  145. $GLOBALS['ods_buffer'] .= '<table:table-cell office:value-type="string">'
  146. . '<text:p>' . htmlspecialchars($GLOBALS[$what . '_null']) . '</text:p>'
  147. . '</table:table-cell>';
  148. // ignore BLOB
  149. } elseif (stristr($field_flags[$j], 'BINARY')
  150. && $fields_meta[$j]->blob) {
  151. $GLOBALS['ods_buffer'] .= '<table:table-cell office:value-type="string">'
  152. . '<text:p></text:p>'
  153. . '</table:table-cell>';
  154. } elseif ($fields_meta[$j]->numeric && $fields_meta[$j]->type != 'timestamp' && ! $fields_meta[$j]->blob) {
  155. $GLOBALS['ods_buffer'] .= '<table:table-cell office:value-type="float" office:value="' . $row[$j] . '" >'
  156. . '<text:p>' . htmlspecialchars($row[$j]) . '</text:p>'
  157. . '</table:table-cell>';
  158. } else {
  159. $GLOBALS['ods_buffer'] .= '<table:table-cell office:value-type="string">'
  160. . '<text:p>' . htmlspecialchars($row[$j]) . '</text:p>'
  161. . '</table:table-cell>';
  162. }
  163. } // end for
  164. $GLOBALS['ods_buffer'] .= '</table:table-row>';
  165. } // end while
  166. PMA_DBI_free_result($result);
  167. $GLOBALS['ods_buffer'] .= '</table:table>';
  168. return TRUE;
  169. }
  170. }
  171. ?>