2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * Generates and renders the top menu
8 if (! defined('PHPMYADMIN')) {
13 * Class for generating the top menu
42 * Creates a new instance of PMA_Menu
44 * @param int $server Server id
45 * @param string $db Database name
46 * @param string $table Table name
48 public function __construct($server, $db, $table)
50 $this->_server
= $server;
52 $this->_table
= $table;
56 * Prints the menu and the breadcrumbs
60 public function display()
62 echo $this->getDisplay();
66 * Returns the menu and the breadcrumbs as a string
70 public function getDisplay()
72 $retval = $this->_getBreadcrumbs();
73 $retval .= $this->_getMenu();
78 * Returns hash for the menu and the breadcrumbs
82 public function getHash()
85 md5($this->_getMenu() . $this->_getBreadcrumbs()),
92 * Returns the menu as HTML
94 * @return string HTML formatted menubar
96 private function _getMenu()
98 $url_params = array('db' => $this->_db
);
100 if (/*overload*/mb_strlen($this->_table
)) {
101 $tabs = $this->_getTableTabs();
102 $url_params['table'] = $this->_table
;
104 } else if (/*overload*/mb_strlen($this->_db
)) {
105 $tabs = $this->_getDbTabs();
108 $tabs = $this->_getServerTabs();
112 $allowedTabs = $this->_getAllowedTabs($level);
113 foreach ($tabs as $key => $value) {
114 if (! array_key_exists($key, $allowedTabs)) {
118 return PMA_Util
::getHtmlTabs($tabs, $url_params, 'topmenu', true);
122 * Returns a list of allowed tabs for the current user for the given level
124 * @param string $level 'server', 'db' or 'table' level
126 * @return array list of allowed tabs
128 private function _getAllowedTabs($level)
130 $allowedTabs = PMA_Util
::getMenuTabList($level);
131 $cfgRelation = PMA_getRelationsParam();
132 if ($cfgRelation['menuswork']) {
133 $groupTable = PMA_Util
::backquote($cfgRelation['db'])
135 . PMA_Util
::backquote($cfgRelation['usergroups']);
136 $userTable = PMA_Util
::backquote($cfgRelation['db'])
137 . "." . PMA_Util
::backquote($cfgRelation['users']);
139 $sql_query = "SELECT `tab` FROM " . $groupTable
140 . " WHERE `allowed` = 'N'"
141 . " AND `tab` LIKE '" . $level . "%'"
142 . " AND `usergroup` = (SELECT usergroup FROM "
143 . $userTable . " WHERE `username` = '"
144 . PMA_Util
::sqlAddSlashes($GLOBALS['cfg']['Server']['user']) . "')";
146 $result = PMA_queryAsControlUser($sql_query, false);
148 while ($row = $GLOBALS['dbi']->fetchAssoc($result)) {
149 $tabName = /*overload*/mb_substr(
151 /*overload*/mb_strpos($row['tab'], '_') +
1
153 unset($allowedTabs[$tabName]);
161 * Returns the breadcrumbs as HTML
163 * @return string HTML formatted breadcrumbs
165 private function _getBreadcrumbs()
168 $tbl_is_view = $GLOBALS['dbi']->getTable($this->_db
, $this->_table
)
170 if (empty($GLOBALS['cfg']['Server']['host'])) {
171 $GLOBALS['cfg']['Server']['host'] = '';
173 $server_info = ! empty($GLOBALS['cfg']['Server']['verbose'])
174 ?
$GLOBALS['cfg']['Server']['verbose']
175 : $GLOBALS['cfg']['Server']['host'];
176 $server_info .= empty($GLOBALS['cfg']['Server']['port'])
178 : ':' . $GLOBALS['cfg']['Server']['port'];
180 $separator = "<span class='separator item'> ยป</span>";
181 $item = '<a href="%1$s%2$s" class="item">';
183 if (PMA_Util
::showText('TabsMode')) {
187 $retval .= "<div id='floating_menubar'></div>";
188 $retval .= "<div id='serverinfo'>";
189 if (PMA_Util
::showIcons('TabsMode')) {
190 $retval .= PMA_Util
::getImage(
193 array('class' => 'item')
198 PMA_Util
::getScriptNameForOption(
199 $GLOBALS['cfg']['DefaultTabServer'], 'server'
202 htmlspecialchars($server_info),
206 if (/*overload*/mb_strlen($this->_db
)) {
207 $retval .= $separator;
208 if (PMA_Util
::showIcons('TabsMode')) {
209 $retval .= PMA_Util
::getImage(
212 array('class' => 'item')
217 PMA_Util
::getScriptNameForOption(
218 $GLOBALS['cfg']['DefaultTabDatabase'], 'database'
220 PMA_URL_getCommon(array('db' => $this->_db
)),
221 htmlspecialchars($this->_db
),
224 // if the table is being dropped, $_REQUEST['purge'] is set to '1'
225 // so do not display the table name in upper div
226 if (/*overload*/mb_strlen($this->_table
)
227 && ! (isset($_REQUEST['purge']) && $_REQUEST['purge'] == '1')
229 include './libraries/tbl_info.inc.php';
231 $retval .= $separator;
232 if (PMA_Util
::showIcons('TabsMode')) {
233 $icon = $tbl_is_view ?
'b_views.png' : 's_tbl.png';
234 $retval .= PMA_Util
::getImage(
237 array('class' => 'item')
242 PMA_Util
::getScriptNameForOption(
243 $GLOBALS['cfg']['DefaultTabTable'], 'table'
247 'db' => $this->_db
, 'table' => $this->_table
250 str_replace(' ', ' ', htmlspecialchars($this->_table
)),
251 $tbl_is_view ?
__('View') : __('Table')
255 * Displays table comment
257 if (! empty($show_comment)
258 && ! isset($GLOBALS['avoid_show_comment'])
260 if (/*overload*/mb_strstr($show_comment, '; InnoDB free')) {
261 $show_comment = preg_replace(
262 '@; InnoDB free:.*?$@',
267 $retval .= '<span class="table_comment"';
268 $retval .= ' id="span_table_comment">"';
269 $retval .= htmlspecialchars($show_comment);
270 $retval .= '"</span>';
273 // no table selected, display database comment if present
274 $cfgRelation = PMA_getRelationsParam();
276 // Get additional information about tables for tooltip is done
277 // in PMA_Util::getDbInfo() only once
278 if ($cfgRelation['commwork']) {
279 $comment = PMA_getDbComment($this->_db
);
281 * Displays table comment
283 if (! empty($comment)) {
284 $retval .= '<span class="table_comment"'
285 . ' id="span_table_comment">"'
286 . htmlspecialchars($comment)
292 $retval .= '<div class="clearfloat"></div>';
298 * Returns the table tabs as an array
300 * @return array Data for generating table tabs
302 private function _getTableTabs()
304 $db_is_system_schema = $GLOBALS['dbi']->isSystemSchema($this->_db
);
305 $tbl_is_view = $GLOBALS['dbi']->getTable($this->_db
, $this->_table
)
307 $is_superuser = $GLOBALS['dbi']->isSuperuser();
308 $isCreateOrGrantUser = $GLOBALS['dbi']->isUserType('grant')
309 ||
$GLOBALS['dbi']->isUserType('create');
313 $tabs['browse']['icon'] = 'b_browse.png';
314 $tabs['browse']['text'] = __('Browse');
315 $tabs['browse']['link'] = 'sql.php';
316 $tabs['browse']['args']['pos'] = 0;
318 $tabs['structure']['icon'] = 'b_props.png';
319 $tabs['structure']['link'] = 'tbl_structure.php';
320 $tabs['structure']['text'] = __('Structure');
321 $tabs['structure']['active'] = in_array(
322 basename($GLOBALS['PMA_PHP_SELF']),
323 array('tbl_structure.php', 'tbl_relation.php')
326 $tabs['sql']['icon'] = 'b_sql.png';
327 $tabs['sql']['link'] = 'tbl_sql.php';
328 $tabs['sql']['text'] = __('SQL');
330 $tabs['search']['icon'] = 'b_search.png';
331 $tabs['search']['text'] = __('Search');
332 $tabs['search']['link'] = 'tbl_select.php';
333 $tabs['search']['active'] = in_array(
334 basename($GLOBALS['PMA_PHP_SELF']),
335 array('tbl_select.php', 'tbl_zoom_select.php', 'tbl_find_replace.php')
338 if (! $db_is_system_schema) {
339 $tabs['insert']['icon'] = 'b_insrow.png';
340 $tabs['insert']['link'] = 'tbl_change.php';
341 $tabs['insert']['text'] = __('Insert');
344 $tabs['export']['icon'] = 'b_tblexport.png';
345 $tabs['export']['link'] = 'tbl_export.php';
346 $tabs['export']['args']['single_table'] = 'true';
347 $tabs['export']['text'] = __('Export');
350 * Don't display "Import" for views and information_schema
352 if (! $tbl_is_view && ! $db_is_system_schema) {
353 $tabs['import']['icon'] = 'b_tblimport.png';
354 $tabs['import']['link'] = 'tbl_import.php';
355 $tabs['import']['text'] = __('Import');
357 if (($is_superuser ||
$isCreateOrGrantUser)
358 && ! PMA_DRIZZLE
&& ! $db_is_system_schema
360 $tabs['privileges']['link'] = 'server_privileges.php';
361 $tabs['privileges']['args']['checkprivsdb'] = $this->_db
;
362 $tabs['privileges']['args']['checkprivstable'] = $this->_table
;
363 // stay on table view
364 $tabs['privileges']['args']['viewing_mode'] = 'table';
365 $tabs['privileges']['text'] = __('Privileges');
366 $tabs['privileges']['icon'] = 's_rights.png';
369 * Don't display "Operations" for views and information_schema
371 if (! $tbl_is_view && ! $db_is_system_schema) {
372 $tabs['operation']['icon'] = 'b_tblops.png';
373 $tabs['operation']['link'] = 'tbl_operations.php';
374 $tabs['operation']['text'] = __('Operations');
377 * Views support a limited number of operations
379 if ($tbl_is_view && ! $db_is_system_schema) {
380 $tabs['operation']['icon'] = 'b_tblops.png';
381 $tabs['operation']['link'] = 'view_operations.php';
382 $tabs['operation']['text'] = __('Operations');
385 if (PMA_Tracker
::isActive()) {
386 $tabs['tracking']['icon'] = 'eye.png';
387 $tabs['tracking']['text'] = __('Tracking');
388 $tabs['tracking']['link'] = 'tbl_tracking.php';
390 if (! $db_is_system_schema
392 && PMA_Util
::currentUserHasPrivilege(
399 $tabs['triggers']['link'] = 'tbl_triggers.php';
400 $tabs['triggers']['text'] = __('Triggers');
401 $tabs['triggers']['icon'] = 'b_triggers.png';
408 * Returns the db tabs as an array
410 * @return array Data for generating db tabs
412 private function _getDbTabs()
414 $db_is_system_schema = $GLOBALS['dbi']->isSystemSchema($this->_db
);
415 $num_tables = count($GLOBALS['dbi']->getTables($this->_db
));
416 $is_superuser = $GLOBALS['dbi']->isSuperuser();
417 $isCreateOrGrantUser = $GLOBALS['dbi']->isUserType('grant')
418 ||
$GLOBALS['dbi']->isUserType('create');
421 * Gets the relation settings
423 $cfgRelation = PMA_getRelationsParam();
427 $tabs['structure']['link'] = 'db_structure.php';
428 $tabs['structure']['text'] = __('Structure');
429 $tabs['structure']['icon'] = 'b_props.png';
431 $tabs['sql']['link'] = 'db_sql.php';
432 $tabs['sql']['text'] = __('SQL');
433 $tabs['sql']['icon'] = 'b_sql.png';
435 $tabs['search']['text'] = __('Search');
436 $tabs['search']['icon'] = 'b_search.png';
437 $tabs['search']['link'] = 'db_search.php';
438 if ($num_tables == 0) {
439 $tabs['search']['warning'] = __('Database seems to be empty!');
442 $tabs['qbe']['text'] = __('Query');
443 $tabs['qbe']['icon'] = 's_db.png';
444 $tabs['qbe']['link'] = 'db_qbe.php';
445 if ($num_tables == 0) {
446 $tabs['qbe']['warning'] = __('Database seems to be empty!');
449 $tabs['export']['text'] = __('Export');
450 $tabs['export']['icon'] = 'b_export.png';
451 $tabs['export']['link'] = 'db_export.php';
452 if ($num_tables == 0) {
453 $tabs['export']['warning'] = __('Database seems to be empty!');
456 if (! $db_is_system_schema) {
457 $tabs['import']['link'] = 'db_import.php';
458 $tabs['import']['text'] = __('Import');
459 $tabs['import']['icon'] = 'b_import.png';
461 $tabs['operation']['link'] = 'db_operations.php';
462 $tabs['operation']['text'] = __('Operations');
463 $tabs['operation']['icon'] = 'b_tblops.png';
465 if (($is_superuser ||
$isCreateOrGrantUser) && ! PMA_DRIZZLE
) {
466 $tabs['privileges']['link'] = 'server_privileges.php';
467 $tabs['privileges']['args']['checkprivsdb'] = $this->_db
;
468 // stay on database view
469 $tabs['privileges']['args']['viewing_mode'] = 'db';
470 $tabs['privileges']['text'] = __('Privileges');
471 $tabs['privileges']['icon'] = 's_rights.png';
474 $tabs['routines']['link'] = 'db_routines.php';
475 $tabs['routines']['text'] = __('Routines');
476 $tabs['routines']['icon'] = 'b_routines.png';
479 && PMA_Util
::currentUserHasPrivilege('EVENT', $this->_db
)
481 $tabs['events']['link'] = 'db_events.php';
482 $tabs['events']['text'] = __('Events');
483 $tabs['events']['icon'] = 'b_events.png';
486 && PMA_Util
::currentUserHasPrivilege('TRIGGER', $this->_db
)
488 $tabs['triggers']['link'] = 'db_triggers.php';
489 $tabs['triggers']['text'] = __('Triggers');
490 $tabs['triggers']['icon'] = 'b_triggers.png';
494 if (PMA_Tracker
::isActive()) {
495 $tabs['tracking']['text'] = __('Tracking');
496 $tabs['tracking']['icon'] = 'eye.png';
497 $tabs['tracking']['link'] = 'db_tracking.php';
500 if (! $db_is_system_schema) {
501 $tabs['designer']['text'] = __('Designer');
502 $tabs['designer']['icon'] = 'b_relations.png';
503 $tabs['designer']['link'] = 'db_designer.php';
504 $tabs['designer']['id'] = 'designer_tab';
507 if (! $db_is_system_schema
508 && $cfgRelation['centralcolumnswork']
510 $tabs['central_columns']['text'] = __('Central columns');
511 $tabs['central_columns']['icon'] = 'centralColumns.png';
512 $tabs['central_columns']['link'] = 'db_central_columns.php';
518 * Returns the server tabs as an array
520 * @return array Data for generating server tabs
522 private function _getServerTabs()
524 $is_superuser = $GLOBALS['dbi']->isSuperuser();
525 $isCreateOrGrantUser = $GLOBALS['dbi']->isUserType('grant')
526 ||
$GLOBALS['dbi']->isUserType('create');
528 if (! defined('PMA_DRIZZLE') ||
! PMA_DRIZZLE
) {
529 if (PMA_Util
::cacheExists('binary_logs')) {
530 $binary_logs = PMA_Util
::cacheGet('binary_logs');
532 $binary_logs = $GLOBALS['dbi']->fetchResult(
537 PMA_DatabaseInterface
::QUERY_STORE
539 PMA_Util
::cacheSet('binary_logs', $binary_logs);
545 $tabs['databases']['icon'] = 's_db.png';
546 $tabs['databases']['link'] = 'server_databases.php';
547 $tabs['databases']['text'] = __('Databases');
549 $tabs['sql']['icon'] = 'b_sql.png';
550 $tabs['sql']['link'] = 'server_sql.php';
551 $tabs['sql']['text'] = __('SQL');
553 $tabs['status']['icon'] = 's_status.png';
554 $tabs['status']['link'] = 'server_status.php';
555 $tabs['status']['text'] = __('Status');
556 $tabs['status']['active'] = in_array(
557 basename($GLOBALS['PMA_PHP_SELF']),
560 'server_status_advisor.php',
561 'server_status_monitor.php',
562 'server_status_queries.php',
563 'server_status_variables.php',
564 'server_status_processes.php'
568 if (($is_superuser ||
$isCreateOrGrantUser) && ! PMA_DRIZZLE
) {
569 $tabs['rights']['icon'] = 's_rights.png';
570 $tabs['rights']['link'] = 'server_privileges.php';
571 $tabs['rights']['text'] = __('User accounts');
572 $tabs['rights']['active'] = in_array(
573 basename($GLOBALS['PMA_PHP_SELF']),
574 array('server_privileges.php', 'server_user_groups.php')
576 $tabs['rights']['args']['viewing_mode'] = 'server';
579 $tabs['export']['icon'] = 'b_export.png';
580 $tabs['export']['link'] = 'server_export.php';
581 $tabs['export']['text'] = __('Export');
583 $tabs['import']['icon'] = 'b_import.png';
584 $tabs['import']['link'] = 'server_import.php';
585 $tabs['import']['text'] = __('Import');
587 $tabs['settings']['icon'] = 'b_tblops.png';
588 $tabs['settings']['link'] = 'prefs_manage.php';
589 $tabs['settings']['text'] = __('Settings');
590 $tabs['settings']['active'] = in_array(
591 basename($GLOBALS['PMA_PHP_SELF']),
592 array('prefs_forms.php', 'prefs_manage.php')
595 if (! empty($binary_logs)) {
596 $tabs['binlog']['icon'] = 's_tbl.png';
597 $tabs['binlog']['link'] = 'server_binlog.php';
598 $tabs['binlog']['text'] = __('Binary log');
601 if ($is_superuser && ! PMA_DRIZZLE
) {
602 $tabs['replication']['icon'] = 's_replication.png';
603 $tabs['replication']['link'] = 'server_replication.php';
604 $tabs['replication']['text'] = __('Replication');
607 $tabs['vars']['icon'] = 's_vars.png';
608 $tabs['vars']['link'] = 'server_variables.php';
609 $tabs['vars']['text'] = __('Variables');
611 $tabs['charset']['icon'] = 's_asci.png';
612 $tabs['charset']['link'] = 'server_collations.php';
613 $tabs['charset']['text'] = __('Charsets');
615 if (defined('PMA_DRIZZLE') && PMA_DRIZZLE
) {
616 $tabs['plugins']['icon'] = 'b_engine.png';
617 $tabs['plugins']['link'] = 'server_plugins.php';
618 $tabs['plugins']['text'] = __('Plugins');
619 $tabs['plugins']['active'] = in_array(
620 basename($GLOBALS['PMA_PHP_SELF']),
622 'server_plugins.php',
623 'server_modules.php',
627 $tabs['engine']['icon'] = 'b_engine.png';
628 $tabs['engine']['link'] = 'server_engines.php';
629 $tabs['engine']['text'] = __('Engines');
637 * @param string $table Current table
641 public function setTable($table)
643 $this->_table
= $table;