NavigationController.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <?php
  2. declare(strict_types=1);
  3. namespace PhpMyAdmin\Controllers;
  4. use PhpMyAdmin\Config\PageSettings;
  5. use PhpMyAdmin\Message;
  6. use PhpMyAdmin\Navigation\Navigation;
  7. use PhpMyAdmin\Relation;
  8. use PhpMyAdmin\Response;
  9. use PhpMyAdmin\Template;
  10. use PhpMyAdmin\Utils\SessionCache;
  11. /**
  12. * The navigation panel
  13. *
  14. * Displays server, database and table selection tree.
  15. */
  16. class NavigationController extends AbstractController
  17. {
  18. /** @var Navigation */
  19. private $navigation;
  20. /** @var Relation */
  21. private $relation;
  22. /**
  23. * @param Response $response
  24. */
  25. public function __construct(
  26. $response,
  27. Template $template,
  28. Navigation $navigation,
  29. Relation $relation
  30. ) {
  31. parent::__construct($response, $template);
  32. $this->navigation = $navigation;
  33. $this->relation = $relation;
  34. }
  35. public function index(): void
  36. {
  37. if (! $this->response->isAjax()) {
  38. $this->response->addHTML(
  39. Message::error(
  40. __('Fatal error: The navigation can only be accessed via AJAX')
  41. )->getDisplay()
  42. );
  43. return;
  44. }
  45. if (isset($_POST['getNaviSettings']) && $_POST['getNaviSettings']) {
  46. $pageSettings = new PageSettings('Navi', 'pma_navigation_settings');
  47. $this->response->addHTML($pageSettings->getErrorHTML());
  48. $this->response->addJSON('message', $pageSettings->getHTML());
  49. return;
  50. }
  51. if (isset($_POST['reload'])) {
  52. SessionCache::set('dbs_to_test', false);// Empty database list cache, see #14252
  53. }
  54. $cfgRelation = $this->relation->getRelationsParam();
  55. if ($cfgRelation['navwork']) {
  56. if (isset($_POST['hideNavItem'])) {
  57. if (! empty($_POST['itemName'])
  58. && ! empty($_POST['itemType'])
  59. && ! empty($_POST['dbName'])
  60. ) {
  61. $this->navigation->hideNavigationItem(
  62. $_POST['itemName'],
  63. $_POST['itemType'],
  64. $_POST['dbName'],
  65. (! empty($_POST['tableName']) ? $_POST['tableName'] : null)
  66. );
  67. }
  68. return;
  69. }
  70. if (isset($_POST['unhideNavItem'])) {
  71. if (! empty($_POST['itemName'])
  72. && ! empty($_POST['itemType'])
  73. && ! empty($_POST['dbName'])
  74. ) {
  75. $this->navigation->unhideNavigationItem(
  76. $_POST['itemName'],
  77. $_POST['itemType'],
  78. $_POST['dbName'],
  79. (! empty($_POST['tableName']) ? $_POST['tableName'] : null)
  80. );
  81. }
  82. return;
  83. }
  84. if (isset($_POST['showUnhideDialog'])) {
  85. if (! empty($_POST['dbName'])) {
  86. $this->response->addJSON(
  87. 'message',
  88. $this->navigation->getItemUnhideDialog($_POST['dbName'])
  89. );
  90. }
  91. return;
  92. }
  93. }
  94. $this->response->addJSON('message', $this->navigation->getDisplay());
  95. }
  96. }