2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * Code for displaying server selection written by nijel
11 * display server selection in list or selectbox form, or option tags only
13 * @uses $GLOBALS['cfg']['DisplayServersList']
14 * @uses $GLOBALS['strServer']
15 * @uses $GLOBALS['cfg']['Servers']
16 * @uses $GLOBALS['strGo']
18 * @uses htmlspecialchars()
19 * @uses PMA_generate_common_hidden_inputs()
20 * @uses PMA_generate_common_url()
21 * @param boolean $not_only_options whether to include form tags or not
22 * @param boolean $ommit_fieldset whether to ommit fieldset tag or not
24 function PMA_select_server($not_only_options, $ommit_fieldset)
27 if ($not_only_options) {
28 $list = $GLOBALS['cfg']['DisplayServersList'];
29 $not_only_options =! $list;
34 if ($not_only_options) {
35 echo '<form method="post" action="index.php" target="_parent">';
36 echo PMA_generate_common_hidden_inputs();
38 if (! $ommit_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";
47 echo $GLOBALS['strServer'] . ':<br />';
48 echo '<ul id="list_server">';
51 foreach ($GLOBALS['cfg']['Servers'] as $key => $server) {
52 if (empty($server['host'])) {
56 if (!empty($GLOBALS['server']) && (int) $GLOBALS['server'] === (int) $key) {
62 if (!empty($server['verbose'])) {
63 $label = $server['verbose'];
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'] . ')';
84 if ($selected && !$ommit_fieldset) {
85 echo '<strong>' . htmlspecialchars($label) . '</strong>';
88 echo '<a class="item" href="index.php'
89 . PMA_generate_common_url(array('server' => $key))
90 . '" target="_top">' . htmlspecialchars($label) . '</a>';
94 echo '<option value="' . $key . '" '
95 . ($selected ?
' selected="selected"' : '') . '>'
96 . htmlspecialchars($label) . '</option>' . "\n";
100 if ($not_only_options) {
102 // Show submit button if we have just one server (this happens with no default)
104 echo '<input type="submit" value="' . $GLOBALS['strGo'] . '" />';
106 if (! $ommit_fieldset) {