Navigation.class.php 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * This class is responsible for instanciating
  5. * the various components of the navigation panel
  6. *
  7. * @package PhpMyAdmin-navigation
  8. */
  9. if (! defined('PHPMYADMIN')) {
  10. exit;
  11. }
  12. require_once 'libraries/navigation/NodeFactory.class.php';
  13. require_once 'libraries/navigation/NavigationHeader.class.php';
  14. require_once 'libraries/navigation/NavigationTree.class.php';
  15. /**
  16. * The navigation panel - displays server, db and table selection tree
  17. *
  18. * @package PhpMyAdmin-Navigation
  19. */
  20. class PMA_Navigation
  21. {
  22. /**
  23. * Initialises the class
  24. */
  25. public function __construct()
  26. {
  27. if (empty($GLOBALS['token'])) {
  28. $GLOBALS['token'] = $_SESSION[' PMA_token '];
  29. }
  30. }
  31. /**
  32. * Renders the navigation tree, or part of it
  33. *
  34. * @return string The navigation tree
  35. */
  36. public function getDisplay()
  37. {
  38. /* Init */
  39. $retval = '';
  40. if (! PMA_Response::getInstance()->isAjax()) {
  41. $header = new PMA_NavigationHeader();
  42. $retval = $header->getDisplay();
  43. }
  44. $tree = new PMA_NavigationTree();
  45. if (! PMA_Response::getInstance()->isAjax()
  46. || ! empty($_REQUEST['full'])
  47. || ! empty($_REQUEST['reload'])
  48. ) {
  49. $treeRender = $tree->renderState();
  50. } else {
  51. $treeRender = $tree->renderPath();
  52. }
  53. if (! $treeRender) {
  54. $retval .= PMA_Message::error(
  55. __('An error has occurred while loading the navigation tree')
  56. )->getDisplay();
  57. } else {
  58. $retval .= $treeRender;
  59. }
  60. if (! PMA_Response::getInstance()->isAjax()) {
  61. // closes the tags that were opened by the navigation header
  62. $retval .= '</div>';
  63. $retval .= '</div>';
  64. $retval .= '</div>';
  65. }
  66. return $retval;
  67. }
  68. /**
  69. * Add an item of navigation tree to the hidden items list in PMA database.
  70. *
  71. * @param string $itemName name of the navigation tree item
  72. * @param string $itemType type of the navigation tree item
  73. * @param string $dbName database name
  74. * @param string $tableName table name if applicable
  75. *
  76. * @return void
  77. */
  78. public function hideNavigationItem(
  79. $itemName, $itemType, $dbName, $tableName = null
  80. ) {
  81. $navTable = PMA_Util::backquote($GLOBALS['cfgRelation']['db'])
  82. . "." . PMA_Util::backquote($GLOBALS['cfgRelation']['navigationhiding']);
  83. $sqlQuery = "INSERT INTO " . $navTable
  84. . "(`username`, `item_name`, `item_type`, `db_name`, `table_name`)"
  85. . " VALUES ("
  86. . "'" . PMA_Util::sqlAddSlashes($GLOBALS['cfg']['Server']['user']) . "',"
  87. . "'" . PMA_Util::sqlAddSlashes($itemName) . "',"
  88. . "'" . PMA_Util::sqlAddSlashes($itemType) . "',"
  89. . "'" . PMA_Util::sqlAddSlashes($dbName) . "',"
  90. . "'" . (! empty($tableName)? PMA_Util::sqlAddSlashes($tableName) : "" )
  91. . "')";
  92. PMA_queryAsControlUser($sqlQuery, false);
  93. }
  94. /**
  95. * Remove a hidden item of navigation tree from the
  96. * list of hidden items in PMA database.
  97. *
  98. * @param string $itemName name of the navigation tree item
  99. * @param string $itemType type of the navigation tree item
  100. * @param string $dbName database name
  101. * @param string $tableName table name if applicable
  102. *
  103. * @return void
  104. */
  105. public function unhideNavigationItem(
  106. $itemName, $itemType, $dbName, $tableName = null
  107. ) {
  108. $navTable = PMA_Util::backquote($GLOBALS['cfgRelation']['db'])
  109. . "." . PMA_Util::backquote($GLOBALS['cfgRelation']['navigationhiding']);
  110. $sqlQuery = "DELETE FROM " . $navTable
  111. . " WHERE"
  112. . " `username`='"
  113. . PMA_Util::sqlAddSlashes($GLOBALS['cfg']['Server']['user']) . "'"
  114. . " AND `item_name`='" . PMA_Util::sqlAddSlashes($itemName) . "'"
  115. . " AND `item_type`='" . PMA_Util::sqlAddSlashes($itemType) . "'"
  116. . " AND `db_name`='" . PMA_Util::sqlAddSlashes($dbName) . "'"
  117. . (! empty($tableName)
  118. ? " AND `table_name`='" . PMA_Util::sqlAddSlashes($tableName) . "'"
  119. : ""
  120. );
  121. PMA_queryAsControlUser($sqlQuery, false);
  122. }
  123. /**
  124. * Returns HTML for the dialog to show hidden nativation items.
  125. *
  126. * @param string $dbName database name
  127. * @param string $itemType type of the items to include
  128. * @param string $tableName table name
  129. *
  130. * @return string HTML for the dialog to show hidden nativation items
  131. */
  132. public function getItemUnhideDialog($dbName, $itemType = null, $tableName = null)
  133. {
  134. $html = '<form method="post" action="navigation.php" class="ajax">';
  135. $html .= '<fieldset>';
  136. $html .= PMA_URL_getHiddenInputs($dbName, $tableName);
  137. $navTable = PMA_Util::backquote($GLOBALS['cfgRelation']['db'])
  138. . "." . PMA_Util::backquote($GLOBALS['cfgRelation']['navigationhiding']);
  139. $sqlQuery = "SELECT `item_name`, `item_type` FROM " . $navTable
  140. . " WHERE `username`='"
  141. . PMA_Util::sqlAddSlashes($GLOBALS['cfg']['Server']['user']) . "'"
  142. . " AND `db_name`='" . PMA_Util::sqlAddSlashes($dbName) . "'"
  143. . " AND `table_name`='"
  144. . (! empty($tableName) ? PMA_Util::sqlAddSlashes($tableName) : '') . "'";
  145. $result = PMA_queryAsControlUser($sqlQuery, false);
  146. $hidden = array();
  147. if ($result) {
  148. while ($row = $GLOBALS['dbi']->fetchArray($result)) {
  149. $type = $row['item_type'];
  150. if (! isset($hidden[$type])) {
  151. $hidden[$type] = array();
  152. }
  153. $hidden[$type][] = $row['item_name'];
  154. }
  155. }
  156. $GLOBALS['dbi']->freeResult($result);
  157. $typeMap = array(
  158. 'event' => __('Events:'),
  159. 'function' => __('Functions:'),
  160. 'procedure' => __('Procedures:'),
  161. 'table' => __('Tables:'),
  162. 'view' => __('Views:'),
  163. );
  164. if (empty($tableName)) {
  165. $first = true;
  166. foreach ($typeMap as $t => $lable) {
  167. if ((empty($itemType) || $itemType == $t)
  168. && isset($hidden[$t])
  169. ) {
  170. $html .= (! $first ? '<br/>' : '')
  171. . '<strong>' . $lable . '</strong>';
  172. $html .= '<table width="100%"><tbody>';
  173. $odd = true;
  174. foreach ($hidden[$t] as $hiddenItem) {
  175. $html .= '<tr class="' . ($odd ? 'odd' : 'even') . '">';
  176. $html .= '<td>' . htmlspecialchars($hiddenItem) . '</td>';
  177. $html .= '<td style="width:80px"><a href="navigation.php?'
  178. . PMA_URL_getCommon()
  179. . '&unhideNavItem=true'
  180. . '&itemType=' . urlencode($t)
  181. . '&itemName=' . urlencode($hiddenItem)
  182. . '&dbName=' . urlencode($dbName) . '"'
  183. . ' class="unhideNavItem ajax">'
  184. . PMA_Util::getIcon('lightbulb.png', __('Show'))
  185. . '</a></td>';
  186. $odd = ! $odd;
  187. }
  188. $html .= '</tbody></table>';
  189. $first = false;
  190. }
  191. }
  192. }
  193. $html .= '</fieldset>';
  194. $html .= '</form>';
  195. return $html;
  196. }
  197. }
  198. ?>