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 / htmlword.php < prev    next >
Encoding:
PHP Script  |  2008-06-23  |  11.0 KB  |  349 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: htmlword.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['htmlword'] = array(
  17.         'text' => 'strHTMLWord',
  18.         'extension' => 'doc',
  19.         'mime_type' => 'application/vnd.ms-word',
  20.         'force_file' => true,
  21.         'options' => array(
  22.             array('type' => 'bool', 'name' => 'structure', 'text' => 'strStructure', 'force' => 'data'),
  23.             array('type' => 'bgroup', 'name' => 'data', 'text' => 'strData', 'force' => 'structure'),
  24.             array('type' => 'text', 'name' => 'null', 'text' => 'strReplaceNULLBy'),
  25.             array('type' => 'bool', 'name' => 'columns', 'text' => 'strPutColNames'),
  26.             array('type' => 'egroup'),
  27.             ),
  28.         'options_text' => 'strOptions',
  29.         );
  30. } else {
  31.  
  32. /**
  33.  * Outputs comment
  34.  *
  35.  * @param   string      Text of comment
  36.  *
  37.  * @return  bool        Whether it suceeded
  38.  */
  39. function PMA_exportComment($text) {
  40.     return TRUE;
  41. }
  42.  
  43. /**
  44.  * Outputs export footer
  45.  *
  46.  * @return  bool        Whether it suceeded
  47.  *
  48.  * @access  public
  49.  */
  50. function PMA_exportFooter() {
  51.     return PMA_exportOutputHandler('</body></html>');
  52. }
  53.  
  54. /**
  55.  * Outputs export header
  56.  *
  57.  * @return  bool        Whether it suceeded
  58.  *
  59.  * @access  public
  60.  */
  61. function PMA_exportHeader() {
  62.     global $charset, $charset_of_file;
  63.     return PMA_exportOutputHandler('<html xmlns:o="urn:schemas-microsoft-com:office:office"
  64. xmlns:x="urn:schemas-microsoft-com:office:word"
  65. xmlns="http://www.w3.org/TR/REC-html40">
  66.  
  67. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  68. <html>
  69. <head>
  70.     <meta http-equiv="Content-type" content="text/html;charset=' . (isset($charset_of_file) ? $charset_of_file : $charset) .'" />
  71. </head>
  72. <body>');
  73. }
  74.  
  75. /**
  76.  * Outputs database header
  77.  *
  78.  * @param   string      Database name
  79.  *
  80.  * @return  bool        Whether it suceeded
  81.  *
  82.  * @access  public
  83.  */
  84. function PMA_exportDBHeader($db) {
  85.     return PMA_exportOutputHandler('<h1>' . $GLOBALS['strDatabase'] . ' ' . $db . '</h1>');
  86. }
  87.  
  88. /**
  89.  * Outputs database footer
  90.  *
  91.  * @param   string      Database name
  92.  *
  93.  * @return  bool        Whether it suceeded
  94.  *
  95.  * @access  public
  96.  */
  97. function PMA_exportDBFooter($db) {
  98.     return TRUE;
  99. }
  100.  
  101. /**
  102.  * Outputs create database database
  103.  *
  104.  * @param   string      Database name
  105.  *
  106.  * @return  bool        Whether it suceeded
  107.  *
  108.  * @access  public
  109.  */
  110. function PMA_exportDBCreate($db) {
  111.     return TRUE;
  112. }
  113.  
  114. /**
  115.  * Outputs the content of a table in CSV format
  116.  *
  117.  * @param   string      the database name
  118.  * @param   string      the table name
  119.  * @param   string      the end of line sequence
  120.  * @param   string      the url to go back in case of error
  121.  * @param   string      SQL query for obtaining data
  122.  *
  123.  * @return  bool        Whether it suceeded
  124.  *
  125.  * @access  public
  126.  */
  127. function PMA_exportData($db, $table, $crlf, $error_url, $sql_query)
  128. {
  129.     global $what;
  130.  
  131.     if (!PMA_exportOutputHandler('<h2>' . $GLOBALS['strDumpingData'] . ' ' . $table . '</h2>')) {
  132.         return FALSE;
  133.     }
  134.     if (!PMA_exportOutputHandler('<table class="width100" cellspacing="1">')) {
  135.         return FALSE;
  136.     }
  137.  
  138.     // Gets the data from the database
  139.     $result      = PMA_DBI_query($sql_query, null, PMA_DBI_QUERY_UNBUFFERED);
  140.     $fields_cnt  = PMA_DBI_num_fields($result);
  141.  
  142.     // If required, get fields name at the first line
  143.     if (isset($GLOBALS['htmlword_columns'])) {
  144.         $schema_insert = '<tr class="print-category">';
  145.         for ($i = 0; $i < $fields_cnt; $i++) {
  146.             $schema_insert .= '<td class="print"><b>' . htmlspecialchars(stripslashes(PMA_DBI_field_name($result, $i))) . '</b></td>';
  147.         } // end for
  148.         $schema_insert .= '</tr>';
  149.         if (!PMA_exportOutputHandler($schema_insert)) {
  150.             return FALSE;
  151.         }
  152.     } // end if
  153.  
  154.     // Format the data
  155.     while ($row = PMA_DBI_fetch_row($result)) {
  156.         $schema_insert = '<tr class="print-category">';
  157.         for ($j = 0; $j < $fields_cnt; $j++) {
  158.             if (!isset($row[$j]) || is_null($row[$j])) {
  159.                 $value = $GLOBALS[$what . '_null'];
  160.             } elseif ($row[$j] == '0' || $row[$j] != '') {
  161.                 $value = $row[$j];
  162.             } else {
  163.                 $value = '';
  164.             }
  165.             $schema_insert .= '<td class="print">' . htmlspecialchars($value) . '</td>';
  166.         } // end for
  167.         $schema_insert .= '</tr>';
  168.         if (!PMA_exportOutputHandler($schema_insert)) {
  169.             return FALSE;
  170.         }
  171.     } // end while
  172.     PMA_DBI_free_result($result);
  173.     if (!PMA_exportOutputHandler('</table>')) {
  174.         return FALSE;
  175.     }
  176.  
  177.     return TRUE;
  178. }
  179.  
  180. function PMA_exportStructure($db, $table, $crlf, $error_url, $do_relation = false, $do_comments = false, $do_mime = false, $dates = false, $dummy)
  181. {
  182.     global $cfgRelation;
  183.  
  184.     if (!PMA_exportOutputHandler('<h2>' . $GLOBALS['strTableStructure'] . ' ' .$table . '</h2>')) {
  185.         return FALSE;
  186.     }
  187.  
  188.     /**
  189.      * Get the unique keys in the table
  190.      */
  191.     $keys_query     = 'SHOW KEYS FROM ' . PMA_backquote($table) . ' FROM '. PMA_backquote($db);
  192.     $keys_result    = PMA_DBI_query($keys_query);
  193.     $unique_keys    = array();
  194.     while ($key = PMA_DBI_fetch_assoc($keys_result)) {
  195.         if ($key['Non_unique'] == 0) {
  196.             $unique_keys[] = $key['Column_name'];
  197.         }
  198.     }
  199.     PMA_DBI_free_result($keys_result);
  200.  
  201.     /**
  202.      * Gets fields properties
  203.      */
  204.     PMA_DBI_select_db($db);
  205.     $local_query = 'SHOW FIELDS FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table);
  206.     $result      = PMA_DBI_query($local_query);
  207.     $fields_cnt  = PMA_DBI_num_rows($result);
  208.  
  209.     // Check if we can use Relations (Mike Beck)
  210.     if ($do_relation && !empty($cfgRelation['relation'])) {
  211.         // Find which tables are related with the current one and write it in
  212.         // an array
  213.         $res_rel = PMA_getForeigners($db, $table);
  214.  
  215.         if ($res_rel && count($res_rel) > 0) {
  216.             $have_rel = TRUE;
  217.         } else {
  218.             $have_rel = FALSE;
  219.         }
  220.     } else {
  221.            $have_rel = FALSE;
  222.     } // end if
  223.  
  224.     /**
  225.      * Displays the table structure
  226.      */
  227.     if (!PMA_exportOutputHandler('<table class="width100" cellspacing="1">')) {
  228.         return FALSE;
  229.     }
  230.  
  231.     $columns_cnt = 4;
  232.     if ($do_relation && $have_rel) {
  233.         $columns_cnt++;
  234.     }
  235.     if ($do_comments && $cfgRelation['commwork']) {
  236.         $columns_cnt++;
  237.     }
  238.     if ($do_mime && $cfgRelation['mimework']) {
  239.         $columns_cnt++;
  240.     }
  241.  
  242.     $schema_insert = '<tr class="print-category">';
  243.     $schema_insert .= '<th class="print">' . htmlspecialchars($GLOBALS['strField']) . '</th>';
  244.     $schema_insert .= '<td class="print"><b>' . htmlspecialchars($GLOBALS['strType']) . '</b></td>';
  245.     $schema_insert .= '<td class="print"><b>' . htmlspecialchars($GLOBALS['strNull']) . '</b></td>';
  246.     $schema_insert .= '<td class="print"><b>' . htmlspecialchars($GLOBALS['strDefault']) . '</b></td>';
  247.     if ($do_relation && $have_rel) {
  248.         $schema_insert .= '<td class="print"><b>' . htmlspecialchars($GLOBALS['strLinksTo']) . '</b></td>';
  249.     }
  250.     if ($do_comments && ($cfgRelation['commwork'] || PMA_MYSQL_INT_VERSION >= 40100)) {
  251.         $schema_insert .= '<td class="print"><b>' . htmlspecialchars($GLOBALS['strComments']) . '</b></td>';
  252.         $comments = PMA_getComments($db, $table);
  253.     }
  254.     if ($do_mime && $cfgRelation['mimework']) {
  255.         $schema_insert .= '<td class="print"><b>' . htmlspecialchars('MIME') . '</b></td>';
  256.         $mime_map = PMA_getMIME($db, $table, true);
  257.     }
  258.     $schema_insert .= '</tr>';
  259.  
  260.     if (!PMA_exportOutputHandler($schema_insert)) {
  261.         return FALSE;
  262.     }
  263.  
  264.     while ($row = PMA_DBI_fetch_assoc($result)) {
  265.  
  266.         $schema_insert = '<tr class="print-category">';
  267.         $type             = $row['Type'];
  268.         // reformat mysql query output - staybyte - 9. June 2001
  269.         // loic1: set or enum types: slashes single quotes inside options
  270.         if (eregi('^(set|enum)\((.+)\)$', $type, $tmp)) {
  271.             $tmp[2]       = substr(ereg_replace('([^,])\'\'', '\\1\\\'', ',' . $tmp[2]), 1);
  272.             $type         = $tmp[1] . '(' . str_replace(',', ', ', $tmp[2]) . ')';
  273.             $type_nowrap  = '';
  274.  
  275.             $binary       = 0;
  276.             $unsigned     = 0;
  277.             $zerofill     = 0;
  278.         } else {
  279.             $type_nowrap  = ' nowrap="nowrap"';
  280.             $type         = eregi_replace('BINARY', '', $type);
  281.             $type         = eregi_replace('ZEROFILL', '', $type);
  282.             $type         = eregi_replace('UNSIGNED', '', $type);
  283.             if (empty($type)) {
  284.                 $type     = ' ';
  285.             }
  286.  
  287.             $binary       = eregi('BINARY', $row['Type']);
  288.             $unsigned     = eregi('UNSIGNED', $row['Type']);
  289.             $zerofill     = eregi('ZEROFILL', $row['Type']);
  290.         }
  291.         $strAttribute     = ' ';
  292.         if ($binary) {
  293.             $strAttribute = 'BINARY';
  294.         }
  295.         if ($unsigned) {
  296.             $strAttribute = 'UNSIGNED';
  297.         }
  298.         if ($zerofill) {
  299.             $strAttribute = 'UNSIGNED ZEROFILL';
  300.         }
  301.         if (!isset($row['Default'])) {
  302.             if ($row['Null'] != '') {
  303.                 $row['Default'] = 'NULL';
  304.             }
  305.         } else {
  306.             $row['Default'] = $row['Default'];
  307.         }
  308.  
  309.         $fmt_pre = '';
  310.         $fmt_post = '';
  311.         if (in_array($row['Field'], $unique_keys)) {
  312.             $fmt_pre = '<b>' . $fmt_pre;
  313.             $fmt_post = $fmt_post . '</b>';
  314.         }
  315.         if ($row['Key']=='PRI') {
  316.             $fmt_pre = '<i>' . $fmt_pre;
  317.             $fmt_post = $fmt_post . '</i>';
  318.         }
  319.         $schema_insert .= '<td class="print">' . $fmt_pre . htmlspecialchars($row['Field']) . $fmt_post . '</td>';
  320.         $schema_insert .= '<td class="print">' . htmlspecialchars($type) . '</td>';
  321.         $schema_insert .= '<td class="print">' . htmlspecialchars($row['Null'] == '' ? $GLOBALS['strNo'] : $GLOBALS['strYes']) . '</td>';
  322.         $schema_insert .= '<td class="print">' . htmlspecialchars(isset($row['Default']) ? $row['Default'] : '') . '</td>';
  323.  
  324.         $field_name = $row['Field'];
  325.  
  326.         if ($do_relation && $have_rel) {
  327.             $schema_insert .= '<td class="print">' . (isset($res_rel[$field_name]) ? htmlspecialchars($res_rel[$field_name]['foreign_table'] . ' (' . $res_rel[$field_name]['foreign_field'] . ')') : '') . '</td>';
  328.         }
  329.         if ($do_comments && $cfgRelation['commwork']) {
  330.             $schema_insert .= '<td class="print">' . (isset($comments[$field_name]) ? htmlspecialchars($comments[$field_name]) : '') . '</td>';
  331.         }
  332.         if ($do_mime && $cfgRelation['mimework']) {
  333.             $schema_insert .= '<td class="print">' . (isset($mime_map[$field_name]) ? htmlspecialchars(str_replace('_', '/', $mime_map[$field_name]['mimetype'])) : '') . '</td>';
  334.         }
  335.  
  336.         $schema_insert .= '</tr>';
  337.  
  338.         if (!PMA_exportOutputHandler($schema_insert)) {
  339.             return FALSE;
  340.         }
  341.     } // end while
  342.     PMA_DBI_free_result($result);
  343.  
  344.     return PMA_exportOutputHandler('</table>');
  345. }
  346.  
  347. }
  348. ?>
  349.