Navigation.php 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * This class is responsible for instantiating
  5. * the various components of the navigation panel
  6. *
  7. * @package PhpMyAdmin-navigation
  8. */
  9. namespace PhpMyAdmin\Navigation;
  10. use PhpMyAdmin\Config\PageSettings;
  11. use PhpMyAdmin\Message;
  12. use PhpMyAdmin\Relation;
  13. use PhpMyAdmin\Response;
  14. use PhpMyAdmin\Url;
  15. use PhpMyAdmin\Util;
  16. /**
  17. * The navigation panel - displays server, db and table selection tree
  18. *
  19. * @package PhpMyAdmin-Navigation
  20. */
  21. class Navigation
  22. {
  23. /**
  24. * @var Relation $relation
  25. */
  26. private $relation;
  27. /**
  28. * Constructor
  29. */
  30. public function __construct()
  31. {
  32. $this->relation = new Relation();
  33. }
  34. /**
  35. * Renders the navigation tree, or part of it
  36. *
  37. * @return string The navigation tree
  38. */
  39. public function getDisplay()
  40. {
  41. /* Init */
  42. $retval = '';
  43. $response = Response::getInstance();
  44. if (! $response->isAjax()) {
  45. $header = new NavigationHeader();
  46. $retval = $header->getDisplay();
  47. }
  48. $tree = new NavigationTree();
  49. if (! $response->isAjax()
  50. || ! empty($_POST['full'])
  51. || ! empty($_POST['reload'])
  52. ) {
  53. if ($GLOBALS['cfg']['ShowDatabasesNavigationAsTree']) {
  54. // provide database tree in navigation
  55. $navRender = $tree->renderState();
  56. } else {
  57. // provide legacy pre-4.0 navigation
  58. $navRender = $tree->renderDbSelect();
  59. }
  60. } else {
  61. $navRender = $tree->renderPath();
  62. }
  63. if (! $navRender) {
  64. $retval .= Message::error(
  65. __('An error has occurred while loading the navigation display')
  66. )->getDisplay();
  67. } else {
  68. $retval .= $navRender;
  69. }
  70. if (! $response->isAjax()) {
  71. // closes the tags that were opened by the navigation header
  72. $retval .= '</div>'; // pma_navigation_tree
  73. $retval .= '<div id="pma_navi_settings_container">';
  74. if (!defined('PMA_DISABLE_NAVI_SETTINGS')) {
  75. $retval .= PageSettings::getNaviSettings();
  76. }
  77. $retval .= '</div>'; //pma_navi_settings_container
  78. $retval .= '</div>'; // pma_navigation_content
  79. $retval .= $this->_getDropHandler();
  80. $retval .= '</div>'; // pma_navigation
  81. }
  82. return $retval;
  83. }
  84. /**
  85. * Add an item of navigation tree to the hidden items list in PMA database.
  86. *
  87. * @param string $itemName name of the navigation tree item
  88. * @param string $itemType type of the navigation tree item
  89. * @param string $dbName database name
  90. * @param string $tableName table name if applicable
  91. *
  92. * @return void
  93. */
  94. public function hideNavigationItem(
  95. $itemName, $itemType, $dbName, $tableName = null
  96. ) {
  97. $navTable = Util::backquote($GLOBALS['cfgRelation']['db'])
  98. . "." . Util::backquote($GLOBALS['cfgRelation']['navigationhiding']);
  99. $sqlQuery = "INSERT INTO " . $navTable
  100. . "(`username`, `item_name`, `item_type`, `db_name`, `table_name`)"
  101. . " VALUES ("
  102. . "'" . $GLOBALS['dbi']->escapeString($GLOBALS['cfg']['Server']['user']) . "',"
  103. . "'" . $GLOBALS['dbi']->escapeString($itemName) . "',"
  104. . "'" . $GLOBALS['dbi']->escapeString($itemType) . "',"
  105. . "'" . $GLOBALS['dbi']->escapeString($dbName) . "',"
  106. . "'" . (! empty($tableName)? $GLOBALS['dbi']->escapeString($tableName) : "" )
  107. . "')";
  108. $this->relation->queryAsControlUser($sqlQuery, false);
  109. }
  110. /**
  111. * Inserts Drag and Drop Import handler
  112. *
  113. * @return string html code for drop handler
  114. */
  115. private function _getDropHandler()
  116. {
  117. $retval = '';
  118. $retval .= '<div class="pma_drop_handler">'
  119. . __('Drop files here')
  120. . '</div>';
  121. $retval .= '<div class="pma_sql_import_status">';
  122. $retval .= '<h2>SQL upload ( ';
  123. $retval .= '<span class="pma_import_count">0</span> ';
  124. $retval .= ') <span class="close">x</span>';
  125. $retval .= '<span class="minimize">-</span></h2>';
  126. $retval .= '<div></div>';
  127. $retval .= '</div>';
  128. return $retval;
  129. }
  130. /**
  131. * Remove a hidden item of navigation tree from the
  132. * list of hidden items in PMA database.
  133. *
  134. * @param string $itemName name of the navigation tree item
  135. * @param string $itemType type of the navigation tree item
  136. * @param string $dbName database name
  137. * @param string $tableName table name if applicable
  138. *
  139. * @return void
  140. */
  141. public function unhideNavigationItem(
  142. $itemName, $itemType, $dbName, $tableName = null
  143. ) {
  144. $navTable = Util::backquote($GLOBALS['cfgRelation']['db'])
  145. . "." . Util::backquote($GLOBALS['cfgRelation']['navigationhiding']);
  146. $sqlQuery = "DELETE FROM " . $navTable
  147. . " WHERE"
  148. . " `username`='"
  149. . $GLOBALS['dbi']->escapeString($GLOBALS['cfg']['Server']['user']) . "'"
  150. . " AND `item_name`='" . $GLOBALS['dbi']->escapeString($itemName) . "'"
  151. . " AND `item_type`='" . $GLOBALS['dbi']->escapeString($itemType) . "'"
  152. . " AND `db_name`='" . $GLOBALS['dbi']->escapeString($dbName) . "'"
  153. . (! empty($tableName)
  154. ? " AND `table_name`='" . $GLOBALS['dbi']->escapeString($tableName) . "'"
  155. : ""
  156. );
  157. $this->relation->queryAsControlUser($sqlQuery, false);
  158. }
  159. /**
  160. * Returns HTML for the dialog to show hidden navigation items.
  161. *
  162. * @param string $dbName database name
  163. * @param string $itemType type of the items to include
  164. * @param string $tableName table name
  165. *
  166. * @return string HTML for the dialog to show hidden navigation items
  167. */
  168. public function getItemUnhideDialog($dbName, $itemType = null, $tableName = null)
  169. {
  170. $html = '<form method="post" action="navigation.php" class="ajax">';
  171. $html .= '<fieldset>';
  172. $html .= Url::getHiddenInputs($dbName, $tableName);
  173. $navTable = Util::backquote($GLOBALS['cfgRelation']['db'])
  174. . "." . Util::backquote($GLOBALS['cfgRelation']['navigationhiding']);
  175. $sqlQuery = "SELECT `item_name`, `item_type` FROM " . $navTable
  176. . " WHERE `username`='"
  177. . $GLOBALS['dbi']->escapeString($GLOBALS['cfg']['Server']['user']) . "'"
  178. . " AND `db_name`='" . $GLOBALS['dbi']->escapeString($dbName) . "'"
  179. . " AND `table_name`='"
  180. . (! empty($tableName) ? $GLOBALS['dbi']->escapeString($tableName) : '') . "'";
  181. $result = $this->relation->queryAsControlUser($sqlQuery, false);
  182. $hidden = array();
  183. if ($result) {
  184. while ($row = $GLOBALS['dbi']->fetchArray($result)) {
  185. $type = $row['item_type'];
  186. if (! isset($hidden[$type])) {
  187. $hidden[$type] = array();
  188. }
  189. $hidden[$type][] = $row['item_name'];
  190. }
  191. }
  192. $GLOBALS['dbi']->freeResult($result);
  193. $typeMap = array(
  194. 'group' => __('Groups:'),
  195. 'event' => __('Events:'),
  196. 'function' => __('Functions:'),
  197. 'procedure' => __('Procedures:'),
  198. 'table' => __('Tables:'),
  199. 'view' => __('Views:'),
  200. );
  201. if (empty($tableName)) {
  202. $first = true;
  203. foreach ($typeMap as $t => $lable) {
  204. if ((empty($itemType) || $itemType == $t)
  205. && isset($hidden[$t])
  206. ) {
  207. $html .= (! $first ? '<br/>' : '')
  208. . '<strong>' . $lable . '</strong>';
  209. $html .= '<table width="100%"><tbody>';
  210. foreach ($hidden[$t] as $hiddenItem) {
  211. $params = array(
  212. 'unhideNavItem' => true,
  213. 'itemType' => $t,
  214. 'itemName' => $hiddenItem,
  215. 'dbName' => $dbName
  216. );
  217. $html .= '<tr>';
  218. $html .= '<td>' . htmlspecialchars($hiddenItem) . '</td>';
  219. $html .= '<td style="width:80px"><a href="navigation.php" data-post="'
  220. . Url::getCommon($params, '', false) . '"'
  221. . ' class="unhideNavItem ajax">'
  222. . Util::getIcon('show', __('Show'))
  223. . '</a></td>';
  224. }
  225. $html .= '</tbody></table>';
  226. $first = false;
  227. }
  228. }
  229. }
  230. $html .= '</fieldset>';
  231. $html .= '</form>';
  232. return $html;
  233. }
  234. }