home *** CD-ROM | disk | FTP | other *** search
/ Internet Magazine 2004 New Year / INTERNET112.ISO / pc / software / windows / building / easy_php / easyphp16_setup.exe / {app} / phpmyadmin / main.php < prev    next >
Encoding:
PHP Script  |  2003-09-24  |  17.3 KB  |  498 lines

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