is*() methods now return boolean values;
[phpmyadmin.git] / server_privileges.php
blob8e0da33b95383240d75c13b8a7ae28e5d563c910
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
5 * @version $Id$
6 * @package phpMyAdmin
7 */
9 /**
12 require_once './libraries/common.inc.php';
14 /**
15 * Does the common work
17 $GLOBALS['js_include'][] = 'server_privileges.js';
18 $GLOBALS['js_include'][] = 'functions.js';
19 require './libraries/server_common.inc.php';
22 /**
23 * Checks if a dropdown box has been used for selecting a database / table
25 if (PMA_isValid($_REQUEST['pred_tablename'])) {
26 $tablename = $_REQUEST['pred_tablename'];
27 unset($pred_tablename);
28 } elseif (PMA_isValid($_REQUEST['tablename'])) {
29 $tablename = $_REQUEST['tablename'];
30 } else {
31 unset($tablename);
34 if (PMA_isValid($_REQUEST['pred_dbname'])) {
35 $dbname = $_REQUEST['pred_dbname'];
36 unset($pred_dbname);
37 } elseif (PMA_isValid($_REQUEST['dbname'])) {
38 $dbname = $_REQUEST['dbname'];
39 } else {
40 unset($dbname);
41 unset($tablename);
44 if (isset($dbname)) {
45 $db_and_table = PMA_backquote(PMA_unescape_mysql_wildcards($dbname)) . '.';
46 if (isset($tablename)) {
47 $db_and_table .= PMA_backquote($tablename);
48 } else {
49 $db_and_table .= '*';
51 } else {
52 $db_and_table = '*.*';
55 // check if given $dbanem is a wildcard or not
56 if (isset($dbname)) {
57 //if (preg_match('/\\\\(?:_|%)/i', $dbname)) {
58 if (preg_match('/(?<!\\\\)(?:_|%)/i', $dbname)) {
59 $dbname_is_wildcard = true;
60 } else {
61 $dbname_is_wildcard = false;
65 /**
66 * Checks if the user is allowed to do what he tries to...
68 if (!$is_superuser) {
69 require './libraries/server_links.inc.php';
70 echo '<h2>' . "\n"
71 . PMA_getIcon('b_usrlist.png')
72 . $GLOBALS['strPrivileges'] . "\n"
73 . '</h2>' . "\n";
74 PMA_Message::error('strNoPrivileges')->display();
75 require_once './libraries/footer.inc.php';
78 /**
79 * Generates a condition on the user name
81 * @param string the user's initial
82 * @return string the generated condition
84 function PMA_RangeOfUsers($initial = '')
86 // strtolower() is used because the User field
87 // might be BINARY, so LIKE would be case sensitive
88 if (!empty($initial)) {
89 $ret = " WHERE `User` LIKE '" . $initial . "%'"
90 . " OR `User` LIKE '" . strtolower($initial) . "%'";
91 } else {
92 $ret = '';
94 return $ret;
95 } // end function
97 /**
98 * Extracts the privilege information of a priv table row
100 * @param array $row the row
101 * @param boolean $enableHTML add <dfn> tag with tooltips
103 * @global ressource $user_link the database connection
105 * @return array
107 function PMA_extractPrivInfo($row = '', $enableHTML = FALSE)
109 $grants = array(
110 array('Select_priv', 'SELECT', $GLOBALS['strPrivDescSelect']),
111 array('Insert_priv', 'INSERT', $GLOBALS['strPrivDescInsert']),
112 array('Update_priv', 'UPDATE', $GLOBALS['strPrivDescUpdate']),
113 array('Delete_priv', 'DELETE', $GLOBALS['strPrivDescDelete']),
114 array('Create_priv', 'CREATE', $GLOBALS['strPrivDescCreateDb']),
115 array('Drop_priv', 'DROP', $GLOBALS['strPrivDescDropDb']),
116 array('Reload_priv', 'RELOAD', $GLOBALS['strPrivDescReload']),
117 array('Shutdown_priv', 'SHUTDOWN', $GLOBALS['strPrivDescShutdown']),
118 array('Process_priv', 'PROCESS', $GLOBALS['strPrivDescProcess']),
119 array('File_priv', 'FILE', $GLOBALS['strPrivDescFile']),
120 array('References_priv', 'REFERENCES', $GLOBALS['strPrivDescReferences']),
121 array('Index_priv', 'INDEX', $GLOBALS['strPrivDescIndex']),
122 array('Alter_priv', 'ALTER', $GLOBALS['strPrivDescAlter']),
123 array('Show_db_priv', 'SHOW DATABASES', $GLOBALS['strPrivDescShowDb']),
124 array('Super_priv', 'SUPER', $GLOBALS['strPrivDescSuper']),
125 array('Create_tmp_table_priv', 'CREATE TEMPORARY TABLES', $GLOBALS['strPrivDescCreateTmpTable']),
126 array('Lock_tables_priv', 'LOCK TABLES', $GLOBALS['strPrivDescLockTables']),
127 array('Repl_slave_priv', 'REPLICATION SLAVE', $GLOBALS['strPrivDescReplSlave']),
128 array('Repl_client_priv', 'REPLICATION CLIENT', $GLOBALS['strPrivDescReplClient']),
129 array('Create_view_priv', 'CREATE VIEW', $GLOBALS['strPrivDescCreateView']),
130 array('Event_priv', 'EVENT', $GLOBALS['strPrivDescEvent']),
131 array('Trigger_priv', 'TRIGGER', $GLOBALS['strPrivDescTrigger']),
132 // for table privs:
133 array('Create View_priv', 'CREATE VIEW', $GLOBALS['strPrivDescCreateView']),
134 array('Show_view_priv', 'SHOW VIEW', $GLOBALS['strPrivDescShowView']),
135 // for table privs:
136 array('Show view_priv', 'SHOW VIEW', $GLOBALS['strPrivDescShowView']),
137 array('Create_routine_priv', 'CREATE ROUTINE', $GLOBALS['strPrivDescCreateRoutine']),
138 array('Alter_routine_priv', 'ALTER ROUTINE', $GLOBALS['strPrivDescAlterRoutine']),
139 array('Create_user_priv', 'CREATE USER', $GLOBALS['strPrivDescCreateUser']),
140 array('Execute_priv', 'EXECUTE', $GLOBALS['strPrivDescExecute5']),
143 if (!empty($row) && isset($row['Table_priv'])) {
144 $row1 = PMA_DBI_fetch_single_row(
145 'SHOW COLUMNS FROM `mysql`.`tables_priv` LIKE \'Table_priv\';',
146 'ASSOC', $GLOBALS['userlink']);
147 $av_grants = explode('\',\'', substr($row1['Type'], 5, strlen($row1['Type']) - 7));
148 unset($row1);
149 $users_grants = explode(',', $row['Table_priv']);
150 foreach ($av_grants as $current_grant) {
151 $row[$current_grant . '_priv'] = in_array($current_grant, $users_grants) ? 'Y' : 'N';
153 unset($current_grant);
154 unset($av_grants);
155 unset($users_grants);
157 $privs = array();
158 $allPrivileges = TRUE;
159 foreach ($grants as $current_grant) {
160 if ((!empty($row) && isset($row[$current_grant[0]]))
161 || (empty($row) && isset($GLOBALS[$current_grant[0]]))) {
162 if ((!empty($row) && $row[$current_grant[0]] == 'Y')
163 || (empty($row)
164 && ($GLOBALS[$current_grant[0]] == 'Y'
165 || (is_array($GLOBALS[$current_grant[0]])
166 && count($GLOBALS[$current_grant[0]]) == $GLOBALS['column_count']
167 && empty($GLOBALS[$current_grant[0] . '_none'])))))
169 if ($enableHTML) {
170 $privs[] = '<dfn title="' . $current_grant[2] . '">' . $current_grant[1] . '</dfn>';
171 } else {
172 $privs[] = $current_grant[1];
174 } elseif (!empty($GLOBALS[$current_grant[0]])
175 && is_array($GLOBALS[$current_grant[0]])
176 && empty($GLOBALS[$current_grant[0] . '_none'])) {
177 if ($enableHTML) {
178 $priv_string = '<dfn title="' . $current_grant[2] . '">' . $current_grant[1] . '</dfn>';
179 } else {
180 $priv_string = $current_grant[1];
182 $privs[] = $priv_string . ' (`' . join('`, `', $GLOBALS[$current_grant[0]]) . '`)';
183 } else {
184 $allPrivileges = FALSE;
188 if (empty($privs)) {
189 if ($enableHTML) {
190 $privs[] = '<dfn title="' . $GLOBALS['strPrivDescUsage'] . '">USAGE</dfn>';
191 } else {
192 $privs[] = 'USAGE';
194 } elseif ($allPrivileges && (!isset($GLOBALS['grant_count']) || count($privs) == $GLOBALS['grant_count'])) {
195 if ($enableHTML) {
196 $privs = array('<dfn title="' . $GLOBALS['strPrivDescAllPrivileges'] . '">ALL PRIVILEGES</dfn>');
197 } else {
198 $privs = array('ALL PRIVILEGES');
201 return $privs;
202 } // end of the 'PMA_extractPrivInfo()' function
205 * Displays on which column(s) a table-specific privilege is granted
207 function PMA_display_column_privs($columns, $row, $name_for_select,
208 $priv_for_header, $name, $name_for_dfn, $name_for_current)
210 echo ' <div class="item" id="div_item_' . $name . '">' . "\n"
211 . ' <label for="select_' . $name . '_priv">' . "\n"
212 . ' <tt><dfn title="' . $name_for_dfn . '">'
213 . $priv_for_header . '</dfn></tt>' . "\n"
214 . ' </label><br />' . "\n"
215 . ' <select id="select_' . $name . '_priv" name="'
216 . $name_for_select . '[]" multiple="multiple" size="8">' . "\n";
218 foreach ($columns as $current_column => $current_column_privileges) {
219 echo ' <option value="' . htmlspecialchars($current_column) . '"';
220 if ($row[$name_for_select] == 'Y' || $current_column_privileges[$name_for_current]) {
221 echo ' selected="selected"';
223 echo '>' . htmlspecialchars($current_column) . '</option>' . "\n";
226 echo ' </select>' . "\n"
227 . ' <i>' . $GLOBALS['strOr'] . '</i>' . "\n"
228 . ' <label for="checkbox_' . $name_for_select
229 . '_none"><input type="checkbox"'
230 . (empty($GLOBALS['checkall']) ? '' : ' checked="checked"')
231 . ' name="' . $name_for_select . '_none" id="checkbox_'
232 . $name_for_select . '_none" title="' . $GLOBALS['strNone'] . '" />'
233 . $GLOBALS['strNone'] . '</label>' . "\n"
234 . ' </div>' . "\n";
235 } // end function
239 * Displays the privileges form table
241 * @param string $db the database
242 * @param string $table the table
243 * @param boolean $submit wheather to display the submit button or not
244 * @global array $cfg the phpMyAdmin configuration
245 * @global ressource $user_link the database connection
247 * @return void
249 function PMA_displayPrivTable($db = '*', $table = '*', $submit = TRUE)
251 if ($db == '*') {
252 $table = '*';
255 if (isset($GLOBALS['username'])) {
256 $username = $GLOBALS['username'];
257 $hostname = $GLOBALS['hostname'];
258 if ($db == '*') {
259 $sql_query =
260 "SELECT * FROM `mysql`.`user`"
261 ." WHERE `User` = '" . PMA_sqlAddslashes($username) . "'"
262 ." AND `Host` = '" . PMA_sqlAddslashes($hostname) . "';";
263 } elseif ($table == '*') {
264 $sql_query =
265 "SELECT * FROM `mysql`.`db`"
266 ." WHERE `User` = '" . PMA_sqlAddslashes($username) . "'"
267 ." AND `Host` = '" . PMA_sqlAddslashes($hostname) . "'"
268 ." AND '" . PMA_unescape_mysql_wildcards($db) . "'"
269 ." LIKE `Db`;";
270 } else {
271 $sql_query =
272 "SELECT `Table_priv`"
273 ." FROM `mysql`.`tables_priv`"
274 ." WHERE `User` = '" . PMA_sqlAddslashes($username) . "'"
275 ." AND `Host` = '" . PMA_sqlAddslashes($hostname) . "'"
276 ." AND `Db` = '" . PMA_unescape_mysql_wildcards($db) . "'"
277 ." AND `Table_name` = '" . PMA_sqlAddslashes($table) . "';";
279 $row = PMA_DBI_fetch_single_row($sql_query);
281 if (empty($row)) {
282 if ($table == '*') {
283 if ($db == '*') {
284 $sql_query = 'SHOW COLUMNS FROM `mysql`.`user`;';
285 } elseif ($table == '*') {
286 $sql_query = 'SHOW COLUMNS FROM `mysql`.`db`;';
288 $res = PMA_DBI_query($sql_query);
289 while ($row1 = PMA_DBI_fetch_row($res)) {
290 if (substr($row1[0], 0, 4) == 'max_') {
291 $row[$row1[0]] = 0;
292 } else {
293 $row[$row1[0]] = 'N';
296 PMA_DBI_free_result($res);
297 } else {
298 $row = array('Table_priv' => '');
301 if (isset($row['Table_priv'])) {
302 $row1 = PMA_DBI_fetch_single_row(
303 'SHOW COLUMNS FROM `mysql`.`tables_priv` LIKE \'Table_priv\';',
304 'ASSOC', $GLOBALS['userlink']);
305 // note: in MySQL 5.0.3 we get "Create View', 'Show view';
306 // the View for Create is spelled with uppercase V
307 // the view for Show is spelled with lowercase v
308 // and there is a space between the words
310 $av_grants = explode('\',\'', substr($row1['Type'], strpos($row1['Type'], '(') + 2, strpos($row1['Type'], ')') - strpos($row1['Type'], '(') - 3));
311 unset($row1);
312 $users_grants = explode(',', $row['Table_priv']);
314 foreach ($av_grants as $current_grant) {
315 $row[$current_grant . '_priv'] = in_array($current_grant, $users_grants) ? 'Y' : 'N';
317 unset($row['Table_priv'], $current_grant, $av_grants, $users_grants);
319 // get collumns
320 $res = PMA_DBI_try_query('SHOW COLUMNS FROM ' . PMA_backquote(PMA_unescape_mysql_wildcards($db)) . '.' . PMA_backquote($table) . ';');
321 $columns = array();
322 if ($res) {
323 while ($row1 = PMA_DBI_fetch_row($res)) {
324 $columns[$row1[0]] = array(
325 'Select' => FALSE,
326 'Insert' => FALSE,
327 'Update' => FALSE,
328 'References' => FALSE
331 PMA_DBI_free_result($res);
333 unset($res, $row1);
335 // t a b l e - s p e c i f i c p r i v i l e g e s
336 if (! empty($columns)) {
337 $res = PMA_DBI_query(
338 'SELECT `Column_name`, `Column_priv`'
339 .' FROM `mysql`.`columns_priv`'
340 .' WHERE `User`'
341 .' = \'' . PMA_sqlAddslashes($username) . "'"
342 .' AND `Host`'
343 .' = \'' . PMA_sqlAddslashes($hostname) . "'"
344 .' AND `Db`'
345 .' = \'' . PMA_unescape_mysql_wildcards($db) . "'"
346 .' AND `Table_name`'
347 .' = \'' . PMA_sqlAddslashes($table) . '\';');
349 while ($row1 = PMA_DBI_fetch_row($res)) {
350 $row1[1] = explode(',', $row1[1]);
351 foreach ($row1[1] as $current) {
352 $columns[$row1[0]][$current] = TRUE;
355 PMA_DBI_free_result($res);
356 unset($res, $row1, $current);
358 echo '<input type="hidden" name="grant_count" value="' . count($row) . '" />' . "\n"
359 . '<input type="hidden" name="column_count" value="' . count($columns) . '" />' . "\n"
360 . '<fieldset id="fieldset_user_priv">' . "\n"
361 . ' <legend>' . $GLOBALS['strTblPrivileges']
362 . PMA_showHint($GLOBALS['strEnglishPrivileges'])
363 . '</legend>' . "\n";
367 // privs that are attached to a specific column
368 PMA_display_column_privs($columns, $row, 'Select_priv',
369 'SELECT', 'select', $GLOBALS['strPrivDescSelect'], 'Select');
371 PMA_display_column_privs($columns, $row, 'Insert_priv',
372 'INSERT', 'insert', $GLOBALS['strPrivDescInsert'], 'Insert');
374 PMA_display_column_privs($columns, $row, 'Update_priv',
375 'UPDATE', 'update', $GLOBALS['strPrivDescUpdate'], 'Update');
377 PMA_display_column_privs($columns, $row, 'References_priv',
378 'REFERENCES', 'references', $GLOBALS['strPrivDescReferences'], 'References');
380 // privs that are not attached to a specific column
382 echo ' <div class="item">' . "\n";
383 foreach ($row as $current_grant => $current_grant_value) {
384 if (in_array(substr($current_grant, 0, (strlen($current_grant) - 5)),
385 array('Select', 'Insert', 'Update', 'References'))) {
386 continue;
388 // make a substitution to match the messages variables;
389 // also we must substitute the grant we get, because we can't generate
390 // a form variable containing blanks (those would get changed to
391 // an underscore when receiving the POST)
392 if ($current_grant == 'Create View_priv') {
393 $tmp_current_grant = 'CreateView_priv';
394 $current_grant = 'Create_view_priv';
395 } elseif ($current_grant == 'Show view_priv') {
396 $tmp_current_grant = 'ShowView_priv';
397 $current_grant = 'Show_view_priv';
398 } else {
399 $tmp_current_grant = $current_grant;
402 echo ' <div class="item">' . "\n"
403 . ' <input type="checkbox"'
404 . (empty($GLOBALS['checkall']) ? '' : ' checked="checked"')
405 . ' name="' . $current_grant . '" id="checkbox_' . $current_grant
406 . '" value="Y" '
407 . ($current_grant_value == 'Y' ? 'checked="checked" ' : '')
408 . 'title="';
410 echo (isset($GLOBALS['strPrivDesc' . substr($tmp_current_grant, 0, (strlen($tmp_current_grant) - 5))])
411 ? $GLOBALS['strPrivDesc' . substr($tmp_current_grant, 0, (strlen($tmp_current_grant) - 5))]
412 : $GLOBALS['strPrivDesc' . substr($tmp_current_grant, 0, (strlen($tmp_current_grant) - 5)) . 'Tbl']) . '"/>' . "\n";
414 echo ' <label for="checkbox_' . $current_grant
415 . '"><tt><dfn title="'
416 . (isset($GLOBALS['strPrivDesc' . substr($tmp_current_grant, 0, (strlen($tmp_current_grant) - 5))])
417 ? $GLOBALS['strPrivDesc' . substr($tmp_current_grant, 0, (strlen($tmp_current_grant) - 5))]
418 : $GLOBALS['strPrivDesc' . substr($tmp_current_grant, 0, (strlen($tmp_current_grant) - 5)) . 'Tbl'])
419 . '">' . strtoupper(substr($current_grant, 0, strlen($current_grant) - 5)) . '</dfn></tt></label>' . "\n"
420 . ' </div>' . "\n";
421 } // end foreach ()
423 echo ' </div>' . "\n";
424 // for Safari 2.0.2
425 echo ' <div class="clearfloat"></div>' . "\n";
427 } else {
429 // g l o b a l o r d b - s p e c i f i c
431 // d a t a
432 $privTable[0] = array(
433 array('Select', 'SELECT', $GLOBALS['strPrivDescSelect']),
434 array('Insert', 'INSERT', $GLOBALS['strPrivDescInsert']),
435 array('Update', 'UPDATE', $GLOBALS['strPrivDescUpdate']),
436 array('Delete', 'DELETE', $GLOBALS['strPrivDescDelete'])
438 if ($db == '*') {
439 $privTable[0][] = array('File', 'FILE', $GLOBALS['strPrivDescFile']);
442 // s t r u c t u r e
443 $privTable[1] = array(
444 array('Create', 'CREATE', ($table == '*' ? $GLOBALS['strPrivDescCreateDb'] : $GLOBALS['strPrivDescCreateTbl'])),
445 array('Alter', 'ALTER', $GLOBALS['strPrivDescAlter']),
446 array('Index', 'INDEX', $GLOBALS['strPrivDescIndex']),
447 array('Drop', 'DROP', ($table == '*' ? $GLOBALS['strPrivDescDropDb'] : $GLOBALS['strPrivDescDropTbl'])),
448 array('Create_tmp_table', 'CREATE TEMPORARY TABLES', $GLOBALS['strPrivDescCreateTmpTable']),
449 array('Show_view', 'SHOW VIEW', $GLOBALS['strPrivDescShowView']),
450 array('Create_routine', 'CREATE ROUTINE', $GLOBALS['strPrivDescCreateRoutine']),
451 array('Alter_routine', 'ALTER ROUTINE', $GLOBALS['strPrivDescAlterRoutine']),
452 array('Execute', 'EXECUTE', $GLOBALS['strPrivDescExecute5']),
454 // this one is for a db-specific priv: Create_view_priv
455 if (isset($row['Create_view_priv'])) {
456 $privTable[1][] = array('Create_view', 'CREATE VIEW', $GLOBALS['strPrivDescCreateView']);
458 // this one is for a table-specific priv: Create View_priv
459 if (isset($row['Create View_priv'])) {
460 $privTable[1][] = array('Create View', 'CREATE VIEW', $GLOBALS['strPrivDescCreateView']);
462 if (isset($row['Event_priv'])) {
463 // MySQL 5.1.6
464 $privTable[1][] = array('Event', 'EVENT', $GLOBALS['strPrivDescEvent']);
465 $privTable[1][] = array('Trigger', 'TRIGGER', $GLOBALS['strPrivDescTrigger']);
468 // a d m i n i s t r a t i o n
469 $privTable[2] = array(
470 array('Grant', 'GRANT', $GLOBALS['strPrivDescGrant']),
472 if ($db == '*') {
473 $privTable[2][] = array('Super', 'SUPER', $GLOBALS['strPrivDescSuper']);
474 $privTable[2][] = array('Process', 'PROCESS', $GLOBALS['strPrivDescProcess']);
475 $privTable[2][] = array('Reload', 'RELOAD', $GLOBALS['strPrivDescReload']);
476 $privTable[2][] = array('Shutdown', 'SHUTDOWN', $GLOBALS['strPrivDescShutdown']);
477 $privTable[2][] = array('Show_db', 'SHOW DATABASES', $GLOBALS['strPrivDescShowDb']);
479 $privTable[2][] = array('Lock_tables', 'LOCK TABLES', $GLOBALS['strPrivDescLockTables']);
480 $privTable[2][] = array('References', 'REFERENCES', $GLOBALS['strPrivDescReferences']);
481 if ($db == '*') {
482 $privTable[2][] = array('Repl_client', 'REPLICATION CLIENT', $GLOBALS['strPrivDescReplClient']);
483 $privTable[2][] = array('Repl_slave', 'REPLICATION SLAVE', $GLOBALS['strPrivDescReplSlave']);
484 $privTable[2][] = array('Create_user', 'CREATE USER', $GLOBALS['strPrivDescCreateUser']);
486 echo '<input type="hidden" name="grant_count" value="'
487 . (count($privTable[0]) + count($privTable[1]) + count($privTable[2]) - (isset($row['Grant_priv']) ? 1 : 0))
488 . '" />' . "\n"
489 . '<fieldset id="fieldset_user_global_rights">' . "\n"
490 . ' <legend>' . "\n"
491 . ' '
492 . ($db == '*'
493 ? $GLOBALS['strGlobalPrivileges']
494 : ($table == '*'
495 ? $GLOBALS['strDbPrivileges']
496 : $GLOBALS['strTblPrivileges'])) . "\n"
497 . ' (<a href="server_privileges.php?'
498 . $GLOBALS['url_query'] . '&amp;checkall=1" onclick="setCheckboxes(\'usersForm\', true); return false;">'
499 . $GLOBALS['strCheckAll'] . '</a> /' . "\n"
500 . ' <a href="server_privileges.php?'
501 . $GLOBALS['url_query'] . '" onclick="setCheckboxes(\'usersForm\', false); return false;">'
502 . $GLOBALS['strUncheckAll'] . '</a>)' . "\n"
503 . ' </legend>' . "\n"
504 . ' <p><small><i>' . $GLOBALS['strEnglishPrivileges'] . '</i></small></p>' . "\n"
505 . ' <fieldset>' . "\n"
506 . ' <legend>' . $GLOBALS['strData'] . '</legend>' . "\n";
507 foreach ($privTable[0] as $priv)
509 echo ' <div class="item">' . "\n"
510 . ' <input type="checkbox"'
511 . (empty($GLOBALS['checkall']) ? '' : ' checked="checked"')
512 . ' name="' . $priv[0] . '_priv" id="checkbox_' . $priv[0]
513 . '_priv" value="Y" '
514 . ($row[$priv[0] . '_priv'] == 'Y' ? 'checked="checked" ' : '')
515 . 'title="' . $priv[2] . '"/>' . "\n"
516 . ' <label for="checkbox_' . $priv[0]
517 . '_priv"><tt><dfn title="' . $priv[2] . '">' . $priv[1]
518 . '</dfn></tt></label>' . "\n"
519 . ' </div>' . "\n";
521 echo ' </fieldset>' . "\n"
522 . ' <fieldset>' . "\n"
523 . ' <legend>' . $GLOBALS['strStructure'] . '</legend>' . "\n";
524 foreach ($privTable[1] as $priv)
526 echo ' <div class="item">' . "\n"
527 . ' <input type="checkbox"'
528 . (empty($GLOBALS['checkall']) ? '' : ' checked="checked"')
529 . ' name="' . $priv[0] . '_priv" id="checkbox_' . $priv[0]
530 . '_priv" value="Y" '
531 . ($row[$priv[0] . '_priv'] == 'Y' ? 'checked="checked" ' : '')
532 . 'title="' . $priv[2] . '"/>' . "\n"
533 . ' <label for="checkbox_' . $priv[0]
534 . '_priv"><tt><dfn title="' . $priv[2] . '">' . $priv[1]
535 . '</dfn></tt></label>' . "\n"
536 . ' </div>' . "\n";
538 echo ' </fieldset>' . "\n"
539 . ' <fieldset>' . "\n"
540 . ' <legend>' . $GLOBALS['strAdministration'] . '</legend>' . "\n";
541 foreach ($privTable[2] as $priv)
543 echo ' <div class="item">' . "\n"
544 . ' <input type="checkbox"'
545 . (empty($GLOBALS['checkall']) ? '' : ' checked="checked"')
546 . ' name="' . $priv[0] . '_priv" id="checkbox_' . $priv[0]
547 . '_priv" value="Y" '
548 . ($row[$priv[0] . '_priv'] == 'Y' ? 'checked="checked" ' : '')
549 . 'title="' . $priv[2] . '"/>' . "\n"
550 . ' <label for="checkbox_' . $priv[0]
551 . '_priv"><tt><dfn title="' . $priv[2] . '">' . $priv[1]
552 . '</dfn></tt></label>' . "\n"
553 . ' </div>' . "\n";
556 echo ' </fieldset>' . "\n";
557 // The "Resource limits" box is not displayed for db-specific privs
558 if ($db == '*') {
559 echo ' <fieldset>' . "\n"
560 . ' <legend>' . $GLOBALS['strResourceLimits'] . '</legend>' . "\n"
561 . ' <p><small><i>' . $GLOBALS['strZeroRemovesTheLimit'] . '</i></small></p>' . "\n"
562 . ' <div class="item">' . "\n"
563 . ' <label for="text_max_questions"><tt><dfn title="'
564 . $GLOBALS['strPrivDescMaxQuestions'] . '">MAX QUERIES PER HOUR</dfn></tt></label>' . "\n"
565 . ' <input type="text" name="max_questions" id="text_max_questions" value="'
566 . $row['max_questions'] . '" size="11" maxlength="11" title="' . $GLOBALS['strPrivDescMaxQuestions'] . '" />' . "\n"
567 . ' </div>' . "\n"
568 . ' <div class="item">' . "\n"
569 . ' <label for="text_max_updates"><tt><dfn title="'
570 . $GLOBALS['strPrivDescMaxUpdates'] . '">MAX UPDATES PER HOUR</dfn></tt></label>' . "\n"
571 . ' <input type="text" name="max_updates" id="text_max_updates" value="'
572 . $row['max_updates'] . '" size="11" maxlength="11" title="' . $GLOBALS['strPrivDescMaxUpdates'] . '" />' . "\n"
573 . ' </div>' . "\n"
574 . ' <div class="item">' . "\n"
575 . ' <label for="text_max_connections"><tt><dfn title="'
576 . $GLOBALS['strPrivDescMaxConnections'] . '">MAX CONNECTIONS PER HOUR</dfn></tt></label>' . "\n"
577 . ' <input type="text" name="max_connections" id="text_max_connections" value="'
578 . $row['max_connections'] . '" size="11" maxlength="11" title="' . $GLOBALS['strPrivDescMaxConnections'] . '" />' . "\n"
579 . ' </div>' . "\n"
580 . ' <div class="item">' . "\n"
581 . ' <label for="text_max_user_connections"><tt><dfn title="'
582 . $GLOBALS['strPrivDescMaxUserConnections'] . '">MAX USER_CONNECTIONS</dfn></tt></label>' . "\n"
583 . ' <input type="text" name="max_user_connections" id="text_max_user_connections" value="'
584 . $row['max_user_connections'] . '" size="11" maxlength="11" title="' . $GLOBALS['strPrivDescMaxUserConnections'] . '" />' . "\n"
585 . ' </div>' . "\n"
586 . ' </fieldset>' . "\n";
588 // for Safari 2.0.2
589 echo ' <div class="clearfloat"></div>' . "\n";
591 echo '</fieldset>' . "\n";
592 if ($submit) {
593 echo '<fieldset id="fieldset_user_privtable_footer" class="tblFooters">' . "\n"
594 . ' <input type="submit" name="update_privs" value="' . $GLOBALS['strGo'] . '" />' . "\n"
595 . '</fieldset>' . "\n";
597 } // end of the 'PMA_displayPrivTable()' function
601 * Displays the fields used by the "new user" form as well as the
602 * "change login information / copy user" form.
604 * @param string $mode are we creating a new user or are we just
605 * changing one? (allowed values: 'new', 'change')
606 * @global array $cfg the phpMyAdmin configuration
607 * @global ressource $user_link the database connection
609 * @return void
611 function PMA_displayLoginInformationFields($mode = 'new')
613 // Get user/host name lengths
614 $fields_info = PMA_DBI_get_fields('mysql', 'user');
615 $username_length = 16;
616 $hostname_length = 41;
617 foreach ($fields_info as $key => $val) {
618 if ($val['Field'] == 'User') {
619 strtok($val['Type'], '()');
620 $v = strtok('()');
621 if (is_int($v)) {
622 $username_length = $v;
624 } elseif ($val['Field'] == 'Host') {
625 strtok($val['Type'], '()');
626 $v = strtok('()');
627 if (is_int($v)) {
628 $hostname_length = $v;
632 unset($fields_info);
634 if (isset($GLOBALS['username']) && strlen($GLOBALS['username']) === 0) {
635 $GLOBALS['pred_username'] = 'any';
637 echo '<fieldset id="fieldset_add_user_login">' . "\n"
638 . '<legend>' . $GLOBALS['strLoginInformation'] . '</legend>' . "\n"
639 . '<div class="item">' . "\n"
640 . '<label for="select_pred_username">' . "\n"
641 . ' ' . $GLOBALS['strUserName'] . ':' . "\n"
642 . '</label>' . "\n"
643 . '<span class="options">' . "\n"
644 . ' <select name="pred_username" id="select_pred_username" title="' . $GLOBALS['strUserName'] . '"' . "\n"
645 . ' onchange="if (this.value == \'any\') { username.value = \'\'; } else if (this.value == \'userdefined\') { username.focus(); username.select(); }">' . "\n"
646 . ' <option value="any"' . ((isset($GLOBALS['pred_username']) && $GLOBALS['pred_username'] == 'any') ? ' selected="selected"' : '') . '>' . $GLOBALS['strAnyUser'] . '</option>' . "\n"
647 . ' <option value="userdefined"' . ((!isset($GLOBALS['pred_username']) || $GLOBALS['pred_username'] == 'userdefined') ? ' selected="selected"' : '') . '>' . $GLOBALS['strUseTextField'] . ':</option>' . "\n"
648 . ' </select>' . "\n"
649 . '</span>' . "\n"
650 . '<input type="text" name="username" maxlength="'
651 . $username_length . '" title="' . $GLOBALS['strUserName'] . '"'
652 . (empty($GLOBALS['username'])
653 ? ''
654 : ' value="' . (isset($GLOBALS['new_username'])
655 ? $GLOBALS['new_username']
656 : $GLOBALS['username']) . '"')
657 . ' onchange="pred_username.value = \'userdefined\';" />' . "\n"
658 . '</div>' . "\n"
659 . '<div class="item">' . "\n"
660 . '<label for="select_pred_hostname">' . "\n"
661 . ' ' . $GLOBALS['strHost'] . ':' . "\n"
662 . '</label>' . "\n"
663 . '<span class="options">' . "\n"
664 . ' <select name="pred_hostname" id="select_pred_hostname" title="' . $GLOBALS['strHost'] . '"' . "\n";
665 $_current_user = PMA_DBI_fetch_value('SELECT USER();');
666 if (! empty($_current_user)) {
667 $thishost = str_replace("'", '', substr($_current_user, (strrpos($_current_user, '@') + 1)));
668 if ($thishost == 'localhost' || $thishost == '127.0.0.1') {
669 unset($thishost);
672 echo ' onchange="if (this.value == \'any\') { hostname.value = \'%\'; } else if (this.value == \'localhost\') { hostname.value = \'localhost\'; } '
673 . (empty($thishost) ? '' : 'else if (this.value == \'thishost\') { hostname.value = \'' . addslashes(htmlspecialchars($thishost)) . '\'; } ')
674 . 'else if (this.value == \'hosttable\') { hostname.value = \'\'; } else if (this.value == \'userdefined\') { hostname.focus(); hostname.select(); }">' . "\n";
675 unset($_current_user);
677 // when we start editing a user, $GLOBALS['pred_hostname'] is not defined
678 if (!isset($GLOBALS['pred_hostname']) && isset($GLOBALS['hostname'])) {
679 switch (strtolower($GLOBALS['hostname'])) {
680 case 'localhost':
681 case '127.0.0.1':
682 $GLOBALS['pred_hostname'] = 'localhost';
683 break;
684 case '%':
685 $GLOBALS['pred_hostname'] = 'any';
686 break;
687 default:
688 $GLOBALS['pred_hostname'] = 'userdefined';
689 break;
692 echo ' <option value="any"'
693 . ((isset($GLOBALS['pred_hostname']) && $GLOBALS['pred_hostname'] == 'any')
694 ? ' selected="selected"' : '') . '>' . $GLOBALS['strAnyHost']
695 . '</option>' . "\n"
696 . ' <option value="localhost"'
697 . ((isset($GLOBALS['pred_hostname']) && $GLOBALS['pred_hostname'] == 'localhost')
698 ? ' selected="selected"' : '') . '>' . $GLOBALS['strLocalhost']
699 . '</option>' . "\n";
700 if (!empty($thishost)) {
701 echo ' <option value="thishost"'
702 . ((isset($GLOBALS['pred_hostname']) && $GLOBALS['pred_hostname'] == 'thishost')
703 ? ' selected="selected"' : '') . '>' . $GLOBALS['strThisHost']
704 . '</option>' . "\n";
706 unset($thishost);
707 echo ' <option value="hosttable"'
708 . ((isset($GLOBALS['pred_hostname']) && $GLOBALS['pred_hostname'] == 'hosttable')
709 ? ' selected="selected"' : '') . '>' . $GLOBALS['strUseHostTable']
710 . '</option>' . "\n"
711 . ' <option value="userdefined"'
712 . ((isset($GLOBALS['pred_hostname']) && $GLOBALS['pred_hostname'] == 'userdefined')
713 ? ' selected="selected"' : '')
714 . '>' . $GLOBALS['strUseTextField'] . ':</option>' . "\n"
715 . ' </select>' . "\n"
716 . '</span>' . "\n"
717 . '<input type="text" name="hostname" maxlength="'
718 . $hostname_length . '" value="'
719 . (isset($GLOBALS['hostname']) ? $GLOBALS['hostname'] : '')
720 . '" title="' . $GLOBALS['strHost']
721 . '" onchange="pred_hostname.value = \'userdefined\';" />' . "\n"
722 . '</div>' . "\n"
723 . '<div class="item">' . "\n"
724 . '<label for="select_pred_password">' . "\n"
725 . ' ' . $GLOBALS['strPassword'] . ':' . "\n"
726 . '</label>' . "\n"
727 . '<span class="options">' . "\n"
728 . ' <select name="pred_password" id="select_pred_password" title="'
729 . $GLOBALS['strPassword'] . '"' . "\n"
730 . ' onchange="if (this.value == \'none\') { pma_pw.value = \'\'; pma_pw2.value = \'\'; } else if (this.value == \'userdefined\') { pma_pw.focus(); pma_pw.select(); }">' . "\n"
731 . ($mode == 'change' ? ' <option value="keep" selected="selected">' . $GLOBALS['strKeepPass'] . '</option>' . "\n" : '')
732 . ' <option value="none"';
733 if (isset($GLOBALS['username']) && $mode != 'change') {
734 echo ' selected="selected"';
736 echo '>' . $GLOBALS['strNoPassword'] . '</option>' . "\n"
737 . ' <option value="userdefined"' . (isset($GLOBALS['username']) ? '' : ' selected="selected"') . '>' . $GLOBALS['strUseTextField'] . ':</option>' . "\n"
738 . ' </select>' . "\n"
739 . '</span>' . "\n"
740 . '<input type="password" id="text_pma_pw" name="pma_pw" title="' . $GLOBALS['strPassword'] . '" onchange="pred_password.value = \'userdefined\';" />' . "\n"
741 . '</div>' . "\n"
742 . '<div class="item">' . "\n"
743 . '<label for="text_pma_pw2">' . "\n"
744 . ' ' . $GLOBALS['strReType'] . ':' . "\n"
745 . '</label>' . "\n"
746 . '<span class="options">&nbsp;</span>' . "\n"
747 . '<input type="password" name="pma_pw2" id="text_pma_pw2" title="' . $GLOBALS['strReType'] . '" onchange="pred_password.value = \'userdefined\';" />' . "\n"
748 . '</div>' . "\n"
749 . '<div class="item">' . "\n"
750 . '<label for="button_generate_password">' . "\n"
751 . ' ' . $GLOBALS['strGeneratePassword'] . ':' . "\n"
752 . '</label>' . "\n"
753 . '<span class="options">' . "\n"
754 . ' <input type="button" id="button_generate_password" value="' . $GLOBALS['strGenerate'] . '" onclick="suggestPassword()" />' . "\n"
755 . ' <input type="button" id="button_copy_password" value="' . $GLOBALS['strCopy'] . '" onclick="suggestPasswordCopy(this.form)" />' . "\n"
756 . '</span>' . "\n"
757 . '<input type="text" name="generated_pw" id="generated_pw" />' . "\n"
758 . '</div>' . "\n"
759 . '</fieldset>' . "\n";
760 } // end of the 'PMA_displayUserAndHostFields()' function
764 * Changes / copies a user, part I
766 if (isset($_REQUEST['change_copy'])) {
767 $user_host_condition =
768 ' WHERE `User`'
769 .' = \'' . PMA_sqlAddslashes($old_username) . "'"
770 .' AND `Host`'
771 .' = \'' . $old_hostname . '\';';
772 $row = PMA_DBI_fetch_single_row('SELECT * FROM `mysql`.`user` ' . $user_host_condition);
773 if (! $row) {
774 PMA_Message::notice('strNoUsersFound')->display();
775 unset($_REQUEST['change_copy']);
776 } else {
777 extract($row, EXTR_OVERWRITE);
778 // Recent MySQL versions have the field "Password" in mysql.user,
779 // so the previous extract creates $Password but this script
780 // uses $password
781 if (!isset($password) && isset($Password)) {
782 $password = $Password;
784 $queries = array();
790 * Adds a user
791 * (Changes / copies a user, part II)
793 if (isset($_REQUEST['adduser_submit']) || isset($_REQUEST['change_copy'])) {
794 $sql_query = '';
795 if ($pred_username == 'any') {
796 $username = '';
798 switch ($pred_hostname) {
799 case 'any':
800 $hostname = '%';
801 break;
802 case 'localhost':
803 $hostname = 'localhost';
804 break;
805 case 'hosttable':
806 $hostname = '';
807 break;
808 case 'thishost':
809 $_user_name = PMA_DBI_fetch_value('SELECT USER()');
810 $hostname = substr($_user_name, (strrpos($_user_name, '@') + 1));
811 unset($_user_name);
812 break;
814 $sql = "SELECT '1' FROM `mysql`.`user`"
815 . " WHERE `User` = '" . PMA_sqlAddslashes($username) . "'"
816 . " AND `Host` = '" . PMA_sqlAddslashes($hostname) . "';";
817 if (PMA_DBI_fetch_value($sql) == 1) {
818 $message = PMA_Message::error('strUserAlreadyExists');
819 $message->addParam('[i]\'' . $username . '\'@\'' . $hostname . '\'[/i]');
820 $_REQUEST['adduser'] = true;
821 } else {
823 $create_user_real = 'CREATE USER \'' . PMA_sqlAddslashes($username) . '\'@\'' . $hostname . '\'';
825 $real_sql_query =
826 'GRANT ' . join(', ', PMA_extractPrivInfo()) . ' ON *.* TO \''
827 . PMA_sqlAddslashes($username) . '\'@\'' . $hostname . '\'';
828 if ($pred_password != 'none' && $pred_password != 'keep') {
829 $sql_query = $real_sql_query . ' IDENTIFIED BY \'***\'';
830 $real_sql_query .= ' IDENTIFIED BY \'' . PMA_sqlAddslashes($pma_pw) . '\'';
831 if (isset($create_user_real)) {
832 $create_user_show = $create_user_real . ' IDENTIFIED BY \'***\'';
833 $create_user_real .= ' IDENTIFIED BY \'' . PMA_sqlAddslashes($pma_pw) . '\'';
835 } else {
836 if ($pred_password == 'keep' && !empty($password)) {
837 $real_sql_query .= ' IDENTIFIED BY PASSWORD \'' . $password . '\'';
838 if (isset($create_user_real)) {
839 $create_user_real .= ' IDENTIFIED BY PASSWORD \'' . $password . '\'';
842 $sql_query = $real_sql_query;
843 if (isset($create_user_real)) {
844 $create_user_show = $create_user_real;
848 * @todo similar code appears twice in this script
850 if ((isset($Grant_priv) && $Grant_priv == 'Y')
851 || (isset($max_questions) || isset($max_connections)
852 || isset($max_updates) || isset($max_user_connections))) {
853 $real_sql_query .= ' WITH';
854 $sql_query .= ' WITH';
855 if (isset($Grant_priv) && $Grant_priv == 'Y') {
856 $real_sql_query .= ' GRANT OPTION';
857 $sql_query .= ' GRANT OPTION';
859 if (isset($max_questions)) {
860 // avoid negative values
861 $max_questions = max(0, (int)$max_questions);
862 $real_sql_query .= ' MAX_QUERIES_PER_HOUR ' . $max_questions;
863 $sql_query .= ' MAX_QUERIES_PER_HOUR ' . $max_questions;
865 if (isset($max_connections)) {
866 $max_connections = max(0, (int)$max_connections);
867 $real_sql_query .= ' MAX_CONNECTIONS_PER_HOUR ' . $max_connections;
868 $sql_query .= ' MAX_CONNECTIONS_PER_HOUR ' . $max_connections;
870 if (isset($max_updates)) {
871 $max_updates = max(0, (int)$max_updates);
872 $real_sql_query .= ' MAX_UPDATES_PER_HOUR ' . $max_updates;
873 $sql_query .= ' MAX_UPDATES_PER_HOUR ' . $max_updates;
875 if (isset($max_user_connections)) {
876 $max_user_connections = max(0, (int)$max_user_connections);
877 $real_sql_query .= ' MAX_USER_CONNECTIONS ' . $max_user_connections;
878 $sql_query .= ' MAX_USER_CONNECTIONS ' . $max_user_connections;
881 if (isset($create_user_real)) {
882 $create_user_real .= ';';
883 $create_user_show .= ';';
885 $real_sql_query .= ';';
886 $sql_query .= ';';
887 if (empty($_REQUEST['change_copy'])) {
888 $_error = false;
890 if (isset($create_user_real)) {
891 if (! PMA_DBI_try_query($create_user_real)) {
892 $_error = true;
894 $sql_query = $create_user_show . $sql_query;
897 if ($_error || ! PMA_DBI_try_query($real_sql_query)) {
898 $_REQUEST['createdb'] = false;
899 $message = PMA_Message::rawError(PMA_DBI_getError());
900 } else {
901 $message = PMA_Message::success('strAddUserMessage');
904 switch (PMA_ifSetOr($_REQUEST['createdb'], '0')) {
905 case '1' :
906 $q = 'CREATE DATABASE IF NOT EXISTS '
907 . PMA_backquote(PMA_sqlAddslashes($username)) . ';';
908 $sql_query .= $q;
909 if (! PMA_DBI_try_query($q)) {
910 $message = PMA_Message::rawError(PMA_DBI_getError());
911 break;
913 $GLOBALS['reload'] = TRUE;
914 PMA_reloadNavigation();
916 $q = 'GRANT ALL PRIVILEGES ON '
917 . PMA_backquote(PMA_sqlAddslashes($username)) . '.* TO \''
918 . PMA_sqlAddslashes($username) . '\'@\'' . $hostname . '\';';
919 $sql_query .= $q;
920 if (! PMA_DBI_try_query($q)) {
921 $message = PMA_Message::rawError(PMA_DBI_getError());
923 break;
924 case '2' :
925 $q = 'GRANT ALL PRIVILEGES ON '
926 . PMA_backquote(PMA_sqlAddslashes($username) . '\_%') . '.* TO \''
927 . PMA_sqlAddslashes($username) . '\'@\'' . $hostname . '\';';
928 $sql_query .= $q;
929 if (! PMA_DBI_try_query($q)) {
930 $message = PMA_Message::rawError(PMA_DBI_getError());
932 break;
933 case '0' :
934 default :
935 break;
937 } else {
938 if (isset($create_user_real)) {
939 $queries[] = $create_user_real;
941 $queries[] = $real_sql_query;
942 // we put the query containing the hidden password in
943 // $queries_for_display, at the same position occupied
944 // by the real query in $queries
945 $tmp_count = count($queries);
946 if (isset($create_user_real)) {
947 $queries_for_display[$tmp_count - 2] = $create_user_show;
949 $queries_for_display[$tmp_count - 1] = $sql_query;
951 unset($res, $real_sql_query);
957 * Changes / copies a user, part III
959 if (isset($_REQUEST['change_copy'])) {
960 $user_host_condition =
961 ' WHERE `User`'
962 .' = \'' . PMA_sqlAddslashes($old_username) . "'"
963 .' AND `Host`'
964 .' = \'' . $old_hostname . '\';';
965 $res = PMA_DBI_query('SELECT * FROM `mysql`.`db`' . $user_host_condition);
966 while ($row = PMA_DBI_fetch_assoc($res)) {
967 $queries[] =
968 'GRANT ' . join(', ', PMA_extractPrivInfo($row))
969 .' ON ' . PMA_backquote($row['Db']) . '.*'
970 .' TO \'' . PMA_sqlAddslashes($username) . '\'@\'' . $hostname . '\''
971 . ($row['Grant_priv'] == 'Y' ? ' WITH GRANT OPTION;' : ';');
973 PMA_DBI_free_result($res);
974 $res = PMA_DBI_query(
975 'SELECT `Db`, `Table_name`, `Table_priv`'
976 .' FROM `mysql`.`tables_priv`' . $user_host_condition,
977 $GLOBALS['userlink'], PMA_DBI_QUERY_STORE);
978 while ($row = PMA_DBI_fetch_assoc($res)) {
980 $res2 = PMA_DBI_QUERY(
981 'SELECT `Column_name`, `Column_priv`'
982 .' FROM `mysql`.`columns_priv`'
983 .' WHERE `User`'
984 .' = \'' . PMA_sqlAddslashes($old_username) . "'"
985 .' AND `Host`'
986 .' = \'' . $old_hostname . '\''
987 .' AND `Db`'
988 .' = \'' . $row['Db'] . "'"
989 .' AND `Table_name`'
990 .' = \'' . $row['Table_name'] . "'"
991 .';',
992 null, PMA_DBI_QUERY_STORE);
994 $tmp_privs1 = PMA_extractPrivInfo($row);
995 $tmp_privs2 = array(
996 'Select' => array(),
997 'Insert' => array(),
998 'Update' => array(),
999 'References' => array()
1002 while ($row2 = PMA_DBI_fetch_assoc($res2)) {
1003 $tmp_array = explode(',', $row2['Column_priv']);
1004 if (in_array('Select', $tmp_array)) {
1005 $tmp_privs2['Select'][] = $row2['Column_name'];
1007 if (in_array('Insert', $tmp_array)) {
1008 $tmp_privs2['Insert'][] = $row2['Column_name'];
1010 if (in_array('Update', $tmp_array)) {
1011 $tmp_privs2['Update'][] = $row2['Column_name'];
1013 if (in_array('References', $tmp_array)) {
1014 $tmp_privs2['References'][] = $row2['Column_name'];
1016 unset($tmp_array);
1018 if (count($tmp_privs2['Select']) > 0 && !in_array('SELECT', $tmp_privs1)) {
1019 $tmp_privs1[] = 'SELECT (`' . join('`, `', $tmp_privs2['Select']) . '`)';
1021 if (count($tmp_privs2['Insert']) > 0 && !in_array('INSERT', $tmp_privs1)) {
1022 $tmp_privs1[] = 'INSERT (`' . join('`, `', $tmp_privs2['Insert']) . '`)';
1024 if (count($tmp_privs2['Update']) > 0 && !in_array('UPDATE', $tmp_privs1)) {
1025 $tmp_privs1[] = 'UPDATE (`' . join('`, `', $tmp_privs2['Update']) . '`)';
1027 if (count($tmp_privs2['References']) > 0 && !in_array('REFERENCES', $tmp_privs1)) {
1028 $tmp_privs1[] = 'REFERENCES (`' . join('`, `', $tmp_privs2['References']) . '`)';
1030 unset($tmp_privs2);
1031 $queries[] =
1032 'GRANT ' . join(', ', $tmp_privs1)
1033 . ' ON ' . PMA_backquote($row['Db']) . '.' . PMA_backquote($row['Table_name'])
1034 . ' TO \'' . PMA_sqlAddslashes($username) . '\'@\'' . $hostname . '\''
1035 . (in_array('Grant', explode(',', $row['Table_priv'])) ? ' WITH GRANT OPTION;' : ';');
1041 * Updates privileges
1043 if (!empty($update_privs)) {
1044 // escaping a wildcard character in a GRANT is only accepted at the global
1045 // or database level, not at table level; this is why I remove
1046 // the escaping character
1047 // Note: in the phpMyAdmin list of Database-specific privileges,
1048 // we will have for example
1049 // test\_db SELECT (this one is for privileges on a db level)
1050 // test_db USAGE (this one is for table-specific privileges)
1052 // It looks curious but reflects the way MySQL works
1054 $sql_query0 =
1055 'REVOKE ALL PRIVILEGES ON ' . $db_and_table
1056 . ' FROM \'' . PMA_sqlAddslashes($username) . '\'@\'' . $hostname . '\';';
1057 if (!isset($Grant_priv) || $Grant_priv != 'Y') {
1058 $sql_query1 =
1059 'REVOKE GRANT OPTION ON ' . $db_and_table
1060 . ' FROM \'' . PMA_sqlAddslashes($username) . '\'@\'' . $hostname . '\';';
1061 } else {
1062 $sql_query1 = '';
1064 $sql_query2 =
1065 'GRANT ' . join(', ', PMA_extractPrivInfo())
1066 . ' ON ' . $db_and_table
1067 . ' TO \'' . PMA_sqlAddslashes($username) . '\'@\'' . $hostname . '\'';
1070 * @todo similar code appears twice in this script
1072 if ((isset($Grant_priv) && $Grant_priv == 'Y')
1073 || (! isset($dbname)
1074 && (isset($max_questions) || isset($max_connections)
1075 || isset($max_updates) || isset($max_user_connections))))
1077 $sql_query2 .= 'WITH';
1078 if (isset($Grant_priv) && $Grant_priv == 'Y') {
1079 $sql_query2 .= ' GRANT OPTION';
1081 if (isset($max_questions)) {
1082 $max_questions = max(0, (int)$max_questions);
1083 $sql_query2 .= ' MAX_QUERIES_PER_HOUR ' . $max_questions;
1085 if (isset($max_connections)) {
1086 $max_connections = max(0, (int)$max_connections);
1087 $sql_query2 .= ' MAX_CONNECTIONS_PER_HOUR ' . $max_connections;
1089 if (isset($max_updates)) {
1090 $max_updates = max(0, (int)$max_updates);
1091 $sql_query2 .= ' MAX_UPDATES_PER_HOUR ' . $max_updates;
1093 if (isset($max_user_connections)) {
1094 $max_user_connections = max(0, (int)$max_user_connections);
1095 $sql_query2 .= ' MAX_USER_CONNECTIONS ' . $max_user_connections;
1098 $sql_query2 .= ';';
1099 if (!PMA_DBI_try_query($sql_query0)) {
1100 // this query may fail, but this does not matter :o)
1101 // a case when it can fail is when the admin does not have all
1102 // privileges: he can't do a REVOKE ALL PRIVILEGES !
1103 // so at least we display the error
1104 echo PMA_DBI_getError();
1105 $sql_query0 = '';
1107 if (isset($sql_query1) && !PMA_DBI_try_query($sql_query1)) {
1108 // this one may fail, too...
1109 $sql_query1 = '';
1111 PMA_DBI_query($sql_query2);
1112 $sql_query = $sql_query0 . ' ' . $sql_query1 . ' ' . $sql_query2;
1113 $message = PMA_Message::success('strUpdatePrivMessage');
1114 $message->addParam('\'' . $username . '\'@\'' . $hostname . '\'');
1119 * Revokes Privileges
1121 if (isset($_REQUEST['revokeall'])) {
1123 $sql_query0 =
1124 'REVOKE ALL PRIVILEGES ON ' . $db_and_table
1125 . ' FROM \'' . $username . '\'@\'' . $hostname . '\';';
1126 $sql_query1 =
1127 'REVOKE GRANT OPTION ON ' . $db_and_table
1128 . ' FROM \'' . $username . '\'@\'' . $hostname . '\';';
1129 PMA_DBI_query($sql_query0);
1130 if (!PMA_DBI_try_query($sql_query1)) {
1131 // this one may fail, too...
1132 $sql_query1 = '';
1134 $sql_query = $sql_query0 . ' ' . $sql_query1;
1135 $message = PMA_Message::success('strRevokeMessage');
1136 $message->addParam('\'' . $username . '\'@\'' . $hostname . '\'');
1137 if (! isset($tablename)) {
1138 unset($dbname);
1139 } else {
1140 unset($tablename);
1146 * Updates the password
1148 if (isset($_REQUEST['change_pw'])) {
1149 // similar logic in user_password.php
1150 $message = '';
1152 if ($nopass == 0 && isset($pma_pw) && isset($pma_pw2)) {
1153 if ($pma_pw != $pma_pw2) {
1154 $message = PMA_Message::error('strPasswordNotSame');
1155 } elseif (empty($pma_pw) || empty($pma_pw2)) {
1156 $message = PMA_Message::error('strPasswordEmpty');
1158 } // end if
1160 // here $nopass could be == 1
1161 if (empty($message)) {
1163 $hashing_function = (!empty($pw_hash) && $pw_hash == 'old' ? 'OLD_' : '')
1164 . 'PASSWORD';
1166 // in $sql_query which will be displayed, hide the password
1167 $sql_query = 'SET PASSWORD FOR \'' . PMA_sqlAddslashes($username) . '\'@\'' . $hostname . '\' = ' . (($pma_pw == '') ? '\'\'' : $hashing_function . '(\'' . preg_replace('@.@s', '*', $pma_pw) . '\')');
1168 $local_query = 'SET PASSWORD FOR \'' . PMA_sqlAddslashes($username) . '\'@\'' . $hostname . '\' = ' . (($pma_pw == '') ? '\'\'' : $hashing_function . '(\'' . PMA_sqlAddslashes($pma_pw) . '\')');
1169 PMA_DBI_try_query($local_query)
1170 or PMA_mysqlDie(PMA_DBI_getError(), $sql_query, FALSE, $err_url);
1171 $message = PMA_Message::success('strPasswordChanged');
1172 $message->addParam('\'' . $username . '\'@\'' . $hostname . '\'');
1178 * Deletes users
1179 * (Changes / copies a user, part IV)
1181 $user_host_separator = chr(27);
1183 if (isset($_REQUEST['delete']) || (isset($_REQUEST['change_copy']) && $_REQUEST['mode'] < 4)) {
1184 if (isset($_REQUEST['change_copy'])) {
1185 $selected_usr = array($old_username . $user_host_separator . $old_hostname);
1186 } else {
1187 $selected_usr = $_REQUEST['selected_usr'];
1188 $queries = array();
1190 foreach ($selected_usr as $each_user) {
1191 list($this_user, $this_host) = explode($user_host_separator, $each_user);
1192 $queries[] = '# ' . sprintf($GLOBALS['strDeleting'], '\'' . $this_user . '\'@\'' . $this_host . '\'') . ' ...';
1193 $queries[] = 'DROP USER \'' . PMA_sqlAddslashes($this_user) . '\'@\'' . $this_host . '\';';
1195 if (isset($_REQUEST['drop_users_db'])) {
1196 $queries[] = 'DROP DATABASE IF EXISTS ' . PMA_backquote($this_user) . ';';
1197 $GLOBALS['reload'] = TRUE;
1198 PMA_reloadNavigation();
1201 if (empty($_REQUEST['change_copy'])) {
1202 if (empty($queries)) {
1203 $message = PMA_Message::error('strDeleteNoUsersSelected');
1204 } else {
1205 if ($_REQUEST['mode'] == 3) {
1206 $queries[] = '# ' . $GLOBALS['strReloadingThePrivileges'] . ' ...';
1207 $queries[] = 'FLUSH PRIVILEGES;';
1209 $drop_user_error = '';
1210 foreach ($queries as $sql_query) {
1211 if ($sql_query{0} != '#') {
1212 if (! PMA_DBI_try_query($sql_query, $GLOBALS['userlink'])) {
1213 $drop_user_error .= PMA_DBI_getError() . "\n";
1217 $sql_query = join("\n", $queries);
1218 if (! empty($drop_user_error)) {
1219 $message = PMA_Message::rawError($drop_user_error);
1220 } else {
1221 $message = PMA_Message::success('strUsersDeleted');
1224 unset($queries);
1230 * Changes / copies a user, part V
1232 if (isset($_REQUEST['change_copy'])) {
1233 $tmp_count = 0;
1234 foreach ($queries as $sql_query) {
1235 if ($sql_query{0} != '#') {
1236 PMA_DBI_query($sql_query);
1238 // when there is a query containing a hidden password, take it
1239 // instead of the real query sent
1240 if (isset($queries_for_display[$tmp_count])) {
1241 $queries[$tmp_count] = $queries_for_display[$tmp_count];
1243 $tmp_count++;
1245 $message = PMA_Message::success();
1246 $sql_query = join("\n", $queries);
1251 * Reloads the privilege tables into memory
1253 if (isset($_REQUEST['flush_privileges'])) {
1254 $sql_query = 'FLUSH PRIVILEGES;';
1255 PMA_DBI_query($sql_query);
1256 $message = PMA_Message::success('strPrivilegesReloaded');
1261 * Displays the links
1263 if (isset($viewing_mode) && $viewing_mode == 'db') {
1264 $db = $checkprivs;
1265 $url_query .= '&amp;goto=db_operations.php';
1267 // Gets the database structure
1268 $sub_part = '_structure';
1269 require './libraries/db_info.inc.php';
1270 echo "\n";
1271 } else {
1272 require './libraries/server_links.inc.php';
1277 * defines some standard links
1279 $link_edit = '<a href="server_privileges.php?' . $GLOBALS['url_query']
1280 . '&amp;username=%s'
1281 . '&amp;hostname=%s'
1282 . '&amp;dbname=%s'
1283 . '&amp;tablename=%s">'
1284 . PMA_getIcon('b_usredit.png', $GLOBALS['strEditPrivileges'])
1285 . '</a>';
1287 $link_revoke = '<a href="server_privileges.php?' . $GLOBALS['url_query']
1288 . '&amp;username=%s'
1289 . '&amp;hostname=%s'
1290 . '&amp;dbname=%s'
1291 . '&amp;tablename=%s'
1292 . '&amp;revokeall=1">'
1293 . PMA_getIcon('b_usrdrop.png', $GLOBALS['strRevoke'])
1294 . '</a>';
1297 * Displays the page
1299 if (empty($_REQUEST['adduser']) && (! isset($checkprivs) || ! strlen($checkprivs))) {
1300 if (! isset($username)) {
1301 // No username is given --> display the overview
1302 echo '<h2>' . "\n"
1303 . PMA_getIcon('b_usrlist.png')
1304 . $GLOBALS['strUserOverview'] . "\n"
1305 . '</h2>' . "\n";
1307 $sql_query =
1308 'SELECT *,' .
1309 " IF(`Password` = _latin1 '', 'N', 'Y') AS 'Password'" .
1310 ' FROM `mysql`.`user`';
1312 $sql_query .= (isset($initial) ? PMA_RangeOfUsers($initial) : '');
1314 $sql_query .= ' ORDER BY `User` ASC, `Host` ASC;';
1315 $res = PMA_DBI_try_query($sql_query, null, PMA_DBI_QUERY_STORE);
1317 if (! $res) {
1318 // the query failed! This may have two reasons:
1319 // - the user does not have enough privileges
1320 // - the privilege tables use a structure of an earlier version.
1321 // so let's try a more simple query
1323 $sql_query = 'SELECT * FROM `mysql`.`user`';
1324 $res = PMA_DBI_try_query($sql_query, null, PMA_DBI_QUERY_STORE);
1326 if (!$res) {
1327 PMA_Message::error('strNoPrivileges')->display();
1328 PMA_DBI_free_result($res);
1329 unset($res);
1330 } else {
1331 // rabus: This message is hardcoded because I will replace it by
1332 // a automatic repair feature soon.
1333 $raw = 'Your privilege table structure seems to be older than'
1334 . ' this MySQL version!<br />'
1335 . 'Please run the script <tt>mysql_fix_privilege_tables</tt>'
1336 . ' that should be included in your MySQL server distribution'
1337 . ' to solve this problem!';
1338 PMA_Message::rawError($raw)->display();
1340 } else {
1342 // we also want users not in table `user` but in other table
1343 $tables = PMA_DBI_fetch_result('SHOW TABLES FROM `mysql`;');
1345 $tables_to_search_for_users = array(
1346 'user', 'db', 'tables_priv', 'columns_priv', 'procs_priv',
1349 $db_rights_sqls = array();
1350 foreach ($tables_to_search_for_users as $table_search_in) {
1351 if (in_array($table_search_in, $tables)) {
1352 $db_rights_sqls[] = 'SELECT DISTINCT `User`, `Host` FROM `mysql`.`' . $table_search_in . '` ' . (isset($initial) ? PMA_RangeOfUsers($initial) : '');
1356 $user_defaults = array(
1357 'User' => '',
1358 'Host' => '%',
1359 'Password' => '?',
1360 'Grant_priv' => 'N',
1361 'privs' => array('USAGE'),
1364 // for all initials, even non A-Z
1365 $array_initials = array();
1366 // for the rights
1367 $db_rights = array();
1369 $db_rights_sql = '(' . implode(') UNION (', $db_rights_sqls) . ')'
1370 .' ORDER BY `User` ASC, `Host` ASC';
1372 $db_rights_result = PMA_DBI_query($db_rights_sql);
1374 while ($db_rights_row = PMA_DBI_fetch_assoc($db_rights_result)) {
1375 $db_rights_row = array_merge($user_defaults, $db_rights_row);
1376 $db_rights[$db_rights_row['User']][$db_rights_row['Host']] =
1377 $db_rights_row;
1379 PMA_DBI_free_result($db_rights_result);
1380 unset($db_rights_sql, $db_rights_sqls, $db_rights_result, $db_rights_row);
1381 ksort($db_rights);
1384 * Displays the initials
1387 // initialize to FALSE the letters A-Z
1388 for ($letter_counter = 1; $letter_counter < 27; $letter_counter++) {
1389 if (! isset($array_initials[chr($letter_counter + 64)])) {
1390 $array_initials[chr($letter_counter + 64)] = FALSE;
1394 $initials = PMA_DBI_try_query('SELECT DISTINCT UPPER(LEFT(`User`,1)) FROM `user` ORDER BY `User` ASC', null, PMA_DBI_QUERY_STORE);
1395 while (list($tmp_initial) = PMA_DBI_fetch_row($initials)) {
1396 $array_initials[$tmp_initial] = TRUE;
1399 // Display the initials, which can be any characters, not
1400 // just letters. For letters A-Z, we add the non-used letters
1401 // as greyed out.
1403 uksort($array_initials, "strnatcasecmp");
1405 echo '<table cellspacing="5"><tr>';
1406 foreach ($array_initials as $tmp_initial => $initial_was_found) {
1407 if ($initial_was_found) {
1408 echo '<td><a href="server_privileges.php?' . $GLOBALS['url_query'] . '&amp;initial=' . urlencode($tmp_initial) . '">' . $tmp_initial . '</a></td>' . "\n";
1409 } else {
1410 echo '<td>' . $tmp_initial . '</td>';
1413 echo '<td><a href="server_privileges.php?' . $GLOBALS['url_query'] . '&amp;showall=1">[' . $GLOBALS['strShowAll'] . ']</a></td>' . "\n";
1414 echo '</tr></table>';
1417 * Display the user overview
1418 * (if less than 50 users, display them immediately)
1421 if (isset($initial) || isset($showall) || PMA_DBI_num_rows($res) < 50) {
1423 while ($row = PMA_DBI_fetch_assoc($res)) {
1424 $row['privs'] = PMA_extractPrivInfo($row, true);
1425 $db_rights[$row['User']][$row['Host']] = $row;
1427 @PMA_DBI_free_result($res);
1428 unset($res);
1430 echo '<form name="usersForm" id="usersForm" action="server_privileges.php" method="post">' . "\n"
1431 . PMA_generate_common_hidden_inputs('', '')
1432 . ' <table id="tableuserrights" class="data">' . "\n"
1433 . ' <thead>' . "\n"
1434 . ' <tr><td></td>' . "\n"
1435 . ' <th>' . $GLOBALS['strUser'] . '</th>' . "\n"
1436 . ' <th>' . $GLOBALS['strHost'] . '</th>' . "\n"
1437 . ' <th>' . $GLOBALS['strPassword'] . '</th>' . "\n"
1438 . ' <th>' . $GLOBALS['strGlobalPrivileges'] . ' '
1439 . PMA_showHint($GLOBALS['strEnglishPrivileges']) . '</th>' . "\n"
1440 . ' <th>' . $GLOBALS['strGrantOption'] . '</th>' . "\n"
1441 . ' ' . ($GLOBALS['cfg']['PropertiesIconic'] ? '<td></td>' : '<th>' . $GLOBALS['strAction'] . '</th>') . "\n";
1442 echo ' </tr>' . "\n";
1443 echo ' </thead>' . "\n";
1444 echo ' <tbody>' . "\n";
1445 $odd_row = true;
1446 $index_checkbox = -1;
1447 foreach ($db_rights as $user) {
1448 $index_checkbox++;
1449 ksort($user);
1450 foreach ($user as $host) {
1451 $index_checkbox++;
1452 echo ' <tr class="' . ($odd_row ? 'odd' : 'even') . '">' . "\n"
1453 . ' <td><input type="checkbox" name="selected_usr[]" id="checkbox_sel_users_'
1454 . $index_checkbox . '" value="'
1455 . str_replace(chr(27), '&#27;', htmlspecialchars($host['User'] . $user_host_separator . $host['Host']))
1456 . '"'
1457 . (empty($GLOBALS['checkall']) ? '' : ' checked="checked"')
1458 . ' /></td>' . "\n"
1459 . ' <td><label for="checkbox_sel_users_' . $index_checkbox . '">' . (empty($host['User']) ? '<span style="color: #FF0000">' . $GLOBALS['strAny'] . '</span>' : htmlspecialchars($host['User'])) . '</label></td>' . "\n"
1460 . ' <td>' . htmlspecialchars($host['Host']) . '</td>' . "\n";
1461 echo ' <td>';
1462 switch ($host['Password']) {
1463 case 'Y':
1464 echo $GLOBALS['strYes'];
1465 break;
1466 case 'N':
1467 echo '<span style="color: #FF0000">' . $GLOBALS['strNo'] . '</span>';
1468 break;
1469 // this happens if this is a definition not coming from mysql.user
1470 default:
1471 echo '--'; // in future version, replace by "not present"
1472 break;
1473 } // end switch
1474 echo '</td>' . "\n"
1475 . ' <td><tt>' . "\n"
1476 . ' ' . implode(',' . "\n" . ' ', $host['privs']) . "\n"
1477 . ' </tt></td>' . "\n"
1478 . ' <td>' . ($host['Grant_priv'] == 'Y' ? $GLOBALS['strYes'] : $GLOBALS['strNo']) . '</td>' . "\n"
1479 . ' <td align="center">';
1480 printf($link_edit, urlencode($host['User']),
1481 urlencode($host['Host']), '', '');
1482 echo '</td>' . "\n"
1483 . ' </tr>' . "\n";
1484 $odd_row = ! $odd_row;
1488 unset($user, $host, $odd_row);
1489 echo ' </tbody></table>' . "\n"
1490 .'<img class="selectallarrow"'
1491 .' src="' . $pmaThemeImage . 'arrow_' . $text_dir . '.png"'
1492 .' width="38" height="22"'
1493 .' alt="' . $GLOBALS['strWithChecked'] . '" />' . "\n"
1494 .'<a href="server_privileges.php?' . $GLOBALS['url_query'] . '&amp;checkall=1"'
1495 .' onclick="if (markAllRows(\'usersForm\')) return false;">'
1496 . $GLOBALS['strCheckAll'] . '</a>' . "\n"
1497 .'/' . "\n"
1498 .'<a href="server_privileges.php?' . $GLOBALS['url_query'] . '"'
1499 .' onclick="if (unMarkAllRows(\'usersForm\')) return false;">'
1500 . $GLOBALS['strUncheckAll'] . '</a>' . "\n";
1502 // add/delete user fieldset
1503 echo ' <fieldset id="fieldset_add_user">' . "\n"
1504 . ' <a href="server_privileges.php?' . $GLOBALS['url_query'] . '&amp;adduser=1">' . "\n"
1505 . PMA_getIcon('b_usradd.png')
1506 . ' ' . $GLOBALS['strAddUser'] . '</a>' . "\n"
1507 . ' </fieldset>' . "\n"
1508 . ' <fieldset id="fieldset_delete_user">'
1509 . ' <legend>' . "\n"
1510 . PMA_getIcon('b_usrdrop.png')
1511 . ' ' . $GLOBALS['strRemoveSelectedUsers'] . '' . "\n"
1512 . ' </legend>' . "\n"
1513 . ' <input type="hidden" name="mode" value="2" />' . "\n"
1514 . '(' . $GLOBALS['strRevokeAndDelete'] . ')<br />' . "\n"
1515 . ' <input type="checkbox" title="' . $GLOBALS['strDropUsersDb'] . '" name="drop_users_db" id="checkbox_drop_users_db" />' . "\n"
1516 . ' <label for="checkbox_drop_users_db" title="' . $GLOBALS['strDropUsersDb'] . '">' . "\n"
1517 . ' ' . $GLOBALS['strDropUsersDb'] . "\n"
1518 . ' </label>' . "\n"
1519 . ' </fieldset>' . "\n"
1520 . ' <fieldset id="fieldset_delete_user_footer" class="tblFooters">' . "\n"
1521 . ' <input type="submit" name="delete" value="' . $GLOBALS['strGo'] . '" id="buttonGo" />' . "\n"
1522 . ' </fieldset>' . "\n";
1523 } else {
1525 unset ($row);
1526 echo ' <fieldset id="fieldset_add_user">' . "\n"
1527 . ' <a href="server_privileges.php?' . $GLOBALS['url_query'] . '&amp;adduser=1">' . "\n"
1528 . PMA_getIcon('b_usradd.png')
1529 . ' ' . $GLOBALS['strAddUser'] . '</a>' . "\n"
1530 . ' </fieldset>' . "\n";
1531 } // end if (display overview)
1532 echo '</form>' . "\n";
1533 $flushnote = new PMA_Message('strFlushPrivilegesNote', PMA_Message::NOTICE);
1534 $flushnote->addParam('<a href="server_privileges.php?' . $GLOBALS['url_query'] . '&amp;flush_privileges=1">', false);
1535 $flushnote->addParam('</a>', false);
1536 $flushnote->display();
1540 } else {
1542 // A user was selected -> display the user's properties
1544 echo '<h2>' . "\n"
1545 . PMA_getIcon('b_usredit.png')
1546 . $GLOBALS['strEditPrivileges'] . ': '
1547 . $GLOBALS['strUser'] ;
1549 if (isset($dbname)) {
1550 echo ' <i><a href="server_privileges.php?'
1551 . $GLOBALS['url_query'] . '&amp;username=' . urlencode($username)
1552 . '&amp;hostname=' . urlencode($hostname) . '">\''
1553 . htmlspecialchars($username) . '\'@\'' . htmlspecialchars($hostname)
1554 . '\'</a></i>' . "\n";
1555 $url_dbname = urlencode(str_replace('\_', '_', $dbname));
1557 if (isset($dbname)) {
1558 if (isset($tablename)) {
1559 echo ' - ' . ($dbname_is_wildcard ? $GLOBALS['strDatabases'] : $GLOBALS['strDatabase'] )
1560 . ' <i><a href="server_privileges.php?' . $GLOBALS['url_query']
1561 . '&amp;username=' . urlencode($username) . '&amp;hostname=' . urlencode($hostname)
1562 . '&amp;dbname=' . $url_dbname . '">' . htmlspecialchars($dbname) . '</a></i>';
1563 echo ' - ' . $GLOBALS['strTable'] . ' <i>' . htmlspecialchars($tablename) . '</i>';
1564 } else {
1565 echo ' - ' . $GLOBALS['strDatabase'] . ' <i>' . htmlspecialchars($dbname) . '</i>';
1569 } else {
1570 echo ' <i>\'' . htmlspecialchars($username) . '\'@\'' . htmlspecialchars($hostname)
1571 . '\'</i>' . "\n";
1574 if (isset($dbname)) {
1575 echo '</h2>' . "\n";
1579 $sql = "SELECT '1' FROM `mysql`.`user`"
1580 . " WHERE `User` = '" . PMA_sqlAddslashes($username) . "'"
1581 . " AND `Host` = '" . PMA_sqlAddslashes($hostname) . "';";
1582 $user_does_not_exists = (bool) ! PMA_DBI_fetch_value($sql);
1583 unset($sql);
1584 if ($user_does_not_exists) {
1585 PMA_Message::warning('strUserNotFound')->display();
1586 PMA_displayLoginInformationFields();
1587 //require_once './libraries/footer.inc.php';
1590 echo '<form name="usersForm" id="usersForm" action="server_privileges.php" method="post">' . "\n";
1591 $_params = array(
1592 'username' => $username,
1593 'hostname' => $hostname,
1595 if (isset($dbname)) {
1596 $_params['dbname'] = $dbname;
1597 if (isset($tablename)) {
1598 $_params['tablename'] = $tablename;
1601 echo PMA_generate_common_hidden_inputs($_params);
1603 PMA_displayPrivTable(PMA_ifSetOr($dbname, '*', 'length'),
1604 PMA_ifSetOr($tablename, '*', 'length'));
1606 echo '</form>' . "\n";
1608 if (! isset($tablename) && empty($dbname_is_wildcard)) {
1610 // no table name was given, display all table specific rights
1611 // but only if $dbname contains no wildcards
1613 // table header
1614 echo '<form action="server_privileges.php" method="post">' . "\n"
1615 . PMA_generate_common_hidden_inputs('', '')
1616 . '<input type="hidden" name="username" value="' . htmlspecialchars($username) . '" />' . "\n"
1617 . '<input type="hidden" name="hostname" value="' . htmlspecialchars($hostname) . '" />' . "\n"
1618 . '<fieldset>' . "\n"
1619 . '<legend>' . (! isset($dbname) ? $GLOBALS['strDbPrivileges'] : $GLOBALS['strTblPrivileges']) . '</legend>' . "\n"
1620 . '<table class="data">' . "\n"
1621 . '<thead>' . "\n"
1622 . '<tr><th>' . (! isset($dbname) ? $GLOBALS['strDatabase'] : $GLOBALS['strTable']) . '</th>' . "\n"
1623 . ' <th>' . $GLOBALS['strPrivileges'] . '</th>' . "\n"
1624 . ' <th>' . $GLOBALS['strGrantOption'] . '</th>' . "\n"
1625 . ' <th>' . (! isset($dbname) ? $GLOBALS['strTblPrivileges'] : $GLOBALS['strColumnPrivileges']) . '</th>' . "\n"
1626 . ' <th colspan="2">' . $GLOBALS['strAction'] . '</th>' . "\n"
1627 . '</tr>' . "\n"
1628 . '</thead>' . "\n"
1629 . '<tbody>' . "\n";
1631 $user_host_condition =
1632 ' WHERE `User`'
1633 . ' = \'' . PMA_sqlAddslashes($username) . "'"
1634 . ' AND `Host`'
1635 . ' = \'' . PMA_sqlAddslashes($hostname) . "'";
1637 // table body
1638 // get data
1640 // we also want privielgs for this user not in table `db` but in other table
1641 $tables = PMA_DBI_fetch_result('SHOW TABLES FROM `mysql`;');
1642 if (! isset($dbname)) {
1644 // no db name given, so we want all privs for the given user
1646 $tables_to_search_for_users = array(
1647 'tables_priv', 'columns_priv',
1650 $db_rights_sqls = array();
1651 foreach ($tables_to_search_for_users as $table_search_in) {
1652 if (in_array($table_search_in, $tables)) {
1653 $db_rights_sqls[] = '
1654 SELECT DISTINCT `Db`
1655 FROM `mysql`.`' . $table_search_in . '`
1656 ' . $user_host_condition;
1660 $user_defaults = array(
1661 'Db' => '',
1662 'Grant_priv' => 'N',
1663 'privs' => array('USAGE'),
1664 'Table_privs' => true,
1667 // for the rights
1668 $db_rights = array();
1670 $db_rights_sql = '(' . implode(') UNION (', $db_rights_sqls) . ')'
1671 .' ORDER BY `Db` ASC';
1673 $db_rights_result = PMA_DBI_query($db_rights_sql);
1675 while ($db_rights_row = PMA_DBI_fetch_assoc($db_rights_result)) {
1676 $db_rights_row = array_merge($user_defaults, $db_rights_row);
1677 // only Db names in the table `mysql`.`db` uses wildcards
1678 // as we are in the db specific rights display we want
1679 // all db names escaped, also from other sources
1680 $db_rights_row['Db'] = PMA_escape_mysql_wildcards(
1681 $db_rights_row['Db']);
1682 $db_rights[$db_rights_row['Db']] = $db_rights_row;
1685 PMA_DBI_free_result($db_rights_result);
1686 unset($db_rights_sql, $db_rights_sqls, $db_rights_result, $db_rights_row);
1688 $sql_query = 'SELECT * FROM `mysql`.`db`' . $user_host_condition . ' ORDER BY `Db` ASC';
1689 $res = PMA_DBI_query($sql_query);
1690 $sql_query = '';
1692 while ($row = PMA_DBI_fetch_assoc($res)) {
1693 if (isset($db_rights[$row['Db']])) {
1694 $db_rights[$row['Db']] = array_merge($db_rights[$row['Db']], $row);
1695 } else {
1696 $db_rights[$row['Db']] = $row;
1698 // there are db specific rights for this user
1699 // so we can drop this db rights
1700 $db_rights[$row['Db']]['can_delete'] = true;
1702 PMA_DBI_free_result($res);
1703 unset($row, $res);
1705 } else {
1707 // db name was given,
1708 // so we want all user specific rights for this db
1710 $user_host_condition .=
1711 ' AND `Db`'
1712 .' LIKE \'' . $dbname . "'";
1714 $tables_to_search_for_users = array(
1715 'columns_priv',
1718 $db_rights_sqls = array();
1719 foreach ($tables_to_search_for_users as $table_search_in) {
1720 if (in_array($table_search_in, $tables)) {
1721 $db_rights_sqls[] = '
1722 SELECT DISTINCT `Table_name`
1723 FROM `mysql`.`' . $table_search_in . '`
1724 ' . $user_host_condition;
1728 $user_defaults = array(
1729 'Table_name' => '',
1730 'Grant_priv' => 'N',
1731 'privs' => array('USAGE'),
1732 'Column_priv' => true,
1735 // for the rights
1736 $db_rights = array();
1738 $db_rights_sql = '(' . implode(') UNION (', $db_rights_sqls) . ')'
1739 .' ORDER BY `Table_name` ASC';
1741 $db_rights_result = PMA_DBI_query($db_rights_sql);
1743 while ($db_rights_row = PMA_DBI_fetch_assoc($db_rights_result)) {
1744 $db_rights_row = array_merge($user_defaults, $db_rights_row);
1745 $db_rights[$db_rights_row['Table_name']] = $db_rights_row;
1747 PMA_DBI_free_result($db_rights_result);
1748 unset($db_rights_sql, $db_rights_sqls, $db_rights_result, $db_rights_row);
1750 $sql_query =
1751 'SELECT `Table_name`,'
1752 .' `Table_priv`,'
1753 .' IF(`Column_priv` = _latin1 \'\', 0, 1)'
1754 .' AS \'Column_priv\''
1755 .' FROM `mysql`.`tables_priv`'
1756 . $user_host_condition
1757 .' ORDER BY `Table_name` ASC;';
1758 $res = PMA_DBI_query($sql_query);
1759 $sql_query = '';
1761 while ($row = PMA_DBI_fetch_assoc($res)) {
1762 if (isset($db_rights[$row['Table_name']])) {
1763 $db_rights[$row['Table_name']] = array_merge($db_rights[$row['Table_name']], $row);
1764 } else {
1765 $db_rights[$row['Table_name']] = $row;
1768 PMA_DBI_free_result($res);
1769 unset($row, $res);
1771 ksort($db_rights);
1773 // display rows
1774 if (count($db_rights) < 1) {
1775 echo '<tr class="odd">' . "\n"
1776 . ' <td colspan="6"><center><i>' . $GLOBALS['strNone'] . '</i></center></td>' . "\n"
1777 . '</tr>' . "\n";
1778 } else {
1779 $odd_row = true;
1780 $found_rows = array();
1781 //while ($row = PMA_DBI_fetch_assoc($res)) {
1782 foreach ($db_rights as $row) {
1783 $found_rows[] = (! isset($dbname)) ? $row['Db'] : $row['Table_name'];
1785 echo '<tr class="' . ($odd_row ? 'odd' : 'even') . '">' . "\n"
1786 . ' <td>' . htmlspecialchars((! isset($dbname)) ? $row['Db'] : $row['Table_name']) . '</td>' . "\n"
1787 . ' <td><tt>' . "\n"
1788 . ' ' . join(',' . "\n" . ' ', PMA_extractPrivInfo($row, TRUE)) . "\n"
1789 . ' </tt></td>' . "\n"
1790 . ' <td>' . ((((! isset($dbname)) && $row['Grant_priv'] == 'Y') || (isset($dbname) && in_array('Grant', explode(',', $row['Table_priv'])))) ? $GLOBALS['strYes'] : $GLOBALS['strNo']) . '</td>' . "\n"
1791 . ' <td>';
1792 if (! empty($row['Table_privs']) || ! empty ($row['Column_priv'])) {
1793 echo $GLOBALS['strYes'];
1794 } else {
1795 echo $GLOBALS['strNo'];
1797 echo '</td>' . "\n"
1798 . ' <td>';
1799 printf($link_edit, urlencode($username),
1800 urlencode($hostname),
1801 urlencode((! isset($dbname)) ? $row['Db'] : $dbname),
1802 urlencode((! isset($dbname)) ? '' : $row['Table_name']));
1803 echo '</td>' . "\n"
1804 . ' <td>';
1805 if (! empty($row['can_delete']) || isset($row['Table_name']) && strlen($row['Table_name'])) {
1806 printf($link_revoke, urlencode($username),
1807 urlencode($hostname),
1808 urlencode((! isset($dbname)) ? $row['Db'] : $dbname),
1809 urlencode((! isset($dbname)) ? '' : $row['Table_name']));
1811 echo '</td>' . "\n"
1812 . '</tr>' . "\n";
1813 $odd_row = ! $odd_row;
1814 } // end while
1816 unset($row);
1817 echo '</tbody>' . "\n"
1818 . '</table>' . "\n";
1820 if (! isset($dbname)) {
1822 // no database name was give, display select db
1824 if (! empty($found_rows)) {
1825 $pred_db_array = array_diff(
1826 PMA_DBI_fetch_result('SHOW DATABASES;'),
1827 $found_rows);
1828 } else {
1829 $pred_db_array =PMA_DBI_fetch_result('SHOW DATABASES;');
1832 echo ' <label for="text_dbname">' . $GLOBALS['strAddPrivilegesOnDb'] . ':</label>' . "\n";
1833 if (!empty($pred_db_array)) {
1834 echo ' <select name="pred_dbname" onchange="this.form.submit();">' . "\n"
1835 . ' <option value="" selected="selected">' . $GLOBALS['strUseTextField'] . ':</option>' . "\n";
1836 foreach ($pred_db_array as $current_db) {
1837 $current_db = PMA_escape_mysql_wildcards($current_db);
1838 echo ' <option value="' . htmlspecialchars($current_db) . '">'
1839 . htmlspecialchars($current_db) . '</option>' . "\n";
1841 echo ' </select>' . "\n";
1843 echo ' <input type="text" id="text_dbname" name="dbname" />' . "\n"
1844 . PMA_showHint($GLOBALS['strEscapeWildcards']);
1845 } else {
1846 echo ' <input type="hidden" name="dbname" value="' . htmlspecialchars($dbname) . '"/>' . "\n"
1847 . ' <label for="text_tablename">' . $GLOBALS['strAddPrivilegesOnTbl'] . ':</label>' . "\n";
1848 if ($res = @PMA_DBI_try_query('SHOW TABLES FROM ' . PMA_backquote($dbname) . ';', null, PMA_DBI_QUERY_STORE)) {
1849 $pred_tbl_array = array();
1850 while ($row = PMA_DBI_fetch_row($res)) {
1851 if (!isset($found_rows) || !in_array($row[0], $found_rows)) {
1852 $pred_tbl_array[] = $row[0];
1855 PMA_DBI_free_result($res);
1856 unset($res, $row);
1857 if (!empty($pred_tbl_array)) {
1858 echo ' <select name="pred_tablename" onchange="this.form.submit();">' . "\n"
1859 . ' <option value="" selected="selected">' . $GLOBALS['strUseTextField'] . ':</option>' . "\n";
1860 foreach ($pred_tbl_array as $current_table) {
1861 echo ' <option value="' . htmlspecialchars($current_table) . '">' . htmlspecialchars($current_table) . '</option>' . "\n";
1863 echo ' </select>' . "\n";
1865 } else {
1866 unset($res);
1868 echo ' <input type="text" id="text_tablename" name="tablename" />' . "\n";
1870 echo '</fieldset>' . "\n";
1871 echo '<fieldset class="tblFooters">' . "\n"
1872 . ' <input type="submit" value="' . $GLOBALS['strGo'] . '" />'
1873 . '</fieldset>' . "\n"
1874 . '</form>' . "\n";
1878 // Provide a line with links to the relevant database and table
1879 if (isset($dbname)) {
1880 echo '[ ' . $GLOBALS['strDatabase']
1881 . ' <a href="' . $GLOBALS['cfg']['DefaultTabDatabase'] . '?'
1882 . $GLOBALS['url_query'] . '&amp;db=' . $url_dbname . '&amp;reload=1">'
1883 . htmlspecialchars($dbname) . ': ' . PMA_getTitleForTarget($GLOBALS['cfg']['DefaultTabDatabase']) . "</a> ]\n";
1885 if (isset($tablename)) {
1886 echo ' [ ' . $GLOBALS['strTable'] . ' <a href="'
1887 . $GLOBALS['cfg']['DefaultTabTable'] . '?' . $GLOBALS['url_query']
1888 . '&amp;db=' . $url_dbname . '&amp;table=' . urlencode($tablename)
1889 . '&amp;reload=1">' . htmlspecialchars($tablename) . ': '
1890 . PMA_getTitleForTarget($GLOBALS['cfg']['DefaultTabTable'])
1891 . "</a> ]\n";
1893 unset($url_dbname);
1896 if (! isset($dbname) && ! $user_does_not_exists) {
1897 require_once './libraries/display_change_password.lib.php';
1899 echo '<form action="server_privileges.php" method="post" onsubmit="return checkPassword(this);">' . "\n"
1900 . PMA_generate_common_hidden_inputs('', '')
1901 . '<input type="hidden" name="old_username" value="' . htmlspecialchars($username) . '" />' . "\n"
1902 . '<input type="hidden" name="old_hostname" value="' . htmlspecialchars($hostname) . '" />' . "\n"
1903 . '<fieldset id="fieldset_change_copy_user">' . "\n"
1904 . ' <legend>' . $GLOBALS['strChangeCopyUser'] . '</legend>' . "\n";
1905 PMA_displayLoginInformationFields('change');
1906 echo ' <fieldset>' . "\n"
1907 . ' <legend>' . $GLOBALS['strChangeCopyMode'] . '</legend>' . "\n";
1908 $choices = array(
1909 '4' => $GLOBALS['strChangeCopyModeCopy'],
1910 '1' => $GLOBALS['strChangeCopyModeJustDelete'],
1911 '2' => $GLOBALS['strChangeCopyModeRevoke'],
1912 '3' => $GLOBALS['strChangeCopyModeDeleteAndReload']);
1913 PMA_generate_html_radio('mode', $choices, '4', true);
1914 unset($choices);
1916 echo ' </fieldset>' . "\n"
1917 . '</fieldset>' . "\n"
1918 . '<fieldset id="fieldset_change_copy_user_footer" class="tblFooters">' . "\n"
1919 . ' <input type="submit" name="change_copy" value="' . $GLOBALS['strGo'] . '" />' . "\n"
1920 . '</fieldset>' . "\n"
1921 . '</form>' . "\n";
1924 } elseif (isset($_REQUEST['adduser'])) {
1925 // Add a new user
1926 $GLOBALS['url_query'] .= '&amp;adduser=1';
1927 echo '<h2>' . "\n"
1928 . PMA_getIcon('b_usradd.png') . $GLOBALS['strAddUser'] . "\n"
1929 . '</h2>' . "\n"
1930 . '<form name="usersForm" id="usersForm" action="server_privileges.php" method="post" onsubmit="return checkAddUser(this);">' . "\n"
1931 . PMA_generate_common_hidden_inputs('', '');
1932 PMA_displayLoginInformationFields('new');
1933 echo '<fieldset id="fieldset_add_user_database">' . "\n"
1934 . '<legend>' . $GLOBALS['strCreateUserDatabase'] . '</legend>' . "\n";
1936 $choices = array(
1937 '0' => $GLOBALS['strCreateUserDatabaseNone'],
1938 '1' => $GLOBALS['strCreateUserDatabaseName'],
1939 '2' => $GLOBALS['strCreateUserDatabaseWildcard']);
1940 PMA_generate_html_radio('createdb', $choices, '0', true);
1941 unset($choices);
1943 echo '</fieldset>' . "\n";
1944 PMA_displayPrivTable('*', '*', FALSE);
1945 echo ' <fieldset id="fieldset_add_user_footer" class="tblFooters">' . "\n"
1946 . ' <input type="submit" name="adduser_submit" value="' . $GLOBALS['strGo'] . '" />' . "\n"
1947 . ' </fieldset>' . "\n"
1948 . '</form>' . "\n";
1949 } else {
1950 // check the privileges for a particular database.
1951 echo '<table id="tablespecificuserrights" class="data">' . "\n"
1952 . '<caption class="tblHeaders">' . "\n"
1953 . PMA_getIcon('b_usrcheck.png')
1954 . ' ' . sprintf($GLOBALS['strUsersHavingAccessToDb'], '<a href="' . $GLOBALS['cfg']['DefaultTabDatabase'] . '?' . PMA_generate_common_url($checkprivs) . '">' . htmlspecialchars($checkprivs) . '</a>') . "\n"
1955 . '</caption>' . "\n"
1956 . '<thead>' . "\n"
1957 . ' <tr><th>' . $GLOBALS['strUser'] . '</th>' . "\n"
1958 . ' <th>' . $GLOBALS['strHost'] . '</th>' . "\n"
1959 . ' <th>' . $GLOBALS['strType'] . '</th>' . "\n"
1960 . ' <th>' . $GLOBALS['strPrivileges'] . '</th>' . "\n"
1961 . ' <th>' . $GLOBALS['strGrantOption'] . '</th>' . "\n"
1962 . ' <th>' . $GLOBALS['strAction'] . '</th>' . "\n"
1963 . ' </tr>' . "\n"
1964 . '</thead>' . "\n"
1965 . '<tbody>' . "\n";
1966 $odd_row = TRUE;
1967 unset($row, $row1, $row2);
1969 // now, we build the table...
1970 $list_of_privileges =
1971 '`User`, '
1972 . '`Host`, '
1973 . '`Select_priv`, '
1974 . '`Insert_priv`, '
1975 . '`Update_priv`, '
1976 . '`Delete_priv`, '
1977 . '`Create_priv`, '
1978 . '`Drop_priv`, '
1979 . '`Grant_priv`, '
1980 . '`Index_priv`, '
1981 . '`Alter_priv`, '
1982 . '`References_priv`, '
1983 . '`Create_tmp_table_priv`, '
1984 . '`Lock_tables_priv`, '
1985 . '`Create_view_priv`, '
1986 . '`Show_view_priv`, '
1987 . '`Create_routine_priv`, '
1988 . '`Alter_routine_priv`, '
1989 . '`Execute_priv`';
1991 $list_of_compared_privileges =
1992 '`Select_priv` = \'N\''
1993 . ' AND `Insert_priv` = \'N\''
1994 . ' AND `Update_priv` = \'N\''
1995 . ' AND `Delete_priv` = \'N\''
1996 . ' AND `Create_priv` = \'N\''
1997 . ' AND `Drop_priv` = \'N\''
1998 . ' AND `Grant_priv` = \'N\''
1999 . ' AND `References_priv` = \'N\''
2000 . ' AND `Create_tmp_table_priv` = \'N\''
2001 . ' AND `Lock_tables_priv` = \'N\''
2002 . ' AND `Create_view_priv` = \'N\''
2003 . ' AND `Show_view_priv` = \'N\''
2004 . ' AND `Create_routine_priv` = \'N\''
2005 . ' AND `Alter_routine_priv` = \'N\''
2006 . ' AND `Execute_priv` = \'N\'';
2008 if (PMA_MYSQL_INT_VERSION >= 50106) {
2009 $list_of_privileges .=
2010 ', `Event_priv`, '
2011 . '`Trigger_priv`';
2012 $list_of_compared_privileges .=
2013 ' AND `Event_priv` = \'N\''
2014 . ' AND `Trigger_priv` = \'N\'';
2017 $sql_query =
2018 '(SELECT ' . $list_of_privileges . ', `Db`'
2019 .' FROM `mysql`.`db`'
2020 .' WHERE \'' . PMA_sqlAddslashes($checkprivs) . "'"
2021 .' LIKE `Db`'
2022 .' AND NOT (' . $list_of_compared_privileges. ')) '
2023 .'UNION '
2024 .'(SELECT ' . $list_of_privileges . ', \'*\' AS `Db`'
2025 .' FROM `mysql`.`user` '
2026 .' WHERE NOT (' . $list_of_compared_privileges . ')) '
2027 .' ORDER BY `User` ASC,'
2028 .' `Host` ASC,'
2029 .' `Db` ASC;';
2030 $res = PMA_DBI_query($sql_query);
2031 $row = PMA_DBI_fetch_assoc($res);
2032 if ($row) {
2033 $found = TRUE;
2036 if ($found) {
2037 while (TRUE) {
2038 // prepare the current user
2039 $current_privileges = array();
2040 $current_user = $row['User'];
2041 $current_host = $row['Host'];
2042 while ($row && $current_user == $row['User'] && $current_host == $row['Host']) {
2043 $current_privileges[] = $row;
2044 $row = PMA_DBI_fetch_assoc($res);
2046 echo ' <tr class="' . ($odd_row ? 'odd' : 'even') . '">' . "\n"
2047 . ' <td';
2048 if (count($current_privileges) > 1) {
2049 echo ' rowspan="' . count($current_privileges) . '"';
2051 echo '>' . (empty($current_user) ? '<span style="color: #FF0000">' . $GLOBALS['strAny'] . '</span>' : htmlspecialchars($current_user)) . "\n"
2052 . ' </td>' . "\n"
2053 . ' <td';
2054 if (count($current_privileges) > 1) {
2055 echo ' rowspan="' . count($current_privileges) . '"';
2057 echo '>' . htmlspecialchars($current_host) . '</td>' . "\n";
2058 foreach ($current_privileges as $current) {
2059 echo ' <td>' . "\n"
2060 . ' ';
2061 if (!isset($current['Db']) || $current['Db'] == '*') {
2062 echo $GLOBALS['strGlobal'];
2063 } elseif ($current['Db'] == PMA_escape_mysql_wildcards($checkprivs)) {
2064 echo $GLOBALS['strDbSpecific'];
2065 } else {
2066 echo $GLOBALS['strWildcard'], ': <tt>' . htmlspecialchars($current['Db']) . '</tt>';
2068 echo "\n"
2069 . ' </td>' . "\n"
2070 . ' <td>' . "\n"
2071 . ' <tt>' . "\n"
2072 . ' ' . join(',' . "\n" . ' ', PMA_extractPrivInfo($current, TRUE)) . "\n"
2073 . ' </tt>' . "\n"
2074 . ' </td>' . "\n"
2075 . ' <td>' . "\n"
2076 . ' ' . ($current['Grant_priv'] == 'Y' ? $GLOBALS['strYes'] : $GLOBALS['strNo']) . "\n"
2077 . ' </td>' . "\n"
2078 . ' <td>' . "\n";
2079 printf($link_edit, urlencode($current_user),
2080 urlencode($current_host),
2081 urlencode(! isset($current['Db']) || $current['Db'] == '*' ? '' : $current['Db']),
2082 '');
2083 echo '</td>' . "\n"
2084 . ' </tr>' . "\n";
2086 if (empty($row) && empty($row1) && empty($row2)) {
2087 break;
2089 $odd_row = ! $odd_row;
2091 } else {
2092 echo ' <tr class="odd">' . "\n"
2093 . ' <td colspan="6">' . "\n"
2094 . ' ' . $GLOBALS['strNoUsersFound'] . "\n"
2095 . ' </td>' . "\n"
2096 . ' </tr>' . "\n";
2098 echo '</tbody>' . "\n"
2099 . '</table>' . "\n";
2100 } // end if (empty($_REQUEST['adduser']) && empty($checkprivs)) ... elseif ... else ...
2104 * Displays the footer
2106 echo "\n\n";
2107 require_once './libraries/footer.inc.php';