Added column privileges editor.

This commit is contained in:
Alexander M. Turek
2003-01-19 23:33:25 +00:00
parent a5c02eb41f
commit b15ac69d4f
2 changed files with 224 additions and 96 deletions

View File

@@ -5,6 +5,10 @@ phpMyAdmin - Changelog
$Id$ $Id$
$Source$ $Source$
2003-01-19 Alexander M. Turek <rabus@users.sourceforge.net>
* server_privileges.php3: Added column privileges editor.
TODO: Deselection of all columns is not possible yet...
2003-01-19 Marc Delisle <lem9@users.sourceforge.net> 2003-01-19 Marc Delisle <lem9@users.sourceforge.net>
* sql.php3, tbl_properties_export.php3, tbl_dump.php3, * sql.php3, tbl_properties_export.php3, tbl_dump.php3,
tbl_move_copy.php3, libraries/build_dump.lib.php3: tbl_move_copy.php3, libraries/build_dump.lib.php3:

View File

@@ -93,12 +93,19 @@ function PMA_extractPrivInfo($row = '', $enableHTML = FALSE)
$allPrivileges = TRUE; $allPrivileges = TRUE;
while (list(, $current_grant) = each($grants)) { while (list(, $current_grant) = each($grants)) {
if ((!empty($row) && isset($row[$current_grant[0]])) || (empty($row) && isset($GLOBALS[$current_grant[0]]))) { if ((!empty($row) && isset($row[$current_grant[0]])) || (empty($row) && isset($GLOBALS[$current_grant[0]]))) {
if ((!empty($row) && $row[$current_grant[0]] == 'Y') || (empty($row) && $GLOBALS[$current_grant[0]] == 'Y')) { if ((!empty($row) && $row[$current_grant[0]] == 'Y') || (empty($row) && ($GLOBALS[$current_grant[0]] == 'Y' || (is_array($GLOBALS[$current_grant[0]]) && count($GLOBALS[$current_grant[0]]) == $GLOBALS['column_count'])))) {
if ($enableHTML) { if ($enableHTML) {
$privs[] = '<dfn title="' . $current_grant[2] . '">' . str_replace(' ', '&nbsp;', $current_grant[1]) . '</dfn>'; $privs[] = '<dfn title="' . $current_grant[2] . '">' . str_replace(' ', '&nbsp;', $current_grant[1]) . '</dfn>';
} else { } else {
$privs[] = $current_grant[1]; $privs[] = $current_grant[1];
} }
} else if (!empty($GLOBALS[$current_grant[0]]) && is_array($GLOBALS[$current_grant[0]]) && empty($GLOBALS[$current_grant[0] . '_none'])) {
if ($enableHTML) {
$priv_string = '<dfn title="' . $current_grant[2] . '">' . str_replace(' ', '&nbsp;', $current_grant[1]) . '</dfn>';
} else {
$priv_string = $current_grant[1];
}
$privs[] = $priv_string . ' (' . join(', ', $GLOBALS[$current_grant[0]]) . ')';
} else { } else {
$allPrivileges = FALSE; $allPrivileges = FALSE;
} }
@@ -197,10 +204,126 @@ function PMA_displayPrivTable($db = '*', $table = '*', $submit = TRUE, $indent =
while (list(, $current_grant) = each($av_grants)) { while (list(, $current_grant) = each($av_grants)) {
$row[$current_grant . '_priv'] = in_array($current_grant, $users_grants) ? 'Y' : 'N'; $row[$current_grant . '_priv'] = in_array($current_grant, $users_grants) ? 'Y' : 'N';
} }
unset($row['Table_priv']);
unset($current_grant); unset($current_grant);
unset($av_grants); unset($av_grants);
unset($users_grants); unset($users_grants);
if ($res = PMA_mysql_query('SHOW COLUMNS FROM `' . $db . '`.`' . $table . '`;', $userlink)) {
$columns = array();
while ($row1 = PMA_mysql_fetch_row($res)) {
$columns[$row1[0]] = array(
'Select' => FALSE,
'Insert' => FALSE,
'Update' => FALSE,
'References' => FALSE
);
} }
mysql_free_result($res);
unset($res);
unset($row1);
}
}
if (!empty($columns)) {
$sql_query = 'SELECT `Column_name`, `Column_priv` FROM `columns_priv` WHERE `User` = "' . $username . '" AND `Host` = "' . $hostname . '" AND `Db` = "' . $db . '" AND `Table_name` = "' . $table . '";';
$res = PMA_mysql_query($sql_query, $userlink) or PMA_mysqlDie(PMA_mysql_error($userlink), $sql_query);
while ($row1 = PMA_mysql_fetch_row($res)) {
$row1[1] = explode(',', $row1[1]);
while (list(, $current) = each($row1[1])) {
$columns[$row1[0]][$current] = TRUE;
}
}
mysql_free_result($res);
unset($res);
unset($row1);
unset($current);
echo $spaces . '<input type="hidden" name="grant_count" value="' . count($row) . '" />' . "\n"
. $spaces . '<input type="hidden" name="column_count" value="' . count($columns) . '" />' . "\n"
. $spaces . '<table border="0">' . "\n"
. $spaces . ' <tr>' . "\n"
. $spaces . ' <th colspan="6">&nbsp;' . $GLOBALS['strTblPrivileges'] . '&nbsp;</th>' . "\n"
. $spaces . ' </tr>' . "\n"
. $spaces . ' <tr>' . "\n"
. $spaces . ' <td bgcolor="' . $cfg['BgcolorTwo'] . '" colspan="6"><small><i>' . $GLOBALS['strEnglishPrivileges'] . '</i></small></td>' . "\n"
. $spaces . ' </tr>' . "\n"
. $spaces . ' <tr>' . "\n"
. $spaces . ' <td bgcolor="' . $cfg['BgcolorOne'] . '">&nbsp;<tt><dfn title="' . $GLOBALS['strPrivDescSelect'] . '">SELECT</dfn></tt>&nbsp;</td>' . "\n"
. $spaces . ' <td bgcolor="' . $cfg['BgcolorOne'] . '">&nbsp;<tt><dfn title="' . $GLOBALS['strPrivDescInsert'] . '">INSERT</dfn></tt>&nbsp;</td>' . "\n"
. $spaces . ' <td bgcolor="' . $cfg['BgcolorOne'] . '">&nbsp;<tt><dfn title="' . $GLOBALS['strPrivDescUpdate'] . '">UPDATE</dfn></tt>&nbsp;</td>' . "\n"
. $spaces . ' <td bgcolor="' . $cfg['BgcolorOne'] . '">&nbsp;<tt><dfn title="' . $GLOBALS['strPrivDescReferences'] . '">REFERENCES</dfn></tt>&nbsp;</td>' . "\n";
list($current_grant, $current_grant_value) = each($row);
while (in_array(substr($current_grant, 0, (strlen($current_grant) - 5)), array('Select', 'Insert', 'Update', 'References'))) {
list($current_grant, $current_grant_value) = each($row);
}
echo $spaces . ' <td bgcolor="' . $cfg['BgcolorTwo'] . '"><input type="checkbox" name="' . $current_grant . '" id="checkbox_' . $current_grant . '" value="Y" ' . ($current_grant_value == 'Y' ? 'checked="checked" ' : '') . 'title="' . (isset($GLOBALS['strPrivDesc' . substr($current_grant, 0, (strlen($current_grant) - 5))]) ? $GLOBALS['strPrivDesc' . substr($current_grant, 0, (strlen($current_grant) - 5))] : $GLOBALS['strPrivDesc' . substr($current_grant, 0, (strlen($current_grant) - 5)) . 'Tbl']) . '"/></td>' . "\n"
. $spaces . ' <td bgcolor="' . $cfg['BgcolorTwo'] . '"><label for="checkbox_' . $current_grant . '"><tt><dfn title="' . (isset($GLOBALS['strPrivDesc' . substr($current_grant, 0, (strlen($current_grant) - 5))]) ? $GLOBALS['strPrivDesc' . substr($current_grant, 0, (strlen($current_grant) - 5))] : $GLOBALS['strPrivDesc' . substr($current_grant, 0, (strlen($current_grant) - 5)) . 'Tbl']) . '">' . strtoupper(substr($current_grant, 0, strlen($current_grant) - 5)) . '</dfn></tt></label></td>' . "\n"
. $spaces . ' </tr>' . "\n"
. $spaces . ' <tr>' . "\n";
$rowspan = count($row) - 5;
echo $spaces . ' <td bgcolor="' . $cfg['BgcolorTwo'] . '" rowspan="' . $rowspan . '" valign="top">' . "\n"
. $spaces . ' <select name="Select_priv[]" multiple="multiple">' . "\n";
while (list($current_column, $current_column_privileges) = each($columns)) {
echo $spaces . ' <option value="' . htmlspecialchars($current_column) . '"';
if ($row['Select_priv'] == 'Y' || $current_column_privileges['Select']) {
echo ' selected="selected"';
}
echo '>' . htmlspecialchars($current_column) . '</option>' . "\n";
}
echo $spaces . ' </select><br />' . "\n"
. $spaces . ' </td>' . "\n"
. $spaces . ' <td bgcolor="' . $cfg['BgcolorTwo'] . '" rowspan="' . $rowspan . '" valign="top">' . "\n"
. $spaces . ' <select name="Insert_priv[]" multiple="multiple">' . "\n";
reset($columns);
while (list($current_column, $current_column_privileges) = each($columns)) {
echo $spaces . ' <option value="' . htmlspecialchars($current_column) . '"';
if ($row['Insert_priv'] == 'Y' || $current_column_privileges['Insert']) {
echo ' selected="selected"';
}
echo '>' . htmlspecialchars($current_column) . '</option>' . "\n";
}
echo $spaces . ' </select>' . "\n"
. $spaces . ' </td>' . "\n"
. $spaces . ' <td bgcolor="' . $cfg['BgcolorTwo'] . '" rowspan="' . $rowspan . '" valign="top">' . "\n"
. $spaces . ' <select name="Update_priv[]" multiple="multiple">' . "\n";
reset($columns);
while (list($current_column, $current_column_privileges) = each($columns)) {
echo $spaces . ' <option value="' . htmlspecialchars($current_column) . '"';
if ($row['Update_priv'] == 'Y' || $current_column_privileges['Update']) {
echo ' selected="selected"';
}
echo '>' . htmlspecialchars($current_column) . '</option>' . "\n";
}
echo $spaces . ' </select>' . "\n"
. $spaces . ' </td>' . "\n"
. $spaces . ' <td bgcolor="' . $cfg['BgcolorTwo'] . '" rowspan="' . $rowspan . '" valign="top">' . "\n"
. $spaces . ' <select name="References_priv[]" multiple="multiple">' . "\n";
reset($columns);
while (list($current_column, $current_column_privileges) = each($columns)) {
echo $spaces . ' <option value="' . htmlspecialchars($current_column) . '"';
if ($row['References_priv'] == 'Y' || $current_column_privileges['References']) {
echo ' selected="selected"';
}
echo '>' . htmlspecialchars($current_column) . '</option>' . "\n";
}
echo $spaces . ' </select>' . "\n"
. $spaces . ' </td>' . "\n";
unset($rowspan);
list($current_grant, $current_grant_value) = each($row);
while (in_array(substr($current_grant, 0, (strlen($current_grant) - 5)), array('Select', 'Insert', 'Update', 'References'))) {
list($current_grant, $current_grant_value) = each($row);
}
echo $spaces . ' <td bgcolor="' . $cfg['BgcolorTwo'] . '"><input type="checkbox" name="' . $current_grant . '" id="checkbox_' . $current_grant . '" value="Y" ' . ($current_grant_value == 'Y' ? 'checked="checked" ' : '') . 'title="' . (isset($GLOBALS['strPrivDesc' . substr($current_grant, 0, (strlen($current_grant) - 5))]) ? $GLOBALS['strPrivDesc' . substr($current_grant, 0, (strlen($current_grant) - 5))] : $GLOBALS['strPrivDesc' . substr($current_grant, 0, (strlen($current_grant) - 5)) . 'Tbl']) . '"/></td>' . "\n"
. $spaces . ' <td bgcolor="' . $cfg['BgcolorTwo'] . '"><label for="checkbox_' . $current_grant . '"><tt><dfn title="' . (isset($GLOBALS['strPrivDesc' . substr($current_grant, 0, (strlen($current_grant) - 5))]) ? $GLOBALS['strPrivDesc' . substr($current_grant, 0, (strlen($current_grant) - 5))] : $GLOBALS['strPrivDesc' . substr($current_grant, 0, (strlen($current_grant) - 5)) . 'Tbl']) . '">' . strtoupper(substr($current_grant, 0, strlen($current_grant) - 5)) . '</dfn></tt></label></td>' . "\n"
. $spaces . ' </tr>' . "\n";
while (list($current_grant, $current_grant_value) = each($row)) {
if (in_array(substr($current_grant, 0, (strlen($current_grant) - 5)), array('Select', 'Insert', 'Update', 'References'))) {
continue;
}
echo $spaces . ' <tr>' . "\n"
. $spaces . ' <td bgcolor="' . $cfg['BgcolorTwo'] . '"><input type="checkbox" name="' . $current_grant . '" id="checkbox_' . $current_grant . '" value="Y" ' . ($current_grant_value == 'Y' ? 'checked="checked" ' : '') . 'title="' . (isset($GLOBALS['strPrivDesc' . substr($current_grant, 0, (strlen($current_grant) - 5))]) ? $GLOBALS['strPrivDesc' . substr($current_grant, 0, (strlen($current_grant) - 5))] : $GLOBALS['strPrivDesc' . substr($current_grant, 0, (strlen($current_grant) - 5)) . 'Tbl']) . '"/></td>' . "\n"
. $spaces . ' <td bgcolor="' . $cfg['BgcolorTwo'] . '"><label for="checkbox_' . $current_grant . '"><tt><dfn title="' . (isset($GLOBALS['strPrivDesc' . substr($current_grant, 0, (strlen($current_grant) - 5))]) ? $GLOBALS['strPrivDesc' . substr($current_grant, 0, (strlen($current_grant) - 5))] : $GLOBALS['strPrivDesc' . substr($current_grant, 0, (strlen($current_grant) - 5)) . 'Tbl']) . '">' . strtoupper(substr($current_grant, 0, strlen($current_grant) - 5)) . '</dfn></tt></label></td>' . "\n"
. $spaces . ' </tr>' . "\n";
}
} else {
$privTable[0] = array( $privTable[0] = array(
array('Select', 'SELECT', $GLOBALS['strPrivDescSelect']), array('Select', 'SELECT', $GLOBALS['strPrivDescSelect']),
array('Insert', 'INSERT', $GLOBALS['strPrivDescInsert']), array('Insert', 'INSERT', $GLOBALS['strPrivDescInsert']),
@@ -301,6 +424,7 @@ function PMA_displayPrivTable($db = '*', $table = '*', $submit = TRUE, $indent =
echo $spaces . ' <td bgcolor="' . $cfg['BgcolorTwo'] . '" colspan="2">&nbsp;</td>' . "\n"; echo $spaces . ' <td bgcolor="' . $cfg['BgcolorTwo'] . '" colspan="2">&nbsp;</td>' . "\n";
} }
} }
}
echo $spaces . ' </tr>' . "\n"; echo $spaces . ' </tr>' . "\n";
} }
if ($submit) { if ($submit) {