home *** CD-ROM | disk | FTP | other *** search
/ PC World 2003 March / PCWorld_2003-03_cd.bin / Software / Vyzkuste / phptriad / phptriad2-2-1.exe / htdocs / phpmyadmin / tbl_printview.php < prev    next >
Encoding:
PHP Script  |  2002-01-06  |  18.8 KB  |  507 lines

  1. <?php
  2. /* $Id: tbl_printview.php,v 1.30 2001/12/07 15:48:27 loic1 Exp $ */
  3.  
  4.  
  5. /**
  6.  * Gets the variables sent or posted to this script, then displays headers
  7.  */
  8. if (!isset($selected_tbl)) {
  9.     include('./libraries/grab_globals.lib.php');
  10.     include('./header.inc.php');
  11. }
  12.  
  13.  
  14. /**
  15.  * Defines the url to return to in case of error in a sql statement
  16.  */
  17. if (isset($table)) {
  18.     $err_url = 'tbl_properties.php'
  19.              . '?lang=' . $lang
  20.              . '&server=' . $server
  21.              . '&db=' . urlencode($db)
  22.              . '&table=' . urlencode($table);
  23. } else {
  24.     $err_url = 'db_details.php'
  25.              . '?lang=' . $lang
  26.              . '&server=' . $server
  27.              . '&db=' . urlencode($db);
  28. }
  29.  
  30.  
  31. /**
  32.  * Selects the database
  33.  */
  34. mysql_select_db($db);
  35.  
  36.  
  37. /**
  38.  * Multi-tables printview thanks to Christophe GeschΘ from the "MySQL Form
  39.  * Generator for PHPMyAdmin" (http://sourceforge.net/projects/phpmysqlformgen/)
  40.  */
  41. if (isset($selected_tbl) && is_array($selected_tbl)) {
  42.     $the_tables   = $selected_tbl;
  43. } else if (isset($table)) {
  44.     $the_tables[] = $table; 
  45. }
  46. $multi_tables     = (count($the_tables) > 1);
  47.  
  48. if ($multi_tables) {
  49.     $tbl_list     = '';
  50.     while (list($key, $table) = each($the_tables)) {
  51.         $tbl_list .= (empty($tbl_list) ? '' : ', ')
  52.                   . PMA_backquote($table);
  53.     }
  54.     echo '<b>'.  $strShowTables . ' : ' . $tbl_list . '</b>' . "\n";
  55. } // end if
  56. reset($the_tables);
  57.  
  58. while (list($key, $table) = each($the_tables)) {
  59.     if ($multi_tables) {
  60.         echo '<div style="page-break-after: always;">' . "\n";
  61.         echo '<h1>' . $table . '</h1>' . "\n";
  62.     } // end if
  63.  
  64.     /**
  65.      * Gets table informations
  66.      */
  67.     // The 'show table' statement works correct since 3.23.03
  68.     if (PMA_MYSQL_INT_VERSION >= 32303) {
  69.         $local_query  = 'SHOW TABLE STATUS LIKE \'' . PMA_sqlAddslashes($table, TRUE) . '\'';
  70.         $result       = mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url);
  71.         $showtable    = mysql_fetch_array($result);
  72.         $num_rows     = (isset($showtable['Rows']) ? $showtable['Rows'] : 0);
  73.         $show_comment = (isset($showtable['Comment']) ? $showtable['Comment'] : '');
  74.     } else {
  75.         $local_query  = 'SELECT COUNT(*) AS count FROM ' . PMA_backquote($table);
  76.         $result       = mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url);
  77.         $showtable    = array();
  78.         $num_rows     = mysql_result($result, 0, 'count');
  79.         $show_comment = '';
  80.     } // end display comments
  81.     if ($result) {
  82.         mysql_free_result($result);
  83.     }
  84.  
  85.  
  86.     /**
  87.      * Gets table keys and retains them
  88.      */
  89.     $local_query  = 'SHOW KEYS FROM ' . PMA_backquote($table);
  90.     $result       = mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url);
  91.     $primary      = '';
  92.     $indexes      = array();
  93.     $lastIndex    = '';
  94.     $indexes_info = array();
  95.     $indexes_data = array();
  96.     $pk_array     = array(); // will be use to emphasis prim. keys in the table
  97.                              // view
  98.     while ($row = mysql_fetch_array($result)) {
  99.         // Backups the list of primary keys
  100.         if ($row['Key_name'] == 'PRIMARY') {
  101.             $primary .= $row['Column_name'] . ', ';
  102.             $pk_array[$row['Column_name']] = 1;
  103.         }
  104.         // Retains keys informations
  105.         if ($row['Key_name'] != $lastIndex ){
  106.             $indexes[] = $row['Key_name'];
  107.             $lastIndex = $row['Key_name'];
  108.         }
  109.         $indexes_info[$row['Key_name']]['Sequences'][]     = $row['Seq_in_index'];
  110.         $indexes_info[$row['Key_name']]['Non_unique']      = $row['Non_unique'];
  111.         if (isset($row['Cardinality'])) {
  112.             $indexes_info[$row['Key_name']]['Cardinality'] = $row['Cardinality'];
  113.         }
  114. //      I don't know what does following column mean....
  115. //      $indexes_info[$row['Key_name']]['Packed']          = $row['Packed'];
  116.         $indexes_info[$row['Key_name']]['Comment']         = $row['Comment'];
  117.  
  118.         $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Column_name']  = $row['Column_name'];
  119.         if (isset($row['Sub_part'])) {
  120.             $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Sub_part'] = $row['Sub_part'];
  121.         }
  122.  
  123.     } // end while
  124.     if ($result) {
  125.         mysql_free_result($result);
  126.     }
  127.  
  128.     /**
  129.      * Gets fields properties
  130.      */
  131.     $local_query = 'SHOW FIELDS FROM ' . PMA_backquote($table);
  132.     $result      = mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url);
  133.     $fields_cnt  = mysql_num_rows($result);
  134.  
  135.  
  136.  
  137.     /**
  138.      * Displays the comments of the table is MySQL >= 3.23
  139.      */
  140.     if (!empty($show_comment)) {
  141.         echo $strTableComments . ' : ' . $row['Comment'];
  142.     }
  143.  
  144.  
  145.     /**
  146.      * Displays the table structure
  147.      */
  148.     ?>
  149.  
  150. <!-- TABLE INFORMATIONS -->
  151. <table border="<?php echo $cfgBorder; ?>">
  152. <tr>
  153.     <th><?php echo ucfirst($strField); ?></th>
  154.     <th><?php echo ucfirst($strType); ?></th>
  155.     <th><?php echo ucfirst($strAttr); ?></th>
  156.     <th><?php echo ucfirst($strNull); ?></th>
  157.     <th><?php echo ucfirst($strDefault); ?></th>
  158.     <th><?php echo ucfirst($strExtra); ?></th>
  159. </tr>
  160.  
  161.     <?php
  162.     $i = 0;
  163.     while ($row = mysql_fetch_array($result)) {
  164.         $bgcolor = ($i % 2) ?$cfgBgcolorOne : $cfgBgcolorTwo;
  165.         $i++;
  166.  
  167.         $type             = $row['Type'];
  168.         // reformat mysql query output - staybyte - 9. June 2001
  169.         // loic1: set or enum types: slashes single quotes inside options
  170.         if (eregi('^(set|enum)\((.+)\)$', $type, $tmp)) {
  171.             $tmp[2]       = substr(ereg_replace('([^,])\'\'', '\\1\\\'', ',' . $tmp[2]), 1);
  172.             $type         = $tmp[1] . '(' . str_replace(',', ', ', $tmp[2]) . ')';
  173.             $type_nowrap  = '';
  174.         } else {
  175.             $type_nowrap  = ' nowrap="nowrap"';
  176.         }
  177.         $type             = eregi_replace('BINARY', '', $type);
  178.         $type             = eregi_replace('ZEROFILL', '', $type);
  179.         $type             = eregi_replace('UNSIGNED', '', $type);
  180.         if (empty($type)) {
  181.             $type         = ' ';
  182.         }
  183.  
  184.         $binary           = eregi('BINARY', $row['Type'], $test);
  185.         $unsigned         = eregi('UNSIGNED', $row['Type'], $test);
  186.         $zerofill         = eregi('ZEROFILL', $row['Type'], $test);
  187.         $strAttribute     = ' ';
  188.         if ($binary) {
  189.             $strAttribute = 'BINARY';
  190.         }
  191.         if ($unsigned) {
  192.             $strAttribute = 'UNSIGNED';
  193.         }
  194.         if ($zerofill) {
  195.             $strAttribute = 'UNSIGNED ZEROFILL';
  196.         }
  197.         if (!isset($row['Default'])) {
  198.             if ($row['Null'] != '') {
  199.                 $row['Default'] = '<i>NULL</i>';
  200.             }
  201.         } else {
  202.             $row['Default'] = htmlspecialchars($row['Default']);
  203.         }
  204.         $field_name = htmlspecialchars($row['Field']);
  205.         if (isset($pk_array[$row['Field']])) {
  206.             $field_name = '<u>' . $field_name . '</u>';
  207.         }
  208.         echo "\n";
  209.         ?>
  210. <tr>
  211.     <td bgcolor="<?php echo $bgcolor; ?>" nowrap="nowrap"><?php echo $field_name; ?> </td>
  212.     <td bgcolor="<?php echo $bgcolor; ?>"<?php echo $type_nowrap; ?>><?php echo $type; ?><bdo dir="ltr"></bdo></td>
  213.     <td bgcolor="<?php echo $bgcolor; ?>" nowrap="nowrap"><?php echo $strAttribute; ?></td>
  214.     <td bgcolor="<?php echo $bgcolor; ?>"><?php echo (($row['Null'] == '') ? $strNo : $strYes); ?> </td>
  215.     <td bgcolor="<?php echo $bgcolor; ?>" nowrap="nowrap"><?php if (isset($row['Default'])) echo $row['Default']; ?> </td>
  216.     <td bgcolor="<?php echo $bgcolor; ?>" nowrap="nowrap"><?php echo $row['Extra']; ?> </td>
  217. </tr>
  218.         <?php
  219.     } // end while
  220.     mysql_free_result($result);
  221.  
  222.     echo "\n";
  223.     ?>
  224. </table>
  225.  
  226.  
  227.     <?php
  228.     /**
  229.      * Displays indexes
  230.      */
  231.     $index_count = (isset($indexes))
  232.                  ? count($indexes)
  233.                  : 0;
  234.     if ($index_count > 0) {
  235.         echo "\n";
  236.         ?>
  237. <br /><br />
  238.  
  239. <!-- Indexes -->
  240.  <big><?php echo $strIndexes . ' :'; ?></big>
  241. <table border="<?php echo $cfgBorder; ?>">
  242.     <tr>
  243.         <th><?php echo $strKeyname; ?></th>
  244.         <th><?php echo $strType; ?></th>
  245.         <th><?php echo $strCardinality; ?></th>
  246.         <th colspan="2"><?php echo $strField; ?></th>
  247.     </tr>
  248.         <?php
  249.         echo "\n";
  250.         while (list($index_no, $index_name) = each($indexes)) {
  251.             $cell_bgd = (($index_no % 2) ? $cfgBgcolorOne : $cfgBgcolorTwo);
  252.             $index_td = '            <td bgcolor="' . $cell_bgd . '" rowspan="' . count($indexes_info[$index_name]['Sequences']) . '">' . "\n";
  253.             echo '        <tr>' . "\n";
  254.             echo $index_td
  255.                  . '                ' . htmlspecialchars($index_name) . "\n"
  256.                  . '            </td>' . "\n";
  257.  
  258.             if ($indexes_info[$index_name]['Comment'] == 'FULLTEXT') {
  259.                 $index_type = 'FULLTEXT';
  260.             } else if ($index_name == 'PRIMARY') {
  261.                 $index_type = 'PRIMARY';
  262.             } else if ($indexes_info[$index_name]['Non_unique'] == '0') {
  263.                 $index_type = 'UNIQUE';
  264.             } else {
  265.                 $index_type = 'INDEX';
  266.             }
  267.             echo $index_td
  268.                  . '                ' . $index_type . "\n"
  269.                  . '            </td>' . "\n";
  270.  
  271.             echo $index_td
  272.                  . '                ' . (isset($indexes_info[$index_name]['Cardinality']) ? $indexes_info[$index_name]['Cardinality'] : $strNone) . "\n"
  273.                  . '            </td>' . "\n";
  274.  
  275.             while (list($row_no, $seq_index) = each($indexes_info[$index_name]['Sequences'])) {
  276.                 if ($row_no > 0) {
  277.                     echo '        <tr>' . "\n";
  278.                 }
  279.                 if (!empty($indexes_data[$index_name][$seq_index]['Sub_part'])) {
  280.                     echo '            <td bgcolor="' . $cell_bgd . '">' . "\n"
  281.                          . '                ' . $indexes_data[$index_name][$seq_index]['Column_name'] . "\n"
  282.                          . '            </td>' . "\n";
  283.                     echo '            <td align="right" bgcolor="' . $cell_bgd . '">' . "\n"
  284.                          . '                ' . $indexes_data[$index_name][$seq_index]['Sub_part'] . "\n"
  285.                          . '            </td>' . "\n";
  286.                     echo '        </tr>' . "\n";
  287.                 } else {
  288.                     echo '            <td bgcolor="' . $cell_bgd . '" colspan="2">' . "\n"
  289.                          . '                ' . $indexes_data[$index_name][$seq_index]['Column_name'] . "\n"
  290.                          . '            </td>' . "\n";
  291.                     echo '        </tr>' . "\n";
  292.                 }
  293.             } // end while
  294.         } // end while
  295.         echo "\n";
  296.         ?>
  297. </table>
  298.         <?php
  299.         echo "\n";
  300.     } // end display indexes
  301.  
  302.  
  303.     /**
  304.      * Displays Space usage and row statistics
  305.      *
  306.      * staybyte - 9 June 2001
  307.      */
  308.     if ($cfgShowStats) {
  309.         $nonisam     = FALSE;
  310.         if (isset($showtable['Type']) && !eregi('ISAM|HEAP', $showtable['Type'])) {
  311.             $nonisam = TRUE;
  312.         }
  313.         if (PMA_MYSQL_INT_VERSION >= 32303 && $nonisam == FALSE) {
  314.             // Gets some sizes
  315.             $mergetable     = FALSE;
  316.             if (isset($showtable['Type']) && $showtable['Type'] == 'MRG_MyISAM') {
  317.                 $mergetable = TRUE;
  318.             }
  319.             list($data_size, $data_unit)         = PMA_formatByteDown($showtable['Data_length']);
  320.             if ($mergetable == FALSE) {
  321.                 list($index_size, $index_unit)   = PMA_formatByteDown($showtable['Index_length']);
  322.             }
  323.             if (isset($showtable['Data_free']) && $showtable['Data_free'] > 0) {
  324.                 list($free_size, $free_unit)     = PMA_formatByteDown($showtable['Data_free']);
  325.                 list($effect_size, $effect_unit) = PMA_formatByteDown($showtable['Data_length'] + $showtable['Index_length'] - $showtable['Data_free']);
  326.             } else {
  327.                 list($effect_size, $effect_unit) = PMA_formatByteDown($showtable['Data_length'] + $showtable['Index_length']);
  328.             }
  329.             list($tot_size, $tot_unit)           = PMA_formatByteDown($showtable['Data_length'] + $showtable['Index_length']);
  330.             if ($num_rows > 0) {
  331.                 list($avg_size, $avg_unit)       = PMA_formatByteDown(($showtable['Data_length'] + $showtable['Index_length']) / $showtable['Rows'], 6, 1);
  332.             }
  333.  
  334.             // Displays them
  335.             ?>
  336. <br /><br />
  337.  
  338. <table border="0" cellspacing="0" cellpadding="0">
  339. <tr>
  340.  
  341.     <!-- Space usage -->
  342.     <td valign="top">
  343.          <big><?php echo $strSpaceUsage . ' :'; ?></big>
  344.         <table border="<?php echo $cfgBorder; ?>">
  345.         <tr>
  346.             <th><?php echo $strType; ?></th>
  347.             <th colspan="2" align="center"><?php echo $strUsage; ?></th>
  348.         </tr>
  349.         <tr>
  350.             <td bgcolor="<?php echo $cfgBgcolorTwo; ?>" style="padding-right: 10px"><?php echo ucfirst($strData); ?></td>
  351.             <td align="right" bgcolor="<?php echo $cfgBgcolorTwo; ?>" nowrap="nowrap"><?php echo $data_size; ?></td>
  352.             <td bgcolor="<?php echo $cfgBgcolorTwo; ?>"><?php echo $data_unit; ?></td>
  353.         </tr>
  354.             <?php
  355.             if (isset($index_size)) {
  356.                 echo "\n";
  357.                 ?>
  358.             <tr>
  359.                 <td bgcolor="<?php echo $cfgBgcolorTwo; ?>" style="padding-right: 10px"><?php echo ucfirst($strIndex); ?></td>
  360.                 <td align="right" bgcolor="<?php echo $cfgBgcolorTwo; ?>" nowrap="nowrap"><?php echo $index_size; ?></td>
  361.                 <td bgcolor="<?php echo $cfgBgcolorTwo; ?>"><?php echo $index_unit; ?></td>
  362.             </tr>
  363.                 <?php
  364.             }
  365.             if (isset($free_size)) {
  366.                 echo "\n";
  367.                 ?>
  368.         <tr style="color: #bb0000">
  369.             <td bgcolor="<?php echo $cfgBgcolorTwo; ?>" style="padding-right: 10px"><?php echo ucfirst($strOverhead); ?></td>
  370.             <td align="right" bgcolor="<?php echo $cfgBgcolorTwo; ?>" nowrap="nowrap"><?php echo $free_size; ?></td>
  371.             <td bgcolor="<?php echo $cfgBgcolorTwo; ?>"><?php echo $free_unit; ?></td>
  372.         </tr>
  373.         <tr>
  374.             <td bgcolor="<?php echo $cfgBgcolorOne; ?>" style="padding-right: 10px"><?php echo ucfirst($strEffective); ?></td>
  375.             <td align="right" bgcolor="<?php echo $cfgBgcolorOne; ?>" nowrap="nowrap"><?php echo $effect_size; ?></td>
  376.             <td bgcolor="<?php echo $cfgBgcolorOne; ?>"><?php echo $effect_unit; ?></td>
  377.         </tr>
  378.                 <?php
  379.             }
  380.             if (isset($tot_size) && $mergetable == FALSE) {
  381.                 echo "\n";
  382.                 ?>
  383.         <tr>
  384.             <td bgcolor="<?php echo $cfgBgcolorOne; ?>" style="padding-right: 10px"><?php echo ucfirst($strTotal); ?></td>
  385.             <td align="right" bgcolor="<?php echo $cfgBgcolorOne; ?>" nowrap="nowrap"><?php echo $tot_size; ?></td>
  386.             <td bgcolor="<?php echo $cfgBgcolorOne; ?>"><?php echo $tot_unit; ?></td>
  387.         </tr>
  388.                 <?php
  389.             }
  390.             echo "\n";
  391.             ?>
  392.         </table>
  393.     </td>
  394.  
  395.     <td width="20"> </td>
  396.  
  397.     <!-- Rows Statistic -->
  398.     <td valign="top">
  399.          <big><?php echo $strRowsStatistic . ' :'; ?></big>
  400.         <table border="<?php echo $cfgBorder; ?>">
  401.         <tr>
  402.             <th><?php echo $strStatement; ?></th>
  403.             <th align="center"><?php echo $strValue; ?></th>
  404.         </tr>
  405.             <?php
  406.             $i = 0;
  407.             if (isset($showtable['Row_format'])) {
  408.                 $bgcolor = ((++$i%2) ? $cfgBgcolorTwo : $cfgBgcolorOne);
  409.                 echo "\n";
  410.                 ?>
  411.         <tr>
  412.             <td bgcolor="<?php echo $bgcolor; ?>"><?php echo ucfirst($strFormat); ?></td>
  413.             <td align="<?php echo $cell_align_left; ?>" bgcolor="<?php echo $bgcolor; ?>" nowrap="nowrap">
  414.                 <?php
  415.                 echo '                ';
  416.                 if ($showtable['Row_format'] == 'Fixed') {
  417.                     echo $strFixed;
  418.                 } else if ($showtable['Row_format'] == 'Dynamic') {
  419.                     echo $strDynamic;
  420.                 } else {
  421.                     echo $showtable['Row_format'];
  422.                 }
  423.                 echo "\n";
  424.                 ?>
  425.             </td>
  426.         </tr>
  427.                 <?php
  428.             }
  429.             if (isset($showtable['Rows'])) {
  430.                 $bgcolor = ((++$i%2) ? $cfgBgcolorTwo : $cfgBgcolorOne);
  431.                 echo "\n";
  432.             ?>
  433.         <tr>
  434.             <td bgcolor="<?php echo $bgcolor; ?>"><?php echo ucfirst($strRows); ?></td>
  435.             <td align="right" bgcolor="<?php echo $bgcolor; ?>" nowrap="nowrap">
  436.                 <?php echo number_format($showtable['Rows'], 0, $number_decimal_separator, $number_thousands_separator) . "\n"; ?>
  437.             </td>
  438.         </tr>
  439.                 <?php
  440.             }
  441.             if (isset($showtable['Avg_row_length']) && $showtable['Avg_row_length'] > 0) {
  442.                 $bgcolor = ((++$i%2) ? $cfgBgcolorTwo : $cfgBgcolorOne);
  443.                 echo "\n";
  444.                 ?>
  445.         <tr>
  446.             <td bgcolor="<?php echo $bgcolor; ?>"><?php echo ucfirst($strRowLength); ?> ø</td>
  447.             <td align="right" bgcolor="<?php echo $bgcolor; ?>" nowrap="nowrap">
  448.                 <?php echo number_format($showtable['Avg_row_length'], 0, $number_decimal_separator, $number_thousands_separator) . "\n"; ?>
  449.             </td>
  450.         </tr>
  451.                 <?php
  452.             }
  453.             if (isset($showtable['Data_length']) && $showtable['Rows'] > 0 && $mergetable == FALSE) {
  454.                 $bgcolor = ((++$i%2) ? $cfgBgcolorTwo : $cfgBgcolorOne);
  455.                 echo "\n";
  456.                 ?>
  457.         <tr>
  458.             <td bgcolor="<?php echo $bgcolor; ?>"><?php echo ucfirst($strRowSize); ?> ø</td>
  459.             <td align="right" bgcolor="<?php echo $bgcolor; ?>" nowrap="nowrap">
  460.                 <?php echo $avg_size . ' ' . $avg_unit . "\n"; ?>
  461.             </td>
  462.         </tr>
  463.                 <?php
  464.             }
  465.             if (isset($showtable['Auto_increment'])) {
  466.                 $bgcolor = ((++$i%2) ? $cfgBgcolorTwo : $cfgBgcolorOne);
  467.                 echo "\n";
  468.                 ?>
  469.         <tr>
  470.             <td bgcolor="<?php echo $bgcolor; ?>"><?php echo ucfirst($strNext); ?> Autoindex</td>
  471.             <td align="right" bgcolor="<?php echo $bgcolor; ?>" nowrap="nowrap">
  472.                 <?php echo number_format($showtable['Auto_increment'], 0, $number_decimal_separator, $number_thousands_separator) . "\n"; ?>
  473.             </td>
  474.         </tr>
  475.                 <?php
  476.             }
  477.             echo "\n";
  478.             ?>
  479.         </table>
  480.     </td>
  481. </tr>
  482. </table>
  483.  
  484.             <?php
  485.         } // end if (PMA_MYSQL_INT_VERSION >= 32303 && $nonisam == FALSE)
  486.     } // end if ($cfgShowStats)
  487.  
  488.     echo "\n";
  489.     if ($multi_tables) {
  490.         unset($ret_keys);
  491.         unset($num_rows);
  492.         unset($show_comment);
  493.         echo '</div>' . "\n";
  494.         echo '<hr />' . "\n";
  495.     } // end if
  496.  
  497. } // end while
  498.  
  499.  
  500.  
  501. /**
  502.  * Displays the footer
  503.  */
  504. echo "\n";
  505. require('./footer.inc.php');
  506. ?>
  507.