home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / Servidores / xampp-win32-1.6.7-installer.exe / phpMyAdmin / libraries / export / ods.php < prev    next >
Encoding:
PHP Script  |  2008-06-23  |  5.4 KB  |  188 lines

  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: ods.php 11326 2008-06-17 21:32:48Z lem9 $
  7.  */
  8. if (! defined('PHPMYADMIN')) {
  9.     exit;
  10. }
  11.  
  12. /**
  13.  *
  14.  */
  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'),
  25.             ),
  26.         'options_text' => 'strOptions',
  27.         );
  28. } else {
  29.  
  30. $GLOBALS['ods_buffer'] = '';
  31. require_once './libraries/opendocument.lib.php';
  32.  
  33. /**
  34.  * Outputs comment
  35.  *
  36.  * @param   string      Text of comment
  37.  *
  38.  * @return  bool        Whether it suceeded
  39.  */
  40. function PMA_exportComment($text) {
  41.     return TRUE;
  42. }
  43.  
  44. /**
  45.  * Outputs export footer
  46.  *
  47.  * @return  bool        Whether it suceeded
  48.  *
  49.  * @access  public
  50.  */
  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;
  57.     }
  58.     return TRUE;
  59. }
  60.  
  61. /**
  62.  * Outputs export header
  63.  *
  64.  * @return  bool        Whether it suceeded
  65.  *
  66.  * @access  public
  67.  */
  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;
  74. }
  75.  
  76. /**
  77.  * Outputs database header
  78.  *
  79.  * @param   string      Database name
  80.  *
  81.  * @return  bool        Whether it suceeded
  82.  *
  83.  * @access  public
  84.  */
  85. function PMA_exportDBHeader($db) {
  86.     return TRUE;
  87. }
  88.  
  89. /**
  90.  * Outputs database footer
  91.  *
  92.  * @param   string      Database name
  93.  *
  94.  * @return  bool        Whether it suceeded
  95.  *
  96.  * @access  public
  97.  */
  98. function PMA_exportDBFooter($db) {
  99.     return TRUE;
  100. }
  101.  
  102. /**
  103.  * Outputs create database database
  104.  *
  105.  * @param   string      Database name
  106.  *
  107.  * @return  bool        Whether it suceeded
  108.  *
  109.  * @access  public
  110.  */
  111. function PMA_exportDBCreate($db) {
  112.     return TRUE;
  113. }
  114.  
  115. /**
  116.  * Outputs the content of a table in CSV format
  117.  *
  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
  123.  *
  124.  * @return  bool        Whether it suceeded
  125.  *
  126.  * @access  public
  127.  */
  128. function PMA_exportData($db, $table, $crlf, $error_url, $sql_query) {
  129.     global $what;
  130.  
  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);
  138.     }
  139.  
  140.     $GLOBALS['ods_buffer'] .= '<table:table table:name="' . htmlspecialchars($table) . '">';
  141.  
  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
  152.  
  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>';
  175.             }
  176.         } // end for
  177.         $GLOBALS['ods_buffer'] .= '</table:table-row>';
  178.     } // end while
  179.     PMA_DBI_free_result($result);
  180.  
  181.     $GLOBALS['ods_buffer'] .= '</table:table>';
  182.  
  183.     return TRUE;
  184. }
  185.  
  186. }
  187. ?>
  188.