Translated using Weblate (Danish)
[phpmyadmin.git] / libraries / Menu.class.php
blob67cec02c94da222371adf2ed7cf739c0be96d41d
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Generates and renders the top menu
6 * @package PhpMyAdmin
7 */
8 if (! defined('PHPMYADMIN')) {
9 exit;
12 /**
13 * Class for generating the top menu
15 * @package PhpMyAdmin
17 class PMA_Menu
19 /**
20 * Server id
22 * @access private
23 * @var string
25 private $_server;
26 /**
27 * Database name
29 * @access private
30 * @var string
32 private $_db;
33 /**
34 * Table name
36 * @access private
37 * @var string
39 private $_table;
41 /**
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 * @return New PMA_Table
50 public function __construct($server, $db, $table)
52 $this->_server = $server;
53 $this->_db = $db;
54 $this->_table = $table;
57 /**
58 * Prints the menu and the breadcrumbs
60 * @return void
62 public function display()
64 echo $this->getDisplay();
67 /**
68 * Returns the menu and the breadcrumbs as a string
70 * @return string
72 public function getDisplay()
74 $retval = $this->_getBreadcrumbs();
75 $retval .= $this->_getMenu();
76 return $retval;
79 /**
80 * Returns hash for the menu and the breadcrumbs
82 * @return string
84 public function getHash()
86 return substr(
87 md5($this->_getMenu() . $this->_getBreadcrumbs()),
93 /**
94 * Returns the menu as HTML
96 * @return string HTML formatted menubar
98 private function _getMenu()
100 $tabs = array();
101 $url_params = array('db' => $this->_db);
102 $level = '';
104 if (strlen($this->_table)) {
105 $tabs = $this->_getTableTabs();
106 $url_params['table'] = $this->_table;
107 $level = 'table';
108 } else if (strlen($this->_db)) {
109 $tabs = $this->_getDbTabs();
110 $level = 'db';
111 } else {
112 $tabs = $this->_getServerTabs();
113 $level = 'server';
116 $allowedTabs = $this->_getAllowedTabs($level);
117 foreach ($tabs as $key => $value) {
118 if (! array_key_exists($key, $allowedTabs)) {
119 unset($tabs[$key]);
122 return PMA_Util::getHtmlTabs($tabs, $url_params, 'topmenu', true);
126 * Returns a list of allowed tabs for the current user for the given level
128 * @param string $level 'server', 'db' or 'table' level
130 * @return array list of allowed tabs
132 private function _getAllowedTabs($level)
134 $allowedTabs = PMA_Util::getMenuTabList($level);
135 $cfgRelation = PMA_getRelationsParam();
136 if ($cfgRelation['menuswork']) {
137 $groupTable = PMA_Util::backquote($GLOBALS['cfg']['Server']['pmadb'])
138 . "."
139 . PMA_Util::backquote($GLOBALS['cfg']['Server']['usergroups']);
140 $userTable = PMA_Util::backquote($GLOBALS['cfg']['Server']['pmadb'])
141 . "." . PMA_Util::backquote($GLOBALS['cfg']['Server']['users']);
143 $sql_query = "SELECT `tab` FROM " . $groupTable
144 . " WHERE `allowed` = 'N' AND `usergroup` = (SELECT usergroup FROM "
145 . $userTable . " WHERE `username` = '"
146 . PMA_Util::sqlAddSlashes($GLOBALS['cfg']['Server']['user']) . "')";
148 $result = PMA_queryAsControlUser($sql_query, false);
149 if ($result) {
150 while ($row = $GLOBALS['dbi']->fetchAssoc($result)) {
151 $tabName = substr($row['tab'], strpos($row['tab'], '_') + 1);
152 unset($allowedTabs[$tabName]);
156 return $allowedTabs;
160 * Returns the breadcrumbs as HTML
162 * @return string HTML formatted breadcrumbs
164 private function _getBreadcrumbs()
166 $retval = '';
167 $tbl_is_view = PMA_Table::isView($this->_db, $this->_table);
168 $server_info = ! empty($GLOBALS['cfg']['Server']['verbose'])
169 ? $GLOBALS['cfg']['Server']['verbose']
170 : $GLOBALS['cfg']['Server']['host'];
171 $server_info .= empty($GLOBALS['cfg']['Server']['port'])
172 ? ''
173 : ':' . $GLOBALS['cfg']['Server']['port'];
175 $separator = "<span class='separator item'>&nbsp;ยป</span>";
176 $item = '<a href="%1$s?%2$s" class="item">';
179 if (PMA_Util::showText('TabsMode')) {
180 $item .= '%4$s: ';
182 $item .= '%3$s</a>';
183 $retval .= "<div id='floating_menubar'></div>";
184 $retval .= "<div id='serverinfo'>";
185 if (PMA_Util::showIcons('TabsMode')) {
186 $retval .= PMA_Util::getImage(
187 's_host.png',
189 array('class' => 'item')
192 $retval .= sprintf(
193 $item,
194 $GLOBALS['cfg']['DefaultTabServer'],
195 PMA_URL_getCommon(),
196 htmlspecialchars($server_info),
197 __('Server')
200 if (strlen($this->_db)) {
201 $retval .= $separator;
202 if (PMA_Util::showIcons('TabsMode')) {
203 $retval .= PMA_Util::getImage(
204 's_db.png',
206 array('class' => 'item')
209 $retval .= sprintf(
210 $item,
211 $GLOBALS['cfg']['DefaultTabDatabase'],
212 PMA_URL_getCommon($this->_db),
213 htmlspecialchars($this->_db),
214 __('Database')
216 // if the table is being dropped, $_REQUEST['purge'] is set to '1'
217 // so do not display the table name in upper div
218 if (strlen($this->_table)
219 && ! (isset($_REQUEST['purge']) && $_REQUEST['purge'] == '1')
221 include './libraries/tbl_info.inc.php';
223 $retval .= $separator;
224 if (PMA_Util::showIcons('TabsMode')) {
225 $icon = $tbl_is_view ? 'b_views.png' : 's_tbl.png';
226 $retval .= PMA_Util::getImage(
227 $icon,
229 array('class' => 'item')
232 $retval .= sprintf(
233 $item,
234 $GLOBALS['cfg']['DefaultTabTable'],
235 PMA_URL_getCommon($this->_db, $this->_table),
236 str_replace(' ', '&nbsp;', htmlspecialchars($this->_table)),
237 $tbl_is_view ? __('View') : __('Table')
241 * Displays table comment
243 if (! empty($show_comment)
244 && ! isset($GLOBALS['avoid_show_comment'])
246 if (strstr($show_comment, '; InnoDB free')) {
247 $show_comment = preg_replace(
248 '@; InnoDB free:.*?$@',
250 $show_comment
253 $retval .= '<span class="table_comment"';
254 $retval .= ' id="span_table_comment">&quot;';
255 $retval .= htmlspecialchars($show_comment);
256 $retval .= '&quot;</span>';
257 } // end if
258 } else {
259 // no table selected, display database comment if present
260 $cfgRelation = PMA_getRelationsParam();
262 // Get additional information about tables for tooltip is done
263 // in libraries/db_info.inc.php only once
264 if ($cfgRelation['commwork']) {
265 $comment = PMA_getDbComment($this->_db);
267 * Displays table comment
269 if (! empty($comment)) {
270 $retval .= '<span class="table_comment"'
271 . ' id="span_table_comment">&quot;'
272 . htmlspecialchars($comment)
273 . '&quot;</span>';
274 } // end if
278 $retval .= '<div class="clearfloat"></div>';
279 $retval .= '</div>';
280 return $retval;
284 * Returns the table tabs as an array
286 * @return array Data for generating table tabs
288 private function _getTableTabs()
290 $db_is_information_schema = $GLOBALS['dbi']->isSystemSchema($this->_db);
291 $tbl_is_view = PMA_Table::isView($this->_db, $this->_table);
292 $is_superuser = $GLOBALS['dbi']->isSuperuser();
294 $tabs = array();
296 $tabs['browse']['icon'] = 'b_browse.png';
297 $tabs['browse']['text'] = __('Browse');
298 $tabs['browse']['link'] = 'sql.php';
299 $tabs['browse']['args']['pos'] = 0;
301 $tabs['structure']['icon'] = 'b_props.png';
302 $tabs['structure']['link'] = 'tbl_structure.php';
303 $tabs['structure']['text'] = __('Structure');
305 $tabs['sql']['icon'] = 'b_sql.png';
306 $tabs['sql']['link'] = 'tbl_sql.php';
307 $tabs['sql']['text'] = __('SQL');
309 $tabs['search']['icon'] = 'b_search.png';
310 $tabs['search']['text'] = __('Search');
311 $tabs['search']['link'] = 'tbl_select.php';
312 $tabs['search']['active'] = in_array(
313 basename($GLOBALS['PMA_PHP_SELF']),
314 array('tbl_select.php', 'tbl_zoom_select.php', 'tbl_find_replace.php')
317 if (! $db_is_information_schema) {
318 $tabs['insert']['icon'] = 'b_insrow.png';
319 $tabs['insert']['link'] = 'tbl_change.php';
320 $tabs['insert']['text'] = __('Insert');
323 $tabs['export']['icon'] = 'b_tblexport.png';
324 $tabs['export']['link'] = 'tbl_export.php';
325 $tabs['export']['args']['single_table'] = 'true';
326 $tabs['export']['text'] = __('Export');
329 * Don't display "Import" for views and information_schema
331 if (! $tbl_is_view && ! $db_is_information_schema) {
332 $tabs['import']['icon'] = 'b_tblimport.png';
333 $tabs['import']['link'] = 'tbl_import.php';
334 $tabs['import']['text'] = __('Import');
336 if ($is_superuser && ! PMA_DRIZZLE && ! $db_is_information_schema) {
337 $tabs['privileges']['link'] = 'server_privileges.php';
338 $tabs['privileges']['args']['checkprivsdb'] = $this->_db;
339 $tabs['privileges']['args']['checkprivstable'] = $this->_table;
340 // stay on table view
341 $tabs['privileges']['args']['viewing_mode'] = 'table';
342 $tabs['privileges']['text'] = __('Privileges');
343 $tabs['privileges']['icon'] = 's_rights.png';
346 * Don't display "Operations" for views and information_schema
348 if (! $tbl_is_view && ! $db_is_information_schema) {
349 $tabs['operation']['icon'] = 'b_tblops.png';
350 $tabs['operation']['link'] = 'tbl_operations.php';
351 $tabs['operation']['text'] = __('Operations');
353 if (PMA_Tracker::isActive()) {
354 $tabs['tracking']['icon'] = 'eye.png';
355 $tabs['tracking']['text'] = __('Tracking');
356 $tabs['tracking']['link'] = 'tbl_tracking.php';
358 if (! $db_is_information_schema
359 && ! PMA_DRIZZLE
360 && PMA_Util::currentUserHasPrivilege(
361 'TRIGGER',
362 $this->_db,
363 $this->_table
365 && ! $tbl_is_view
367 $tabs['triggers']['link'] = 'tbl_triggers.php';
368 $tabs['triggers']['text'] = __('Triggers');
369 $tabs['triggers']['icon'] = 'b_triggers.png';
373 * Views support a limited number of operations
375 if ($tbl_is_view && ! $db_is_information_schema) {
376 $tabs['operation']['icon'] = 'b_tblops.png';
377 $tabs['operation']['link'] = 'view_operations.php';
378 $tabs['operation']['text'] = __('Operations');
381 return $tabs;
385 * Returns the db tabs as an array
387 * @return array Data for generating db tabs
389 private function _getDbTabs()
391 $db_is_information_schema = $GLOBALS['dbi']->isSystemSchema($this->_db);
392 $num_tables = count($GLOBALS['dbi']->getTables($this->_db));
393 $is_superuser = $GLOBALS['dbi']->isSuperuser();
396 * Gets the relation settings
398 $cfgRelation = PMA_getRelationsParam();
400 $tabs = array();
402 $tabs['structure']['link'] = 'db_structure.php';
403 $tabs['structure']['text'] = __('Structure');
404 $tabs['structure']['icon'] = 'b_props.png';
406 $tabs['sql']['link'] = 'db_sql.php';
407 $tabs['sql']['text'] = __('SQL');
408 $tabs['sql']['icon'] = 'b_sql.png';
410 $tabs['search']['text'] = __('Search');
411 $tabs['search']['icon'] = 'b_search.png';
412 $tabs['search']['link'] = 'db_search.php';
413 if ($num_tables == 0) {
414 $tabs['search']['warning'] = __('Database seems to be empty!');
417 $tabs['qbe']['text'] = __('Query');
418 $tabs['qbe']['icon'] = 's_db.png';
419 $tabs['qbe']['link'] = 'db_qbe.php';
420 if ($num_tables == 0) {
421 $tabs['qbe']['warning'] = __('Database seems to be empty!');
424 $tabs['export']['text'] = __('Export');
425 $tabs['export']['icon'] = 'b_export.png';
426 $tabs['export']['link'] = 'db_export.php';
427 if ($num_tables == 0) {
428 $tabs['export']['warning'] = __('Database seems to be empty!');
431 if (! $db_is_information_schema) {
432 $tabs['import']['link'] = 'db_import.php';
433 $tabs['import']['text'] = __('Import');
434 $tabs['import']['icon'] = 'b_import.png';
436 $tabs['operation']['link'] = 'db_operations.php';
437 $tabs['operation']['text'] = __('Operations');
438 $tabs['operation']['icon'] = 'b_tblops.png';
440 if ($is_superuser && ! PMA_DRIZZLE) {
441 $tabs['privileges']['link'] = 'server_privileges.php';
442 $tabs['privileges']['args']['checkprivsdb'] = $this->_db;
443 // stay on database view
444 $tabs['privileges']['args']['viewing_mode'] = 'db';
445 $tabs['privileges']['text'] = __('Privileges');
446 $tabs['privileges']['icon'] = 's_rights.png';
448 if (! PMA_DRIZZLE) {
449 $tabs['routines']['link'] = 'db_routines.php';
450 $tabs['routines']['text'] = __('Routines');
451 $tabs['routines']['icon'] = 'b_routines.png';
453 if (PMA_MYSQL_INT_VERSION >= 50106
454 && ! PMA_DRIZZLE
455 && PMA_Util::currentUserHasPrivilege('EVENT', $this->_db)
457 $tabs['events']['link'] = 'db_events.php';
458 $tabs['events']['text'] = __('Events');
459 $tabs['events']['icon'] = 'b_events.png';
461 if (! PMA_DRIZZLE
462 && PMA_Util::currentUserHasPrivilege('TRIGGER', $this->_db)
464 $tabs['triggers']['link'] = 'db_triggers.php';
465 $tabs['triggers']['text'] = __('Triggers');
466 $tabs['triggers']['icon'] = 'b_triggers.png';
470 if (PMA_Tracker::isActive()) {
471 $tabs['tracking']['text'] = __('Tracking');
472 $tabs['tracking']['icon'] = 'eye.png';
473 $tabs['tracking']['link'] = 'db_tracking.php';
476 if (! $db_is_information_schema && $cfgRelation['designerwork']) {
477 $tabs['designer']['text'] = __('Designer');
478 $tabs['designer']['icon'] = 'b_relations.png';
479 $tabs['designer']['link'] = 'pmd_general.php';
482 return $tabs;
486 * Returns the server tabs as an array
488 * @return array Data for generating server tabs
490 private function _getServerTabs()
492 $is_superuser = isset($GLOBALS['dbi']) && $GLOBALS['dbi']->isSuperuser();
493 $binary_logs = null;
494 $notDrizzle = ! defined('PMA_DRIZZLE')
495 || (defined('PMA_DRIZZLE') && ! PMA_DRIZZLE);
496 if (isset($GLOBALS['dbi']) && $notDrizzle) {
497 $binary_logs = $GLOBALS['dbi']->fetchResult(
498 'SHOW MASTER LOGS',
499 'Log_name',
500 null,
501 null,
502 PMA_DatabaseInterface::QUERY_STORE
506 $tabs = array();
508 $tabs['databases']['icon'] = 's_db.png';
509 $tabs['databases']['link'] = 'server_databases.php';
510 $tabs['databases']['text'] = __('Databases');
512 $tabs['sql']['icon'] = 'b_sql.png';
513 $tabs['sql']['link'] = 'server_sql.php';
514 $tabs['sql']['text'] = __('SQL');
516 $tabs['status']['icon'] = 's_status.png';
517 $tabs['status']['link'] = 'server_status.php';
518 $tabs['status']['text'] = __('Status');
519 $tabs['status']['active'] = in_array(
520 basename($GLOBALS['PMA_PHP_SELF']),
521 array(
522 'server_status.php',
523 'server_status_advisor.php',
524 'server_status_monitor.php',
525 'server_status_queries.php',
526 'server_status_variables.php'
530 if ($is_superuser && ! PMA_DRIZZLE) {
531 $tabs['rights']['icon'] = 's_rights.png';
532 $tabs['rights']['link'] = 'server_privileges.php';
533 $tabs['rights']['text'] = __('Users');
534 $tabs['rights']['active'] = in_array(
535 basename($GLOBALS['PMA_PHP_SELF']),
536 array('server_privileges.php', 'server_user_groups.php')
538 $tabs['rights']['args']['viewing_mode'] = 'server';
541 $tabs['export']['icon'] = 'b_export.png';
542 $tabs['export']['link'] = 'server_export.php';
543 $tabs['export']['text'] = __('Export');
545 $tabs['import']['icon'] = 'b_import.png';
546 $tabs['import']['link'] = 'server_import.php';
547 $tabs['import']['text'] = __('Import');
549 $tabs['settings']['icon'] = 'b_tblops.png';
550 $tabs['settings']['link'] = 'prefs_manage.php';
551 $tabs['settings']['text'] = __('Settings');
552 $tabs['settings']['active'] = in_array(
553 basename($GLOBALS['PMA_PHP_SELF']),
554 array('prefs_forms.php', 'prefs_manage.php')
557 if (! empty($binary_logs)) {
558 $tabs['binlog']['icon'] = 's_tbl.png';
559 $tabs['binlog']['link'] = 'server_binlog.php';
560 $tabs['binlog']['text'] = __('Binary log');
563 if ($is_superuser && ! PMA_DRIZZLE) {
564 $tabs['replication']['icon'] = 's_replication.png';
565 $tabs['replication']['link'] = 'server_replication.php';
566 $tabs['replication']['text'] = __('Replication');
569 $tabs['vars']['icon'] = 's_vars.png';
570 $tabs['vars']['link'] = 'server_variables.php';
571 $tabs['vars']['text'] = __('Variables');
573 $tabs['charset']['icon'] = 's_asci.png';
574 $tabs['charset']['link'] = 'server_collations.php';
575 $tabs['charset']['text'] = __('Charsets');
577 if (defined('PMA_DRIZZLE') && PMA_DRIZZLE) {
578 $tabs['plugins']['icon'] = 'b_engine.png';
579 $tabs['plugins']['link'] = 'server_plugins.php';
580 $tabs['plugins']['text'] = __('Plugins');
581 } else {
582 $tabs['engine']['icon'] = 'b_engine.png';
583 $tabs['engine']['link'] = 'server_engines.php';
584 $tabs['engine']['text'] = __('Engines');
586 return $tabs;