home *** CD-ROM | disk | FTP | other *** search
/ Freelog 70 / Freelog070.iso / Internet / EasyPHP / easyphp1-8_setup.exe / {app} / phpmyadmin / server_privileges.php < prev    next >
Encoding:
PHP Script  |  2004-11-21  |  97.8 KB  |  1,543 lines

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