diff --git a/libraries/classes/Server/Privileges.php b/libraries/classes/Server/Privileges.php index d0a9a4f756..f447cbc371 100644 --- a/libraries/classes/Server/Privileges.php +++ b/libraries/classes/Server/Privileges.php @@ -1501,60 +1501,19 @@ class Privileges * * @return string */ - public function getHtmlForSpecificDbPrivileges($db) + public function getHtmlForSpecificDbPrivileges(string $db): string { - $html_output = ''; + global $cfg, $pmaThemeImage, $text_dir, $is_createuser; + $scriptName = Util::getScriptNameForOption( + $cfg['DefaultTabDatabase'], + 'database' + ); + + $tableBody = ''; if ($this->dbi->isSuperuser()) { - // check the privileges for a particular database. - $html_output = '
'; - $html_output .= Url::getHiddenInputs($db); - $html_output .= '
'; - $html_output .= '
'; - $scriptName = Util::getScriptNameForOption( - $GLOBALS['cfg']['DefaultTabDatabase'], - 'database' - ); - $html_output .= '' . "\n" - . Util::getIcon('b_usrcheck') - . ' ' - . sprintf( - __('Users having access to "%s"'), - '' - . htmlspecialchars($db) - . '' - ) - . "\n" - . '' . "\n"; - - $html_output .= '
'; - $html_output .= ''; - $html_output .= $this->getHtmlForPrivsTableHead(); $privMap = $this->getPrivMap($db); - $html_output .= $this->getHtmlTableBodyForSpecificDbOrTablePrivs($privMap, $db); - $html_output .= '
'; - $html_output .= '
'; - - $html_output .= '
'; - $html_output .= $this->template->render('select_all', [ - 'pma_theme_image' => $GLOBALS['pmaThemeImage'], - 'text_dir' => $GLOBALS['text_dir'], - 'form_name' => "usersForm", - ]); - $html_output .= Util::getButtonOrImage( - 'submit_mult', - 'mult_submit', - __('Export'), - 'b_tblexport', - 'export' - ); - - $html_output .= '
'; - $html_output .= '
'; - $html_output .= '
'; - } else { - $html_output .= $this->getHtmlForViewUsersError(); + $tableBody = $this->getHtmlTableBodyForSpecificDbOrTablePrivs($privMap, $db); } $response = Response::getInstance(); @@ -1563,13 +1522,18 @@ class Privileges ) { $message = Message::success(__('User has been added.')); $response->addJSON('message', $message); - $response->addJSON('user_form', $html_output); exit; - } else { - // Offer to create a new user for the current database - $html_output .= $this->getAddUserHtmlFieldset($db); } - return $html_output; + + return $this->template->render('server/privileges/database', [ + 'is_superuser' => $this->dbi->isSuperuser(), + 'db' => $db, + 'database_url' => $scriptName, + 'pma_theme_image' => $pmaThemeImage, + 'text_dir' => $text_dir, + 'table_body' => $tableBody, + 'is_createuser' => $is_createuser, + ]); } /** diff --git a/templates/server/privileges/database.twig b/templates/server/privileges/database.twig new file mode 100644 index 0000000000..aed0e808cd --- /dev/null +++ b/templates/server/privileges/database.twig @@ -0,0 +1,59 @@ +{% if is_superuser %} +
+ {{ get_hidden_inputs(db) }} + +
+
+ + {{ get_icon('b_usrcheck') }} + {{ 'Users having access to "%s"'|trans|format('' ~ db ~ '')|raw }} + + +
+ + + + + + + + + + + + + + {{ table_body|raw }} +
{% trans 'User name' %}{% trans 'Host name' %}{% trans 'Type' %}{% trans 'Privileges' %}{% trans 'Grant' %}{% trans 'Action' %}
+
+ +
+ 
+            {%- trans 'With selected:' %} + + + {% trans 'With selected:' %} + {{ get_button_or_image('submit_mult', 'mult_submit', 'Export'|trans, 'b_tblexport', 'export') }} +
+
+
+
+{% else %} + {{ 'Not enough privilege to view users.'|trans|error }} +{% endif %} + +{% if is_createuser %} +
+
+
+ {% trans %}New{% context %}Create new user{% endtrans %} + + {{ get_icon('b_usradd', 'Add user account'|trans) }} + +
+
+
+{% endif %}