1. Check existence of mb_string, mysql and xml extensions before installation.
[openemr.git] / phpmyadmin / libraries / Menu.class.php
blobd2e8ca12b9c2fe723e1f8aada2878957d3149b69
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);
100 if (/*overload*/mb_strlen($this->_table)) {
101 $tabs = $this->_getTableTabs();
102 $url_params['table'] = $this->_table;
103 $level = 'table';
104 } else if (/*overload*/mb_strlen($this->_db)) {
105 $tabs = $this->_getDbTabs();
106 $level = 'db';
107 } else {
108 $tabs = $this->_getServerTabs();
109 $level = 'server';
112 $allowedTabs = $this->_getAllowedTabs($level);
113 foreach ($tabs as $key => $value) {
114 if (! array_key_exists($key, $allowedTabs)) {
115 unset($tabs[$key]);
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'])
134 . "."
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);
147 if ($result) {
148 while ($row = $GLOBALS['dbi']->fetchAssoc($result)) {
149 $tabName = /*overload*/mb_substr(
150 $row['tab'],
151 /*overload*/mb_strpos($row['tab'], '_') + 1
153 unset($allowedTabs[$tabName]);
157 return $allowedTabs;
161 * Returns the breadcrumbs as HTML
163 * @return string HTML formatted breadcrumbs
165 private function _getBreadcrumbs()
167 $retval = '';
168 $tbl_is_view = $GLOBALS['dbi']->getTable($this->_db, $this->_table)
169 ->isView();
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'])
177 ? ''
178 : ':' . $GLOBALS['cfg']['Server']['port'];
180 $separator = "<span class='separator item'>&nbsp;ยป</span>";
181 $item = '<a href="%1$s%2$s" class="item">';
183 if (PMA_Util::showText('TabsMode')) {
184 $item .= '%4$s: ';
186 $item .= '%3$s</a>';
187 $retval .= "<div id='floating_menubar'></div>";
188 $retval .= "<div id='serverinfo'>";
189 if (PMA_Util::showIcons('TabsMode')) {
190 $retval .= PMA_Util::getImage(
191 's_host.png',
193 array('class' => 'item')
196 $retval .= sprintf(
197 $item,
198 PMA_Util::getScriptNameForOption(
199 $GLOBALS['cfg']['DefaultTabServer'], 'server'
201 PMA_URL_getCommon(),
202 htmlspecialchars($server_info),
203 __('Server')
206 if (/*overload*/mb_strlen($this->_db)) {
207 $retval .= $separator;
208 if (PMA_Util::showIcons('TabsMode')) {
209 $retval .= PMA_Util::getImage(
210 's_db.png',
212 array('class' => 'item')
215 $retval .= sprintf(
216 $item,
217 PMA_Util::getScriptNameForOption(
218 $GLOBALS['cfg']['DefaultTabDatabase'], 'database'
220 PMA_URL_getCommon(array('db' => $this->_db)),
221 htmlspecialchars($this->_db),
222 __('Database')
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(
235 $icon,
237 array('class' => 'item')
240 $retval .= sprintf(
241 $item,
242 PMA_Util::getScriptNameForOption(
243 $GLOBALS['cfg']['DefaultTabTable'], 'table'
245 PMA_URL_getCommon(
246 array(
247 'db' => $this->_db, 'table' => $this->_table
250 str_replace(' ', '&nbsp;', 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:.*?$@',
264 $show_comment
267 $retval .= '<span class="table_comment"';
268 $retval .= ' id="span_table_comment">&quot;';
269 $retval .= htmlspecialchars($show_comment);
270 $retval .= '&quot;</span>';
271 } // end if
272 } else {
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">&quot;'
286 . htmlspecialchars($comment)
287 . '&quot;</span>';
288 } // end if
292 $retval .= '<div class="clearfloat"></div>';
293 $retval .= '</div>';
294 return $retval;
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)
306 ->isView();
307 $is_superuser = $GLOBALS['dbi']->isSuperuser();
308 $isCreateOrGrantUser = $GLOBALS['dbi']->isUserType('grant')
309 || $GLOBALS['dbi']->isUserType('create');
311 $tabs = array();
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
391 && ! PMA_DRIZZLE
392 && PMA_Util::currentUserHasPrivilege(
393 'TRIGGER',
394 $this->_db,
395 $this->_table
397 && ! $tbl_is_view
399 $tabs['triggers']['link'] = 'tbl_triggers.php';
400 $tabs['triggers']['text'] = __('Triggers');
401 $tabs['triggers']['icon'] = 'b_triggers.png';
404 return $tabs;
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();
425 $tabs = array();
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';
473 if (! PMA_DRIZZLE) {
474 $tabs['routines']['link'] = 'db_routines.php';
475 $tabs['routines']['text'] = __('Routines');
476 $tabs['routines']['icon'] = 'b_routines.png';
478 if (! PMA_DRIZZLE
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';
485 if (! PMA_DRIZZLE
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';
514 return $tabs;
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');
527 $binary_logs = null;
528 if (! defined('PMA_DRIZZLE') || ! PMA_DRIZZLE) {
529 if (PMA_Util::cacheExists('binary_logs')) {
530 $binary_logs = PMA_Util::cacheGet('binary_logs');
531 } else {
532 $binary_logs = $GLOBALS['dbi']->fetchResult(
533 'SHOW MASTER LOGS',
534 'Log_name',
535 null,
536 null,
537 PMA_DatabaseInterface::QUERY_STORE
539 PMA_Util::cacheSet('binary_logs', $binary_logs);
543 $tabs = array();
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']),
558 array(
559 'server_status.php',
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']),
621 array(
622 'server_plugins.php',
623 'server_modules.php',
626 } else {
627 $tabs['engine']['icon'] = 'b_engine.png';
628 $tabs['engine']['link'] = 'server_engines.php';
629 $tabs['engine']['text'] = __('Engines');
631 return $tabs;
635 * Set current table
637 * @param string $table Current table
639 * @return $this
641 public function setTable($table)
643 $this->_table = $table;
644 return $this;