3 // vim: expandtab sw=4 ts=4 sts=4:
7 * Gets some core libraries
9 require('./libraries/grab_globals.lib.php3');
10 require('./libraries/common.lib.php3');
14 * Defines the url to return to in case of error in a sql statement
16 $err_url = 'user_details.php3'
18 . '&convcharset=' . $convcharset
19 . '&server=' . $server
25 * Displays the table of grants for an user
27 * @param mixed the id of the query used to get hosts and databases lists
28 * or an arry containing host and user informations
29 * @param mixed the database to check garnts for, FALSE for all databases
31 * @return boolean always true
33 * @global string the current language
34 * @global string the current charset for MySQL
35 * @global integer the server to use (refers to the number in the
40 * @TODO "SHOW GRANTS" statements is available and buggyless since
41 * MySQL 3.23.4 and it seems not to return privileges of the anonymous
42 * user while these privileges applies to all users.
44 function PMA_tableGrants(&$host_db_result, $dbcheck = FALSE) {
45 global $lang, $convcharset, $server;
48 <!-- Table of grants
-->
49 <table border
="<?php echo $GLOBALS['cfg']['Border']; ?>">
55 echo ' <th>' . $GLOBALS['strAction'] . '</th>' . "\n";
56 echo ' <th>' . $GLOBALS['strHost'] . '</th>' . "\n";
57 echo ' <th>' . $GLOBALS['strUser'] . '</th>';
60 echo ' <th colspan="2">' . $GLOBALS['strAction'] . '</th>';
63 echo ' <th>' . $GLOBALS['strDatabase'] . '</th>' . "\n";
64 echo ' <th>' . UCFirst($GLOBALS['strTable']) . '</th>' . "\n";
65 echo ' <th>' . $GLOBALS['strPrivileges'] . '</th>' . "\n";
67 echo ' <th>Grant Option</th>' . "\n";
75 $url_query = 'lang=' . $lang . '&convcharset=' . $convcharset . '&server=' . $server . '&db=mysql&table=user';
77 while ($row = (is_array($host_db_result) ?
$host_db_result : PMA_mysql_fetch_array($host_db_result))) {
78 $local_query = 'SHOW GRANTS FOR \'' . $row['User'] . '\'@\'' . $row['Host'] . '\'';
79 $result = PMA_mysql_query($local_query);
80 $grants_cnt = ($result) ? @mysql_num_rows
($result) : 0;
84 while ($usr_row = PMA_mysql_fetch_row($result)) {
85 if (eregi('GRANT (.*) ON ([^.]+).([^.]+) TO .*$', $usr_row[0], $parts)) {
86 if ($parts[1] == 'USAGE') {
89 // loic1: bug #487673 - revoke 'reference'
90 $priv = ereg_replace('REFERENCE([^S]|$)', 'REFERENCES\\1', trim($parts[1]));
91 // loic1: bug #576896 - No "FILE" privileges on a
92 // database if neither "INSERT" nor "UPDATE" one
93 if (strpos(' ' . $priv, 'FILE')
94 && !(strpos(' ' . $priv, 'INSERT') ||
strpos(' ' . $priv, 'UPDATE'))) {
95 $priv = ereg_replace('(^FILE(, )?)|(, FILE)', '', $priv);
99 $table = trim($parts[3]);
100 $grantopt = eregi('WITH GRANT OPTION$', $usr_row[0]);
110 if ($priv == '' && !$grantopt) {
114 // Checking the database (take into account wildcards)
116 && ($db != '*' && $db != $dbcheck)) {
117 // TODO: db names may contain characters that are regexp
119 $re = '(^|(\\\\\\\\)+|[^\])';
120 $db_regex = ereg_replace($re . '%', '\\1.*', ereg_replace($re . '_', '\\1.{1}', $db));
121 if (!eregi('^' . $db_regex . '$', $dbcheck)) {
126 $bgcolor = ($i %
2) ?
$GLOBALS['cfg']['BgcolorOne'] : $GLOBALS['cfg']['BgcolorTwo'];
127 $revoke_url = 'sql.php3'
129 . '&sql_query=' . urlencode('REVOKE ' . $priv . ' ON ' . PMA_backquote($db) . '.' . PMA_backquote($table) . ' FROM \'' . $row['User'] . '\'@\'' . $row['Host'] . '\'')
130 . '&zero_rows=' . urlencode(sprintf($GLOBALS['strRevokeMessage'], ' <span style="color: #002E80">' . $row['User'] . '@' . $row['Host'] . '</span>') . '<br />' . $GLOBALS['strRememberReload'])
131 . '&goto=user_details.php3';
133 $revoke_grant_url = 'sql.php3'
135 . '&sql_query=' . urlencode('REVOKE GRANT OPTION ON ' . PMA_backquote($db) . '.' . PMA_backquote($table) . ' FROM \'' . $row['User'] . '\'@\'' . $row['Host'] . '\'')
136 . '&zero_rows=' . urlencode(sprintf($GLOBALS['strRevokeGrantMessage'], ' <span style="color: #002E80">' . $row['User'] . '@' . $row['Host'] . '</span>') . '<br />' . $GLOBALS['strRememberReload'])
137 . '&goto=user_details.php3';
146 <td
<?php
if (!$grantopt) echo ' colspan="2"'; ?
> bgcolor
="<?php echo $bgcolor; ?>">
147 <a href
="<?php echo $revoke_url; ?>">
148 <?php
echo $GLOBALS['strRevokePriv']; ?
></a
>
155 <td
<?php
if (!$priv) echo ' colspan="2"'; ?
> bgcolor
="<?php echo $bgcolor; ?>">
156 <a href
="<?php echo $revoke_grant_url; ?>">
157 <?php
echo $GLOBALS['strRevokeGrant']; ?
></a
>
165 <td bgcolor
="<?php echo $bgcolor; ?>">
166 <a href
="<?php echo $revoke_url; ?>">
167 <?php
echo $GLOBALS['strRevoke']; ?
></a
>
173 <td bgcolor
="<?php echo $bgcolor; ?>"> 
;</td
>
178 <td bgcolor
="<?php echo $bgcolor; ?>"><?php
echo $row['Host']; ?
></td
>
179 <td bgcolor
="<?php echo $bgcolor; ?>"><?php
echo ($row['User']) ?
$row['User'] : '<span style="color: #FF0000">' . $GLOBALS['strAny'] . '</span>'; ?
></td
>
184 <td bgcolor
="<?php echo $bgcolor; ?>"><?php
echo ($db == '*') ?
'<span style="color: #002E80">' . $GLOBALS['strAll'] . '</span>' : $db; ?
></td
>
185 <td bgcolor
="<?php echo $bgcolor; ?>"><?php
echo ($table == '*') ?
'<span style="color: #002E80">' . $GLOBALS['strAll'] . '</span>' : $table; ?
></td
>
186 <td bgcolor
="<?php echo $bgcolor; ?>"><?php
echo ($priv != '') ?
$priv : '<span style="color: #002E80">' . $GLOBALS['strNoPrivileges'] . '</span>'; ?
></td
>
191 <td bgcolor
="<?php echo $bgcolor; ?>"><?php
echo ($grantopt) ?
$GLOBALS['strYes'] : $GLOBALS['strNo']; ?
></td
>
196 <!-- Debug
<td bgcolor
="<?php echo $bgcolor; ?>"><?php
echo $usr_row[0] ?
></td
> Debug
-->
201 } // end while $usr_row
202 } // end if $grants_cnt >0
203 // $host_db_result is an array containing related to only one user
205 if (is_array($host_db_result)) {
217 } // end of the 'PMA_tableGrants()' function
221 * Displays the list of grants for a/all database/s
223 * @param mixed the database to check garnts for, FALSE for all databases
225 * @return boolean true/false in case of success/failure
227 * @see PMA_tableGrants()
229 function PMA_checkDb($dbcheck)
231 $local_query = 'SELECT Host, User FROM mysql.user ORDER BY Host, User';
232 $result = PMA_mysql_query($local_query);
233 $host_usr_cnt = ($result) ? @mysql_num_rows
($result) : 0;
235 if (!$host_usr_cnt) {
238 PMA_tableGrants($result, $dbcheck);
241 } // end of the 'PMA_checkDb()' function
245 * Displays the privileges part of a page
247 * @param string the name of the form for js validation
248 * @param array the list of the privileges of the user
250 * @return boolean always true
252 * @global integer whether all/none of the privileges have to be checked or
255 * @see PMA_normalOperations()
257 function PMA_tablePrivileges($form, $row = FALSE)
261 $checkpriv_url = $GLOBALS['cfg']['PmaAbsoluteUri']
262 . 'user_details.php3?';
263 if (empty($GLOBALS['QUERY_STRING'])) {
264 if (isset($_SERVER) && !empty($_SERVER['QUERY_STRING'])) {
265 $GLOBALS['QUERY_STRING'] = $_SERVER['QUERY_STRING'];
267 else if (isset($GLOBALS['HTTP_SERVER_VARS']) && !empty($GLOBALS['HTTP_SERVER_VARS']['QUERY_STRING'])) {
268 $GLOBALS['QUERY_STRING'] = $GLOBALS['HTTP_SERVER_VARS']['QUERY_STRING'];
271 if (!empty($GLOBALS['QUERY_STRING'])) {
272 $checkpriv_url .= str_replace('&', '&', $GLOBALS['QUERY_STRING']) . '&';
279 $list_priv = array('Select', 'Insert', 'Update', 'Delete', 'Create', 'Drop', 'Reload',
280 'Shutdown', 'Process', 'File', 'Grant', 'References', 'Index', 'Alter');
282 while ((list(,$priv) = each($list_priv)) && ++
$item) {
283 $priv_priv = $priv . '_priv';
284 if (isset($checkpriv)) {
285 $checked = ($checkpriv == 'all') ?
' checked="checked"' : '';
287 $checked = ($row && $row[$priv_priv] == 'Y') ?
' checked="checked"' : '';
289 if ($item %
2 == 1) {
292 echo ' <td> </td>' . "\n";
295 echo ' <input type="checkbox" name="' . $priv . '_priv" id="checkbox_priv_' . $priv . '"' . $checked . ' />' . "\n";
296 echo ' </td>' . "\n";
297 echo ' <td><label for="checkbox_priv_' . $priv . '">' . $priv . '</label></td>' . "\n";
298 if ($item %
2 == 0) {
299 echo ' </tr>' . "\n";
302 if ($item %
2 == 1) {
303 echo ' <td colspan="2"> <td>' . "\n";
304 echo ' </tr>' . "\n";
311 <a href
="<?php echo $checkpriv_url; ?>checkpriv=all" onclick
="checkForm('<?php echo $form; ?>', true); return false">
312 <?php
echo $GLOBALS['strCheckAll']; ?
></a
>
316 <a href
="<?php echo $checkpriv_url; ?>checkpriv=none" onclick
="checkForm('<?php echo $form; ?>', false); return false">
317 <?php
echo $GLOBALS['strUncheckAll']; ?
></a
>
325 } // end of the 'PMA_tablePrivileges()' function
329 * Displays the page for "normal" operations
331 * @return boolean always true
333 * @global string the current language
334 * @global string the current charset for MySQL
335 * @global integer the server to use (refers to the number in the
336 * configuration file)
338 * @see PMA_tablePrivileges()
340 function PMA_normalOperations()
342 global $lang, $convcharset, $server;
348 <div style
="margin-bottom: 10px">
349 <a href
="user_details.php3?lang=<?php echo $lang; ?>&convcharset=<?php echo $convcharset; ?>&server=<?php echo $server; ?>&db=mysql&table=user&mode=reload">
350 <?php
echo $GLOBALS['strReloadMySQL']; ?
></a
> 
;
351 <?php
echo PMA_showMySQLDocu('MySQL_Database_Administration.', 'FLUSH') . "\n"; ?
>
356 <form name
="dbPrivForm" action
="user_details.php3" method
="post">
357 <?php
echo $GLOBALS['strCheckDbPriv'] . "\n"; ?
>
361 <?php
echo $GLOBALS['strDatabase']; ?
> 
;: 
;
365 $result = PMA_mysql_query('SHOW DATABASES');
366 if ($result && @mysql_num_rows
($result)) {
367 while ($row = PMA_mysql_fetch_row($result)) {
369 echo '<option value="' . str_replace('"', '"', $row[0]) . '">' . htmlspecialchars($row[0]) . '</option>' . "\n";
374 <input type
="hidden" name
="lang" value
="<?php echo $lang; ?>" />
375 <input type
="hidden" name
="convcharset" value
="<?php echo $convcharset; ?>" />
376 <input type
="hidden" name
="server" value
="<?php echo $server; ?>" />
377 <input type
="hidden" name
="check" value
="1" />
378 <input type
="submit" value
="<?php echo $GLOBALS['strGo']; ?>" />
386 <form action
="user_details.php3" method
="post" name
="addUserForm" onsubmit
="return checkAddUser()">
387 <?php
echo $GLOBALS['strAddUser'] . "\n"; ?
>
391 <input type
="radio" name
="anyhost" id
="radio_anyhost0" checked
="checked" />
392 <label
for="radio_anyhost0"><?php
echo $GLOBALS['strAnyHost']; ?
></label
>
396 <input type
="radio" name
="anyhost" id
="radio_anyhost1" />
397 <label
for="radio_anyhost1"><?php
echo $GLOBALS['strHost']; ?
></label
> 
;: 
;
400 <input type
="text" name
="host" size
="10" class="textfield" <?php
echo $GLOBALS['chg_evt_handler']; ?
>="this.form.anyhost[1].checked = true" />
405 <input type
="radio" name
="anyuser" id
="radio_anyuser0" />
406 <label
for="radio_anyuser0"><?php
echo $GLOBALS['strAnyUser']; ?
></label
>
410 <input type
="radio" name
="anyuser" id
="radio_anyuser1" checked
="checked" />
411 <label
for="radio_anyuser1"><?php
echo $GLOBALS['strUserName']; ?
></label
> 
;: 
;
414 <input type
="text" name
="pma_user" size
="10" class="textfield" <?php
echo $GLOBALS['chg_evt_handler']; ?
>="this.form.anyuser[1].checked = true" />
419 <input type
="radio" name
="nopass" value
="1" id
="radio_nopass1" onclick
="pma_pw.value = ''; pma_pw2.value = ''; this.checked = true" />
420 <label
for="radio_nopass1"><?php
echo $GLOBALS['strNoPassword']; ?
></label
>
424 <input type
="radio" name
="nopass" value
="0" id
="radio_nopass0" checked
="checked" />
425 <label
for="radio_nopass0"><?php
echo $GLOBALS['strPassword']; ?
></label
> 
;: 
;
428 <input type
="password" name
="pma_pw" size
="10" class="textfield" <?php
echo $GLOBALS['chg_evt_handler']; ?
>="nopass[1].checked = true" />
430 <?php
echo $GLOBALS['strReType']; ?
> 
;: 
;
431 <input type
="password" name
="pma_pw2" size
="10" class="textfield" <?php
echo $GLOBALS['chg_evt_handler']; ?
>="nopass[1].checked = true" />
437 <?php
echo $GLOBALS['strPrivileges']; ?
> 
;:
444 PMA_tablePrivileges('addUserForm');
446 <input type
="hidden" name
="lang" value
="<?php echo $lang; ?>" />
447 <input type
="hidden" name
="convcharset" value
="<?php echo $convcharset; ?>" />
448 <input type
="hidden" name
="server" value
="<?php echo $server; ?>" />
449 <input type
="submit" name
="submit_addUser" value
="<?php echo $GLOBALS['strGo']; ?>" />
457 } // end of the 'PMA_normalOperations()' function
461 * Displays the grant operations part of an user properties page
463 * @param array grants of the current user
465 * @return boolean always true
467 * @global string the current language
468 * @global string the current charset for MySQL
469 * @global integer the server to use (refers to the number in the
470 * configuration file)
471 * @global string the host name to check grants for
472 * @global string the username to check grants for
473 * @global string the database to check grants for
474 * @global string the table to check grants for
476 * @see PMA_tablePrivileges()
478 function PMA_grantOperations($grants)
480 global $lang, $convcharset, $server, $host, $pma_user;
481 global $dbgrant, $tablegrant, $newdb;
487 <div style
="margin-bottom: 10px">
488 <a href
="user_details.php3?lang=<?php echo $lang; ?>&convcharset=<?php echo $convcharset; ?>&server=<?php echo $server; ?>&db=mysql&table=user">
489 <?php
echo $GLOBALS['strBack']; ?
></a
>
494 <form action
="user_details.php3" method
="post" name
="userGrants">
495 <input type
="hidden" name
="lang" value
="<?php echo $lang; ?>" />
496 <input type
="hidden" name
="convcharset" value
="<?php echo $convcharset; ?>" />
497 <input type
="hidden" name
="server" value
="<?php echo $server; ?>" />
498 <input type
="hidden" name
="grants" value
="1" />
499 <input type
="hidden" name
="host" value
="<?php echo str_replace('"', '"
;', $host); ?>" />
500 <input type="hidden" name="pma_user" value="<?php echo str_replace('"', '"', $pma_user); ?>" />
502 <?php
echo $GLOBALS['strAddPriv'] . "\n"; ?
>
506 <input type
="radio" name
="anydb" value
="1" id
="radio_anydb1"<?php
echo ($dbgrant) ?
'' : ' checked="checked"'; ?
> />
507 <label
for="radio_anydb1"><?php
echo $GLOBALS['strAnyDatabase']; ?
></label
>
509 <td
> 
; 
; 
;</td
>
511 <input type
="radio" name
="anydb" value
="0" id
="radio_anydb0"<?php
echo ($dbgrant) ?
' checked="checked"' : ''; ?
> />
512 <label
for="radio_anydb0"><?php
echo $GLOBALS['strDatabase']; ?
></label
><a href
="./Documentation.html#underscore" target
="documentation" title
="<?php echo $GLOBALS['strDocu']; ?>">(*)</a
> 
;: 
;
515 <select name
="dbgrant" onchange
="change(this)">
519 // if (!isset($dbgrant)) {
521 // echo '<option></option>' . "\n";
523 $is_selected_db = FALSE;
524 $result = PMA_mysql_query('SHOW DATABASES');
525 if ($result && @mysql_num_rows
($result)) {
526 while ($row = PMA_mysql_fetch_row($result)) {
527 $selected = (($row[0] == $dbgrant) ?
' selected="selected"' : '');
528 if (!empty($selected)) {
529 $is_selected_db = TRUE;
532 echo '<option' . $selected . '>' . $row[0] . '</option>' . "\n";
540 <input type
="submit" value
="<?php echo $GLOBALS['strShowTables']; ?>" />
545 <input type
="radio" name
="anytable" value
="1" id
="radio_anytable1"<?php
echo ($tablegrant) ?
'' : ' checked="checked"'; ?
> />
546 <label
for="radio_anytable1"><?php
echo $GLOBALS['strAnyTable']; ?
></label
>
548 <td
> 
; 
; 
;</td
>
550 <input type
="radio" name
="anytable" value
="0" id
="radio_anytable0"<?php
echo ($tablegrant) ?
' checked="checked"' : ''; ?
> />
551 <label
for="radio_anytable0"><?php
echo $GLOBALS['strTable']; ?
></label
> 
;: 
;
554 <select name
="tablegrant" onchange
="change(this)">
558 // if (!isset($tablegrant)) {
560 // echo '<option></option>' . "\n";
562 if (isset($dbgrant)) {
563 $result = PMA_mysql_query('SHOW TABLES FROM ' . PMA_backquote($dbgrant));
564 if ($result && @mysql_num_rows
($result)) {
565 while ($row = PMA_mysql_fetch_row($result)) {
566 $selected = ((isset($tablegrant) && $row[0] == $tablegrant) ?
' selected="selected"' : '');
568 echo '<option' . $selected . '>' . $row[0] . '</option>' . "\n";
577 <input type
="submit" value
="<?php echo $GLOBALS['strShowCols']; ?>" />
582 <input type
="radio" name
="anycolumn" value
="1" id
="radio_anycolumn1" checked
="checked" />
583 <label
for="radio_anycolumn1"><?php
echo $GLOBALS['strAnyColumn']; ?
></label
>
585 <td
> 
; 
; 
;</td
>
587 <input type
="radio" name
="anycolumn" value
="0" id
="radio_anycolumn0" />
588 <label
for="radio_anycolumn0"><?php
echo $GLOBALS['strColumn']; ?
></label
> 
;: 
;
593 if (!isset($dbgrant) ||
!isset($tablegrant)) {
594 echo ' ' . '<select name="colgrant[]">' . "\n";
595 echo ' ' . '<option></option>' . "\n";
596 echo ' ' . '</select>' . "\n";
599 $result = PMA_mysql_query('SHOW COLUMNS FROM ' . PMA_backquote($tablegrant) . ' FROM ' . PMA_backquote($dbgrant));
600 if ($result && @mysql_num_rows
($result)) {
602 . '<select name="colgrant[]" multiple="multiple" onchange="anycolumn[1].checked = true">' . "\n";
603 while ($row = PMA_mysql_fetch_row($result)) {
605 echo '<option value="' . str_replace('"', '"', $row[0]) . '">' . $row[0] . '</option>' . "\n";
608 echo ' ' . '<select name="colgrant[]">' . "\n";
609 echo ' ' . '<option></option>' . "\n";
610 } // end if... else...
612 . '</select>' . "\n";
620 <i
><?php
echo $GLOBALS['strOr']; ?
></i
>
625 <?php
echo $GLOBALS['strDatabaseWildcard'] . "\n"; ?
> 
;
626 <input type
="text" name
="newdb" value
="<?php echo ((!$is_selected_db && !empty($pma_user)) ? $pma_user . '%' : ''); ?>" class="textfield" <?php
echo $GLOBALS['chg_evt_handler']; ?
>="change(this)" />
635 <?php
echo $GLOBALS['strPrivileges']; ?
> 
;: 
;
642 PMA_tablePrivileges('userGrants', $grants);
644 <input type
="submit" name
="upd_grants" value
="<?php echo $GLOBALS['strGo']; ?>" />
653 } // end of the 'PMA_grantOperations()' function
657 * Displays the page to edit operations
659 * @param string the host name to check grants for
660 * @param string the user name to check grants for
662 * @return boolean always true
664 * @global string the current language
665 * @global string the current charset for MySQL
666 * @global integer the server to use (refers to the number in the
667 * configuration file)
669 * @see PMA_tablePrivileges()
671 function PMA_editOperations($host, $user)
673 global $lang, $convcharset, $server;
675 $result = PMA_mysql_query('SELECT * FROM mysql.user WHERE User = \'' . PMA_sqlAddslashes($user) . '\' AND Host = \'' . PMA_sqlAddslashes($host) . '\'');
676 $rows = ($result) ? @mysql_num_rows
($result) : 0;
682 $row = PMA_mysql_fetch_array($result);
688 <div style
="margin-bottom: 10px">
689 <a href
="user_details.php3?lang=<?php echo $lang; ?>&convcharset=<?php echo $convcharset; ?>&server=<?php echo $server; ?>&db=mysql&table=user">
690 <?php
echo $GLOBALS['strBack']; ?
></a
>
695 <form action
="user_details.php3" method
="post" name
="updUserForm" onsubmit
="return checkUpdProfile()">
696 <?php
echo $GLOBALS['strUpdateProfile'] . "\n"; ?
>
700 <input type
="radio" value
="1" name
="anyhost" id
="radio_anyhost1"<?php
if ($host == '' ||
$host == '%') echo ' checked="checked"'; ?
> />
701 <label
for="radio_anyhost1"><?php
echo $GLOBALS['strAnyHost']; ?
></label
>
705 <input type
="radio" value
="0" name
="anyhost" id
="radio_anyhost0"<?php
if ($host != '' && $host != '%') echo ' checked="checked"'; ?
> />
706 <label
for="radio_anyhost0"><?php
echo $GLOBALS['strHost']; ?
></label
> 
;: 
;
709 <input type
="text" name
="new_server" size
="10" value
="<?php echo str_replace('"', '"
;', $host); ?>" class="textfield" <?php echo $GLOBALS['chg_evt_handler
']; ?>="this.form.anyhost[1].checked = true" />
714 <input type="radio" value="1" name="anyuser" id="radio_anyuser1"<?php if ($user == '' || $user == '%
') echo ' checked
="checked"'; ?> />
715 <label for="radio_anyuser1"><?php echo $GLOBALS['strAnyUser
']; ?></label>
719 <input type="radio" value="0" name="anyuser" id="radio_anyuser0"<?php if ($user != '' && $user != '%
') echo ' checked
="checked"'; ?> />
720 <label for="radio_anyuser0"><?php echo $GLOBALS['strUserName
']; ?></label> :
723 <input type="text" name="new_user" size="10" value="<?php echo str_replace('"', '"', $user); ?>" class="textfield" <?php
echo $GLOBALS['chg_evt_handler']; ?
>="this.form.anyuser[1].checked = true" />
728 <input type
="radio" name
="nopass" value
="-1" id
="radio_nopass-1" checked
="checked" onclick
="new_pw.value = ''; new_pw2.value = ''; this.checked = true" />
729 <label
for="radio_nopass-1"><?php
echo $GLOBALS['strKeepPass']; ?
></label
>
731 <td colspan
="3"> 
;</td
>
734 <td colspan
="4" align
="<?php echo $GLOBALS['cell_align_left']; ?>"> 
; 
; 
; 
; 
; 
;<?php
echo $GLOBALS['strOr']; ?
></td
>
738 <input type
="radio" name
="nopass" value
="1" id
="radio_nopass1" onclick
="new_pw.value = ''; new_pw2.value = ''; this.checked = true" />
739 <label
for="radio_nopass1"><?php
echo $GLOBALS['strNoPassword']; ?
></label
>
743 <input type
="radio" name
="nopass" value
="0" id
="radio_nopass0" />
744 <label
for="radio_nopass0"><?php
echo $GLOBALS['strPassword']; ?
></label
> 
;: 
;
747 <input type
="password" name
="new_pw" size
="10" <?php
echo $GLOBALS['chg_evt_handler']; ?
>="nopass[2].checked = true" />
749 <?php
echo $GLOBALS['strReType']; ?
> 
;: 
;
750 <input type
="password" name
="new_pw2" size
="10" <?php
echo $GLOBALS['chg_evt_handler']; ?
>="nopass[2].checked = true" />
754 <input type
="hidden" name
="lang" value
="<?php echo $lang; ?>" />
755 <input type
="hidden" name
="convcharset" value
="<?php echo $convcharset; ?>" />
756 <input type
="hidden" name
="server" value
="<?php echo $server; ?>" />
757 <input type
="hidden" name
="host" value
="<?php echo str_replace('"', '"
;', $host); ?>" />
758 <input type="hidden" name="pma_user" value="<?php echo str_replace('"', '"', $user); ?>" />
759 <input type
="submit" name
="submit_updProfile" value
="<?php echo $GLOBALS['strGo']; ?>" />
764 <form action
="user_details.php3" method
="post" name
="privForm">
765 <?php
echo $GLOBALS['strEditPrivileges'] . "\n"; ?
>
767 PMA_tablePrivileges('privForm', $row);
770 <input type
="hidden" name
="lang" value
="<?php echo $lang; ?>" />
771 <input type
="hidden" name
="convcharset" value
="<?php echo $convcharset; ?>" />
772 <input type
="hidden" name
="server" value
="<?php echo $server; ?>" />
773 <input type
="hidden" name
="host" value
="<?php echo str_replace('"', '"
;', $host); ?>" />
774 <input type="hidden" name="pma_user" value="<?php echo str_replace('"', '"', $user); ?>" />
775 <input type
="submit" name
="submit_chgPriv" value
="<?php echo $GLOBALS['strGo']; ?>" />
784 } // end of the 'PMA_editOperations()' function
788 * Displays the table of the users
790 * @param string the host name
791 * @param string the user name
793 * @return boolean always true
795 * @global string the current language
796 * @global string the current charset for MySQL
797 * @global integer the server to use (refers to the number in the
798 * configuration file)
800 function PMA_tableUsers($host = FALSE, $user = FALSE)
802 global $lang, $convcharset, $server;
804 $local_query = 'SELECT * FROM mysql.user ';
805 if ($host ||
$user) {
806 $local_query .= ' WHERE 1 ';
809 $local_query .= ' AND Host = \'' . PMA_sqlAddslashes($host) . '\'';
810 $local_query .= ' AND User = \'' . PMA_sqlAddslashes($user) . '\'';
812 $local_query .= ' ORDER BY Host, User';
813 $result = PMA_mysql_query($local_query);
814 $rows = ($result) ? @mysql_num_rows
($result) : 0;
820 echo '<i>' . $GLOBALS['strEnglishPrivileges'] . '</i><br />' . "\n";
821 echo '<table border="' . $GLOBALS['cfg']['Border'] . '">' . "\n";
823 echo ' <th colspan="'. (($user) ?
'2' : '3') . '">' . $GLOBALS['strAction'] . '</th>' . "\n";
824 echo ' <th>' . $GLOBALS['strHost'] . '</th>' . "\n";
825 echo ' <th>' . $GLOBALS['strUser'] . '</th>' . "\n";
826 echo ' <th>' . $GLOBALS['strPassword'] . '</th>' . "\n";
827 echo ' <th>' . $GLOBALS['strPrivileges'] . '</th>' . "\n";
831 while ($row = PMA_mysql_fetch_array($result)) {
833 $bgcolor = ($i %
2) ?
$GLOBALS['cfg']['BgcolorOne'] : $GLOBALS['cfg']['BgcolorTwo'];
836 if ($row['Select_priv'] == 'Y') {
837 $strPriv .= 'Select ';
839 if ($row['Insert_priv'] == 'Y') {
840 $strPriv .= 'Insert ';
842 if ($row['Update_priv'] == 'Y') {
843 $strPriv .= 'Update ';
845 if ($row['Delete_priv'] == 'Y') {
846 $strPriv .= 'Delete ';
848 if ($row['Create_priv'] == 'Y') {
849 $strPriv .= 'Create ';
851 if ($row['Drop_priv'] == 'Y') {
854 if ($row['Reload_priv'] == 'Y') {
855 $strPriv .= 'Reload ';
857 if ($row['Shutdown_priv'] == 'Y') {
858 $strPriv .= 'Shutdown ';
860 if ($row['Process_priv'] == 'Y') {
861 $strPriv .= 'Process ';
863 if ($row['File_priv'] == 'Y') {
866 if ($row['Grant_priv'] == 'Y') {
867 $strPriv .= 'Grant ';
869 if ($row['References_priv'] == 'Y') {
870 $strPriv .= 'References ';
872 if ($row['Index_priv'] == 'Y') {
873 $strPriv .= 'Index ';
875 if ($row['Alter_priv'] == 'Y') {
876 $strPriv .= 'Alter ';
878 if ($strPriv == '') {
879 $strPriv = '<span style="color: #002E80">' . $GLOBALS['strNoPrivileges'] . '</span>';
882 $query = 'lang=' . $lang . '&server=' . $server . '&db=mysql&table=user&convcharset=' . $convcharset;
884 $edit_url = 'user_details.php3'
885 . '?lang=' . $lang . '&convcharset=' . $convcharset . '&server=' . $server
886 . '&edit=1&host=' . urlencode($row['Host']) . '&pma_user=' . urlencode($row['User']);
888 $delete_url = 'user_details.php3'
890 . '&delete=1&confirm=1&delete_host=' . urlencode($row['Host']) . '&delete_user=' . urlencode($row['User']);
891 $check_url = 'user_details.php3'
892 . '?lang=' . $lang . '&convcharset=' . $convcharset . '&server=' . $server
893 . '&grants=1&host=' . urlencode($row['Host']) . '&pma_user=' . urlencode($row['User']);
901 <td bgcolor
="<?php echo $bgcolor;?>">
902 <a href
="<?php echo $edit_url; ?>">
903 <?php
echo $GLOBALS['strEdit']; ?
></a
>
909 <td bgcolor
="<?php echo $bgcolor;?>">
910 <a href
="<?php echo $delete_url; ?>">
911 <?php
echo $GLOBALS['strDelete']; ?
></a
>
913 <td bgcolor
="<?php echo $bgcolor;?>">
914 <a href
="<?php echo $check_url; ?>">
915 <?php
echo $GLOBALS['strGrants']; ?
></a
>
918 <td bgcolor
="<?php echo $bgcolor;?>">
919 <a href
="<?php echo (($check_url != '') ? $check_url : '#'); ?>">
920 <?php
echo $GLOBALS['strGrants']; ?
></a
>
923 <td bgcolor
="<?php echo $bgcolor;?>">
924 <?php
echo $row['Host'] . "\n"; ?
>
926 <td bgcolor
="<?php echo $bgcolor;?>">
927 <?php
echo (($row['User']) ?
'<b>' . $row['User'] . '</b>' : '<span style="color: #FF0000">' . $GLOBALS['strAny'] . '</span>') . "\n"; ?
>
929 <td bgcolor
="<?php echo $bgcolor;?>">
930 <?php
echo (($row[$GLOBALS['password_field']]) ?
$GLOBALS['strYes'] : '<span style="color: #FF0000">' . $GLOBALS['strNo'] . '</span>') . "\n"; ?
>
932 <td bgcolor
="<?php echo $bgcolor;?>">
933 <?php
echo $strPriv . "\n"; ?
>
949 } // end of the 'PMA_tableUsers()' function
953 * Displays a confirmation form
955 * @param string the host name and...
956 * @param string ... the username to delete
958 * @global string the current language
959 * @global string the current charset for MySQL
960 * @global integer the server to use (refers to the number in the
961 * configuration file)
963 function PMA_confirm($the_host, $the_user) {
964 global $lang, $convcharset, $server;
966 if (get_magic_quotes_gpc() == 1) {
967 $the_host = stripslashes($the_host);
968 $the_user = stripslashes($the_user);
971 echo $GLOBALS['strConfirm'] . ' : <br />' . "\n";
972 echo 'DELETE FROM mysql.user WHERE Host = \'' . $the_host . '\' AND User = \'' . $the_user . '\'' . '<br />' . "\n";
974 <form action
="user_details.php3" method
="post">
975 <input type
="hidden" name
="lang" value
="<?php echo $lang; ?>" />
976 <input type
="hidden" name
="convcharset" value
="<?php echo $convcharset; ?>" />
977 <input type
="hidden" name
="server" value
="<?php echo $server; ?>" />
978 <input type
="hidden" name
="db" value
="mysql" />
979 <input type
="hidden" name
="table" value
="user" />
980 <input type
="hidden" name
="delete" value
="<?php echo(isset($GLOBALS['delete']) ? '1' : '0'); ?>" />
981 <input type
="hidden" name
="delete_host" value
="<?php echo str_replace('"', '"
;', $the_host); ?>" />
982 <input type="hidden" name="delete_user" value="<?php echo str_replace('"', '"', $the_user); ?>" />
983 <input type
="submit" name
="btnConfirm" value
="<?php echo $GLOBALS['strYes']; ?>" />
984 <input type
="submit" name
="btnConfirm" value
="<?php echo $GLOBALS['strNo']; ?>" />
989 include('./footer.inc.php3');
990 } // end of the 'PMA_confirm()' function
995 * Ensures the user is super-user and gets the case sensitive password field
998 $result = @PMA_mysql_query
('USE mysql');
999 if (PMA_mysql_error()) {
1000 include('./header.inc.php3');
1001 echo '<p><b>' . $strError . '</b></p>' . "\n";
1002 echo '<p> ' . $strNoRights . '</p>' . "\n";
1003 include('./footer.inc.php3');
1006 // The previous logic did not work if the password field is named "password":
1007 //$result = @PMA_mysql_query('SELECT COUNT(Password) FROM mysql.user');
1008 //$password_field = (($result && PMA_mysql_result($result, 0)) ? 'Password' : 'password');
1010 // using a syntax that works with older and recent MySQL,
1011 // and assumes that the field name ends with "assword":
1012 $result = @PMA_mysql_query
('SHOW FIELDS FROM user FROM mysql LIKE \'%assword\'');
1014 $password_field = PMA_mysql_result($result, 0);
1018 * Autocomplete feature of IE kills the "onchange" event handler and it must be
1019 * replaced by the "onpropertychange" one in this case
1021 $chg_evt_handler = (PMA_USR_BROWSER_AGENT
== 'IE' && PMA_USR_BROWSER_VER
>= 5)
1022 ?
'onpropertychange'
1030 $db_bkp = (get_magic_quotes_gpc() ?
stripslashes($db) : $db);
1033 if (isset($table)) {
1034 $table_bkp = (get_magic_quotes_gpc() ?
stripslashes($table) : $table);
1037 if (get_magic_quotes_gpc()) {
1038 if (!empty($host)) {
1039 $host = stripslashes($host);
1041 if (!empty($pma_user)) {
1042 $pma_user = stripslashes($pma_user);
1046 if (!isset($message)) {
1047 $js_to_run = 'user_details.js';
1048 include('./header.inc.php3');
1050 if (!isset($submit_updProfile)) {
1052 echo ' ' . ((!isset($host) ||
$host == '') ?
$strAnyHost : $strHost . ' ' . $host) . ' - ' . ((!isset($pma_user) ||
$pma_user == '') ?
$strAnyUser : $strUser . ' ' . $pma_user) . "\n";
1055 if (isset($message)) {
1057 PMA_showMessage($message);
1060 if (isset($db_bkp)) {
1064 if (isset($table_bkp)) {
1065 $table = $table_bkp;
1071 * Some actions has been submitted
1073 // Confirms an action
1074 if (isset($confirm) && $confirm) {
1075 PMA_confirm($delete_host, $delete_user);
1080 else if (($server > 0) && isset($mode) && ($mode == 'reload')) {
1081 $result = PMA_mysql_query('FLUSH PRIVILEGES');
1083 echo '<p><b>' . $strMySQLReloaded . '</b></p>' . "\n";
1085 echo '<p><b>' . $strReloadFailed . '</b></p>' . "\n";
1090 else if (isset($delete) && $delete
1091 && isset($btnConfirm) && $btnConfirm == $strYes) {
1092 if (get_magic_quotes_gpc()) {
1093 $delete_host = stripslashes($delete_host);
1094 $delete_user = stripslashes($delete_user);
1096 $common_where = ' WHERE Host = \'' . PMA_sqlAddslashes($delete_host) . '\' AND User = \'' . PMA_sqlAddslashes($delete_user) . '\'';
1098 // Delete Grants First!
1099 $sql_query = 'DELETE FROM mysql.db' . $common_where;
1100 $sql_query_cpy = $sql_query;
1101 PMA_mysql_query($sql_query);
1102 $sql_query = 'DELETE FROM mysql.tables_priv' . $common_where;
1103 $sql_query_cpy .= ";\n" . $sql_query;
1104 PMA_mysql_query($sql_query);
1105 $sql_query = 'DELETE FROM mysql.columns_priv' . $common_where;
1106 $sql_query_cpy .= ";\n" . $sql_query;
1107 PMA_mysql_query($sql_query);
1109 $sql_query = 'DELETE FROM mysql.user' . $common_where;
1110 $sql_query_cpy .= ";\n" . $sql_query;
1111 $result = PMA_mysql_query($sql_query);
1113 $sql_query = $sql_query_cpy;
1114 unset($sql_query_cpy);
1116 PMA_showMessage(sprintf($strDeleteUserMessage, '<span style="color: #002E80">' . $delete_user . '@' . $delete_host . '</span>') . '<br />' . $strRememberReload);
1118 PMA_showMessage($strDeleteFailed);
1123 else if (isset($submit_addUser)) {
1125 if (!isset($host) ||
$host == '') {
1128 if (!isset($pma_user) ||
$pma_user == '') {
1132 // Password is not confirmed
1133 if ((!isset($nopass) ||
!$nopass) && $pma_pw == '') {
1134 echo '<p><b>' . $strError . ' : ' . $strPasswordEmpty . '</b></p>' . "\n";
1138 else if ($pma_pw != ''
1139 && (!isset($pma_pw2) ||
$pma_pw != $pma_pw2)) {
1140 echo '<p><b>' . $strError . ' : ' . $strPasswordNotSame . '</b></p>' . "\n";
1145 // Password confirmed
1148 $list_priv = array('Select', 'Insert', 'Update', 'Delete', 'Create', 'Drop', 'Reload',
1149 'Shutdown', 'Process', 'File', 'Grant', 'References', 'Index', 'Alter');
1150 for ($i = 0; $i < 14; $i++
) {
1151 $priv_name = $list_priv[$i] . '_priv';
1152 if (isset($
$priv_name)) {
1153 $sql_query .= (empty($sql_query) ?
$priv_name : ', ' . $priv_name) . ' = \'Y\'';
1155 $sql_query .= (empty($sql_query) ?
$priv_name : ', ' . $priv_name) . ' = \'N\'';
1160 if (get_magic_quotes_gpc() && $pma_pw != '') {
1161 $pma_pw = stripslashes($pma_pw);
1164 $local_query = 'INSERT INTO mysql.user '
1165 . 'SET Host = \'' . PMA_sqlAddslashes($host) . '\', User = \'' . PMA_sqlAddslashes($pma_user) . '\', ' . $password_field . ' = ' . (($pma_pw == '') ?
'\'\'' : 'PASSWORD(\'' . PMA_sqlAddslashes($pma_pw) . '\')')
1166 . ', ' . $sql_query;
1167 $sql_query = 'INSERT INTO mysql.user '
1168 . 'SET Host = \'' . PMA_sqlAddslashes($host) . '\', User = \'' . PMA_sqlAddslashes($pma_user) . '\', ' . $password_field . ' = ' . (($pma_pw == '') ?
'\'\'' : 'PASSWORD(\'' . ereg_replace('.', '*', $pma_pw) . '\')')
1169 . ', ' . $sql_query;
1170 $result = @PMA_mysql_query
($local_query) or PMA_mysqlDie('', '', FALSE, $err_url);
1173 PMA_showMessage($strAddUserMessage . '<br />' . $strRememberReload);
1177 // Updates the profile of an user
1178 else if (isset($submit_updProfile)) {
1181 if (!isset($host) ||
$host == '') {
1184 if (!isset($pma_user) ||
$pma_user == '') {
1188 // Builds the sql query
1191 if (isset($anyhost) && $anyhost) {
1193 } else if ($new_server != '' && get_magic_quotes_gpc()) {
1194 $new_server = stripslashes($new_server);
1196 if ($new_server != '' && $new_server != $host) {
1197 $common_upd .= 'Host = \'' . PMA_sqlAddslashes($new_server) . '\'';
1198 } else if (isset($new_server)) {
1202 if (isset($anyuser) && $anyuser) {
1204 } else if ($new_user != '' && get_magic_quotes_gpc()) {
1205 $new_user = stripslashes($new_user);
1207 if ($new_user != '' && $new_user != $pma_user) {
1208 $common_upd .= (empty($common_upd) ?
'' : ', ')
1209 . 'User = \'' . PMA_sqlAddslashes($new_user) . '\'';
1210 } else if (isset($new_user)) {
1214 if (isset($nopass) && $nopass == -1) {
1215 $sql_query = $common_upd;
1216 $local_query = $common_upd;
1218 else if ((!isset($nopass) ||
$nopass == 0) && $new_pw == '') {
1220 echo ' ' . $strHost . ' ' . $host . ' - ' . $strUser . ' ' . (($pma_user != '') ?
$pma_user : $strAny) . "\n";
1221 echo '</h1>' . "\n";
1222 echo '<p><b>' . $strError . ' : ' . $strPasswordEmpty . '</b></p>' . "\n";
1224 else if ($new_pw != ''
1225 && (!isset($new_pw2) ||
$new_pw != $new_pw2)) {
1227 echo ' ' . $strHost . ' ' . $host . ' - ' . $strUser . ' ' . (($pma_user != '') ?
$pma_user : $strAny) . "\n";
1228 echo '</h1>' . "\n";
1229 echo '<p><b>' . $strError . ' : ' . $strPasswordNotSame . '</b></p>' . "\n";
1232 $sql_query = (empty($common_upd) ?
'' : $common_upd . ', ')
1233 . $password_field . ' = ' . (($new_pw == '') ?
'\'\'' : 'PASSWORD(\'' . ereg_replace('.', '*', $new_pw) . '\')');
1234 $local_query = (empty($common_upd) ?
'' : $common_upd . ', ')
1235 . $password_field . ' = ' . (($new_pw == '') ?
'\'\'' : 'PASSWORD(\'' . PMA_sqlAddslashes($new_pw) . '\')');
1238 if (!empty($sql_query)) {
1239 $common_where = ' WHERE Host = \'' . PMA_sqlAddslashes($host) . '\' AND User = \'' . PMA_sqlAddslashes($pma_user) . '\'';
1242 $local_query = 'UPDATE user SET ' . $local_query . $common_where;
1243 $sql_query_cpy = 'UPDATE user SET ' . $sql_query . $common_where;
1244 $result = @PMA_mysql_query
($local_query) or PMA_mysqlDie('', '', FALSE, $err_url . '&host=' . urlencode($host) . '&pma_user=' . urlencode($pma_user) . '&edit=1');
1247 if (isset($new_server) ||
isset($new_user)) {
1248 $sql_query = 'UPDATE mysql.db SET ' . $common_upd . $common_where;
1249 $sql_query_cpy .= ";\n" . $sql_query;
1250 PMA_mysql_query($sql_query);
1251 $sql_query = 'UPDATE mysql.tables_priv SET ' . $common_upd . $common_where;
1252 $sql_query_cpy .= ";\n" . $sql_query;
1253 PMA_mysql_query($sql_query);
1254 $sql_query = 'UPDATE mysql.columns_priv SET ' . $common_upd . $common_where;
1255 $sql_query_cpy .= ";\n" . $sql_query;
1256 PMA_mysql_query($sql_query);
1260 $sql_query = $sql_query_cpy;
1261 unset($sql_query_cpy);
1262 if (isset($new_server)) {
1263 $host = $new_server;
1265 if (isset($new_user)) {
1266 $pma_user = $new_user;
1269 echo ' ' . $strHost . ' ' . $host . ' - ' . $strUser . ' ' . (($pma_user != '') ?
$pma_user : $strAny) . "\n";
1270 echo '</h1>' . "\n";
1271 PMA_showMessage($strUpdateProfileMessage . '<br />' . $strRememberReload);
1274 echo ' ' . $strHost . ' ' . $host . ' - ' . $strUser . ' ' . (($pma_user != '') ?
$pma_user : $strAny) . "\n";
1275 echo '</h1>' . "\n";
1276 PMA_showMessage($strNoModification);
1280 // Changes the privileges of an user
1281 else if (isset($submit_chgPriv)) {
1284 if (!isset($host) ||
$host == '') {
1287 if (!isset($pma_user) ||
$pma_user == '') {
1292 $list_priv = array('Select', 'Insert', 'Update', 'Delete', 'Create', 'Drop', 'Reload',
1293 'Shutdown', 'Process', 'File', 'Grant', 'References', 'Index', 'Alter');
1294 for ($i = 0; $i < 14; $i++
) {
1295 $priv_name = $list_priv[$i] . '_priv';
1296 if (isset($
$priv_name)) {
1297 $sql_query .= (empty($sql_query) ?
$priv_name : ', ' . $priv_name) . ' = \'Y\'';
1299 $sql_query .= (empty($sql_query) ?
$priv_name : ', ' . $priv_name) . ' = \'N\'';
1304 $sql_query = 'UPDATE user SET '
1306 . ' WHERE Host = \'' . PMA_sqlAddslashes($host) . '\' AND User = \'' . PMA_sqlAddslashes($pma_user) . '\'';
1307 $result = @PMA_mysql_query
($sql_query) or PMA_mysqlDie('', '', FALSE, $err_url . '&host=' . urlencode($host) . '&pma_user=' . urlencode($pma_user) . '&edit=1');
1308 PMA_showMessage(sprintf($strUpdatePrivMessage, '<span style="color: #002E80">' . $pma_user . '@' . $host . '</span>') . '<br />' . $strRememberReload);
1311 // Revoke/Grant privileges
1312 else if (isset($grants) && $grants) {
1314 if (!isset($host) ||
$host == '') {
1317 if (!isset($pma_user) ||
$pma_user == '') {
1321 if (isset($upd_grants)) {
1325 if (isset($colgrant) && !$anycolumn && !$newdb) {
1326 $colgrant_cnt = count($colgrant);
1327 for ($i = 0; $i < $colgrant_cnt; $i++
) {
1328 if (get_magic_quotes_gpc()) {
1329 $colgrant[$i] = stripslashes($colgrant[$i]);
1331 $col_list .= (empty($col_list) ?
PMA_backquote($colgrant[$i]) : ', ' . PMA_backquote($colgrant[$i]));
1334 $col_list = ' (' . $col_list . ')';
1337 $list_priv = array('Select', 'Insert', 'Update', 'Delete', 'Create', 'Drop', 'Reload',
1338 'Shutdown', 'Process', 'File', 'References', 'Index', 'Alter');
1339 for ($i = 0; $i < 13; $i++
) {
1340 $priv_name = $list_priv[$i] . '_priv';
1341 if (isset($
$priv_name)) {
1342 $sql_query .= (empty($sql_query) ?
$list_priv[$i] : ', ' . $list_priv[$i]) . $col_list;
1346 if (empty($sql_query)) {
1347 $sql_query = 'USAGE' . $col_list;
1349 $priv_grant = 'Grant_priv';
1350 $priv_grant = (isset($
$priv_grant) ?
' WITH GRANT OPTION' : '');
1352 if (get_magic_quotes_gpc()) {
1354 $newdb = stripslashes($newdb);
1356 if (isset($dbgrant) && !$anydb && !$newdb) {
1357 $dbgrant = stripslashes($dbgrant);
1359 if (isset($tablegrant) && !$anytable && !$newdb) {
1360 $tablegrant = stripslashes($tablegrant);
1365 // Escape wilcard characters if required
1366 if (isset($dbgrant) && !$anydb && !$newdb) {
1367 $re = '(^|(\\\\\\\\)+|[^\])(_|%)'; // non-escaped wildcards
1368 $dbgrant = ereg_replace($re, '\\1\\\\3', $dbgrant);
1372 $sql_query .= ' ON '
1373 . (($anydb ||
$dbgrant == '') ?
'*' : PMA_backquote($dbgrant))
1375 . (($anytable ||
$tablegrant == '') ?
'*' : PMA_backquote($tablegrant));
1377 $sql_query .= ' ON ' . PMA_backquote($newdb) . '.*';
1380 $sql_query .= ' TO ' . '\'' . PMA_sqlAddslashes($pma_user) . '\'' . '@' . '\'' . PMA_sqlAddslashes($host) . '\'';
1382 $sql_query = 'GRANT ' . $sql_query . $priv_grant;
1383 $result = @PMA_mysql_query
($sql_query) or PMA_mysqlDie('', '', FALSE, $err_url . '&host=' . urlencode($host) . '&pma_user=' . urlencode($pma_user) . '&grants=1');
1384 PMA_showMessage($strAddPrivMessage . '.<br />' . $strRememberReload);
1393 // Edit an user properies
1394 if (isset($edit) && $edit) {
1395 PMA_tableUsers($host, $pma_user);
1396 PMA_editOperations($host, $pma_user);
1399 // Revoke/Grant privileges for an user
1400 else if (isset($grants) && $grants) {
1401 // Displays the full list of privileges for this host & user
1402 $infos['Host'] = $host;
1403 $infos['User'] = $pma_user;
1404 PMA_tableGrants($infos);
1406 // Displays the list of privileges for user on the selected db/table/column
1407 $user_priv = array();
1408 $list_priv = array('Select', 'Insert', 'Update', 'Delete', 'Create', 'Drop', 'Reload',
1409 'Shutdown', 'Process', 'File', 'Grant', 'References', 'Index',
1411 $list_priv_new = array();
1413 // Gets globals privileges
1414 $result = PMA_mysql_query('SELECT * FROM mysql.user WHERE (Host = \'' . PMA_sqlAddslashes($host) . '\' OR Host = \'%\') AND (User = \'' . PMA_sqlAddslashes($pma_user) . '\' OR User = \'\')');
1415 $row = ($result) ? @PMA_mysql_fetch_array
($result) : FALSE;
1417 while (list(,$priv) = each($list_priv)) {
1418 $priv_priv = $priv . '_priv';
1419 if ($row[$priv_priv] == 'Y') {
1420 $user_priv[$priv_priv] = 'Y';
1422 $user_priv[$priv_priv] = 'N';
1423 $list_priv_new[] = $priv;
1426 mysql_free_result($result);
1427 $list_priv = $list_priv_new;
1428 unset($list_priv_new);
1429 $list_priv_new = array();
1432 // If a target database is set, gets privileges for this database
1433 if (count($list_priv) && isset($dbgrant)) {
1434 if (get_magic_quotes_gpc()) {
1435 $dbgrant = stripslashes($dbgrant);
1437 $result = PMA_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) . '\'');
1438 $row = ($result) ? @PMA_mysql_fetch_array
($result) : FALSE;
1440 while (list(,$priv) = each($list_priv)) {
1441 $priv_priv = $priv . '_priv';
1442 if (isset($row[$priv_priv]) && $row[$priv_priv] == 'Y') {
1443 $user_priv[$priv_priv] = 'Y';
1445 $list_priv_new[] = $priv;
1448 mysql_free_result($result);
1449 $list_priv = $list_priv_new;
1450 unset($list_priv_new);
1451 $list_priv_new = array();
1455 // If a target table is set, gets privileges for this table
1456 if (count($list_priv) && isset($tablegrant)) {
1457 if (get_magic_quotes_gpc()) {
1458 $tablegrant = stripslashes($tablegrant);
1460 $result = PMA_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) . '\'');
1461 $row = ($result) ? @PMA_mysql_fetch_array
($result) : FALSE;
1462 if ($row && $row['Table_priv']) {
1463 while (list(,$priv) = each($list_priv)) {
1464 $priv_priv = $priv . '_priv';
1465 if (eregi('(^|,)' . $priv . '(,|$)', $row['Table_priv'])) {
1466 $user_priv[$priv_priv] = 'Y';
1468 $list_priv_new[] = $priv;
1471 mysql_free_result($result);
1472 $list_priv = $list_priv_new;
1473 unset($list_priv_new);
1474 $list_priv_new = array();
1478 // TODO: column privileges
1480 PMA_grantOperations($user_priv);
1483 // Check database privileges
1484 else if (isset($check) && $check) {
1489 <a href
="user_details.php3?lang=<?php echo $lang;?>&convcharset=<?php echo $convcharset; ?>&server=<?php echo $server; ?>&db=mysql&table=user">
1490 <?php
echo $strBack; ?
></a
>
1497 // Displays all users profiles
1499 if (!isset($host)) {
1502 if (!isset($pma_user)) {
1505 PMA_tableUsers($host, $pma_user) or PMA_mysqlDie($strNoUsersFound, '', FALSE, '');
1506 PMA_normalOperations();
1511 * Displays the footer
1513 require('./footer.inc.php3');