2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * Code for displaying server selection written by nijel
10 * display server selection in list or selectbox form, or option tags only
12 * @uses $GLOBALS['cfg']['DisplayServersList']
13 * @uses $GLOBALS['strServer']
14 * @uses $GLOBALS['cfg']['Servers']
15 * @uses $GLOBALS['strGo']
17 * @uses htmlspecialchars()
18 * @uses PMA_generate_common_hidden_inputs()
19 * @uses PMA_generate_common_url()
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)
26 if ($not_only_options) {
27 $list = $GLOBALS['cfg']['DisplayServersList'];
28 $not_only_options =! $list;
33 if ($not_only_options) {
34 echo '<form method="post" action="index.php" target="_parent">';
35 echo PMA_generate_common_hidden_inputs();
37 if (! $ommit_fieldset) {
40 echo '<label for="select_server">' . $GLOBALS['strServer'] . ':</label> ';
42 echo '<select name="server" id="select_server"'
43 . ' onchange="if (this.value != \'\') this.form.submit();">';
44 echo '<option value="">(' . $GLOBALS['strServers'] . ') ...</option>' . "\n";
46 echo $GLOBALS['strServer'] . ':<br />';
47 echo '<ul id="list_server">';
50 foreach ($GLOBALS['cfg']['Servers'] as $key => $server) {
51 if (empty($server['host'])) {
55 if (!empty($GLOBALS['server']) && (int) $GLOBALS['server'] === (int) $key) {
61 if (!empty($server['verbose'])) {
62 $label = $server['verbose'];
64 $label = $server['host'];
65 if (!empty($server['port'])) {
66 $label .= ':' . $server['port'];
69 if (! empty($server['only_db'])) {
70 if (! is_array($server['only_db'])) {
71 $label .= ' - ' . $server['only_db'];
72 // try to avoid displaying a too wide selector
73 } elseif (count($server['only_db']) < 4) {
74 $label .= ' - ' . implode(', ', $server['only_db']);
77 if (!empty($server['user']) && $server['auth_type'] == 'config') {
78 $label .= ' (' . $server['user'] . ')';
83 if ($selected && !$ommit_fieldset) {
84 echo '<b>' . htmlspecialchars($label) . '</b>';
87 echo '<a class="item" href="index.php'
88 . PMA_generate_common_url(array('server' => $key))
89 . '" target="_top">' . htmlspecialchars($label) . '</a>';
93 echo '<option value="' . $key . '" '
94 . ($selected ?
' selected="selected"' : '') . '>'
95 . htmlspecialchars($label) . '</option>' . "\n";
99 if ($not_only_options) {
101 // Show submit button if we have just one server (this happens with no default)
103 echo '<input type="submit" value="' . $GLOBALS['strGo'] . '" />';
105 if (! $ommit_fieldset) {