NavigationHeader.class.php 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * Header for the navigation panel
  5. *
  6. * @package PhpMyAdmin-Navigation
  7. */
  8. if (! defined('PHPMYADMIN')) {
  9. exit;
  10. }
  11. /**
  12. * This class renders the logo, links, server selection and recent tables,
  13. * which are then displayed at the top of the naviagtion panel
  14. *
  15. * @package PhpMyAdmin-Navigation
  16. */
  17. class PMA_NavigationHeader
  18. {
  19. /**
  20. * Renders the navigation
  21. *
  22. * @return void
  23. */
  24. public function getDisplay()
  25. {
  26. if (empty($GLOBALS['url_query'])) {
  27. $GLOBALS['url_query'] = PMA_generate_common_url();
  28. }
  29. $link_url = PMA_generate_common_url(
  30. array(
  31. 'ajax_request' => true
  32. )
  33. );
  34. $class = ' class="list_container';
  35. if ($GLOBALS['cfg']['NavigationTreePointerEnable']) {
  36. $class .= ' highlight';
  37. }
  38. $class .= '"';
  39. $buffer = '<div id="pma_navigation">';
  40. $buffer .= '<div id="pma_navigation_resizer"></div>';
  41. $buffer .= '<div id="pma_navigation_collapser"></div>';
  42. $buffer .= '<div id="pma_navigation_content">';
  43. $buffer .= '<div id="pma_navigation_header">';
  44. $buffer .= sprintf(
  45. '<a class="hide navigation_url" href="navigation.php%s"></a>',
  46. $link_url
  47. );
  48. $buffer .= $this->_logo();
  49. $buffer .= $this->_links();
  50. $buffer .= $this->_serverChoice();
  51. $buffer .= $this->_recent();
  52. $buffer .= PMA_Util::getImage(
  53. 'ajax_clock_small.gif',
  54. __('Loading'),
  55. array('style' => 'visibility: hidden;', 'class' => 'throbber')
  56. );
  57. $buffer .= '</div>'; // pma_navigation_header
  58. $buffer .= '<div id="pma_navigation_tree"' . $class . '>';
  59. return $buffer;
  60. }
  61. /**
  62. * Create the code for displaying the phpMyAdmin
  63. * logo based on configuration settings
  64. *
  65. * @return string HTML code for the logo
  66. */
  67. private function _logo()
  68. {
  69. $retval = '<!-- LOGO START -->';
  70. // display Logo, depending on $GLOBALS['cfg']['NavigationDisplayLogo']
  71. if ($GLOBALS['cfg']['NavigationDisplayLogo']) {
  72. $logo = 'phpMyAdmin';
  73. if (@file_exists($GLOBALS['pmaThemeImage'] . 'logo_left.png')) {
  74. $logo = '<img src="' . $GLOBALS['pmaThemeImage'] . 'logo_left.png" '
  75. . 'alt="' . $logo . '" id="imgpmalogo" />';
  76. } elseif (@file_exists($GLOBALS['pmaThemeImage'] . 'pma_logo2.png')) {
  77. $logo = '<img src="' . $GLOBALS['pmaThemeImage'] . 'pma_logo2.png" '
  78. . 'alt="' . $logo . '" id="imgpmalogo" />';
  79. }
  80. $retval .= '<div id="pmalogo">';
  81. if ($GLOBALS['cfg']['NavigationLogoLink']) {
  82. $logo_link = trim(htmlspecialchars($GLOBALS['cfg']['NavigationLogoLink']));
  83. $parsed = parse_url($logo_link);
  84. /* Allow only links with http/https */
  85. if (! isset($parsed['scheme']) || ! in_array(strtolower($parsed['scheme']), array('http', 'https'))) {
  86. $logo_link = 'index.php';
  87. }
  88. $retval .= ' <a href="' . $logo_link;
  89. switch ($GLOBALS['cfg']['NavigationLogoLinkWindow']) {
  90. case 'new':
  91. $retval .= '" target="_blank"';
  92. break;
  93. case 'main':
  94. // do not add our parameters for an external link
  95. if (substr(strtolower($GLOBALS['cfg']['NavigationLogoLink']), 0, 4) !== '://') {
  96. $retval .= '?' . $GLOBALS['url_query'] . '"';
  97. } else {
  98. $retval .= '" target="_blank"';
  99. }
  100. }
  101. $retval .= '>';
  102. $retval .= $logo;
  103. $retval .= '</a>';
  104. } else {
  105. $retval .= $logo;
  106. }
  107. $retval .= '</div>';
  108. }
  109. $retval .= '<!-- LOGO END -->';
  110. return $retval;
  111. }
  112. /**
  113. * Renders a single link for the top of the navigation panel
  114. *
  115. * @param string $link The url for the link
  116. * @param bool $showText Whether to show the text or to
  117. * only use it for title attributes
  118. * @param string $text The text to display and use for title attributes
  119. * @param bool $showIcon Whether to show the icon
  120. * @param string $icon The filename of the icon to show
  121. * @param string $linkId Value to use for the ID attribute
  122. * @param string $disableAjax Whether to disable ajax page loading for this link
  123. * @param string $linkTarget The name of the target frame for the link
  124. *
  125. * @return string HTML code for one link
  126. */
  127. private function _getLink(
  128. $link,
  129. $showText,
  130. $text,
  131. $showIcon,
  132. $icon,
  133. $linkId = '',
  134. $disableAjax = false,
  135. $linkTarget = ''
  136. ) {
  137. $retval = '<a href="' . $link . '"';
  138. if (! empty($linkId)) {
  139. $retval .= ' id="' . $linkId . '"';
  140. }
  141. if (! empty($linkTarget)) {
  142. $retval .= ' target="' . $linkTarget . '"';
  143. }
  144. if ($disableAjax) {
  145. $retval .= ' class="disableAjax"';
  146. }
  147. $retval .= ' title="' . $text . '">';
  148. if ($showIcon) {
  149. $retval .= PMA_Util::getImage(
  150. $icon,
  151. $text
  152. );
  153. }
  154. if ($showText) {
  155. $retval .= $text;
  156. }
  157. $retval .= '</a>';
  158. if ($showText) {
  159. $retval .= '<br />';
  160. }
  161. return $retval;
  162. }
  163. /**
  164. * Creates the code for displaying the links
  165. * at the top of the navigation frame
  166. *
  167. * @return string HTML code for the links
  168. */
  169. private function _links()
  170. {
  171. // always iconic
  172. $showIcon = true;
  173. $showText = false;
  174. $retval = '<!-- LINKS START -->';
  175. $retval .= '<div id="leftframelinks">';
  176. $retval .= $this->_getLink(
  177. 'index.php?' . PMA_generate_common_url(),
  178. $showText,
  179. __('Home'),
  180. $showIcon,
  181. 'b_home.png'
  182. );
  183. // if we have chosen server
  184. if ($GLOBALS['server'] != 0) {
  185. // Logout for advanced authentication
  186. if ($GLOBALS['cfg']['Server']['auth_type'] != 'config') {
  187. $link = 'index.php?' . $GLOBALS['url_query'];
  188. $link .= '&amp;old_usr=' . urlencode($GLOBALS['PHP_AUTH_USER']);
  189. $retval .= $this->_getLink(
  190. $link,
  191. $showText,
  192. __('Log out'),
  193. $showIcon,
  194. 's_loggoff.png',
  195. '',
  196. true
  197. );
  198. }
  199. $link = 'querywindow.php?';
  200. $link .= PMA_generate_common_url($GLOBALS['db'], $GLOBALS['table']);
  201. $link .= '&amp;no_js=true';
  202. $retval .= $this->_getLink(
  203. $link,
  204. $showText,
  205. __('Query window'),
  206. $showIcon,
  207. 'b_selboard.png',
  208. 'pma_open_querywindow',
  209. true
  210. );
  211. }
  212. $retval .= $this->_getLink(
  213. PMA_Util::getDocuLink('index'),
  214. $showText,
  215. __('phpMyAdmin documentation'),
  216. $showIcon,
  217. 'b_docs.png',
  218. '',
  219. false,
  220. 'documentation'
  221. );
  222. if ($showIcon) {
  223. $retval .= PMA_Util::showMySQLDocu('', '', true);
  224. }
  225. if ($showText) {
  226. // PMA_showMySQLDocu always spits out an icon,
  227. // we just replace it with some perl regexp.
  228. $link = preg_replace(
  229. '/<img[^>]+>/i',
  230. __('Documentation'),
  231. PMA_Util::showMySQLDocu('', '', true)
  232. );
  233. $retval .= $link;
  234. $retval .= '<br />';
  235. }
  236. $retval .= $this->_getLink(
  237. '#',
  238. $showText,
  239. __('Reload navigation frame'),
  240. $showIcon,
  241. 's_reload.png',
  242. 'pma_navigation_reload'
  243. );
  244. $retval .= '</div>';
  245. $retval .= '<!-- LINKS ENDS -->';
  246. return $retval;
  247. }
  248. /**
  249. * Displays the MySQL servers choice form
  250. *
  251. * @return string HTML code for the MySQL servers choice
  252. */
  253. private function _serverChoice()
  254. {
  255. $retval = '';
  256. if ($GLOBALS['cfg']['NavigationDisplayServers']
  257. && count($GLOBALS['cfg']['Servers']) > 1
  258. ) {
  259. include_once './libraries/select_server.lib.php';
  260. $retval .= '<!-- SERVER CHOICE START -->';
  261. $retval .= '<div id="serverChoice">';
  262. $retval .= PMA_selectServer(true, true);
  263. $retval .= '</div>';
  264. $retval .= '<!-- SERVER CHOICE END -->';
  265. }
  266. return $retval;
  267. }
  268. /**
  269. * Displays a drop-down choice of most recently used tables
  270. *
  271. * @return string HTML code for the Recent tables
  272. */
  273. private function _recent()
  274. {
  275. $retval = '';
  276. // display recently used tables
  277. if ($GLOBALS['cfg']['NumRecentTables'] > 0) {
  278. $retval .= '<!-- RECENT START -->';
  279. $retval .= '<div id="recentTableList">';
  280. $retval .= '<form method="post" ';
  281. $retval .= 'action="' . $GLOBALS['cfg']['DefaultTabTable'] . '">';
  282. $retval .= PMA_generate_common_hidden_inputs(
  283. array(
  284. 'db' => '',
  285. 'table' => '',
  286. 'server' => $GLOBALS['server']
  287. )
  288. );
  289. $retval .= PMA_RecentTable::getInstance()->getHtmlSelect();
  290. $retval .= '</form>';
  291. $retval .= '</div>';
  292. $retval .= '<!-- RECENT END -->';
  293. }
  294. return $retval;
  295. }
  296. }
  297. ?>