Merge branch 'master' of git://phpmyadmin.git.sourceforge.net/gitroot/phpmyadmin...
[phpmyadmin/crack.git] / libraries / select_server.lib.php
blob68541d8ce638d5d5bf5c877e056c9335b2229d8c
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Code for displaying server selection
6 * @package phpMyAdmin
7 */
9 /**
10 * display server selection in list or selectbox form, or option tags only
12 * @param boolean $not_only_options whether to include form tags or not
13 * @param boolean $ommit_fieldset whether to ommit fieldset tag or not
15 function PMA_select_server($not_only_options, $ommit_fieldset)
17 // Show as list?
18 if ($not_only_options) {
19 $list = $GLOBALS['cfg']['DisplayServersList'];
20 $not_only_options =! $list;
21 } else {
22 $list = false;
25 if ($not_only_options) {
26 echo '<form method="post" action="index.php" target="_parent">';
27 echo PMA_generate_common_hidden_inputs();
29 if (! $ommit_fieldset) {
30 echo '<fieldset>';
32 echo '<label for="select_server">' . __('Current Server') . ':</label> ';
34 echo '<select name="server" id="select_server"'
35 . ' onchange="if (this.value != \'\') this.form.submit();">';
36 echo '<option value="">(' . __('Servers') . ') ...</option>' . "\n";
37 } elseif ($list) {
38 echo __('Current Server') . ':<br />';
39 echo '<ul id="list_server">';
42 foreach ($GLOBALS['cfg']['Servers'] as $key => $server) {
43 if (empty($server['host'])) {
44 continue;
47 if (!empty($GLOBALS['server']) && (int) $GLOBALS['server'] === (int) $key) {
48 $selected = 1;
49 } else {
50 $selected = 0;
52 if (!empty($server['verbose'])) {
53 $label = $server['verbose'];
54 } else {
55 $label = $server['host'];
56 if (!empty($server['port'])) {
57 $label .= ':' . $server['port'];
60 if (! empty($server['only_db'])) {
61 if (! is_array($server['only_db'])) {
62 $label .= ' - ' . $server['only_db'];
63 // try to avoid displaying a too wide selector
64 } elseif (count($server['only_db']) < 4) {
65 $label .= ' - ' . implode(', ', $server['only_db']);
68 if (!empty($server['user']) && $server['auth_type'] == 'config') {
69 $label .= ' (' . $server['user'] . ')';
72 if ($list) {
73 echo '<li>';
74 if ($selected) {
75 echo '<strong>' . htmlspecialchars($label) . '</strong>';
76 } else {
78 echo '<a class="item" href="index.php'
79 . PMA_generate_common_url(array('server' => $key))
80 . '" target="_top">' . htmlspecialchars($label) . '</a>';
82 echo '</li>';
83 } else {
84 echo '<option value="' . $key . '" '
85 . ($selected ? ' selected="selected"' : '') . '>'
86 . htmlspecialchars($label) . '</option>' . "\n";
88 } // end while
90 if ($not_only_options) {
91 echo '</select>';
92 // Show submit button if we have just one server (this happens with no default)
93 echo '<noscript>';
94 echo '<input type="submit" value="' . __('Go') . '" />';
95 echo '</noscript>';
96 if (! $ommit_fieldset) {
97 echo '</fieldset>';
99 echo '</form>';
100 } elseif ($list) {
101 echo '</ul>';