Translated using Weblate (Estonian)
[phpmyadmin.git] / libraries / select_server.lib.php
blobec69b91d91cc53950065ad9a8e73290775f04b58
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Code for displaying server selection
6 * @package PhpMyAdmin
7 */
9 use PMA\libraries\URL;
11 /**
12 * Renders the server selection in list or selectbox form, or option tags only
14 * @param boolean $not_only_options whether to include form tags or not
15 * @param boolean $omit_fieldset whether to omit fieldset tag or not
17 * @return string
19 function PMA_selectServer($not_only_options, $omit_fieldset)
21 $retval = '';
23 // Show as list?
24 if ($not_only_options) {
25 $list = $GLOBALS['cfg']['DisplayServersList'];
26 $not_only_options =! $list;
27 } else {
28 $list = false;
31 if ($not_only_options) {
32 $retval .= '<form method="post" action="'
33 . PMA\libraries\Util::getScriptNameForOption(
34 $GLOBALS['cfg']['DefaultTabServer'], 'server'
36 . '" class="disableAjax">';
38 if (! $omit_fieldset) {
39 $retval .= '<fieldset>';
42 $retval .= '<input type="hidden" name="token" value="' . $_SESSION[" PMA_token "] . '" >';
43 $retval .= '<label for="select_server">'
44 . __('Current server:') . '</label> ';
46 $retval .= '<select name="server" id="select_server" class="autosubmit">';
47 $retval .= '<option value="">(' . __('Servers') . ') ...</option>' . "\n";
48 } elseif ($list) {
49 $retval .= __('Current server:') . '<br />';
50 $retval .= '<ul id="list_server">';
53 foreach ($GLOBALS['cfg']['Servers'] as $key => $server) {
54 if (empty($server['host'])) {
55 continue;
58 if (!empty($GLOBALS['server']) && (int) $GLOBALS['server'] === (int) $key) {
59 $selected = 1;
60 } else {
61 $selected = 0;
63 if (!empty($server['verbose'])) {
64 $label = $server['verbose'];
65 } else {
66 $label = $server['host'];
67 if (!empty($server['port'])) {
68 $label .= ':' . $server['port'];
71 if (! empty($server['only_db'])) {
72 if (! is_array($server['only_db'])) {
73 $label .= ' - ' . $server['only_db'];
74 // try to avoid displaying a too wide selector
75 } elseif (count($server['only_db']) < 4) {
76 $label .= ' - ' . implode(', ', $server['only_db']);
79 if (!empty($server['user']) && $server['auth_type'] == 'config') {
80 $label .= ' (' . $server['user'] . ')';
83 if ($list) {
84 $retval .= '<li>';
85 if ($selected) {
86 $retval .= '<strong>' . htmlspecialchars($label) . '</strong>';
87 } else {
89 $retval .= '<a class="disableAjax item" href="'
90 . PMA\libraries\Util::getScriptNameForOption(
91 $GLOBALS['cfg']['DefaultTabServer'], 'server'
93 . URL::getCommon(array('server' => $key))
94 . '" >' . htmlspecialchars($label) . '</a>';
96 $retval .= '</li>';
97 } else {
98 $retval .= '<option value="' . $key . '" '
99 . ($selected ? ' selected="selected"' : '') . '>'
100 . htmlspecialchars($label) . '</option>' . "\n";
102 } // end while
104 if ($not_only_options) {
105 $retval .= '</select>';
106 if (! $omit_fieldset) {
107 $retval .= '</fieldset>';
109 $retval .= '</form>';
110 } elseif ($list) {
111 $retval .= '</ul>';
114 return $retval;