home *** CD-ROM | disk | FTP | other *** search
/ Freelog 70 / Freelog070.iso / Internet / EasyPHP / easyphp1-8_setup.exe / {app} / phpmyadmin / db_printview.php < prev    next >
Encoding:
PHP Script  |  2004-05-20  |  10.2 KB  |  309 lines

  1. <?php
  2. /* $Id: db_printview.php,v 2.8 2004/05/20 16:14:08 nijel Exp $ */
  3. // vim: expandtab sw=4 ts=4 sts=4:
  4.  
  5.  
  6. /**
  7.  * Gets the variables sent or posted to this script, then displays headers
  8.  */
  9. require_once('./libraries/grab_globals.lib.php');
  10. require_once('./header.inc.php');
  11.  
  12. // Check parameters
  13. require_once('./libraries/common.lib.php');
  14.  
  15. PMA_checkParameters(array('db'));
  16.  
  17. /**
  18.  * Defines the url to return to in case of error in a sql statement
  19.  */
  20. $err_url = 'db_details.php?' . PMA_generate_common_url($db);
  21.  
  22. /**
  23.  * Settings for relations stuff
  24.  */
  25. require_once('./libraries/relation.lib.php');
  26. $cfgRelation = PMA_getRelationsParam();
  27.  
  28. /**
  29.  * Gets the list of the table in the current db and informations about these
  30.  * tables if possible
  31.  */
  32. // staybyte: speedup view on locked tables - 11 June 2001
  33. // Special speedup for newer MySQL Versions (in 4.0 format changed)
  34. if ($cfg['SkipLockedTables'] == TRUE) {
  35.     $result = PMA_DBI_query('SHOW OPEN TABLES FROM ' . PMA_backquote($db) . ';');
  36.     // Blending out tables in use
  37.     if ($result != FALSE && PMA_DBI_num_rows($result) > 0) {
  38.         while ($tmp = PMA_DBI_fetch_row($result)) {
  39.             // if in use memorize tablename
  40.             if (preg_match('@in_use=[1-9]+@i', $tmp[0])) {
  41.                 $sot_cache[$tmp[0]] = TRUE;
  42.             }
  43.         }
  44.         PMA_DBI_free_result($result);
  45.         unset($result);
  46.  
  47.         if (isset($sot_cache)) {
  48.             $result      = PMA_DBI_query('SHOW TABLES FROM ' . PMA_backquote($db) . ';', NULL, PMA_DBI_QUERY_STORE);
  49.             if ($result != FALSE && PMA_DBI_num_rows($result) > 0) {
  50.                 while ($tmp = PMA_DBI_fetch_row($result)) {
  51.                     if (!isset($sot_cache[$tmp[0]])) {
  52.                         $sts_result  = PMA_DBI_query('SHOW TABLE STATUS FROM ' . PMA_backquote($db) . ' LIKE \'' . addslashes($tmp[0]) . '\';');
  53.                         $sts_tmp     = PMA_DBI_fetch_assoc($sts_result);
  54.                         $tables[]    = $sts_tmp;
  55.                     } else { // table in use
  56.                         $tables[]    = array('Name' => $tmp[0]);
  57.                     }
  58.                 }
  59.                 PMA_DBI_free_result($result);
  60.                 unset($result);
  61.                 $sot_ready = TRUE;
  62.             }
  63.         }
  64.     }
  65. }
  66. if (!isset($sot_ready)) {
  67.     $result      = PMA_DBI_query('SHOW TABLE STATUS FROM ' . PMA_backquote($db) . ';');
  68.     if (PMA_DBI_num_rows($result) > 0) {
  69.         while ($sts_tmp = PMA_DBI_fetch_assoc($result)) {
  70.             $tables[] = $sts_tmp;
  71.         }
  72.         PMA_DBI_free_result($result);
  73.         unset($res);
  74.     }
  75. }
  76. $num_tables = (isset($tables) ? count($tables) : 0);
  77.  
  78. if ($cfgRelation['commwork']) {
  79.     $comment = PMA_getComments($db);
  80.  
  81.     /**
  82.      * Displays DB comment
  83.      */
  84.     if (is_array($comment)) {
  85.         ?>
  86.     <!-- DB comment -->
  87.     <p><i>
  88.         <?php echo htmlspecialchars(implode(' ', $comment)) . "\n"; ?>
  89.     </i></p>
  90.         <?php
  91.     } // end if
  92. }
  93.  
  94. /**
  95.  * If there is at least one table, displays the printer friendly view, else
  96.  * an error message
  97.  */
  98. // 1. No table
  99. if ($num_tables == 0) {
  100.     echo $strNoTablesFound;
  101. }
  102. // 2. Shows table informations on mysql >= 3.23.03 - staybyte - 11 June 2001
  103. else {
  104.     ?>
  105.  
  106. <!-- The tables list -->
  107. <table border="<?php echo $cfg['Border']; ?>">
  108. <tr>
  109.     <th> <?php echo $strTable; ?> </th>
  110.     <th><?php echo $strRecords; ?></th>
  111.     <th><?php echo $strType; ?></th>
  112.     <?php
  113.     if ($cfg['ShowStats']) {
  114.         echo '<th>' . $strSize . '</th>';
  115.     }
  116.     echo "\n";
  117.     ?>
  118.     <th><?php echo $strComments; ?></th>
  119. </tr>
  120.     <?php
  121.     $i = $sum_entries = $sum_size = 0;
  122.     foreach ($tables AS $keyname => $sts_data) {
  123.         $table     = $sts_data['Name'];
  124.         $bgcolor   = ($i++ % 2) ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo'];
  125.         echo "\n";
  126.         ?>
  127. <tr>
  128.     <td bgcolor="<?php echo $bgcolor; ?>" nowrap="nowrap">
  129.          <b><?php echo htmlspecialchars($table); ?> </b> 
  130.     </td>
  131.         <?php
  132.         echo "\n";
  133.         $mergetable         = FALSE;
  134.         $nonisam            = FALSE;
  135.         if (isset($sts_data['Type'])) {
  136.             if ($sts_data['Type'] == 'MRG_MyISAM') {
  137.                 $mergetable = TRUE;
  138.             } else if (!preg_match('@ISAM|HEAP@i', $sts_data['Type'])) {
  139.                 $nonisam    = TRUE;
  140.             }
  141.         }
  142.  
  143.         if (isset($sts_data['Rows'])) {
  144.             if ($mergetable == FALSE) {
  145.                 if ($cfg['ShowStats'] && $nonisam == FALSE) {
  146.                     $tblsize                        =  $sts_data['Data_length'] + $sts_data['Index_length'];
  147.                     $sum_size                       += $tblsize;
  148.                     if ($tblsize > 0) {
  149.                         list($formated_size, $unit) =  PMA_formatByteDown($tblsize, 3, 1);
  150.                     } else {
  151.                         list($formated_size, $unit) =  PMA_formatByteDown($tblsize, 3, 0);
  152.                     }
  153.                 } else if ($cfg['ShowStats']) {
  154.                     $formated_size                  = ' - ';
  155.                     $unit                           = '';
  156.                 }
  157.                 $sum_entries                        += $sts_data['Rows'];
  158.             }
  159.             // MyISAM MERGE Table
  160.             else if ($cfg['ShowStats'] && $mergetable == TRUE) {
  161.                 $formated_size = ' - ';
  162.                 $unit          = '';
  163.             }
  164.             else if ($cfg['ShowStats']) {
  165.                 $formated_size = 'unknown';
  166.                 $unit          = '';
  167.             }
  168.             ?>
  169.     <td align="right" bgcolor="<?php echo $bgcolor; ?>">
  170.             <?php
  171.             echo "\n" . '        ';
  172.             if ($mergetable == TRUE) {
  173.                 echo '<i>' . number_format($sts_data['Rows'], 0, $number_decimal_separator, $number_thousands_separator) . '</i>' . "\n";
  174.             } else {
  175.                 echo number_format($sts_data['Rows'], 0, $number_decimal_separator, $number_thousands_separator) . "\n";
  176.             }
  177.             ?>
  178.     </td>
  179.     <td nowrap="nowrap" bgcolor="<?php echo $bgcolor; ?>">
  180.          <?php echo (isset($sts_data['Type']) ? $sts_data['Type'] : ' '); ?> 
  181.     </td>
  182.             <?php
  183.             if ($cfg['ShowStats']) {
  184.                 echo "\n";
  185.                 ?>
  186.     <td align="right" bgcolor="<?php echo $bgcolor; ?>" nowrap="nowrap">
  187.          <?php echo $formated_size . ' ' . $unit . "\n"; ?>
  188.     </td>
  189.                 <?php
  190.                 echo "\n";
  191.             } // end if
  192.         } else {
  193.             ?>
  194.     <td colspan="3" align="center" bgcolor="<?php echo $bgcolor; ?>">
  195.         <?php echo $strInUse . "\n"; ?>
  196.     </td>
  197.             <?php
  198.         }
  199.         echo "\n";
  200.         ?>
  201.     <td bgcolor="<?php echo $bgcolor; ?>">
  202.         <?php echo $sts_data['Comment']; ?>
  203.         <?php
  204.             if (!empty($sts_data['Comment'])) {
  205.                 $needs_break = '<br />';
  206.             } else {
  207.                 $needs_break = '';
  208.             }
  209.  
  210.             if ((isset($sts_data['Create_time']) && !empty($sts_data['Create_time']))
  211.                  || (isset($sts_data['Update_time']) && !empty($sts_data['Update_time']))
  212.                  || (isset($sts_data['Check_time']) && !empty($sts_data['Check_time']))) {
  213.                 echo $needs_break;
  214.                 ?>
  215.                 <table border="0" cellpadding="1" cellspacing="1" width="100%">
  216.                 <?php
  217.  
  218.                 if (isset($sts_data['Create_time']) && !empty($sts_data['Create_time'])) {
  219.                     ?>
  220.                     <tr>
  221.                         <td style="font-size: <?php echo $font_smaller; ?>" align="right"><?php echo $strStatCreateTime . ': '; ?></td>
  222.                         <td style="font-size: <?php echo $font_smaller; ?>" align="right"><?php echo PMA_localisedDate(strtotime($sts_data['Create_time'])); ?></td>
  223.                     </tr>
  224.                     <?php
  225.                 }
  226.  
  227.                 if (isset($sts_data['Update_time']) && !empty($sts_data['Update_time'])) {
  228.                     ?>
  229.                     <tr>
  230.                         <td style="font-size: <?php echo $font_smaller; ?>" align="right"><?php echo $strStatUpdateTime . ': '; ?></td>
  231.                         <td style="font-size: <?php echo $font_smaller; ?>" align="right"><?php echo PMA_localisedDate(strtotime($sts_data['Update_time'])); ?></td>
  232.                     </tr>
  233.                     <?php
  234.                 }
  235.  
  236.                 if (isset($sts_data['Check_time']) && !empty($sts_data['Check_time'])) {
  237.                     ?>
  238.                     <tr>
  239.                         <td style="font-size: <?php echo $font_smaller; ?>" align="right"><?php echo $strStatCheckTime . ': '; ?></td>
  240.                         <td style="font-size: <?php echo $font_smaller; ?>" align="right"><?php echo PMA_localisedDate(strtotime($sts_data['Check_time'])); ?></td>
  241.                     </tr>
  242.                     <?php
  243.                 }
  244.                 ?>
  245.                 </table>
  246.                 <?php
  247.             }
  248.         ?>
  249.     </td>
  250. </tr>
  251.         <?php
  252.     }
  253.     // Show Summary
  254.     if ($cfg['ShowStats']) {
  255.         list($sum_formated, $unit) = PMA_formatByteDown($sum_size, 3, 1);
  256.     }
  257.     echo "\n";
  258.     ?>
  259. <tr>
  260.     <th align="center">
  261.          <b><?php echo sprintf($strTables, number_format($num_tables, 0, $number_decimal_separator, $number_thousands_separator)); ?></b> 
  262.     </th>
  263.     <th align="right" nowrap="nowrap">
  264.         <b><?php echo number_format($sum_entries, 0, $number_decimal_separator, $number_thousands_separator); ?></b>
  265.     </th>
  266.     <th align="center">
  267.         <b>--</b>
  268.     </th>
  269.     <?php
  270.     if ($cfg['ShowStats']) {
  271.         echo "\n";
  272.         ?>
  273.     <th align="right" nowrap="nowrap">
  274.         <b><?php echo $sum_formated . ' ' . $unit; ?></b>
  275.     </th>
  276.         <?php
  277.     }
  278.     echo "\n";
  279.     ?>
  280.     <th> </th>
  281. </tr>
  282. </table>
  283.     <?php
  284. }
  285.  
  286. /**
  287.  * Displays the footer
  288.  */
  289. echo "\n";
  290. ?>
  291. <script type="text/javascript" language="javascript1.2">
  292. <!--
  293. function printPage()
  294. {
  295.     document.getElementById('print').style.visibility = 'hidden';
  296.     // Do print the page
  297.     if (typeof(window.print) != 'undefined') {
  298.         window.print();
  299.     }
  300.     document.getElementById('print').style.visibility = '';
  301. }
  302. //-->
  303. </script>
  304. <?php
  305. echo '<br /><br /> <input type="button" style="visibility: ; width: 100px; height: 25px" id="print" value="' . $strPrint . '" onclick="printPage()">' . "\n";
  306.  
  307. require_once('./footer.inc.php');
  308. ?>
  309.