home *** CD-ROM | disk | FTP | other *** search
/ Enter 2004 June / ENTER.ISO / files / xampp-win32-1.4.5-installer.exe / xampp / server_databases.php < prev    next >
Encoding:
PHP Script  |  2003-11-26  |  17.6 KB  |  378 lines

  1. <?php
  2. /* $Id: server_databases.php,v 2.4 2003/11/26 22:52:24 rabus Exp $ */
  3. // vim: expandtab sw=4 ts=4 sts=4:
  4.  
  5.  
  6. /**
  7.  * Checks if the left frame has to be reloaded
  8.  */
  9. require_once('./libraries/grab_globals.lib.php');
  10.  
  11.  
  12. /**
  13.  * Does the common work
  14.  */
  15. $js_to_run = 'functions.js';
  16. require('./server_common.inc.php');
  17.  
  18. ?>
  19. <script type="text/javascript" language="javascript1.2">
  20. <!--
  21. function reload_window(db) {
  22.     if (typeof(window.parent) != 'undefined'
  23.         && typeof(window.parent.frames['nav']) != 'undefined') {
  24.         window.parent.frames['nav'].location.replace('./left.php?<?php echo PMA_generate_common_url('','','&');?>&db=' + db + '&hash=' + <?php echo (($cfg['QueryFrame'] && $cfg['QueryFrameJS']) ? 'window.parent.frames[\'queryframe\'].document.hashform.hash.value' : "'" . md5($cfg['PmaAbsoluteUri']) . "'"); ?>);
  25.     }
  26. }
  27. //-->
  28. </script>
  29.  
  30. <?php
  31.  
  32. /**
  33.  * Sorts the databases array according to the user's choice
  34.  *
  35.  * @param   array    a record associated to a database
  36.  * @param   array    a record associated to a database
  37.  *
  38.  * @return  integer  a value representing whether $a should be before $b in the
  39.  *                   sorted array or not
  40.  *
  41.  * @global  string   the column the array shall be sorted by
  42.  * @global  string   the sorting order ('asc' or 'desc')
  43.  *
  44.  * @access  private
  45.  */
  46. function PMA_dbCmp($a, $b)
  47. {
  48.     global $sort_by, $sort_order;
  49.     if ($sort_by == 'db_name') {
  50.         return ($sort_order == 'asc' ? 1 : -1) * strcasecmp($a['db_name'], $b['db_name']);
  51.     } else if ($a[$sort_by] == $b[$sort_by]) {
  52.         return strcasecmp($a['db_name'], $b['db_name']);
  53.     } else {
  54.         return ($sort_order == 'asc' ? 1 : -1) * ((int)$a[$sort_by] > (int)$b[$sort_by] ? 1 : -1);
  55.     }
  56. } // end of the 'PMA_dbCmp()' function
  57.  
  58.  
  59. /**
  60.  * Gets the databases list - if it has not been built yet
  61.  */
  62. if ($server > 0 && empty($dblist)) {
  63.     PMA_availableDatabases();
  64. }
  65.  
  66.  
  67. /**
  68.  * Drops multiple databases
  69.  */
  70. if ((!empty($drop_selected_dbs) || isset($query_type)) && ($is_superuser || $cfg['AllowUserDropDatabase'])) {
  71.     if (empty($selected_db) && ! (isset($query_type) && !empty($selected))) {
  72.         $message = $strNoDatabasesSelected;
  73.     } else {
  74.         $action = 'server_databases.php';
  75.         $submit_mult = 'drop_db' ;
  76.         $err_url = 'server_databases.php?' . PMA_generate_common_url();
  77.         require('./mult_submits.inc.php');
  78.         $message = sprintf($strDatabasesDropped, count($selected));
  79.         // we need to reload the database list now.
  80.         PMA_availableDatabases();
  81.         $reload = 1;
  82.     }
  83. }
  84.  
  85.  
  86. /**
  87.  * Displays the links
  88.  */
  89. require('./server_links.inc.php');
  90.  
  91.  
  92. /**
  93.  * Displays the sub-page heading
  94.  */
  95. echo '<h2>' . "\n"
  96.    . '    ' . (empty($dbstats) ? $strDatabases : $strDatabasesStats) . "\n"
  97.    . '</h2>' . "\n";
  98.  
  99.  
  100. /**
  101.  * Checks if the user is allowed to do what he tries to...
  102.  */
  103. if (!empty($dbstats) && !$is_superuser) {
  104.     echo $strNoPrivileges . "\n";
  105.     require_once('./footer.inc.php');
  106. }
  107.  
  108.  
  109. /**
  110.  * Prepares the statistics
  111.  */
  112. $statistics = array();
  113. foreach($dblist AS $current_db) {
  114.     $tmp_array = array(
  115.         'db_name' => $current_db,
  116.         'tbl_cnt' => 0,
  117.         'data_sz' => 0,
  118.         'idx_sz' => 0,
  119.         'tot_sz' => 0
  120.     );
  121.     if (!empty($dbstats)) {
  122.         $res = PMA_mysql_query('SHOW TABLE STATUS FROM ' . PMA_backquote($current_db) . ';', $userlink) or PMA_mysqlDie(PMA_mysql_error($userlink), 'SHOW TABLE STATUS FROM ' . PMA_backquote($current_db) . ';');
  123.         while ($row = PMA_mysql_fetch_array($res, MYSQL_ASSOC)) {
  124.             $tmp_array['tbl_cnt']++;
  125.             $tmp_array['data_sz'] += $row['Data_length'];
  126.             $tmp_array['idx_sz'] += $row['Index_length'];
  127.         }
  128.     }
  129.     $tmp_array['tot_sz'] = $tmp_array['data_sz'] + $tmp_array['idx_sz'];
  130.     $statistics[] = $tmp_array;
  131. }
  132.  
  133. // avoids 'undefined index' errors
  134. if (empty($sort_by)) {
  135.     $sort_by = 'db_name';
  136. }
  137. if (empty($sort_order)) {
  138.     if ($sort_by == 'db_name') {
  139.         $sort_order = 'asc';
  140.     } else {
  141.         $sort_order = 'desc';
  142.     }
  143. }
  144.  
  145. // sorts the array
  146. usort($statistics, 'PMA_dbCmp');
  147.  
  148.  
  149. /**
  150.  * Displays the page
  151.  */
  152. if (count($statistics) > 0) {
  153.     echo '<form action="./server_databases.php" method="post" name="dbStatsForm">' . "\n"
  154.        . PMA_generate_common_hidden_inputs('', '', 1)
  155.        . '    <input type="hidden" name="dbstats" value="' . (empty($dbstats) ? '0' : '1') . '" />' . "\n"
  156.        . '    <input type="hidden" name="sort_by" value="' . $sort_by . '" />' . "\n"
  157.        . '    <input type="hidden" name="sort_order" value="' . $sort_order . '" />' . "\n"
  158.        . '    <table border="0">' . "\n"
  159.        . '        <tr>' . "\n"
  160.        . ($is_superuser || $cfg['AllowUserDropDatabase'] ? '            <th> </th>' . "\n" : '')
  161.        . '            <th>' . "\n"
  162.        . '                 ';
  163.     if (empty($dbstats)) {
  164.         echo $strDatabase . "\n"
  165.            . '                <img src="./images/asc_order.png" border="0" width="7" height="7"  alt="' . $strAscending . '" />' . "\n"
  166.            . '                 ' . "\n"
  167.            . '            </th>' . "\n";
  168.     } else {
  169.         echo "\n"
  170.            . '                <a href="./server_databases.php?' . $url_query . '&dbstats=1&sort_by=db_name&sort_order=' . (($sort_by == 'db_name' && $sort_order == 'asc') ? 'desc' : 'asc') . '">' . "\n"
  171.            . '                    ' . $strDatabase . "\n"
  172.            . ($sort_by == 'db_name' ? '                    <img src="./images/' . $sort_order . '_order.png" border="0" width="7" height="7"  alt="' . ($sort_order == 'asc' ? $strAscending : $strDescending) . '" />' . "\n" : '')
  173.            . '                </a>' . "\n"
  174.            . '                 ' . "\n"
  175.            . '            </th>' . "\n"
  176.            . '            <th>' . "\n"
  177.            . '                 ' . "\n"
  178.            . '                <a href="./server_databases.php?' . $url_query . '&dbstats=1&sort_by=tbl_cnt&sort_order=' . (($sort_by == 'tbl_cnt' && $sort_order == 'desc') ? 'asc' : 'desc') . '">' . "\n"
  179.            . '                    ' . $strNumTables . "\n"
  180.            . ($sort_by == 'tbl_cnt' ? '                    <img src="./images/' . $sort_order . '_order.png" border="0" width="7" height="7"  alt="' . ($sort_order == 'asc' ? $strAscending : $strDescending) . '" />' . "\n" : '')
  181.            . '                </a>' . "\n"
  182.            . '                 ' . "\n"
  183.            . '            </th>' . "\n"
  184.            . '            <th colspan="2">' . "\n"
  185.            . '                 ' . "\n"
  186.            . '                <a href="./server_databases.php?' . $url_query . '&dbstats=1&sort_by=data_sz&sort_order=' . (($sort_by == 'data_sz' && $sort_order == 'desc') ? 'asc' : 'desc') . '">' . "\n"
  187.            . '                    ' . $strData . "\n"
  188.            . ($sort_by == 'data_sz' ? '                    <img src="./images/' . $sort_order . '_order.png" border="0" width="7" height="7"  alt="' . ($sort_order == 'asc' ? $strAscending : $strDescending) . '" />' . "\n" : '')
  189.            . '                </a>' . "\n"
  190.            . '                 ' . "\n"
  191.            . '            </th>' . "\n"
  192.            . '            <th colspan="2">' . "\n"
  193.            . '                 ' . "\n"
  194.            . '                <a href="./server_databases.php?' . $url_query . '&dbstats=1&sort_by=idx_sz&sort_order=' . (($sort_by == 'idx_sz' && $sort_order == 'desc') ? 'asc' : 'desc') . '">' . "\n"
  195.            . '                    ' . $strIndexes . "\n"
  196.            . ($sort_by == 'idx_sz' ? '                    <img src="./images/' . $sort_order . '_order.png" border="0" width="7" height="7"  alt="' . ($sort_order == 'asc' ? $strAscending : $strDescending) . '" />' . "\n" : '')
  197.            . '                </a>' . "\n"
  198.            . '                 ' . "\n"
  199.            . '            </th>' . "\n"
  200.            . '            <th colspan="2">' . "\n"
  201.            . '                 ' . "\n"
  202.            . '                <a href="./server_databases.php?' . $url_query . '&dbstats=1&sort_by=tot_sz&sort_order=' . (($sort_by == 'tot_sz' && $sort_order == 'desc') ? 'asc' : 'desc') . '">' . "\n"
  203.            . '                    ' . $strTotalUC . "\n"
  204.            . ($sort_by == 'tot_sz' ? '                    <img src="./images/' . $sort_order . '_order.png" border="0" width="7" height="7"  alt="' . ($sort_order == 'asc' ? $strAscending : $strDescending) . '" />' . "\n" : '')
  205.            . '                </a>' . "\n"
  206.            . '                 ' . "\n"
  207.            . '            </th>' . "\n";
  208.     }
  209.     if ($is_superuser) {
  210.         echo '            <th>' . "\n"
  211.            . '                 ' . $strAction . ' ' . "\n"
  212.            . '            </th>' . "\n";
  213.     }
  214.     echo '        </tr>' . "\n";
  215.     $useBgcolorOne = TRUE;
  216.     $total_calc = array(
  217.         'db_cnt' => 0,
  218.         'tbl_cnt' => 0,
  219.         'data_sz' => 0,
  220.         'idx_sz' => 0,
  221.         'tot_sz' => 0
  222.     );
  223.     foreach ($statistics as $current) {
  224.         list($data_size, $data_unit) = PMA_formatByteDown($current['data_sz'], 3, 1);
  225.         list($idx_size, $idx_unit)   = PMA_formatByteDown($current['idx_sz'], 3, 1);
  226.         list($tot_size, $tot_unit)   = PMA_formatByteDown($current['tot_sz'], 3, 1);
  227.         $total_calc['db_cnt']++;
  228.         $total_calc['tbl_cnt'] += $current['tbl_cnt'];
  229.         $total_calc['data_sz'] += $current['data_sz'];
  230.         $total_calc['idx_sz']  += $current['idx_sz'];
  231.         $total_calc['tot_sz']  += $current['tot_sz'];
  232.         echo '        <tr>' . "\n";
  233.         if ($is_superuser || $cfg['AllowUserDropDatabase']) {
  234.             echo '            <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '">' . "\n"
  235.                . '                <input type="checkbox" name="selected_db[]" title="' . htmlspecialchars($current['db_name']) . '" value="' . htmlspecialchars($current['db_name']) . '" ' . (empty($checkall) ? '' : 'checked="checked" ') . '/>' . "\n"
  236.                . '            </td>' . "\n";
  237.         }
  238.         echo '            <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '">' . "\n"
  239.            . '                <a onclick="reload_window(\'' . urlencode($current['db_name']) . '\'); return true;" href="' . $cfg['DefaultTabDatabase'] . '?' . $url_query . '&db=' . urlencode($current['db_name']) . '" title="' . sprintf($strJumpToDB, htmlspecialchars($current['db_name'])) . '">' . "\n"
  240.            . '                    ' . htmlspecialchars($current['db_name']) . "\n"
  241.            . '                </a>' . "\n"
  242.            . '            </td>' . "\n";
  243.         if (!empty($dbstats)) {
  244.             echo '            <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '" align="right">' . "\n"
  245.                . '                ' . $current['tbl_cnt'] . "\n"
  246.                . '            </td>' . "\n"
  247.                . '            <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '" align="right">' . "\n"
  248.                . '                ' . $data_size . "\n"
  249.                . '            </td>' . "\n"
  250.                . '            <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '">' . "\n"
  251.                . '                ' . $data_unit . "\n"
  252.                . '            </td>' . "\n"
  253.                . '            <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '" align="right">' . "\n"
  254.                . '                ' . $idx_size . "\n"
  255.                . '            </td>' . "\n"
  256.                . '            <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '">' . "\n"
  257.                . '                ' . $idx_unit . "\n"
  258.                . '            </td>' . "\n"
  259.                . '            <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '" align="right">' . "\n"
  260.                . '                <b>' . "\n"
  261.                . '                    ' . $tot_size . "\n"
  262.                . '                </b>' . "\n"
  263.                . '            </td>' . "\n"
  264.                . '            <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '">' . "\n"
  265.                . '                <b>' . "\n"
  266.                . '                    ' . $tot_unit . "\n"
  267.                . '                </b>' . "\n"
  268.                . '            </td>' . "\n";
  269.         }
  270.         if ($is_superuser) {
  271.             echo '            <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '">' . "\n"
  272.                . '                <a onclick="reload_window(\'' . urlencode($current['db_name']) . '\'); return true;" href="./server_privileges.php?' . $url_query . '&checkprivs=' . urlencode($current['db_name']) . '" title="' . sprintf($strCheckPrivsLong, htmlspecialchars($current['db_name'])) . '">'. "\n"
  273.                . '                    ' . $strCheckPrivs . "\n"
  274.                . '                </a>' . "\n"
  275.                . '            </td>' . "\n";
  276.         }
  277.         echo '        </tr>' . "\n";
  278.         $useBgcolorOne = !$useBgcolorOne;
  279.     } // end while
  280.     if (!empty($dbstats)) {
  281.         list($data_size, $data_unit) = PMA_formatByteDown($total_calc['data_sz'], 3, 1);
  282.         list($idx_size, $idx_unit)   = PMA_formatByteDown($total_calc['idx_sz'], 3, 1);
  283.         list($tot_size, $tot_unit)   = PMA_formatByteDown($total_calc['tot_sz'], 3, 1);
  284.         echo '        <tr>' . "\n"
  285.            . '            <th> </th>' . "\n"
  286.            . '            <th>' . "\n"
  287.            . '                 ' . $strTotalUC . ': ' . $total_calc['db_cnt'] . ' ' . "\n"
  288.            . '            </th>' . "\n"
  289.            . '            <th align="right">' . "\n"
  290.            . '                 ' . $total_calc['tbl_cnt'] . ' ' . "\n"
  291.            . '            </th>' . "\n"
  292.            . '            <th align="right">' . "\n"
  293.            . '                 ' . $data_size . "\n"
  294.            . '            </th>' . "\n"
  295.            . '            <th align="left">' . "\n"
  296.            . '                ' . $data_unit . ' ' . "\n"
  297.            . '            </th>' . "\n"
  298.            . '            <th align="right">' . "\n"
  299.            . '                 ' . $idx_size . "\n"
  300.            . '            </th>' . "\n"
  301.            . '            <th align="left">' . "\n"
  302.            . '                ' . $idx_unit . ' ' . "\n"
  303.            . '            </th>' . "\n"
  304.            . '            <th align="right">' . "\n"
  305.            . '                 ' . $tot_size . "\n"
  306.            . '            </th>' . "\n"
  307.            . '            <th align="left">' . "\n"
  308.            . '                ' . $tot_unit . ' ' . "\n"
  309.            . '            </th>' . "\n"
  310.            . '            <th> </th>' . "\n"
  311.            . '        </tr>' . "\n";
  312.     }
  313.     if ($is_superuser || $cfg['AllowUserDropDatabase']) {
  314.         $common_url_query = PMA_generate_common_url() . '&sort_by=' . $sort_by . '&sort_order=' . $sort_order . '&dbstats=' . (empty($dbstats) ? '10' : '3');
  315.         echo '    <tr>' . "\n"
  316.            . '        <td colspan="' . (empty($dbstats) ? '10' : '3') . '">' . "\n"
  317.            . '            <img src="./images/arrow_' . $text_dir . '.gif" border="0" width="38" height="22" alt="' . $strWithChecked . '" />' . "\n"
  318.            . '            <a href="./server_databases.php?' . $common_url_query . '&checkall=1" onclick="setCheckboxes(\'dbStatsForm\', true); return false;">' . "\n"
  319.            . '                ' . $strCheckAll
  320.            . '            </a>' . "\n"
  321.            . '             / ' . "\n"
  322.            . '            <a href="./server_databases.php?' . $common_url_query . '" onclick="setCheckboxes(\'dbStatsForm\', false); return false;">' . "\n"
  323.            . '                ' . $strUncheckAll
  324.            . '            </a>' . "\n"
  325.            . '        </td>' . "\n"
  326.            . '    </tr>' . "\n";
  327.     }
  328.     echo '    </table>' . "\n";
  329.     unset($data_size);
  330.     unset($data_unit);
  331.     unset($idx_size);
  332.     unset($idx_unit);
  333.     unset($tot_size);
  334.     unset($tot_unit);
  335.     if ($is_superuser || $cfg['AllowUserDropDatabase']) {
  336.         echo '    <ul>' . "\n";
  337.     }
  338.     if ($is_superuser && empty($dbstats)) {
  339.         echo '        <li>' . "\n"
  340.            . '            <b>' . "\n"
  341.            . '                <a href="./server_databases.php?' . $url_query . '&dbstats=1" title="' . $strDatabasesStatsEnable . '">' . "\n"
  342.            . '                    ' . $strDatabasesStatsEnable . "\n"
  343.            . '                </a>' . "\n"
  344.            . '            </b>' . "\n"
  345.            . '            <br />' . "\n"
  346.            . '            ' . $strDatabasesStatsHeavyTraffic . "\n"
  347.            . '        </li><br /><br />' . "\n";
  348.     } else if ($is_superuser && !empty($dbstats)) {
  349.         echo '        <li>' . "\n"
  350.            . '            <b>' . "\n"
  351.            . '                <a href="./server_databases.php?' . $url_query . '" title="' . $strDatabasesStatsDisable . '">'. "\n"
  352.            . '                    ' . $strDatabasesStatsDisable . "\n"
  353.            . '                </a>' . "\n"
  354.            . '            </b>' . "\n"
  355.            . '        </li><br /><br />' . "\n";
  356.     }
  357.     if ($is_superuser || $cfg['AllowUserDropDatabase']) {
  358.         echo '        <li>' . "\n"
  359.            . '            <b>' . "\n"
  360.            . '                ' . $strDropSelectedDatabases . "\n"
  361.            . '            </b><br />' . "\n"
  362.            . '            <input type="submit" name="drop_selected_dbs" value="' . $strGo . '" />' . "\n"
  363.            . '        </li>' . "\n"
  364.            . '    </ul>' . "\n";
  365.     }
  366.     echo '</form>' . "\n";
  367. } else {
  368.     echo $strNoDatabases . "\n";
  369. }
  370.  
  371.  
  372. /**
  373.  * Sends the footer
  374.  */
  375. require_once('./footer.inc.php');
  376.  
  377. ?>
  378.