home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / Servidores / xampp-win32-1.6.7-installer.exe / phpMyAdmin / tbl_printview.php < prev    next >
PHP Script  |  2008-06-23  |  18KB  |  561 lines

  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4.  *
  5.  * @version $Id: tbl_printview.php 11228 2008-05-03 11:59:52Z lem9 $
  6.  */
  7.  
  8. /**
  9.  *
  10.  */
  11. require_once './libraries/common.inc.php';
  12.  
  13. require './libraries/tbl_common.php';
  14.  
  15. /**
  16.  * Gets the variables sent or posted to this script, then displays headers
  17.  */
  18. $print_view = true;
  19. if (! isset($selected_tbl)) {
  20.     require_once './libraries/header.inc.php';
  21. }
  22.  
  23. // Check parameters
  24.  
  25. if (! isset($the_tables) || ! is_array($the_tables)) {
  26.     $the_tables = array();
  27. }
  28.  
  29. /**
  30.  * Gets the relations settings
  31.  */
  32. require_once './libraries/relation.lib.php';
  33. require_once './libraries/transformations.lib.php';
  34. require_once './libraries/tbl_indexes.lib.php';
  35.  
  36. $cfgRelation = PMA_getRelationsParam();
  37.  
  38. /**
  39.  * Defines the url to return to in case of error in a sql statement
  40.  */
  41. if (strlen($table)) {
  42.     $err_url = 'tbl_sql.php?' . PMA_generate_common_url($db, $table);
  43. } else {
  44.     $err_url = 'db_sql.php?' . PMA_generate_common_url($db);
  45. }
  46.  
  47.  
  48. /**
  49.  * Selects the database
  50.  */
  51. PMA_DBI_select_db($db);
  52.  
  53.  
  54. /**
  55.  * Multi-tables printview thanks to Christophe Gesche from the "MySQL Form
  56.  * Generator for PHPMyAdmin" (http://sourceforge.net/projects/phpmysqlformgen/)
  57.  */
  58. if (isset($selected_tbl) && is_array($selected_tbl)) {
  59.     $the_tables   = $selected_tbl;
  60. } elseif (strlen($table)) {
  61.     $the_tables[] = $table;
  62. }
  63. $multi_tables     = (count($the_tables) > 1);
  64.  
  65. if ($multi_tables) {
  66.     if (empty($GLOBALS['is_header_sent'])) {
  67.         require_once './libraries/header.inc.php';
  68.     }
  69.     $tbl_list     = '';
  70.     foreach ($the_tables as $key => $table) {
  71.         $tbl_list .= (empty($tbl_list) ? '' : ', ')
  72.                   . PMA_backquote(urldecode($table));
  73.     }
  74.     echo '<b>'.  $strShowTables . ': ' . $tbl_list . '</b>' . "\n";
  75.     echo '<hr />' . "\n";
  76. } // end if
  77.  
  78. $tables_cnt = count($the_tables);
  79. $counter    = 0;
  80.  
  81. foreach ($the_tables as $key => $table) {
  82.     $table = urldecode($table);
  83.     if ($counter + 1 >= $tables_cnt) {
  84.         $breakstyle = '';
  85.     } else {
  86.         $breakstyle = ' style="page-break-after: always;"';
  87.     }
  88.     $counter++;
  89.     echo '<div' . $breakstyle . '>' . "\n";
  90.     echo '<h1>' . $table . '</h1>' . "\n";
  91.  
  92.     /**
  93.      * Gets table informations
  94.      */
  95.     $result       = PMA_DBI_query(
  96.         'SHOW TABLE STATUS LIKE \'' . PMA_sqlAddslashes($table, true) . '\';');
  97.     $showtable    = PMA_DBI_fetch_assoc($result);
  98.     $num_rows     = (isset($showtable['Rows']) ? $showtable['Rows'] : 0);
  99.     $show_comment = (isset($showtable['Comment']) ? $showtable['Comment'] : '');
  100.     PMA_DBI_free_result($result);
  101.  
  102.     $tbl_is_view = PMA_Table::isView($db, $table);
  103.  
  104.     //  Gets table keys and store them in arrays
  105.     $indexes      = array();
  106.     $indexes_info = array();
  107.     $indexes_data = array();
  108.     $ret_keys = PMA_get_indexes($table, $err_url_0);
  109.  
  110.     PMA_extract_indexes($ret_keys, $indexes, $indexes_info, $indexes_data);
  111.  
  112.     /**
  113.      * Gets fields properties
  114.      */
  115.     $result      = PMA_DBI_query(
  116.         'SHOW FIELDS FROM ' . PMA_backquote($table) . ';', null,
  117.         PMA_DBI_QUERY_STORE);
  118.     $fields_cnt  = PMA_DBI_num_rows($result);
  119.  
  120.  
  121. // We need this to correctly learn if a TIMESTAMP is NOT NULL, since
  122. // SHOW FULL FIELDS or INFORMATION_SCHEMA incorrectly says NULL
  123. // and SHOW CREATE TABLE says NOT NULL (tested
  124. // in MySQL 4.0.25 and 5.0.21, http://bugs.mysql.com/20910).
  125.  
  126.     $show_create_table = PMA_DBI_fetch_value(
  127.         'SHOW CREATE TABLE ' . PMA_backquote($db) . '.' . PMA_backquote($table),
  128.         0, 1);
  129.     $analyzed_sql = PMA_SQP_analyze(PMA_SQP_parse($show_create_table));
  130.  
  131.     // Check if we can use Relations (Mike Beck)
  132.     if (!empty($cfgRelation['relation'])) {
  133.         // Find which tables are related with the current one and write it in
  134.         // an array
  135.         $res_rel = PMA_getForeigners($db, $table);
  136.  
  137.         if (count($res_rel) > 0) {
  138.             $have_rel = true;
  139.         } else {
  140.             $have_rel = false;
  141.         }
  142.     } else {
  143.            $have_rel = false;
  144.     } // end if
  145.  
  146.  
  147.     /**
  148.      * Displays the comments of the table if MySQL >= 3.23
  149.      */
  150.     if (!empty($show_comment)) {
  151.         echo $strTableComments . ': ' . htmlspecialchars($show_comment) . '<br /><br />';
  152.     }
  153.  
  154.     /**
  155.      * Displays the table structure
  156.      */
  157.     ?>
  158.  
  159. <!-- TABLE INFORMATIONS -->
  160. <table style="width: 100%;">
  161. <thead>
  162. <tr>
  163.     <th><?php echo $strField; ?></th>
  164.     <th><?php echo $strType; ?></th>
  165.     <!--<th><?php echo $strAttr; ?></th>-->
  166.     <th><?php echo $strNull; ?></th>
  167.     <th><?php echo $strDefault; ?></th>
  168.     <!--<th><?php echo $strExtra; ?></th>-->
  169.     <?php
  170.     if ($have_rel) {
  171.         echo '<th>' . $strLinksTo . '</th>' . "\n";
  172.     }
  173.     if ($cfgRelation['commwork'] || PMA_MYSQL_INT_VERSION >= 40100) {
  174.         echo '    <th>' . $strComments . '</th>' . "\n";
  175.     }
  176.     if ($cfgRelation['mimework']) {
  177.         echo '    <th>MIME</th>' . "\n";
  178.     }
  179.     ?>
  180. </tr>
  181. </thead>
  182. <tbody>
  183.     <?php
  184.     while ($row = PMA_DBI_fetch_assoc($result)) {
  185.         $type             = $row['Type'];
  186.         // reformat mysql query output - staybyte - 9. June 2001
  187.         // loic1: set or enum types: slashes single quotes inside options
  188.         if (preg_match('@^(set|enum)\((.+)\)$@i', $type, $tmp)) {
  189.             $tmp[2]       = substr(preg_replace('@([^,])\'\'@', '\\1\\\'',
  190.                                     ',' . $tmp[2]), 1);
  191.             $type         = $tmp[1] . '(' . str_replace(',', ', ', $tmp[2]) . ')';
  192.  
  193.             $binary       = 0;
  194.             $unsigned     = 0;
  195.             $zerofill     = 0;
  196.         } else {
  197.             $type         = preg_replace('@BINARY@i', '', $type);
  198.             $type         = preg_replace('@ZEROFILL@i', '', $type);
  199.             $type         = preg_replace('@UNSIGNED@i', '', $type);
  200.             if (empty($type)) {
  201.                 $type     = ' ';
  202.             }
  203.  
  204.             $binary       = stristr($row['Type'], 'binary');
  205.             $unsigned     = stristr($row['Type'], 'unsigned');
  206.             $zerofill     = stristr($row['Type'], 'zerofill');
  207.         }
  208.         $strAttribute     = ' ';
  209.         if ($binary) {
  210.             $strAttribute = 'BINARY';
  211.         }
  212.         if ($unsigned) {
  213.             $strAttribute = 'UNSIGNED';
  214.         }
  215.         if ($zerofill) {
  216.             $strAttribute = 'UNSIGNED ZEROFILL';
  217.         }
  218.         if (!isset($row['Default'])) {
  219.             if ($row['Null'] != ''  && $row['Null'] != 'NO') {
  220.                 $row['Default'] = '<i>NULL</i>';
  221.             }
  222.         } else {
  223.             $row['Default'] = htmlspecialchars($row['Default']);
  224.         }
  225.         $field_name = htmlspecialchars($row['Field']);
  226.  
  227.         // here, we have a TIMESTAMP that SHOW FULL FIELDS reports as having the
  228.         // NULL attribute, but SHOW CREATE TABLE says the contrary. Believe
  229.         // the latter.
  230.         /**
  231.          * @todo merge this logic with the one in tbl_structure.php
  232.          * or move it in a function similar to PMA_DBI_get_columns_full()
  233.          * but based on SHOW CREATE TABLE because information_schema
  234.          * cannot be trusted in this case (MySQL bug)
  235.          */
  236.         if (!empty($analyzed_sql[0]['create_table_fields'][$field_name]['type']) && $analyzed_sql[0]['create_table_fields'][$field_name]['type'] == 'TIMESTAMP' && $analyzed_sql[0]['create_table_fields'][$field_name]['timestamp_not_null']) {
  237.             $row['Null'] = '';
  238.         }
  239.         ?>
  240.  
  241. <tr><td>
  242.     <?php
  243.     if (isset($pk_array[$row['Field']])) {
  244.         echo '    <u>' . $field_name . '</u>' . "\n";
  245.     } else {
  246.         echo '    ' . $field_name . "\n";
  247.     }
  248.     ?>
  249.     </td>
  250.     <td><?php echo $type; ?><bdo dir="ltr"></bdo></td>
  251.     <!--<td><?php echo $strAttribute; ?></td>-->
  252.     <td><?php echo (($row['Null'] == '' || $row['Null'] == 'NO') ? $strNo : $strYes); ?> </td>
  253.     <td><?php if (isset($row['Default'])) { echo $row['Default']; } ?> </td>
  254.     <!--<td><?php echo $row['Extra']; ?> </td>-->
  255.     <?php
  256.     if ($have_rel) {
  257.         echo '    <td>';
  258.         if (isset($res_rel[$field_name])) {
  259.             echo htmlspecialchars($res_rel[$field_name]['foreign_table'] . ' -> ' . $res_rel[$field_name]['foreign_field']);
  260.         }
  261.         echo ' </td>' . "\n";
  262.     }
  263.     if ($cfgRelation['commwork'] || PMA_MYSQL_INT_VERSION >= 40100) {
  264.         echo '    <td>';
  265.         $comments = PMA_getComments($db, $table);
  266.         if (isset($comments[$field_name])) {
  267.             echo htmlspecialchars($comments[$field_name]);
  268.         }
  269.         echo ' </td>' . "\n";
  270.     }
  271.     if ($cfgRelation['mimework']) {
  272.         $mime_map = PMA_getMIME($db, $table, true);
  273.  
  274.         echo '    <td>';
  275.         if (isset($mime_map[$field_name])) {
  276.             echo htmlspecialchars(str_replace('_', '/', $mime_map[$field_name]['mimetype']));
  277.         }
  278.         echo ' </td>' . "\n";
  279.     }
  280.     ?>
  281. </tr>
  282.         <?php
  283.     } // end while
  284.     PMA_DBI_free_result($result);
  285.     ?>
  286. </tbody>
  287. </table>
  288.  
  289.     <?php
  290.  
  291.     if (! $tbl_is_view
  292.      && ($db != 'information_schema' || PMA_MYSQL_INT_VERSION < 50002)) {
  293.  
  294.         /**
  295.          * Displays indexes
  296.          */
  297.         $index_count = (isset($indexes))
  298.                      ? count($indexes)
  299.                      : 0;
  300.         if ($index_count > 0) {
  301.             echo "\n";
  302.             ?>
  303.     <br /><br />
  304.  
  305.     <!-- Indexes -->
  306.     <big><?php echo $strIndexes . ':'; ?></big>
  307.     <table>
  308.         <tr>
  309.             <th><?php echo $strKeyname; ?></th>
  310.             <th><?php echo $strType; ?></th>
  311.             <th><?php echo $strCardinality; ?></th>
  312.             <th colspan="2"><?php echo $strField; ?></th>
  313.         </tr>
  314.             <?php
  315.             echo "\n";
  316.             PMA_show_indexes($table, $indexes, $indexes_info, $indexes_data, true, true);
  317.             echo "\n";
  318.             ?>
  319.     </table>
  320.             <?php
  321.             echo "\n";
  322.         } // end display indexes
  323.  
  324.  
  325.         /**
  326.          * Displays Space usage and row statistics
  327.          *
  328.          * staybyte - 9 June 2001
  329.          */
  330.         if ($cfg['ShowStats']) {
  331.             $nonisam     = false;
  332.             if (isset($showtable['Type']) && !preg_match('@ISAM|HEAP@i', $showtable['Type'])) {
  333.                 $nonisam = true;
  334.             }
  335.             if ($nonisam == false) {
  336.                 // Gets some sizes
  337.                 $mergetable     = false;
  338.                 if (isset($showtable['Type']) && $showtable['Type'] == 'MRG_MyISAM') {
  339.                     $mergetable = true;
  340.                 }
  341.                 list($data_size, $data_unit)         = PMA_formatByteDown($showtable['Data_length']);
  342.                 if ($mergetable == false) {
  343.                     list($index_size, $index_unit)   = PMA_formatByteDown($showtable['Index_length']);
  344.                 }
  345.                 if (isset($showtable['Data_free']) && $showtable['Data_free'] > 0) {
  346.                     list($free_size, $free_unit)     = PMA_formatByteDown($showtable['Data_free']);
  347.                     list($effect_size, $effect_unit) = PMA_formatByteDown($showtable['Data_length'] + $showtable['Index_length'] - $showtable['Data_free']);
  348.                 } else {
  349.                     unset($free_size);
  350.                     unset($free_unit);
  351.                     list($effect_size, $effect_unit) = PMA_formatByteDown($showtable['Data_length'] + $showtable['Index_length']);
  352.                 }
  353.                 list($tot_size, $tot_unit)           = PMA_formatByteDown($showtable['Data_length'] + $showtable['Index_length']);
  354.                 if ($num_rows > 0) {
  355.                     list($avg_size, $avg_unit)       = PMA_formatByteDown(($showtable['Data_length'] + $showtable['Index_length']) / $showtable['Rows'], 6, 1);
  356.                 }
  357.  
  358.                 // Displays them
  359.                 ?>
  360.     <br /><br />
  361.  
  362.     <table border="0" cellspacing="0" cellpadding="0" class="noborder">
  363.     <tr>
  364.  
  365.         <!-- Space usage -->
  366.         <td valign="top">
  367.             <big><?php echo $strSpaceUsage . ':'; ?></big>
  368.             <table width="100%">
  369.             <tr>
  370.                 <th><?php echo $strType; ?></th>
  371.                 <th colspan="2" align="center"><?php echo $strUsage; ?></th>
  372.             </tr>
  373.             <tr>
  374.                 <td style="padding-right: 10px"><?php echo $strData; ?></td>
  375.                 <td align="right"><?php echo $data_size; ?></td>
  376.                 <td><?php echo $data_unit; ?></td>
  377.             </tr>
  378.                 <?php
  379.                 if (isset($index_size)) {
  380.                     echo "\n";
  381.                     ?>
  382.             <tr>
  383.                 <td style="padding-right: 10px"><?php echo $strIndex; ?></td>
  384.                 <td align="right"><?php echo $index_size; ?></td>
  385.                 <td><?php echo $index_unit; ?></td>
  386.             </tr>
  387.                     <?php
  388.                 }
  389.                 if (isset($free_size)) {
  390.                     echo "\n";
  391.                     ?>
  392.             <tr style="color: #bb0000">
  393.                 <td style="padding-right: 10px"><?php echo $strOverhead; ?></td>
  394.                 <td align="right"><?php echo $free_size; ?></td>
  395.                 <td><?php echo $free_unit; ?></td>
  396.             </tr>
  397.             <tr>
  398.                 <td style="padding-right: 10px"><?php echo $strEffective; ?></td>
  399.                 <td align="right"><?php echo $effect_size; ?></td>
  400.                 <td><?php echo $effect_unit; ?></td>
  401.             </tr>
  402.                     <?php
  403.                 }
  404.                 if (isset($tot_size) && $mergetable == false) {
  405.                     echo "\n";
  406.                     ?>
  407.             <tr>
  408.                 <td style="padding-right: 10px"><?php echo $strTotalUC; ?></td>
  409.                 <td align="right"><?php echo $tot_size; ?></td>
  410.                 <td><?php echo $tot_unit; ?></td>
  411.             </tr>
  412.                     <?php
  413.                 }
  414.                 echo "\n";
  415.                 ?>
  416.             </table>
  417.         </td>
  418.  
  419.         <td width="20"> </td>
  420.  
  421.         <!-- Rows Statistic -->
  422.         <td valign="top">
  423.             <big><?php echo $strRowsStatistic . ':'; ?></big>
  424.             <table width="100%">
  425.             <tr>
  426.                 <th><?php echo $strStatement; ?></th>
  427.                 <th align="center"><?php echo $strValue; ?></th>
  428.             </tr>
  429.                 <?php
  430.                 if (isset($showtable['Row_format'])) {
  431.                     ?>
  432.             <tr>
  433.                 <td><?php echo ucfirst($strFormat); ?></td>
  434.                 <td align="<?php echo $cell_align_left; ?>">
  435.                     <?php
  436.                     if ($showtable['Row_format'] == 'Fixed') {
  437.                         echo $strFixed;
  438.                     } elseif ($showtable['Row_format'] == 'Dynamic') {
  439.                         echo $strDynamic;
  440.                     } else {
  441.                         echo $showtable['Row_format'];
  442.                     }
  443.                     ?>
  444.                 </td>
  445.             </tr>
  446.                     <?php
  447.                 }
  448.                 if (isset($showtable['Rows'])) {
  449.                     ?>
  450.             <tr>
  451.                 <td><?php echo ucfirst($strRows); ?></td>
  452.                 <td align="right">
  453.                     <?php echo PMA_formatNumber($showtable['Rows'], 0) . "\n"; ?>
  454.                 </td>
  455.             </tr>
  456.                     <?php
  457.                 }
  458.                 if (isset($showtable['Avg_row_length']) && $showtable['Avg_row_length'] > 0) {
  459.                     ?>
  460.             <tr>
  461.                 <td><?php echo ucfirst($strRowLength); ?> ø</td>
  462.                 <td>
  463.                     <?php echo PMA_formatNumber($showtable['Avg_row_length'], 0) . "\n"; ?>
  464.                 </td>
  465.             </tr>
  466.                     <?php
  467.                 }
  468.                 if (isset($showtable['Data_length']) && $showtable['Rows'] > 0 && $mergetable == false) {
  469.                     ?>
  470.             <tr>
  471.                 <td><?php echo ucfirst($strRowSize); ?> ø</td>
  472.                 <td align="right">
  473.                     <?php echo $avg_size . ' ' . $avg_unit . "\n"; ?>
  474.                 </td>
  475.             </tr>
  476.                     <?php
  477.                 }
  478.                 if (isset($showtable['Auto_increment'])) {
  479.                     ?>
  480.             <tr>
  481.                 <td><?php echo ucfirst($strNext); ?> Autoindex</td>
  482.                 <td align="right">
  483.                     <?php echo PMA_formatNumber($showtable['Auto_increment'], 0) . "\n"; ?>
  484.                 </td>
  485.             </tr>
  486.                     <?php
  487.                 }
  488.                 if (isset($showtable['Create_time'])) {
  489.                     ?>
  490.             <tr>
  491.                 <td><?php echo $strStatCreateTime; ?></td>
  492.                 <td align="right">
  493.                     <?php echo PMA_localisedDate(strtotime($showtable['Create_time'])) . "\n"; ?>
  494.                 </td>
  495.             </tr>
  496.                     <?php
  497.                 }
  498.                 if (isset($showtable['Update_time'])) {
  499.                     ?>
  500.             <tr>
  501.                 <td><?php echo $strStatUpdateTime; ?></td>
  502.                 <td align="right">
  503.                     <?php echo PMA_localisedDate(strtotime($showtable['Update_time'])) . "\n"; ?>
  504.                 </td>
  505.             </tr>
  506.                     <?php
  507.                 }
  508.                 if (isset($showtable['Check_time'])) {
  509.                     ?>
  510.             <tr>
  511.                 <td><?php echo $strStatCheckTime; ?></td>
  512.                 <td align="right">
  513.                     <?php echo PMA_localisedDate(strtotime($showtable['Check_time'])) . "\n"; ?>
  514.                 </td>
  515.             </tr>
  516.                     <?php
  517.                 }
  518.                 ?>
  519.  
  520.             </table>
  521.         </td>
  522.     </tr>
  523.     </table>
  524.  
  525.                 <?php
  526.             } // end if ($nonisam == false)
  527.         } // end if ($cfg['ShowStats'])
  528.     }
  529.     if ($multi_tables) {
  530.         unset($ret_keys, $num_rows, $show_comment);
  531.         echo '<hr />' . "\n";
  532.     } // end if
  533.     echo '</div>' . "\n";
  534.  
  535. } // end while
  536.  
  537. /**
  538.  * Displays the footer
  539.  */
  540. ?>
  541.  
  542. <script type="text/javascript">
  543. //<![CDATA[
  544. function printPage()
  545. {
  546.     // Do print the page
  547.     if (typeof(window.print) != 'undefined') {
  548.         window.print();
  549.     }
  550. }
  551. //]]>
  552. </script>
  553.  
  554. <p class="print_ignore">
  555.     <input type="button" id="print" value="<?php echo $strPrint; ?>"
  556.         onclick="printPage()" /></p>
  557.  
  558. <?php
  559. require_once './libraries/footer.inc.php';
  560. ?>
  561.