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

  1. <?php
  2. /* $Id: user_details.php,v 1.49 2001/12/24 11:17:37 loic1 Exp $*/
  3.  
  4.  
  5. /**
  6.  * Gets some core libraries
  7.  */
  8. require('./libraries/grab_globals.lib.php');
  9. require('./libraries/common.lib.php');
  10.  
  11.  
  12. /**
  13.  * Defines the url to return to in case of error in a sql statement
  14.  */
  15. $err_url = 'user_details.php'
  16.          . '?lang=' . $lang
  17.          . '&server=' . $server
  18.          . '&db=mysql'
  19.          . '&table=user';
  20.  
  21.  
  22. /**
  23.  * Displays the table of grants for an user
  24.  *
  25.  * @param   mixed    the id of the query used to get hosts and databases lists
  26.  *                   or an arry containing host and user informations
  27.  * @param   mixed    the database to check garnts for, FALSE for all databases
  28.  *
  29.  * @return  boolean  always true
  30.  *
  31.  * @global  string   the current language
  32.  * @global  integer  the server to use (refers to the number in the
  33.  *                   configuration file)
  34.  *
  35.  * @see     PMA_checkDb()
  36.  *
  37.  * @TODO    "SHOW GRANTS" statements is available and buggyless since
  38.  *          MySQL 3.23.4 and it seems not to return privileges of the anonymous
  39.  *          user while these privileges applies to all users.
  40.  */
  41. function PMA_tableGrants(&$host_db_result, $dbcheck = FALSE) {
  42.     global $lang, $server;
  43.     ?>
  44.  
  45. <!-- Table of grants -->
  46. <table border="<?php echo $GLOBALS['cfgBorder']; ?>">
  47. <tr>
  48.     <?php
  49.     // 1. Table headers
  50.     if ($dbcheck) {
  51.         echo "\n";
  52.         echo '    <th>' . $GLOBALS['strAction'] . '</th>' . "\n";
  53.         echo '    <th>' . $GLOBALS['strHost'] . '</th>' . "\n";
  54.         echo '    <th>' . $GLOBALS['strUser'] . '</th>';
  55.     } else {
  56.         echo "\n";
  57.         echo '    <th colspan="2">' . $GLOBALS['strAction'] . '</th>';
  58.     }
  59.     echo "\n";
  60.     echo '    <th>' . $GLOBALS['strDatabase'] . '</th>' . "\n";
  61.     echo '    <th>' . UCFirst($GLOBALS['strTable']) . '</th>' . "\n";
  62.     echo '    <th>' . $GLOBALS['strPrivileges'] . '</th>' . "\n";
  63.     if (!$dbcheck) {
  64.         echo '    <th>Grant Option</th>' . "\n";
  65.     }
  66.     ?>
  67. </tr>
  68.     <?php
  69.     echo "\n";
  70.  
  71.     // 2. Table body
  72.     $url_query  = 'lang=' . $lang . '&server=' . $server . '&db=mysql&table=user';
  73.  
  74.     while ($row = (is_array($host_db_result) ? $host_db_result : mysql_fetch_array($host_db_result))) {
  75.         $local_query = 'SHOW GRANTS FOR \'' . $row['User'] . '\'@\'' . $row['Host'] . '\'';
  76.         $result      = mysql_query($local_query);
  77.         $grants_cnt  = @mysql_num_rows($result);
  78.  
  79.         if ($grants_cnt) {
  80.             $i = 0;
  81.             while ($usr_row = mysql_fetch_row($result)) {
  82.                 if (eregi('GRANT (.*) ON ([^\.]+).([^\.]+) TO .*$', $usr_row[0], $parts)) {
  83.                     // loic1: bug #487673 - revoke 'reference'
  84.                     if ($parts[1] == 'USAGE') {
  85.                         $priv = '';
  86.                     } else {
  87.                         $priv = ereg_replace('REFERENCE([^S]|$)', 'REFERENCES', trim($parts[1]));
  88.                     }
  89.                     $db       = $parts[2];
  90.                     $table    = trim($parts[3]);
  91.                     $grantopt = eregi('WITH GRANT OPTION$', $usr_row[0]);
  92.                 } else {
  93.                     $priv     = '';
  94.                     $db       = ' ';
  95.                     $table    = ' ';
  96.                     $column   = ' ';
  97.                     $grantopt = FALSE;
  98.                 } // end if...else
  99.  
  100.                 // Password Line
  101.                 if ($priv == '' && !$grantopt) {
  102.                     continue;
  103.                 }
  104.  
  105.                 // Checking the database (take into account wildcards)
  106.                 if ($dbcheck
  107.                     && ($db != '*' && $db != $dbcheck)) {
  108.                     // TODO: db names may contain characters that are regexp
  109.                     //       instructions
  110.                     $re        = '(^|(\\\\\\\\)+|[^\])';
  111.                     $db_regex  = ereg_replace($re . '%', '\\1.*', ereg_replace($re . '_', '\\1.{1}', $db));
  112.                     if (!eregi('^' . $db_regex . '$', $dbcheck)) {
  113.                         continue;
  114.                     }
  115.                 } // end if
  116.  
  117.                 $bgcolor    = ($i % 2) ? $GLOBALS['cfgBgcolorOne'] : $GLOBALS['cfgBgcolorTwo'];
  118.                 $revoke_url = 'sql.php'
  119.                             . '?' . $url_query
  120.                             . '&sql_query=' . urlencode('REVOKE ' . $priv . ' ON ' . PMA_backquote($db) . '.' . PMA_backquote($table) . ' FROM \'' . $row['User'] . '\'@\'' . $row['Host'] . '\'')
  121.                             . '&zero_rows=' . urlencode(sprintf($GLOBALS['strRevokeMessage'], ' <span style="color: #002E80">' . $row['User'] . '@' . $row['Host'] . '</span>') . '<br />' . $GLOBALS['strRememberReload'])
  122.                             . '&goto=user_details.php';
  123.                 if ($grantopt) {
  124.                     $revoke_grant_url = 'sql.php'
  125.                                       . '?' . $url_query
  126.                                       . '&sql_query=' . urlencode('REVOKE GRANT OPTION ON ' . PMA_backquote($db) . '.' . PMA_backquote($table) . ' FROM \'' . $row['User'] . '\'@\'' . $row['Host'] . '\'')
  127.                                       . '&zero_rows=' . urlencode(sprintf($GLOBALS['strRevokeGrantMessage'], ' <span style="color: #002E80">' . $row['User'] . '@' . $row['Host'] . '</span>') . '<br />' . $GLOBALS['strRememberReload'])
  128.                                       . '&goto=user_details.php';
  129.                 }
  130.                 ?>
  131. <tr>
  132.                 <?php
  133.                 if (!$dbcheck) {
  134.                     if ($priv) {
  135.                         echo "\n";
  136.                         ?>
  137.     <td<?php if (!$grantopt) echo ' colspan="2"'; ?> bgcolor="<?php echo $bgcolor; ?>">
  138.         <a href="<?php echo $revoke_url; ?>">
  139.             <?php echo $GLOBALS['strRevokePriv']; ?></a>
  140.     </td>
  141.                         <?php
  142.                     }
  143.                     if ($grantopt) {
  144.                         echo "\n";
  145.                         ?>
  146.     <td<?php if (!$priv) echo ' colspan="2"'; ?> bgcolor="<?php echo $bgcolor; ?>">
  147.         <a href="<?php echo $revoke_grant_url; ?>">
  148.             <?php echo $GLOBALS['strRevokeGrant']; ?></a>
  149.     </td>
  150.                         <?php
  151.                     }
  152.                 } else {
  153.                     if ($priv) {
  154.                         echo "\n";
  155.                         ?>
  156.     <td bgcolor="<?php echo $bgcolor; ?>">
  157.         <a href="<?php echo $revoke_url; ?>">
  158.             <?php echo $GLOBALS['strRevoke']; ?></a>
  159.     </td>
  160.                         <?php
  161.                     } else {
  162.                         echo "\n";
  163.                         ?>
  164.     <td bgcolor="<?php echo $bgcolor; ?>"> </td>
  165.                         <?php
  166.                     }
  167.                     echo "\n";
  168.                     ?>
  169.     <td bgcolor="<?php echo $bgcolor; ?>"><?php echo $row['Host']; ?></td>
  170.     <td bgcolor="<?php echo $bgcolor; ?>"><?php echo ($row['User']) ? $row['User'] : '<span style="color: #FF0000">' . $GLOBALS['strAny'] . '</span>'; ?></td>
  171.                     <?php
  172.                 }
  173.                 echo "\n";
  174.                 ?>
  175.     <td bgcolor="<?php echo $bgcolor; ?>"><?php echo ($db == '*') ? '<span style="color: #002E80">' . $GLOBALS['strAll'] . '</span>' : $db; ?></td>
  176.     <td bgcolor="<?php echo $bgcolor; ?>"><?php echo ($table == '*') ? '<span style="color: #002E80">' . $GLOBALS['strAll'] . '</span>' : $table; ?></td>
  177.     <td bgcolor="<?php echo $bgcolor; ?>"><?php echo ($priv != '') ? $priv : '<span style="color: #002E80">' . $GLOBALS['strNoPrivileges'] . '</span>'; ?></td>
  178.                 <?php
  179.                 if (!$dbcheck) {
  180.                     echo "\n";
  181.                     ?>
  182.     <td bgcolor="<?php echo $bgcolor; ?>"><?php echo ($grantopt) ? $GLOBALS['strYes'] : $GLOBALS['strNo']; ?></td>
  183.                     <?php
  184.                 }
  185.                 echo "\n";
  186.                 ?>
  187.     <!-- Debug <td bgcolor="<?php echo $bgcolor; ?>"><?php echo $usr_row[0] ?></td> Debug -->
  188. </tr>
  189.                 <?php
  190.                 $i++;
  191.                 echo "\n";
  192.             } // end while $usr_row
  193.         } // end if $grants_cnt >0
  194.         // $host_db_result is an array containing related to only one user
  195.         // -> exit the loop
  196.         if (is_array($host_db_result)) {
  197.             break;
  198.         }
  199.     } // end while $row
  200.     ?>
  201. </table>
  202. <hr />
  203.  
  204.     <?php
  205.     echo "\n";
  206.  
  207.     return TRUE;
  208. } // end of the 'PMA_tableGrants()' function
  209.  
  210.  
  211. /**
  212.  * Displays the list of grants for a/all database/s
  213.  *
  214.  * @param   mixed    the database to check garnts for, FALSE for all databases
  215.  *
  216.  * @return  boolean  true/false in case of success/failure
  217.  *
  218.  * @see     PMA_tableGrants()
  219.  */
  220. function PMA_checkDb($dbcheck)
  221. {
  222.     $local_query  = 'SELECT Host, User FROM mysql.user ORDER BY Host, User';
  223.     $result       = mysql_query($local_query);
  224.     $host_usr_cnt = @mysql_num_rows($result);
  225.  
  226.     if (!$host_usr_cnt) {
  227.         return FALSE;
  228.     }
  229.     PMA_tableGrants($result, $dbcheck);
  230.  
  231.     return TRUE;
  232. } // end of the 'PMA_checkDb()' function
  233.  
  234.  
  235. /**
  236.  * Displays the privileges part of a page
  237.  *
  238.  * @param   string   the name of the form for js validation
  239.  * @param   array    the list of the privileges of the user
  240.  *
  241.  * @return  boolean  always true
  242.  *
  243.  * @global  integer  whether all/none of the privileges have to be checked or
  244.  *                   not
  245.  *
  246.  * @see     PMA_normalOperations()
  247.  */
  248. function PMA_tablePrivileges($form, $row = FALSE)
  249. {
  250.     global $checkpriv;
  251.  
  252.     $checkpriv_url               = $GLOBALS['cfgPmaAbsoluteUri']
  253.                                  . 'user_details.php?';
  254.     if (empty($GLOBALS['QUERY_STRING'])) {
  255.         $GLOBALS['QUERY_STRING'] = (isset($_SERVER))
  256.                                  ? $_SERVER['QUERY_STRING']
  257.                                  : $GLOBALS['HTTP_SERVER_VARS']['QUERY_STRING'];
  258.     }
  259.     if (!empty($GLOBALS['QUERY_STRING'])) {
  260.         $checkpriv_url           .= $GLOBALS['QUERY_STRING'] . '&';
  261.     }
  262.     ?>
  263.  
  264.             <table>
  265.     <?php
  266.     echo "\n";
  267.     $list_priv = array('Select', 'Insert', 'Update', 'Delete', 'Create', 'Drop', 'Reload',
  268.                        'Shutdown', 'Process', 'File', 'Grant', 'References', 'Index', 'Alter');
  269.     $item      = 0;
  270.     while ((list(,$priv) = each($list_priv)) && ++$item) {
  271.         $priv_priv   = $priv . '_priv';
  272.         if (isset($checkpriv)) {
  273.             $checked = ($checkpriv == 'all') ?  ' checked="checked"' : '';
  274.         } else {
  275.             $checked = ($row && $row[$priv_priv] == 'Y') ?  ' checked="checked"' : '';
  276.         }
  277.         if ($item % 2 == 1) {
  278.             echo '            <tr>' . "\n";
  279.         } else {
  280.             echo '                <td> </td>' . "\n";
  281.         }
  282.         echo '                <td>' . "\n";
  283.         echo '                    <input type="checkbox" name="' . $priv . '_priv"' . $checked . ' />' . "\n";
  284.         echo '                </td>' . "\n";
  285.         echo '                <td>' . $priv . '</td>' . "\n";
  286.         if ($item % 2 == 0) {
  287.             echo '            </tr>' . "\n";
  288.         }
  289.     } // end while
  290.     if ($item % 2 == 1) {
  291.         echo '                <td colspan="2"> <td>' . "\n";
  292.         echo '            </tr>' . "\n";
  293.     } // end if
  294.     ?>
  295.             </table>
  296.             <table>
  297.             <tr>
  298.                 <td>
  299.                     <a href="<?php echo $checkpriv_url; ?>checkpriv=all" onclick="checkForm('<?php echo $form; ?>', true); return false">
  300.                         <?php echo $GLOBALS['strCheckAll']; ?></a>
  301.                 </td>
  302.                 <td> </td>
  303.                 <td>
  304.                     <a href="<?php echo $checkpriv_url; ?>checkpriv=none" onclick="checkForm('<?php echo $form; ?>', false); return false">
  305.                         <?php echo $GLOBALS['strUncheckAll']; ?></a>
  306.                 </td>
  307.             </tr>
  308.             </table>
  309.     <?php
  310.     echo "\n";
  311.  
  312.     return TRUE;
  313. } // end of the 'PMA_tablePrivileges()' function
  314.  
  315.  
  316. /**
  317.  * Displays the page for "normal" operations
  318.  *
  319.  * @return  boolean  always true
  320.  *
  321.  * @global  string   the current language
  322.  * @global  integer  the server to use (refers to the number in the
  323.  *                   configuration file)
  324.  *
  325.  * @see     PMA_tablePrivileges()
  326.  */
  327. function PMA_normalOperations()
  328. {
  329.     global $lang, $server;
  330.     ?>
  331.  
  332. <ul>
  333.  
  334.     <li>
  335.         <div style="margin-bottom: 10px">
  336.         <a href="user_details.php?lang=<?php echo $lang; ?>&server=<?php echo $server; ?>&db=mysql&table=user&mode=reload">
  337.             <?php echo $GLOBALS['strReloadMySQL']; ?></a> 
  338.         <?php echo PMA_showDocuShort('F/L/FLUSH.html') . "\n"; ?>
  339.         </div>
  340.     </li>
  341.  
  342.     <li>
  343.         <form name="dbPrivForm" action="user_details.php" method="post">
  344.             <?php echo $GLOBALS['strCheckDbPriv'] . "\n"; ?>
  345.             <table>
  346.             <tr>
  347.                 <td>
  348.                     <?php echo $GLOBALS['strDatabase']; ?> : 
  349.                     <select name="db">
  350.     <?php
  351.     echo "\n";
  352.     $result = mysql_query('SHOW DATABASES');
  353.     if (@mysql_num_rows($result)) {
  354.         while ($row = mysql_fetch_row($result)) {
  355.             echo '                        ';
  356.             echo '<option value="' . str_replace('"', '"', $row[0]) . '">' . htmlspecialchars($row[0]) . '</option>' . "\n";
  357.         } // end while
  358.     } // end if
  359.     ?>
  360.                     </select>
  361.                     <input type="hidden" name="lang" value="<?php echo $lang; ?>" />
  362.                     <input type="hidden" name="server" value="<?php echo $server; ?>" />
  363.                     <input type="hidden" name="check" value="1" />
  364.                     <input type="submit" value="<?php echo $GLOBALS['strGo']; ?>" />
  365.                 </td>
  366.             </tr>
  367.             </table>
  368.         </form>
  369.     </li>
  370.  
  371.     <li>
  372.         <form action="user_details.php" method="post" name="addUserForm" onsubmit="return checkAddUser()">
  373.             <?php echo $GLOBALS['strAddUser'] . "\n"; ?>
  374.             <table>
  375.             <tr>
  376.                 <td>
  377.                     <input type="radio" name="anyhost" checked="checked" />
  378.                     <?php echo $GLOBALS['strAnyHost'] . "\n"; ?>
  379.                 </td>
  380.                 <td> </td>
  381.                 <td>
  382.                     <input type="radio" name="anyhost" />
  383.                     <?php echo $GLOBALS['strHost']; ?> : 
  384.                 </td>
  385.                 <td>
  386.                     <input type="text" name="host" size="10" onchange="this.form.anyhost[1].checked = true" />
  387.                 </td>
  388.             </tr>
  389.             <tr>
  390.                 <td>
  391.                     <input type="radio" name="anyuser" />
  392.                     <?php echo $GLOBALS['strAnyUser']; ?>
  393.                 </td>
  394.                 <td> </td>
  395.                 <td>
  396.                     <input type="radio" name="anyuser" checked="checked" />
  397.                     <?php echo $GLOBALS['strUserName']; ?> : 
  398.                 </td>
  399.                 <td>
  400.                     <input type="text" name="pma_user" size="10" onchange="this.form.anyuser[1].checked = true" />
  401.                 </td>
  402.             </tr>
  403.             <tr>
  404.                 <td>
  405.                     <input type="radio" name="nopass" value="1" onclick="pma_pw.value = ''; pma_pw2.value = ''" />
  406.                     <?php echo $GLOBALS['strNoPassword'] . "\n"; ?>
  407.                 </td>
  408.                 <td> </td>
  409.                 <td>
  410.                     <input type="radio" name="nopass" value="0" checked="checked" />
  411.                     <?php echo $GLOBALS['strPassword']; ?> : 
  412.                 </td>
  413.                 <td>
  414.                     <input type="password" name="pma_pw" size="10" onchange="nopass[1].checked = true" />
  415.                       
  416.                     <?php echo $GLOBALS['strReType']; ?> : 
  417.                     <input type="password" name="pma_pw2" size="10" onchange="nopass[1].checked = true" />
  418.                 </td>
  419.             </tr>
  420.             <tr>
  421.                 <td colspan="4">
  422.                     <br />
  423.                     <?php echo $GLOBALS['strPrivileges']; ?> :
  424.                     <br />
  425.                 </td>
  426.             </tr>
  427.             </table>
  428.     <?php
  429.     echo "\n";
  430.     PMA_tablePrivileges('addUserForm');
  431.     ?>
  432.             <input type="hidden" name="lang" value="<?php echo $lang; ?>" />
  433.             <input type="hidden" name="server" value="<?php echo $server; ?>" />
  434.             <input type="submit" name="submit_addUser" value="<?php echo $GLOBALS['strGo']; ?>" />
  435.         </form>
  436.     </li>
  437.  
  438. </ul>
  439.     <?php
  440.  
  441.     return TRUE;
  442. } // end of the 'PMA_normalOperations()' function
  443.  
  444.  
  445. /**
  446.  * Displays the grant operations part of an user properties page
  447.  *
  448.  * @param   array    grants of the current user
  449.  *
  450.  * @return  boolean  always true
  451.  *
  452.  * @global  string   the current language
  453.  * @global  integer  the server to use (refers to the number in the
  454.  *                   configuration file)
  455.  * @global  string   the host name to check grants for
  456.  * @global  string   the username to check grants for
  457.  * @global  string   the database to check grants for
  458.  * @global  string   the table to check grants for
  459.  *
  460.  * @see     PMA_tablePrivileges()
  461.  */
  462. function PMA_grantOperations($grants)
  463. {
  464.     global $lang, $server, $host, $pma_user;
  465.     global $dbgrant, $tablegrant;
  466.     ?>
  467.  
  468. <ul>
  469.  
  470.     <li>
  471.         <div style="margin-bottom: 10px">
  472.         <a href="user_details.php?lang=<?php echo $lang; ?>&server=<?php echo $server; ?>&db=mysql&table=user">
  473.             <?php echo $GLOBALS['strBack']; ?></a>
  474.         </div>
  475.     </li>
  476.  
  477.     <li>
  478.         <form action="user_details.php" method="post" name="userGrants">
  479.             <input type="hidden" name="lang" value="<?php echo $lang; ?>" />
  480.             <input type="hidden" name="server" value="<?php echo $server; ?>" />
  481.             <input type="hidden" name="grants" value="1" />
  482.             <input type="hidden" name="host" value="<?php echo str_replace('"', '"', $host); ?>" />
  483.             <input type="hidden" name="pma_user" value="<?php echo str_replace('"', '"', $pma_user); ?>" />
  484.  
  485.             <?php echo $GLOBALS['strAddPriv'] . "\n"; ?>
  486.             <table>
  487.             <tr>
  488.                 <td>
  489.                     <input type="radio" name="anydb" value="1"<?php echo ($dbgrant) ? '' : ' checked="checked"'; ?> />
  490.                     <?php echo $GLOBALS['strAnyDatabase'] . "\n"; ?>
  491.                 </td>
  492.                 <td>   </td>
  493.                 <td>
  494.                     <input type="radio" name="anydb" value="0"<?php echo ($dbgrant) ? ' checked="checked"' : ''; ?> />
  495.                     <?php echo $GLOBALS['strDatabase']; ?> : 
  496.                 </td>
  497.                 <td>
  498.                     <select name="dbgrant" onchange="change(this)">
  499.                         <option></option>
  500.     <?php
  501.     echo "\n";
  502. //    if (!isset($dbgrant)) {
  503. //        echo '                        ';
  504. //        echo '<option></option>' . "\n";
  505. //    }
  506.     $result = mysql_query('SHOW DATABASES');
  507.     if (@mysql_num_rows($result)) {
  508.         while ($row = mysql_fetch_row($result)) {
  509.             $selected = (($row[0] == $dbgrant) ? ' selected="selected"' : '');
  510.             echo '                        ';
  511.             echo '<option' . $selected . '>' . $row[0] . '</option>' . "\n";
  512.         } // end while
  513.     } // end if
  514.     ?>
  515.                     </select>
  516.                 </td>
  517.                 <td>
  518.                      
  519.                     <input type="submit" value="<?php echo $GLOBALS['strShowTables']; ?>" />
  520.                 </td>
  521.             </tr>
  522.             <tr>
  523.                 <td>
  524.                     <input type="radio" name="anytable" value="1"<?php echo ($tablegrant) ? '' : ' checked="checked"'; ?> />
  525.                     <?php echo $GLOBALS['strAnyTable'] . "\n"; ?>
  526.                 </td>
  527.                 <td>   </td>
  528.                 <td>
  529.                     <input type="radio" name="anytable" value="0"<?php echo ($tablegrant) ? ' checked="checked"' : ''; ?> />
  530.                     <?php echo $GLOBALS['strTable']; ?> : 
  531.                 </td>
  532.                 <td>
  533.                     <select name="tablegrant" onchange="change(this)">
  534.                         <option></option>
  535.     <?php
  536.     echo "\n";
  537. //    if (!isset($tablegrant)) {
  538. //        echo '                        ';
  539. //        echo '<option></option>' . "\n";
  540. //    }
  541.     if (isset($dbgrant)) {
  542.         $result = mysql_query('SHOW TABLES FROM ' . PMA_backquote($dbgrant));
  543.         if (@mysql_num_rows($result)) {
  544.             while ($row = mysql_fetch_row($result)) {
  545.                 $selected = ((isset($tablegrant) && $row[0] == $tablegrant) ? ' selected="selected"' : '');
  546.                 echo '                        ';
  547.                 echo '<option' . $selected . '>' . $row[0] . '</option>' . "\n";
  548.             } // end while
  549.         } // end if
  550.     } // end if
  551.     ?>
  552.                     </select>
  553.                 </td>
  554.                 <td>
  555.                      
  556.                     <input type="submit" value="<?php echo $GLOBALS['strShowCols']; ?>" />
  557.                 </td>
  558.             </tr>
  559.             <tr>
  560.                 <td valign="top">
  561.                     <input type="radio" name="anycolumn" value="1" checked="checked" />
  562.                     <?php echo $GLOBALS['strAnyColumn'] . "\n"; ?>
  563.                 </td>
  564.                 <td>   </td>
  565.                 <td valign="top">
  566.                     <input type="radio" name="anycolumn" value="0" />
  567.                     <?php echo $GLOBALS['strColumn']; ?> : 
  568.                 </td>
  569.                 <td>
  570.     <?php
  571.     echo "\n";
  572.     if (!isset($dbgrant) || !isset($tablegrant)) {
  573.         echo '                    ' . '<select name="colgrant[]">' . "\n";
  574.         echo '                        ' . '<option></option>' . "\n";
  575.         echo '                    ' . '</select>' . "\n";
  576.     }
  577.     else {
  578.         $result = mysql_query('SHOW COLUMNS FROM ' . PMA_backquote($dbgrant) . '.' . PMA_backquote($tablegrant));
  579.         if (@mysql_num_rows($result)) {
  580.             echo '                    '
  581.                  . '<select name="colgrant[]" multiple="multiple" onchange="anycolumn[1].checked = true">' . "\n";
  582.             while ($row = mysql_fetch_row($result)) {
  583.                 echo '                        ';
  584.                 echo '<option value="' . str_replace('"', '"', $row[0]) . '">' . $row[0] . '</option>' . "\n";
  585.             } // end while
  586.         } else {
  587.             echo '                    ' . '<select name="colgrant[]">' . "\n";
  588.             echo '                        ' . '<option></option>' . "\n";
  589.         } // end if... else...
  590.         echo '                    '
  591.              . '</select>' . "\n";
  592.     } // end if... else
  593.     ?>
  594.                 </td>
  595.                 <td></td>
  596.             </tr>
  597.             </table>
  598.  
  599.             <table>
  600.             <tr>
  601.                 <td>
  602.                     <br />
  603.                     <?php echo $GLOBALS['strPrivileges']; ?> : 
  604.                     <br />
  605.                 </td>
  606.             </tr>
  607.             </table>
  608.     <?php
  609.     echo "\n";
  610.     PMA_tablePrivileges('userGrants', $grants);
  611.     ?>
  612.             <input type="submit" name="upd_grants" value="<?php echo $GLOBALS['strGo']; ?>" />
  613.         </form>
  614.     </li>
  615.  
  616. </ul>
  617.     <?php
  618.     echo "\n";
  619.  
  620.     return TRUE;
  621. } // end of the 'PMA_grantOperations()' function
  622.  
  623.  
  624. /**
  625.  * Displays the page to edit operations
  626.  *
  627.  * @param   string   the host name to check grants for
  628.  * @param   string   the user name to check grants for
  629.  *
  630.  * @return  boolean  always true
  631.  *
  632.  * @global  string   the current language
  633.  * @global  integer  the server to use (refers to the number in the
  634.  *                   configuration file)
  635.  *
  636.  * @see     PMA_tablePrivileges()
  637.  */
  638. function PMA_editOperations($host, $user)
  639. {
  640.     global $lang, $server;
  641.  
  642.     $result = mysql_query('SELECT * FROM mysql.user WHERE User = \'' . PMA_sqlAddslashes($user) . '\' AND Host = \'' . PMA_sqlAddslashes($host) . '\'');
  643.     $rows   = @mysql_num_rows($result);
  644.  
  645.     if (!$rows) {
  646.         return FALSE;
  647.     }
  648.  
  649.     $row = mysql_fetch_array($result);
  650.     ?>
  651.  
  652. <ul>
  653.  
  654.     <li>
  655.         <div style="margin-bottom: 10px">
  656.         <a href="user_details.php?lang=<?php echo $lang; ?>&server=<?php echo $server; ?>&db=mysql&table=user">
  657.             <?php echo $GLOBALS['strBack']; ?></a>
  658.         </div>
  659.     </li>
  660.  
  661.     <li>
  662.         <form action="user_details.php" method="post" name="updUserForm" onsubmit="return checkUpdProfile()">
  663.             <?php echo $GLOBALS['strUpdateProfile'] . "\n"; ?>
  664.             <table>
  665.             <tr>
  666.                 <td>
  667.                     <input type="radio" value="1" name="anyhost"<?php if ($host == '' || $host == '%') echo ' checked="checked"'; ?> />
  668.                     <?php echo $GLOBALS['strAnyHost'] . "\n"; ?>
  669.                 </td>
  670.                 <td> </td>
  671.                 <td>
  672.                     <input type="radio" value="0" name="anyhost"<?php if ($host != '' && $host != '%') echo ' checked="checked"'; ?> />
  673.                     <?php echo $GLOBALS['strHost']; ?> : 
  674.                 </td>
  675.                 <td>
  676.                     <input type="text" name="new_server" size="10" value="<?php echo str_replace('"', '"', $host); ?>" onchange="this.form.anyhost[1].checked = true" />
  677.                 </td>
  678.             </tr>
  679.             <tr>
  680.                 <td>
  681.                     <input type="radio" value="1" name="anyuser"<?php if ($user == '' || $user == '%') echo ' checked="checked"'; ?> />
  682.                     <?php echo $GLOBALS['strAnyUser']; ?>
  683.                 </td>
  684.                 <td> </td>
  685.                 <td>
  686.                     <input type="radio" value="0" name="anyuser" checked="checked"<?php if ($user != '' && $user != '%') echo ' checked="checked"'; ?> />
  687.                     <?php echo $GLOBALS['strUserName']; ?> : 
  688.                 </td>
  689.                 <td>
  690.                     <input type="text" name="new_user" size="10" value="<?php echo str_replace('"', '"', $user); ?>" onchange="this.form.anyuser[1].checked = true" />
  691.                 </td>
  692.             </tr>
  693.             <tr>
  694.                 <td>
  695.                     <input type="radio" name="nopass" value="-1" checked="checked" onclick="new_pw.value = ''; new_pw2.value = ''" />
  696.                     <?php echo $GLOBALS['strKeepPass'] . "\n"; ?>
  697.                 </td>
  698.                 <td colspan="3"> </td>
  699.             </tr>
  700.             <tr>
  701.                 <td colspan="4" align="<?php echo $GLOBALS['cell_align_left']; ?>">      <?php echo $GLOBALS['strOr']; ?></td>
  702.             </tr>
  703.             <tr>
  704.                 <td>
  705.                     <input type="radio" name="nopass" value="1" onclick="new_pw.value = ''; new_pw2.value = ''" />
  706.                     <?php echo $GLOBALS['strNoPassword'] . "\n"; ?>
  707.                 </td>
  708.                 <td> </td>
  709.                 <td>
  710.                     <input type="radio" name="nopass" value="0" />
  711.                     <?php echo $GLOBALS['strPassword']; ?> : 
  712.                 </td>
  713.                 <td>
  714.                     <input type="password" name="new_pw" size="10" onchange="nopass[2].checked = true" />
  715.                       
  716.                     <?php echo $GLOBALS['strReType']; ?> : 
  717.                     <input type="password" name="new_pw2" size="10" onchange="nopass[2].checked = true" />
  718.                 </td>
  719.             </tr>
  720.             </table>
  721.             <input type="hidden" name="lang" value="<?php echo $lang; ?>" />
  722.             <input type="hidden" name="server" value="<?php echo $server; ?>" />
  723.             <input type="hidden" name="host" value="<?php echo str_replace('"', '"', $host); ?>" />
  724.             <input type="hidden" name="pma_user" value="<?php echo str_replace('"', '"', $user); ?>" />
  725.             <input type="submit" name="submit_updProfile" value="<?php echo $GLOBALS['strGo']; ?>" />
  726.         </form>
  727.     </li>
  728.  
  729.     <li>
  730.         <form action="user_details.php" method="post" name="privForm">
  731.             <?php echo $GLOBALS['strEditPrivileges'] . "\n"; ?>
  732.     <?php
  733.     PMA_tablePrivileges('privForm', $row);
  734.     echo "\n";
  735.     ?>
  736.             <input type="hidden" name="lang" value="<?php echo $lang; ?>" />
  737.             <input type="hidden" name="server" value="<?php echo $server; ?>" />
  738.             <input type="hidden" name="host" value="<?php echo str_replace('"', '"', $host); ?>" />
  739.             <input type="hidden" name="pma_user" value="<?php echo str_replace('"', '"', $user); ?>" />
  740.             <input type="submit" name="submit_chgPriv" value="<?php echo $GLOBALS['strGo']; ?>" />
  741.         </form>
  742.     </li>
  743.  
  744. </ul>
  745.     <?php
  746.     echo "\n";
  747.  
  748.     return TRUE;
  749. } // end of the 'PMA_editOperations()' function
  750.  
  751.  
  752. /**
  753.  * Displays the table of the users
  754.  *
  755.  * @param   string   the host name
  756.  * @param   string   the user name
  757.  *
  758.  * @return  boolean  always true
  759.  *
  760.  * @global  string   the current language
  761.  * @global  integer  the server to use (refers to the number in the
  762.  *                   configuration file)
  763.  */
  764. function PMA_tableUsers($host = FALSE, $user = FALSE)
  765. {
  766.     global $lang, $server;
  767.  
  768.     $local_query     = 'SELECT * FROM mysql.user ';
  769.     if ($host || $user) {
  770.         $local_query .= ' WHERE 1 ';
  771.     }
  772.     if ($host) {
  773.         $local_query .= ' AND Host = \'' . PMA_sqlAddslashes($host) . '\'';
  774.         $local_query .= ' AND User = \'' . PMA_sqlAddslashes($user) . '\'';
  775.     }
  776.     $local_query     .= ' ORDER BY Host, User';
  777.     $result          = mysql_query($local_query);
  778.     $rows            = @mysql_num_rows($result);
  779.  
  780.     if (!$rows) {
  781.         return FALSE;
  782.     }
  783.  
  784.     echo '<i>' . $GLOBALS['strEnglishPrivileges'] . '</i><br />' . "\n";
  785.     echo '<table border="' . $GLOBALS['cfgBorder'] . '">' . "\n";
  786.     echo '<tr>' . "\n";
  787.     echo '    <th colspan="'. (($user) ? '2' : '3') . '">' . $GLOBALS['strAction'] . '</th>' . "\n";
  788.     echo '    <th>' . $GLOBALS['strHost'] . '</th>' . "\n";
  789.     echo '    <th>' . $GLOBALS['strUser'] . '</th>' . "\n";
  790.     echo '    <th>' . $GLOBALS['strPassword'] . '</th>' . "\n";
  791.     echo '    <th>' . $GLOBALS['strPrivileges'] . '</th>' . "\n";
  792.     echo '</tr>' . "\n";
  793.  
  794.     $i = 0;
  795.     while ($row = mysql_fetch_array($result)) {
  796.  
  797.         $bgcolor = ($i % 2) ? $GLOBALS['cfgBgcolorOne'] : $GLOBALS['cfgBgcolorTwo'];
  798.  
  799.         $strPriv     = '';
  800.         if ($row['Select_priv'] == 'Y') {
  801.             $strPriv .= 'Select ';
  802.         }
  803.         if ($row['Insert_priv'] == 'Y') {
  804.             $strPriv .= 'Insert ';
  805.         }
  806.         if ($row['Update_priv'] == 'Y') {
  807.             $strPriv .= 'Update ';
  808.         }
  809.         if ($row['Delete_priv'] == 'Y') {
  810.             $strPriv .= 'Delete ';
  811.         }
  812.         if ($row['Create_priv'] == 'Y') {
  813.             $strPriv .= 'Create ';
  814.         }
  815.         if ($row['Drop_priv'] == 'Y') {
  816.             $strPriv .= 'Drop ';
  817.         }
  818.         if ($row['Reload_priv'] == 'Y') {
  819.             $strPriv .= 'Reload ';
  820.         }
  821.         if ($row['Shutdown_priv'] == 'Y') {
  822.             $strPriv .= 'Shutdown ';
  823.         }
  824.         if ($row['Process_priv'] == 'Y') {
  825.             $strPriv .= 'Process ';
  826.         }
  827.         if ($row['File_priv'] == 'Y') {
  828.             $strPriv .= 'File ';
  829.         }
  830.         if ($row['Grant_priv'] == 'Y') {
  831.             $strPriv .= 'Grant ';
  832.         }
  833.         if ($row['References_priv'] == 'Y') {
  834.             $strPriv .= 'References ';
  835.         }
  836.         if ($row['Index_priv'] == 'Y') {
  837.             $strPriv .= 'Index ';
  838.         }
  839.         if ($row['Alter_priv'] == 'Y') {
  840.             $strPriv .= 'Alter ';
  841.         }
  842.         if ($strPriv == '') {
  843.             $strPriv = '<span style="color: #002E80">' . $GLOBALS['strNoPrivileges'] . '</span>';
  844.         }
  845.  
  846.         $query          = 'lang=' . $lang . '&server=' . $server . '&db=mysql&table=user';
  847.         if (!$user) {
  848.             $edit_url   = 'user_details.php'
  849.                         . '?lang=' . $lang . '&server=' . $server
  850.                         . '&edit=1&host=' . urlencode($row['Host']) . '&pma_user=' . urlencode($row['User']);
  851.         }
  852.         $delete_url     = 'user_details.php'
  853.                         . '?' . $query
  854.                         . '&delete=1&confirm=1&delete_host=' . urlencode($row['Host']) . '&delete_user=' . urlencode($row['User']);
  855.         $check_url      = 'user_details.php'
  856.                         . '?lang=' . $lang . '&server=' . $server
  857.                         . '&grants=1&host=' . urlencode($row['Host']) . '&pma_user=' . urlencode($row['User']);
  858.  
  859. //        $check_result = mysql_query('SHOW GRANTS FOR \'' . $row['User'] . '\'@\'' . $row['Host'] . '\'');
  860. //        if (@mysql_num_rows($check_result) == 0) {
  861. //            $check_url = '';
  862. //        }
  863.         ?>
  864.  
  865. <tr>
  866.         <?php
  867.         if (!$user) {
  868.             echo "\n";
  869.             ?>
  870.     <td bgcolor="<?php echo $bgcolor;?>">
  871.         <a href="<?php echo $edit_url; ?>">
  872.             <?php echo $GLOBALS['strEdit']; ?></a>
  873.     </td>
  874.             <?php
  875.         }
  876.         echo "\n";
  877.         ?>
  878.     <td bgcolor="<?php echo $bgcolor;?>">
  879.         <a href="<?php echo $delete_url; ?>">
  880.             <?php echo $GLOBALS['strDelete']; ?></a>
  881.     </td>
  882.     <td bgcolor="<?php echo $bgcolor;?>">
  883.         <a href="<?php echo $check_url; ?>">
  884.             <?php echo $GLOBALS['strGrants']; ?></a>
  885.     </td>
  886. <!--
  887.     <td bgcolor="<?php echo $bgcolor;?>">
  888.         <a href="<?php echo (($check_url != '') ? $check_url : '#'); ?>">
  889.             <?php echo $GLOBALS['strGrants']; ?></a>
  890.     </td>
  891. //-->
  892.     <td bgcolor="<?php echo $bgcolor;?>">
  893.         <?php echo $row['Host'] . "\n"; ?>
  894.     </td>
  895.     <td bgcolor="<?php echo $bgcolor;?>">
  896.         <?php echo (($row['User']) ? '<b>' . $row['User'] . '</b>' : '<span style="color: #FF0000">' . $GLOBALS['strAny'] . '</span>') . "\n"; ?>
  897.     </td>
  898.     <td bgcolor="<?php echo $bgcolor;?>">
  899.         <?php echo (($row[$GLOBALS['password_field']]) ? $GLOBALS['strYes'] : '<span style="color: #FF0000">' . $GLOBALS['strNo'] . '</span>') . "\n"; ?>
  900.     </td>
  901.     <td bgcolor="<?php echo $bgcolor;?>">
  902.         <?php echo $strPriv . "\n"; ?>
  903.     </td>
  904. </tr>
  905.         <?php
  906.         echo "\n";
  907.         $i++;
  908.     } //  end while
  909.  
  910.     echo "\n";
  911.     ?>
  912. </table>
  913. <hr />
  914.     <?php
  915.     echo "\n";
  916.  
  917.     return TRUE;
  918. } // end of the 'PMA_tableUsers()' function
  919.  
  920.  
  921. /**
  922.  * Displays a confirmation form
  923.  *
  924.  * @param   string   the host name and...
  925.  * @param   string   ... the username to delete
  926.  *
  927.  * @global  string   the current language
  928.  * @global  integer  the server to use (refers to the number in the
  929.  *                   configuration file)
  930.  */
  931. function PMA_confirm($the_host, $the_user) {
  932.     global $lang, $server;
  933.  
  934.     if (get_magic_quotes_gpc() == 1) {
  935.         $the_host = stripslashes($the_host);
  936.         $the_user = stripslashes($the_user);
  937.     }
  938.  
  939.     echo $GLOBALS['strConfirm'] . ' : <br />' . "\n";
  940.     echo 'DELETE FROM mysql.user WHERE Host = \'' . $the_host . '\' AND User = \'' . $the_user . '\'' . '<br />' . "\n";
  941.     ?>
  942. <form action="user_details.php" method="post">
  943.     <input type="hidden" name="lang" value="<?php echo $lang; ?>" />
  944.     <input type="hidden" name="server" value="<?php echo $server; ?>" />
  945.     <input type="hidden" name="db" value="mysql" />
  946.     <input type="hidden" name="table" value="user" />
  947.     <input type="hidden" name="delete" value="<?php echo(isset($GLOBALS['delete']) ? '1' : '0'); ?>" />
  948.     <input type="hidden" name="delete_host" value="<?php echo str_replace('"', '"', $the_host); ?>" />
  949.     <input type="hidden" name="delete_user" value="<?php echo str_replace('"', '"', $the_user); ?>" />
  950.     <input type="submit" name="btnConfirm" value="<?php echo $GLOBALS['strYes']; ?>" />
  951.     <input type="submit" name="btnConfirm" value="<?php echo $GLOBALS['strNo']; ?>" />
  952. </form>
  953.     <?php
  954.     echo "\n";
  955.  
  956.     include('./footer.inc.php');
  957. } // end of the 'PMA_confirm()' function
  958.  
  959.  
  960.  
  961. /**
  962.  * Ensures the user is super-user and gets the case sensitive password field
  963.  * name
  964.  */
  965. $result         = @mysql_query('USE mysql');
  966. if (mysql_error()) {
  967.     PMA_mysqlDie($GLOBALS['strNoRights'], '', FALSE, '');
  968. }
  969. $result         = @mysql_query('SELECT COUNT(Password) FROM mysql.user');
  970. $password_field = (mysql_result($result, 0) ? 'Password' : 'password');
  971.  
  972.  
  973. /**
  974.  * Displays headers
  975.  */
  976. if (isset($db)) {
  977.     $db_bkp       = (get_magic_quotes_gpc() ? stripslashes($db) : $db);
  978.     unset($db);
  979. }
  980. if (isset($table)) {
  981.     $table_bkp    =  (get_magic_quotes_gpc() ? stripslashes($table) : $table);
  982.     unset($table);
  983. }
  984. if (get_magic_quotes_gpc()) {
  985.     if (!empty($host)) {
  986.         $host     = stripslashes($host);
  987.     }
  988.     if (!empty($pma_user)) {
  989.         $pma_user = stripslashes($pma_user);
  990.     }
  991. }
  992.  
  993. if (!isset($message)) {
  994.     $js_to_run = 'user_details.js';
  995.     include('./header.inc.php');
  996. }
  997. if (!isset($submit_updProfile)) {
  998.     echo '<h1>' . "\n";
  999.     echo '    ' . ((!isset($host) || $host == '') ? $strAnyHost : $strHost . ' ' . $host) . ' - ' . ((!isset($pma_user) || $pma_user == '') ? $strAnyUser : $strUser . ' ' . $pma_user) . "\n";
  1000.     echo '</h1>';
  1001. }
  1002. if (isset($message)) {
  1003.     $show_query = 'y';
  1004.     PMA_showMessage($message);
  1005. }
  1006.  
  1007. if (isset($db_bkp)) {
  1008.     $db    = $db_bkp;
  1009.     unset($db_bkp);
  1010. }
  1011. if (isset($table_bkp)) {
  1012.     $table = $table_bkp;
  1013.     unset($table_bkp);
  1014. }
  1015.  
  1016.  
  1017. /**
  1018.  * Some actions has been submitted
  1019.  */
  1020. // Confirms an action
  1021. if (isset($confirm) && $confirm) {
  1022.     PMA_confirm($delete_host, $delete_user);
  1023.     exit();
  1024. }
  1025.  
  1026. // Reloads mysql
  1027. else if (($server > 0) && isset($mode) && ($mode == 'reload')) {
  1028.     $result = mysql_query('FLUSH PRIVILEGES');
  1029.     if ($result != 0) {
  1030.         echo '<p><b>' . $strMySQLReloaded . '</b></p>' . "\n";
  1031.     } else {
  1032.         echo '<p><b>' . $strReloadFailed . '</b></p>' . "\n";
  1033.     }
  1034. }
  1035.  
  1036. // Deletes an user
  1037. else if (isset($delete) && $delete
  1038.          && isset($btnConfirm) && $btnConfirm == $strYes) {
  1039.     if (get_magic_quotes_gpc()) {
  1040.         $delete_host = stripslashes($delete_host);
  1041.         $delete_user = stripslashes($delete_user);
  1042.     }
  1043.     $common_where    = ' WHERE Host = \'' . PMA_sqlAddslashes($delete_host) . '\' AND User = \'' . PMA_sqlAddslashes($delete_user) . '\'';
  1044.  
  1045.     // Delete Grants First!
  1046.     $sql_query       = 'DELETE FROM mysql.db' . $common_where;
  1047.     $sql_query_cpy   = $sql_query;
  1048.     mysql_query($sql_query);
  1049.     $sql_query       = 'DELETE FROM mysql.tables_priv' . $common_where;
  1050.     $sql_query_cpy   .= ";\n" . $sql_query;
  1051.     mysql_query($sql_query);
  1052.     $sql_query       = 'DELETE FROM mysql.columns_priv' . $common_where;
  1053.     $sql_query_cpy   .= ";\n" . $sql_query;
  1054.     mysql_query($sql_query);
  1055.  
  1056.     $sql_query       = 'DELETE FROM mysql.user' . $common_where;
  1057.     $sql_query_cpy   .= ";\n" . $sql_query;
  1058.     $result          = mysql_query($sql_query);
  1059.  
  1060.     $sql_query       = $sql_query_cpy;
  1061.     unset($sql_query_cpy);
  1062.     if ($result) {
  1063.         PMA_showMessage(sprintf($strDeleteUserMessage, '<span style="color: #002E80">' . $delete_user . '@' . $delete_host . '</span>') . '<br />' . $strRememberReload);
  1064.     } else {
  1065.         PMA_showMessage($strDeleteFailed);
  1066.     }
  1067. }
  1068.  
  1069. // Adds an user
  1070. else if (isset($submit_addUser)) {
  1071.     $show_query   = 'y';
  1072.     if (!isset($host) || $host == '') {
  1073.         $host     = '%';
  1074.     }
  1075.     if (!isset($pma_user) || $pma_user == '') {
  1076.         $pma_user = '%';
  1077.     }
  1078.  
  1079.     // Password is not confirmed
  1080.     if ((!isset($nopass) || !$nopass) && $pma_pw == '') {
  1081.         echo '<p><b>' . $strError . ' : ' . $strPasswordEmpty . '</b></p>' . "\n";
  1082.         unset($host);
  1083.         unset($pma_user);
  1084.     }
  1085.     else if ($pma_pw != ''
  1086.         && (!isset($pma_pw2) || $pma_pw != $pma_pw2)) {
  1087.         echo '<p><b>' . $strError . ' : ' . $strPasswordNotSame . '</b></p>' . "\n";
  1088.         unset($host);
  1089.         unset($pma_user);
  1090.     }
  1091.  
  1092.     // Password confirmed
  1093.     else {
  1094.         $sql_query = '';
  1095.         $list_priv = array('Select', 'Insert', 'Update', 'Delete', 'Create', 'Drop', 'Reload',
  1096.                            'Shutdown', 'Process', 'File', 'Grant', 'References', 'Index', 'Alter');
  1097.         for ($i = 0; $i < 14; $i++) {
  1098.             $priv_name = $list_priv[$i] . '_priv';
  1099.             if (isset($$priv_name)) {
  1100.                 $sql_query .= (empty($sql_query) ? $priv_name : ', ' . $priv_name) . ' = \'Y\'';
  1101.             } else  {
  1102.                 $sql_query .= (empty($sql_query) ? $priv_name : ', ' . $priv_name) . ' = \'N\'';
  1103.             }
  1104.         } // end for
  1105.         unset($list_priv);
  1106.  
  1107.         if (get_magic_quotes_gpc() && $pma_pw != '') {
  1108.             $pma_pw = stripslashes($pma_pw);
  1109.         }
  1110.  
  1111.         $sql_query  = 'INSERT INTO mysql.user '
  1112.                     . 'SET Host = \'' . PMA_sqlAddslashes($host) . '\', User = \'' . PMA_sqlAddslashes($pma_user) . '\', ' . $password_field . ' = ' . (($pma_pw == '') ? '\'\'' : 'PASSWORD(\'' . PMA_sqlAddslashes($pma_pw) . '\')')
  1113.                     . ', ' . $sql_query;
  1114.         $result     = @mysql_query($sql_query) or PMA_mysqlDie('', '', FALSE, $err_url);
  1115.         unset($host);
  1116.         unset($pma_user);
  1117.         PMA_showMessage($strAddUserMessage . '<br />' . $strRememberReload);
  1118.     } // end else
  1119. }
  1120.  
  1121. // Updates the profile of an user
  1122. else if (isset($submit_updProfile)) {
  1123.     $show_query     = 'y';
  1124.     $edit           = TRUE;
  1125.     if (!isset($host) || $host == '') {
  1126.         $host     = '%';
  1127.     }
  1128.     if (!isset($pma_user) || $pma_user == '') {
  1129.         $pma_user = '%';
  1130.     }
  1131.  
  1132.     // Builds the sql query
  1133.     $common_upd     = '';
  1134.  
  1135.     if (isset($anyhost) && $anyhost) {
  1136.         $new_server = '%';
  1137.     } else if ($new_server != '' && get_magic_quotes_gpc()) {
  1138.         $new_server = stripslashes($new_server);
  1139.     }
  1140.     if ($new_server != '' && $new_server != $host) {
  1141.         $common_upd .= 'Host = \'' . PMA_sqlAddslashes($new_server) . '\'';
  1142.     } else if (isset($new_server)) {
  1143.         unset($new_server);
  1144.     }
  1145.  
  1146.     if (isset($anyuser) && $anyuser) {
  1147.         $new_user   = '%';
  1148.     } else if ($new_user != '' && get_magic_quotes_gpc()) {
  1149.         $new_user   = stripslashes($new_user);
  1150.     }
  1151.     if ($new_user != '' && $new_user != $pma_user) {
  1152.         $common_upd .= (empty($common_upd) ? '' : ', ')
  1153.                     . 'User = \'' . PMA_sqlAddslashes($new_user) . '\'';
  1154.     } else if (isset($new_user)) {
  1155.         unset($new_user);
  1156.     }
  1157.  
  1158.     if (isset($nopass) && $nopass == -1) {
  1159.         $sql_query = $common_upd;
  1160.     }
  1161.     else if ((!isset($nopass) || $nopass == 0) && $new_pw == '') {
  1162.         echo '<h1>' . "\n";
  1163.         echo '    ' . $strHost . ' ' . $host . ' - ' . $strUser . ' ' . (($pma_user != '') ?  $pma_user : $strAny) . "\n";
  1164.         echo '</h1>' . "\n";
  1165.         echo '<p><b>' . $strError . ' : ' . $strPasswordEmpty . '</b></p>' . "\n";
  1166.     }
  1167.     else if ($new_pw != ''
  1168.         && (!isset($new_pw2) || $new_pw != $new_pw2)) {
  1169.         echo '<h1>' . "\n";
  1170.         echo '    ' . $strHost . ' ' . $host . ' - ' . $strUser . ' ' . (($pma_user != '') ?  $pma_user : $strAny) . "\n";
  1171.         echo '</h1>' . "\n";
  1172.         echo '<p><b>' . $strError . ' : ' . $strPasswordNotSame . '</b></p>' . "\n";
  1173.     }
  1174.     else {
  1175.         $sql_query = (empty($common_upd) ? '' : $common_upd . ', ')
  1176.                    . $password_field . ' = ' . (($new_pw == '') ? '\'\'' : 'PASSWORD(\'' . PMA_sqlAddslashes($new_pw) . '\')');
  1177.     }
  1178.     
  1179.     if (!empty($sql_query)) {
  1180.         $common_where       = ' WHERE Host = \'' . PMA_sqlAddslashes($host) . '\' AND User = \'' . PMA_sqlAddslashes($pma_user) . '\'';
  1181.         $sql_query_cpy      = '';
  1182.  
  1183.         // Updates profile
  1184.         $sql_query          = 'UPDATE user SET ' . $sql_query . $common_where;
  1185.         $sql_query_cpy      = $sql_query;
  1186.         $result             = @mysql_query($sql_query) or PMA_mysqlDie('', '', FALSE, $err_url . '&host=' . urlencode($host) . '&pma_user=' . urlencode($pma_user) . '&edit=1');
  1187.  
  1188.         // Updates grants
  1189.         if (isset($new_server) || isset($new_user)) {
  1190.             $sql_query      = 'UPDATE mysql.db SET ' . $common_upd . $common_where;
  1191.             $sql_query_cpy  .= ";\n" . $sql_query;
  1192.             mysql_query($sql_query);
  1193.             $sql_query      = 'UPDATE mysql.tables_priv SET ' . $common_upd . $common_where;
  1194.             $sql_query_cpy  .= ";\n" . $sql_query;
  1195.             mysql_query($sql_query);
  1196.             $sql_query      = 'UPDATE mysql.columns_priv SET ' . $common_upd . $common_where;
  1197.             $sql_query_cpy  .= ";\n" . $sql_query;
  1198.             mysql_query($sql_query);
  1199.             unset($common_upd);
  1200.         }
  1201.  
  1202.         $sql_query = $sql_query_cpy;
  1203.         unset($sql_query_cpy);
  1204.         if (isset($new_server)) {
  1205.             $host     = $new_server;
  1206.         }
  1207.         if (isset($new_user)) {
  1208.             $pma_user = $new_user;
  1209.         }
  1210.         echo '<h1>' . "\n";
  1211.         echo '    ' . $strHost . ' ' . $host . ' - ' . $strUser . ' ' . (($pma_user != '') ?  $pma_user : $strAny) . "\n";
  1212.         echo '</h1>' . "\n";
  1213.         PMA_showMessage($strUpdateProfileMessage . '<br />' . $strRememberReload);
  1214.     } else {
  1215.         echo '<h1>' . "\n";
  1216.         echo '    ' . $strHost . ' ' . $host . ' - ' . $strUser . ' ' . (($pma_user != '') ?  $pma_user : $strAny) . "\n";
  1217.         echo '</h1>' . "\n";
  1218.         PMA_showMessage($strNoModification);
  1219.     }
  1220. }
  1221.  
  1222. // Changes the privileges of an user
  1223. else if (isset($submit_chgPriv)) {
  1224.     $show_query   = 'y';
  1225.     $edit         = TRUE;
  1226.     if (!isset($host) || $host == '') {
  1227.         $host     = '%';
  1228.     }
  1229.     if (!isset($pma_user) || $pma_user == '') {
  1230.         $pma_user = '%';
  1231.     }
  1232.  
  1233.     $sql_query = '';
  1234.     $list_priv = array('Select', 'Insert', 'Update', 'Delete', 'Create', 'Drop', 'Reload',
  1235.                        'Shutdown', 'Process', 'File', 'Grant', 'References', 'Index', 'Alter');
  1236.     for ($i = 0; $i < 14; $i++) {
  1237.         $priv_name = $list_priv[$i] . '_priv';
  1238.         if (isset($$priv_name)) {
  1239.             $sql_query .= (empty($sql_query) ? $priv_name : ', ' . $priv_name) . ' = \'Y\'';
  1240.         } else  {
  1241.             $sql_query .= (empty($sql_query) ? $priv_name : ', ' . $priv_name) . ' = \'N\'';
  1242.         }
  1243.     } // end for
  1244.     unset($list_priv);
  1245.  
  1246.     $sql_query = 'UPDATE user SET '
  1247.                . $sql_query
  1248.                . ' WHERE Host = \'' . PMA_sqlAddslashes($host) . '\' AND User = \'' . PMA_sqlAddslashes($pma_user) . '\'';
  1249.     $result     = @mysql_query($sql_query) or PMA_mysqlDie('', '', FALSE, $err_url . '&host=' . urlencode($host) . '&pma_user=' . urlencode($pma_user) . '&edit=1');
  1250.     PMA_showMessage(sprintf($strUpdatePrivMessage, '<span style="color: #002E80">' . $pma_user . '@' . $host . '</span>') . '<br />' . $strRememberReload);
  1251. }
  1252.  
  1253. // Revoke/Grant privileges
  1254. else if (isset($grants) && $grants) {
  1255.     $show_query   = 'y';
  1256.     if (!isset($host) || $host == '') {
  1257.         $host     = '%';
  1258.     }
  1259.     if (!isset($pma_user) || $pma_user == '') {
  1260.         $pma_user = '%';
  1261.     }
  1262.  
  1263.     if (isset($upd_grants)) {
  1264.         $sql_query = '';
  1265.         $col_list  = '';
  1266.  
  1267.         if (isset($colgrant) && !$anycolumn) {
  1268.             $colgrant_cnt = count($colgrant);
  1269.             for ($i = 0; $i < $colgrant_cnt; $i++) {
  1270.                 if (get_magic_quotes_gpc()) {
  1271.                     $colgrant[$i] = stripslashes($colgrant[$i]);
  1272.                 }
  1273.                 $col_list .= (empty($col_list) ?  PMA_backquote($colgrant[$i]) : ', ' . PMA_backquote($colgrant[$i]));
  1274.             } // end for
  1275.             unset($colgrant);
  1276.             $col_list     = ' (' . $col_list . ')';
  1277.         } // end if
  1278.  
  1279.         $list_priv = array('Select', 'Insert', 'Update', 'Delete', 'Create', 'Drop', 'Reload',
  1280.                            'Shutdown', 'Process', 'File', 'References', 'Index', 'Alter');
  1281.         for ($i = 0; $i < 13; $i++) {
  1282.             $priv_name = $list_priv[$i] . '_priv';
  1283.             if (isset($$priv_name)) {
  1284.                 $sql_query .= (empty($sql_query) ? $list_priv[$i] : ', ' . $list_priv[$i]) . $col_list;
  1285.             }
  1286.         } // end for
  1287.         unset($list_priv);
  1288.         if (empty($sql_query)) {
  1289.             $sql_query = 'USAGE' . $col_list;
  1290.         }
  1291.         $priv_grant = 'Grant_priv';
  1292.         $priv_grant = (isset($$priv_grant) ? ' WITH GRANT OPTION' : '');
  1293.  
  1294.         if (get_magic_quotes_gpc()) {
  1295.             if (isset($dbgrant) && !$anydb) {
  1296.                 $dbgrant    = stripslashes($dbgrant);
  1297.             }
  1298.             if (isset($tablegrant) && !$anytable) {
  1299.                 $tablegrant = stripslashes($tablegrant);
  1300.             }
  1301.         } // end if
  1302.         $sql_query .= ' ON '
  1303.                    . (($anydb || $dbgrant == '') ? '*' : PMA_backquote($dbgrant))
  1304.                    . '.'
  1305.                    . (($anytable || $tablegrant == '') ? '*' : PMA_backquote($tablegrant));
  1306.  
  1307.         $sql_query .= ' TO ' . '\'' . PMA_sqlAddslashes($pma_user) . '\'' . '@' . '\'' . PMA_sqlAddslashes($host) . '\'';
  1308.  
  1309.         $sql_query  = 'GRANT ' . $sql_query . $priv_grant;
  1310.         $result     = @mysql_query($sql_query) or PMA_mysqlDie('', '', FALSE, $err_url . '&host=' . urlencode($host) . '&pma_user=' . urlencode($pma_user) . '&grants=1');
  1311.         PMA_showMessage($strAddPrivMessage . '.<br />' . $strRememberReload);
  1312.     } // end if
  1313. }
  1314.  
  1315.  
  1316.  
  1317. /**
  1318.  * Displays the page
  1319.  */
  1320. // Edit an user properies
  1321. if (isset($edit) && $edit) {
  1322.     PMA_tableUsers($host, $pma_user);
  1323.     PMA_editOperations($host, $pma_user);
  1324. }
  1325.  
  1326. // Revoke/Grant privileges for an user
  1327. else if (isset($grants) && $grants) {
  1328.     // Displays the full list of privileges for this host & user
  1329.     $infos['Host'] = $host;
  1330.     $infos['User'] = $pma_user;
  1331.     PMA_tableGrants($infos);
  1332.  
  1333.     // Displays the list of privileges for user on the selected db/table/column
  1334.     $user_priv     = array();
  1335.     $list_priv     = array('Select', 'Insert', 'Update', 'Delete', 'Create', 'Drop', 'Reload',
  1336.                            'Shutdown', 'Process', 'File', 'Grant', 'References', 'Index',
  1337.                            'Alter');
  1338.     $list_priv_new = array();
  1339.  
  1340.     // Gets globals privileges
  1341.     $result = mysql_query('SELECT * FROM mysql.user WHERE (Host = \'' . PMA_sqlAddslashes($host) . '\' OR Host = \'%\') AND (User = \'' . PMA_sqlAddslashes($pma_user) . '\' OR User = \'\')');
  1342.     $row    = @mysql_fetch_array($result);
  1343.     if ($row) {
  1344.         while (list(,$priv) = each($list_priv)) {
  1345.             $priv_priv = $priv . '_priv';
  1346.             if ($row[$priv_priv] == 'Y') {
  1347.                 $user_priv[$priv_priv] = 'Y';
  1348.             } else {
  1349.                 $user_priv[$priv_priv] = 'N';
  1350.                 $list_priv_new[]       = $priv;
  1351.             }
  1352.         } // end while
  1353.         mysql_free_result($result);
  1354.         $list_priv     = $list_priv_new;
  1355.         unset($list_priv_new);
  1356.         $list_priv_new = array();
  1357.     } // end if $row
  1358.  
  1359.     // If a target database is set, gets privileges for this database
  1360.     if (count($list_priv) && isset($dbgrant)) {
  1361.         if (get_magic_quotes_gpc()) {
  1362.             $dbgrant = stripslashes($dbgrant);
  1363.         }
  1364.         $result      = mysql_query('SELECT * FROM mysql.db WHERE (Host = \'' . PMA_sqlAddslashes($host) . '\' OR Host = \'%\') AND (User = \'' . PMA_sqlAddslashes($pma_user) . '\' OR User = \'\') AND Db = \'' . PMA_sqlAddslashes($dbgrant) . '\'');
  1365.         $row         = @mysql_fetch_array($result);
  1366.         if ($row) {
  1367.             while (list(,$priv) = each($list_priv)) {
  1368.                 $priv_priv = $priv . '_priv';
  1369.                 if (isset($row[$priv_priv]) && $row[$priv_priv] == 'Y') {
  1370.                     $user_priv[$priv_priv] = 'Y';
  1371.                 } else {
  1372.                     $list_priv_new[]       = $priv;
  1373.                 }
  1374.             } // end while
  1375.             mysql_free_result($result);
  1376.             $list_priv     = $list_priv_new;
  1377.             unset($list_priv_new);
  1378.             $list_priv_new = array();
  1379.         } // end if $row
  1380.     } // end if
  1381.  
  1382.     // If a target table is set, gets privileges for this table
  1383.     if (count($list_priv) && isset($tablegrant)) {
  1384.         if (get_magic_quotes_gpc()) {
  1385.             $tablegrant = stripslashes($tablegrant);
  1386.         }
  1387.         $result         = mysql_query('SELECT * FROM mysql.tables_priv WHERE (Host = \'' . PMA_sqlAddslashes($host) . '\' OR Host = \'%\') AND (User = \'' . PMA_sqlAddslashes($pma_user) . '\' OR User = \'\') AND Db = \'' . PMA_sqlAddslashes($dbgrant) . '\' AND Table_name = \'' . PMA_sqlAddslashes($tablegrant) . '\'');
  1388.         $row            = @mysql_fetch_array($result);
  1389.         if ($row && $row['Table_priv']) {
  1390.             while (list(,$priv) = each($list_priv)) {
  1391.                 $priv_priv = $priv . '_priv';
  1392.                 if (eregi('(^|,)' . $priv . '(,|$)', $row['Table_priv'])) {
  1393.                     $user_priv[$priv_priv] = 'Y';
  1394.                 } else {
  1395.                     $list_priv_new[]       = $priv;
  1396.                 }
  1397.             } // end while
  1398.             mysql_free_result($result);
  1399.             $list_priv     = $list_priv_new;
  1400.             unset($list_priv_new);
  1401.             $list_priv_new = array();
  1402.         } // end if $row
  1403.     } // end if
  1404.  
  1405.     // TODO: column privileges
  1406.  
  1407.     PMA_grantOperations($user_priv);
  1408. }
  1409.  
  1410. // Check database privileges
  1411. else if (isset($check) && $check) {
  1412.     PMA_checkDb($db);
  1413.     ?>
  1414. <ul>
  1415.     <li>
  1416.         <a href="user_details.php?lang=<?php echo $lang;?>&server=<?php echo $server; ?>&db=mysql&table=user">
  1417.             <?php echo $strBack; ?></a>
  1418.     </li>
  1419. </ul>
  1420.     <?php
  1421.     echo "\n";
  1422. }
  1423.  
  1424. // Displays all users profiles
  1425. else {
  1426.     if (!isset($host)) {
  1427.         $host = FALSE;
  1428.     }
  1429.     if (!isset($pma_user)) {
  1430.         $pma_user = FALSE;
  1431.     }
  1432.     PMA_tableUsers($host, $pma_user) or PMA_mysqlDie($strNoUsersFound, '', FALSE, '');
  1433.     PMA_normalOperations();
  1434. }
  1435.  
  1436.  
  1437. /**
  1438.  * Displays the footer
  1439.  */
  1440. require('./footer.inc.php');
  1441. ?>
  1442.