Translation update done using Pootle.
[phpmyadmin.git] / libraries / replication_gui.lib.php
blobc1098fce3ff50cc23636dcea93fba5e94341caa7
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
5 * @package PhpMyAdmin
6 */
7 if (! defined('PHPMYADMIN')) {
8 exit;
11 /**
12 * returns code for selecting databases
14 * @return String HTML code
16 function PMA_replication_db_multibox()
18 $multi_values = '';
19 $multi_values .= '<select name="db_select[]" size="6" multiple="multiple" id="db_select">';
21 foreach ($GLOBALS['pma']->databases as $current_db) {
22 if (PMA_is_system_schema($current_db)) {
23 continue;
25 if (! empty($selectall) || (isset($tmp_select) && strpos(' ' . $tmp_select, '|' . $current_db . '|'))) {
26 $is_selected = ' selected="selected"';
27 } else {
28 $is_selected = '';
30 $current_db = htmlspecialchars($current_db);
31 $multi_values .= ' <option value="' . $current_db . '" ' . $is_selected . '>' . $current_db . '</option>';
32 } // end while
34 $multi_values .= '</select>';
35 $multi_values .= '<br /><a href="#" id="db_reset_href">' . __('Uncheck All') . '</a>';
37 return $multi_values;
40 /**
41 * prints out code for changing master
43 * @param String $submitname - submit button name
46 function PMA_replication_gui_changemaster($submitname)
49 list($username_length, $hostname_length) = PMA_replication_get_username_hostname_length();
51 echo '<form method="post" action="server_replication.php">';
52 echo PMA_generate_common_hidden_inputs('', '');
53 echo ' <fieldset id="fieldset_add_user_login">';
54 echo ' <legend>' . __('Slave configuration') . ' - ' . __('Change or reconfigure master server') . '</legend>';
55 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 />';
56 echo '<pre>server-id=' . time() . '</pre>';
57 echo ' <div class="item">';
58 echo ' <label for="text_username">' . __('User name') . ':</label>';
59 echo ' <input type="text" name="username" id="text_username" maxlength="'. $username_length . '" title="' . __('User name') . '" />';
60 echo ' </div>';
61 echo ' <div class="item">';
62 echo ' <label for="text_pma_pw">' . __('Password') .' :</label>';
63 echo ' <input type="password" id="text_pma_pw" name="pma_pw" title="' . __('Password') . '" />';
64 echo ' </div>';
65 echo ' <div class="item">';
66 echo ' <label for="text_hostname">' . __('Host') . ' :</label>';
67 echo ' <input type="text" id="text_hostname" name="hostname" maxlength="' . $hostname_length . '" value="" />';
68 echo ' </div>';
69 echo ' <div class="item">';
70 echo ' <label for="text_port">' . __('Port') . ':</label>';
71 echo ' <input type="text" id="text_port" name="port" maxlength="6" value="3306" />';
72 echo ' </div>';
73 echo ' </fieldset>';
74 echo ' <fieldset id="fieldset_user_privtable_footer" class="tblFooters">';
75 echo ' <input type="hidden" name="sr_take_action" value="true" />';
76 echo ' <input type="submit" name="' . $submitname . '" id="confslave_submit" value="' . __('Go') . '" />';
77 echo ' </fieldset>';
78 echo '</form>';
81 /**
82 * This function prints out table with replication status.
84 * @param string $type either master or slave
85 * @param boolean $hidden if true, then default style is set to hidden, default value false
86 * @param boolen $title if true, then title is displayed, default true
88 function PMA_replication_print_status_table($type, $hidden = false, $title = true)
90 global ${"{$type}_variables"};
91 global ${"{$type}_variables_alerts"};
92 global ${"{$type}_variables_oks"};
93 global ${"server_{$type}_replication"};
94 global ${"strReplicationStatus_{$type}"};
96 // TODO check the Masters server id?
97 // seems to default to '1' when queried via SHOW VARIABLES , but resulted in error on the master when slave connects
98 // [ERROR] Error reading packet from server: Misconfigured master - server id was not set ( server_errno=1236)
99 // [ERROR] Got fatal error 1236: 'Misconfigured master - server id was not set' from master when reading data from binary log
101 //$server_id = PMA_DBI_fetch_value("SHOW VARIABLES LIKE 'server_id'", 0, 1);
103 echo '<div id="replication_' . $type . '_section" style="' . ($hidden ? 'display: none;' : '') . '"> ';
105 if ($title) {
106 if ($type == 'master') {
107 echo '<h4><a name="replication_' . $type . '"></a>' . __('Master status') . '</h4>';
108 } else {
109 echo '<h4><a name="replication_' . $type . '"></a>' . __('Slave status') . '</h4>';
111 } else {
112 echo '<br />';
115 echo ' <table id="server' . $type . 'replicationsummary" class="data"> ';
116 echo ' <thead>';
117 echo ' <tr>';
118 echo ' <th>' . __('Variable') . '</th>';
119 echo ' <th>' . __('Value') . '</th>';
120 echo ' </tr>';
121 echo ' </thead>';
122 echo ' <tbody>';
124 $odd_row = true;
125 foreach (${"{$type}_variables"} as $variable) {
126 echo ' <tr class="' . ($odd_row ? 'odd' : 'even') . '">';
127 echo ' <td class="name">';
128 echo $variable;
129 echo ' </td>';
130 echo ' <td class="value">';
133 // TODO change to regexp or something, to allow for negative match
134 if (isset(${"{$type}_variables_alerts"}[$variable])
135 && ${"{$type}_variables_alerts"}[$variable] == ${"server_{$type}_replication"}[0][$variable]
137 echo '<span class="attention">';
139 } elseif (isset(${"{$type}_variables_oks"}[$variable])
140 && ${"{$type}_variables_oks"}[$variable] == ${"server_{$type}_replication"}[0][$variable]
142 echo '<span class="allfine">';
143 } else {
144 echo '<span>';
146 echo ${"server_{$type}_replication"}[0][$variable];
147 echo '</span>';
149 echo ' </td>';
150 echo ' </tr>';
152 $odd_row = ! $odd_row;
155 echo ' </tbody>';
156 echo ' </table>';
157 echo ' <br />';
158 echo '</div>';
163 * Prints table with slave users connected to this master
165 * @param boolean $hidden - if true, then default style is set to hidden, default value false
167 function PMA_replication_print_slaves_table($hidden = false)
170 // Fetch data
171 $data = PMA_DBI_fetch_result('SHOW SLAVE HOSTS', null, null);
173 echo ' <br />';
174 echo ' <div id="replication_slaves_section" style="' . ($hidden ? 'display: none;' : '') . '"> ';
175 echo ' <table class="data">';
176 echo ' <thead>';
177 echo ' <tr>';
178 echo ' <th>' . __('Server ID') . '</th>';
179 echo ' <th>' . __('Host') . '</th>';
180 echo ' </tr>';
181 echo ' </thead>';
182 echo ' <tbody>';
184 $odd_row = true;
185 foreach ($data as $slave) {
186 echo ' <tr class="' . ($odd_row ? 'odd' : 'even') . '">';
187 echo ' <td class="value">' . $slave['Server_id'] . '</td>';
188 echo ' <td class="value">' . $slave['Host'] . '</td>';
189 echo ' </tr>';
191 $odd_row = ! $odd_row;
194 echo ' </tbody>';
195 echo ' </table>';
196 echo ' <br />';
197 PMA_Message::notice(__('Only slaves started with the --report-host=host_name option are visible in this list.'))->display();
198 echo ' <br />';
199 echo ' </div>';
203 * get the correct username and hostname lengths for this MySQL server
205 * @return array username length, hostname length
208 function PMA_replication_get_username_hostname_length()
210 $fields_info = PMA_DBI_get_columns('mysql', 'user');
211 $username_length = 16;
212 $hostname_length = 41;
213 foreach ($fields_info as $val) {
214 if ($val['Field'] == 'User') {
215 strtok($val['Type'], '()');
216 $v = strtok('()');
217 if (is_int($v)) {
218 $username_length = $v;
220 } elseif ($val['Field'] == 'Host') {
221 strtok($val['Type'], '()');
222 $v = strtok('()');
223 if (is_int($v)) {
224 $hostname_length = $v;
228 return array($username_length, $hostname_length);
232 * Print code to add a replication slave user to the master
234 function PMA_replication_gui_master_addslaveuser()
237 list($username_length, $hostname_length) = PMA_replication_get_username_hostname_length();
239 if (isset($GLOBALS['username']) && strlen($GLOBALS['username']) === 0) {
240 $GLOBALS['pred_username'] = 'any';
242 echo '<div id="master_addslaveuser_gui">';
243 echo '<form autocomplete="off" method="post" action="server_privileges.php" onsubmit="return checkAddUser(this);">';
244 echo PMA_generate_common_hidden_inputs('', '');
245 echo '<fieldset id="fieldset_add_user_login">'
246 . '<legend>'.__('Add slave replication user').'</legend>'
247 . '<input type="hidden" name="grant_count" value="25" />'
248 . '<input type="hidden" name="createdb" id="createdb_0" value="0" />'
249 . '<input id="checkbox_Repl_slave_priv" type="hidden" title="Needed for the replication slaves." value="Y" name="Repl_slave_priv"/>'
250 . '<input id="checkbox_Repl_client_priv" type="hidden" title="Needed for the replication slaves." value="Y" name="Repl_client_priv"/>'
251 . ''
252 . '<input type="hidden" name="sr_take_action" value="true" />'
253 . '<div class="item">'
254 . '<label for="select_pred_username">'
255 . ' ' . __('User name') . ':'
256 . '</label>'
257 . '<span class="options">'
258 . ' <select name="pred_username" id="select_pred_username" title="' . __('User name') . '"'
259 . ' onchange="if (this.value == \'any\') { username.value = \'\'; } else if (this.value == \'userdefined\') { username.focus(); username.select(); }">'
260 . ' <option value="any"' . ((isset($GLOBALS['pred_username']) && $GLOBALS['pred_username'] == 'any') ? ' selected="selected"' : '') . '>' . __('Any user') . '</option>'
261 . ' <option value="userdefined"' . ((! isset($GLOBALS['pred_username']) || $GLOBALS['pred_username'] == 'userdefined') ? ' selected="selected"' : '') . '>' . __('Use text field') . ':</option>'
262 . ' </select>'
263 . '</span>'
264 . '<input type="text" name="username" maxlength="'
265 . $username_length . '" title="' . __('User name') . '"'
266 . (empty($GLOBALS['username'])
267 ? ''
268 : ' value="' . (isset($GLOBALS['new_username'])
269 ? $GLOBALS['new_username']
270 : $GLOBALS['username']) . '"')
271 . ' onchange="pred_username.value = \'userdefined\';" />'
272 . '</div>'
273 . '<div class="item">'
274 . '<label for="select_pred_hostname">'
275 . ' ' . __('Host') . ':'
276 . '</label>'
277 . '<span class="options">'
278 . ' <select name="pred_hostname" id="select_pred_hostname" title="' . __('Host') . '"';
279 $_current_user = PMA_DBI_fetch_value('SELECT USER();');
280 if (! empty($_current_user)) {
281 $thishost = str_replace("'", '', substr($_current_user, (strrpos($_current_user, '@') + 1)));
282 if ($thishost == 'localhost' || $thishost == '127.0.0.1') {
283 unset($thishost);
286 echo ' onchange="if (this.value == \'any\') { hostname.value = \'%\'; } else if (this.value == \'localhost\') { hostname.value = \'localhost\'; } '
287 . (empty($thishost) ? '' : 'else if (this.value == \'thishost\') { hostname.value = \'' . addslashes(htmlspecialchars($thishost)) . '\'; } ')
288 . 'else if (this.value == \'hosttable\') { hostname.value = \'\'; } else if (this.value == \'userdefined\') { hostname.focus(); hostname.select(); }">' . "\n";
289 unset($_current_user);
291 // when we start editing a user, $GLOBALS['pred_hostname'] is not defined
292 if (! isset($GLOBALS['pred_hostname']) && isset($GLOBALS['hostname'])) {
293 switch (strtolower($GLOBALS['hostname'])) {
294 case 'localhost':
295 case '127.0.0.1':
296 $GLOBALS['pred_hostname'] = 'localhost';
297 break;
298 case '%':
299 $GLOBALS['pred_hostname'] = 'any';
300 break;
301 default:
302 $GLOBALS['pred_hostname'] = 'userdefined';
303 break;
306 echo ' <option value="any"'
307 . ((isset($GLOBALS['pred_hostname']) && $GLOBALS['pred_hostname'] == 'any')
308 ? ' selected="selected"' : '') . '>' . __('Any host')
309 . '</option>'
310 . ' <option value="localhost"'
311 . ((isset($GLOBALS['pred_hostname']) && $GLOBALS['pred_hostname'] == 'localhost')
312 ? ' selected="selected"' : '') . '>' . __('Local')
313 . '</option>';
315 if (!empty($thishost)) {
316 echo ' <option value="thishost"'
317 . ((isset($GLOBALS['pred_hostname']) && $GLOBALS['pred_hostname'] == 'thishost')
318 ? ' selected="selected"' : '') . '>' . __('This Host')
319 . '</option>';
321 unset($thishost);
322 echo ' <option value="hosttable"'
323 . ((isset($GLOBALS['pred_hostname']) && $GLOBALS['pred_hostname'] == 'hosttable')
324 ? ' selected="selected"' : '') . '>' . __('Use Host Table')
325 . '</option>'
326 . ' <option value="userdefined"'
327 . ((isset($GLOBALS['pred_hostname']) && $GLOBALS['pred_hostname'] == 'userdefined')
328 ? ' selected="selected"' : '')
329 . '>' . __('Use text field') . ':</option>'
330 . ' </select>'
331 . '</span>'
332 . '<input type="text" name="hostname" maxlength="'
333 . $hostname_length . '" value="'
334 . (isset($GLOBALS['hostname']) ? $GLOBALS['hostname'] : '')
335 . '" title="' . __('Host')
336 . '" onchange="pred_hostname.value = \'userdefined\';" />'
337 . PMA_showHint(__('When Host table is used, this field is ignored and values stored in Host table are used instead.'))
338 . '</div>'
339 . '<div class="item">'
340 . '<label for="select_pred_password">'
341 . ' ' . __('Password') . ':'
342 . '</label>'
343 . '<span class="options">'
344 . ' <select name="pred_password" id="select_pred_password" title="'
345 . __('Password') . '"'
346 . ' onchange="if (this.value == \'none\') { pma_pw.value = \'\'; pma_pw2.value = \'\'; } else if (this.value == \'userdefined\') { pma_pw.focus(); pma_pw.select(); }">'
347 . ' <option value="none"';
348 if (isset($GLOBALS['username']) && $mode != 'change') {
349 echo ' selected="selected"';
351 echo '>' . __('No Password') . '</option>'
352 . ' <option value="userdefined"' . (isset($GLOBALS['username']) ? '' : ' selected="selected"') . '>' . __('Use text field') . ':</option>'
353 . ' </select>'
354 . '</span>'
355 . '<input type="password" id="text_pma_pw" name="pma_pw" title="' . __('Password') . '" onchange="pred_password.value = \'userdefined\';" />'
356 . '</div>'
357 . '<div class="item">'
358 . '<label for="text_pma_pw2">'
359 . ' ' . __('Re-type') . ':'
360 . '</label>'
361 . '<span class="options">&nbsp;</span>'
362 . '<input type="password" name="pma_pw2" id="text_pma_pw2" title="' . __('Re-type') . '" onchange="pred_password.value = \'userdefined\';" />'
363 . '</div>'
364 . '<div class="item">'
365 . '<label for="button_generate_password">'
366 . ' ' . __('Generate Password') . ':'
367 . '</label>'
368 . '<span class="options">'
369 . ' <input type="button" id="button_generate_password" value="' . __('Generate') . '" onclick="suggestPassword(this.form)" />'
370 . '</span>'
371 . '<input type="text" name="generated_pw" id="generated_pw" />'
372 . '</div>'
373 . '</fieldset>';
374 echo '<fieldset id="fieldset_user_privtable_footer" class="tblFooters">'
375 . ' <input type="submit" name="adduser_submit" id="adduser_submit" value="' . __('Go') . '" />'
376 . '</fieldset>';
377 echo '</form>';
378 echo '</div>';