home *** CD-ROM | disk | FTP | other *** search
/ Enter 2004 June / ENTER.ISO / files / xampp-win32-1.4.5-installer.exe / xampp / server_privileges.php < prev    next >
Encoding:
PHP Script  |  2004-06-07  |  89.9 KB  |  1,449 lines

  1. <?php
  2. /* $Id: server_privileges.php,v 2.4.4.3 2004/06/08 10:16:26 rabus Exp $ */
  3. // vim: expandtab sw=4 ts=4 sts=4:
  4.  
  5.  
  6. /**
  7.  * Does the common work
  8.  */
  9. $js_to_run = 'server_privileges.js';
  10. require('./server_common.inc.php');
  11.  
  12.  
  13. /**
  14.  * Checks if a dropdown box has been used for selecting a database / table
  15.  */
  16. if (!empty($pred_dbname)) {
  17.     $dbname = $pred_dbname;
  18.     unset($pred_dbname);
  19. }
  20. if (!empty($pred_tablename)) {
  21.     $tablename = $pred_tablename;
  22.     unset($pred_tablename);
  23. }
  24.  
  25.  
  26. /**
  27.  * Checks if the user is allowed to do what he tries to...
  28.  */
  29. if (!$is_superuser) {
  30.     require('./server_links.inc.php');
  31.     echo '<h2>' . "\n"
  32.        . '    ' . $strPrivileges . "\n"
  33.        . '</h2>' . "\n"
  34.        . $strNoPrivileges . "\n";
  35.     require_once('./footer.inc.php');
  36. }
  37.  
  38.  
  39. /**
  40.  * Extracts the privilege information of a priv table row
  41.  *
  42.  * @param   array    the row
  43.  * @param   boolean  add <dfn> tag with tooltips
  44.  *
  45.  * @global  ressource  the database connection
  46.  *
  47.  * @return  array
  48.  */
  49. function PMA_extractPrivInfo($row = '', $enableHTML = FALSE)
  50. {
  51.     global $userlink;
  52.  
  53.     $grants = array(
  54.         array('Select_priv', 'SELECT', $GLOBALS['strPrivDescSelect']),
  55.         array('Insert_priv', 'INSERT', $GLOBALS['strPrivDescInsert']),
  56.         array('Update_priv', 'UPDATE', $GLOBALS['strPrivDescUpdate']),
  57.         array('Delete_priv', 'DELETE', $GLOBALS['strPrivDescDelete']),
  58.         array('Create_priv', 'CREATE', $GLOBALS['strPrivDescCreateDb']),
  59.         array('Drop_priv', 'DROP', $GLOBALS['strPrivDescDropDb']),
  60.         array('Reload_priv', 'RELOAD', $GLOBALS['strPrivDescReload']),
  61.         array('Shutdown_priv', 'SHUTDOWN', $GLOBALS['strPrivDescShutdown']),
  62.         array('Process_priv', 'PROCESS', $GLOBALS['strPrivDescProcess' . ((!empty($row) && isset($row['Super_priv'])) || (empty($row) && isset($GLOBALS['Super_priv'])) ? '4' : '3')]),
  63.         array('File_priv', 'FILE', $GLOBALS['strPrivDescFile']),
  64.         array('References_priv', 'REFERENCES', $GLOBALS['strPrivDescReferences']),
  65.         array('Index_priv', 'INDEX', $GLOBALS['strPrivDescIndex']),
  66.         array('Alter_priv', 'ALTER', $GLOBALS['strPrivDescAlter']),
  67.         array('Show_db_priv', 'SHOW DATABASES', $GLOBALS['strPrivDescShowDb']),
  68.         array('Super_priv', 'SUPER', $GLOBALS['strPrivDescSuper']),
  69.         array('Create_tmp_table_priv', 'CREATE TEMPORARY TABLES', $GLOBALS['strPrivDescCreateTmpTable']),
  70.         array('Lock_tables_priv', 'LOCK TABLES', $GLOBALS['strPrivDescLockTables']),
  71.         array('Execute_priv', 'EXECUTE', $GLOBALS['strPrivDescExecute']),
  72.         array('Repl_slave_priv', 'REPLICATION SLAVE', $GLOBALS['strPrivDescReplSlave']),
  73.         array('Repl_client_priv', 'REPLICATION CLIENT', $GLOBALS['strPrivDescReplClient'])
  74.     );
  75.     if (!empty($row) && isset($row['Table_priv'])) {
  76.         $sql_query = 'SHOW COLUMNS FROM `tables_priv` LIKE "Table_priv";';
  77.         $res = PMA_mysql_query($sql_query, $userlink) or PMA_mysqlDie(PMA_mysql_error($userlink), $sql_query);
  78.         unset($sql_query);
  79.         $row1 = PMA_mysql_fetch_array($res, MYSQL_ASSOC);
  80.         mysql_free_result($res);
  81.         $av_grants = explode ('\',\'' , substr($row1['Type'], 5, strlen($row1['Type']) - 7));
  82.         unset($row1);
  83.         $users_grants = explode(',', $row['Table_priv']);
  84.         foreach ($av_grants as $current_grant) {
  85.             $row[$current_grant . '_priv'] = in_array($current_grant, $users_grants) ? 'Y' : 'N';
  86.         }
  87.         unset($current_grant);
  88.         unset($av_grants);
  89.         unset($users_grants);
  90.     }
  91.     $privs = array();
  92.     $allPrivileges = TRUE;
  93.     foreach ($grants as $current_grant) {
  94.         if ((!empty($row) && isset($row[$current_grant[0]])) || (empty($row) && isset($GLOBALS[$current_grant[0]]))) {
  95.             if ((!empty($row) && $row[$current_grant[0]] == 'Y') || (empty($row) && ($GLOBALS[$current_grant[0]] == 'Y' || (is_array($GLOBALS[$current_grant[0]]) && count($GLOBALS[$current_grant[0]]) == $GLOBALS['column_count'] && empty($GLOBALS[$current_grant[0] . '_none']))))) {
  96.                 if ($enableHTML) {
  97.                     $privs[] = '<dfn title="' . $current_grant[2] . '">' . str_replace(' ', ' ', $current_grant[1]) . '</dfn>';
  98.                 } else {
  99.                     $privs[] = $current_grant[1];
  100.                 }
  101.             } else if (!empty($GLOBALS[$current_grant[0]]) && is_array($GLOBALS[$current_grant[0]]) && empty($GLOBALS[$current_grant[0] . '_none'])) {
  102.                 if ($enableHTML) {
  103.                     $priv_string = '<dfn title="' . $current_grant[2] . '">' . str_replace(' ', ' ', $current_grant[1]) . '</dfn>';
  104.                 } else {
  105.                     $priv_string = $current_grant[1];
  106.                 }
  107.                 $privs[] = $priv_string . ' (`' . join('`, `', $GLOBALS[$current_grant[0]]) . '`)';
  108.             } else {
  109.                 $allPrivileges = FALSE;
  110.             }
  111.         }
  112.     }
  113.     if (empty($privs)) {
  114.         if ($enableHTML) {
  115.             $privs[] = '<dfn title="' . $GLOBALS['strPrivDescUsage'] . '">USAGE</dfn>';
  116.         } else {
  117.             $privs[] = 'USAGE';
  118.         }
  119.     } else if ($allPrivileges && (!isset($GLOBALS['grant_count']) || count($privs) == $GLOBALS['grant_count'])) {
  120.         if ($enableHTML) {
  121.             $privs = array('<dfn title="' . $GLOBALS['strPrivDescAllPrivileges'] . '">ALL PRIVILEGES</dfn>');
  122.         } else {
  123.             $privs = array('ALL PRIVILEGES');
  124.         }
  125.     }
  126.     return $privs;
  127. } // end of the 'PMA_extractPrivInfo()' function
  128.  
  129. /**
  130.  * Displays the privileges form table
  131.  *
  132.  * @param   string     the database
  133.  * @param   string     the table
  134.  * @param   boolean    wheather to display the submit button or not
  135.  * @param   int        the indenting level of the code
  136.  *
  137.  * @global  array      the phpMyAdmin configuration
  138.  * @global  ressource  the database connection
  139.  *
  140.  * @return  void
  141.  */
  142. function PMA_displayPrivTable($db = '*', $table = '*', $submit = TRUE, $indent = 0)
  143. {
  144.     global $cfg, $userlink;
  145.  
  146.     if ($db == '*') {
  147.         $table = '*';
  148.     }
  149.     $spaces = '';
  150.     for ($i = 0; $i < $indent; $i++) {
  151.         $spaces .= '    ';
  152.     }
  153.     if (isset($GLOBALS['username'])) {
  154.         $username = $GLOBALS['username'];
  155.         $hostname = $GLOBALS['hostname'];
  156.         if ($db == '*') {
  157.             $sql_query = 'SELECT * FROM `user` WHERE `User` = "' . PMA_sqlAddslashes($username) . '" AND `Host` = "' . $hostname . '";';
  158.         } else if ($table == '*') {
  159.             $sql_query = 'SELECT * FROM `db` WHERE `User` = "' . PMA_sqlAddslashes($username) . '" AND `Host` = "' . $hostname . '" AND `Db` = "' . $db . '";';
  160.         } else {
  161.             $sql_query = 'SELECT `Table_priv` FROM `tables_priv` WHERE `User` = "' . PMA_sqlAddslashes($username) . '" AND `Host` = "' . $hostname . '" AND `Db` = "' . $db . '" AND `Table_name` = "' . $table . '";';
  162.         }
  163.         $res = PMA_mysql_query($sql_query, $userlink) or PMA_mysqlDie(PMA_mysql_error($userlink), $sql_query);
  164.         if ($res) {
  165.             $row = PMA_mysql_fetch_array($res, MYSQL_ASSOC);
  166.         }
  167.         @mysql_free_result($res);
  168.     }
  169.     if (empty($row)) {
  170.         if ($table == '*') {
  171.             if ($db == '*') {
  172.                 $sql_query = 'SHOW COLUMNS FROM `mysql`.`user`;';
  173.             } else if ($table == '*') {
  174.                 $sql_query = 'SHOW COLUMNS FROM `mysql`.`db`;';
  175.             }
  176.             $res = PMA_mysql_query($sql_query, $userlink)
  177.                 or PMA_mysqlDie(PMA_mysql_error($userlink), $sql_query);
  178.             while ($row1 = PMA_mysql_fetch_row($res)) {
  179.                 if (substr($row1[0], 0, 4) == 'max_') {
  180.                     $row[$row1[0]] = 0;
  181.                 } else {
  182.                     $row[$row1[0]] = 'N';
  183.                 }
  184.             }
  185.             mysql_free_result($res);
  186.         } else {
  187.             $row = array('Table_priv' => '');
  188.         }
  189.     }
  190.     if (isset($row['Table_priv'])) {
  191.         $sql_query = 'SHOW COLUMNS FROM `tables_priv` LIKE "Table_priv";';
  192.         $res = PMA_mysql_query($sql_query, $userlink) or PMA_mysqlDie(PMA_mysql_error($userlink), $sql_query);
  193.         unset($sql_query);
  194.         $row1 = PMA_mysql_fetch_array($res, MYSQL_ASSOC);
  195.         mysql_free_result($res);
  196.         $av_grants = explode ('\',\'' , substr($row1['Type'], strpos($row1['Type'], '(') + 2, strpos($row1['Type'], ')') - strpos($row1['Type'], '(') - 3));
  197.         unset($row1);
  198.         $users_grants = explode(',', $row['Table_priv']);
  199.         foreach ($av_grants as $current_grant) {
  200.             $row[$current_grant . '_priv'] = in_array($current_grant, $users_grants) ? 'Y' : 'N';
  201.         }
  202.         unset($row['Table_priv']);
  203.         unset($current_grant);
  204.         unset($av_grants);
  205.         unset($users_grants);
  206.         if ($res = PMA_mysql_query('SHOW COLUMNS FROM `' . $db . '`.`' . $table . '`;', $userlink)) {
  207.             $columns = array();
  208.             while ($row1 = PMA_mysql_fetch_row($res)) {
  209.                 $columns[$row1[0]] = array(
  210.                     'Select' => FALSE,
  211.                     'Insert' => FALSE,
  212.                     'Update' => FALSE,
  213.                     'References' => FALSE
  214.                 );
  215.             }
  216.             mysql_free_result($res);
  217.             unset($res);
  218.             unset($row1);
  219.         }
  220.     }
  221.     if (!empty($columns)) {
  222.         $sql_query = 'SELECT `Column_name`, `Column_priv` FROM `columns_priv` WHERE `User` = "' . PMA_sqlAddslashes($username) . '" AND `Host` = "' . $hostname . '" AND `Db` = "' . $db . '" AND `Table_name` = "' . $table . '";';
  223.         $res = PMA_mysql_query($sql_query, $userlink) or PMA_mysqlDie(PMA_mysql_error($userlink), $sql_query);
  224.         while ($row1 = PMA_mysql_fetch_row($res)) {
  225.             $row1[1] = explode(',', $row1[1]);
  226.             foreach ($row1[1] as $current) {
  227.                 $columns[$row1[0]][$current] = TRUE;
  228.             }
  229.         }
  230.         mysql_free_result($res);
  231.         unset($res);
  232.         unset($row1);
  233.         unset($current);
  234.         echo $spaces . '<input type="hidden" name="grant_count" value="' . count($row) . '" />' . "\n"
  235.            . $spaces . '<input type="hidden" name="column_count" value="' . count($columns) . '" />' . "\n"
  236.            . $spaces . '<table border="0">' . "\n"
  237.            . $spaces . '    <tr>' . "\n"
  238.            . $spaces . '        <th colspan="6"> ' . $GLOBALS['strTblPrivileges'] . ' </th>' . "\n"
  239.            . $spaces . '    </tr>' . "\n"
  240.            . $spaces . '    <tr>' . "\n"
  241.            . $spaces . '        <td bgcolor="' . $cfg['BgcolorTwo'] . '" colspan="6"><small><i>' . $GLOBALS['strEnglishPrivileges'] . '</i></small></td>' . "\n"
  242.            . $spaces . '    </tr>' . "\n"
  243.            . $spaces . '    <tr>' . "\n"
  244.            . $spaces . '        <td bgcolor="' . $cfg['BgcolorOne'] . '"> <tt><dfn title="' . $GLOBALS['strPrivDescSelect'] . '">SELECT</dfn></tt> </td>' . "\n"
  245.            . $spaces . '        <td bgcolor="' . $cfg['BgcolorOne'] . '"> <tt><dfn title="' . $GLOBALS['strPrivDescInsert'] . '">INSERT</dfn></tt> </td>' . "\n"
  246.            . $spaces . '        <td bgcolor="' . $cfg['BgcolorOne'] . '"> <tt><dfn title="' . $GLOBALS['strPrivDescUpdate'] . '">UPDATE</dfn></tt> </td>' . "\n"
  247.            . $spaces . '        <td bgcolor="' . $cfg['BgcolorOne'] . '"> <tt><dfn title="' . $GLOBALS['strPrivDescReferences'] . '">REFERENCES</dfn></tt> </td>' . "\n";
  248.         list($current_grant, $current_grant_value) = each($row);
  249.         while (in_array(substr($current_grant, 0, (strlen($current_grant) - 5)), array('Select', 'Insert', 'Update', 'References'))) {
  250.             list($current_grant, $current_grant_value) = each($row);
  251.         }
  252.         echo $spaces . '        <td bgcolor="' . $cfg['BgcolorTwo'] . '"><input type="checkbox" name="' . $current_grant . '" id="checkbox_' . $current_grant . '" value="Y" ' . ($current_grant_value == 'Y' ? 'checked="checked" ' : '') . 'title="' . (isset($GLOBALS['strPrivDesc' . substr($current_grant, 0, (strlen($current_grant) - 5))]) ? $GLOBALS['strPrivDesc' . substr($current_grant, 0, (strlen($current_grant) - 5))] : $GLOBALS['strPrivDesc' . substr($current_grant, 0, (strlen($current_grant) - 5)) . 'Tbl']) . '"/></td>' . "\n"
  253.            . $spaces . '        <td bgcolor="' . $cfg['BgcolorTwo'] . '"><label for="checkbox_' . $current_grant . '"><tt><dfn title="' . (isset($GLOBALS['strPrivDesc' . substr($current_grant, 0, (strlen($current_grant) - 5))]) ? $GLOBALS['strPrivDesc' . substr($current_grant, 0, (strlen($current_grant) - 5))] : $GLOBALS['strPrivDesc' . substr($current_grant, 0, (strlen($current_grant) - 5)) . 'Tbl']) . '">' . strtoupper(substr($current_grant, 0, strlen($current_grant) - 5)) . '</dfn></tt></label></td>' . "\n"
  254.            . $spaces . '    </tr>' . "\n"
  255.            . $spaces . '    <tr>' . "\n";
  256.         $rowspan = count($row) - 5;
  257.         echo $spaces . '        <td bgcolor="' . $cfg['BgcolorTwo'] . '" rowspan="' . $rowspan . '" valign="top">' . "\n"
  258.            . $spaces . '            <select name="Select_priv[]" multiple="multiple">' . "\n";
  259.         foreach ($columns as $current_column => $current_column_privileges) {
  260.             echo $spaces . '                <option value="' . htmlspecialchars($current_column) . '"';
  261.             if ($row['Select_priv'] == 'Y' || $current_column_privileges['Select']) {
  262.                 echo ' selected="selected"';
  263.             }
  264.             echo '>' . htmlspecialchars($current_column) . '</option>' . "\n";
  265.         }
  266.         echo $spaces . '            </select><br />' . "\n"
  267.            . $spaces . '            <i>' . $GLOBALS['strOr'] . '</i><br />' . "\n"
  268.            . $spaces . '            <input type="checkbox" name="Select_priv_none" id="checkbox_Select_priv_none" title="' . $GLOBALS['strNone'] . '" />' . "\n"
  269.            . $spaces . '            <label for="checkbox_Select_priv_none">' . $GLOBALS['strNone'] . '</label>' . "\n"
  270.            . $spaces . '        </td>' . "\n"
  271.            . $spaces . '        <td bgcolor="' . $cfg['BgcolorTwo'] . '" rowspan="' . $rowspan . '" valign="top">' . "\n"
  272.            . $spaces . '            <select name="Insert_priv[]" multiple="multiple">' . "\n";
  273.         foreach ($columns as $current_column => $current_column_privileges) {
  274.             echo $spaces . '                <option value="' . htmlspecialchars($current_column) . '"';
  275.             if ($row['Insert_priv'] == 'Y' || $current_column_privileges['Insert']) {
  276.                 echo ' selected="selected"';
  277.             }
  278.             echo '>' . htmlspecialchars($current_column) . '</option>' . "\n";
  279.         }
  280.         echo $spaces . '            </select><br />' . "\n"
  281.            . $spaces . '            <i>' . $GLOBALS['strOr'] . '</i><br />' . "\n"
  282.            . $spaces . '            <input type="checkbox" name="Insert_priv_none" id="checkbox_Insert_priv_none" title="' . $GLOBALS['strNone'] . '" />' . "\n"
  283.            . $spaces . '            <label for="checkbox_Insert_priv_none">' . $GLOBALS['strNone'] . '</label>' . "\n"
  284.            . $spaces . '        </td>' . "\n"
  285.            . $spaces . '        <td bgcolor="' . $cfg['BgcolorTwo'] . '" rowspan="' . $rowspan . '" valign="top">' . "\n"
  286.            . $spaces . '            <select name="Update_priv[]" multiple="multiple">' . "\n";
  287.         foreach ($columns as $current_column => $current_column_privileges) {
  288.             echo $spaces . '                <option value="' . htmlspecialchars($current_column) . '"';
  289.             if ($row['Update_priv'] == 'Y' || $current_column_privileges['Update']) {
  290.                 echo ' selected="selected"';
  291.             }
  292.             echo '>' . htmlspecialchars($current_column) . '</option>' . "\n";
  293.         }
  294.         echo $spaces . '            </select><br />' . "\n"
  295.            . $spaces . '            <i>' . $GLOBALS['strOr'] . '</i><br />' . "\n"
  296.            . $spaces . '            <input type="checkbox" name="Update_priv_none" id="checkbox_Update_priv_none" title="' . $GLOBALS['strNone'] . '" />' . "\n"
  297.            . $spaces . '            <label for="checkbox_Update_priv_none">' . $GLOBALS['strNone'] . '</label>' . "\n"
  298.            . $spaces . '        </td>' . "\n"
  299.            . $spaces . '        <td bgcolor="' . $cfg['BgcolorTwo'] . '" rowspan="' . $rowspan . '" valign="top">' . "\n"
  300.            . $spaces . '            <select name="References_priv[]" multiple="multiple">' . "\n";
  301.         foreach ($columns as $current_column => $current_column_privileges) {
  302.             echo $spaces . '                <option value="' . htmlspecialchars($current_column) . '"';
  303.             if ($row['References_priv'] == 'Y' || $current_column_privileges['References']) {
  304.                 echo ' selected="selected"';
  305.             }
  306.             echo '>' . htmlspecialchars($current_column) . '</option>' . "\n";
  307.         }
  308.         echo $spaces . '            </select><br />' . "\n"
  309.            . $spaces . '            <i>' . $GLOBALS['strOr'] . '</i><br />' . "\n"
  310.            . $spaces . '            <input type="checkbox" name="References_priv_none" id="checkbox_References_priv_none" title="' . $GLOBALS['strNone'] . '" />' . "\n"
  311.            . $spaces . '            <label for="checkbox_References_priv_none">' . $GLOBALS['strNone'] . '</label>' . "\n"
  312.            . $spaces . '        </td>' . "\n";
  313.         unset($rowspan);
  314.         list($current_grant, $current_grant_value) = each($row);
  315.         while (in_array(substr($current_grant, 0, (strlen($current_grant) - 5)), array('Select', 'Insert', 'Update', 'References'))) {
  316.             list($current_grant, $current_grant_value) = each($row);
  317.         }
  318.         echo $spaces . '        <td bgcolor="' . $cfg['BgcolorTwo'] . '"><input type="checkbox" name="' . $current_grant . '" id="checkbox_' . $current_grant . '" value="Y" ' . ($current_grant_value == 'Y' ? 'checked="checked" ' : '') . 'title="' . (isset($GLOBALS['strPrivDesc' . substr($current_grant, 0, (strlen($current_grant) - 5))]) ? $GLOBALS['strPrivDesc' . substr($current_grant, 0, (strlen($current_grant) - 5))] : $GLOBALS['strPrivDesc' . substr($current_grant, 0, (strlen($current_grant) - 5)) . 'Tbl']) . '"/></td>' . "\n"
  319.            . $spaces . '        <td bgcolor="' . $cfg['BgcolorTwo'] . '"><label for="checkbox_' . $current_grant . '"><tt><dfn title="' . (isset($GLOBALS['strPrivDesc' . substr($current_grant, 0, (strlen($current_grant) - 5))]) ? $GLOBALS['strPrivDesc' . substr($current_grant, 0, (strlen($current_grant) - 5))] : $GLOBALS['strPrivDesc' . substr($current_grant, 0, (strlen($current_grant) - 5)) . 'Tbl']) . '">' . strtoupper(substr($current_grant, 0, strlen($current_grant) - 5)) . '</dfn></tt></label></td>' . "\n"
  320.            . $spaces . '    </tr>' . "\n";
  321.         while (list($current_grant, $current_grant_value) = each($row)) {
  322.             if (in_array(substr($current_grant, 0, (strlen($current_grant) - 5)), array('Select', 'Insert', 'Update', 'References'))) {
  323.                 continue;
  324.             }
  325.             echo $spaces . '    <tr>' . "\n"
  326.                . $spaces . '        <td bgcolor="' . $cfg['BgcolorTwo'] . '"><input type="checkbox" name="' . $current_grant . '" id="checkbox_' . $current_grant . '" value="Y" ' . ($current_grant_value == 'Y' ? 'checked="checked" ' : '') . 'title="' . (isset($GLOBALS['strPrivDesc' . substr($current_grant, 0, (strlen($current_grant) - 5))]) ? $GLOBALS['strPrivDesc' . substr($current_grant, 0, (strlen($current_grant) - 5))] : $GLOBALS['strPrivDesc' . substr($current_grant, 0, (strlen($current_grant) - 5)) . 'Tbl']) . '"/></td>' . "\n"
  327.                . $spaces . '        <td bgcolor="' . $cfg['BgcolorTwo'] . '"><label for="checkbox_' . $current_grant . '"><tt><dfn title="' . (isset($GLOBALS['strPrivDesc' . substr($current_grant, 0, (strlen($current_grant) - 5))]) ? $GLOBALS['strPrivDesc' . substr($current_grant, 0, (strlen($current_grant) - 5))] : $GLOBALS['strPrivDesc' . substr($current_grant, 0, (strlen($current_grant) - 5)) . 'Tbl']) . '">' . strtoupper(substr($current_grant, 0, strlen($current_grant) - 5)) . '</dfn></tt></label></td>' . "\n"
  328.                . $spaces . '    </tr>' . "\n";
  329.         }
  330.     } else {
  331.         $privTable[0] = array(
  332.             array('Select', 'SELECT', $GLOBALS['strPrivDescSelect']),
  333.             array('Insert', 'INSERT', $GLOBALS['strPrivDescInsert']),
  334.             array('Update', 'UPDATE', $GLOBALS['strPrivDescUpdate']),
  335.             array('Delete', 'DELETE', $GLOBALS['strPrivDescDelete'])
  336.         );
  337.         if ($db == '*') {
  338.             $privTable[0][] = array('File', 'FILE', $GLOBALS['strPrivDescFile']);
  339.         }
  340.         $privTable[1] = array(
  341.             array('Create', 'CREATE', ($table == '*' ? $GLOBALS['strPrivDescCreateDb'] : $GLOBALS['strPrivDescCreateTbl'])),
  342.             array('Alter', 'ALTER', $GLOBALS['strPrivDescAlter']),
  343.             array('Index', 'INDEX', $GLOBALS['strPrivDescIndex']),
  344.             array('Drop', 'DROP', ($table == '*' ? $GLOBALS['strPrivDescDropDb'] : $GLOBALS['strPrivDescDropTbl']))
  345.         );
  346.         if (isset($row['Create_tmp_table_priv'])) {
  347.             $privTable[1][] = array('Create_tmp_table', 'CREATE TEMPORARY TABLES', $GLOBALS['strPrivDescCreateTmpTable']);
  348.         }
  349.         $privTable[2] = array();
  350.         if (isset($row['Grant_priv'])) {
  351.             $privTable[2][] = array('Grant', 'GRANT', $GLOBALS['strPrivDescGrant']);
  352.         }
  353.         if ($db == '*') {
  354.             if (isset($row['Super_priv'])) {
  355.                 $privTable[2][] = array('Super', 'SUPER', $GLOBALS['strPrivDescSuper']);
  356.                 $privTable[2][] = array('Process', 'PROCESS', $GLOBALS['strPrivDescProcess4']);
  357.             } else {
  358.                 $privTable[2][] = array('Process', 'PROCESS', $GLOBALS['strPrivDescProcess3']);
  359.             }
  360.             $privTable[2][] = array('Reload', 'RELOAD', $GLOBALS['strPrivDescReload']);
  361.             $privTable[2][] = array('Shutdown', 'SHUTDOWN', $GLOBALS['strPrivDescShutdown']);
  362.             if (isset($row['Show_db_priv'])) {
  363.                 $privTable[2][] = array('Show_db', 'SHOW DATABASES', $GLOBALS['strPrivDescShowDb']);
  364.             }
  365.         }
  366.         if (isset($row['Lock_tables_priv'])) {
  367.             $privTable[2][] = array('Lock_tables', 'LOCK TABLES', $GLOBALS['strPrivDescLockTables']);
  368.         }
  369.         $privTable[2][] = array('References', 'REFERENCES', $GLOBALS['strPrivDescReferences']);
  370.         if ($db == '*') {
  371.             if (isset($row['Execute_priv'])) {
  372.                 $privTable[2][] = array('Execute', 'EXECUTE', $GLOBALS['strPrivDescExecute']);
  373.             }
  374.             if (isset($row['Repl_client_priv'])) {
  375.                 $privTable[2][] = array('Repl_client', 'REPLICATION CLIENT', $GLOBALS['strPrivDescReplClient']);
  376.             }
  377.             if (isset($row['Repl_slave_priv'])) {
  378.                 $privTable[2][] = array('Repl_slave', 'REPLICATION SLAVE', $GLOBALS['strPrivDescReplSlave']);
  379.             }
  380.         }
  381.         echo $spaces . '<input type="hidden" name="grant_count" value="' . (count($privTable[0]) + count($privTable[1]) + count($privTable[2]) - (isset($row['Grant_priv']) ? 1 : 0)) . '" />' . "\n"
  382.            . $spaces . '<table border="0">' . "\n"
  383.            . $spaces . '    <tr>' . "\n"
  384.            . $spaces . '        <th colspan="6"> ' . ($db == '*' ? $GLOBALS['strGlobalPrivileges'] : ($table == '*' ? $GLOBALS['strDbPrivileges'] : $GLOBALS['strTblPrivileges'])) . ' </th>' . "\n"
  385.            . $spaces . '    </tr>' . "\n"
  386.            . $spaces . '    <tr>' . "\n"
  387.            . $spaces . '        <td bgcolor="' . $cfg['BgcolorTwo'] . '" colspan="6"><small><i>' . $GLOBALS['strEnglishPrivileges'] . '</i></small></td>' . "\n"
  388.            . $spaces . '    </tr>' . "\n"
  389.            . $spaces . '    <tr>' . "\n"
  390.            . $spaces . '        <td bgcolor="' . $cfg['BgcolorOne'] . '" colspan="2"> <b><i>' . $GLOBALS['strData'] . '</i></b> </td>' . "\n"
  391.            . $spaces . '        <td bgcolor="' . $cfg['BgcolorOne'] . '" colspan="2"> <b><i>' . $GLOBALS['strStructure'] . '</i></b> </td>' . "\n"
  392.            . $spaces . '        <td bgcolor="' . $cfg['BgcolorOne'] . '" colspan="2"> <b><i>' . $GLOBALS['strAdministration'] . '</i></b> </td>' . "\n"
  393.            . $spaces . '    </tr>' . "\n";
  394.         $limitTable = FALSE;
  395.         for ($i = 0; isset($privTable[0][$i]) || isset($privTable[1][$i]) || isset($privTable[2][$i]); $i++) {
  396.             echo $spaces . '    <tr>' . "\n";
  397.             for ($j = 0; $j < 3; $j++) {
  398.                 if (isset($privTable[$j][$i])) {
  399.                     echo $spaces . '        <td bgcolor="' . $cfg['BgcolorTwo'] . '"><input type="checkbox" name="' . $privTable[$j][$i][0] . '_priv" id="checkbox_' . $privTable[$j][$i][0] . '_priv" value="Y" ' . ($row[$privTable[$j][$i][0] . '_priv'] == 'Y' ? 'checked="checked" ' : '') . 'title="' . $privTable[$j][$i][2] . '"/></td>' . "\n"
  400.                        . $spaces . '        <td bgcolor="' . $cfg['BgcolorTwo'] . '"><label for="checkbox_' . $privTable[$j][$i][0] . '_priv"><tt><dfn title="' . $privTable[$j][$i][2] . '">' . $privTable[$j][$i][1] . '</dfn></tt></label></td>' . "\n";
  401.                 } else if ($db == '*' && !isset($privTable[0][$i]) && !isset($privTable[1][$i])
  402.                     && isset($row['max_questions']) && isset($row['max_updates']) && isset($row['max_connections'])
  403.                     && !$limitTable) {
  404.                     echo $spaces . '        <td colspan="4" rowspan="' . (count($privTable[2]) - $i) . '">' . "\n"
  405.                        . $spaces . '            <table border="0">' . "\n"
  406.                        . $spaces . '                <tr>' . "\n"
  407.                        . $spaces . '                    <th colspan="2"> ' . $GLOBALS['strResourceLimits'] . ' </th>' . "\n"
  408.                        . $spaces . '                </tr>' . "\n"
  409.                        . $spaces . '                <tr>' . "\n"
  410.                        . $spaces . '                    <td bgcolor="' . $cfg['BgcolorTwo'] . '" colspan="2"><small><i>' . $GLOBALS['strZeroRemovesTheLimit'] . '</i></small></td>' . "\n"
  411.                        . $spaces . '                </tr>' . "\n"
  412.                        . $spaces . '                <tr>' . "\n"
  413.                        . $spaces . '                    <td bgcolor="' . $cfg['BgcolorTwo'] . '"><label for="text_max_questions"><tt><dfn title="' . $GLOBALS['strPrivDescMaxQuestions'] . '">MAX QUERIES PER HOUR</dfn></tt></label></td>' . "\n"
  414.                        . $spaces . '                    <td bgcolor="' . $cfg['BgcolorTwo'] . '"><input type="text" class="textfield" name="max_questions" id="text_max_questions" value="' . $row['max_questions'] . '" size="11" maxlength="11" title="' . $GLOBALS['strPrivDescMaxQuestions'] . '" /></td>' . "\n"
  415.                        . $spaces . '                </tr>' . "\n"
  416.                        . $spaces . '                <tr>' . "\n"
  417.                        . $spaces . '                    <td bgcolor="' . $cfg['BgcolorTwo'] . '"><label for="text_max_updates"><tt><dfn title="' . $GLOBALS['strPrivDescMaxUpdates'] . '">MAX UPDATES PER HOUR</dfn></tt></label></td>' . "\n"
  418.                        . $spaces . '                    <td bgcolor="' . $cfg['BgcolorTwo'] . '"><input type="text" class="textfield" name="max_updates" id="text_max_updates" value="' . $row['max_updates'] . '" size="11" maxlength="11" title="' . $GLOBALS['strPrivDescMaxUpdates'] . '" /></td>' . "\n"
  419.                        . $spaces . '                </tr>' . "\n"
  420.                        . $spaces . '                <tr>' . "\n"
  421.                        . $spaces . '                    <td bgcolor="' . $cfg['BgcolorTwo'] . '"><label for="text_max_connections"><tt><dfn title="' . $GLOBALS['strPrivDescMaxConnections'] . '">MAX CONNECTIONS PER HOUR</dfn></tt></label></td>' . "\n"
  422.                        . $spaces . '                    <td bgcolor="' . $cfg['BgcolorTwo'] . '"><input type="text" class="textfield" name="max_connections" id="text_max_connections" value="' . $row['max_connections'] . '" size="11" maxlength="11" title="' . $GLOBALS['strPrivDescMaxConnections'] . '" /></td>' . "\n"
  423.                        . $spaces . '                </tr>' . "\n"
  424.                        . $spaces . '            </table>' . "\n"
  425.                        . $spaces . '        </td>' . "\n";
  426.                     $limitTable = TRUE;
  427.                 } else if (!$limitTable) {
  428.                     echo $spaces . '        <td bgcolor="' . $cfg['BgcolorTwo'] . '" colspan="2"> </td>' . "\n";
  429.                 }
  430.             }
  431.         }
  432.         echo $spaces . '    </tr>' . "\n";
  433.     }
  434.     if ($submit) {
  435.         echo $spaces . '    <tr>' . "\n"
  436.            . $spaces . '        <td colspan="6" align="center">' . "\n"
  437.            . $spaces . '            <input type="submit" name="update_privs" value="' . $GLOBALS['strGo'] . '" />' . "\n"
  438.            . $spaces . '        </td>' . "\n"
  439.            . $spaces . '    </tr>' . "\n";
  440.     }
  441.     echo $spaces . '</table>' . "\n";
  442. } // end of the 'PMA_displayPrivTable()' function
  443.  
  444.  
  445. /**
  446.  * Displays the fields used by the "new user" form as well as the
  447.  * "change login information / copy user" form.
  448.  *
  449.  * @param   string     are we creating a new user or are we just changing one?
  450.  *                     (allowed values: 'new', 'change')
  451.  * @param   int        the indenting level of the code
  452.  *
  453.  * @global  array      the phpMyAdmin configuration
  454.  * @global  ressource  the database connection
  455.  *
  456.  * @return  void
  457.  */
  458. function PMA_displayLoginInformationFields($mode = 'new', $indent = 0)
  459. {
  460.     global $cfg, $userlink;
  461.     $spaces = '';
  462.     for ($i = 0; $i < $indent; $i++) {
  463.         $spaces .= '    ';
  464.     }
  465.     echo $spaces . '<tr>' . "\n"
  466.        . $spaces . '    <td bgcolor="' . $cfg['BgcolorTwo'] . '">' . "\n"
  467.        . $spaces . '        <label for="select_pred_username">' . "\n"
  468.        . $spaces . '            ' . $GLOBALS['strUserName'] . ':' . "\n"
  469.        . $spaces . '        </label>' . "\n"
  470.        . $spaces . '    </td>' . "\n"
  471.        . $spaces . '    <td bgcolor="' . $cfg['BgcolorTwo'] . '">' . "\n"
  472.        . $spaces . '        <select name="pred_username" id="select_pred_username" title="' . $GLOBALS['strUserName'] . '"' . "\n"
  473.        . $spaces . '            onchange="if (this.value == \'any\') { username.value = \'\'; } else if (this.value == \'userdefined\') { username.focus(); username.select(); }">' . "\n"
  474.        . $spaces . '            <option value="any"' . ((isset($GLOBALS['pred_username']) && $GLOBALS['pred_username'] == 'any') ? ' selected="selected"' : '') . '>' . $GLOBALS['strAnyUser'] . '</option>' . "\n"
  475.        . $spaces . '            <option value="userdefined"' . ((!isset($GLOBALS['pred_username']) || $GLOBALS['pred_username'] == 'userdefined') ? ' selected="selected"' : '') . '>' . $GLOBALS['strUseTextField'] . ':</option>' . "\n"
  476.        . $spaces . '        </select>' . "\n"
  477.        . $spaces . '    </td>' . "\n"
  478.        . $spaces . '    <td bgcolor="' . $cfg['BgcolorTwo'] . '">' . "\n"
  479.        . $spaces . '        <input type="text" class="textfield" name="username" class="textfield" title="' . $GLOBALS['strUserName'] . '"' . (empty($GLOBALS['username']) ? '' : ' value="' . (isset($GLOBALS['new_username']) ? $GLOBALS['new_username'] : $GLOBALS['username']) . '"') . ' onchange="pred_username.value = \'userdefined\';" />' . "\n"
  480.        . $spaces . '    </td>' . "\n"
  481.        . $spaces . '</tr>' . "\n"
  482.        . $spaces . '<tr>' . "\n"
  483.        . $spaces . '    <td bgcolor="' . $cfg['BgcolorTwo'] . '">' . "\n"
  484.        . $spaces . '        <label for="select_pred_hostname">' . "\n"
  485.        . $spaces . '            ' . $GLOBALS['strHost'] . ':' . "\n"
  486.        . $spaces . '        </label>' . "\n"
  487.        . $spaces . '    </td>' . "\n"
  488.        . $spaces . '    <td bgcolor="' . $cfg['BgcolorTwo'] . '">' . "\n"
  489.        . $spaces . '        <select name="pred_hostname" id="select_pred_hostname" title="' . $GLOBALS['strHost'] . '"' . "\n";
  490.     $res = PMA_mysql_query('SELECT USER();', $userlink);
  491.     $row = @PMA_mysql_fetch_row($res);
  492.     @mysql_free_result($res);
  493.     unset($res);
  494.     if (!empty($row[0])) {
  495.         $thishost = str_replace("'", '', substr($row[0], (strrpos($row[0], '@') + 1)));
  496.         if ($thishost == 'localhost' || $thishost == '127.0.0.1') {
  497.             unset($thishost);
  498.         }
  499.     }
  500.     echo $spaces . '            onchange="if (this.value == \'any\') { hostname.value = \'%\'; } else if (this.value == \'localhost\') { hostname.value = \'localhost\'; } '
  501.        . (empty($thishost) ? '' : 'else if (this.value == \'thishost\') { hostname.value = \'' . addslashes(htmlspecialchars($thishost)) . '\'; } ')
  502.        . 'else if (this.value == \'hosttable\') { hostname.value = \'\'; } else if (this.value == \'userdefined\') { hostname.focus(); hostname.select(); }">' . "\n";
  503.     unset($row);
  504.     echo $spaces . '            <option value="any"' . ((isset($GLOBALS['pred_hostname']) && $GLOBALS['pred_hostname'] == 'any') ? ' selected="selected"' : '') . '>' . $GLOBALS['strAnyHost'] . '</option>' . "\n"
  505.        . $spaces . '            <option value="localhost"' . ((isset($GLOBALS['pred_hostname']) && $GLOBALS['pred_hostname'] == 'localhost') ? ' selected="selected"' : '') . '>' . $GLOBALS['strLocalhost'] . '</option>' . "\n";
  506.     if (!empty($thishost)) {
  507.         echo $spaces . '            <option value="thishost"' . ((isset($GLOBALS['pred_hostname']) && $GLOBALS['pred_hostname'] == 'thishost') ? ' selected="selected"' : '') . '>' . $GLOBALS['strThisHost'] . '</option>' . "\n";
  508.     }
  509.     unset($thishost);
  510.     echo $spaces . '            <option value="hosttable"' . ((isset($GLOBALS['pred_hostname']) && $GLOBALS['pred_hostname'] == 'hosttable') ? ' selected="selected"' : '') . '>' . $GLOBALS['strUseHostTable'] . '</option>' . "\n"
  511.        . $spaces . '            <option value="userdefined"' . ((isset($GLOBALS['pred_hostname']) && $GLOBALS['pred_hostname'] == 'userdefined') ? ' selected="selected"' : '') . '>' . $GLOBALS['strUseTextField'] . ':</option>' . "\n"
  512.        . $spaces . '        </select>' . "\n"
  513.        . $spaces . '    </td>' . "\n"
  514.        . $spaces . '    <td bgcolor="' . $cfg['BgcolorTwo'] . '">' . "\n"
  515.        . $spaces . '        <input type="text" class="textfield" name="hostname" value="' . ( isset($GLOBALS['hostname']) ? $GLOBALS['hostname'] : '' ) . '" class="textfield" title="' . $GLOBALS['strHost'] . '" onchange="pred_hostname.value = \'userdefined\';" />' . "\n"
  516.        . $spaces . '    </td>' . "\n"
  517.        . $spaces . '</tr>' . "\n"
  518.        . $spaces . '<tr>' . "\n"
  519.        . $spaces . '    <td bgcolor="' . $cfg['BgcolorTwo'] . '">' . "\n"
  520.        . $spaces . '        <label for="select_pred_password">' . "\n"
  521.        . $spaces . '            ' . $GLOBALS['strPassword'] . ':' . "\n"
  522.        . $spaces . '        </label>' . "\n"
  523.        . $spaces . '    </td>' . "\n"
  524.        . $spaces . '    <td bgcolor="' . $cfg['BgcolorTwo'] . '">' . "\n"
  525.        . $spaces . '        <select name="pred_password" id="select_pred_password" title="' . $GLOBALS['strPassword'] . '"' . "\n"
  526.        . $spaces . '            onchange="if (this.value == \'none\') { pma_pw.value = \'\'; pma_pw2.value = \'\'; } else if (this.value == \'userdefined\') { pma_pw.focus(); pma_pw.select(); }">' . "\n"
  527.        . ($mode == 'change' ? $spaces . '            <option value="keep" selected="selected">' . $GLOBALS['strKeepPass'] . '</option>' . "\n" : '')
  528.        . $spaces . '            <option value="none">' . $GLOBALS['strNoPassword'] . '</option>' . "\n"
  529.        . $spaces . '            <option value="userdefined"' . ($mode == 'change' ? '' : ' selected="selected"') . '>' . $GLOBALS['strUseTextField'] . ':</option>' . "\n"
  530.        . $spaces . '        </select>' . "\n"
  531.        . $spaces . '    </td>' . "\n"
  532.        . $spaces . '    <td bgcolor="' . $cfg['BgcolorTwo'] . '">' . "\n"
  533.        . $spaces . '        <input type="password" name="pma_pw" class="textfield" title="' . $GLOBALS['strPassword'] . '" onchange="pred_password.value = \'userdefined\';" />' . "\n"
  534.        . $spaces . '    </td>' . "\n"
  535.        . $spaces . '</tr>' . "\n"
  536.        . $spaces . '<tr>' . "\n"
  537.        . $spaces . '    <td bgcolor="' . $cfg['BgcolorTwo'] . '">' . "\n"
  538.        . $spaces . '        <label for="text_pma_pw2">' . "\n"
  539.        . $spaces . '            ' . $GLOBALS['strReType'] . ':' . "\n"
  540.        . $spaces . '        </label>' . "\n"
  541.        . $spaces . '    </td>' . "\n"
  542.        . $spaces . '    <td bgcolor="' . $cfg['BgcolorTwo'] . '"> </td>' . "\n"
  543.        . $spaces . '    <td bgcolor="' . $cfg['BgcolorTwo'] . '">' . "\n"
  544.        . $spaces . '        <input type="password" name="pma_pw2" id="text_pma_pw2" class="textfield" title="' . $GLOBALS['strReType'] . '" onchange="pred_password.value = \'userdefined\';" />' . "\n"
  545.        . $spaces . '    </td>' . "\n"
  546.        . $spaces . '</tr>' . "\n";
  547. } // end of the 'PMA_displayUserAndHostFields()' function
  548.  
  549.  
  550. /**
  551.  * Changes / copies a user, part I
  552.  */
  553. if (!empty($change_copy)) {
  554.     $local_query = 'SELECT * FROM `mysql`.`user` WHERE `User` = "' . PMA_sqlAddslashes($old_username) . '" AND `Host` = "' . $old_hostname . '";';
  555.     $res = PMA_mysql_query($local_query, $userlink) or PMA_mysqlDie(PMA_mysql_error($userlink), $local_query);
  556.     if (!$res) {
  557.         $message = $strNoUsersFound;
  558.         unset($change_copy);
  559.     } else {
  560.         $row = PMA_mysql_fetch_array($res, MYSQL_ASSOC);
  561.         extract($row, EXTR_OVERWRITE);
  562.         // Recent MySQL versions have the field "Password" in mysql.user,
  563.         // so the previous extract creates $Password but this script
  564.         // uses $password
  565.         if (!isset($password) && isset($Password)) {
  566.             $password=$Password;
  567.         }
  568.         mysql_free_result($res);
  569.         $queries = array();
  570.     }
  571. }
  572.  
  573.  
  574. /**
  575.  * Adds a user
  576.  *   (Changes / copies a user, part II)
  577.  */
  578. if (!empty($adduser_submit) || !empty($change_copy)) {
  579.     unset($sql_query);
  580.     if ($pred_username == 'any') {
  581.         $username = '';
  582.     }
  583.     switch ($pred_hostname) {
  584.         case 'any':
  585.             $hostname = '%';
  586.             break;
  587.         case 'localhost':
  588.             $hostname = 'localhost';
  589.             break;
  590.         case 'hosttable':
  591.             $hostname = '';
  592.             break;
  593.         case 'thishost':
  594.             $res = PMA_mysql_query('SELECT USER();', $userlink) or PMA_mysqlDie(PMA_mysql_error($userlink), 'SELECT USER();');
  595.             $row = PMA_mysql_fetch_row($res);
  596.             mysql_free_result($res);
  597.             unset($res);
  598.             $hostname = substr($row[0], (strrpos($row[0], '@') + 1));
  599.             unset($row);
  600.             break;
  601.     }
  602.     $local_query = 'SELECT "foo" FROM `user` WHERE `User` = "' . PMA_sqlAddslashes($username) . '" AND `Host` = "' . $hostname . '";';
  603.     $res = PMA_mysql_query($local_query, $userlink) or PMA_mysqlDie(PMA_mysql_error($userlink), $local_query);
  604.     unset($local_query);
  605.     if (mysql_affected_rows($userlink) == 1) {
  606.         $message = sprintf($strUserAlreadyExists, '<i>\'' . $username . '\'@\'' . $hostname . '\'</i>');
  607.         $adduser = 1;
  608.     } else {
  609.         $real_sql_query = 'GRANT ' . join(', ', PMA_extractPrivInfo()) . ' ON *.* TO "' . PMA_sqlAddslashes($username) . '"@"' . $hostname . '"';
  610.         if ($pred_password != 'none' && $pred_password != 'keep') {
  611.             $pma_pw_hidden = '';
  612.             for ($i = 0; $i < strlen($pma_pw); $i++) {
  613.                 $pma_pw_hidden .= '*';
  614.             }
  615.             $sql_query = $real_sql_query . ' IDENTIFIED BY "' . $pma_pw_hidden . '"';
  616.             $real_sql_query .= ' IDENTIFIED BY "' . $pma_pw . '"';
  617.         } else {
  618.             if ($pred_password == 'keep' && !empty($password)) {
  619.                 $real_sql_query .= ' IDENTIFIED BY PASSWORD "' . $password . '"';
  620.             }
  621.             $sql_query = $real_sql_query;
  622.         }
  623.         if ((isset($Grant_priv) && $Grant_priv == 'Y') || (PMA_MYSQL_INT_VERSION >= 40002 && (isset($max_questions) || isset($max_connections) || isset($max_updates)))) {
  624.             $real_sql_query .= 'WITH';
  625.             $sql_query .= 'WITH';
  626.             if (isset($Grant_priv) && $Grant_priv == 'Y') {
  627.                 $real_sql_query .= ' GRANT OPTION';
  628.                 $sql_query .= ' GRANT OPTION';
  629.             }
  630.             if (PMA_MYSQL_INT_VERSION >= 40002) {
  631.                 if (isset($max_questions)) {
  632.                     $real_sql_query .= ' MAX_QUERIES_PER_HOUR ' . (int)$max_questions;
  633.                     $sql_query .= ' MAX_QUERIES_PER_HOUR ' . (int)$max_questions;
  634.                 }
  635.                 if (isset($max_connections)) {
  636.                     $real_sql_query .= ' MAX_CONNECTIONS_PER_HOUR ' . (int)$max_connections;
  637.                     $sql_query .= ' MAX_CONNECTIONS_PER_HOUR ' . (int)$max_connections;
  638.                 }
  639.                 if (isset($max_updates)) {
  640.                     $real_sql_query .= ' MAX_UPDATES_PER_HOUR ' . (int)$max_updates;
  641.                     $sql_query .= ' MAX_UPDATES_PER_HOUR ' . (int)$max_updates;
  642.                 }
  643.             }
  644.         }
  645.         $real_sql_query .= ';';
  646.         $sql_query .= ';';
  647.         if (empty($change_copy)) {
  648.             PMA_mysql_query($real_sql_query, $userlink) or PMA_mysqlDie(PMA_mysql_error($userlink), $sql_query);
  649.             $message = $strAddUserMessage;
  650.         } else {
  651.             $queries[]             = $real_sql_query;
  652.             // we put the query containing the hidden password in
  653.             // $queries_for_display, at the same position occupied
  654.             // by the real query in $queries
  655.             $tmp_count = count($queries);
  656.             $queries_for_display[$tmp_count - 1] = $sql_query;
  657.         }
  658.         unset($real_sql_query);
  659.         mysql_free_result($res);
  660.         unset($res);
  661.     }
  662. }
  663.  
  664.  
  665. /**
  666.  * Changes / copies a user, part III
  667.  */
  668. if (!empty($change_copy)) {
  669.     $local_query = 'SELECT * FROM `mysql`.`db` WHERE `User` = "' . PMA_sqlAddslashes($old_username) . '" AND `Host` = "' . $old_hostname . '";';
  670.     $res = PMA_mysql_query($local_query, $userlink) or PMA_mysqlDie(PMA_mysql_error($userlink), $local_query);
  671.     while ($row = PMA_mysql_fetch_array($res, MYSQL_ASSOC)) {
  672.         $queries[] = 'GRANT ' . join(', ', PMA_extractPrivInfo($row)) . ' ON `' . $row['Db'] . '`.* TO "' . PMA_sqlAddslashes($username) . '"@"' . $hostname . '"' . ($row['Grant_priv'] == 'Y' ? ' WITH GRANT OPTION' : '') . ';';
  673.     }
  674.     mysql_free_result($res);
  675.     $local_query = 'SELECT `Db`, `Table_name`, `Table_priv` FROM `mysql`.`tables_priv` WHERE `User` = "' . PMA_sqlAddslashes($old_username) . '" AND `Host` = "' . $old_hostname . '";';
  676.     $res = PMA_mysql_query($local_query, $userlink) or PMA_mysqlDie(PMA_mysql_error($userlink), $local_query);
  677.     while ($row = PMA_mysql_fetch_array($res, MYSQL_ASSOC)) {
  678.         $local_query = 'SELECT `Column_name`, `Column_priv` FROM `mysql`.`columns_priv` WHERE `User` = "' . PMA_sqlAddslashes($old_username) . '" AND `Host` = "' . $old_hostname . '" AND `Db` = "' . $row['Db'] . '" AND `Table_name` = "' . $row['Table_name'] . '";';
  679.         $res2 = PMA_mysql_query($local_query, $userlink) or PMA_mysqlDie(PMA_mysql_error($userlink), $local_query);
  680.         $tmp_privs1 = PMA_extractPrivInfo($row);
  681.         $tmp_privs2 = array(
  682.             'Select' => array(),
  683.             'Insert' => array(),
  684.             'Update' => array(),
  685.             'References' => array()
  686.         );
  687.         while ($row2 = PMA_mysql_fetch_array($res2, MYSQL_ASSOC)) {
  688.             $tmp_array = explode(',', $row2['Column_priv']);
  689.             if (in_array('Select', $tmp_array)) {
  690.                 $tmp_privs2['Select'][] = $row2['Column_name'];
  691.             }
  692.             if (in_array('Insert', $tmp_array)) {
  693.                 $tmp_privs2['Insert'][] = $row2['Column_name'];
  694.             }
  695.             if (in_array('Update', $tmp_array)) {
  696.                 $tmp_privs2['Update'][] = $row2['Column_name'];
  697.             }
  698.             if (in_array('References', $tmp_array)) {
  699.                 $tmp_privs2['References'][] = $row2['Column_name'];
  700.             }
  701.             unset($tmp_array);
  702.         }
  703.         if (count($tmp_privs2['Select']) > 0 && !in_array('SELECT', $tmp_privs1)) {
  704.             $tmp_privs1[] = 'SELECT (`' . join('`, `', $tmp_privs2['Select']) . '`)';
  705.         }
  706.         if (count($tmp_privs2['Insert']) > 0 && !in_array('INSERT', $tmp_privs1)) {
  707.             $tmp_privs1[] = 'INSERT (`' . join(', ', $tmp_privs2['Insert']) . '`)';
  708.         }
  709.         if (count($tmp_privs2['Update']) > 0 && !in_array('UPDATE', $tmp_privs1)) {
  710.             $tmp_privs1[] = 'UPDATE (`' . join(', ', $tmp_privs2['Update']) . '`)';
  711.         }
  712.         if (count($tmp_privs2['References']) > 0 && !in_array('REFERENCES', $tmp_privs1)) {
  713.             $tmp_privs1[] = 'REFERENCES (`' . join(', ', $tmp_privs2['References']) . '`)';
  714.         }
  715.         unset($tmp_privs2);
  716.         $queries[] = 'GRANT ' . join(', ', $tmp_privs1) . ' ON `' . $row['Db'] . '`.`' . $row['Table_name'] . '` TO "' . PMA_sqlAddslashes($username) . '"@"' . $hostname . '"' . (in_array('Grant', explode(',', $row['Table_priv'])) ? ' WITH GRANT OPTION' : '') . ';';
  717.     }
  718. }
  719.  
  720.  
  721. /**
  722.  * Updates privileges
  723.  */
  724. if (!empty($update_privs)) {
  725.     $db_and_table = empty($dbname) ? '*.*' : PMA_backquote($dbname) . '.' . (empty($tablename) ? '*' : PMA_backquote($tablename));
  726.     $sql_query0 = 'REVOKE ALL PRIVILEGES ON ' . $db_and_table . ' FROM "' . PMA_sqlAddslashes($username) . '"@"' . $hostname . '";';
  727.     if (!isset($Grant_priv) || $Grant_priv != 'Y') {
  728.         $sql_query1 = 'REVOKE GRANT OPTION ON ' . $db_and_table . ' FROM "' . PMA_sqlAddslashes($username) . '"@"' . $hostname . '";';
  729.     }
  730.     $sql_query2 = 'GRANT ' . join(', ', PMA_extractPrivInfo()) . ' ON ' . $db_and_table . ' TO "' . PMA_sqlAddslashes($username) . '"@"' . $hostname . '"';
  731.     if ((isset($Grant_priv) && $Grant_priv == 'Y') || (empty($dbname) && PMA_MYSQL_INT_VERSION >= 40002 && (isset($max_questions) || isset($max_connections) || isset($max_updates)))) {
  732.         $sql_query2 .= 'WITH';
  733.         if (isset($Grant_priv) && $Grant_priv == 'Y') {
  734.             $sql_query2 .= ' GRANT OPTION';
  735.         }
  736.         if (PMA_MYSQL_INT_VERSION >= 40002) {
  737.             if (isset($max_questions)) {
  738.                 $sql_query2 .= ' MAX_QUERIES_PER_HOUR ' . (int)$max_questions;
  739.             }
  740.             if (isset($max_connections)) {
  741.                 $sql_query2 .= ' MAX_CONNECTIONS_PER_HOUR ' . (int)$max_connections;
  742.             }
  743.             if (isset($max_updates)) {
  744.                 $sql_query2 .= ' MAX_UPDATES_PER_HOUR ' . (int)$max_updates;
  745.             }
  746.         }
  747.     }
  748.     $sql_query2 .= ';';
  749.     PMA_mysql_query($sql_query0, $userlink); // this query may fail, but this does not matter :o)
  750.     if (isset($sql_query1)) {
  751.         PMA_mysql_query($sql_query1, $userlink); // this one may fail, too...
  752.     }
  753.     PMA_mysql_query($sql_query2, $userlink) or PMA_mysqlDie(PMA_mysql_error($userlink), $sql_query2);
  754.     $sql_query = $sql_query0 . ' ' . (isset($sql_query1) ? $sql_query1 . ' ' : '') . $sql_query2;
  755.     $message = sprintf($strUpdatePrivMessage, '\'' . $username . '\'@\'' . $hostname . '\'');
  756. }
  757.  
  758.  
  759. /**
  760.  * Revokes Privileges
  761.  */
  762. if (!empty($revokeall)) {
  763.     $db_and_table = PMA_backquote($dbname) . '.' . (empty($tablename) ? '*' : PMA_backquote($tablename));
  764.     $sql_query0 = 'REVOKE ALL PRIVILEGES ON ' . $db_and_table . ' FROM "' . $username . '"@"' . $hostname . '";';
  765.     $sql_query1 = 'REVOKE GRANT OPTION ON ' . $db_and_table . ' FROM "' . $username . '"@"' . $hostname . '";';
  766.     PMA_mysql_query($sql_query0, $userlink) or PMA_mysqlDie(PMA_mysql_error($userlink), $sql_query0);
  767.     PMA_mysql_query($sql_query1, $userlink); // this one may fail, too...
  768.     $sql_query = $sql_query0 . ' ' . $sql_query1;
  769.     $message = sprintf($strRevokeMessage, '\'' . $username . '\'@\'' . $hostname . '\'');
  770.     if (empty($tablename)) {
  771.         unset($dbname);
  772.     } else {
  773.         unset($tablename);
  774.     }
  775. }
  776.  
  777.  
  778. /**
  779.  * Updates the password
  780.  */
  781. if (!empty($change_pw)) {
  782.     if ($nopass == 1) {
  783.         $sql_query = 'SET PASSWORD FOR "' . $username . '"@"' . $hostname . '" = ""';
  784.         PMA_mysql_query($sql_query, $userlink) or PMA_mysqlDie(PMA_mysql_error($userlink));
  785.         $message = sprintf($strPasswordChanged, '\'' . $username . '\'@\'' . $hostname . '\'');
  786.     } else if (empty($pma_pw) || empty($pma_pw2)) {
  787.         $message = $strPasswordEmpty;
  788.     } else if ($pma_pw != $pma_pw2) {
  789.         $message = $strPasswordNotSame;
  790.     } else {
  791.         $hidden_pw = '';
  792.         for ($i = 0; $i < strlen($pma_pw); $i++) {
  793.             $hidden_pw .= '*';
  794.         }
  795.         $local_query = 'SET PASSWORD FOR "' . PMA_sqlAddslashes($username) . '"@"' . $hostname . '" = PASSWORD("' . PMA_sqlAddslashes($pma_pw) . '")';
  796.         $sql_query = 'SET PASSWORD FOR "' . PMA_sqlAddslashes($username) . '"@"' . $hostname . '" = PASSWORD("' . $hidden_pw . '")';
  797.         PMA_mysql_query($local_query, $userlink) or PMA_mysqlDie(PMA_mysql_error($userlink));
  798.         $message = sprintf($strPasswordChanged, '\'' . $username . '\'@\'' . $hostname . '\'');
  799.     }
  800. }
  801.  
  802.  
  803. /**
  804.  * Deletes users
  805.  *   (Changes / copies a user, part IV)
  806.  */
  807. if (!empty($delete) || (!empty($change_copy) && $mode < 4)) {
  808.     if (!empty($change_copy)) {
  809.         $selected_usr = array($old_username . '@' . $old_hostname);
  810.     } else {
  811.         $queries = array();
  812.     }
  813.     for ($i = 0; isset($selected_usr[$i]); $i++) {
  814.         list($this_user, $this_host) = explode('@', $selected_usr[$i]);
  815.         $queries[] = '# ' . sprintf($strDeleting, '\'' . $this_user . '\'@\'' . $this_host . '\'') . ' ...';
  816.         if ($mode == 2) {
  817.             // The SHOW GRANTS query may fail if the user has not been loaded
  818.             // into memory
  819.             $res = PMA_mysql_query('SHOW GRANTS FOR "' . PMA_sqlAddslashes($this_user) . '"@"' . $this_host . '";', $userlink);
  820.             if ($res) {
  821.                 $queries[] = 'REVOKE ALL PRIVILEGES ON *.* FROM "' . PMA_sqlAddslashes($this_user) . '"@"' . $this_host . '";';
  822.                 while ($row = PMA_mysql_fetch_row($res)) {
  823.                     $this_table = substr($row[0], (strpos($row[0], 'ON') + 3), (strpos($row[0], ' TO ') - strpos($row[0], 'ON') - 3));
  824.                     if ($this_table != '*.*') {
  825.                         $queries[] = 'REVOKE ALL PRIVILEGES ON ' . $this_table . ' FROM "' . PMA_sqlAddslashes($this_user) . '"@"' . $this_host . '";';
  826.  
  827.                         if (strpos($row[0], 'WITH GRANT OPTION')) {
  828.                             $queries[] = 'REVOKE GRANT OPTION ON ' . $this_table . ' FROM "' . PMA_sqlAddslashes($this_user) . '"@"' . $this_host . '";';
  829.                         }
  830.                     }
  831.                     unset($this_table);
  832.                 }
  833.                 mysql_free_result($res);
  834.             }
  835.             unset($res);
  836.         }
  837.         $queries[] = 'DELETE FROM `user` WHERE `User` = "' . PMA_sqlAddslashes($this_user) . '" AND `Host` = "' . $this_host . '";';
  838.         if ($mode != 2) {
  839.             // If we REVOKE the table grants, we should not need to modify the
  840.             // `db`, `tables_priv` and `columns_priv` tables manually...
  841.             $queries[] = 'DELETE FROM `db` WHERE `User` = "' . PMA_sqlAddslashes($this_user) . '" AND `Host` = "' . $this_host . '";';
  842.             $queries[] = 'DELETE FROM `tables_priv` WHERE `User` = "' . PMA_sqlAddslashes($this_user) . '" AND `Host` = "' . $this_host . '";';
  843.             $queries[] = 'DELETE FROM `columns_priv` WHERE `User` = "' . PMA_sqlAddslashes($this_user) . '" AND `Host` = "' . $this_host . '";';
  844.         }
  845.         if (!empty($drop_users_db)) {
  846.             $queries[] = 'DROP DATABASE IF EXISTS ' . PMA_backquote($this_user) . ';';
  847.         }
  848.     }
  849.     if (empty($change_copy)) {
  850.         if (empty($queries)) {
  851.             $message = $strError . ': ' . $strDeleteNoUsersSelected;
  852.         } else {
  853.             if ($mode == 3) {
  854.                 $queries[] = '# ' . $strReloadingThePrivileges . ' ...';
  855.                 $queries[] = 'FLUSH PRIVILEGES;';
  856.             }
  857.             foreach ($queries as $sql_query) {
  858.                 if ($sql_query{0} != '#') {
  859.                     PMA_mysql_query($sql_query, $userlink) or PMA_mysqlDie(PMA_mysql_error($userlink));
  860.                 }
  861.             }
  862.             $sql_query = join("\n", $queries);
  863.             $message = $strUsersDeleted;
  864.         }
  865.         unset($queries);
  866.     }
  867. }
  868.  
  869.  
  870. /**
  871.  * Changes / copies a user, part V
  872.  */
  873. if (!empty($change_copy)) {
  874.     $tmp_count = -1;
  875.     foreach ($queries as $sql_query) {
  876.         $tmp_count++;
  877.         if ($sql_query{0} != '#') {
  878.             PMA_mysql_query($sql_query, $userlink) or PMA_mysqlDie(PMA_mysql_error($userlink));
  879.         }
  880.         // when there is a query containing a hidden password, take it
  881.         // instead of the real query sent
  882.         if (isset($queries_for_display[$tmp_count])) {
  883.             $queries[$tmp_count] = $queries_for_display[$tmp_count];
  884.         }
  885.     }
  886.     $message = $strSuccess;
  887.     $sql_query = join("\n", $queries);
  888. }
  889.  
  890.  
  891. /**
  892.  * Reloads the privilege tables into memory
  893.  */
  894. if (!empty($flush_privileges)) {
  895.     $sql_query = 'FLUSH PRIVILEGES';
  896.     if (@PMA_mysql_query($sql_query, $userlink)) {
  897.         $message = $strPrivilegesReloaded;
  898.     } else {
  899.         PMA_mysqlDie(PMA_mysql_error($userlink));
  900.     }
  901. }
  902.  
  903.  
  904. /**
  905.  * Displays the links
  906.  */
  907. require('./server_links.inc.php');
  908.  
  909.  
  910. /**
  911.  * Displays the page
  912.  */
  913. if (empty($adduser) && empty($checkprivs)) {
  914.     if (!isset($username)) {
  915.         // No username is given --> display the overview
  916.         echo '<h2>' . "\n"
  917.            . '    ' . $strUserOverview . "\n"
  918.            . '</h2>' . "\n";
  919.         $oldPrivTables = FALSE;
  920.         if (PMA_MYSQL_INT_VERSION >= 40002) {
  921.             $res = PMA_mysql_query('SELECT `User`, `Host`, IF(`Password` = "", "N", "Y") AS "Password", `Select_priv`, `Insert_priv`, `Update_priv`, `Delete_priv`, `Create_priv`, `Drop_priv`, `Reload_priv`, `Shutdown_priv`, `Process_priv`, `File_priv`, `Grant_priv`, `References_priv`, `Index_priv`, `Alter_priv`, `Show_db_priv`, `Super_priv`, `Create_tmp_table_priv`, `Lock_tables_priv`, `Execute_priv`, `Repl_slave_priv`, `Repl_client_priv` FROM `user` ORDER BY `User` ASC, `Host` ASC;', $userlink);
  922.             if (!$res) {
  923.                 // the query failed! This may have two reasons:
  924.                 // - the user has not enough privileges
  925.                 // - the privilege tables use a structure of an earlier version.
  926.                 $oldPrivTables = TRUE;
  927.             }
  928.         }
  929.         if (empty($res) || PMA_MYSQL_INT_VERSION < 40002) {
  930.             $res = PMA_mysql_query('SELECT `User`, `Host`, IF(`Password` = "", "N", "Y") AS "Password", `Select_priv`, `Insert_priv`, `Update_priv`, `Delete_priv`, `Index_priv`, `Alter_priv`, `Create_priv`, `Drop_priv`, `Grant_priv`, `References_priv`, `Reload_priv`, `Shutdown_priv`, `Process_priv`, `File_priv` FROM `user`  ORDER BY `User` ASC, `Host` ASC;', $userlink);
  931.             if (!$res) {
  932.                 // the query failed! This may have two reasons:
  933.                 // - the user has not enough privileges
  934.                 // - the privilege tables use a structure of an earlier version.
  935.                 $oldPrivTables = TRUE;
  936.             }
  937.         }
  938.         if (!$res) {
  939.             echo '<i>' . $strNoPrivileges . '</i>' . "\n";
  940.             @mysql_free_result($res);
  941.             unset($res);
  942.         } else {
  943.             if ($oldPrivTables) {
  944.                 // rabus: This message is hardcoded because I will replace it by
  945.                 // a automatic repair feature soon.
  946.                 echo '<div class="warning">' . "\n"
  947.                    . '    Warning: Your privilege table structure seem to be older than this MySQL version!<br />' . "\n"
  948.                    . '    Please run the script <tt>mysql_fix_privilege_tables</tt> that should be included in your MySQL server distribution to solve this problem!' . "\n"
  949.                    . '</div><br />' . "\n";
  950.             }
  951.             echo '<form name="usersForm" action="server_privileges.php" method="post" />' . "\n"
  952.                . PMA_generate_common_hidden_inputs('', '', 1)
  953.                . '    <table border="0">' . "\n"
  954.                . '        <tr>' . "\n"
  955.                . '            <th></th>' . "\n"
  956.                . '            <th> ' . $strUser . ' </th>' . "\n"
  957.                . '            <th> ' . $strHost . ' </th>' . "\n"
  958.                . '            <th> ' . $strPassword . ' </th>' . "\n"
  959.                . '            <th> ' . $strGlobalPrivileges . ' </th>' . "\n"
  960.                . '            <th> ' . $strGrantOption . ' </th>' . "\n"
  961.                . '            <th> ' . $strAction . ' </th>' . "\n";
  962.             echo '        </tr>' . "\n";
  963.             $useBgcolorOne = TRUE;
  964.             for ($i = 0; $row = PMA_mysql_fetch_array($res, MYSQL_ASSOC); $i++) {
  965.                 echo '        <tr>' . "\n"
  966.                    . '            <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '"><input type="checkbox" name="selected_usr[]" id="checkbox_sel_users_' . $i . '" value="' . htmlspecialchars($row['User'] . '@' . $row['Host']) . '"' . (empty($checkall) ?  '' : ' checked="checked"') . ' /></td>' . "\n"
  967.                    . '            <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '"><label for="checkbox_sel_users_' . $i . '">' . (empty($row['User']) ? '<span style="color: #FF0000">' . $strAny . '</span>' : htmlspecialchars($row['User'])) . '</label></td>' . "\n"
  968.                    . '            <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '">' . htmlspecialchars($row['Host']) . '</td>' . "\n";
  969.                 $privs = PMA_extractPrivInfo($row, TRUE);
  970.                 echo '            <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '">' . ($row['Password'] == 'Y' ? $strYes : '<span style="color: #FF0000">' . $strNo . '</span>') . '</td>' . "\n"
  971.                    . '            <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '"><tt>' . "\n"
  972.                    . '                ' . join(',' . "\n" . '            ', $privs) . "\n"
  973.                    . '            </tt></td>' . "\n"
  974.                    . '            <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '">' . ($row['Grant_priv'] == 'Y' ? $strYes : $strNo) . '</td>' . "\n"
  975.                    . '            <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '"><a href="server_privileges.php?' . $url_query . '&username=' . urlencode($row['User']) . '&hostname=' . urlencode($row['Host']) . '">' . $strEdit . '</a></td>' . "\n"
  976.                    . '        </tr>' . "\n";
  977.                 $useBgcolorOne = !$useBgcolorOne;
  978.             }
  979.             @mysql_free_result($res);
  980.             unset($res);
  981.             unset ($row);
  982.             echo '        <tr>' . "\n"
  983.                . '            <td></td>' . "\n"
  984.                . '            <td colspan="5">' . "\n"
  985.                . '                 <i>' . $strEnglishPrivileges . '</i> ' . "\n"
  986.                . '            </td>' . "\n"
  987.                . '        </tr>' . "\n"
  988.                . '        <tr>' . "\n"
  989.                . '            <td colspan="6" valign="bottom">' . "\n"
  990.                . '                <img src="./images/arrow_' . $text_dir . '.gif" border="0" width="38" height="22" alt="' . $strWithChecked . '" />' . "\n"
  991.                . '                <a href="./server_privileges.php?' . $url_query .  '&checkall=1" onclick="setCheckboxes(\'usersForm\', \'selected_usr\', true); return false;">' . $strCheckAll . '</a>' . "\n"
  992.                . '                 / ' . "\n"
  993.                . '                <a href="server_privileges.php?' . $url_query .  '" onclick="setCheckboxes(\'usersForm\', \'selected_usr\', false); return false;">' . $strUncheckAll . '</a>' . "\n"
  994.                . '            </td>' . "\n"
  995.                . '        </tr>' . "\n"
  996.                . '    </table>' . "\n"
  997.                . '    <ul>' . "\n"
  998.                . '        <li>' . "\n"
  999.                . '            <b><a href="server_privileges.php?' . $url_query . '&adduser=1">' . $strAddUser . '</a></b><br />' . "\n"
  1000.                . '        </li><br /><br />' . "\n"
  1001.                . '        <li>' . "\n"
  1002.                . '            <b>' . $strRemoveSelectedUsers . '</b><br />' . "\n"
  1003.                . '            <input type="radio" title="' . $strJustDelete . ' ' . $strJustDeleteDescr . '" name="mode" id="radio_mode_1" value="1" checked="checked" />' . "\n"
  1004.                . '            <label for="radio_mode_1" title="' . $strJustDelete . ' ' . $strJustDeleteDescr . '">' . "\n"
  1005.                . '                ' . $strJustDelete . "\n"
  1006.                . '            </label><br />' . "\n"
  1007.                . '            <input type="radio" title="' . $strRevokeAndDelete . ' ' . $strRevokeAndDeleteDescr . '" name="mode" id="radio_mode_2" value="2" />' . "\n"
  1008.                . '            <label for="radio_mode_2" title="' . $strRevokeAndDelete . ' ' . $strRevokeAndDeleteDescr . '">' . "\n"
  1009.                . '                ' . $strRevokeAndDelete . "\n"
  1010.                . '            </label><br />' . "\n"
  1011.                . '            <input type="radio" title="' . $strDeleteAndFlush . ' ' . $strDeleteAndFlushDescr . '" name="mode" id="radio_mode_3" value="3" />' . "\n"
  1012.                . '            <label for="radio_mode_3" title="' . $strDeleteAndFlush . ' ' . $strDeleteAndFlushDescr . '">' . "\n"
  1013.                . '                ' . $strDeleteAndFlush . "\n"
  1014.                . '            </label><br />' . "\n"
  1015.                . '            <input type="checkbox" title="' . $strDropUsersDb . '" name="drop_users_db" id="checkbox_drop_users_db" />' . "\n"
  1016.                . '            <label for="checkbox_drop_users_db" title="' . $strDropUsersDb . '">' . "\n"
  1017.                . '                ' . $strDropUsersDb . "\n"
  1018.                . '            </label><br />' . "\n"
  1019.                . '            <input type="submit" name="delete" value="' . $strGo . '" />' . "\n"
  1020.                . '        </li>' . "\n"
  1021.                . '    </ul>' . "\n"
  1022.                . '</form>' . "\n"
  1023.                . '<div>' . "\n"
  1024.                . '    ' . sprintf($strFlushPrivilegesNote, '<a href="server_privileges.php?' . $url_query . '&flush_privileges=1">', '</a>') . "\n"
  1025.                . '</div>' . "\n";
  1026.         }
  1027.     } else {
  1028.         // A user was selected -> display the user's properties
  1029.         echo '<h2>' . "\n"
  1030.            . '    ' . $strUser . ' <i><a class="h2" href="server_privileges.php?' . $url_query . '&username=' . urlencode($username) . '&hostname=' . urlencode($hostname) . '">\'' . htmlspecialchars($username) . '\'@\'' . htmlspecialchars($hostname) . '\'</a></i>' . "\n";
  1031.         if (!empty($dbname)) {
  1032.             echo '    - ' . $strDatabase . ' <i><a class="h2" href="' . $cfg['DefaultTabDatabase'] . '?' . $url_query . '&db=' . urlencode($dbname) . '&reload=1">' . htmlspecialchars($dbname) . '</a></i>' . "\n";
  1033.             if (!empty($tablename)) {
  1034.                 echo '    - ' . $strTable . ' <i><a class="h2" href="' . $cfg['DefaultTabTable'] . '?' . $url_query . '&db=' . urlencode($dbname) . '&table=' . urlencode($tablename) . '&reload=1">' . htmlspecialchars($tablename) . '</a></i>' . "\n";
  1035.             }
  1036.         }
  1037.         echo '</h2>' . "\n";
  1038.         $res = PMA_mysql_query('SELECT "foo" FROM `user` WHERE `User` = "' . PMA_sqlAddslashes($username) . '" AND `Host` = "' . $hostname . '";', $userlink);
  1039.         if (mysql_affected_rows($userlink) <= 0) {
  1040.             echo $strUserNotFound;
  1041.             require_once('./footer.inc.php');
  1042.         }
  1043.         mysql_free_result($res);
  1044.         unset($res);
  1045.         echo '<ul>' . "\n"
  1046.            . '    <li>' . "\n"
  1047.            . '        <form action="server_privileges.php" method="post">' . "\n"
  1048.            . PMA_generate_common_hidden_inputs('', '', 3)
  1049.            . '            <input type="hidden" name="username" value="' . htmlspecialchars($username) . '" />' . "\n"
  1050.            . '            <input type="hidden" name="hostname" value="' . htmlspecialchars($hostname) . '" />' . "\n";
  1051.         if (!empty($dbname)) {
  1052.             echo '            <input type="hidden" name="dbname" value="' . htmlspecialchars($dbname) . '" />' . "\n";
  1053.             if (!empty($tablename)) {
  1054.                 echo '            <input type="hidden" name="tablename" value="' . htmlspecialchars($tablename) . '" />' . "\n";
  1055.             }
  1056.         }
  1057.         echo '            <b>' . $strEditPrivileges . '</b><br />' . "\n";
  1058.         PMA_displayPrivTable((empty($dbname) ? '*' : $dbname), ((empty($dbname) || empty($tablename)) ? '*' : $tablename), TRUE, 3);
  1059.         echo '        </form>' . "\n"
  1060.            . '    </li>' . "\n";
  1061.         if (empty($tablename)) {
  1062.             echo '    <li>' . "\n"
  1063.                . '        <b>' . (empty($dbname) ? $strDbPrivileges : $strTblPrivileges) . '</b><br />' . "\n"
  1064.                . '        <table border="0">' . "\n"
  1065.                . '            <tr>' . "\n"
  1066.                . '                <th> ' . (empty($dbname) ? $strDatabase : $strTable) . ' </th>' . "\n"
  1067.                . '                <th> ' . $strPrivileges . ' </th>' . "\n"
  1068.                . '                <th> ' . $strGrantOption . ' </th>' . "\n"
  1069.                . '                <th> ' . (empty($dbname) ? $strTblPrivileges : $strColumnPrivileges) . ' </th>' . "\n"
  1070.                . '                <th colspan="2"> ' . $strAction . ' </th>' . "\n"
  1071.                . '            </tr>' . "\n";
  1072.             if (empty($dbname)) {
  1073.                 $sql_query = 'SELECT * FROM `db` WHERE `Host` = "' . $hostname . '" AND `User` = "' . PMA_sqlAddslashes($username) . '" ORDER BY `Db` ASC;';
  1074.             } else {
  1075.                 $sql_query = 'SELECT `Table_name`, `Table_priv`, IF(`Column_priv` = "", 0, 1) AS "Column_priv" FROM `tables_priv` WHERE `Host` = "' . $hostname . '" AND `User` = "' . PMA_sqlAddslashes($username) . '" AND `Db` = "' . $dbname . '" ORDER BY `Table_name` ASC;';
  1076.             }
  1077.             $res = PMA_mysql_query($sql_query, $userlink) or PMA_mysqlDie(PMA_mysql_error($userlink), $sql_query);
  1078.             if (mysql_affected_rows($userlink) == 0) {
  1079.                 echo '            <tr>' . "\n"
  1080.                    . '                <td bgcolor="' . $cfg['BgcolorOne'] . '" colspan="6"><center><i>' . $strNone . '</i></center></td>' . "\n"
  1081.                    . '            </tr>' . "\n";
  1082.             } else {
  1083.                 $useBgcolorOne = TRUE;
  1084.                 if (empty($dbname)) {
  1085.                     $res2 = PMA_mysql_query('SELECT `Db` FROM `tables_priv` WHERE `Host` = "' . $hostname . '" AND `User` = "' . PMA_sqlAddslashes($username) . '" GROUP BY `Db` ORDER BY `Db` ASC;') or PMA_mysqlDie(PMA_mysql_error($userlink), 'SELECT `Db` FROM `tables_priv` WHERE `Host` = "' . $hostname . '" AND `User` = "' . PMA_sqlAddslashes($username) . '" GROUP BY `Db` ORDER BY `Db` ASC;');
  1086.                     $row2 = PMA_mysql_fetch_array($res2, MYSQL_ASSOC);
  1087.                 }
  1088.                 $found_rows = array();
  1089.                 while ($row = PMA_mysql_fetch_array($res, MYSQL_ASSOC)) {
  1090.  
  1091.                     while (empty($dbname) && $row2 && $row['Db'] > $row2['Db']) {
  1092.                         $found_rows[] = $row2['Db'];
  1093.  
  1094.                         echo '            <tr>' . "\n"
  1095.                            . '                <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '">' . htmlspecialchars($row2['Db']) . '</td>' . "\n"
  1096.                            . '                <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '"><tt>' . "\n"
  1097.                            . '                    <dfn title="' . $strPrivDescUsage . '">USAGE</dfn>' . "\n"
  1098.                            . '                </tt></td>' . "\n"
  1099.                            . '                <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '">' . $strNo . '</td>' . "\n"
  1100.                            . '                <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '">' . $strYes . '</td>' . "\n"
  1101.                            . '                <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '"><a href="server_privileges.php?' . $url_query . '&username=' . urlencode($username) . '&hostname=' . urlencode($hostname) . '&dbname=' . urlencode($row2['Db']) . '">' . $strEdit . '</a></td>' . "\n"
  1102.                            . '                <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '"><a href="server_privileges.php?' . $url_query . '&username=' . urlencode($username) . '&hostname=' . urlencode($hostname) . '&dbname=' . urlencode($row2['Db']) . '&revokeall=1">' . $strRevoke . '</a></td>' . "\n"
  1103.                            . '            </tr>' . "\n";
  1104.                         $row2 = PMA_mysql_fetch_array($res2, MYSQL_ASSOC);
  1105.                         $useBgcolorOne = !$useBgcolorOne;
  1106.                     } // end while
  1107.                     $found_rows[] = empty($dbname) ? $row['Db'] : $row['Table_name'];
  1108.  
  1109.                     echo '            <tr>' . "\n"
  1110.                        . '                <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '">' . htmlspecialchars(empty($dbname) ? $row['Db'] : $row['Table_name']) . '</td>' . "\n"
  1111.                        . '                <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '"><tt>' . "\n"
  1112.                        . '                    ' . join(',' . "\n" . '            ', PMA_extractPrivInfo($row, TRUE)) . "\n"
  1113.                        . '                </tt></td>' . "\n"
  1114.                        . '                <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '">' . (((empty($dbname) && $row['Grant_priv'] == 'Y') || (!empty($dbname) && in_array('Grant', explode(',', $row['Table_priv'])))) ? $strYes : $strNo) . '</td>' . "\n"
  1115.                        . '                <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '">';
  1116.                     if ((empty($dbname) && $row2 && $row['Db'] == $row2['Db'])
  1117.                         || (!empty($dbname) && $row['Column_priv'])) {
  1118.                         echo $strYes;
  1119.                         if (empty($dbname)) {
  1120.                             $row2 = PMA_mysql_fetch_array($res2, MYSQL_ASSOC);
  1121.                         }
  1122.                     } else {
  1123.                         echo $strNo;
  1124.                     }
  1125.                     echo '</td>' . "\n"
  1126.                        . '                <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '"><a href="server_privileges.php?' . $url_query . '&username=' . urlencode($username) . '&hostname=' . urlencode($hostname) . '&dbname=' . (empty($dbname) ? urlencode($row['Db']) : urlencode($dbname) . '&tablename=' . urlencode($row['Table_name'])) . '">' . $strEdit . '</a></td>' . "\n"
  1127.                        . '                <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '"><a href="server_privileges.php?' . $url_query . '&username=' . urlencode($username) . '&hostname=' . urlencode($hostname) . '&dbname=' . (empty($dbname) ? urlencode($row['Db']) : urlencode($dbname) . '&tablename=' . urlencode($row['Table_name'])) . '&revokeall=1">' . $strRevoke . '</a></td>' . "\n"
  1128.                        . '            </tr>' . "\n";
  1129.                     $useBgcolorOne = !$useBgcolorOne;
  1130.                 } // end while
  1131.  
  1132.  
  1133.                 while (empty($dbname) && $row2) {
  1134.  
  1135.                     $found_rows[] = $row2['Db'];
  1136.                     echo '            <tr>' . "\n"
  1137.                        . '                <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '">' . htmlspecialchars($row2['Db']) . '</td>' . "\n"
  1138.                        . '                <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '"><tt>' . "\n"
  1139.                        . '                    <dfn title="' . $strPrivDescUsage . '">USAGE</dfn>' . "\n"
  1140.                        . '                </tt></td>' . "\n"
  1141.                        . '                <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '">' . $strNo . '</td>' . "\n"
  1142.                        . '                <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '">' . $strYes . '</td>' . "\n"
  1143.                        . '                <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '"><a href="server_privileges.php?' . $url_query . '&username=' . urlencode($username) . '&hostname=' . urlencode($hostname) . '&dbname=' . urlencode($row2['Db']) . '">' . $strEdit . '</a></td>' . "\n"
  1144.                        . '                <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '"><a href="server_privileges.php?' . $url_query . '&username=' . urlencode($username) . '&hostname=' . urlencode($hostname) . '&dbname=' . urlencode($row2['Db']) . '&revokeall=1">' . $strRevoke . '</a></td>' . "\n"
  1145.                        . '            </tr>' . "\n";
  1146.                     $row2 = PMA_mysql_fetch_array($res2, MYSQL_ASSOC);
  1147.  
  1148.                     $useBgcolorOne = !$useBgcolorOne;
  1149.                 } // end while
  1150.                 if (empty($dbname)) {
  1151.                     mysql_free_result($res2);
  1152.                     unset($res2);
  1153.                     unset($row2);
  1154.                 }
  1155.             }
  1156.             mysql_free_result($res);
  1157.             unset($res);
  1158.             unset($row);
  1159.             echo '            <tr>' . "\n"
  1160.                . '                <td colspan="5">' . "\n"
  1161.                . '                    <form action="server_privileges.php" method="post">' . "\n"
  1162.                . PMA_generate_common_hidden_inputs('', '', 6)
  1163.                . '                        <input type="hidden" name="username" value="' . htmlspecialchars($username) . '" />' . "\n"
  1164.                . '                        <input type="hidden" name="hostname" value="' . htmlspecialchars($hostname) . '" />' . "\n";
  1165.             if (empty($dbname)) {
  1166.                 echo '                        <label for="text_dbname">' . $strAddPrivilegesOnDb . ':</label>' . "\n";
  1167.                 $res = PMA_mysql_query('SHOW DATABASES;', $userlink) or PMA_mysqlDie(PMA_mysql_error($userlink), 'SHOW DATABASES;');
  1168.                 $pred_db_array = array();
  1169.                 while ($row = PMA_mysql_fetch_row($res)) {
  1170.                     if (!isset($found_rows) || !in_array($row[0], $found_rows)) {
  1171.                         $pred_db_array[] = $row[0];
  1172.                     }
  1173.                 }
  1174.                 mysql_free_result($res);
  1175.                 unset($res);
  1176.                 unset($row);
  1177.                 if (!empty($pred_db_array)) {
  1178.                     echo '                        <select name="pred_dbname" onchange="this.form.submit();">' . "\n"
  1179.                        . '                            <option value="" selected="selected">' . $strUseTextField . ':</option>' . "\n";
  1180.                     foreach ($pred_db_array as $current_db) {
  1181.                         echo '                            <option value="' . htmlspecialchars($current_db) . '">' . htmlspecialchars($current_db) . '</option>' . "\n";
  1182.                     }
  1183.                     echo '                        </select>' . "\n";
  1184.                 }
  1185.                 echo '                        <input type="text" id="text_dbname" name="dbname" class="textfield" />' . "\n";
  1186.             } else {
  1187.                 echo '                        <input type="hidden" name="dbname" value="' . htmlspecialchars($dbname) . '"/>' . "\n"
  1188.                    . '                        <label for="text_tablename">' . $strAddPrivilegesOnTbl . ':</label>' . "\n";
  1189.                 if ($res = @PMA_mysql_query('SHOW TABLES FROM ' . PMA_backquote($dbname) . ';', $userlink)) {
  1190.                     $pred_tbl_array = array();
  1191.                     while ($row = PMA_mysql_fetch_row($res)) {
  1192.                         if (!isset($found_rows) || !in_array($row[0], $found_rows)) {
  1193.                             $pred_tbl_array[] = $row[0];
  1194.                         }
  1195.                     }
  1196.                     mysql_free_result($res);
  1197.                     unset($res);
  1198.                     unset($row);
  1199.                     if (!empty($pred_tbl_array)) {
  1200.                         echo '                        <select name="pred_tablename" onchange="this.form.submit();">' . "\n"
  1201.                            . '                            <option value="" selected="selected">' . $strUseTextField . ':</option>' . "\n";
  1202.                         foreach ($pred_tbl_array as $current_table) {
  1203.                             echo '                            <option value="' . htmlspecialchars($current_table) . '">' . htmlspecialchars($current_table) . '</option>' . "\n";
  1204.                         }
  1205.                         echo '                        </select>' . "\n";
  1206.                     }
  1207.                 } else {
  1208.                     unset($res);
  1209.                 }
  1210.                 echo '                        <input type="text" id="text_tablename" name="tablename" class="textfield" />' . "\n";
  1211.             }
  1212.             echo '                        <input type="submit" value="' . $strGo . '" />' . "\n"
  1213.                . '                    </form>' . "\n"
  1214.                . '                </td>' . "\n"
  1215.                . '            </tr>' . "\n"
  1216.                . '        </table><br />' . "\n"
  1217.                . '    </li>' . "\n";
  1218.         }
  1219.         if (empty($dbname)) {
  1220.             echo '    <li>' . "\n"
  1221.                . '        <form action="server_privileges.php" method="post" onsubmit="checkPassword(this);">' . "\n"
  1222.                . PMA_generate_common_hidden_inputs('', '', 3)
  1223.                . '            <input type="hidden" name="username" value="' . htmlspecialchars($username) . '" />' . "\n"
  1224.                . '            <input type="hidden" name="hostname" value="' . htmlspecialchars($hostname) . '" />' . "\n";
  1225.             echo '            <b>' . $strChangePassword . '</b><br />' . "\n"
  1226.                . '            <table border="0">' . "\n"
  1227.                . '                <tr>' . "\n"
  1228.                . '                    <td bgcolor="' . $cfg['BgcolorOne'] . '"><input type="radio" name="nopass" value="1" id="radio_nopass_1" onclick="pma_pw.value=\'\'; pma_pw2.value=\'\';" /></td>' . "\n"
  1229.                . '                    <td bgcolor="' . $cfg['BgcolorOne'] . '" colspan="2"><label for="radio_nopass_1">' . $strNoPassword . '</label></td>' . "\n"
  1230.                . '                </tr>' . "\n"
  1231.                . '                <tr>' . "\n"
  1232.                . '                    <td bgcolor="' . $cfg['BgcolorTwo'] . '"><input type="radio" name="nopass" value="0" id="radio_nopass_0" onclick="document.getElementById(\'pw_pma_pw\').focus();" /></td>' . "\n"
  1233.                . '                    <td bgcolor="' . $cfg['BgcolorTwo'] . '"><label for="radio_nopass_0">' . $strPassword . ':</label></td>' . "\n"
  1234.                . '                    <td bgcolor="' . $cfg['BgcolorTwo'] . '"><input type="password" name="pma_pw" id="pw_pma_pw" class="textfield" onchange="nopass[1].checked = true;" /></td>' . "\n"
  1235.                . '                </tr>' . "\n"
  1236.                . '                <tr>' . "\n"
  1237.                . '                    <td bgcolor="' . $cfg['BgcolorTwo'] . '"> </td>' . "\n"
  1238.                . '                    <td bgcolor="' . $cfg['BgcolorTwo'] . '"><label for="pw_pma_pw2">' . $strReType . ':</label></td>' . "\n"
  1239.                . '                    <td bgcolor="' . $cfg['BgcolorTwo'] . '"><input type="password" name="pma_pw2" id="pw_pma_pw2" class="textfield" onchange="nopass[1].checked = true;" /></td>' . "\n"
  1240.                . '                </tr>' . "\n"
  1241.                . '                <tr>' . "\n"
  1242.                . '                    <td colspan="3" align="center">' . "\n"
  1243.                . '                        <input type="submit" name="change_pw" value="' . $strGo . '" />' . "\n"
  1244.                . '                    </td>' . "\n"
  1245.                . '                </tr>' . "\n"
  1246.                . '            </table>' . "\n"
  1247.                . '        </form>' . "\n"
  1248.                . '    </li>' . "\n"
  1249.                . '    <li>' . "\n"
  1250.                . '        <form action="server_privileges.php" method="post" onsubmit="checkPassword(this);">' . "\n"
  1251.                . PMA_generate_common_hidden_inputs('', '', 3)
  1252.                . '            <input type="hidden" name="old_username" value="' . htmlspecialchars($username) . '" />' . "\n"
  1253.                . '            <input type="hidden" name="old_hostname" value="' . htmlspecialchars($hostname) . '" />' . "\n"
  1254.                . '            <b>' . $strChangeCopyUser . '</b><br />' . "\n"
  1255.                . '            <table border="0">' . "\n";
  1256.             PMA_displayLoginInformationFields('change', 3);
  1257.             echo '            </table>' . "\n"
  1258.                . '            ' . $strChangeCopyMode . '<br />' . "\n"
  1259.                . '            <input type="radio" name="mode" value="4" id="radio_mode_4" checked="checked" />' . "\n"
  1260.                . '            <label for="radio_mode_4">' . "\n"
  1261.                . '                ' . $strChangeCopyModeCopy . "\n"
  1262.                . '            </label>' . "\n"
  1263.                . '            <br />' . "\n"
  1264.                . '            <input type="radio" name="mode" value="1" id="radio_mode_1" />' . "\n"
  1265.                . '            <label for="radio_mode_1">' . "\n"
  1266.                . '                ' . $strChangeCopyModeJustDelete . "\n"
  1267.                . '            </label>' . "\n"
  1268.                . '            <br />' . "\n"
  1269.                . '            <input type="radio" name="mode" value="2" id="radio_mode_2" />' . "\n"
  1270.                . '            <label for="radio_mode_2">' . "\n"
  1271.                . '                ' . $strChangeCopyModeRevoke . "\n"
  1272.                . '            </label>' . "\n"
  1273.                . '            <br />' . "\n"
  1274.                . '            <input type="radio" name="mode" value="3" id="radio_mode_3" />' . "\n"
  1275.                . '            <label for="radio_mode_3">' . "\n"
  1276.                . '                ' . $strChangeCopyModeDeleteAndReload . "\n"
  1277.                . '            </label>' . "\n"
  1278.                . '            <br />' . "\n"
  1279.                . '            <input type="submit" name="change_copy" value="' . $strGo . '" />' . "\n"
  1280.                . '        </form>' . "\n"
  1281.                . '    </li>' . "\n";
  1282.         }
  1283.         echo '</ul>' . "\n";
  1284.     }
  1285. } else if (!empty($adduser)) {
  1286.     // Add a new user
  1287.     echo '<h2>' . "\n"
  1288.        . '    ' . $strAddUser . "\n"
  1289.        . '</h2>' . "\n"
  1290.        . '<form action="server_privileges.php" method="post" onsubmit="return checkAddUser(this);">' . "\n"
  1291.        . PMA_generate_common_hidden_inputs('', '', 1)
  1292.        . '    <table border="0">' . "\n"
  1293.        . '        <tr>' . "\n"
  1294.        . '            <th colspan="3">' . "\n"
  1295.        . '                ' . $strLoginInformation . "\n"
  1296.        . '            </th>' . "\n"
  1297.        . '        </tr>' . "\n";
  1298.     PMA_displayLoginInformationFields('new', 2);
  1299.     echo '    </table><br />' . "\n";
  1300.     PMA_displayPrivTable('*', '*', FALSE, 1);
  1301.     echo '    <br />' . "\n"
  1302.        . '    <input type="submit" name="adduser_submit" value="' . $strGo . '" />' . "\n"
  1303.        . '</form>' . "\n";
  1304. } else {
  1305.     // check the privileges for a particular database.
  1306.     echo '<h2>' . "\n"
  1307.        . '    ' . sprintf($strUsersHavingAccessToDb, htmlspecialchars($checkprivs)) . "\n"
  1308.        . '</h2>' . "\n"
  1309.        . '<table border="0">' . "\n"
  1310.        . '    <tr>' . "\n"
  1311.        . '        <th>' . "\n"
  1312.        . '             ' . $strUser . ' ' . "\n"
  1313.        . '        </th>' . "\n"
  1314.        . '        <th>' . "\n"
  1315.        . '             ' . $strHost . ' ' . "\n"
  1316.        . '        </th>' . "\n"
  1317.        . '        <th>' . "\n"
  1318.        . '             ' . $strType . ' ' . "\n"
  1319.        . '        </th>' . "\n"
  1320.        . '        <th>' . "\n"
  1321.        . '             ' . $strPrivileges . ' ' . "\n"
  1322.        . '        </th>' . "\n"
  1323.        . '        <th>' . "\n"
  1324.        . '             ' . $strGrantOption . ' ' . "\n"
  1325.        . '        </th>' . "\n"
  1326.        . '        <th>' . "\n"
  1327.        . '             ' . $strAction . ' ' . "\n"
  1328.        . '        </th>' . "\n"
  1329.        . '    </tr>' . "\n";
  1330.     $useBgcolorOne = TRUE;
  1331.     unset($row);
  1332.     unset($row1);
  1333.     unset($row2);
  1334.     // now, we build the table...
  1335.     if (PMA_MYSQL_INT_VERSION >= 40000) {
  1336.         // Starting with MySQL 4.0.0, we may use UNION SELECTs and this makes
  1337.         // the job much easier here!
  1338.         $sql_query = '(SELECT `User`, `Host`, `Db`, `Select_priv`, `Insert_priv`, `Update_priv`, `Delete_priv`, `Create_priv`, `Drop_priv`, `Grant_priv`, `References_priv` FROM `db` WHERE "' . $checkprivs . '" LIKE `Db` AND NOT (`Select_priv` = "N" AND `Insert_priv` = "N" AND `Update_priv` = "N" AND `Delete_priv` = "N" AND `Create_priv` = "N" AND `Drop_priv` = "N" AND `Grant_priv` = "N" AND `References_priv` = "N")) UNION (SELECT `User`, `Host`, "*" AS "Db", `Select_priv`, `Insert_priv`, `Update_priv`, `Delete_priv`, `Create_priv`, `Drop_priv`, `Grant_priv`, `References_priv` FROM `user` WHERE NOT (`Select_priv` = "N" AND `Insert_priv` = "N" AND `Update_priv` = "N" AND `Delete_priv` = "N" AND `Create_priv` = "N" AND `Drop_priv` = "N" AND `Grant_priv` = "N" AND `References_priv` = "N")) ORDER BY `User` ASC, `Host` ASC, `Db` ASC;';
  1339.         $res = PMA_mysql_query($sql_query, $userlink) or PMA_mysqlDie(PMA_mysql_error($userlink), $sql_query);
  1340.         $row = PMA_mysql_fetch_array($res, MYSQL_ASSOC);
  1341.         if ($row) {
  1342.             $found = TRUE;
  1343.         }
  1344.     } else {
  1345.         // With MySQL 3, we need 2 seperate queries here.
  1346.         $sql_query = 'SELECT * FROM `user` WHERE NOT (`Select_priv` = "N" AND `Insert_priv` = "N" AND `Update_priv` = "N" AND `Delete_priv` = "N" AND `Create_priv` = "N" AND `Drop_priv` = "N" AND `Grant_priv` = "N" AND `References_priv` = "N") ORDER BY `User` ASC, `Host` ASC;';
  1347.         $res1 = PMA_mysql_query($sql_query, $userlink) or PMA_mysqlDie(PMA_mysql_error($userlink), $sql_query);
  1348.         $row1 = PMA_mysql_fetch_array($res1, MYSQL_ASSOC);
  1349.         $sql_query = 'SELECT * FROM `db` WHERE "' . $checkprivs . '" LIKE `Db` AND NOT (`Select_priv` = "N" AND `Insert_priv` = "N" AND `Update_priv` = "N" AND `Delete_priv` = "N" AND `Create_priv` = "N" AND `Drop_priv` = "N" AND `Grant_priv` = "N" AND `References_priv` = "N") ORDER BY `User` ASC, `Host` ASC;';
  1350.         $res2 = PMA_mysql_query($sql_query, $userlink) or PMA_mysqlDie(PMA_mysql_error($userlink), $sql_query);
  1351.         $row2 = PMA_mysql_fetch_array($res2, MYSQL_ASSOC);
  1352.         if ($row1 || $row2) {
  1353.             $found = TRUE;
  1354.         }
  1355.     } // end if (PMA_MYSQL_INT_VERSION >= 40000) ... else ...
  1356.     if ($found) {
  1357.         while (TRUE) {
  1358.             // prepare the current user
  1359.             if (PMA_MYSQL_INT_VERSION >= 40000) {
  1360.                 $current_privileges = array();
  1361.                 $current_user = $row['User'];
  1362.                 $current_host = $row['Host'];
  1363.                 while ($row && $current_user == $row['User'] && $current_host == $row['Host']) {
  1364.                     $current_privileges[] = $row;
  1365.                     $row = PMA_mysql_fetch_array($res, MYSQL_ASSOC);
  1366.                 }
  1367.             } else {
  1368.                 $current_privileges = array();
  1369.                 if ($row1 && (!$row2 || ($row1['User'] < $row2['User'] || ($row1['User'] == $row2['User'] && $row1['Host'] <= $row2['Host'])))) {
  1370.                     $current_user = $row1['User'];
  1371.                     $current_host = $row1['Host'];
  1372.                     $current_privileges = array($row1);
  1373.                     $row1 = PMA_mysql_fetch_array($res1, MYSQL_ASSOC);
  1374.                 } else {
  1375.                     $current_user = $row2['User'];
  1376.                     $current_host = $row2['Host'];
  1377.                     $current_privileges = array();
  1378.                 }
  1379.                 while ($row2 && $current_user == $row2['User'] && $current_host == $row2['Host']) {
  1380.                     $current_privileges[] = $row2;
  1381.                     $row2 = PMA_mysql_fetch_array($res2, MYSQL_ASSOC);
  1382.                 }
  1383.             }
  1384.             echo '    <tr>' . "\n"
  1385.                . '        <td';
  1386.             if (count($current_privileges) > 1) {
  1387.                 echo ' rowspan="' . count($current_privileges) . '"';
  1388.             }
  1389.             echo ' bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '">' . "\n"
  1390.                . '            ' . (empty($current_user) ? '<span style="color: #FF0000">' . $strAny . '</span>' : htmlspecialchars($current_user)) . "\n"
  1391.                . '        </td>' . "\n"
  1392.                . '        <td';
  1393.             if (count($current_privileges) > 1) {
  1394.                 echo ' rowspan="' . count($current_privileges) . '"';
  1395.             }
  1396.             echo ' bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '">' . "\n"
  1397.                . '            ' . htmlspecialchars($current_host) . "\n"
  1398.                . '        </td>' . "\n";
  1399.             foreach ($current_privileges as $current) {
  1400.                 echo '        <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '">' . "\n"
  1401.                    . '            ';
  1402.                 if (!isset($current['Db']) || $current['Db'] == '*') {
  1403.                     echo $strGlobal;
  1404.                 } else if ($current['Db'] == $checkprivs) {
  1405.                     echo $strDbSpecific;
  1406.                 } else {
  1407.                     echo $strWildcard, ': <tt>' . htmlspecialchars($current['Db']) . '</tt>';
  1408.                 }
  1409.                 echo "\n"
  1410.                    . '        </td>' . "\n"
  1411.                    . '        <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '">' . "\n"
  1412.                    . '            <tt>' . "\n"
  1413.                    . '                ' . join(',' . "\n" . '                ', PMA_extractPrivInfo($current, TRUE)) . "\n"
  1414.                    . '            <tt>' . "\n"
  1415.                    . '        </td>' . "\n"
  1416.                    . '        <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '">' . "\n"
  1417.                    . '            ' . ($current['Grant_priv'] == 'Y' ? $strYes : $strNo) . "\n"
  1418.                    . '        </td>' . "\n"
  1419.                    . '        <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '">' . "\n"
  1420.                    . '            <a href="./server_privileges.php?' . $url_query . '&username=' . urlencode($current_user) . '&hostname=' . urlencode($current_host) . (!isset($current['Db']) || $current['Db'] == '*' ? '' : '&dbname=' . urlencode($current['Db'])) . '">' . "\n"
  1421.                    . '                ' . $strEdit . "\n"
  1422.                    . '            </a>' . "\n"
  1423.                    . '        </td>' . "\n"
  1424.                    . '    </tr>' . "\n";
  1425.             }
  1426.             if (empty($row) && empty($row1) && empty($row2)) {
  1427.                 break;
  1428.             }
  1429.             $useBgcolorOne = !$useBgcolorOne;
  1430.         }
  1431.     } else {
  1432.         echo '    <tr>' . "\n"
  1433.            . '        <td colspan="6" bgcolor="' . $cfg['BgcolorTwo'] . '">' . "\n"
  1434.            . '            ' . $strNoUsersFound . "\n"
  1435.            . '        </td>' . "\n"
  1436.            . '    </tr>' . "\n";
  1437.     }
  1438.     echo '</table>' . "\n";
  1439. } // end if (empty($adduser) && empty($checkprivs)) ... else if ... else ...
  1440.  
  1441.  
  1442. /**
  1443.  * Displays the footer
  1444.  */
  1445. echo "\n\n";
  1446. require_once('./footer.inc.php');
  1447.  
  1448. ?>
  1449.