2.11.11.3 release
[phpmyadmin/arisferyanto.git] / libraries / select_server.lib.php
blob2107e3b7e205256e7c30d374c236534cbffd0e62
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Code for displaying server selection written by nijel
6 * @version $Id$
7 */
9 /**
10 * display server selection in list or selectbox form, or option tags only
12 * @globals $lang
13 * @globals $convcharset
14 * @uses $GLOBALS['cfg']['DisplayServersList']
15 * @uses $GLOBALS['strServer']
16 * @uses $GLOBALS['cfg']['Servers']
17 * @uses $GLOBALS['strGo']
18 * @uses implode()
19 * @uses htmlspecialchars()
20 * @param boolean $not_only_options whether to include form tags or not
21 * @param boolean $ommit_fieldset whether to ommit fieldset tag or not
23 function PMA_select_server($not_only_options, $ommit_fieldset)
25 global $lang, $convcharset;
27 // Show as list?
28 if ($not_only_options) {
29 $list = $GLOBALS['cfg']['DisplayServersList'];
30 $not_only_options =! $list;
31 } else {
32 $list = false;
35 if ($not_only_options) {
36 echo '<form method="post" action="index.php" target="_parent">';
38 if (! $ommit_fieldset) {
39 echo '<fieldset>';
41 echo '<label for="select_server">' . $GLOBALS['strServer'] . ':</label> ';
43 echo '<select name="server" id="select_server"'
44 . ' onchange="if (this.value != \'\') this.form.submit();">';
45 echo '<option value="">(' . $GLOBALS['strServers'] . ') ...</option>' . "\n";
46 } elseif ($list) {
47 echo $GLOBALS['strServer'] . ':<br />';
48 echo '<ul id="list_server">';
51 foreach ($GLOBALS['cfg']['Servers'] as $key => $server) {
52 if (empty($server['host'])) {
53 continue;
56 if (!empty($GLOBALS['server']) && (int) $GLOBALS['server'] === (int) $key) {
57 $selected = 1;
58 } else {
59 $selected = 0;
62 if (!empty($server['verbose'])) {
63 $label = $server['verbose'];
64 } else {
65 $label = $server['host'];
66 if (!empty($server['port'])) {
67 $label .= ':' . $server['port'];
70 if (! empty($server['only_db'])) {
71 if (! is_array($server['only_db'])) {
72 $label .= ' - ' . $server['only_db'];
73 // try to avoid displaying a too wide selector
74 } elseif (count($server['only_db']) < 4) {
75 $label .= ' - ' . implode(', ', $server['only_db']);
78 if (!empty($server['user']) && $server['auth_type'] == 'config') {
79 $label .= ' (' . $server['user'] . ')';
82 if ($list) {
83 echo '<li>';
84 if ($selected && !$ommit_fieldset) {
85 echo '<b>' . htmlspecialchars($label) . '</b>';
86 } else {
87 echo '<a class="item" href="index.php?server=' . $key . '&amp;lang=' . $lang . '&amp;convcharset=' . $convcharset . '" target="_top">' . htmlspecialchars($label) . '</a>';
89 echo '</li>';
90 } else {
91 echo ' <option value="' . $key . '" ' . ($selected ? ' selected="selected"' : '') . '>' . htmlspecialchars($label) . '</option>' . "\n";
93 } // end while
95 if ($not_only_options) {
96 echo '</select>';
98 <input type="hidden" name="lang" value="<?php echo $lang; ?>" />
99 <input type="hidden" name="convcharset" value="<?php echo $convcharset; ?>" />
100 <?php
101 // Show submit button if we have just one server (this happens with no default)
102 echo '<noscript>';
103 echo '<input type="submit" value="' . $GLOBALS['strGo'] . '" />';
104 echo '</noscript>';
105 if (! $ommit_fieldset) {
106 echo '</fieldset>';
108 echo '</form>';
109 } elseif ($list) {
110 echo '</ul>';