Improve docs.
[phpmyadmin/crack.git] / libraries / select_server.lib.php
blob3b94c4601f751e8a357cdb606b0a06a115452b74
1 <?php
2 /*
3 * Code for displaying server selection written by nijel
4 * $Id$
5 */
7 /**
8 * display server selection in list or selectbox form, or option tags only
10 * @globals $lang
11 * @globals $convcharset
12 * @uses $GLOBALS['cfg']['DisplayServersList']
13 * @uses $GLOBALS['strServer']
14 * @uses $GLOBALS['cfg']['Servers']
15 * @uses $GLOBALS['strGo']
16 * @uses implode()
17 * @uses htmlspecialchars()
18 * @param boolean $not_only_options whether to include form tags or not
19 * @param boolean $ommit_fieldset whether to ommit fieldset tag or not
21 function PMA_select_server($not_only_options, $ommit_fieldset)
23 global $lang, $convcharset;
25 // Show as list?
26 if ($not_only_options) {
27 $list = $GLOBALS['cfg']['DisplayServersList'];
28 $not_only_options =! $list;
29 } else {
30 $list = false;
33 if ($not_only_options) {
34 echo '<form method="post" action="index.php" target="_parent">';
36 if (! $ommit_fieldset) {
37 echo '<fieldset>';
39 echo '<label for="select_server">' . $GLOBALS['strServer'] . ':</label> ';
41 echo '<select name="server" id="select_server"'
42 . ' onchange="if (this.value != \'\') this.form.submit();">';
43 echo '<option value="">(' . $GLOBALS['strServers'] . ') ...</option>' . "\n";
44 } elseif ($list) {
45 echo $GLOBALS['strServer'] . ':<br />';
46 echo '<ul id="list_server">';
49 foreach ($GLOBALS['cfg']['Servers'] as $key => $server) {
50 if (empty($server['host'])) {
51 continue;
54 if (!empty($GLOBALS['server']) && (int) $GLOBALS['server'] === (int) $key) {
55 $selected = 1;
56 } else {
57 $selected = 0;
60 if (!empty($server['verbose'])) {
61 $label = $server['verbose'];
62 } else {
63 $label = $server['host'];
64 if (!empty($server['port'])) {
65 $label .= ':' . $server['port'];
68 // loic1: if 'only_db' is an array and there is more than one
69 // value, displaying such informations may not be a so good
70 // idea
71 if (!empty($server['only_db'])) {
72 /**
73 * @todo this can become a really big/long/wide selectbox ...
75 $label .= ' - ' . (is_array($server['only_db']) ? implode(', ', $server['only_db']) : $server['only_db']);
77 if (!empty($server['user']) && $server['auth_type'] == 'config') {
78 $label .= ' (' . $server['user'] . ')';
81 if ($list) {
82 echo '<li>';
83 if ($selected && !$ommit_fieldset) {
84 echo '<b>' . htmlspecialchars($label) . '</b>';
85 } else {
86 echo '<a class="item" href="index.php?server=' . $key . '&amp;lang=' . $lang . '&amp;convcharset=' . $convcharset . '" target="_top">' . htmlspecialchars($label) . '</a>';
88 echo '</li>';
89 } else {
90 echo ' <option value="' . $key . '" ' . ($selected ? ' selected="selected"' : '') . '>' . htmlspecialchars($label) . '</option>' . "\n";
92 } // end while
94 if ($not_only_options) {
95 echo '</select>';
97 <input type="hidden" name="lang" value="<?php echo $lang; ?>" />
98 <input type="hidden" name="convcharset" value="<?php echo $convcharset; ?>" />
99 <?php
100 // Show submit button if we have just one server (this happens with no default)
101 echo '<noscript>';
102 echo '<input type="submit" value="' . $GLOBALS['strGo'] . '" />';
103 echo '</noscript>';
104 if (! $ommit_fieldset) {
105 echo '</fieldset>';
107 echo '</form>';
108 } elseif ($list) {
109 echo '</ul>';