UserGroupsController.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. declare(strict_types=1);
  3. namespace PhpMyAdmin\Controllers\Server;
  4. use PhpMyAdmin\Controllers\AbstractController;
  5. use PhpMyAdmin\DatabaseInterface;
  6. use PhpMyAdmin\Message;
  7. use PhpMyAdmin\Relation;
  8. use PhpMyAdmin\Response;
  9. use PhpMyAdmin\Server\UserGroups;
  10. use PhpMyAdmin\Template;
  11. /**
  12. * Displays the 'User groups' sub page under 'Users' page.
  13. */
  14. class UserGroupsController extends AbstractController
  15. {
  16. /** @var Relation */
  17. private $relation;
  18. /** @var DatabaseInterface */
  19. private $dbi;
  20. /**
  21. * @param Response $response
  22. * @param DatabaseInterface $dbi
  23. */
  24. public function __construct($response, Template $template, Relation $relation, $dbi)
  25. {
  26. parent::__construct($response, $template);
  27. $this->relation = $relation;
  28. $this->dbi = $dbi;
  29. }
  30. public function index(): void
  31. {
  32. $cfgRelation = $this->relation->getRelationsParam();
  33. if (! $cfgRelation['menuswork']) {
  34. return;
  35. }
  36. $this->addScriptFiles(['server/user_groups.js']);
  37. /**
  38. * Only allowed to superuser
  39. */
  40. if (! $this->dbi->isSuperUser()) {
  41. $this->response->addHTML(
  42. Message::error(__('No Privileges'))->getDisplay()
  43. );
  44. return;
  45. }
  46. $this->response->addHTML('<div class="container-fluid">');
  47. $this->render('server/privileges/subnav', [
  48. 'active' => 'user-groups',
  49. 'is_super_user' => $this->dbi->isSuperUser(),
  50. ]);
  51. /**
  52. * Delete user group
  53. */
  54. if (! empty($_POST['deleteUserGroup'])) {
  55. UserGroups::delete($_POST['userGroup']);
  56. }
  57. /**
  58. * Add a new user group
  59. */
  60. if (! empty($_POST['addUserGroupSubmit'])) {
  61. UserGroups::edit($_POST['userGroup'], true);
  62. }
  63. /**
  64. * Update a user group
  65. */
  66. if (! empty($_POST['editUserGroupSubmit'])) {
  67. UserGroups::edit($_POST['userGroup']);
  68. }
  69. if (isset($_POST['viewUsers'])) {
  70. // Display users belonging to a user group
  71. $this->response->addHTML(UserGroups::getHtmlForListingUsersofAGroup($_POST['userGroup']));
  72. }
  73. if (isset($_GET['addUserGroup'])) {
  74. // Display add user group dialog
  75. $this->response->addHTML(UserGroups::getHtmlToEditUserGroup());
  76. } elseif (isset($_POST['editUserGroup'])) {
  77. // Display edit user group dialog
  78. $this->response->addHTML(UserGroups::getHtmlToEditUserGroup($_POST['userGroup']));
  79. } else {
  80. // Display user groups table
  81. $this->response->addHTML(UserGroups::getHtmlForUserGroupsTable());
  82. }
  83. $this->response->addHTML('</div>');
  84. }
  85. }