Skip to content

Commit

Permalink
Fix phpmyadmin#4205 Add user shows "edit user group" link
Browse files Browse the repository at this point in the history
Signed-off-by: J.M <[email protected]>
  • Loading branch information
mynetx committed Dec 27, 2013
2 parents 9951278 + 02ced82 commit 480f663
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 16 deletions.
1 change: 1 addition & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ phpMyAdmin - ChangeLog
- bug #4200 Missing syntax highlighting
- bug #4201 Exports are not compressed
- bug #4131 Import: "number of rows to skip" is ambiguous
- bug #4205 Add a user shows additional "edit user group" link

4.1.2.0 (2013-12-23)
- bug #4178 Quick edit for BIT type does not work
Expand Down
54 changes: 38 additions & 16 deletions libraries/server_privileges.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -2276,6 +2276,23 @@ function PMA_getUserGroupEditLink($username)
. '</a>';
}

/**
* Returns number of defined user groups
*
* @return integer $user_group_count
*/
function PMA_getUserGroupCount()
{
$user_group_table = PMA_Util::backquote($GLOBALS['cfg']['Server']['pmadb'])
. '.' . PMA_Util::backquote($GLOBALS['cfg']['Server']['usergroups']);
$sql_query = 'SELECT COUNT(*) FROM ' . $user_group_table;
$user_group_count = $GLOBALS['dbi']->fetchValue(
$sql_query, 0, 0, $GLOBALS['controllink']
);

return $user_group_count;
}

/**
* This function return the extra data array for the ajax behavior
*
Expand All @@ -2298,6 +2315,11 @@ function PMA_getExtraDataForAjaxBehavior(
}
}

$user_group_count = 0;
if ($GLOBALS['cfgRelation']['menuswork']) {
$user_group_count = PMA_getUserGroupCount();
}

$extra_data = array();
if (strlen($sql_query)) {
$extra_data['sql_query']
Expand Down Expand Up @@ -2357,7 +2379,7 @@ function PMA_getExtraDataForAjaxBehavior(
. PMA_getUserEditLink($username, $hostname)
. '</td>' . "\n";

if (isset($cfgRelation['users']) && isset($cfgRelation['usergroups'])) {
if (isset($cfgRelation['menuswork']) && $user_group_count > 0) {
$new_user_string .= '<td>'
. PMA_getUserGroupEditLink($username)
. '</td>' . "\n";
Expand Down Expand Up @@ -2889,6 +2911,10 @@ function PMA_getUsersOverview($result, $db_rights, $pmaThemeImage, $text_dir)
$db_rights[$row['User']][$row['Host']] = $row;
}
@$GLOBALS['dbi']->freeResult($result);
$user_group_count = 0;
if ($GLOBALS['cfgRelation']['menuswork']) {
$user_group_count = PMA_getUserGroupCount();
}

$html_output
= '<form name="usersForm" id="usersForm" action="server_privileges.php" '
Expand All @@ -2909,7 +2935,8 @@ function PMA_getUsersOverview($result, $db_rights, $pmaThemeImage, $text_dir)
$html_output .= '<th>' . __('User group') . '</th>' . "\n";
}
$html_output .= '<th>' . __('Grant') . '</th>' . "\n"
. '<th colspan="3">' . __('Action') . '</th>' . "\n"
. '<th colspan="' . ($user_group_count > 0 ? '3' : '2') . '">'
. __('Action') . '</th>' . "\n"
. '</tr>' . "\n"
. '</thead>' . "\n";

Expand Down Expand Up @@ -2954,24 +2981,19 @@ function PMA_getUsersOverview($result, $db_rights, $pmaThemeImage, $text_dir)
function PMA_getTableBodyForUserRightsTable($db_rights)
{
if ($GLOBALS['cfgRelation']['menuswork']) {
$usersTable = PMA_Util::backquote($GLOBALS['cfg']['Server']['pmadb'])
$users_table = PMA_Util::backquote($GLOBALS['cfg']['Server']['pmadb'])
. "." . PMA_Util::backquote($GLOBALS['cfg']['Server']['users']);
$sqlQuery = "SELECT * FROM " . $usersTable;
$result = PMA_queryAsControlUser($sqlQuery, false);
$groupAssignment = array();
$sql_query = 'SELECT * FROM ' . $users_table;
$result = PMA_queryAsControlUser($sql_query, false);
$group_assignment = array();
if ($result) {
while ($row = $GLOBALS['dbi']->fetchAssoc($result)) {
$groupAssignment[$row['username']] = $row['usergroup'];
$group_assignment[$row['username']] = $row['usergroup'];
}
}
$GLOBALS['dbi']->freeResult($result);

$userGroupTable = PMA_Util::backquote($GLOBALS['cfg']['Server']['pmadb'])
. "." . PMA_Util::backquote($GLOBALS['cfg']['Server']['usergroups']);
$sqlQuery = "SELECT COUNT(*) FROM " . $userGroupTable;
$userGroupCount = $GLOBALS['dbi']->fetchValue(
$sqlQuery, 0, 0, $GLOBALS['controllink']
);
$user_group_count = PMA_getUserGroupCount();
}

$odd_row = true;
Expand Down Expand Up @@ -3019,8 +3041,8 @@ function PMA_getTableBodyForUserRightsTable($db_rights)
. '</code></td>' . "\n";
if ($GLOBALS['cfgRelation']['menuswork']) {
$html_output .= '<td class="usrGroup">' . "\n"
. (isset($groupAssignment[$host['User']])
? $groupAssignment[$host['User']]
. (isset($group_assignment[$host['User']])
? $group_assignment[$host['User']]
: ''
)
. '</td>' . "\n";
Expand All @@ -3035,7 +3057,7 @@ function PMA_getTableBodyForUserRightsTable($db_rights)
$host['Host']
)
. '</td>';
if ($GLOBALS['cfgRelation']['menuswork'] && $userGroupCount > 0) {
if ($GLOBALS['cfgRelation']['menuswork'] && $user_group_count > 0) {
if (empty($host['User'])) {
$html_output .= '<td class="center"></td>';
} else {
Expand Down

0 comments on commit 480f663

Please sign in to comment.