Translation update done using Pootle.
[phpmyadmin/dkf.git] / libraries / replication_gui.lib.php
blob4e85e3270099851d9785452086fe15235a5a3268
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
5 * @version $Id$
6 * @package phpMyAdmin
7 */
8 if (! defined('PHPMYADMIN')) {
9 exit;
12 /**
13 * returns code for selecting databases
15 * @return String HTML code
17 function PMA_replication_db_multibox()
19 $multi_values = '';
20 $multi_values .= '<select name="db_select[]" size="6" multiple="multiple" id="db_select">';
22 foreach ($GLOBALS['pma']->databases as $current_db) {
23 if (! empty($selectall) || (isset($tmp_select) && strpos(' ' . $tmp_select, '|' . $current_db . '|'))) {
24 $is_selected = ' selected="selected"';
25 } else {
26 $is_selected = '';
28 $current_db = htmlspecialchars($current_db);
29 $multi_values .= ' <option value="' . $current_db . '" ' . $is_selected . '>' . $current_db . '</option>';
30 } // end while
32 $multi_values .= '</select>';
33 $multi_values .= '<br /><a href="#" id="db_reset_href">' . __('Uncheck All') . '</a>';
35 return $multi_values;
38 /**
39 * prints out code for changing master
41 * @param String $submitname - submit button name
44 function PMA_replication_gui_changemaster($submitname) {
46 list($username_length, $hostname_length) = PMA_replication_get_username_hostname_length();
48 echo '<form method="post" action="server_replication.php">';
49 echo PMA_generate_common_hidden_inputs('', '');
50 echo ' <fieldset id="fieldset_add_user_login">';
51 echo ' <legend>' . __('Slave configuration') . ' - ' . __('Change or reconfigure master server') . '</legend>';
52 echo __('Make sure, you have unique server-id in your configuration file (my.cnf). If not, please add the following line into [mysqld] section:') . '<br />';
53 echo '<pre>server-id=' . time() . '</pre>';
54 echo ' <div class="item">';
55 echo ' <label for="text_username">' . __('User name') . ':</label>';
56 echo ' <input type="text" name="username" id="text_username" maxlength="'. $username_length . '" title="' . __('User name') . '" />';
57 echo ' </div>';
58 echo ' <div class="item">';
59 echo ' <label for="text_pma_pw">' . __('Password') .' :</label>';
60 echo ' <input type="password" id="text_pma_pw" name="pma_pw" title="' . __('Password') . '" />';
61 echo ' </div>';
62 echo ' <div class="item">';
63 echo ' <label for="text_hostname">' . __('Host') . ' :</label>';
64 echo ' <input type="text" id="text_hostname" name="hostname" maxlength="' . $hostname_length . '" value="" />';
65 echo ' </div>';
66 echo ' <div class="item">';
67 echo ' <label for="text_port">' . __('Port') . ':</label>';
68 echo ' <input type="text" id="text_port" name="port" maxlength="6" value="3306" />';
69 echo ' </div>';
70 echo ' </fieldset>';
71 echo ' <fieldset id="fieldset_user_privtable_footer" class="tblFooters">';
72 echo ' <input type="hidden" name="sr_take_action" value="true" />';
73 echo ' <input type="submit" name="' . $submitname . '" id="confslave_submit" value="' . __('Go') . '" />';
74 echo ' </fieldset>';
75 echo '</form>';
78 /**
79 * This function prints out table with replication status.
81 * @param String type - either master or slave
82 * @param boolean $hidden - if true, then default style is set to hidden, default value false
83 * @param boolen $title - if true, then title is displayed, default true
85 function PMA_replication_print_status_table($type, $hidden = false, $title = true) {
86 global ${"{$type}_variables"};
87 global ${"{$type}_variables_alerts"};
88 global ${"{$type}_variables_oks"};
89 global ${"server_{$type}_replication"};
90 global ${"strReplicationStatus_{$type}"};
92 // TODO check the Masters server id?
93 // seems to default to '1' when queried via SHOW VARIABLES , but resulted in error on the master when slave connects
94 // [ERROR] Error reading packet from server: Misconfigured master - server id was not set ( server_errno=1236)
95 // [ERROR] Got fatal error 1236: 'Misconfigured master - server id was not set' from master when reading data from binary log
97 //$server_id = PMA_DBI_fetch_value("SHOW VARIABLES LIKE 'server_id'", 0, 1);
99 echo '<div id="replication_' . $type . '_section" style="' . ($hidden ? 'display: none;' : '') . '"> ';
101 if ($title) {
102 echo '<h4><a name="replication_' . $type . '"></a>' . ${"strReplicationStatus_{$type}"} . '</h4>';
103 } else {
104 echo '<br />';
107 echo ' <table id="server' . $type . 'replicationsummary" class="data"> ';
108 echo ' <thead>';
109 echo ' <tr>';
110 echo ' <th>' . __('Variable') . '</th>';
111 echo ' <th>' . __('Value') . '</th>';
112 echo ' </tr>';
113 echo ' </thead>';
114 echo ' <tbody>';
116 $odd_row = true;
117 foreach (${"{$type}_variables"} as $variable) {
118 echo ' <tr class="' . ($odd_row ? 'odd' : 'even') . '">';
119 echo ' <td class="name">';
120 echo $variable;
121 echo ' </td>';
122 echo ' <td class="value">';
125 // TODO change to regexp or something, to allow for negative match
126 if (isset(${"{$type}_variables_alerts"}[$variable])
127 && ${"{$type}_variables_alerts"}[$variable] == ${"server_{$type}_replication"}[0][$variable]
129 echo '<span class="attention">';
131 } elseif (isset(${"{$type}_variables_oks"}[$variable])
132 && ${"{$type}_variables_oks"}[$variable] == ${"server_{$type}_replication"}[0][$variable]
134 echo '<span class="allfine">';
135 } else {
136 echo '<span>';
138 echo ${"server_{$type}_replication"}[0][$variable];
139 echo '</span>';
141 echo ' </td>';
142 echo ' </tr>';
144 $odd_row = ! $odd_row;
147 echo ' </tbody>';
148 echo ' </table>';
149 echo ' <br />';
150 echo '</div>';
155 * Prints table with slave users connected to this master
157 * @param boolean $hidden - if true, then default style is set to hidden, default value false
159 function PMA_replication_print_slaves_table($hidden = false) {
161 // Fetch data
162 $data = PMA_DBI_fetch_result('SHOW SLAVE HOSTS', null, null);
164 echo ' <br />';
165 echo ' <div id="replication_slaves_section" style="' . ($hidden ? 'display: none;' : '') . '"> ';
166 echo ' <table class="data">';
167 echo ' <thead>';
168 echo ' <tr>';
169 echo ' <th>' . __('Server ID') . '</th>';
170 echo ' <th>' . __('Host') . '</th>';
171 echo ' </tr>';
172 echo ' </thead>';
173 echo ' <tbody>';
175 $odd_row = true;
176 foreach ($data as $slave) {
177 echo ' <tr class="' . ($odd_row ? 'odd' : 'even') . '">';
178 echo ' <td class="value">' . $slave['Server_id'] . '</td>';
179 echo ' <td class="value">' . $slave['Host'] . '</td>';
180 echo ' </tr>';
182 $odd_row = ! $odd_row;
185 echo ' </tbody>';
186 echo ' </table>';
187 echo ' <br />';
188 PMA_Message::notice(__('Only slaves started with the --report-host=host_name option are visible in this list.'))->display();
189 echo ' <br />';
190 echo ' </div>';
194 * get the correct username and hostname lengths for this MySQL server
196 * @uses strtok()
197 * @return array username length, hostname length
200 function PMA_replication_get_username_hostname_length() {
201 $fields_info = PMA_DBI_get_fields('mysql', 'user');
202 $username_length = 16;
203 $hostname_length = 41;
204 foreach ($fields_info as $key => $val) {
205 if ($val['Field'] == 'User') {
206 strtok($val['Type'], '()');
207 $v = strtok('()');
208 if (is_int($v)) {
209 $username_length = $v;
211 } elseif ($val['Field'] == 'Host') {
212 strtok($val['Type'], '()');
213 $v = strtok('()');
214 if (is_int($v)) {
215 $hostname_length = $v;
219 return array($username_length, $hostname_length);
223 * Print code to add a replication slave user to the master
225 function PMA_replication_gui_master_addslaveuser() {
227 list($username_length, $hostname_length) = PMA_replication_get_username_hostname_length();
229 if (isset($GLOBALS['username']) && strlen($GLOBALS['username']) === 0) {
230 $GLOBALS['pred_username'] = 'any';
232 echo '<div id="master_addslaveuser_gui">';
233 echo '<form autocomplete="off" method="post" action="server_privileges.php" onsubmit="return checkAddUser(this);">';
234 echo PMA_generate_common_hidden_inputs('', '');
235 echo '<fieldset id="fieldset_add_user_login">'
236 . '<legend>'.__('Add slave replication user').'</legend>'
237 . '<input type="hidden" name="grant_count" value="25" />'
238 . '<input type="hidden" name="createdb" id="createdb_0" value="0" />'
239 . '<input id="checkbox_Repl_slave_priv" type="hidden" title="Needed for the replication slaves." value="Y" name="Repl_slave_priv"/>'
240 . '<input id="checkbox_Repl_client_priv" type="hidden" title="Needed for the replication slaves." value="Y" name="Repl_client_priv"/>'
241 . ''
242 . '<input type="hidden" name="sr_take_action" value="true" />'
243 . '<div class="item">'
244 . '<label for="select_pred_username">'
245 . ' ' . __('User name') . ':'
246 . '</label>'
247 . '<span class="options">'
248 . ' <select name="pred_username" id="select_pred_username" title="' . __('User name') . '"'
249 . ' onchange="if (this.value == \'any\') { username.value = \'\'; } else if (this.value == \'userdefined\') { username.focus(); username.select(); }">'
250 . ' <option value="any"' . ((isset($GLOBALS['pred_username']) && $GLOBALS['pred_username'] == 'any') ? ' selected="selected"' : '') . '>' . __('Any user') . '</option>'
251 . ' <option value="userdefined"' . ((! isset($GLOBALS['pred_username']) || $GLOBALS['pred_username'] == 'userdefined') ? ' selected="selected"' : '') . '>' . __('Use text field') . ':</option>'
252 . ' </select>'
253 . '</span>'
254 . '<input type="text" name="username" maxlength="'
255 . $username_length . '" title="' . __('User name') . '"'
256 . (empty($GLOBALS['username'])
257 ? ''
258 : ' value="' . (isset($GLOBALS['new_username'])
259 ? $GLOBALS['new_username']
260 : $GLOBALS['username']) . '"')
261 . ' onchange="pred_username.value = \'userdefined\';" />'
262 . '</div>'
263 . '<div class="item">'
264 . '<label for="select_pred_hostname">'
265 . ' ' . __('Host') . ':'
266 . '</label>'
267 . '<span class="options">'
268 . ' <select name="pred_hostname" id="select_pred_hostname" title="' . __('Host') . '"';
269 $_current_user = PMA_DBI_fetch_value('SELECT USER();');
270 if (! empty($_current_user)) {
271 $thishost = str_replace("'", '', substr($_current_user, (strrpos($_current_user, '@') + 1)));
272 if ($thishost == 'localhost' || $thishost == '127.0.0.1') {
273 unset($thishost);
276 echo ' onchange="if (this.value == \'any\') { hostname.value = \'%\'; } else if (this.value == \'localhost\') { hostname.value = \'localhost\'; } '
277 . (empty($thishost) ? '' : 'else if (this.value == \'thishost\') { hostname.value = \'' . addslashes(htmlspecialchars($thishost)) . '\'; } ')
278 . 'else if (this.value == \'hosttable\') { hostname.value = \'\'; } else if (this.value == \'userdefined\') { hostname.focus(); hostname.select(); }">' . "\n";
279 unset($_current_user);
281 // when we start editing a user, $GLOBALS['pred_hostname'] is not defined
282 if (! isset($GLOBALS['pred_hostname']) && isset($GLOBALS['hostname'])) {
283 switch (strtolower($GLOBALS['hostname'])) {
284 case 'localhost':
285 case '127.0.0.1':
286 $GLOBALS['pred_hostname'] = 'localhost';
287 break;
288 case '%':
289 $GLOBALS['pred_hostname'] = 'any';
290 break;
291 default:
292 $GLOBALS['pred_hostname'] = 'userdefined';
293 break;
296 echo ' <option value="any"'
297 . ((isset($GLOBALS['pred_hostname']) && $GLOBALS['pred_hostname'] == 'any')
298 ? ' selected="selected"' : '') . '>' . __('Any host')
299 . '</option>'
300 . ' <option value="localhost"'
301 . ((isset($GLOBALS['pred_hostname']) && $GLOBALS['pred_hostname'] == 'localhost')
302 ? ' selected="selected"' : '') . '>' . __('Local')
303 . '</option>';
305 if (!empty($thishost)) {
306 echo ' <option value="thishost"'
307 . ((isset($GLOBALS['pred_hostname']) && $GLOBALS['pred_hostname'] == 'thishost')
308 ? ' selected="selected"' : '') . '>' . __('This Host')
309 . '</option>';
311 unset($thishost);
312 echo ' <option value="hosttable"'
313 . ((isset($GLOBALS['pred_hostname']) && $GLOBALS['pred_hostname'] == 'hosttable')
314 ? ' selected="selected"' : '') . '>' . __('Use Host Table')
315 . '</option>'
316 . ' <option value="userdefined"'
317 . ((isset($GLOBALS['pred_hostname']) && $GLOBALS['pred_hostname'] == 'userdefined')
318 ? ' selected="selected"' : '')
319 . '>' . __('Use text field') . ':</option>'
320 . ' </select>'
321 . '</span>'
322 . '<input type="text" name="hostname" maxlength="'
323 . $hostname_length . '" value="'
324 . (isset($GLOBALS['hostname']) ? $GLOBALS['hostname'] : '')
325 . '" title="' . __('Host')
326 . '" onchange="pred_hostname.value = \'userdefined\';" />'
327 . PMA_showHint(__('When Host table is used, this field is ignored and values stored in Host table are used instead.'))
328 . '</div>'
329 . '<div class="item">'
330 . '<label for="select_pred_password">'
331 . ' ' . __('Password') . ':'
332 . '</label>'
333 . '<span class="options">'
334 . ' <select name="pred_password" id="select_pred_password" title="'
335 . __('Password') . '"'
336 . ' onchange="if (this.value == \'none\') { pma_pw.value = \'\'; pma_pw2.value = \'\'; } else if (this.value == \'userdefined\') { pma_pw.focus(); pma_pw.select(); }">'
337 . ' <option value="none"';
338 if (isset($GLOBALS['username']) && $mode != 'change') {
339 echo ' selected="selected"';
341 echo '>' . __('No Password') . '</option>'
342 . ' <option value="userdefined"' . (isset($GLOBALS['username']) ? '' : ' selected="selected"') . '>' . __('Use text field') . ':</option>'
343 . ' </select>'
344 . '</span>'
345 . '<input type="password" id="text_pma_pw" name="pma_pw" title="' . __('Password') . '" onchange="pred_password.value = \'userdefined\';" />'
346 . '</div>'
347 . '<div class="item">'
348 . '<label for="text_pma_pw2">'
349 . ' ' . __('Re-type') . ':'
350 . '</label>'
351 . '<span class="options">&nbsp;</span>'
352 . '<input type="password" name="pma_pw2" id="text_pma_pw2" title="' . __('Re-type') . '" onchange="pred_password.value = \'userdefined\';" />'
353 . '</div>'
354 . '<div class="item">'
355 . '<label for="button_generate_password">'
356 . ' ' . __('Generate Password') . ':'
357 . '</label>'
358 . '<span class="options">'
359 . ' <input type="button" id="button_generate_password" value="' . __('Generate') . '" onclick="suggestPassword(this.form)" />'
360 . '</span>'
361 . '<input type="text" name="generated_pw" id="generated_pw" />'
362 . '</div>'
363 . '</fieldset>';
364 echo '<fieldset id="fieldset_user_privtable_footer" class="tblFooters">'
365 . ' <input type="submit" name="adduser_submit" id="adduser_submit" value="' . __('Go') . '" />'
366 . '</fieldset>';
367 echo '</form>';
368 echo '</div>';