Translated using Weblate (Turkish)
[phpmyadmin.git] / libraries / Menu.class.php
blob824038ccb65026275884a8838afc9397e5136f8b
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 int
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 public function __construct($server, $db, $table)
50 $this->_server = $server;
51 $this->_db = $db;
52 $this->_table = $table;
55 /**
56 * Prints the menu and the breadcrumbs
58 * @return void
60 public function display()
62 echo $this->getDisplay();
65 /**
66 * Returns the menu and the breadcrumbs as a string
68 * @return string
70 public function getDisplay()
72 $retval = $this->_getBreadcrumbs();
73 $retval .= $this->_getMenu();
74 return $retval;
77 /**
78 * Returns hash for the menu and the breadcrumbs
80 * @return string
82 public function getHash()
84 return substr(
85 md5($this->_getMenu() . $this->_getBreadcrumbs()),
91 /**
92 * Returns the menu as HTML
94 * @return string HTML formatted menubar
96 private function _getMenu()
98 $url_params = array('db' => $this->_db);
99 $level = '';
101 if (strlen($this->_table)) {
102 $tabs = $this->_getTableTabs();
103 $url_params['table'] = $this->_table;
104 $level = 'table';
105 } else if (strlen($this->_db)) {
106 $tabs = $this->_getDbTabs();
107 $level = 'db';
108 } else {
109 $tabs = $this->_getServerTabs();
110 $level = 'server';
113 $allowedTabs = $this->_getAllowedTabs($level);
114 foreach ($tabs as $key => $value) {
115 if (! array_key_exists($key, $allowedTabs)) {
116 unset($tabs[$key]);
119 return PMA_Util::getHtmlTabs($tabs, $url_params, 'topmenu', true);
123 * Returns a list of allowed tabs for the current user for the given level
125 * @param string $level 'server', 'db' or 'table' level
127 * @return array list of allowed tabs
129 private function _getAllowedTabs($level)
131 $allowedTabs = PMA_Util::getMenuTabList($level);
132 $cfgRelation = PMA_getRelationsParam();
133 if ($cfgRelation['menuswork']) {
134 $groupTable = PMA_Util::backquote($GLOBALS['cfg']['Server']['pmadb'])
135 . "."
136 . PMA_Util::backquote($GLOBALS['cfg']['Server']['usergroups']);
137 $userTable = PMA_Util::backquote($GLOBALS['cfg']['Server']['pmadb'])
138 . "." . PMA_Util::backquote($GLOBALS['cfg']['Server']['users']);
140 $sql_query = "SELECT `tab` FROM " . $groupTable
141 . " WHERE `allowed` = 'N'"
142 . " AND `tab` LIKE '" . $level . "%'"
143 . " AND `usergroup` = (SELECT usergroup FROM "
144 . $userTable . " WHERE `username` = '"
145 . PMA_Util::sqlAddSlashes($GLOBALS['cfg']['Server']['user']) . "')";
147 $result = PMA_queryAsControlUser($sql_query, false);
148 if ($result) {
149 while ($row = $GLOBALS['dbi']->fetchAssoc($result)) {
150 $tabName = substr($row['tab'], strpos($row['tab'], '_') + 1);
151 unset($allowedTabs[$tabName]);
155 return $allowedTabs;
159 * Returns the breadcrumbs as HTML
161 * @return string HTML formatted breadcrumbs
163 private function _getBreadcrumbs()
165 $retval = '';
166 $tbl_is_view = PMA_Table::isView($this->_db, $this->_table);
167 $server_info = ! empty($GLOBALS['cfg']['Server']['verbose'])
168 ? $GLOBALS['cfg']['Server']['verbose']
169 : $GLOBALS['cfg']['Server']['host'];
170 $server_info .= empty($GLOBALS['cfg']['Server']['port'])
171 ? ''
172 : ':' . $GLOBALS['cfg']['Server']['port'];
174 $separator = "<span class='separator item'>&nbsp;ยป</span>";
175 $item = '<a href="%1$s?%2$s" class="item">';
177 if (PMA_Util::showText('TabsMode')) {
178 $item .= '%4$s: ';
180 $item .= '%3$s</a>';
181 $retval .= "<div id='floating_menubar'></div>";
182 $retval .= "<div id='serverinfo'>";
183 if (PMA_Util::showIcons('TabsMode')) {
184 $retval .= PMA_Util::getImage(
185 's_host.png',
187 array('class' => 'item')
190 $retval .= sprintf(
191 $item,
192 $GLOBALS['cfg']['DefaultTabServer'],
193 PMA_URL_getCommon(),
194 htmlspecialchars($server_info),
195 __('Server')
198 if (strlen($this->_db)) {
199 $retval .= $separator;
200 if (PMA_Util::showIcons('TabsMode')) {
201 $retval .= PMA_Util::getImage(
202 's_db.png',
204 array('class' => 'item')
207 $retval .= sprintf(
208 $item,
209 $GLOBALS['cfg']['DefaultTabDatabase'],
210 PMA_URL_getCommon($this->_db),
211 htmlspecialchars($this->_db),
212 __('Database')
214 // if the table is being dropped, $_REQUEST['purge'] is set to '1'
215 // so do not display the table name in upper div
216 if (strlen($this->_table)
217 && ! (isset($_REQUEST['purge']) && $_REQUEST['purge'] == '1')
219 include './libraries/tbl_info.inc.php';
221 $retval .= $separator;
222 if (PMA_Util::showIcons('TabsMode')) {
223 $icon = $tbl_is_view ? 'b_views.png' : 's_tbl.png';
224 $retval .= PMA_Util::getImage(
225 $icon,
227 array('class' => 'item')
230 $retval .= sprintf(
231 $item,
232 $GLOBALS['cfg']['DefaultTabTable'],
233 PMA_URL_getCommon($this->_db, $this->_table),
234 str_replace(' ', '&nbsp;', htmlspecialchars($this->_table)),
235 $tbl_is_view ? __('View') : __('Table')
239 * Displays table comment
241 if (! empty($show_comment)
242 && ! isset($GLOBALS['avoid_show_comment'])
244 if (strstr($show_comment, '; InnoDB free')) {
245 $show_comment = preg_replace(
246 '@; InnoDB free:.*?$@',
248 $show_comment
251 $retval .= '<span class="table_comment"';
252 $retval .= ' id="span_table_comment">&quot;';
253 $retval .= htmlspecialchars($show_comment);
254 $retval .= '&quot;</span>';
255 } // end if
256 } else {
257 // no table selected, display database comment if present
258 $cfgRelation = PMA_getRelationsParam();
260 // Get additional information about tables for tooltip is done
261 // in libraries/db_info.inc.php only once
262 if ($cfgRelation['commwork']) {
263 $comment = PMA_getDbComment($this->_db);
265 * Displays table comment
267 if (! empty($comment)) {
268 $retval .= '<span class="table_comment"'
269 . ' id="span_table_comment">&quot;'
270 . htmlspecialchars($comment)
271 . '&quot;</span>';
272 } // end if
276 $retval .= '<div class="clearfloat"></div>';
277 $retval .= '</div>';
278 return $retval;
282 * Returns the table tabs as an array
284 * @return array Data for generating table tabs
286 private function _getTableTabs()
288 $db_is_system_schema = $GLOBALS['dbi']->isSystemSchema($this->_db);
289 $tbl_is_view = PMA_Table::isView($this->_db, $this->_table);
290 $is_superuser = $GLOBALS['dbi']->isSuperuser();
291 $isCreateOrGrantUser = $GLOBALS['dbi']->isUserType('grant')
292 || $GLOBALS['dbi']->isUserType('create');
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_system_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_system_schema) {
332 $tabs['import']['icon'] = 'b_tblimport.png';
333 $tabs['import']['link'] = 'tbl_import.php';
334 $tabs['import']['text'] = __('Import');
336 if (($is_superuser || $isCreateOrGrantUser)
337 && ! PMA_DRIZZLE && ! $db_is_system_schema
339 $tabs['privileges']['link'] = 'server_privileges.php';
340 $tabs['privileges']['args']['checkprivsdb'] = $this->_db;
341 $tabs['privileges']['args']['checkprivstable'] = $this->_table;
342 // stay on table view
343 $tabs['privileges']['args']['viewing_mode'] = 'table';
344 $tabs['privileges']['text'] = __('Privileges');
345 $tabs['privileges']['icon'] = 's_rights.png';
348 * Don't display "Operations" for views and information_schema
350 if (! $tbl_is_view && ! $db_is_system_schema) {
351 $tabs['operation']['icon'] = 'b_tblops.png';
352 $tabs['operation']['link'] = 'tbl_operations.php';
353 $tabs['operation']['text'] = __('Operations');
355 if (PMA_Tracker::isActive()) {
356 $tabs['tracking']['icon'] = 'eye.png';
357 $tabs['tracking']['text'] = __('Tracking');
358 $tabs['tracking']['link'] = 'tbl_tracking.php';
360 if (! $db_is_system_schema
361 && ! PMA_DRIZZLE
362 && PMA_Util::currentUserHasPrivilege(
363 'TRIGGER',
364 $this->_db,
365 $this->_table
367 && ! $tbl_is_view
369 $tabs['triggers']['link'] = 'tbl_triggers.php';
370 $tabs['triggers']['text'] = __('Triggers');
371 $tabs['triggers']['icon'] = 'b_triggers.png';
375 * Views support a limited number of operations
377 if ($tbl_is_view && ! $db_is_system_schema) {
378 $tabs['operation']['icon'] = 'b_tblops.png';
379 $tabs['operation']['link'] = 'view_operations.php';
380 $tabs['operation']['text'] = __('Operations');
383 return $tabs;
387 * Returns the db tabs as an array
389 * @return array Data for generating db tabs
391 private function _getDbTabs()
393 $db_is_system_schema = $GLOBALS['dbi']->isSystemSchema($this->_db);
394 $num_tables = count($GLOBALS['dbi']->getTables($this->_db));
395 $is_superuser = $GLOBALS['dbi']->isSuperuser();
396 $isCreateOrGrantUser = $GLOBALS['dbi']->isUserType('grant')
397 || $GLOBALS['dbi']->isUserType('create');
400 * Gets the relation settings
402 $cfgRelation = PMA_getRelationsParam();
404 $tabs = array();
406 $tabs['structure']['link'] = 'db_structure.php';
407 $tabs['structure']['text'] = __('Structure');
408 $tabs['structure']['icon'] = 'b_props.png';
410 $tabs['sql']['link'] = 'db_sql.php';
411 $tabs['sql']['text'] = __('SQL');
412 $tabs['sql']['icon'] = 'b_sql.png';
414 $tabs['search']['text'] = __('Search');
415 $tabs['search']['icon'] = 'b_search.png';
416 $tabs['search']['link'] = 'db_search.php';
417 if ($num_tables == 0) {
418 $tabs['search']['warning'] = __('Database seems to be empty!');
421 $tabs['qbe']['text'] = __('Query');
422 $tabs['qbe']['icon'] = 's_db.png';
423 $tabs['qbe']['link'] = 'db_qbe.php';
424 if ($num_tables == 0) {
425 $tabs['qbe']['warning'] = __('Database seems to be empty!');
428 $tabs['export']['text'] = __('Export');
429 $tabs['export']['icon'] = 'b_export.png';
430 $tabs['export']['link'] = 'db_export.php';
431 if ($num_tables == 0) {
432 $tabs['export']['warning'] = __('Database seems to be empty!');
435 if (! $db_is_system_schema) {
436 $tabs['import']['link'] = 'db_import.php';
437 $tabs['import']['text'] = __('Import');
438 $tabs['import']['icon'] = 'b_import.png';
440 $tabs['operation']['link'] = 'db_operations.php';
441 $tabs['operation']['text'] = __('Operations');
442 $tabs['operation']['icon'] = 'b_tblops.png';
444 if (($is_superuser || $isCreateOrGrantUser) && ! PMA_DRIZZLE) {
445 $tabs['privileges']['link'] = 'server_privileges.php';
446 $tabs['privileges']['args']['checkprivsdb'] = $this->_db;
447 // stay on database view
448 $tabs['privileges']['args']['viewing_mode'] = 'db';
449 $tabs['privileges']['text'] = __('Privileges');
450 $tabs['privileges']['icon'] = 's_rights.png';
452 if (! PMA_DRIZZLE) {
453 $tabs['routines']['link'] = 'db_routines.php';
454 $tabs['routines']['text'] = __('Routines');
455 $tabs['routines']['icon'] = 'b_routines.png';
457 if (PMA_MYSQL_INT_VERSION >= 50106
458 && ! PMA_DRIZZLE
459 && PMA_Util::currentUserHasPrivilege('EVENT', $this->_db)
461 $tabs['events']['link'] = 'db_events.php';
462 $tabs['events']['text'] = __('Events');
463 $tabs['events']['icon'] = 'b_events.png';
465 if (! PMA_DRIZZLE
466 && PMA_Util::currentUserHasPrivilege('TRIGGER', $this->_db)
468 $tabs['triggers']['link'] = 'db_triggers.php';
469 $tabs['triggers']['text'] = __('Triggers');
470 $tabs['triggers']['icon'] = 'b_triggers.png';
474 if (PMA_Tracker::isActive()) {
475 $tabs['tracking']['text'] = __('Tracking');
476 $tabs['tracking']['icon'] = 'eye.png';
477 $tabs['tracking']['link'] = 'db_tracking.php';
480 if (! $db_is_system_schema) {
481 $tabs['designer']['text'] = __('Designer');
482 $tabs['designer']['icon'] = 'b_relations.png';
483 $tabs['designer']['link'] = 'db_designer.php';
484 $tabs['designer']['id'] = 'designer_tab';
487 if (! $db_is_system_schema && $cfgRelation['central_columnswork']) {
488 $tabs['central_columns']['text'] = __('Central columns');
489 $tabs['central_columns']['icon'] = 'centralColumns.png';
490 $tabs['central_columns']['link'] = 'db_central_columns.php';
492 return $tabs;
496 * Returns the server tabs as an array
498 * @return array Data for generating server tabs
500 private function _getServerTabs()
502 $is_superuser = isset($GLOBALS['dbi']) && $GLOBALS['dbi']->isSuperuser();
503 $isCreateOrGrantUser = $GLOBALS['dbi']->isUserType('grant')
504 || $GLOBALS['dbi']->isUserType('create');
505 $binary_logs = null;
506 $notDrizzle = ! defined('PMA_DRIZZLE')
507 || (defined('PMA_DRIZZLE') && ! PMA_DRIZZLE);
508 if (isset($GLOBALS['dbi']) && $notDrizzle) {
509 $binary_logs = $GLOBALS['dbi']->fetchResult(
510 'SHOW MASTER LOGS',
511 'Log_name',
512 null,
513 null,
514 PMA_DatabaseInterface::QUERY_STORE
518 $tabs = array();
520 $tabs['databases']['icon'] = 's_db.png';
521 $tabs['databases']['link'] = 'server_databases.php';
522 $tabs['databases']['text'] = __('Databases');
524 $tabs['sql']['icon'] = 'b_sql.png';
525 $tabs['sql']['link'] = 'server_sql.php';
526 $tabs['sql']['text'] = __('SQL');
528 $tabs['status']['icon'] = 's_status.png';
529 $tabs['status']['link'] = 'server_status.php';
530 $tabs['status']['text'] = __('Status');
531 $tabs['status']['active'] = in_array(
532 basename($GLOBALS['PMA_PHP_SELF']),
533 array(
534 'server_status.php',
535 'server_status_advisor.php',
536 'server_status_monitor.php',
537 'server_status_queries.php',
538 'server_status_variables.php'
542 if (($is_superuser || $isCreateOrGrantUser) && ! PMA_DRIZZLE) {
543 $tabs['rights']['icon'] = 's_rights.png';
544 $tabs['rights']['link'] = 'server_privileges.php';
545 $tabs['rights']['text'] = __('Users');
546 $tabs['rights']['active'] = in_array(
547 basename($GLOBALS['PMA_PHP_SELF']),
548 array('server_privileges.php', 'server_user_groups.php')
550 $tabs['rights']['args']['viewing_mode'] = 'server';
553 $tabs['export']['icon'] = 'b_export.png';
554 $tabs['export']['link'] = 'server_export.php';
555 $tabs['export']['text'] = __('Export');
557 $tabs['import']['icon'] = 'b_import.png';
558 $tabs['import']['link'] = 'server_import.php';
559 $tabs['import']['text'] = __('Import');
561 $tabs['settings']['icon'] = 'b_tblops.png';
562 $tabs['settings']['link'] = 'prefs_manage.php';
563 $tabs['settings']['text'] = __('Settings');
564 $tabs['settings']['active'] = in_array(
565 basename($GLOBALS['PMA_PHP_SELF']),
566 array('prefs_forms.php', 'prefs_manage.php')
569 if (! empty($binary_logs)) {
570 $tabs['binlog']['icon'] = 's_tbl.png';
571 $tabs['binlog']['link'] = 'server_binlog.php';
572 $tabs['binlog']['text'] = __('Binary log');
575 if ($is_superuser && ! PMA_DRIZZLE) {
576 $tabs['replication']['icon'] = 's_replication.png';
577 $tabs['replication']['link'] = 'server_replication.php';
578 $tabs['replication']['text'] = __('Replication');
581 $tabs['vars']['icon'] = 's_vars.png';
582 $tabs['vars']['link'] = 'server_variables.php';
583 $tabs['vars']['text'] = __('Variables');
585 $tabs['charset']['icon'] = 's_asci.png';
586 $tabs['charset']['link'] = 'server_collations.php';
587 $tabs['charset']['text'] = __('Charsets');
589 if (defined('PMA_DRIZZLE') && PMA_DRIZZLE) {
590 $tabs['plugins']['icon'] = 'b_engine.png';
591 $tabs['plugins']['link'] = 'server_plugins.php';
592 $tabs['plugins']['text'] = __('Plugins');
593 } else {
594 $tabs['engine']['icon'] = 'b_engine.png';
595 $tabs['engine']['link'] = 'server_engines.php';
596 $tabs['engine']['text'] = __('Engines');
598 return $tabs;