home *** CD-ROM | disk | FTP | other *** search
/ PC World 2005 April / PCWorld_2005-04_cd.bin / akce / web / phptriad / phptriad2-2-1.exe / htdocs / phpmyadmin / main.php < prev    next >
PHP Script  |  2002-01-06  |  17KB  |  475 lines

  1. <?php
  2. /* $Id: main.php,v 1.83 2002/01/05 16:10:54 loic1 Exp $ */
  3.  
  4.  
  5. /**
  6.  * Gets some core libraries and displays a top message if required
  7.  */
  8. require('./libraries/grab_globals.lib.php');
  9. require('./libraries/common.lib.php');
  10. // Puts the language to use in a cookie that will expire in 30 days
  11. setcookie('lang', $lang, time() + 60*60*24*30);
  12. // Defines the "item" image depending on text direction
  13. $item_img = 'images/item_' . $text_dir . '.gif';
  14. // Handles some variables that may have been sent by the calling script
  15. if (isset($db)) {
  16.     unset($db);
  17. }
  18. if (isset($table)) {
  19.     unset($table);
  20. }
  21. $show_query = 'y';
  22. require('./header.inc.php');
  23. if (isset($message)) {
  24.     PMA_showMessage($message);
  25. }
  26. else if (isset($reload) && $reload) {
  27.     // Reloads the navigation frame via JavaScript if required
  28.     echo "\n";
  29.     ?>
  30. <script type="text/javascript" language="javascript1.2">
  31. <!--
  32. window.parent.frames['nav'].location.replace('./left.php?lang=<?php echo $lang; ?>&server=<?php echo $server; ?>');
  33. //-->
  34. </script>
  35.     <?php
  36. }
  37. echo "\n";
  38.  
  39.  
  40. /**
  41.  * Displays the welcome message and the server informations
  42.  */
  43. ?>
  44. <h1><?php echo sprintf($strWelcome, ' phpMyAdmin ' . PMA_VERSION); ?></h1>
  45.  
  46. <?php
  47. // Don't display server info if $server == 0 (no server selected)
  48. // loic1: modified in order to have a valid words order whatever is the
  49. //        language used
  50. if ($server > 0) {
  51.     $server_info     = $cfgServer['host']
  52.                      . (empty($cfgServer['port']) ? '' : ':' . $cfgServer['port']);
  53.     // loic1: skip this because it's not a so good idea to display sockets
  54.     //        used to everybody
  55.     // if (!empty($cfgServer['socket']) && PMA_PHP_INT_VERSION >= 30010) {
  56.     //     $server_info .= ':' . $cfgServer['socket'];
  57.     // }
  58.     $local_query     = 'SELECT VERSION() as version, USER() as user';
  59.     $res             = mysql_query($local_query) or PMA_mysqlDie('', $local_query, FALSE, '');
  60.     $mysql_cur_user  = mysql_result($res, 0, 'user');
  61.  
  62.     $full_string     = str_replace('%pma_s1%', mysql_result($res, 0, 'version'), $strMySQLServerProcess);
  63.     $full_string     = str_replace('%pma_s2%', $server_info, $full_string);
  64.     $full_string     = str_replace('%pma_s3%', $mysql_cur_user, $full_string);
  65.  
  66.     echo '<p><b>' . $full_string . '</b></p><br />' . "\n";
  67. } // end if
  68.  
  69.  
  70. /**
  71.  * Reload mysql (flush privileges)
  72.  */
  73. if (($server > 0) && isset($mode) && ($mode == 'reload')) {
  74.     $result = mysql_query('FLUSH PRIVILEGES'); // Debug: or PMA_mysqlDie('', 'FLUSH PRIVILEGES', FALSE, 'main.php?lang=' . $lang . '&server=' . $server);
  75.     echo '<p><b>';
  76.     if ($result != 0) {
  77.       echo $strMySQLReloaded;
  78.     } else {
  79.       echo $strReloadFailed;
  80.     }
  81.     echo '</b></p>' . "\n\n";
  82. }
  83.  
  84.  
  85. /**
  86.  * Displays the MySQL servers choice form 
  87.  */
  88. if ($server == 0 || count($cfgServers) > 1) {
  89.     ?>
  90. <!-- MySQL servers choice form -->
  91. <table>
  92. <tr>
  93.     <th><?php echo $strServerChoice; ?></th>
  94. </tr>
  95. <tr>
  96.     <td>
  97.         <form method="post" action="index.php" target="_parent">
  98.             <select name="server">
  99.     <?php
  100.     echo "\n";
  101.     reset($cfgServers);
  102.     while (list($key, $val) = each($cfgServers)) {
  103.         if (!empty($val['host'])) {
  104.             echo '                <option value="' . $key . '"';
  105.             if (!empty($server) && ($server == $key)) {
  106.                 echo ' selected="selected"';
  107.             }
  108.             echo '>';
  109.             if ($val['verbose'] != '') {
  110.                 echo $val['verbose'];
  111.             } else {
  112.                 echo $val['host'];
  113.                 if (!empty($val['port'])) {
  114.                     echo ':' . $val['port'];
  115.                 }
  116.                 // loic1: skip this because it's not a so good idea to display
  117.                 //        sockets used to everybody
  118.                 // if (!empty($val['socket']) && PMA_PHP_INT_VERSION >= 30010) {
  119.                 //     echo ':' . $val['socket'];
  120.                 // }
  121.             }
  122.             // loic1: if 'only_db' is an array and there is more than one
  123.             //        value, displaying such informations may not be a so good
  124.             //        idea
  125.             if (!empty($val['only_db'])) {
  126.                 echo ' - ' . (is_array($val['only_db']) ? implode(', ', $val['only_db']) : $val['only_db']);
  127.             }
  128.             if (!empty($val['user']) && ($val['auth_type'] == 'config')) {
  129.                 echo '  (' . $val['user'] . ')';
  130.             }
  131.             echo ' </option>' . "\n";
  132.         } // end if (!empty($val['host']))
  133.     } // end while
  134.     ?>
  135.             </select>
  136.             <input type="hidden" name="lang" value="<?php echo $lang; ?>" />
  137.             <input type="submit" value="<?php echo $strGo; ?>" />
  138.         </form>
  139.     </td>
  140. </tr>
  141. </table>
  142. <br />
  143.     <?php
  144. } // end of the servers choice form
  145. ?>
  146.  
  147. <!-- MySQL and phpMyAdmin related links -->
  148. <table>
  149. <tr>
  150.  
  151. <?php
  152. /**
  153.  * Displays the mysql server related links 
  154.  */
  155. $is_superuser        = FALSE;
  156. if ($server > 0) {
  157.     // Get user's global privileges ($dbh and $userlink are links to MySQL
  158.     // defined in the "common.lib.php" library)
  159.     $mysql_cur_user  = substr($mysql_cur_user, 0, strpos($mysql_cur_user, '@'));
  160.     $is_create_priv  = FALSE;
  161.     $is_process_priv = FALSE;
  162.     $is_reload_priv  = FALSE;
  163.     $is_superuser    = @mysql_query('USE mysql', $userlink);
  164.     if ($dbh) {
  165.         $local_query = 'SELECT Create_priv, Process_priv, Reload_priv FROM mysql.user WHERE User = \'' . PMA_sqlAddslashes($mysql_cur_user) . '\'';
  166.         $rs_usr      = mysql_query($local_query, $dbh); // Debug: or PMA_mysqlDie('', $local_query, FALSE);
  167.         if ($rs_usr) {
  168.             while ($result_usr = mysql_fetch_array($rs_usr)) {
  169.                 if (!$is_create_priv) {
  170.                     $is_create_priv  = ($result_usr['Create_priv'] == 'Y');
  171.                 }
  172.                 if (!$is_process_priv) {
  173.                     $is_process_priv = ($result_usr['Process_priv'] == 'Y');
  174.                 }
  175.                 if (!$is_reload_priv) {
  176.                     $is_reload_priv  = ($result_usr['Reload_priv'] == 'Y');
  177.                 }
  178.             } // end while
  179.             mysql_free_result($rs_usr);
  180.         } // end if
  181.     } // end if
  182.  
  183.     // If the user has Create priv on a inexistant db, show him in the dialog
  184.     // the first inexistant db name that we find, in most cases it's probably
  185.     // the one he just dropped :)
  186.     // (Note: we only get here after a browser reload, I don't know why)
  187.     if (!$is_create_priv) {
  188.         $local_query = 'SELECT DISTINCT Db FROM mysql.db WHERE Create_priv = \'Y\' AND User = \'' . PMA_sqlAddslashes($mysql_cur_user) . '\'';
  189.         $rs_usr      = mysql_query($local_query, $dbh); // Debug: or PMA_mysqlDie('', $local_query, FALSE);
  190.         if ($rs_usr) {
  191.             while ($row = mysql_fetch_array($rs_usr)) {
  192.                 if (!mysql_select_db($row['Db'], $userlink) && @mysql_errno() != 1044) {
  193.                     $re              = '(^|(\\\\\\\\)+|[^\])';
  194.                     $row['Db']       = ereg_replace($re . '%', '\\1...', ereg_replace($re . '_', '\\1?', $row['Db']));
  195.                     $db_to_create    = $row['Db'];
  196.                     $is_create_priv  = TRUE;
  197.                     break;
  198.                 } // end if
  199.             } // end while
  200.             mysql_free_result($rs_usr);
  201.         } // end if
  202.     } // end if
  203.     else {
  204.         $db_to_create = '';
  205.     } // end else
  206.  
  207.     $common_url_query = 'lang=' . $lang . '&server=' . $server;
  208.  
  209.     // loic1: Displays the MySQL column only if at least one feature has to be
  210.     //        displayed
  211.     if ($is_superuser || $is_create_priv || $is_process_priv || $is_reload_priv
  212.         || $cfgShowMysqlInfo || $cfgShowMysqlVars || $cfgServer['auth_type'] != 'config') {
  213.         ?>
  214.     <!-- MySQL server related links -->
  215.     <td valign="top" align="<?php echo $cell_align_left; ?>">
  216.         <table>
  217.         <tr>
  218.             <th colspan="2">  MySQL</th>
  219.         </tr>
  220.         <?php
  221.         // The user is allowed to create a db
  222.         if ($is_create_priv) {
  223.             echo "\n";
  224.             ?>
  225.         <!-- db creation form -->
  226.         <tr>
  227.             <td valign="baseline"><img src="<?php echo $item_img; ?>" width="7" height="7" alt="item" /></td>
  228.             <td>
  229.             <form method="post" action="db_create.php">
  230.                 <?php echo $strCreateNewDatabase . ' ' . PMA_showDocuShort('C/R/CREATE_DATABASE.html'); ?><br />
  231.                 <input type="hidden" name="server" value="<?php echo $server; ?>" />
  232.                 <input type="hidden" name="lang" value="<?php echo $lang; ?>" />
  233.                 <input type="hidden" name="reload" value="1" />
  234.                 <input type="text" name="db" value="<?php echo $db_to_create; ?>" maxlength="64" />
  235.                 <input type="submit" value="<?php echo $strCreate; ?>" />
  236.             </form>
  237.             </td>
  238.         </tr>
  239.             <?php
  240.         } // end create db form
  241.         echo "\n";
  242.  
  243.         // Server related links
  244.         ?>
  245.         <!-- server-related links -->
  246.         <?php
  247.         if ($is_superuser || $cfgShowMysqlInfo) {
  248.             echo "\n";
  249.             ?>
  250.         <tr>
  251.             <td valign="baseline"><img src="<?php echo $item_img; ?>" width="7" height="7" alt="item" /></td>
  252.             <td>
  253.                 <a href="sql.php?<?php echo $common_url_query; ?>&db=mysql&sql_query=<?php echo urlencode('SHOW STATUS'); ?>&goto=main.php">
  254.                     <?php echo $strMySQLShowStatus; ?></a> 
  255.                 <?php echo PMA_showDocuShort('S/H/SHOW_STATUS.html') . "\n"; ?>
  256.             </td>
  257.         </tr>
  258.             <?php
  259.         } // end if
  260.         if ($is_superuser || $cfgShowMysqlVars) {
  261.             echo "\n";
  262.             ?>
  263.         <tr>
  264.             <td valign="baseline"><img src="<?php echo $item_img; ?>" width="7" height="7" alt="item" /></td>
  265.             <td>
  266.                 <a href="sql.php?<?php echo $common_url_query; ?>&db=mysql&sql_query=<?php echo urlencode('SHOW VARIABLES'); ?>&goto=main.php">
  267.                 <?php echo $strMySQLShowVars;?></a> 
  268.                 <?php echo PMA_showDocuShort('S/H/SHOW_VARIABLES.html') . "\n"; ?>
  269.             </td>
  270.         </tr>
  271.             <?php
  272.         }
  273.  
  274.         if ($is_process_priv) {
  275.             echo "\n";
  276.             ?>
  277.         <tr>
  278.             <td valign="baseline"><img src="<?php echo $item_img; ?>" width="7" height="7" alt="item" /></td>
  279.             <td>
  280.                 <a href="sql.php?<?php echo $common_url_query; ?>&db=mysql&sql_query=<?php echo urlencode('SHOW PROCESSLIST'); ?>&goto=main.php">
  281.                     <?php echo $strMySQLShowProcess; ?></a> 
  282.                 <?php echo PMA_showDocuShort('S/H/SHOW_PROCESSLIST.html') . "\n"; ?>
  283.             </td>
  284.         </tr>
  285.             <?php
  286.         } // end if
  287.  
  288.         if ($is_reload_priv) {
  289.             echo "\n";
  290.             ?>
  291.         <tr>
  292.             <td valign="baseline"><img src="<?php echo $item_img; ?>" width="7" height="7" alt="item" /></td>
  293.             <td>
  294.                 <a href="main.php?<?php echo $common_url_query; ?>&mode=reload">
  295.                     <?php echo $strReloadMySQL; ?></a> 
  296.                 <?php echo PMA_showDocuShort('F/L/FLUSH.html') . "\n"; ?>
  297.             </td>
  298.         </tr>
  299.             <?php
  300.         }
  301.  
  302.         if ($is_superuser) {
  303.             echo "\n";
  304.             ?>
  305.         <tr>
  306.             <td valign="baseline"><img src="<?php echo $item_img; ?>" width="7" height="7" alt="item" /></td>
  307.             <td>
  308.                 <a href="user_details.php?<?php echo $common_url_query; ?>&db=mysql&table=user">
  309.                     <?php echo $strUsers; ?></a> 
  310.                 <?php echo PMA_showDocuShort('P/r/Privilege_system.html') . "\n"; ?>
  311.             </td>
  312.         </tr>
  313.             <?php
  314.             if (PMA_MYSQL_INT_VERSION >= 32303) {
  315.                 echo "\n";
  316.                 ?>
  317.         <tr>
  318.             <td valign="baseline"><img src="<?php echo $item_img; ?>" width="7" height="7" alt="item" /></td>
  319.             <td>
  320.                 <a href="db_stats.php?<?php echo $common_url_query; ?>">
  321.                     <?php echo $strDatabasesStats; ?></a>
  322.             </td>
  323.         </tr>
  324.                 <?php
  325.             }
  326.         }
  327.  
  328.         // Logout for advanced authentication
  329.         if ($cfgServer['auth_type'] != 'config') {
  330.             $http_logout = ($cfgServer['auth_type'] == 'http')
  331.                          ? "\n" . '                <a href="' . $cfgPmaAbsoluteUri . 'Documentation.html#login_bug" target="documentation">(*)</a>'
  332.                          : '';
  333.             echo "\n";
  334.             ?>
  335.         <tr>
  336.             <td valign="baseline"><img src="<?php echo $item_img; ?>" width="7" height="7" alt="item" /></td>
  337.             <td>
  338.                 <a href="index.php?<?php echo $common_url_query; ?>&old_usr=<?php echo urlencode($PHP_AUTH_USER); ?>" target="_parent">
  339.                     <b><?php echo $strLogout; ?></b></a> <?php echo $http_logout . "\n"; ?>
  340.             </td>
  341.         </tr>
  342.             <?php
  343.         } // end if
  344.         echo "\n";
  345.         ?>
  346.         </table>
  347.     </td>
  348.     
  349.     <td>    </td>
  350.         <?php
  351.     } // end if
  352. } // end of if ($server > 0)
  353. echo "\n";
  354.  
  355.  
  356. /**
  357.  * Displays the phpMyAdmin related links 
  358.  */
  359. ?>
  360.  
  361.     <!-- phpMyAdmin related links -->
  362.     <td valign="top" align="<?php echo $cell_align_left; ?>">
  363.         <table>
  364.         <tr>
  365.             <th colspan="2">  phpMyAdmin</th>
  366.         </tr>
  367.  
  368. <?php
  369. // Displays language selection combo
  370. if (empty($cfgLang)) {
  371.     ?>
  372.         <!-- Language Selection -->
  373.         <tr>
  374.             <td valign="baseline"><img src="<?php echo $item_img; ?>" width="7" height="7" alt="item" /></td>
  375.             <td nowrap="nowrap">
  376.                 <form method="post" action="index.php" target="_parent">
  377.                     <input type="hidden" name="server" value="<?php echo $server; ?>" />
  378.                     Language:
  379.                     <select name="lang" dir="ltr" onchange="this.form.submit();">
  380.     <?php
  381.     echo "\n";
  382.  
  383.     /**
  384.      * Sorts available languages by their true names
  385.      *
  386.      * @param   array   the array to be sorted
  387.      * @param   mixed   a required parameter
  388.      *
  389.      * @return  the sorted array
  390.      *
  391.      * @access  private
  392.      */
  393.     function PMA_cmp(&$a, $b)
  394.     {
  395.         return (strcmp($a[1], $b[1]));
  396.     } // end of the 'PMA_cmp()' function
  397.  
  398.     uasort($available_languages, 'PMA_cmp');
  399.     reset($available_languages);
  400.     while (list($id, $tmplang) = each($available_languages)) {
  401.         $lang_name = ucfirst(substr(strstr($tmplang[0], '|'), 1));
  402.         if ($lang == $id) {
  403.             $selected = ' selected="selected"';
  404.         } else {
  405.             $selected = '';
  406.         }
  407.         echo '                        ';
  408.         echo '<option value="' . $id . '"' . $selected . '>' . $lang_name . ' (' . $id . ')</option>' . "\n";
  409.     }
  410.     ?> 
  411.                     </select>
  412.                     <input type="submit" value="Go" />
  413.                 </form>
  414.             </td>
  415.         </tr>
  416.     <?php
  417. }
  418. echo "\n";
  419. ?>
  420.  
  421.         <!-- Documentation -->
  422.         <tr>
  423.             <td valign="baseline"><img src="<?php echo $item_img; ?>" width="7" height="7" alt="item" /></td>
  424.             <td>
  425.                 <a href="Documentation.html" target="documentation"><b><?php echo $strPmaDocumentation; ?></b></a>
  426.             </td>
  427.         </tr>
  428.  
  429. <?php
  430. if ($is_superuser || $cfgShowPhpInfo) {
  431.     ?>
  432.         <!-- PHP Information -->
  433.         <tr>
  434.             <td valign="baseline"><img src="<?php echo $item_img; ?>" width="7" height="7" alt="item" /></td>
  435.             <td>
  436.                 <a href="phpinfo.php" target="_new"><?php echo $strShowPHPInfo; ?></a>
  437.             </td>
  438.         </tr>
  439.     <?php
  440. }
  441. echo "\n";
  442. ?>
  443.  
  444.         <!-- phpMyAdmin related urls -->
  445.         <tr>
  446.             <td valign="baseline"><img src="<?php echo $item_img; ?>" width="7" height="7" alt="item" /></td>
  447.             <td>
  448.                 <a href="http://phpwizard.net/projects/phpMyAdmin/" target="_new"><?php echo $strHomepageOfficial; ?></a>
  449.             </td>
  450.         </tr>
  451.         <tr>
  452.             <td valign="baseline"><img src="<?php echo $item_img; ?>" width="7" height="7" alt="item" /></td>
  453.             <td>
  454.                 <a href="http://phpmyadmin.sourceforge.net/" target="_new">
  455.                     <?php echo $strHomepageSourceforge; ?></a><br />
  456.                       [<a href="ChangeLog" target="_new">ChangeLog</a>]
  457.                    [<a href="http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/phpmyadmin/phpMyAdmin/" target="_new">CVS</a>]
  458.                    [<a href="http://sourceforge.net/mail/?group_id=23067" target="_new">Lists</a>]
  459.             </td>
  460.         </tr>
  461.         </table>
  462.     </td>
  463.  
  464. </tr>
  465. </table>
  466.  
  467.  
  468. <?php
  469. /**
  470.  * Displays the footer
  471.  */
  472. echo "\n";
  473. require('./footer.inc.php');
  474. ?>
  475.