Upgraded phpmyadmin to 4.0.4 (All Languages) - No modifications yet
[openemr.git] / phpmyadmin / libraries / Menu.class.php
blobac5042b2823b83a5707d2d58a91add3fbd7eef9d
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 if (strlen($this->_table)) {
103 $tabs = $this->_getTableTabs();
104 $url_params['table'] = $this->_table;
105 } else if (strlen($this->_db)) {
106 $tabs = $this->_getDbTabs();
107 } else {
108 $tabs = $this->_getServerTabs();
110 return PMA_Util::getHtmlTabs($tabs, $url_params, 'topmenu', true);
114 * Returns the breadcrumbs as HTML
116 * @return string HTML formatted breadcrumbs
118 private function _getBreadcrumbs()
120 $retval = '';
121 $tbl_is_view = PMA_Table::isView($this->_db, $this->_table);
122 $server_info = ! empty($GLOBALS['cfg']['Server']['verbose'])
123 ? $GLOBALS['cfg']['Server']['verbose']
124 : $GLOBALS['cfg']['Server']['host'];
125 $server_info .= empty($GLOBALS['cfg']['Server']['port'])
126 ? ''
127 : ':' . $GLOBALS['cfg']['Server']['port'];
129 $separator = "<span class='separator item'>&nbsp;ยป</span>";
130 $item = '<a href="%1$s?%2$s" class="item">';
132 if ($GLOBALS['cfg']['NavigationBarIconic'] !== true) {
133 $item .= '%4$s: ';
135 $item .= '%3$s</a>';
136 $retval .= "<div id='floating_menubar'></div>";
137 $retval .= "<div id='serverinfo'>";
138 if ($GLOBALS['cfg']['NavigationBarIconic']) {
139 $retval .= PMA_Util::getImage(
140 's_host.png',
142 array('class' => 'item')
145 $retval .= sprintf(
146 $item,
147 $GLOBALS['cfg']['DefaultTabServer'],
148 PMA_generate_common_url(),
149 htmlspecialchars($server_info),
150 __('Server')
153 if (strlen($this->_db)) {
154 $retval .= $separator;
155 if ($GLOBALS['cfg']['NavigationBarIconic']) {
156 $retval .= PMA_Util::getImage(
157 's_db.png',
159 array('class' => 'item')
162 $retval .= sprintf(
163 $item,
164 $GLOBALS['cfg']['DefaultTabDatabase'],
165 PMA_generate_common_url($this->_db),
166 htmlspecialchars($this->_db),
167 __('Database')
169 // if the table is being dropped, $_REQUEST['purge'] is set to '1'
170 // so do not display the table name in upper div
171 if (strlen($this->_table)
172 && ! (isset($_REQUEST['purge']) && $_REQUEST['purge'] == '1')
174 include './libraries/tbl_info.inc.php';
176 $retval .= $separator;
177 if ($GLOBALS['cfg']['NavigationBarIconic']) {
178 $icon = $tbl_is_view ? 'b_views.png' : 's_tbl.png';
179 $retval .= PMA_Util::getImage(
180 $icon,
182 array('class' => 'item')
185 $retval .= sprintf(
186 $item,
187 $GLOBALS['cfg']['DefaultTabTable'],
188 PMA_generate_common_url($this->_db, $this->_table),
189 str_replace(' ', '&nbsp;', htmlspecialchars($this->_table)),
190 $tbl_is_view ? __('View') : __('Table')
194 * Displays table comment
196 if (! empty($show_comment)
197 && ! isset($GLOBALS['avoid_show_comment'])
199 if (strstr($show_comment, '; InnoDB free')) {
200 $show_comment = preg_replace(
201 '@; InnoDB free:.*?$@',
203 $show_comment
206 $retval .= '<span class="table_comment"';
207 $retval .= ' id="span_table_comment">&quot;';
208 $retval .= htmlspecialchars($show_comment);
209 $retval .= '&quot;</span>';
210 } // end if
211 } else {
212 // no table selected, display database comment if present
213 $cfgRelation = PMA_getRelationsParam();
215 // Get additional information about tables for tooltip is done
216 // in libraries/db_info.inc.php only once
217 if ($cfgRelation['commwork']) {
218 $comment = PMA_getDbComment($this->_db);
220 * Displays table comment
222 if (! empty($comment)) {
223 $retval .= '<span class="table_comment"'
224 . ' id="span_table_comment">&quot;'
225 . htmlspecialchars($comment)
226 . '&quot;</span>';
227 } // end if
231 $retval .= '<div class="clearfloat"></div>';
232 $retval .= '</div>';
233 return $retval;
237 * Returns the table tabs as an array
239 * @return array Data for generating table tabs
241 private function _getTableTabs()
243 $db_is_information_schema = PMA_is_system_schema($this->_db);
244 $tbl_is_view = PMA_Table::isView($this->_db, $this->_table);
245 $table_info_num_rows = PMA_Table::countRecords($this->_db, $this->_table);
247 $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;
254 $tabs['structure']['icon'] = 'b_props.png';
255 $tabs['structure']['link'] = 'tbl_structure.php';
256 $tabs['structure']['text'] = __('Structure');
258 $tabs['sql']['icon'] = 'b_sql.png';
259 $tabs['sql']['link'] = 'tbl_sql.php';
260 $tabs['sql']['text'] = __('SQL');
262 $tabs['search']['icon'] = 'b_search.png';
263 $tabs['search']['text'] = __('Search');
264 $tabs['search']['link'] = 'tbl_select.php';
265 $tabs['search']['active'] = in_array(
266 basename($GLOBALS['PMA_PHP_SELF']),
267 array('tbl_select.php', 'tbl_zoom_select.php')
270 if (! $db_is_information_schema) {
271 $tabs['insert']['icon'] = 'b_insrow.png';
272 $tabs['insert']['link'] = 'tbl_change.php';
273 $tabs['insert']['text'] = __('Insert');
276 $tabs['export']['icon'] = 'b_tblexport.png';
277 $tabs['export']['link'] = 'tbl_export.php';
278 $tabs['export']['args']['single_table'] = 'true';
279 $tabs['export']['text'] = __('Export');
282 * Don't display "Import" and "Operations"
283 * for views and information_schema
285 if (! $tbl_is_view && ! $db_is_information_schema) {
286 $tabs['import']['icon'] = 'b_tblimport.png';
287 $tabs['import']['link'] = 'tbl_import.php';
288 $tabs['import']['text'] = __('Import');
290 $tabs['operation']['icon'] = 'b_tblops.png';
291 $tabs['operation']['link'] = 'tbl_operations.php';
292 $tabs['operation']['text'] = __('Operations');
294 if (PMA_Tracker::isActive()) {
295 $tabs['tracking']['icon'] = 'eye.png';
296 $tabs['tracking']['text'] = __('Tracking');
297 $tabs['tracking']['link'] = 'tbl_tracking.php';
299 if (! $db_is_information_schema
300 && ! PMA_DRIZZLE
301 && PMA_Util::currentUserHasPrivilege('TRIGGER', $this->_db, $this->_table)
302 && ! $tbl_is_view
304 $tabs['triggers']['link'] = 'tbl_triggers.php';
305 $tabs['triggers']['text'] = __('Triggers');
306 $tabs['triggers']['icon'] = 'b_triggers.png';
310 * Views support a limited number of operations
312 if ($tbl_is_view && ! $db_is_information_schema) {
313 $tabs['operation']['icon'] = 'b_tblops.png';
314 $tabs['operation']['link'] = 'view_operations.php';
315 $tabs['operation']['text'] = __('Operations');
318 return $tabs;
322 * Returns the db tabs as an array
324 * @return array Data for generating db tabs
326 private function _getDbTabs()
328 $db_is_information_schema = PMA_is_system_schema($this->_db);
329 $num_tables = count(PMA_DBI_get_tables($this->_db));
330 $is_superuser = PMA_isSuperuser();
333 * Gets the relation settings
335 $cfgRelation = PMA_getRelationsParam();
337 $tabs = array();
339 $tabs['structure']['link'] = 'db_structure.php';
340 $tabs['structure']['text'] = __('Structure');
341 $tabs['structure']['icon'] = 'b_props.png';
343 $tabs['sql']['link'] = 'db_sql.php';
344 $tabs['sql']['args']['db_query_force'] = 1;
345 $tabs['sql']['text'] = __('SQL');
346 $tabs['sql']['icon'] = 'b_sql.png';
348 $tabs['search']['text'] = __('Search');
349 $tabs['search']['icon'] = 'b_search.png';
350 $tabs['search']['link'] = 'db_search.php';
351 if ($num_tables == 0) {
352 $tabs['search']['warning'] = __('Database seems to be empty!');
355 $tabs['qbe']['text'] = __('Query');
356 $tabs['qbe']['icon'] = 's_db.png';
357 $tabs['qbe']['link'] = 'db_qbe.php';
358 if ($num_tables == 0) {
359 $tabs['qbe']['warning'] = __('Database seems to be empty!');
362 $tabs['export']['text'] = __('Export');
363 $tabs['export']['icon'] = 'b_export.png';
364 $tabs['export']['link'] = 'db_export.php';
365 if ($num_tables == 0) {
366 $tabs['export']['warning'] = __('Database seems to be empty!');
369 if (! $db_is_information_schema) {
370 $tabs['import']['link'] = 'db_import.php';
371 $tabs['import']['text'] = __('Import');
372 $tabs['import']['icon'] = 'b_import.png';
374 $tabs['operation']['link'] = 'db_operations.php';
375 $tabs['operation']['text'] = __('Operations');
376 $tabs['operation']['icon'] = 'b_tblops.png';
378 if ($is_superuser && ! PMA_DRIZZLE) {
379 $tabs['privileges']['link'] = 'server_privileges.php';
380 $tabs['privileges']['args']['checkprivs'] = $this->_db;
381 // stay on database view
382 $tabs['privileges']['args']['viewing_mode'] = 'db';
383 $tabs['privileges']['text'] = __('Privileges');
384 $tabs['privileges']['icon'] = 's_rights.png';
386 if (! PMA_DRIZZLE) {
387 $tabs['routines']['link'] = 'db_routines.php';
388 $tabs['routines']['text'] = __('Routines');
389 $tabs['routines']['icon'] = 'b_routines.png';
391 if (PMA_MYSQL_INT_VERSION >= 50106
392 && ! PMA_DRIZZLE
393 && PMA_Util::currentUserHasPrivilege('EVENT', $this->_db)
395 $tabs['events']['link'] = 'db_events.php';
396 $tabs['events']['text'] = __('Events');
397 $tabs['events']['icon'] = 'b_events.png';
399 if (! PMA_DRIZZLE
400 && PMA_Util::currentUserHasPrivilege('TRIGGER', $this->_db)
402 $tabs['triggers']['link'] = 'db_triggers.php';
403 $tabs['triggers']['text'] = __('Triggers');
404 $tabs['triggers']['icon'] = 'b_triggers.png';
408 if (PMA_Tracker::isActive()) {
409 $tabs['tracking']['text'] = __('Tracking');
410 $tabs['tracking']['icon'] = 'eye.png';
411 $tabs['tracking']['link'] = 'db_tracking.php';
414 if (! $db_is_information_schema && $cfgRelation['designerwork']) {
415 $tabs['designer']['text'] = __('Designer');
416 $tabs['designer']['icon'] = 'b_relations.png';
417 $tabs['designer']['link'] = 'pmd_general.php';
420 return $tabs;
424 * Returns the server tabs as an array
426 * @return array Data for generating server tabs
428 private function _getServerTabs()
430 $is_superuser = function_exists('PMA_isSuperuser') && PMA_isSuperuser();
431 $binary_logs = null;
432 if (function_exists('PMA_DBI_fetch_result')
433 && (! defined('PMA_DRIZZLE')
434 || (defined('PMA_DRIZZLE') && ! PMA_DRIZZLE)
437 $binary_logs = PMA_DBI_fetch_result(
438 'SHOW MASTER LOGS',
439 'Log_name',
440 null,
441 null,
442 PMA_DBI_QUERY_STORE
446 $tabs = array();
448 $tabs['databases']['icon'] = 's_db.png';
449 $tabs['databases']['link'] = 'server_databases.php';
450 $tabs['databases']['text'] = __('Databases');
452 $tabs['sql']['icon'] = 'b_sql.png';
453 $tabs['sql']['link'] = 'server_sql.php';
454 $tabs['sql']['text'] = __('SQL');
456 $tabs['status']['icon'] = 's_status.png';
457 $tabs['status']['link'] = 'server_status.php';
458 $tabs['status']['text'] = __('Status');
459 $tabs['status']['active'] = in_array(
460 basename($GLOBALS['PMA_PHP_SELF']),
461 array(
462 'server_status.php',
463 'server_status_advisor.php',
464 'server_status_monitor.php',
465 'server_status_queries.php',
466 'server_status_variables.php'
470 if ($is_superuser && ! PMA_DRIZZLE) {
471 $tabs['rights']['icon'] = 's_rights.png';
472 $tabs['rights']['link'] = 'server_privileges.php';
473 $tabs['rights']['text'] = __('Users');
476 $tabs['export']['icon'] = 'b_export.png';
477 $tabs['export']['link'] = 'server_export.php';
478 $tabs['export']['text'] = __('Export');
480 $tabs['import']['icon'] = 'b_import.png';
481 $tabs['import']['link'] = 'server_import.php';
482 $tabs['import']['text'] = __('Import');
484 $tabs['settings']['icon'] = 'b_tblops.png';
485 $tabs['settings']['link'] = 'prefs_manage.php';
486 $tabs['settings']['text'] = __('Settings');
487 $tabs['settings']['active'] = in_array(
488 basename($GLOBALS['PMA_PHP_SELF']),
489 array('prefs_forms.php', 'prefs_manage.php')
492 if (! empty($binary_logs)) {
493 $tabs['binlog']['icon'] = 's_tbl.png';
494 $tabs['binlog']['link'] = 'server_binlog.php';
495 $tabs['binlog']['text'] = __('Binary log');
498 if ($is_superuser && ! PMA_DRIZZLE) {
499 $tabs['replication']['icon'] = 's_replication.png';
500 $tabs['replication']['link'] = 'server_replication.php';
501 $tabs['replication']['text'] = __('Replication');
504 $tabs['vars']['icon'] = 's_vars.png';
505 $tabs['vars']['link'] = 'server_variables.php';
506 $tabs['vars']['text'] = __('Variables');
508 $tabs['charset']['icon'] = 's_asci.png';
509 $tabs['charset']['link'] = 'server_collations.php';
510 $tabs['charset']['text'] = __('Charsets');
512 if (defined('PMA_DRIZZLE') && PMA_DRIZZLE) {
513 $tabs['plugins']['icon'] = 'b_engine.png';
514 $tabs['plugins']['link'] = 'server_plugins.php';
515 $tabs['plugins']['text'] = __('Plugins');
516 } else {
517 $tabs['engine']['icon'] = 'b_engine.png';
518 $tabs['engine']['link'] = 'server_engines.php';
519 $tabs['engine']['text'] = __('Engines');
521 return $tabs;