bug #2780356 [calendar] Null checkbox not unchecked when date is chosen
[phpmyadmin/crack.git] / server_privileges.php
blob8eb5c4e355738294210f8a6d0c52447b37e42f1e
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
5 * @version $Id$
6 */
8 /**
11 require_once './libraries/common.inc.php';
13 /**
14 * Does the common work
16 $GLOBALS['js_include'][] = 'server_privileges.js';
17 $GLOBALS['js_include'][] = 'functions.js';
18 require './libraries/server_common.inc.php';
21 /**
22 * Checks if a dropdown box has been used for selecting a database / table
24 if (PMA_isValid($_REQUEST['pred_tablename'])) {
25 $tablename = $_REQUEST['pred_tablename'];
26 unset($pred_tablename);
27 } elseif (PMA_isValid($_REQUEST['tablename'])) {
28 $tablename = $_REQUEST['tablename'];
29 } else {
30 unset($tablename);
33 if (PMA_isValid($_REQUEST['pred_dbname'])) {
34 $dbname = $_REQUEST['pred_dbname'];
35 unset($pred_dbname);
36 } elseif (PMA_isValid($_REQUEST['dbname'])) {
37 $dbname = $_REQUEST['dbname'];
38 } else {
39 unset($dbname);
40 unset($tablename);
43 if (isset($dbname)) {
44 $db_and_table = PMA_backquote(PMA_unescape_mysql_wildcards($dbname)) . '.';
45 if (isset($tablename)) {
46 $db_and_table .= PMA_backquote($tablename);
47 } else {
48 $db_and_table .= '*';
50 } else {
51 $db_and_table = '*.*';
54 // check if given $dbanem is a wildcard or not
55 if (isset($dbname)) {
56 //if (preg_match('/\\\\(?:_|%)/i', $dbname)) {
57 if (preg_match('/(?<!\\\\)(?:_|%)/i', $dbname)) {
58 $dbname_is_wildcard = true;
59 } else {
60 $dbname_is_wildcard = false;
64 /**
65 * Checks if the user is allowed to do what he tries to...
67 if (!$is_superuser) {
68 require './libraries/server_links.inc.php';
69 echo '<h2>' . "\n"
70 . PMA_getIcon('b_usrlist.png')
71 . $GLOBALS['strPrivileges'] . "\n"
72 . '</h2>' . "\n";
73 PMA_Message::error('strNoPrivileges')->display();
74 require_once './libraries/footer.inc.php';
77 /**
78 * Escapes wildcard in a database+table specification
79 * before using it in a GRANT statement.
81 * Escaping a wildcard character in a GRANT is only accepted at the global
82 * or database level, not at table level; this is why I remove
83 * the escaping character. Internally, in mysql.tables_priv.Db there are
84 * no escaping (for example test_db) but in mysql.db you'll see test\_db
85 * for a db-specific privilege.
87 * @param string $db_and_table
88 * @param string $dbname
89 * @param string $tablename
90 * @return string the escaped (if necessary) $db_and_table
92 function PMA_WildcardEscapeForGrant($db_and_table, $dbname, $tablename) {
94 if (! strlen($dbname)) {
95 $db_and_table = '*.*';
96 } else {
97 if (strlen($tablename)) {
98 $db_and_table = PMA_backquote(PMA_unescape_mysql_wildcards($dbname)) . '.';
99 $db_and_table .= PMA_backquote($tablename);
100 } else {
101 $db_and_table = PMA_backquote($dbname) . '.';
102 $db_and_table .= '*';
105 return $db_and_table;
109 * Generates a condition on the user name
111 * @param string the user's initial
112 * @return string the generated condition
114 function PMA_RangeOfUsers($initial = '')
116 // strtolower() is used because the User field
117 // might be BINARY, so LIKE would be case sensitive
118 if (!empty($initial)) {
119 $ret = " WHERE `User` LIKE '" . $initial . "%'"
120 . " OR `User` LIKE '" . strtolower($initial) . "%'";
121 } else {
122 $ret = '';
124 return $ret;
125 } // end function
128 * Extracts the privilege information of a priv table row
130 * @param array $row the row
131 * @param boolean $enableHTML add <dfn> tag with tooltips
133 * @global ressource $user_link the database connection
135 * @return array
137 function PMA_extractPrivInfo($row = '', $enableHTML = FALSE)
139 $grants = array(
140 array('Select_priv', 'SELECT', $GLOBALS['strPrivDescSelect']),
141 array('Insert_priv', 'INSERT', $GLOBALS['strPrivDescInsert']),
142 array('Update_priv', 'UPDATE', $GLOBALS['strPrivDescUpdate']),
143 array('Delete_priv', 'DELETE', $GLOBALS['strPrivDescDelete']),
144 array('Create_priv', 'CREATE', $GLOBALS['strPrivDescCreateDb']),
145 array('Drop_priv', 'DROP', $GLOBALS['strPrivDescDropDb']),
146 array('Reload_priv', 'RELOAD', $GLOBALS['strPrivDescReload']),
147 array('Shutdown_priv', 'SHUTDOWN', $GLOBALS['strPrivDescShutdown']),
148 array('Process_priv', 'PROCESS', $GLOBALS['strPrivDescProcess']),
149 array('File_priv', 'FILE', $GLOBALS['strPrivDescFile']),
150 array('References_priv', 'REFERENCES', $GLOBALS['strPrivDescReferences']),
151 array('Index_priv', 'INDEX', $GLOBALS['strPrivDescIndex']),
152 array('Alter_priv', 'ALTER', $GLOBALS['strPrivDescAlter']),
153 array('Show_db_priv', 'SHOW DATABASES', $GLOBALS['strPrivDescShowDb']),
154 array('Super_priv', 'SUPER', $GLOBALS['strPrivDescSuper']),
155 array('Create_tmp_table_priv', 'CREATE TEMPORARY TABLES', $GLOBALS['strPrivDescCreateTmpTable']),
156 array('Lock_tables_priv', 'LOCK TABLES', $GLOBALS['strPrivDescLockTables']),
157 array('Repl_slave_priv', 'REPLICATION SLAVE', $GLOBALS['strPrivDescReplSlave']),
158 array('Repl_client_priv', 'REPLICATION CLIENT', $GLOBALS['strPrivDescReplClient']),
159 array('Create_view_priv', 'CREATE VIEW', $GLOBALS['strPrivDescCreateView']),
160 array('Event_priv', 'EVENT', $GLOBALS['strPrivDescEvent']),
161 array('Trigger_priv', 'TRIGGER', $GLOBALS['strPrivDescTrigger']),
162 // for table privs:
163 array('Create View_priv', 'CREATE VIEW', $GLOBALS['strPrivDescCreateView']),
164 array('Show_view_priv', 'SHOW VIEW', $GLOBALS['strPrivDescShowView']),
165 // for table privs:
166 array('Show view_priv', 'SHOW VIEW', $GLOBALS['strPrivDescShowView']),
167 array('Create_routine_priv', 'CREATE ROUTINE', $GLOBALS['strPrivDescCreateRoutine']),
168 array('Alter_routine_priv', 'ALTER ROUTINE', $GLOBALS['strPrivDescAlterRoutine']),
169 array('Create_user_priv', 'CREATE USER', $GLOBALS['strPrivDescCreateUser']),
170 array('Execute_priv', 'EXECUTE', $GLOBALS['strPrivDescExecute5']),
173 if (!empty($row) && isset($row['Table_priv'])) {
174 $row1 = PMA_DBI_fetch_single_row(
175 'SHOW COLUMNS FROM `mysql`.`tables_priv` LIKE \'Table_priv\';',
176 'ASSOC', $GLOBALS['userlink']);
177 $av_grants = explode('\',\'', substr($row1['Type'], 5, strlen($row1['Type']) - 7));
178 unset($row1);
179 $users_grants = explode(',', $row['Table_priv']);
180 foreach ($av_grants as $current_grant) {
181 $row[$current_grant . '_priv'] = in_array($current_grant, $users_grants) ? 'Y' : 'N';
183 unset($current_grant);
184 unset($av_grants);
185 unset($users_grants);
187 $privs = array();
188 $allPrivileges = TRUE;
189 foreach ($grants as $current_grant) {
190 if ((!empty($row) && isset($row[$current_grant[0]]))
191 || (empty($row) && isset($GLOBALS[$current_grant[0]]))) {
192 if ((!empty($row) && $row[$current_grant[0]] == 'Y')
193 || (empty($row)
194 && ($GLOBALS[$current_grant[0]] == 'Y'
195 || (is_array($GLOBALS[$current_grant[0]])
196 && count($GLOBALS[$current_grant[0]]) == $GLOBALS['column_count']
197 && empty($GLOBALS[$current_grant[0] . '_none'])))))
199 if ($enableHTML) {
200 $privs[] = '<dfn title="' . $current_grant[2] . '">' . $current_grant[1] . '</dfn>';
201 } else {
202 $privs[] = $current_grant[1];
204 } elseif (!empty($GLOBALS[$current_grant[0]])
205 && is_array($GLOBALS[$current_grant[0]])
206 && empty($GLOBALS[$current_grant[0] . '_none'])) {
207 if ($enableHTML) {
208 $priv_string = '<dfn title="' . $current_grant[2] . '">' . $current_grant[1] . '</dfn>';
209 } else {
210 $priv_string = $current_grant[1];
212 $privs[] = $priv_string . ' (`' . join('`, `', $GLOBALS[$current_grant[0]]) . '`)';
213 } else {
214 $allPrivileges = FALSE;
218 if (empty($privs)) {
219 if ($enableHTML) {
220 $privs[] = '<dfn title="' . $GLOBALS['strPrivDescUsage'] . '">USAGE</dfn>';
221 } else {
222 $privs[] = 'USAGE';
224 } elseif ($allPrivileges && (!isset($GLOBALS['grant_count']) || count($privs) == $GLOBALS['grant_count'])) {
225 if ($enableHTML) {
226 $privs = array('<dfn title="' . $GLOBALS['strPrivDescAllPrivileges'] . '">ALL PRIVILEGES</dfn>');
227 } else {
228 $privs = array('ALL PRIVILEGES');
231 return $privs;
232 } // end of the 'PMA_extractPrivInfo()' function
235 * Displays on which column(s) a table-specific privilege is granted
237 function PMA_display_column_privs($columns, $row, $name_for_select,
238 $priv_for_header, $name, $name_for_dfn, $name_for_current)
240 echo ' <div class="item" id="div_item_' . $name . '">' . "\n"
241 . ' <label for="select_' . $name . '_priv">' . "\n"
242 . ' <tt><dfn title="' . $name_for_dfn . '">'
243 . $priv_for_header . '</dfn></tt>' . "\n"
244 . ' </label><br />' . "\n"
245 . ' <select id="select_' . $name . '_priv" name="'
246 . $name_for_select . '[]" multiple="multiple" size="8">' . "\n";
248 foreach ($columns as $current_column => $current_column_privileges) {
249 echo ' <option value="' . htmlspecialchars($current_column) . '"';
250 if ($row[$name_for_select] == 'Y' || $current_column_privileges[$name_for_current]) {
251 echo ' selected="selected"';
253 echo '>' . htmlspecialchars($current_column) . '</option>' . "\n";
256 echo ' </select>' . "\n"
257 . ' <i>' . $GLOBALS['strOr'] . '</i>' . "\n"
258 . ' <label for="checkbox_' . $name_for_select
259 . '_none"><input type="checkbox"'
260 . (empty($GLOBALS['checkall']) ? '' : ' checked="checked"')
261 . ' name="' . $name_for_select . '_none" id="checkbox_'
262 . $name_for_select . '_none" title="' . $GLOBALS['strNone'] . '" />'
263 . $GLOBALS['strNone'] . '</label>' . "\n"
264 . ' </div>' . "\n";
265 } // end function
269 * Displays the privileges form table
271 * @param string $db the database
272 * @param string $table the table
273 * @param boolean $submit wheather to display the submit button or not
274 * @global array $cfg the phpMyAdmin configuration
275 * @global ressource $user_link the database connection
277 * @return void
279 function PMA_displayPrivTable($db = '*', $table = '*', $submit = TRUE)
281 if ($db == '*') {
282 $table = '*';
285 if (isset($GLOBALS['username'])) {
286 $username = $GLOBALS['username'];
287 $hostname = $GLOBALS['hostname'];
288 if ($db == '*') {
289 $sql_query =
290 "SELECT * FROM `mysql`.`user`"
291 ." WHERE `User` = '" . PMA_sqlAddslashes($username) . "'"
292 ." AND `Host` = '" . PMA_sqlAddslashes($hostname) . "';";
293 } elseif ($table == '*') {
294 $sql_query =
295 "SELECT * FROM `mysql`.`db`"
296 ." WHERE `User` = '" . PMA_sqlAddslashes($username) . "'"
297 ." AND `Host` = '" . PMA_sqlAddslashes($hostname) . "'"
298 ." AND '" . PMA_unescape_mysql_wildcards($db) . "'"
299 ." LIKE `Db`;";
300 } else {
301 $sql_query =
302 "SELECT `Table_priv`"
303 ." FROM `mysql`.`tables_priv`"
304 ." WHERE `User` = '" . PMA_sqlAddslashes($username) . "'"
305 ." AND `Host` = '" . PMA_sqlAddslashes($hostname) . "'"
306 ." AND `Db` = '" . PMA_unescape_mysql_wildcards($db) . "'"
307 ." AND `Table_name` = '" . PMA_sqlAddslashes($table) . "';";
309 $row = PMA_DBI_fetch_single_row($sql_query);
311 if (empty($row)) {
312 if ($table == '*') {
313 if ($db == '*') {
314 $sql_query = 'SHOW COLUMNS FROM `mysql`.`user`;';
315 } elseif ($table == '*') {
316 $sql_query = 'SHOW COLUMNS FROM `mysql`.`db`;';
318 $res = PMA_DBI_query($sql_query);
319 while ($row1 = PMA_DBI_fetch_row($res)) {
320 if (substr($row1[0], 0, 4) == 'max_') {
321 $row[$row1[0]] = 0;
322 } else {
323 $row[$row1[0]] = 'N';
326 PMA_DBI_free_result($res);
327 } else {
328 $row = array('Table_priv' => '');
331 if (isset($row['Table_priv'])) {
332 $row1 = PMA_DBI_fetch_single_row(
333 'SHOW COLUMNS FROM `mysql`.`tables_priv` LIKE \'Table_priv\';',
334 'ASSOC', $GLOBALS['userlink']);
335 // note: in MySQL 5.0.3 we get "Create View', 'Show view';
336 // the View for Create is spelled with uppercase V
337 // the view for Show is spelled with lowercase v
338 // and there is a space between the words
340 $av_grants = explode('\',\'', substr($row1['Type'], strpos($row1['Type'], '(') + 2, strpos($row1['Type'], ')') - strpos($row1['Type'], '(') - 3));
341 unset($row1);
342 $users_grants = explode(',', $row['Table_priv']);
344 foreach ($av_grants as $current_grant) {
345 $row[$current_grant . '_priv'] = in_array($current_grant, $users_grants) ? 'Y' : 'N';
347 unset($row['Table_priv'], $current_grant, $av_grants, $users_grants);
349 // get collumns
350 $res = PMA_DBI_try_query('SHOW COLUMNS FROM `' . PMA_unescape_mysql_wildcards($db) . '`.`' . $table . '`;');
351 $columns = array();
352 if ($res) {
353 while ($row1 = PMA_DBI_fetch_row($res)) {
354 $columns[$row1[0]] = array(
355 'Select' => FALSE,
356 'Insert' => FALSE,
357 'Update' => FALSE,
358 'References' => FALSE
361 PMA_DBI_free_result($res);
363 unset($res, $row1);
365 // t a b l e - s p e c i f i c p r i v i l e g e s
366 if (! empty($columns)) {
367 $res = PMA_DBI_query(
368 'SELECT `Column_name`, `Column_priv`'
369 .' FROM `mysql`.`columns_priv`'
370 .' WHERE `User`'
371 .' = \'' . PMA_sqlAddslashes($username) . "'"
372 .' AND `Host`'
373 .' = \'' . PMA_sqlAddslashes($hostname) . "'"
374 .' AND `Db`'
375 .' = \'' . PMA_unescape_mysql_wildcards($db) . "'"
376 .' AND `Table_name`'
377 .' = \'' . PMA_sqlAddslashes($table) . '\';');
379 while ($row1 = PMA_DBI_fetch_row($res)) {
380 $row1[1] = explode(',', $row1[1]);
381 foreach ($row1[1] as $current) {
382 $columns[$row1[0]][$current] = TRUE;
385 PMA_DBI_free_result($res);
386 unset($res, $row1, $current);
388 echo '<input type="hidden" name="grant_count" value="' . count($row) . '" />' . "\n"
389 . '<input type="hidden" name="column_count" value="' . count($columns) . '" />' . "\n"
390 . '<fieldset id="fieldset_user_priv">' . "\n"
391 . ' <legend>' . $GLOBALS['strTblPrivileges']
392 . PMA_showHint($GLOBALS['strEnglishPrivileges'])
393 . '</legend>' . "\n";
397 // privs that are attached to a specific column
398 PMA_display_column_privs($columns, $row, 'Select_priv',
399 'SELECT', 'select', $GLOBALS['strPrivDescSelect'], 'Select');
401 PMA_display_column_privs($columns, $row, 'Insert_priv',
402 'INSERT', 'insert', $GLOBALS['strPrivDescInsert'], 'Insert');
404 PMA_display_column_privs($columns, $row, 'Update_priv',
405 'UPDATE', 'update', $GLOBALS['strPrivDescUpdate'], 'Update');
407 PMA_display_column_privs($columns, $row, 'References_priv',
408 'REFERENCES', 'references', $GLOBALS['strPrivDescReferences'], 'References');
410 // privs that are not attached to a specific column
412 echo ' <div class="item">' . "\n";
413 foreach ($row as $current_grant => $current_grant_value) {
414 if (in_array(substr($current_grant, 0, (strlen($current_grant) - 5)),
415 array('Select', 'Insert', 'Update', 'References'))) {
416 continue;
418 // make a substitution to match the messages variables;
419 // also we must substitute the grant we get, because we can't generate
420 // a form variable containing blanks (those would get changed to
421 // an underscore when receiving the POST)
422 if ($current_grant == 'Create View_priv') {
423 $tmp_current_grant = 'CreateView_priv';
424 $current_grant = 'Create_view_priv';
425 } elseif ($current_grant == 'Show view_priv') {
426 $tmp_current_grant = 'ShowView_priv';
427 $current_grant = 'Show_view_priv';
428 } else {
429 $tmp_current_grant = $current_grant;
432 echo ' <div class="item">' . "\n"
433 . ' <input type="checkbox"'
434 . (empty($GLOBALS['checkall']) ? '' : ' checked="checked"')
435 . ' name="' . $current_grant . '" id="checkbox_' . $current_grant
436 . '" value="Y" '
437 . ($current_grant_value == 'Y' ? 'checked="checked" ' : '')
438 . 'title="';
440 echo (isset($GLOBALS['strPrivDesc' . substr($tmp_current_grant, 0, (strlen($tmp_current_grant) - 5))])
441 ? $GLOBALS['strPrivDesc' . substr($tmp_current_grant, 0, (strlen($tmp_current_grant) - 5))]
442 : $GLOBALS['strPrivDesc' . substr($tmp_current_grant, 0, (strlen($tmp_current_grant) - 5)) . 'Tbl']) . '"/>' . "\n";
444 echo ' <label for="checkbox_' . $current_grant
445 . '"><tt><dfn title="'
446 . (isset($GLOBALS['strPrivDesc' . substr($tmp_current_grant, 0, (strlen($tmp_current_grant) - 5))])
447 ? $GLOBALS['strPrivDesc' . substr($tmp_current_grant, 0, (strlen($tmp_current_grant) - 5))]
448 : $GLOBALS['strPrivDesc' . substr($tmp_current_grant, 0, (strlen($tmp_current_grant) - 5)) . 'Tbl'])
449 . '">' . strtoupper(substr($current_grant, 0, strlen($current_grant) - 5)) . '</dfn></tt></label>' . "\n"
450 . ' </div>' . "\n";
451 } // end foreach ()
453 echo ' </div>' . "\n";
454 // for Safari 2.0.2
455 echo ' <div class="clearfloat"></div>' . "\n";
457 } else {
459 // g l o b a l o r d b - s p e c i f i c
461 // d a t a
462 $privTable[0] = array(
463 array('Select', 'SELECT', $GLOBALS['strPrivDescSelect']),
464 array('Insert', 'INSERT', $GLOBALS['strPrivDescInsert']),
465 array('Update', 'UPDATE', $GLOBALS['strPrivDescUpdate']),
466 array('Delete', 'DELETE', $GLOBALS['strPrivDescDelete'])
468 if ($db == '*') {
469 $privTable[0][] = array('File', 'FILE', $GLOBALS['strPrivDescFile']);
472 // s t r u c t u r e
473 $privTable[1] = array(
474 array('Create', 'CREATE', ($table == '*' ? $GLOBALS['strPrivDescCreateDb'] : $GLOBALS['strPrivDescCreateTbl'])),
475 array('Alter', 'ALTER', $GLOBALS['strPrivDescAlter']),
476 array('Index', 'INDEX', $GLOBALS['strPrivDescIndex']),
477 array('Drop', 'DROP', ($table == '*' ? $GLOBALS['strPrivDescDropDb'] : $GLOBALS['strPrivDescDropTbl'])),
478 array('Create_tmp_table', 'CREATE TEMPORARY TABLES', $GLOBALS['strPrivDescCreateTmpTable']),
479 array('Show_view', 'SHOW VIEW', $GLOBALS['strPrivDescShowView']),
480 array('Create_routine', 'CREATE ROUTINE', $GLOBALS['strPrivDescCreateRoutine']),
481 array('Alter_routine', 'ALTER ROUTINE', $GLOBALS['strPrivDescAlterRoutine']),
482 array('Execute', 'EXECUTE', $GLOBALS['strPrivDescExecute5']),
484 // this one is for a db-specific priv: Create_view_priv
485 if (isset($row['Create_view_priv'])) {
486 $privTable[1][] = array('Create_view', 'CREATE VIEW', $GLOBALS['strPrivDescCreateView']);
488 // this one is for a table-specific priv: Create View_priv
489 if (isset($row['Create View_priv'])) {
490 $privTable[1][] = array('Create View', 'CREATE VIEW', $GLOBALS['strPrivDescCreateView']);
492 if (isset($row['Event_priv'])) {
493 // MySQL 5.1.6
494 $privTable[1][] = array('Event', 'EVENT', $GLOBALS['strPrivDescEvent']);
495 $privTable[1][] = array('Trigger', 'TRIGGER', $GLOBALS['strPrivDescTrigger']);
498 // a d m i n i s t r a t i o n
499 $privTable[2] = array(
500 array('Grant', 'GRANT', $GLOBALS['strPrivDescGrant']),
502 if ($db == '*') {
503 $privTable[2][] = array('Super', 'SUPER', $GLOBALS['strPrivDescSuper']);
504 $privTable[2][] = array('Process', 'PROCESS', $GLOBALS['strPrivDescProcess']);
505 $privTable[2][] = array('Reload', 'RELOAD', $GLOBALS['strPrivDescReload']);
506 $privTable[2][] = array('Shutdown', 'SHUTDOWN', $GLOBALS['strPrivDescShutdown']);
507 $privTable[2][] = array('Show_db', 'SHOW DATABASES', $GLOBALS['strPrivDescShowDb']);
509 $privTable[2][] = array('Lock_tables', 'LOCK TABLES', $GLOBALS['strPrivDescLockTables']);
510 $privTable[2][] = array('References', 'REFERENCES', $GLOBALS['strPrivDescReferences']);
511 if ($db == '*') {
512 $privTable[2][] = array('Repl_client', 'REPLICATION CLIENT', $GLOBALS['strPrivDescReplClient']);
513 $privTable[2][] = array('Repl_slave', 'REPLICATION SLAVE', $GLOBALS['strPrivDescReplSlave']);
514 $privTable[2][] = array('Create_user', 'CREATE USER', $GLOBALS['strPrivDescCreateUser']);
516 echo '<input type="hidden" name="grant_count" value="'
517 . (count($privTable[0]) + count($privTable[1]) + count($privTable[2]) - (isset($row['Grant_priv']) ? 1 : 0))
518 . '" />' . "\n"
519 . '<fieldset id="fieldset_user_global_rights">' . "\n"
520 . ' <legend>' . "\n"
521 . ' '
522 . ($db == '*'
523 ? $GLOBALS['strGlobalPrivileges']
524 : ($table == '*'
525 ? $GLOBALS['strDbPrivileges']
526 : $GLOBALS['strTblPrivileges'])) . "\n"
527 . ' (<a href="server_privileges.php?'
528 . $GLOBALS['url_query'] . '&amp;checkall=1" onclick="setCheckboxes(\'usersForm\', true); return false;">'
529 . $GLOBALS['strCheckAll'] . '</a> /' . "\n"
530 . ' <a href="server_privileges.php?'
531 . $GLOBALS['url_query'] . '" onclick="setCheckboxes(\'usersForm\', false); return false;">'
532 . $GLOBALS['strUncheckAll'] . '</a>)' . "\n"
533 . ' </legend>' . "\n"
534 . ' <p><small><i>' . $GLOBALS['strEnglishPrivileges'] . '</i></small></p>' . "\n"
535 . ' <fieldset>' . "\n"
536 . ' <legend>' . $GLOBALS['strData'] . '</legend>' . "\n";
537 foreach ($privTable[0] as $priv)
539 echo ' <div class="item">' . "\n"
540 . ' <input type="checkbox"'
541 . (empty($GLOBALS['checkall']) ? '' : ' checked="checked"')
542 . ' name="' . $priv[0] . '_priv" id="checkbox_' . $priv[0]
543 . '_priv" value="Y" '
544 . ($row[$priv[0] . '_priv'] == 'Y' ? 'checked="checked" ' : '')
545 . 'title="' . $priv[2] . '"/>' . "\n"
546 . ' <label for="checkbox_' . $priv[0]
547 . '_priv"><tt><dfn title="' . $priv[2] . '">' . $priv[1]
548 . '</dfn></tt></label>' . "\n"
549 . ' </div>' . "\n";
551 echo ' </fieldset>' . "\n"
552 . ' <fieldset>' . "\n"
553 . ' <legend>' . $GLOBALS['strStructure'] . '</legend>' . "\n";
554 foreach ($privTable[1] as $priv)
556 echo ' <div class="item">' . "\n"
557 . ' <input type="checkbox"'
558 . (empty($GLOBALS['checkall']) ? '' : ' checked="checked"')
559 . ' name="' . $priv[0] . '_priv" id="checkbox_' . $priv[0]
560 . '_priv" value="Y" '
561 . ($row[$priv[0] . '_priv'] == 'Y' ? 'checked="checked" ' : '')
562 . 'title="' . $priv[2] . '"/>' . "\n"
563 . ' <label for="checkbox_' . $priv[0]
564 . '_priv"><tt><dfn title="' . $priv[2] . '">' . $priv[1]
565 . '</dfn></tt></label>' . "\n"
566 . ' </div>' . "\n";
568 echo ' </fieldset>' . "\n"
569 . ' <fieldset>' . "\n"
570 . ' <legend>' . $GLOBALS['strAdministration'] . '</legend>' . "\n";
571 foreach ($privTable[2] as $priv)
573 echo ' <div class="item">' . "\n"
574 . ' <input type="checkbox"'
575 . (empty($GLOBALS['checkall']) ? '' : ' checked="checked"')
576 . ' name="' . $priv[0] . '_priv" id="checkbox_' . $priv[0]
577 . '_priv" value="Y" '
578 . ($row[$priv[0] . '_priv'] == 'Y' ? 'checked="checked" ' : '')
579 . 'title="' . $priv[2] . '"/>' . "\n"
580 . ' <label for="checkbox_' . $priv[0]
581 . '_priv"><tt><dfn title="' . $priv[2] . '">' . $priv[1]
582 . '</dfn></tt></label>' . "\n"
583 . ' </div>' . "\n";
586 echo ' </fieldset>' . "\n";
587 // The "Resource limits" box is not displayed for db-specific privs
588 if ($db == '*') {
589 echo ' <fieldset>' . "\n"
590 . ' <legend>' . $GLOBALS['strResourceLimits'] . '</legend>' . "\n"
591 . ' <p><small><i>' . $GLOBALS['strZeroRemovesTheLimit'] . '</i></small></p>' . "\n"
592 . ' <div class="item">' . "\n"
593 . ' <label for="text_max_questions"><tt><dfn title="'
594 . $GLOBALS['strPrivDescMaxQuestions'] . '">MAX QUERIES PER HOUR</dfn></tt></label>' . "\n"
595 . ' <input type="text" name="max_questions" id="text_max_questions" value="'
596 . $row['max_questions'] . '" size="11" maxlength="11" title="' . $GLOBALS['strPrivDescMaxQuestions'] . '" />' . "\n"
597 . ' </div>' . "\n"
598 . ' <div class="item">' . "\n"
599 . ' <label for="text_max_updates"><tt><dfn title="'
600 . $GLOBALS['strPrivDescMaxUpdates'] . '">MAX UPDATES PER HOUR</dfn></tt></label>' . "\n"
601 . ' <input type="text" name="max_updates" id="text_max_updates" value="'
602 . $row['max_updates'] . '" size="11" maxlength="11" title="' . $GLOBALS['strPrivDescMaxUpdates'] . '" />' . "\n"
603 . ' </div>' . "\n"
604 . ' <div class="item">' . "\n"
605 . ' <label for="text_max_connections"><tt><dfn title="'
606 . $GLOBALS['strPrivDescMaxConnections'] . '">MAX CONNECTIONS PER HOUR</dfn></tt></label>' . "\n"
607 . ' <input type="text" name="max_connections" id="text_max_connections" value="'
608 . $row['max_connections'] . '" size="11" maxlength="11" title="' . $GLOBALS['strPrivDescMaxConnections'] . '" />' . "\n"
609 . ' </div>' . "\n"
610 . ' <div class="item">' . "\n"
611 . ' <label for="text_max_user_connections"><tt><dfn title="'
612 . $GLOBALS['strPrivDescMaxUserConnections'] . '">MAX USER_CONNECTIONS</dfn></tt></label>' . "\n"
613 . ' <input type="text" name="max_user_connections" id="text_max_user_connections" value="'
614 . $row['max_user_connections'] . '" size="11" maxlength="11" title="' . $GLOBALS['strPrivDescMaxUserConnections'] . '" />' . "\n"
615 . ' </div>' . "\n"
616 . ' </fieldset>' . "\n";
618 // for Safari 2.0.2
619 echo ' <div class="clearfloat"></div>' . "\n";
621 echo '</fieldset>' . "\n";
622 if ($submit) {
623 echo '<fieldset id="fieldset_user_privtable_footer" class="tblFooters">' . "\n"
624 . ' <input type="submit" name="update_privs" value="' . $GLOBALS['strGo'] . '" />' . "\n"
625 . '</fieldset>' . "\n";
627 } // end of the 'PMA_displayPrivTable()' function
631 * Displays the fields used by the "new user" form as well as the
632 * "change login information / copy user" form.
634 * @param string $mode are we creating a new user or are we just
635 * changing one? (allowed values: 'new', 'change')
636 * @global array $cfg the phpMyAdmin configuration
637 * @global ressource $user_link the database connection
639 * @return void
641 function PMA_displayLoginInformationFields($mode = 'new')
643 // Get user/host name lengths
644 $fields_info = PMA_DBI_get_fields('mysql', 'user');
645 $username_length = 16;
646 $hostname_length = 41;
647 foreach ($fields_info as $key => $val) {
648 if ($val['Field'] == 'User') {
649 strtok($val['Type'], '()');
650 $v = strtok('()');
651 if (is_int($v)) {
652 $username_length = $v;
654 } elseif ($val['Field'] == 'Host') {
655 strtok($val['Type'], '()');
656 $v = strtok('()');
657 if (is_int($v)) {
658 $hostname_length = $v;
662 unset($fields_info);
664 if (isset($GLOBALS['username']) && strlen($GLOBALS['username']) === 0) {
665 $GLOBALS['pred_username'] = 'any';
667 echo '<fieldset id="fieldset_add_user_login">' . "\n"
668 . '<legend>' . $GLOBALS['strLoginInformation'] . '</legend>' . "\n"
669 . '<div class="item">' . "\n"
670 . '<label for="select_pred_username">' . "\n"
671 . ' ' . $GLOBALS['strUserName'] . ':' . "\n"
672 . '</label>' . "\n"
673 . '<span class="options">' . "\n"
674 . ' <select name="pred_username" id="select_pred_username" title="' . $GLOBALS['strUserName'] . '"' . "\n"
675 . ' onchange="if (this.value == \'any\') { username.value = \'\'; } else if (this.value == \'userdefined\') { username.focus(); username.select(); }">' . "\n"
676 . ' <option value="any"' . ((isset($GLOBALS['pred_username']) && $GLOBALS['pred_username'] == 'any') ? ' selected="selected"' : '') . '>' . $GLOBALS['strAnyUser'] . '</option>' . "\n"
677 . ' <option value="userdefined"' . ((!isset($GLOBALS['pred_username']) || $GLOBALS['pred_username'] == 'userdefined') ? ' selected="selected"' : '') . '>' . $GLOBALS['strUseTextField'] . ':</option>' . "\n"
678 . ' </select>' . "\n"
679 . '</span>' . "\n"
680 . '<input type="text" name="username" maxlength="'
681 . $username_length . '" title="' . $GLOBALS['strUserName'] . '"'
682 . (empty($GLOBALS['username'])
683 ? ''
684 : ' value="' . (isset($GLOBALS['new_username'])
685 ? $GLOBALS['new_username']
686 : $GLOBALS['username']) . '"')
687 . ' onchange="pred_username.value = \'userdefined\';" />' . "\n"
688 . '</div>' . "\n"
689 . '<div class="item">' . "\n"
690 . '<label for="select_pred_hostname">' . "\n"
691 . ' ' . $GLOBALS['strHost'] . ':' . "\n"
692 . '</label>' . "\n"
693 . '<span class="options">' . "\n"
694 . ' <select name="pred_hostname" id="select_pred_hostname" title="' . $GLOBALS['strHost'] . '"' . "\n";
695 $_current_user = PMA_DBI_fetch_value('SELECT USER();');
696 if (! empty($_current_user)) {
697 $thishost = str_replace("'", '', substr($_current_user, (strrpos($_current_user, '@') + 1)));
698 if ($thishost == 'localhost' || $thishost == '127.0.0.1') {
699 unset($thishost);
702 echo ' onchange="if (this.value == \'any\') { hostname.value = \'%\'; } else if (this.value == \'localhost\') { hostname.value = \'localhost\'; } '
703 . (empty($thishost) ? '' : 'else if (this.value == \'thishost\') { hostname.value = \'' . addslashes(htmlspecialchars($thishost)) . '\'; } ')
704 . 'else if (this.value == \'hosttable\') { hostname.value = \'\'; } else if (this.value == \'userdefined\') { hostname.focus(); hostname.select(); }">' . "\n";
705 unset($_current_user);
707 // when we start editing a user, $GLOBALS['pred_hostname'] is not defined
708 if (!isset($GLOBALS['pred_hostname']) && isset($GLOBALS['hostname'])) {
709 switch (strtolower($GLOBALS['hostname'])) {
710 case 'localhost':
711 case '127.0.0.1':
712 $GLOBALS['pred_hostname'] = 'localhost';
713 break;
714 case '%':
715 $GLOBALS['pred_hostname'] = 'any';
716 break;
717 default:
718 $GLOBALS['pred_hostname'] = 'userdefined';
719 break;
722 echo ' <option value="any"'
723 . ((isset($GLOBALS['pred_hostname']) && $GLOBALS['pred_hostname'] == 'any')
724 ? ' selected="selected"' : '') . '>' . $GLOBALS['strAnyHost']
725 . '</option>' . "\n"
726 . ' <option value="localhost"'
727 . ((isset($GLOBALS['pred_hostname']) && $GLOBALS['pred_hostname'] == 'localhost')
728 ? ' selected="selected"' : '') . '>' . $GLOBALS['strLocalhost']
729 . '</option>' . "\n";
730 if (!empty($thishost)) {
731 echo ' <option value="thishost"'
732 . ((isset($GLOBALS['pred_hostname']) && $GLOBALS['pred_hostname'] == 'thishost')
733 ? ' selected="selected"' : '') . '>' . $GLOBALS['strThisHost']
734 . '</option>' . "\n";
736 unset($thishost);
737 echo ' <option value="hosttable"'
738 . ((isset($GLOBALS['pred_hostname']) && $GLOBALS['pred_hostname'] == 'hosttable')
739 ? ' selected="selected"' : '') . '>' . $GLOBALS['strUseHostTable']
740 . '</option>' . "\n"
741 . ' <option value="userdefined"'
742 . ((isset($GLOBALS['pred_hostname']) && $GLOBALS['pred_hostname'] == 'userdefined')
743 ? ' selected="selected"' : '')
744 . '>' . $GLOBALS['strUseTextField'] . ':</option>' . "\n"
745 . ' </select>' . "\n"
746 . '</span>' . "\n"
747 . '<input type="text" name="hostname" maxlength="'
748 . $hostname_length . '" value="'
749 . (isset($GLOBALS['hostname']) ? $GLOBALS['hostname'] : '')
750 . '" title="' . $GLOBALS['strHost']
751 . '" onchange="pred_hostname.value = \'userdefined\';" />' . "\n"
752 . '</div>' . "\n"
753 . '<div class="item">' . "\n"
754 . '<label for="select_pred_password">' . "\n"
755 . ' ' . $GLOBALS['strPassword'] . ':' . "\n"
756 . '</label>' . "\n"
757 . '<span class="options">' . "\n"
758 . ' <select name="pred_password" id="select_pred_password" title="'
759 . $GLOBALS['strPassword'] . '"' . "\n"
760 . ' onchange="if (this.value == \'none\') { pma_pw.value = \'\'; pma_pw2.value = \'\'; } else if (this.value == \'userdefined\') { pma_pw.focus(); pma_pw.select(); }">' . "\n"
761 . ($mode == 'change' ? ' <option value="keep" selected="selected">' . $GLOBALS['strKeepPass'] . '</option>' . "\n" : '')
762 . ' <option value="none"';
763 if (isset($GLOBALS['username']) && $mode != 'change') {
764 echo ' selected="selected"';
766 echo '>' . $GLOBALS['strNoPassword'] . '</option>' . "\n"
767 . ' <option value="userdefined"' . (isset($GLOBALS['username']) ? '' : ' selected="selected"') . '>' . $GLOBALS['strUseTextField'] . ':</option>' . "\n"
768 . ' </select>' . "\n"
769 . '</span>' . "\n"
770 . '<input type="password" id="text_pma_pw" name="pma_pw" title="' . $GLOBALS['strPassword'] . '" onchange="pred_password.value = \'userdefined\';" />' . "\n"
771 . '</div>' . "\n"
772 . '<div class="item">' . "\n"
773 . '<label for="text_pma_pw2">' . "\n"
774 . ' ' . $GLOBALS['strReType'] . ':' . "\n"
775 . '</label>' . "\n"
776 . '<span class="options">&nbsp;</span>' . "\n"
777 . '<input type="password" name="pma_pw2" id="text_pma_pw2" title="' . $GLOBALS['strReType'] . '" onchange="pred_password.value = \'userdefined\';" />' . "\n"
778 . '</div>' . "\n"
779 . '<div class="item">' . "\n"
780 . '<label for="button_generate_password">' . "\n"
781 . ' ' . $GLOBALS['strGeneratePassword'] . ':' . "\n"
782 . '</label>' . "\n"
783 . '<span class="options">' . "\n"
784 . ' <input type="button" id="button_generate_password" value="' . $GLOBALS['strGenerate'] . '" onclick="suggestPassword()" />' . "\n"
785 . ' <input type="button" id="button_copy_password" value="' . $GLOBALS['strCopy'] . '" onclick="suggestPasswordCopy(this.form)" />' . "\n"
786 . '</span>' . "\n"
787 . '<input type="text" name="generated_pw" id="generated_pw" />' . "\n"
788 . '</div>' . "\n"
789 . '</fieldset>' . "\n";
790 } // end of the 'PMA_displayUserAndHostFields()' function
794 * Changes / copies a user, part I
796 if (isset($_REQUEST['change_copy'])) {
797 $user_host_condition =
798 ' WHERE `User`'
799 .' = \'' . PMA_sqlAddslashes($old_username) . "'"
800 .' AND `Host`'
801 .' = \'' . $old_hostname . '\';';
802 $row = PMA_DBI_fetch_single_row('SELECT * FROM `mysql`.`user` ' . $user_host_condition);
803 if (! $row) {
804 PMA_Message::notice('strNoUsersFound')->display();
805 unset($_REQUEST['change_copy']);
806 } else {
807 extract($row, EXTR_OVERWRITE);
808 // Recent MySQL versions have the field "Password" in mysql.user,
809 // so the previous extract creates $Password but this script
810 // uses $password
811 if (!isset($password) && isset($Password)) {
812 $password = $Password;
814 $queries = array();
820 * Adds a user
821 * (Changes / copies a user, part II)
823 if (isset($_REQUEST['adduser_submit']) || isset($_REQUEST['change_copy'])) {
824 $sql_query = '';
825 if ($pred_username == 'any') {
826 $username = '';
828 switch ($pred_hostname) {
829 case 'any':
830 $hostname = '%';
831 break;
832 case 'localhost':
833 $hostname = 'localhost';
834 break;
835 case 'hosttable':
836 $hostname = '';
837 break;
838 case 'thishost':
839 $_user_name = PMA_DBI_fetch_value('SELECT USER()');
840 $hostname = substr($_user_name, (strrpos($_user_name, '@') + 1));
841 unset($_user_name);
842 break;
844 $sql = "SELECT '1' FROM `mysql`.`user`"
845 . " WHERE `User` = '" . PMA_sqlAddslashes($username) . "'"
846 . " AND `Host` = '" . PMA_sqlAddslashes($hostname) . "';";
847 if (PMA_DBI_fetch_value($sql) == 1) {
848 $message = PMA_Message::error('strUserAlreadyExists');
849 $message->addParam('[i]\'' . $username . '\'@\'' . $hostname . '\'[/i]');
850 $_REQUEST['adduser'] = true;
851 } else {
853 $create_user_real = 'CREATE USER \'' . PMA_sqlAddslashes($username) . '\'@\'' . $hostname . '\'';
855 $real_sql_query =
856 'GRANT ' . join(', ', PMA_extractPrivInfo()) . ' ON *.* TO \''
857 . PMA_sqlAddslashes($username) . '\'@\'' . $hostname . '\'';
858 if ($pred_password != 'none' && $pred_password != 'keep') {
859 $sql_query = $real_sql_query . ' IDENTIFIED BY \'***\'';
860 $real_sql_query .= ' IDENTIFIED BY \'' . PMA_sqlAddslashes($pma_pw) . '\'';
861 if (isset($create_user_real)) {
862 $create_user_show = $create_user_real . ' IDENTIFIED BY \'***\'';
863 $create_user_real .= ' IDENTIFIED BY \'' . PMA_sqlAddslashes($pma_pw) . '\'';
865 } else {
866 if ($pred_password == 'keep' && !empty($password)) {
867 $real_sql_query .= ' IDENTIFIED BY PASSWORD \'' . $password . '\'';
868 if (isset($create_user_real)) {
869 $create_user_real .= ' IDENTIFIED BY PASSWORD \'' . $password . '\'';
872 $sql_query = $real_sql_query;
873 if (isset($create_user_real)) {
874 $create_user_show = $create_user_real;
878 * @todo similar code appears twice in this script
880 if ((isset($Grant_priv) && $Grant_priv == 'Y')
881 || (isset($max_questions) || isset($max_connections)
882 || isset($max_updates) || isset($max_user_connections))) {
883 $real_sql_query .= ' WITH';
884 $sql_query .= ' WITH';
885 if (isset($Grant_priv) && $Grant_priv == 'Y') {
886 $real_sql_query .= ' GRANT OPTION';
887 $sql_query .= ' GRANT OPTION';
889 if (isset($max_questions)) {
890 // avoid negative values
891 $max_questions = max(0, (int)$max_questions);
892 $real_sql_query .= ' MAX_QUERIES_PER_HOUR ' . $max_questions;
893 $sql_query .= ' MAX_QUERIES_PER_HOUR ' . $max_questions;
895 if (isset($max_connections)) {
896 $max_connections = max(0, (int)$max_connections);
897 $real_sql_query .= ' MAX_CONNECTIONS_PER_HOUR ' . $max_connections;
898 $sql_query .= ' MAX_CONNECTIONS_PER_HOUR ' . $max_connections;
900 if (isset($max_updates)) {
901 $max_updates = max(0, (int)$max_updates);
902 $real_sql_query .= ' MAX_UPDATES_PER_HOUR ' . $max_updates;
903 $sql_query .= ' MAX_UPDATES_PER_HOUR ' . $max_updates;
905 if (isset($max_user_connections)) {
906 $max_user_connections = max(0, (int)$max_user_connections);
907 $real_sql_query .= ' MAX_USER_CONNECTIONS ' . $max_user_connections;
908 $sql_query .= ' MAX_USER_CONNECTIONS ' . $max_user_connections;
911 if (isset($create_user_real)) {
912 $create_user_real .= ';';
913 $create_user_show .= ';';
915 $real_sql_query .= ';';
916 $sql_query .= ';';
917 if (empty($_REQUEST['change_copy'])) {
918 $_error = false;
920 if (isset($create_user_real)) {
921 if (! PMA_DBI_try_query($create_user_real)) {
922 $_error = true;
924 $sql_query = $create_user_show . $sql_query;
927 if ($_error || ! PMA_DBI_try_query($real_sql_query)) {
928 $_REQUEST['createdb'] = false;
929 $message = PMA_Message::rawError(PMA_DBI_getError());
930 } else {
931 $message = PMA_Message::success('strAddUserMessage');
934 switch (PMA_ifSetOr($_REQUEST['createdb'], '0')) {
935 case '1' :
936 $q = 'CREATE DATABASE IF NOT EXISTS '
937 . PMA_backquote(PMA_sqlAddslashes($username)) . ';';
938 $sql_query .= $q;
939 if (! PMA_DBI_try_query($q)) {
940 $message = PMA_Message::rawError(PMA_DBI_getError());
941 break;
943 $GLOBALS['reload'] = TRUE;
944 PMA_reloadNavigation();
946 $q = 'GRANT ALL PRIVILEGES ON '
947 . PMA_backquote(PMA_sqlAddslashes($username)) . '.* TO \''
948 . PMA_sqlAddslashes($username) . '\'@\'' . $hostname . '\';';
949 $sql_query .= $q;
950 if (! PMA_DBI_try_query($q)) {
951 $message = PMA_Message::rawError(PMA_DBI_getError());
953 break;
954 case '2' :
955 $q = 'GRANT ALL PRIVILEGES ON '
956 . PMA_backquote(PMA_sqlAddslashes($username) . '\_%') . '.* TO \''
957 . PMA_sqlAddslashes($username) . '\'@\'' . $hostname . '\';';
958 $sql_query .= $q;
959 if (! PMA_DBI_try_query($q)) {
960 $message = PMA_Message::rawError(PMA_DBI_getError());
962 break;
963 case '0' :
964 default :
965 break;
967 } else {
968 if (isset($create_user_real)) {
969 $queries[] = $create_user_real;
971 $queries[] = $real_sql_query;
972 // we put the query containing the hidden password in
973 // $queries_for_display, at the same position occupied
974 // by the real query in $queries
975 $tmp_count = count($queries);
976 if (isset($create_user_real)) {
977 $queries_for_display[$tmp_count - 2] = $create_user_show;
979 $queries_for_display[$tmp_count - 1] = $sql_query;
981 unset($res, $real_sql_query);
987 * Changes / copies a user, part III
989 if (isset($_REQUEST['change_copy'])) {
990 $user_host_condition =
991 ' WHERE `User`'
992 .' = \'' . PMA_sqlAddslashes($old_username) . "'"
993 .' AND `Host`'
994 .' = \'' . $old_hostname . '\';';
995 $res = PMA_DBI_query('SELECT * FROM `mysql`.`db`' . $user_host_condition);
996 while ($row = PMA_DBI_fetch_assoc($res)) {
997 $queries[] =
998 'GRANT ' . join(', ', PMA_extractPrivInfo($row))
999 .' ON `' . $row['Db'] . '`.*'
1000 .' TO \'' . PMA_sqlAddslashes($username) . '\'@\'' . $hostname . '\''
1001 . ($row['Grant_priv'] == 'Y' ? ' WITH GRANT OPTION;' : ';');
1003 PMA_DBI_free_result($res);
1004 $res = PMA_DBI_query(
1005 'SELECT `Db`, `Table_name`, `Table_priv`'
1006 .' FROM `mysql`.`tables_priv`' . $user_host_condition,
1007 $GLOBALS['userlink'], PMA_DBI_QUERY_STORE);
1008 while ($row = PMA_DBI_fetch_assoc($res)) {
1010 $res2 = PMA_DBI_QUERY(
1011 'SELECT `Column_name`, `Column_priv`'
1012 .' FROM `mysql`.`columns_priv`'
1013 .' WHERE `User`'
1014 .' = \'' . PMA_sqlAddslashes($old_username) . "'"
1015 .' AND `Host`'
1016 .' = \'' . $old_hostname . '\''
1017 .' AND `Db`'
1018 .' = \'' . $row['Db'] . "'"
1019 .' AND `Table_name`'
1020 .' = \'' . $row['Table_name'] . "'"
1021 .';',
1022 null, PMA_DBI_QUERY_STORE);
1024 $tmp_privs1 = PMA_extractPrivInfo($row);
1025 $tmp_privs2 = array(
1026 'Select' => array(),
1027 'Insert' => array(),
1028 'Update' => array(),
1029 'References' => array()
1032 while ($row2 = PMA_DBI_fetch_assoc($res2)) {
1033 $tmp_array = explode(',', $row2['Column_priv']);
1034 if (in_array('Select', $tmp_array)) {
1035 $tmp_privs2['Select'][] = $row2['Column_name'];
1037 if (in_array('Insert', $tmp_array)) {
1038 $tmp_privs2['Insert'][] = $row2['Column_name'];
1040 if (in_array('Update', $tmp_array)) {
1041 $tmp_privs2['Update'][] = $row2['Column_name'];
1043 if (in_array('References', $tmp_array)) {
1044 $tmp_privs2['References'][] = $row2['Column_name'];
1046 unset($tmp_array);
1048 if (count($tmp_privs2['Select']) > 0 && !in_array('SELECT', $tmp_privs1)) {
1049 $tmp_privs1[] = 'SELECT (`' . join('`, `', $tmp_privs2['Select']) . '`)';
1051 if (count($tmp_privs2['Insert']) > 0 && !in_array('INSERT', $tmp_privs1)) {
1052 $tmp_privs1[] = 'INSERT (`' . join('`, `', $tmp_privs2['Insert']) . '`)';
1054 if (count($tmp_privs2['Update']) > 0 && !in_array('UPDATE', $tmp_privs1)) {
1055 $tmp_privs1[] = 'UPDATE (`' . join('`, `', $tmp_privs2['Update']) . '`)';
1057 if (count($tmp_privs2['References']) > 0 && !in_array('REFERENCES', $tmp_privs1)) {
1058 $tmp_privs1[] = 'REFERENCES (`' . join('`, `', $tmp_privs2['References']) . '`)';
1060 unset($tmp_privs2);
1061 $queries[] =
1062 'GRANT ' . join(', ', $tmp_privs1)
1063 . ' ON `' . $row['Db'] . '`.`' . $row['Table_name']
1064 . '` TO \'' . PMA_sqlAddslashes($username) . '\'@\'' . $hostname . '\''
1065 . (in_array('Grant', explode(',', $row['Table_priv'])) ? ' WITH GRANT OPTION;' : ';');
1071 * Updates privileges
1073 if (!empty($update_privs)) {
1074 $db_and_table = PMA_WildcardEscapeForGrant($db_and_table, $dbname, (isset($tablename) ? $tablename : ''));
1076 $sql_query0 =
1077 'REVOKE ALL PRIVILEGES ON ' . $db_and_table
1078 . ' FROM \'' . PMA_sqlAddslashes($username) . '\'@\'' . $hostname . '\';';
1079 if (!isset($Grant_priv) || $Grant_priv != 'Y') {
1080 $sql_query1 =
1081 'REVOKE GRANT OPTION ON ' . $db_and_table
1082 . ' FROM \'' . PMA_sqlAddslashes($username) . '\'@\'' . $hostname . '\';';
1083 } else {
1084 $sql_query1 = '';
1087 // Should not do a GRANT USAGE for a table-specific privilege, it
1088 // causes problems later (cannot revoke it)
1089 if (! (isset($tablename) && 'USAGE' == implode('', PMA_extractPrivInfo()))) {
1090 $sql_query2 =
1091 'GRANT ' . join(', ', PMA_extractPrivInfo())
1092 . ' ON ' . $db_and_table
1093 . ' TO \'' . PMA_sqlAddslashes($username) . '\'@\'' . $hostname . '\'';
1096 * @todo similar code appears twice in this script
1098 if ((isset($Grant_priv) && $Grant_priv == 'Y')
1099 || (! isset($dbname)
1100 && (isset($max_questions) || isset($max_connections)
1101 || isset($max_updates) || isset($max_user_connections))))
1103 $sql_query2 .= 'WITH';
1104 if (isset($Grant_priv) && $Grant_priv == 'Y') {
1105 $sql_query2 .= ' GRANT OPTION';
1107 if (isset($max_questions)) {
1108 $max_questions = max(0, (int)$max_questions);
1109 $sql_query2 .= ' MAX_QUERIES_PER_HOUR ' . $max_questions;
1111 if (isset($max_connections)) {
1112 $max_connections = max(0, (int)$max_connections);
1113 $sql_query2 .= ' MAX_CONNECTIONS_PER_HOUR ' . $max_connections;
1115 if (isset($max_updates)) {
1116 $max_updates = max(0, (int)$max_updates);
1117 $sql_query2 .= ' MAX_UPDATES_PER_HOUR ' . $max_updates;
1119 if (isset($max_user_connections)) {
1120 $max_user_connections = max(0, (int)$max_user_connections);
1121 $sql_query2 .= ' MAX_USER_CONNECTIONS ' . $max_user_connections;
1124 $sql_query2 .= ';';
1126 if (! PMA_DBI_try_query($sql_query0)) {
1127 // this query may fail, but this does not matter :o)
1128 $sql_query0 = '';
1130 if (isset($sql_query1) && !PMA_DBI_try_query($sql_query1)) {
1131 // this one may fail, too...
1132 $sql_query1 = '';
1134 if (isset($sql_query2)) {
1135 PMA_DBI_query($sql_query2);
1136 } else {
1137 $sql_query2 = '';
1139 $sql_query = $sql_query0 . ' ' . $sql_query1 . ' ' . $sql_query2;
1140 $message = PMA_Message::success('strUpdatePrivMessage');
1141 $message->addParam('\'' . $username . '\'@\'' . $hostname . '\'');
1146 * Revokes Privileges
1148 if (isset($_REQUEST['revokeall'])) {
1149 $db_and_table = PMA_WildcardEscapeForGrant($db_and_table, $dbname, isset($tablename) ? $tablename : '');
1151 $sql_query0 =
1152 'REVOKE ALL PRIVILEGES ON ' . $db_and_table
1153 . ' FROM \'' . $username . '\'@\'' . $hostname . '\';';
1154 $sql_query1 =
1155 'REVOKE GRANT OPTION ON ' . $db_and_table
1156 . ' FROM \'' . $username . '\'@\'' . $hostname . '\';';
1157 PMA_DBI_query($sql_query0);
1158 if (!PMA_DBI_try_query($sql_query1)) {
1159 // this one may fail, too...
1160 $sql_query1 = '';
1162 $sql_query = $sql_query0 . ' ' . $sql_query1;
1163 $message = PMA_Message::success('strRevokeMessage');
1164 $message->addParam('\'' . $username . '\'@\'' . $hostname . '\'');
1165 if (! isset($tablename)) {
1166 unset($dbname);
1167 } else {
1168 unset($tablename);
1174 * Updates the password
1176 if (isset($_REQUEST['change_pw'])) {
1177 // similar logic in user_password.php
1178 $message = '';
1180 if ($nopass == 0 && isset($pma_pw) && isset($pma_pw2)) {
1181 if ($pma_pw != $pma_pw2) {
1182 $message = PMA_Message::error('strPasswordNotSame');
1183 } elseif (empty($pma_pw) || empty($pma_pw2)) {
1184 $message = PMA_Message::error('strPasswordEmpty');
1186 } // end if
1188 // here $nopass could be == 1
1189 if (empty($message)) {
1191 $hashing_function = (!empty($pw_hash) && $pw_hash == 'old' ? 'OLD_' : '')
1192 . 'PASSWORD';
1194 // in $sql_query which will be displayed, hide the password
1195 $sql_query = 'SET PASSWORD FOR \'' . PMA_sqlAddslashes($username) . '\'@\'' . $hostname . '\' = ' . (($pma_pw == '') ? '\'\'' : $hashing_function . '(\'' . preg_replace('@.@s', '*', $pma_pw) . '\')');
1196 $local_query = 'SET PASSWORD FOR \'' . PMA_sqlAddslashes($username) . '\'@\'' . $hostname . '\' = ' . (($pma_pw == '') ? '\'\'' : $hashing_function . '(\'' . PMA_sqlAddslashes($pma_pw) . '\')');
1197 PMA_DBI_try_query($local_query)
1198 or PMA_mysqlDie(PMA_DBI_getError(), $sql_query, FALSE, $err_url);
1199 $message = PMA_Message::success('strPasswordChanged');
1200 $message->addParam('\'' . $username . '\'@\'' . $hostname . '\'');
1206 * Deletes users
1207 * (Changes / copies a user, part IV)
1209 $user_host_separator = chr(27);
1211 if (isset($_REQUEST['delete']) || (isset($_REQUEST['change_copy']) && $_REQUEST['mode'] < 4)) {
1212 if (isset($_REQUEST['change_copy'])) {
1213 $selected_usr = array($old_username . $user_host_separator . $old_hostname);
1214 } else {
1215 $selected_usr = $_REQUEST['selected_usr'];
1216 $queries = array();
1218 foreach ($selected_usr as $each_user) {
1219 list($this_user, $this_host) = explode($user_host_separator, $each_user);
1220 $queries[] = '# ' . sprintf($GLOBALS['strDeleting'], '\'' . $this_user . '\'@\'' . $this_host . '\'') . ' ...';
1221 $queries[] = 'DROP USER \'' . PMA_sqlAddslashes($this_user) . '\'@\'' . $this_host . '\';';
1223 if (isset($_REQUEST['drop_users_db'])) {
1224 $queries[] = 'DROP DATABASE IF EXISTS ' . PMA_backquote($this_user) . ';';
1225 $GLOBALS['reload'] = TRUE;
1226 PMA_reloadNavigation();
1229 if (empty($_REQUEST['change_copy'])) {
1230 if (empty($queries)) {
1231 $message = PMA_Message::error('strDeleteNoUsersSelected');
1232 } else {
1233 if ($_REQUEST['mode'] == 3) {
1234 $queries[] = '# ' . $GLOBALS['strReloadingThePrivileges'] . ' ...';
1235 $queries[] = 'FLUSH PRIVILEGES;';
1237 $drop_user_error = '';
1238 foreach ($queries as $sql_query) {
1239 if ($sql_query{0} != '#') {
1240 if (! PMA_DBI_try_query($sql_query, $GLOBALS['userlink'])) {
1241 $drop_user_error .= PMA_DBI_getError() . "\n";
1245 $sql_query = join("\n", $queries);
1246 if (! empty($drop_user_error)) {
1247 $message = PMA_Message::rawError($drop_user_error);
1248 } else {
1249 $message = PMA_Message::success('strUsersDeleted');
1252 unset($queries);
1258 * Changes / copies a user, part V
1260 if (isset($_REQUEST['change_copy'])) {
1261 $tmp_count = 0;
1262 foreach ($queries as $sql_query) {
1263 if ($sql_query{0} != '#') {
1264 PMA_DBI_query($sql_query);
1266 // when there is a query containing a hidden password, take it
1267 // instead of the real query sent
1268 if (isset($queries_for_display[$tmp_count])) {
1269 $queries[$tmp_count] = $queries_for_display[$tmp_count];
1271 $tmp_count++;
1273 $message = PMA_Message::success();
1274 $sql_query = join("\n", $queries);
1279 * Reloads the privilege tables into memory
1281 if (isset($_REQUEST['flush_privileges'])) {
1282 $sql_query = 'FLUSH PRIVILEGES;';
1283 PMA_DBI_query($sql_query);
1284 $message = PMA_Message::success('strPrivilegesReloaded');
1289 * Displays the links
1291 if (isset($viewing_mode) && $viewing_mode == 'db') {
1292 $db = $checkprivs;
1293 $url_query .= '&amp;goto=db_operations.php';
1295 // Gets the database structure
1296 $sub_part = '_structure';
1297 require './libraries/db_info.inc.php';
1298 echo "\n";
1299 } else {
1300 require './libraries/server_links.inc.php';
1305 * defines some standard links
1307 $link_edit = '<a href="server_privileges.php?' . $GLOBALS['url_query']
1308 . '&amp;username=%s'
1309 . '&amp;hostname=%s'
1310 . '&amp;dbname=%s'
1311 . '&amp;tablename=%s">'
1312 . PMA_getIcon('b_usredit.png', $GLOBALS['strEditPrivileges'])
1313 . '</a>';
1315 $link_revoke = '<a href="server_privileges.php?' . $GLOBALS['url_query']
1316 . '&amp;username=%s'
1317 . '&amp;hostname=%s'
1318 . '&amp;dbname=%s'
1319 . '&amp;tablename=%s'
1320 . '&amp;revokeall=1">'
1321 . PMA_getIcon('b_usrdrop.png', $GLOBALS['strRevoke'])
1322 . '</a>';
1325 * Displays the page
1327 if (empty($_REQUEST['adduser']) && (! isset($checkprivs) || ! strlen($checkprivs))) {
1328 if (! isset($username)) {
1329 // No username is given --> display the overview
1330 echo '<h2>' . "\n"
1331 . PMA_getIcon('b_usrlist.png')
1332 . $GLOBALS['strUserOverview'] . "\n"
1333 . '</h2>' . "\n";
1335 $sql_query =
1336 'SELECT *,' .
1337 " IF(`Password` = _latin1 '', 'N', 'Y') AS 'Password'" .
1338 ' FROM `mysql`.`user`';
1340 $sql_query .= (isset($initial) ? PMA_RangeOfUsers($initial) : '');
1342 $sql_query .= ' ORDER BY `User` ASC, `Host` ASC;';
1343 $res = PMA_DBI_try_query($sql_query, null, PMA_DBI_QUERY_STORE);
1345 if (! $res) {
1346 // the query failed! This may have two reasons:
1347 // - the user does not have enough privileges
1348 // - the privilege tables use a structure of an earlier version.
1349 // so let's try a more simple query
1351 $sql_query = 'SELECT * FROM `mysql`.`user`';
1352 $res = PMA_DBI_try_query($sql_query, null, PMA_DBI_QUERY_STORE);
1354 if (!$res) {
1355 PMA_Message::error('strNoPrivileges')->display();
1356 PMA_DBI_free_result($res);
1357 unset($res);
1358 } else {
1359 // rabus: This message is hardcoded because I will replace it by
1360 // a automatic repair feature soon.
1361 $raw = 'Your privilege table structure seems to be older than'
1362 . ' this MySQL version!<br />'
1363 . 'Please run the <tt>mysql_upgrade</tt> command'
1364 . '(<tt>mysql_fix_privilege_tables</tt> on older systems)'
1365 . ' that should be included in your MySQL server distribution'
1366 . ' to solve this problem!';
1367 PMA_Message::rawError($raw)->display();
1369 } else {
1371 // we also want users not in table `user` but in other table
1372 $tables = PMA_DBI_fetch_result('SHOW TABLES FROM `mysql`;');
1374 $tables_to_search_for_users = array(
1375 'user', 'db', 'tables_priv', 'columns_priv', 'procs_priv',
1378 $db_rights_sqls = array();
1379 foreach ($tables_to_search_for_users as $table_search_in) {
1380 if (in_array($table_search_in, $tables)) {
1381 $db_rights_sqls[] = 'SELECT DISTINCT `User`, `Host` FROM `mysql`.`' . $table_search_in . '` ' . (isset($initial) ? PMA_RangeOfUsers($initial) : '');
1385 $user_defaults = array(
1386 'User' => '',
1387 'Host' => '%',
1388 'Password' => '?',
1389 'Grant_priv' => 'N',
1390 'privs' => array('USAGE'),
1393 // for all initials, even non A-Z
1394 $array_initials = array();
1395 // for the rights
1396 $db_rights = array();
1398 $db_rights_sql = '(' . implode(') UNION (', $db_rights_sqls) . ')'
1399 .' ORDER BY `User` ASC, `Host` ASC';
1401 $db_rights_result = PMA_DBI_query($db_rights_sql);
1403 while ($db_rights_row = PMA_DBI_fetch_assoc($db_rights_result)) {
1404 $db_rights_row = array_merge($user_defaults, $db_rights_row);
1405 $db_rights[$db_rights_row['User']][$db_rights_row['Host']] =
1406 $db_rights_row;
1408 PMA_DBI_free_result($db_rights_result);
1409 unset($db_rights_sql, $db_rights_sqls, $db_rights_result, $db_rights_row);
1410 ksort($db_rights);
1413 * Displays the initials
1416 // initialize to FALSE the letters A-Z
1417 for ($letter_counter = 1; $letter_counter < 27; $letter_counter++) {
1418 if (! isset($array_initials[chr($letter_counter + 64)])) {
1419 $array_initials[chr($letter_counter + 64)] = FALSE;
1423 $initials = PMA_DBI_try_query('SELECT DISTINCT UPPER(LEFT(`User`,1)) FROM `user` ORDER BY `User` ASC', null, PMA_DBI_QUERY_STORE);
1424 while (list($tmp_initial) = PMA_DBI_fetch_row($initials)) {
1425 $array_initials[$tmp_initial] = TRUE;
1428 // Display the initials, which can be any characters, not
1429 // just letters. For letters A-Z, we add the non-used letters
1430 // as greyed out.
1432 uksort($array_initials, "strnatcasecmp");
1434 echo '<table cellspacing="5"><tr>';
1435 foreach ($array_initials as $tmp_initial => $initial_was_found) {
1436 if ($initial_was_found) {
1437 echo '<td><a href="server_privileges.php?' . $GLOBALS['url_query'] . '&amp;initial=' . urlencode($tmp_initial) . '">' . $tmp_initial . '</a></td>' . "\n";
1438 } else {
1439 echo '<td>' . $tmp_initial . '</td>';
1442 echo '<td><a href="server_privileges.php?' . $GLOBALS['url_query'] . '&amp;showall=1">[' . $GLOBALS['strShowAll'] . ']</a></td>' . "\n";
1443 echo '</tr></table>';
1446 * Display the user overview
1447 * (if less than 50 users, display them immediately)
1450 if (isset($initial) || isset($showall) || PMA_DBI_num_rows($res) < 50) {
1452 while ($row = PMA_DBI_fetch_assoc($res)) {
1453 $row['privs'] = PMA_extractPrivInfo($row, true);
1454 $db_rights[$row['User']][$row['Host']] = $row;
1456 @PMA_DBI_free_result($res);
1457 unset($res);
1459 echo '<form name="usersForm" id="usersForm" action="server_privileges.php" method="post">' . "\n"
1460 . PMA_generate_common_hidden_inputs('', '')
1461 . ' <table id="tableuserrights" class="data">' . "\n"
1462 . ' <thead>' . "\n"
1463 . ' <tr><td></td>' . "\n"
1464 . ' <th>' . $GLOBALS['strUser'] . '</th>' . "\n"
1465 . ' <th>' . $GLOBALS['strHost'] . '</th>' . "\n"
1466 . ' <th>' . $GLOBALS['strPassword'] . '</th>' . "\n"
1467 . ' <th>' . $GLOBALS['strGlobalPrivileges'] . ' '
1468 . PMA_showHint($GLOBALS['strEnglishPrivileges']) . '</th>' . "\n"
1469 . ' <th>' . $GLOBALS['strGrantOption'] . '</th>' . "\n"
1470 . ' ' . ($GLOBALS['cfg']['PropertiesIconic'] ? '<td></td>' : '<th>' . $GLOBALS['strAction'] . '</th>') . "\n";
1471 echo ' </tr>' . "\n";
1472 echo ' </thead>' . "\n";
1473 echo ' <tbody>' . "\n";
1474 $odd_row = true;
1475 $index_checkbox = -1;
1476 foreach ($db_rights as $user) {
1477 $index_checkbox++;
1478 ksort($user);
1479 foreach ($user as $host) {
1480 $index_checkbox++;
1481 echo ' <tr class="' . ($odd_row ? 'odd' : 'even') . '">' . "\n"
1482 . ' <td><input type="checkbox" name="selected_usr[]" id="checkbox_sel_users_'
1483 . $index_checkbox . '" value="'
1484 . str_replace(chr(27), '&#27;', htmlspecialchars($host['User'] . $user_host_separator . $host['Host']))
1485 . '"'
1486 . (empty($GLOBALS['checkall']) ? '' : ' checked="checked"')
1487 . ' /></td>' . "\n"
1488 . ' <td><label for="checkbox_sel_users_' . $index_checkbox . '">' . (empty($host['User']) ? '<span style="color: #FF0000">' . $GLOBALS['strAny'] . '</span>' : htmlspecialchars($host['User'])) . '</label></td>' . "\n"
1489 . ' <td>' . htmlspecialchars($host['Host']) . '</td>' . "\n";
1490 echo ' <td>';
1491 switch ($host['Password']) {
1492 case 'Y':
1493 echo $GLOBALS['strYes'];
1494 break;
1495 case 'N':
1496 echo '<span style="color: #FF0000">' . $GLOBALS['strNo'] . '</span>';
1497 break;
1498 // this happens if this is a definition not coming from mysql.user
1499 default:
1500 echo '--'; // in future version, replace by "not present"
1501 break;
1502 } // end switch
1503 echo '</td>' . "\n"
1504 . ' <td><tt>' . "\n"
1505 . ' ' . implode(',' . "\n" . ' ', $host['privs']) . "\n"
1506 . ' </tt></td>' . "\n"
1507 . ' <td>' . ($host['Grant_priv'] == 'Y' ? $GLOBALS['strYes'] : $GLOBALS['strNo']) . '</td>' . "\n"
1508 . ' <td align="center">';
1509 printf($link_edit, urlencode($host['User']),
1510 urlencode($host['Host']), '', '');
1511 echo '</td>' . "\n"
1512 . ' </tr>' . "\n";
1513 $odd_row = ! $odd_row;
1517 unset($user, $host, $odd_row);
1518 echo ' </tbody></table>' . "\n"
1519 .'<img class="selectallarrow"'
1520 .' src="' . $pmaThemeImage . 'arrow_' . $text_dir . '.png"'
1521 .' width="38" height="22"'
1522 .' alt="' . $GLOBALS['strWithChecked'] . '" />' . "\n"
1523 .'<a href="server_privileges.php?' . $GLOBALS['url_query'] . '&amp;checkall=1"'
1524 .' onclick="if (markAllRows(\'usersForm\')) return false;">'
1525 . $GLOBALS['strCheckAll'] . '</a>' . "\n"
1526 .'/' . "\n"
1527 .'<a href="server_privileges.php?' . $GLOBALS['url_query'] . '"'
1528 .' onclick="if (unMarkAllRows(\'usersForm\')) return false;">'
1529 . $GLOBALS['strUncheckAll'] . '</a>' . "\n";
1531 // add/delete user fieldset
1532 echo ' <fieldset id="fieldset_add_user">' . "\n"
1533 . ' <a href="server_privileges.php?' . $GLOBALS['url_query'] . '&amp;adduser=1">' . "\n"
1534 . PMA_getIcon('b_usradd.png')
1535 . ' ' . $GLOBALS['strAddUser'] . '</a>' . "\n"
1536 . ' </fieldset>' . "\n"
1537 . ' <fieldset id="fieldset_delete_user">'
1538 . ' <legend>' . "\n"
1539 . PMA_getIcon('b_usrdrop.png')
1540 . ' ' . $GLOBALS['strRemoveSelectedUsers'] . '' . "\n"
1541 . ' </legend>' . "\n"
1542 . ' <input type="hidden" name="mode" value="2" />' . "\n"
1543 . '(' . $GLOBALS['strRevokeAndDelete'] . ')<br />' . "\n"
1544 . ' <input type="checkbox" title="' . $GLOBALS['strDropUsersDb'] . '" name="drop_users_db" id="checkbox_drop_users_db" />' . "\n"
1545 . ' <label for="checkbox_drop_users_db" title="' . $GLOBALS['strDropUsersDb'] . '">' . "\n"
1546 . ' ' . $GLOBALS['strDropUsersDb'] . "\n"
1547 . ' </label>' . "\n"
1548 . ' </fieldset>' . "\n"
1549 . ' <fieldset id="fieldset_delete_user_footer" class="tblFooters">' . "\n"
1550 . ' <input type="submit" name="delete" value="' . $GLOBALS['strGo'] . '" id="buttonGo" />' . "\n"
1551 . ' </fieldset>' . "\n";
1552 } else {
1554 unset ($row);
1555 echo ' <fieldset id="fieldset_add_user">' . "\n"
1556 . ' <a href="server_privileges.php?' . $GLOBALS['url_query'] . '&amp;adduser=1">' . "\n"
1557 . PMA_getIcon('b_usradd.png')
1558 . ' ' . $GLOBALS['strAddUser'] . '</a>' . "\n"
1559 . ' </fieldset>' . "\n";
1560 } // end if (display overview)
1561 echo '</form>' . "\n";
1562 $flushnote = new PMA_Message('strFlushPrivilegesNote', PMA_Message::NOTICE);
1563 $flushnote->addParam('<a href="server_privileges.php?' . $GLOBALS['url_query'] . '&amp;flush_privileges=1">', false);
1564 $flushnote->addParam('</a>', false);
1565 $flushnote->display();
1569 } else {
1571 // A user was selected -> display the user's properties
1573 echo '<h2>' . "\n"
1574 . PMA_getIcon('b_usredit.png')
1575 . $GLOBALS['strUser'] . ' <i><a href="server_privileges.php?'
1576 . $GLOBALS['url_query'] . '&amp;username=' . urlencode($username)
1577 . '&amp;hostname=' . urlencode($hostname) . '">\''
1578 . htmlspecialchars($username) . '\'@\'' . htmlspecialchars($hostname)
1579 . '\'</a></i>' . "\n";
1580 if (isset($dbname)) {
1581 if ($dbname_is_wildcard) {
1582 echo ' - ' . $GLOBALS['strDatabases'];
1583 } else {
1584 echo ' - ' . $GLOBALS['strDatabase'];
1586 $url_dbname = urlencode(str_replace('\_', '_', $dbname));
1587 echo ' <i><a href="' . $GLOBALS['cfg']['DefaultTabDatabase'] . '?'
1588 . $GLOBALS['url_query'] . '&amp;db=' . $url_dbname . '&amp;reload=1">'
1589 . htmlspecialchars($dbname) . '</a></i>' . "\n";
1590 if (isset($tablename)) {
1591 echo ' - ' . $GLOBALS['strTable'] . ' <i><a href="'
1592 . $GLOBALS['cfg']['DefaultTabTable'] . '?' . $GLOBALS['url_query']
1593 . '&amp;db=' . $url_dbname . '&amp;table=' . urlencode($tablename)
1594 . '&amp;reload=1">' . htmlspecialchars($tablename) . '</a></i>'
1595 . "\n";
1597 unset($url_dbname);
1599 echo ' : ' . $GLOBALS['strEditPrivileges'] . '</h2>' . "\n";
1601 $sql = "SELECT '1' FROM `mysql`.`user`"
1602 . " WHERE `User` = '" . PMA_sqlAddslashes($username) . "'"
1603 . " AND `Host` = '" . PMA_sqlAddslashes($hostname) . "';";
1604 $user_does_not_exists = (bool) ! PMA_DBI_fetch_value($sql);
1605 unset($sql);
1606 if ($user_does_not_exists) {
1607 PMA_Message::warning('strUserNotFound')->display();
1608 PMA_displayLoginInformationFields();
1609 //require_once './libraries/footer.inc.php';
1612 echo '<form name="usersForm" id="usersForm" action="server_privileges.php" method="post">' . "\n";
1613 $_params = array(
1614 'username' => $username,
1615 'hostname' => $hostname,
1617 if (isset($dbname)) {
1618 $_params['dbname'] = $dbname;
1619 if (isset($tablename)) {
1620 $_params['tablename'] = $tablename;
1623 echo PMA_generate_common_hidden_inputs($_params);
1625 PMA_displayPrivTable(PMA_ifSetOr($dbname, '*', 'length'),
1626 PMA_ifSetOr($tablename, '*', 'length'));
1628 echo '</form>' . "\n";
1630 if (! isset($tablename) && empty($dbname_is_wildcard)) {
1632 // no table name was given, display all table specific rights
1633 // but only if $dbname contains no wildcards
1635 // table header
1636 echo '<form action="server_privileges.php" method="post">' . "\n"
1637 . PMA_generate_common_hidden_inputs('', '')
1638 . '<input type="hidden" name="username" value="' . htmlspecialchars($username) . '" />' . "\n"
1639 . '<input type="hidden" name="hostname" value="' . htmlspecialchars($hostname) . '" />' . "\n"
1640 . '<fieldset>' . "\n"
1641 . '<legend>' . (! isset($dbname) ? $GLOBALS['strDbPrivileges'] : $GLOBALS['strTblPrivileges']) . '</legend>' . "\n"
1642 . '<table class="data">' . "\n"
1643 . '<thead>' . "\n"
1644 . '<tr><th>' . (! isset($dbname) ? $GLOBALS['strDatabase'] : $GLOBALS['strTable']) . '</th>' . "\n"
1645 . ' <th>' . $GLOBALS['strPrivileges'] . '</th>' . "\n"
1646 . ' <th>' . $GLOBALS['strGrantOption'] . '</th>' . "\n"
1647 . ' <th>' . (! isset($dbname) ? $GLOBALS['strTblPrivileges'] : $GLOBALS['strColumnPrivileges']) . '</th>' . "\n"
1648 . ' <th colspan="2">' . $GLOBALS['strAction'] . '</th>' . "\n"
1649 . '</tr>' . "\n"
1650 . '</thead>' . "\n"
1651 . '<tbody>' . "\n";
1653 $user_host_condition =
1654 ' WHERE `User`'
1655 . ' = \'' . PMA_sqlAddslashes($username) . "'"
1656 . ' AND `Host`'
1657 . ' = \'' . PMA_sqlAddslashes($hostname) . "'";
1659 // table body
1660 // get data
1662 // we also want privielgs for this user not in table `db` but in other table
1663 $tables = PMA_DBI_fetch_result('SHOW TABLES FROM `mysql`;');
1664 if (! isset($dbname)) {
1666 // no db name given, so we want all privs for the given user
1668 $tables_to_search_for_users = array(
1669 'tables_priv', 'columns_priv',
1672 $db_rights_sqls = array();
1673 foreach ($tables_to_search_for_users as $table_search_in) {
1674 if (in_array($table_search_in, $tables)) {
1675 $db_rights_sqls[] = '
1676 SELECT DISTINCT `Db`
1677 FROM `mysql`.`' . $table_search_in . '`
1678 ' . $user_host_condition;
1682 $user_defaults = array(
1683 'Db' => '',
1684 'Grant_priv' => 'N',
1685 'privs' => array('USAGE'),
1686 'Table_privs' => true,
1689 // for the rights
1690 $db_rights = array();
1692 $db_rights_sql = '(' . implode(') UNION (', $db_rights_sqls) . ')'
1693 .' ORDER BY `Db` ASC';
1695 $db_rights_result = PMA_DBI_query($db_rights_sql);
1697 while ($db_rights_row = PMA_DBI_fetch_assoc($db_rights_result)) {
1698 $db_rights_row = array_merge($user_defaults, $db_rights_row);
1699 // only Db names in the table `mysql`.`db` uses wildcards
1700 // as we are in the db specific rights display we want
1701 // all db names escaped, also from other sources
1702 $db_rights_row['Db'] = PMA_escape_mysql_wildcards(
1703 $db_rights_row['Db']);
1704 $db_rights[$db_rights_row['Db']] = $db_rights_row;
1707 PMA_DBI_free_result($db_rights_result);
1708 unset($db_rights_sql, $db_rights_sqls, $db_rights_result, $db_rights_row);
1710 $sql_query = 'SELECT * FROM `mysql`.`db`' . $user_host_condition . ' ORDER BY `Db` ASC';
1711 $res = PMA_DBI_query($sql_query);
1712 $sql_query = '';
1714 while ($row = PMA_DBI_fetch_assoc($res)) {
1715 if (isset($db_rights[$row['Db']])) {
1716 $db_rights[$row['Db']] = array_merge($db_rights[$row['Db']], $row);
1717 } else {
1718 $db_rights[$row['Db']] = $row;
1720 // there are db specific rights for this user
1721 // so we can drop this db rights
1722 $db_rights[$row['Db']]['can_delete'] = true;
1724 PMA_DBI_free_result($res);
1725 unset($row, $res);
1727 } else {
1729 // db name was given,
1730 // so we want all user specific rights for this db
1732 $user_host_condition .=
1733 ' AND `Db`'
1734 .' LIKE \'' . $dbname . "'";
1736 $tables_to_search_for_users = array(
1737 'columns_priv',
1740 $db_rights_sqls = array();
1741 foreach ($tables_to_search_for_users as $table_search_in) {
1742 if (in_array($table_search_in, $tables)) {
1743 $db_rights_sqls[] = '
1744 SELECT DISTINCT `Table_name`
1745 FROM `mysql`.`' . $table_search_in . '`
1746 ' . $user_host_condition;
1750 $user_defaults = array(
1751 'Table_name' => '',
1752 'Grant_priv' => 'N',
1753 'privs' => array('USAGE'),
1754 'Column_priv' => true,
1757 // for the rights
1758 $db_rights = array();
1760 $db_rights_sql = '(' . implode(') UNION (', $db_rights_sqls) . ')'
1761 .' ORDER BY `Table_name` ASC';
1763 $db_rights_result = PMA_DBI_query($db_rights_sql);
1765 while ($db_rights_row = PMA_DBI_fetch_assoc($db_rights_result)) {
1766 $db_rights_row = array_merge($user_defaults, $db_rights_row);
1767 $db_rights[$db_rights_row['Table_name']] = $db_rights_row;
1769 PMA_DBI_free_result($db_rights_result);
1770 unset($db_rights_sql, $db_rights_sqls, $db_rights_result, $db_rights_row);
1772 $sql_query =
1773 'SELECT `Table_name`,'
1774 .' `Table_priv`,'
1775 .' IF(`Column_priv` = _latin1 \'\', 0, 1)'
1776 .' AS \'Column_priv\''
1777 .' FROM `mysql`.`tables_priv`'
1778 . $user_host_condition
1779 .' ORDER BY `Table_name` ASC;';
1780 $res = PMA_DBI_query($sql_query);
1781 $sql_query = '';
1783 while ($row = PMA_DBI_fetch_assoc($res)) {
1784 if (isset($db_rights[$row['Table_name']])) {
1785 $db_rights[$row['Table_name']] = array_merge($db_rights[$row['Table_name']], $row);
1786 } else {
1787 $db_rights[$row['Table_name']] = $row;
1790 PMA_DBI_free_result($res);
1791 unset($row, $res);
1793 ksort($db_rights);
1795 // display rows
1796 if (count($db_rights) < 1) {
1797 echo '<tr class="odd">' . "\n"
1798 . ' <td colspan="6"><center><i>' . $GLOBALS['strNone'] . '</i></center></td>' . "\n"
1799 . '</tr>' . "\n";
1800 } else {
1801 $odd_row = true;
1802 $found_rows = array();
1803 //while ($row = PMA_DBI_fetch_assoc($res)) {
1804 foreach ($db_rights as $row) {
1805 $found_rows[] = (! isset($dbname)) ? $row['Db'] : $row['Table_name'];
1807 echo '<tr class="' . ($odd_row ? 'odd' : 'even') . '">' . "\n"
1808 . ' <td>' . htmlspecialchars((! isset($dbname)) ? $row['Db'] : $row['Table_name']) . '</td>' . "\n"
1809 . ' <td><tt>' . "\n"
1810 . ' ' . join(',' . "\n" . ' ', PMA_extractPrivInfo($row, TRUE)) . "\n"
1811 . ' </tt></td>' . "\n"
1812 . ' <td>' . ((((! isset($dbname)) && $row['Grant_priv'] == 'Y') || (isset($dbname) && in_array('Grant', explode(',', $row['Table_priv'])))) ? $GLOBALS['strYes'] : $GLOBALS['strNo']) . '</td>' . "\n"
1813 . ' <td>';
1814 if (! empty($row['Table_privs']) || ! empty ($row['Column_priv'])) {
1815 echo $GLOBALS['strYes'];
1816 } else {
1817 echo $GLOBALS['strNo'];
1819 echo '</td>' . "\n"
1820 . ' <td>';
1821 printf($link_edit, urlencode($username),
1822 urlencode($hostname),
1823 urlencode((! isset($dbname)) ? $row['Db'] : $dbname),
1824 urlencode((! isset($dbname)) ? '' : $row['Table_name']));
1825 echo '</td>' . "\n"
1826 . ' <td>';
1827 if (! empty($row['can_delete']) || isset($row['Table_name']) && strlen($row['Table_name'])) {
1828 printf($link_revoke, urlencode($username),
1829 urlencode($hostname),
1830 urlencode((! isset($dbname)) ? $row['Db'] : $dbname),
1831 urlencode((! isset($dbname)) ? '' : $row['Table_name']));
1833 echo '</td>' . "\n"
1834 . '</tr>' . "\n";
1835 $odd_row = ! $odd_row;
1836 } // end while
1838 unset($row);
1839 echo '</tbody>' . "\n"
1840 . '</table>' . "\n";
1842 if (! isset($dbname)) {
1844 // no database name was give, display select db
1846 if (! empty($found_rows)) {
1847 $pred_db_array = array_diff(
1848 PMA_DBI_fetch_result('SHOW DATABASES;'),
1849 $found_rows);
1850 } else {
1851 $pred_db_array =PMA_DBI_fetch_result('SHOW DATABASES;');
1854 echo ' <label for="text_dbname">' . $GLOBALS['strAddPrivilegesOnDb'] . ':</label>' . "\n";
1855 if (!empty($pred_db_array)) {
1856 echo ' <select name="pred_dbname" onchange="this.form.submit();">' . "\n"
1857 . ' <option value="" selected="selected">' . $GLOBALS['strUseTextField'] . ':</option>' . "\n";
1858 foreach ($pred_db_array as $current_db) {
1859 $current_db = PMA_escape_mysql_wildcards($current_db);
1860 echo ' <option value="' . htmlspecialchars($current_db) . '">'
1861 . htmlspecialchars($current_db) . '</option>' . "\n";
1863 echo ' </select>' . "\n";
1865 echo ' <input type="text" id="text_dbname" name="dbname" />' . "\n"
1866 . PMA_showHint($GLOBALS['strEscapeWildcards']);
1867 } else {
1868 echo ' <input type="hidden" name="dbname" value="' . htmlspecialchars($dbname) . '"/>' . "\n"
1869 . ' <label for="text_tablename">' . $GLOBALS['strAddPrivilegesOnTbl'] . ':</label>' . "\n";
1870 if ($res = @PMA_DBI_try_query('SHOW TABLES FROM ' . PMA_backquote($dbname) . ';', null, PMA_DBI_QUERY_STORE)) {
1871 $pred_tbl_array = array();
1872 while ($row = PMA_DBI_fetch_row($res)) {
1873 if (!isset($found_rows) || !in_array($row[0], $found_rows)) {
1874 $pred_tbl_array[] = $row[0];
1877 PMA_DBI_free_result($res);
1878 unset($res, $row);
1879 if (!empty($pred_tbl_array)) {
1880 echo ' <select name="pred_tablename" onchange="this.form.submit();">' . "\n"
1881 . ' <option value="" selected="selected">' . $GLOBALS['strUseTextField'] . ':</option>' . "\n";
1882 foreach ($pred_tbl_array as $current_table) {
1883 echo ' <option value="' . htmlspecialchars($current_table) . '">' . htmlspecialchars($current_table) . '</option>' . "\n";
1885 echo ' </select>' . "\n";
1887 } else {
1888 unset($res);
1890 echo ' <input type="text" id="text_tablename" name="tablename" />' . "\n";
1892 echo '</fieldset>' . "\n";
1893 echo '<fieldset class="tblFooters">' . "\n"
1894 . ' <input type="submit" value="' . $GLOBALS['strGo'] . '" />'
1895 . '</fieldset>' . "\n"
1896 . '</form>' . "\n";
1899 if (! isset($dbname) && ! $user_does_not_exists) {
1900 require_once './libraries/display_change_password.lib.php';
1902 echo '<form action="server_privileges.php" method="post" onsubmit="return checkPassword(this);">' . "\n"
1903 . PMA_generate_common_hidden_inputs('', '')
1904 . '<input type="hidden" name="old_username" value="' . htmlspecialchars($username) . '" />' . "\n"
1905 . '<input type="hidden" name="old_hostname" value="' . htmlspecialchars($hostname) . '" />' . "\n"
1906 . '<fieldset id="fieldset_change_copy_user">' . "\n"
1907 . ' <legend>' . $GLOBALS['strChangeCopyUser'] . '</legend>' . "\n";
1908 PMA_displayLoginInformationFields('change');
1909 echo ' <fieldset>' . "\n"
1910 . ' <legend>' . $GLOBALS['strChangeCopyMode'] . '</legend>' . "\n";
1911 $choices = array(
1912 '4' => $GLOBALS['strChangeCopyModeCopy'],
1913 '1' => $GLOBALS['strChangeCopyModeJustDelete'],
1914 '2' => $GLOBALS['strChangeCopyModeRevoke'],
1915 '3' => $GLOBALS['strChangeCopyModeDeleteAndReload']);
1916 PMA_generate_html_radio('mode', $choices, '4', true);
1917 unset($choices);
1919 echo ' </fieldset>' . "\n"
1920 . '</fieldset>' . "\n"
1921 . '<fieldset id="fieldset_change_copy_user_footer" class="tblFooters">' . "\n"
1922 . ' <input type="submit" name="change_copy" value="' . $GLOBALS['strGo'] . '" />' . "\n"
1923 . '</fieldset>' . "\n"
1924 . '</form>' . "\n";
1927 } elseif (isset($_REQUEST['adduser'])) {
1928 // Add a new user
1929 $GLOBALS['url_query'] .= '&amp;adduser=1';
1930 echo '<h2>' . "\n"
1931 . PMA_getIcon('b_usradd.png') . $GLOBALS['strAddUser'] . "\n"
1932 . '</h2>' . "\n"
1933 . '<form name="usersForm" id="usersForm" action="server_privileges.php" method="post" onsubmit="return checkAddUser(this);">' . "\n"
1934 . PMA_generate_common_hidden_inputs('', '');
1935 PMA_displayLoginInformationFields('new');
1936 echo '<fieldset id="fieldset_add_user_database">' . "\n"
1937 . '<legend>' . $GLOBALS['strCreateUserDatabase'] . '</legend>' . "\n";
1939 $choices = array(
1940 '0' => $GLOBALS['strCreateUserDatabaseNone'],
1941 '1' => $GLOBALS['strCreateUserDatabaseName'],
1942 '2' => $GLOBALS['strCreateUserDatabaseWildcard']);
1943 PMA_generate_html_radio('createdb', $choices, '0', true);
1944 unset($choices);
1946 echo '</fieldset>' . "\n";
1947 PMA_displayPrivTable('*', '*', FALSE);
1948 echo ' <fieldset id="fieldset_add_user_footer" class="tblFooters">' . "\n"
1949 . ' <input type="submit" name="adduser_submit" value="' . $GLOBALS['strGo'] . '" />' . "\n"
1950 . ' </fieldset>' . "\n"
1951 . '</form>' . "\n";
1952 } else {
1953 // check the privileges for a particular database.
1954 echo '<table id="tablespecificuserrights" class="data">' . "\n"
1955 . '<caption class="tblHeaders">' . "\n"
1956 . PMA_getIcon('b_usrcheck.png')
1957 . ' ' . sprintf($GLOBALS['strUsersHavingAccessToDb'], '<a href="' . $GLOBALS['cfg']['DefaultTabDatabase'] . '?' . PMA_generate_common_url($checkprivs) . '">' . htmlspecialchars($checkprivs) . '</a>') . "\n"
1958 . '</caption>' . "\n"
1959 . '<thead>' . "\n"
1960 . ' <tr><th>' . $GLOBALS['strUser'] . '</th>' . "\n"
1961 . ' <th>' . $GLOBALS['strHost'] . '</th>' . "\n"
1962 . ' <th>' . $GLOBALS['strType'] . '</th>' . "\n"
1963 . ' <th>' . $GLOBALS['strPrivileges'] . '</th>' . "\n"
1964 . ' <th>' . $GLOBALS['strGrantOption'] . '</th>' . "\n"
1965 . ' <th>' . $GLOBALS['strAction'] . '</th>' . "\n"
1966 . ' </tr>' . "\n"
1967 . '</thead>' . "\n"
1968 . '<tbody>' . "\n";
1969 $odd_row = TRUE;
1970 unset($row, $row1, $row2);
1972 // now, we build the table...
1973 $list_of_privileges =
1974 '`User`, '
1975 . '`Host`, '
1976 . '`Select_priv`, '
1977 . '`Insert_priv`, '
1978 . '`Update_priv`, '
1979 . '`Delete_priv`, '
1980 . '`Create_priv`, '
1981 . '`Drop_priv`, '
1982 . '`Grant_priv`, '
1983 . '`Index_priv`, '
1984 . '`Alter_priv`, '
1985 . '`References_priv`, '
1986 . '`Create_tmp_table_priv`, '
1987 . '`Lock_tables_priv`, '
1988 . '`Create_view_priv`, '
1989 . '`Show_view_priv`, '
1990 . '`Create_routine_priv`, '
1991 . '`Alter_routine_priv`, '
1992 . '`Execute_priv`';
1994 $list_of_compared_privileges =
1995 '`Select_priv` = \'N\''
1996 . ' AND `Insert_priv` = \'N\''
1997 . ' AND `Update_priv` = \'N\''
1998 . ' AND `Delete_priv` = \'N\''
1999 . ' AND `Create_priv` = \'N\''
2000 . ' AND `Drop_priv` = \'N\''
2001 . ' AND `Grant_priv` = \'N\''
2002 . ' AND `References_priv` = \'N\''
2003 . ' AND `Create_tmp_table_priv` = \'N\''
2004 . ' AND `Lock_tables_priv` = \'N\''
2005 . ' AND `Create_view_priv` = \'N\''
2006 . ' AND `Show_view_priv` = \'N\''
2007 . ' AND `Create_routine_priv` = \'N\''
2008 . ' AND `Alter_routine_priv` = \'N\''
2009 . ' AND `Execute_priv` = \'N\'';
2011 if (PMA_MYSQL_INT_VERSION >= 50106) {
2012 $list_of_privileges .=
2013 ', `Event_priv`, '
2014 . '`Trigger_priv`';
2015 $list_of_compared_privileges .=
2016 ' AND `Event_priv` = \'N\''
2017 . ' AND `Trigger_priv` = \'N\'';
2020 $sql_query =
2021 '(SELECT ' . $list_of_privileges . ', `Db`'
2022 .' FROM `mysql`.`db`'
2023 .' WHERE \'' . PMA_sqlAddslashes($checkprivs) . "'"
2024 .' LIKE `Db`'
2025 .' AND NOT (' . $list_of_compared_privileges. ')) '
2026 .'UNION '
2027 .'(SELECT ' . $list_of_privileges . ', \'*\' AS `Db`'
2028 .' FROM `mysql`.`user` '
2029 .' WHERE NOT (' . $list_of_compared_privileges . ')) '
2030 .' ORDER BY `User` ASC,'
2031 .' `Host` ASC,'
2032 .' `Db` ASC;';
2033 $res = PMA_DBI_query($sql_query);
2034 $row = PMA_DBI_fetch_assoc($res);
2035 if ($row) {
2036 $found = TRUE;
2039 if ($found) {
2040 while (TRUE) {
2041 // prepare the current user
2042 $current_privileges = array();
2043 $current_user = $row['User'];
2044 $current_host = $row['Host'];
2045 while ($row && $current_user == $row['User'] && $current_host == $row['Host']) {
2046 $current_privileges[] = $row;
2047 $row = PMA_DBI_fetch_assoc($res);
2049 echo ' <tr class="' . ($odd_row ? 'odd' : 'even') . '">' . "\n"
2050 . ' <td';
2051 if (count($current_privileges) > 1) {
2052 echo ' rowspan="' . count($current_privileges) . '"';
2054 echo '>' . (empty($current_user) ? '<span style="color: #FF0000">' . $GLOBALS['strAny'] . '</span>' : htmlspecialchars($current_user)) . "\n"
2055 . ' </td>' . "\n"
2056 . ' <td';
2057 if (count($current_privileges) > 1) {
2058 echo ' rowspan="' . count($current_privileges) . '"';
2060 echo '>' . htmlspecialchars($current_host) . '</td>' . "\n";
2061 foreach ($current_privileges as $current) {
2062 echo ' <td>' . "\n"
2063 . ' ';
2064 if (!isset($current['Db']) || $current['Db'] == '*') {
2065 echo $GLOBALS['strGlobal'];
2066 } elseif ($current['Db'] == PMA_escape_mysql_wildcards($checkprivs)) {
2067 echo $GLOBALS['strDbSpecific'];
2068 } else {
2069 echo $GLOBALS['strWildcard'], ': <tt>' . htmlspecialchars($current['Db']) . '</tt>';
2071 echo "\n"
2072 . ' </td>' . "\n"
2073 . ' <td>' . "\n"
2074 . ' <tt>' . "\n"
2075 . ' ' . join(',' . "\n" . ' ', PMA_extractPrivInfo($current, TRUE)) . "\n"
2076 . ' </tt>' . "\n"
2077 . ' </td>' . "\n"
2078 . ' <td>' . "\n"
2079 . ' ' . ($current['Grant_priv'] == 'Y' ? $GLOBALS['strYes'] : $GLOBALS['strNo']) . "\n"
2080 . ' </td>' . "\n"
2081 . ' <td>' . "\n";
2082 printf($link_edit, urlencode($current_user),
2083 urlencode($current_host),
2084 urlencode(! isset($current['Db']) || $current['Db'] == '*' ? '' : $current['Db']),
2085 '');
2086 echo '</td>' . "\n"
2087 . ' </tr>' . "\n";
2089 if (empty($row) && empty($row1) && empty($row2)) {
2090 break;
2092 $odd_row = ! $odd_row;
2094 } else {
2095 echo ' <tr class="odd">' . "\n"
2096 . ' <td colspan="6">' . "\n"
2097 . ' ' . $GLOBALS['strNoUsersFound'] . "\n"
2098 . ' </td>' . "\n"
2099 . ' </tr>' . "\n";
2101 echo '</tbody>' . "\n"
2102 . '</table>' . "\n";
2103 } // end if (empty($_REQUEST['adduser']) && empty($checkprivs)) ... elseif ... else ...
2107 * Displays the footer
2109 echo "\n\n";
2110 require_once './libraries/footer.inc.php';