home *** CD-ROM | disk | FTP | other *** search
/ Enter 2004 June / ENTER.ISO / files / xampp-win32-1.4.5-installer.exe / xampp / db_printview.php < prev    next >
Encoding:
PHP Script  |  2003-12-22  |  10.5 KB  |  310 lines

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