Menu.class.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * Generates and renders the top menu
  5. *
  6. * @package PhpMyAdmin
  7. */
  8. if (! defined('PHPMYADMIN')) {
  9. exit;
  10. }
  11. /**
  12. * Class for generating the top menu
  13. *
  14. * @package PhpMyAdmin
  15. */
  16. class PMA_Menu
  17. {
  18. /**
  19. * Server id
  20. *
  21. * @access private
  22. * @var string
  23. */
  24. private $_server;
  25. /**
  26. * Database name
  27. *
  28. * @access private
  29. * @var string
  30. */
  31. private $_db;
  32. /**
  33. * Table name
  34. *
  35. * @access private
  36. * @var string
  37. */
  38. private $_table;
  39. /**
  40. * Creates a new instance of PMA_Menu
  41. *
  42. * @param int $server Server id
  43. * @param string $db Database name
  44. * @param string $table Table name
  45. *
  46. * @return New PMA_Table
  47. */
  48. public function __construct($server, $db, $table)
  49. {
  50. $this->_server = $server;
  51. $this->_db = $db;
  52. $this->_table = $table;
  53. }
  54. /**
  55. * Prints the menu and the breadcrumbs
  56. *
  57. * @return void
  58. */
  59. public function display()
  60. {
  61. echo $this->getDisplay();
  62. }
  63. /**
  64. * Returns the menu and the breadcrumbs as a string
  65. *
  66. * @return string
  67. */
  68. public function getDisplay()
  69. {
  70. $retval = $this->_getBreadcrumbs();
  71. $retval .= $this->_getMenu();
  72. return $retval;
  73. }
  74. /**
  75. * Returns hash for the menu and the breadcrumbs
  76. *
  77. * @return string
  78. */
  79. public function getHash()
  80. {
  81. return substr(
  82. md5($this->_getMenu() . $this->_getBreadcrumbs()),
  83. 0,
  84. 8
  85. );
  86. }
  87. /**
  88. * Returns the menu as HTML
  89. *
  90. * @return string HTML formatted menubar
  91. */
  92. private function _getMenu()
  93. {
  94. $tabs = array();
  95. $url_params = array('db' => $this->_db);
  96. if (strlen($this->_table)) {
  97. $tabs = $this->_getTableTabs();
  98. $url_params['table'] = $this->_table;
  99. } else if (strlen($this->_db)) {
  100. $tabs = $this->_getDbTabs();
  101. } else {
  102. $tabs = $this->_getServerTabs();
  103. }
  104. return PMA_Util::getHtmlTabs($tabs, $url_params, 'topmenu', true);
  105. }
  106. /**
  107. * Returns the breadcrumbs as HTML
  108. *
  109. * @return string HTML formatted breadcrumbs
  110. */
  111. private function _getBreadcrumbs()
  112. {
  113. $retval = '';
  114. $tbl_is_view = PMA_Table::isView($this->_db, $this->_table);
  115. $server_info = ! empty($GLOBALS['cfg']['Server']['verbose'])
  116. ? $GLOBALS['cfg']['Server']['verbose']
  117. : $GLOBALS['cfg']['Server']['host'];
  118. $server_info .= empty($GLOBALS['cfg']['Server']['port'])
  119. ? ''
  120. : ':' . $GLOBALS['cfg']['Server']['port'];
  121. $separator = "<span class='separator item'>&nbsp;»</span>";
  122. $item = '<a href="%1$s?%2$s" class="item">';
  123. if (in_array(
  124. $GLOBALS['cfg']['TabsMode'],
  125. array('text', 'both')
  126. )
  127. ) {
  128. $item .= '%4$s: ';
  129. }
  130. $item .= '%3$s</a>';
  131. $retval .= "<div id='floating_menubar'></div>";
  132. $retval .= "<div id='serverinfo'>";
  133. if (in_array(
  134. $GLOBALS['cfg']['TabsMode'],
  135. array('icons', 'both')
  136. )
  137. ) {
  138. $retval .= PMA_Util::getImage(
  139. 's_host.png',
  140. '',
  141. array('class' => 'item')
  142. );
  143. }
  144. $retval .= sprintf(
  145. $item,
  146. $GLOBALS['cfg']['DefaultTabServer'],
  147. PMA_generate_common_url(),
  148. htmlspecialchars($server_info),
  149. __('Server')
  150. );
  151. if (strlen($this->_db)) {
  152. $retval .= $separator;
  153. if (in_array(
  154. $GLOBALS['cfg']['TabsMode'],
  155. array('icons', 'both')
  156. )
  157. ) {
  158. $retval .= PMA_Util::getImage(
  159. 's_db.png',
  160. '',
  161. array('class' => 'item')
  162. );
  163. }
  164. $retval .= sprintf(
  165. $item,
  166. $GLOBALS['cfg']['DefaultTabDatabase'],
  167. PMA_generate_common_url($this->_db),
  168. htmlspecialchars($this->_db),
  169. __('Database')
  170. );
  171. // if the table is being dropped, $_REQUEST['purge'] is set to '1'
  172. // so do not display the table name in upper div
  173. if (strlen($this->_table)
  174. && ! (isset($_REQUEST['purge']) && $_REQUEST['purge'] == '1')
  175. ) {
  176. include './libraries/tbl_info.inc.php';
  177. $retval .= $separator;
  178. if (in_array(
  179. $GLOBALS['cfg']['TabsMode'],
  180. array('icons', 'both')
  181. )
  182. ) {
  183. $icon = $tbl_is_view ? 'b_views.png' : 's_tbl.png';
  184. $retval .= PMA_Util::getImage(
  185. $icon,
  186. '',
  187. array('class' => 'item')
  188. );
  189. }
  190. $retval .= sprintf(
  191. $item,
  192. $GLOBALS['cfg']['DefaultTabTable'],
  193. PMA_generate_common_url($this->_db, $this->_table),
  194. str_replace(' ', '&nbsp;', htmlspecialchars($this->_table)),
  195. $tbl_is_view ? __('View') : __('Table')
  196. );
  197. /**
  198. * Displays table comment
  199. */
  200. if (! empty($show_comment)
  201. && ! isset($GLOBALS['avoid_show_comment'])
  202. ) {
  203. if (strstr($show_comment, '; InnoDB free')) {
  204. $show_comment = preg_replace(
  205. '@; InnoDB free:.*?$@',
  206. '',
  207. $show_comment
  208. );
  209. }
  210. $retval .= '<span class="table_comment"';
  211. $retval .= ' id="span_table_comment">&quot;';
  212. $retval .= htmlspecialchars($show_comment);
  213. $retval .= '&quot;</span>';
  214. } // end if
  215. } else {
  216. // no table selected, display database comment if present
  217. $cfgRelation = PMA_getRelationsParam();
  218. // Get additional information about tables for tooltip is done
  219. // in libraries/db_info.inc.php only once
  220. if ($cfgRelation['commwork']) {
  221. $comment = PMA_getDbComment($this->_db);
  222. /**
  223. * Displays table comment
  224. */
  225. if (! empty($comment)) {
  226. $retval .= '<span class="table_comment"'
  227. . ' id="span_table_comment">&quot;'
  228. . htmlspecialchars($comment)
  229. . '&quot;</span>';
  230. } // end if
  231. }
  232. }
  233. }
  234. $retval .= '<div class="clearfloat"></div>';
  235. $retval .= '</div>';
  236. return $retval;
  237. }
  238. /**
  239. * Returns the table tabs as an array
  240. *
  241. * @return array Data for generating table tabs
  242. */
  243. private function _getTableTabs()
  244. {
  245. $db_is_information_schema = PMA_is_system_schema($this->_db);
  246. $tbl_is_view = PMA_Table::isView($this->_db, $this->_table);
  247. $table_info_num_rows = PMA_Table::countRecords($this->_db, $this->_table);
  248. $tabs = array();
  249. $tabs['browse']['icon'] = 'b_browse.png';
  250. $tabs['browse']['text'] = __('Browse');
  251. $tabs['browse']['link'] = 'sql.php';
  252. $tabs['browse']['args']['pos'] = 0;
  253. $tabs['structure']['icon'] = 'b_props.png';
  254. $tabs['structure']['link'] = 'tbl_structure.php';
  255. $tabs['structure']['text'] = __('Structure');
  256. $tabs['sql']['icon'] = 'b_sql.png';
  257. $tabs['sql']['link'] = 'tbl_sql.php';
  258. $tabs['sql']['text'] = __('SQL');
  259. $tabs['search']['icon'] = 'b_search.png';
  260. $tabs['search']['text'] = __('Search');
  261. $tabs['search']['link'] = 'tbl_select.php';
  262. $tabs['search']['active'] = in_array(
  263. basename($GLOBALS['PMA_PHP_SELF']),
  264. array('tbl_select.php', 'tbl_zoom_select.php')
  265. );
  266. if (! $db_is_information_schema) {
  267. $tabs['insert']['icon'] = 'b_insrow.png';
  268. $tabs['insert']['link'] = 'tbl_change.php';
  269. $tabs['insert']['text'] = __('Insert');
  270. }
  271. $tabs['export']['icon'] = 'b_tblexport.png';
  272. $tabs['export']['link'] = 'tbl_export.php';
  273. $tabs['export']['args']['single_table'] = 'true';
  274. $tabs['export']['text'] = __('Export');
  275. /**
  276. * Don't display "Import" and "Operations"
  277. * for views and information_schema
  278. */
  279. if (! $tbl_is_view && ! $db_is_information_schema) {
  280. $tabs['import']['icon'] = 'b_tblimport.png';
  281. $tabs['import']['link'] = 'tbl_import.php';
  282. $tabs['import']['text'] = __('Import');
  283. $tabs['operation']['icon'] = 'b_tblops.png';
  284. $tabs['operation']['link'] = 'tbl_operations.php';
  285. $tabs['operation']['text'] = __('Operations');
  286. }
  287. if (PMA_Tracker::isActive()) {
  288. $tabs['tracking']['icon'] = 'eye.png';
  289. $tabs['tracking']['text'] = __('Tracking');
  290. $tabs['tracking']['link'] = 'tbl_tracking.php';
  291. }
  292. if (! $db_is_information_schema
  293. && ! PMA_DRIZZLE
  294. && PMA_Util::currentUserHasPrivilege('TRIGGER', $this->_db, $this->_table)
  295. && ! $tbl_is_view
  296. ) {
  297. $tabs['triggers']['link'] = 'tbl_triggers.php';
  298. $tabs['triggers']['text'] = __('Triggers');
  299. $tabs['triggers']['icon'] = 'b_triggers.png';
  300. }
  301. /**
  302. * Views support a limited number of operations
  303. */
  304. if ($tbl_is_view && ! $db_is_information_schema) {
  305. $tabs['operation']['icon'] = 'b_tblops.png';
  306. $tabs['operation']['link'] = 'view_operations.php';
  307. $tabs['operation']['text'] = __('Operations');
  308. }
  309. return $tabs;
  310. }
  311. /**
  312. * Returns the db tabs as an array
  313. *
  314. * @return array Data for generating db tabs
  315. */
  316. private function _getDbTabs()
  317. {
  318. $db_is_information_schema = PMA_is_system_schema($this->_db);
  319. $num_tables = count(PMA_DBI_get_tables($this->_db));
  320. $is_superuser = PMA_isSuperuser();
  321. /**
  322. * Gets the relation settings
  323. */
  324. $cfgRelation = PMA_getRelationsParam();
  325. $tabs = array();
  326. $tabs['structure']['link'] = 'db_structure.php';
  327. $tabs['structure']['text'] = __('Structure');
  328. $tabs['structure']['icon'] = 'b_props.png';
  329. $tabs['sql']['link'] = 'db_sql.php';
  330. $tabs['sql']['args']['db_query_force'] = 1;
  331. $tabs['sql']['text'] = __('SQL');
  332. $tabs['sql']['icon'] = 'b_sql.png';
  333. $tabs['search']['text'] = __('Search');
  334. $tabs['search']['icon'] = 'b_search.png';
  335. $tabs['search']['link'] = 'db_search.php';
  336. if ($num_tables == 0) {
  337. $tabs['search']['warning'] = __('Database seems to be empty!');
  338. }
  339. $tabs['qbe']['text'] = __('Query');
  340. $tabs['qbe']['icon'] = 's_db.png';
  341. $tabs['qbe']['link'] = 'db_qbe.php';
  342. if ($num_tables == 0) {
  343. $tabs['qbe']['warning'] = __('Database seems to be empty!');
  344. }
  345. $tabs['export']['text'] = __('Export');
  346. $tabs['export']['icon'] = 'b_export.png';
  347. $tabs['export']['link'] = 'db_export.php';
  348. if ($num_tables == 0) {
  349. $tabs['export']['warning'] = __('Database seems to be empty!');
  350. }
  351. if (! $db_is_information_schema) {
  352. $tabs['import']['link'] = 'db_import.php';
  353. $tabs['import']['text'] = __('Import');
  354. $tabs['import']['icon'] = 'b_import.png';
  355. $tabs['operation']['link'] = 'db_operations.php';
  356. $tabs['operation']['text'] = __('Operations');
  357. $tabs['operation']['icon'] = 'b_tblops.png';
  358. if ($is_superuser && ! PMA_DRIZZLE) {
  359. $tabs['privileges']['link'] = 'server_privileges.php';
  360. $tabs['privileges']['args']['checkprivs'] = $this->_db;
  361. // stay on database view
  362. $tabs['privileges']['args']['viewing_mode'] = 'db';
  363. $tabs['privileges']['text'] = __('Privileges');
  364. $tabs['privileges']['icon'] = 's_rights.png';
  365. }
  366. if (! PMA_DRIZZLE) {
  367. $tabs['routines']['link'] = 'db_routines.php';
  368. $tabs['routines']['text'] = __('Routines');
  369. $tabs['routines']['icon'] = 'b_routines.png';
  370. }
  371. if (PMA_MYSQL_INT_VERSION >= 50106
  372. && ! PMA_DRIZZLE
  373. && PMA_Util::currentUserHasPrivilege('EVENT', $this->_db)
  374. ) {
  375. $tabs['events']['link'] = 'db_events.php';
  376. $tabs['events']['text'] = __('Events');
  377. $tabs['events']['icon'] = 'b_events.png';
  378. }
  379. if (! PMA_DRIZZLE
  380. && PMA_Util::currentUserHasPrivilege('TRIGGER', $this->_db)
  381. ) {
  382. $tabs['triggers']['link'] = 'db_triggers.php';
  383. $tabs['triggers']['text'] = __('Triggers');
  384. $tabs['triggers']['icon'] = 'b_triggers.png';
  385. }
  386. }
  387. if (PMA_Tracker::isActive()) {
  388. $tabs['tracking']['text'] = __('Tracking');
  389. $tabs['tracking']['icon'] = 'eye.png';
  390. $tabs['tracking']['link'] = 'db_tracking.php';
  391. }
  392. if (! $db_is_information_schema && $cfgRelation['designerwork']) {
  393. $tabs['designer']['text'] = __('Designer');
  394. $tabs['designer']['icon'] = 'b_relations.png';
  395. $tabs['designer']['link'] = 'pmd_general.php';
  396. }
  397. return $tabs;
  398. }
  399. /**
  400. * Returns the server tabs as an array
  401. *
  402. * @return array Data for generating server tabs
  403. */
  404. private function _getServerTabs()
  405. {
  406. $is_superuser = function_exists('PMA_isSuperuser') && PMA_isSuperuser();
  407. $binary_logs = null;
  408. if (function_exists('PMA_DBI_fetch_result')
  409. && (! defined('PMA_DRIZZLE')
  410. || (defined('PMA_DRIZZLE') && ! PMA_DRIZZLE)
  411. )
  412. ) {
  413. $binary_logs = PMA_DBI_fetch_result(
  414. 'SHOW MASTER LOGS',
  415. 'Log_name',
  416. null,
  417. null,
  418. PMA_DBI_QUERY_STORE
  419. );
  420. }
  421. $tabs = array();
  422. $tabs['databases']['icon'] = 's_db.png';
  423. $tabs['databases']['link'] = 'server_databases.php';
  424. $tabs['databases']['text'] = __('Databases');
  425. $tabs['sql']['icon'] = 'b_sql.png';
  426. $tabs['sql']['link'] = 'server_sql.php';
  427. $tabs['sql']['text'] = __('SQL');
  428. $tabs['status']['icon'] = 's_status.png';
  429. $tabs['status']['link'] = 'server_status.php';
  430. $tabs['status']['text'] = __('Status');
  431. $tabs['status']['active'] = in_array(
  432. basename($GLOBALS['PMA_PHP_SELF']),
  433. array(
  434. 'server_status.php',
  435. 'server_status_advisor.php',
  436. 'server_status_monitor.php',
  437. 'server_status_queries.php',
  438. 'server_status_variables.php'
  439. )
  440. );
  441. if ($is_superuser && ! PMA_DRIZZLE) {
  442. $tabs['rights']['icon'] = 's_rights.png';
  443. $tabs['rights']['link'] = 'server_privileges.php';
  444. $tabs['rights']['text'] = __('Users');
  445. }
  446. $tabs['export']['icon'] = 'b_export.png';
  447. $tabs['export']['link'] = 'server_export.php';
  448. $tabs['export']['text'] = __('Export');
  449. $tabs['import']['icon'] = 'b_import.png';
  450. $tabs['import']['link'] = 'server_import.php';
  451. $tabs['import']['text'] = __('Import');
  452. $tabs['settings']['icon'] = 'b_tblops.png';
  453. $tabs['settings']['link'] = 'prefs_manage.php';
  454. $tabs['settings']['text'] = __('Settings');
  455. $tabs['settings']['active'] = in_array(
  456. basename($GLOBALS['PMA_PHP_SELF']),
  457. array('prefs_forms.php', 'prefs_manage.php')
  458. );
  459. if (! empty($binary_logs)) {
  460. $tabs['binlog']['icon'] = 's_tbl.png';
  461. $tabs['binlog']['link'] = 'server_binlog.php';
  462. $tabs['binlog']['text'] = __('Binary log');
  463. }
  464. if ($is_superuser && ! PMA_DRIZZLE) {
  465. $tabs['replication']['icon'] = 's_replication.png';
  466. $tabs['replication']['link'] = 'server_replication.php';
  467. $tabs['replication']['text'] = __('Replication');
  468. }
  469. $tabs['vars']['icon'] = 's_vars.png';
  470. $tabs['vars']['link'] = 'server_variables.php';
  471. $tabs['vars']['text'] = __('Variables');
  472. $tabs['charset']['icon'] = 's_asci.png';
  473. $tabs['charset']['link'] = 'server_collations.php';
  474. $tabs['charset']['text'] = __('Charsets');
  475. if (defined('PMA_DRIZZLE') && PMA_DRIZZLE) {
  476. $tabs['plugins']['icon'] = 'b_engine.png';
  477. $tabs['plugins']['link'] = 'server_plugins.php';
  478. $tabs['plugins']['text'] = __('Plugins');
  479. } else {
  480. $tabs['engine']['icon'] = 'b_engine.png';
  481. $tabs['engine']['link'] = 'server_engines.php';
  482. $tabs['engine']['text'] = __('Engines');
  483. }
  484. return $tabs;
  485. }
  486. }
  487. ?>