Translation update done using Pootle.
[phpmyadmin/ammar_yasir.git] / libraries / select_server.lib.php
blobf71f7cde0ce5ef9608671ba0396e965ab4fc71f6
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Code for displaying server selection
6 * @package phpMyAdmin
7 */
9 /**
10 * display server selection in list or selectbox form, or option tags only
12 * @uses $GLOBALS['cfg']['DisplayServersList']
13 * @uses $GLOBALS['cfg']['Servers']
14 * @uses implode()
15 * @uses htmlspecialchars()
16 * @uses PMA_generate_common_hidden_inputs()
17 * @uses PMA_generate_common_url()
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 // 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 echo '<form method="post" action="index.php" target="_parent">';
33 echo PMA_generate_common_hidden_inputs();
35 if (! $ommit_fieldset) {
36 echo '<fieldset>';
38 echo '<label for="select_server">' . __('Current Server') . ':</label> ';
40 echo '<select name="server" id="select_server"'
41 . ' onchange="if (this.value != \'\') this.form.submit();">';
42 echo '<option value="">(' . __('Servers') . ') ...</option>' . "\n";
43 } elseif ($list) {
44 echo __('Current Server') . ':<br />';
45 echo '<ul id="list_server">';
48 foreach ($GLOBALS['cfg']['Servers'] as $key => $server) {
49 if (empty($server['host'])) {
50 continue;
53 if (!empty($GLOBALS['server']) && (int) $GLOBALS['server'] === (int) $key) {
54 $selected = 1;
55 } else {
56 $selected = 0;
58 if (!empty($server['verbose'])) {
59 $label = $server['verbose'];
60 } else {
61 $label = $server['host'];
62 if (!empty($server['port'])) {
63 $label .= ':' . $server['port'];
66 if (! empty($server['only_db'])) {
67 if (! is_array($server['only_db'])) {
68 $label .= ' - ' . $server['only_db'];
69 // try to avoid displaying a too wide selector
70 } elseif (count($server['only_db']) < 4) {
71 $label .= ' - ' . implode(', ', $server['only_db']);
74 if (!empty($server['user']) && $server['auth_type'] == 'config') {
75 $label .= ' (' . $server['user'] . ')';
78 if ($list) {
79 echo '<li>';
80 if ($selected) {
81 echo '<strong>' . htmlspecialchars($label) . '</strong>';
82 } else {
84 echo '<a class="item" href="index.php'
85 . PMA_generate_common_url(array('server' => $key))
86 . '" target="_top">' . htmlspecialchars($label) . '</a>';
88 echo '</li>';
89 } else {
90 echo '<option value="' . $key . '" '
91 . ($selected ? ' selected="selected"' : '') . '>'
92 . htmlspecialchars($label) . '</option>' . "\n";
94 } // end while
96 if ($not_only_options) {
97 echo '</select>';
98 // Show submit button if we have just one server (this happens with no default)
99 echo '<noscript>';
100 echo '<input type="submit" value="' . __('Go') . '" />';
101 echo '</noscript>';
102 if (! $ommit_fieldset) {
103 echo '</fieldset>';
105 echo '</form>';
106 } elseif ($list) {
107 echo '</ul>';