diff --git a/libraries/classes/Server/Privileges.php b/libraries/classes/Server/Privileges.php index f447cbc371..d4a26c81df 100644 --- a/libraries/classes/Server/Privileges.php +++ b/libraries/classes/Server/Privileges.php @@ -1544,35 +1544,17 @@ class Privileges * * @return string */ - public function getHtmlForSpecificTablePrivileges($db, $table) + public function getHtmlForSpecificTablePrivileges(string $db, string $table): string { - $html_output = ''; - if ($this->dbi->isSuperuser()) { - // check the privileges for a particular table. - $html_output = '
'; - $html_output .= Url::getHiddenInputs($db, $table); - $html_output .= '
'; - $scriptName = Util::getScriptNameForOption( - $GLOBALS['cfg']['DefaultTabTable'], - 'table' - ); - $html_output .= '' - . Util::getIcon('b_usrcheck') - . sprintf( - __('Users having access to "%s"'), - '' - . htmlspecialchars($db) . '.' . htmlspecialchars($table) - . '' - ) - . ''; + global $cfg, $pmaThemeImage, $text_dir, $is_createuser; - $html_output .= '
'; - $html_output .= ''; - $html_output .= $this->getHtmlForPrivsTableHead(); + $scriptName = Util::getScriptNameForOption( + $cfg['DefaultTabTable'], + 'table' + ); + + $tableBody = ''; + if ($this->dbi->isSuperuser()) { $privMap = $this->getPrivMap($db); $sql_query = "SELECT `User`, `Host`, `Db`," . " 't' AS `Type`, `Table_name`, `Table_priv`" @@ -1583,31 +1565,20 @@ class Privileges . " ORDER BY `User` ASC, `Host` ASC, `Db` ASC, `Table_priv` ASC;"; $res = $this->dbi->query($sql_query); $this->mergePrivMapFromResult($privMap, $res); - $html_output .= $this->getHtmlTableBodyForSpecificDbOrTablePrivs($privMap, $db); - $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 .= '
'; - } else { - $html_output .= $this->getHtmlForViewUsersError(); + $tableBody = $this->getHtmlTableBodyForSpecificDbOrTablePrivs($privMap, $db); } - // Offer to create a new user for the current database - $html_output .= $this->getAddUserHtmlFieldset($db, $table); - return $html_output; + + return $this->template->render('server/privileges/table', [ + 'db' => $db, + 'table' => $table, + 'is_superuser' => $this->dbi->isSuperuser(), + 'table_url' => $scriptName, + 'pma_theme_image' => $pmaThemeImage, + 'text_dir' => $text_dir, + 'table_body' => $tableBody, + 'is_createuser' => $is_createuser, + ]); } /** @@ -1664,26 +1635,6 @@ class Privileges } } - /** - * Get HTML snippet for privileges table head - * - * @return string - */ - public function getHtmlForPrivsTableHead() - { - return '' - . '' - . '' - . '' . __('User name') . '' - . '' . __('Host name') . '' - . '' . __('Type') . '' - . '' . __('Privileges') . '' - . '' . __('Grant') . '' - . '' . __('Action') . '' - . '' - . ''; - } - /** * Get HTML error for View Users form * For non superusers such as grant/create users diff --git a/templates/server/privileges/table.twig b/templates/server/privileges/table.twig new file mode 100644 index 0000000000..4c328cff3c --- /dev/null +++ b/templates/server/privileges/table.twig @@ -0,0 +1,61 @@ +{% if is_superuser %} +
+ {{ get_hidden_inputs(db, table) }} + +
+ + {{ get_icon('b_usrcheck') }} + {{ 'Users having access to "%s"'|trans|format('' ~ db ~ '.' ~ table ~ '')|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 %}