Translation update done using Pootle.
[phpmyadmin/ammar_yasir.git] / libraries / replication_gui.lib.php
blobd64e5f417a9268bcd2172aef2b5bd247d29b3c52
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 ('information_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) {
48 list($username_length, $hostname_length) = PMA_replication_get_username_hostname_length();
50 echo '<form method="post" action="server_replication.php">';
51 echo PMA_generate_common_hidden_inputs('', '');
52 echo ' <fieldset id="fieldset_add_user_login">';
53 echo ' <legend>' . __('Slave configuration') . ' - ' . __('Change or reconfigure master server') . '</legend>';
54 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 />';
55 echo '<pre>server-id=' . time() . '</pre>';
56 echo ' <div class="item">';
57 echo ' <label for="text_username">' . __('User name') . ':</label>';
58 echo ' <input type="text" name="username" id="text_username" maxlength="'. $username_length . '" title="' . __('User name') . '" />';
59 echo ' </div>';
60 echo ' <div class="item">';
61 echo ' <label for="text_pma_pw">' . __('Password') .' :</label>';
62 echo ' <input type="password" id="text_pma_pw" name="pma_pw" title="' . __('Password') . '" />';
63 echo ' </div>';
64 echo ' <div class="item">';
65 echo ' <label for="text_hostname">' . __('Host') . ' :</label>';
66 echo ' <input type="text" id="text_hostname" name="hostname" maxlength="' . $hostname_length . '" value="" />';
67 echo ' </div>';
68 echo ' <div class="item">';
69 echo ' <label for="text_port">' . __('Port') . ':</label>';
70 echo ' <input type="text" id="text_port" name="port" maxlength="6" value="3306" />';
71 echo ' </div>';
72 echo ' </fieldset>';
73 echo ' <fieldset id="fieldset_user_privtable_footer" class="tblFooters">';
74 echo ' <input type="hidden" name="sr_take_action" value="true" />';
75 echo ' <input type="submit" name="' . $submitname . '" id="confslave_submit" value="' . __('Go') . '" />';
76 echo ' </fieldset>';
77 echo '</form>';
80 /**
81 * This function prints out table with replication status.
83 * @param String type - either master or slave
84 * @param boolean $hidden - if true, then default style is set to hidden, default value false
85 * @param boolen $title - if true, then title is displayed, default true
87 function PMA_replication_print_status_table($type, $hidden = false, $title = true) {
88 global ${"{$type}_variables"};
89 global ${"{$type}_variables_alerts"};
90 global ${"{$type}_variables_oks"};
91 global ${"server_{$type}_replication"};
92 global ${"strReplicationStatus_{$type}"};
94 // TODO check the Masters server id?
95 // seems to default to '1' when queried via SHOW VARIABLES , but resulted in error on the master when slave connects
96 // [ERROR] Error reading packet from server: Misconfigured master - server id was not set ( server_errno=1236)
97 // [ERROR] Got fatal error 1236: 'Misconfigured master - server id was not set' from master when reading data from binary log
99 //$server_id = PMA_DBI_fetch_value("SHOW VARIABLES LIKE 'server_id'", 0, 1);
101 echo '<div id="replication_' . $type . '_section" style="' . ($hidden ? 'display: none;' : '') . '"> ';
103 if ($title) {
104 if ($type == 'master') {
105 echo '<h4><a name="replication_' . $type . '"></a>' . __('Master status') . '</h4>';
106 } else {
107 echo '<h4><a name="replication_' . $type . '"></a>' . __('Slave status') . '</h4>';
109 } else {
110 echo '<br />';
113 echo ' <table id="server' . $type . 'replicationsummary" class="data"> ';
114 echo ' <thead>';
115 echo ' <tr>';
116 echo ' <th>' . __('Variable') . '</th>';
117 echo ' <th>' . __('Value') . '</th>';
118 echo ' </tr>';
119 echo ' </thead>';
120 echo ' <tbody>';
122 $odd_row = true;
123 foreach (${"{$type}_variables"} as $variable) {
124 echo ' <tr class="' . ($odd_row ? 'odd' : 'even') . '">';
125 echo ' <td class="name">';
126 echo $variable;
127 echo ' </td>';
128 echo ' <td class="value">';
131 // TODO change to regexp or something, to allow for negative match
132 if (isset(${"{$type}_variables_alerts"}[$variable])
133 && ${"{$type}_variables_alerts"}[$variable] == ${"server_{$type}_replication"}[0][$variable]
135 echo '<span class="attention">';
137 } elseif (isset(${"{$type}_variables_oks"}[$variable])
138 && ${"{$type}_variables_oks"}[$variable] == ${"server_{$type}_replication"}[0][$variable]
140 echo '<span class="allfine">';
141 } else {
142 echo '<span>';
144 echo ${"server_{$type}_replication"}[0][$variable];
145 echo '</span>';
147 echo ' </td>';
148 echo ' </tr>';
150 $odd_row = ! $odd_row;
153 echo ' </tbody>';
154 echo ' </table>';
155 echo ' <br />';
156 echo '</div>';
161 * Prints table with slave users connected to this master
163 * @param boolean $hidden - if true, then default style is set to hidden, default value false
165 function PMA_replication_print_slaves_table($hidden = false) {
167 // Fetch data
168 $data = PMA_DBI_fetch_result('SHOW SLAVE HOSTS', null, null);
170 echo ' <br />';
171 echo ' <div id="replication_slaves_section" style="' . ($hidden ? 'display: none;' : '') . '"> ';
172 echo ' <table class="data">';
173 echo ' <thead>';
174 echo ' <tr>';
175 echo ' <th>' . __('Server ID') . '</th>';
176 echo ' <th>' . __('Host') . '</th>';
177 echo ' </tr>';
178 echo ' </thead>';
179 echo ' <tbody>';
181 $odd_row = true;
182 foreach ($data as $slave) {
183 echo ' <tr class="' . ($odd_row ? 'odd' : 'even') . '">';
184 echo ' <td class="value">' . $slave['Server_id'] . '</td>';
185 echo ' <td class="value">' . $slave['Host'] . '</td>';
186 echo ' </tr>';
188 $odd_row = ! $odd_row;
191 echo ' </tbody>';
192 echo ' </table>';
193 echo ' <br />';
194 PMA_Message::notice(__('Only slaves started with the --report-host=host_name option are visible in this list.'))->display();
195 echo ' <br />';
196 echo ' </div>';
200 * get the correct username and hostname lengths for this MySQL server
202 * @uses strtok()
203 * @return array username length, hostname length
206 function PMA_replication_get_username_hostname_length() {
207 $fields_info = PMA_DBI_get_fields('mysql', 'user');
208 $username_length = 16;
209 $hostname_length = 41;
210 foreach ($fields_info as $key => $val) {
211 if ($val['Field'] == 'User') {
212 strtok($val['Type'], '()');
213 $v = strtok('()');
214 if (is_int($v)) {
215 $username_length = $v;
217 } elseif ($val['Field'] == 'Host') {
218 strtok($val['Type'], '()');
219 $v = strtok('()');
220 if (is_int($v)) {
221 $hostname_length = $v;
225 return array($username_length, $hostname_length);
229 * Print code to add a replication slave user to the master
231 function PMA_replication_gui_master_addslaveuser() {
233 list($username_length, $hostname_length) = PMA_replication_get_username_hostname_length();
235 if (isset($GLOBALS['username']) && strlen($GLOBALS['username']) === 0) {
236 $GLOBALS['pred_username'] = 'any';
238 echo '<div id="master_addslaveuser_gui">';
239 echo '<form autocomplete="off" method="post" action="server_privileges.php" onsubmit="return checkAddUser(this);">';
240 echo PMA_generate_common_hidden_inputs('', '');
241 echo '<fieldset id="fieldset_add_user_login">'
242 . '<legend>'.__('Add slave replication user').'</legend>'
243 . '<input type="hidden" name="grant_count" value="25" />'
244 . '<input type="hidden" name="createdb" id="createdb_0" value="0" />'
245 . '<input id="checkbox_Repl_slave_priv" type="hidden" title="Needed for the replication slaves." value="Y" name="Repl_slave_priv"/>'
246 . '<input id="checkbox_Repl_client_priv" type="hidden" title="Needed for the replication slaves." value="Y" name="Repl_client_priv"/>'
247 . ''
248 . '<input type="hidden" name="sr_take_action" value="true" />'
249 . '<div class="item">'
250 . '<label for="select_pred_username">'
251 . ' ' . __('User name') . ':'
252 . '</label>'
253 . '<span class="options">'
254 . ' <select name="pred_username" id="select_pred_username" title="' . __('User name') . '"'
255 . ' onchange="if (this.value == \'any\') { username.value = \'\'; } else if (this.value == \'userdefined\') { username.focus(); username.select(); }">'
256 . ' <option value="any"' . ((isset($GLOBALS['pred_username']) && $GLOBALS['pred_username'] == 'any') ? ' selected="selected"' : '') . '>' . __('Any user') . '</option>'
257 . ' <option value="userdefined"' . ((! isset($GLOBALS['pred_username']) || $GLOBALS['pred_username'] == 'userdefined') ? ' selected="selected"' : '') . '>' . __('Use text field') . ':</option>'
258 . ' </select>'
259 . '</span>'
260 . '<input type="text" name="username" maxlength="'
261 . $username_length . '" title="' . __('User name') . '"'
262 . (empty($GLOBALS['username'])
263 ? ''
264 : ' value="' . (isset($GLOBALS['new_username'])
265 ? $GLOBALS['new_username']
266 : $GLOBALS['username']) . '"')
267 . ' onchange="pred_username.value = \'userdefined\';" />'
268 . '</div>'
269 . '<div class="item">'
270 . '<label for="select_pred_hostname">'
271 . ' ' . __('Host') . ':'
272 . '</label>'
273 . '<span class="options">'
274 . ' <select name="pred_hostname" id="select_pred_hostname" title="' . __('Host') . '"';
275 $_current_user = PMA_DBI_fetch_value('SELECT USER();');
276 if (! empty($_current_user)) {
277 $thishost = str_replace("'", '', substr($_current_user, (strrpos($_current_user, '@') + 1)));
278 if ($thishost == 'localhost' || $thishost == '127.0.0.1') {
279 unset($thishost);
282 echo ' onchange="if (this.value == \'any\') { hostname.value = \'%\'; } else if (this.value == \'localhost\') { hostname.value = \'localhost\'; } '
283 . (empty($thishost) ? '' : 'else if (this.value == \'thishost\') { hostname.value = \'' . addslashes(htmlspecialchars($thishost)) . '\'; } ')
284 . 'else if (this.value == \'hosttable\') { hostname.value = \'\'; } else if (this.value == \'userdefined\') { hostname.focus(); hostname.select(); }">' . "\n";
285 unset($_current_user);
287 // when we start editing a user, $GLOBALS['pred_hostname'] is not defined
288 if (! isset($GLOBALS['pred_hostname']) && isset($GLOBALS['hostname'])) {
289 switch (strtolower($GLOBALS['hostname'])) {
290 case 'localhost':
291 case '127.0.0.1':
292 $GLOBALS['pred_hostname'] = 'localhost';
293 break;
294 case '%':
295 $GLOBALS['pred_hostname'] = 'any';
296 break;
297 default:
298 $GLOBALS['pred_hostname'] = 'userdefined';
299 break;
302 echo ' <option value="any"'
303 . ((isset($GLOBALS['pred_hostname']) && $GLOBALS['pred_hostname'] == 'any')
304 ? ' selected="selected"' : '') . '>' . __('Any host')
305 . '</option>'
306 . ' <option value="localhost"'
307 . ((isset($GLOBALS['pred_hostname']) && $GLOBALS['pred_hostname'] == 'localhost')
308 ? ' selected="selected"' : '') . '>' . __('Local')
309 . '</option>';
311 if (!empty($thishost)) {
312 echo ' <option value="thishost"'
313 . ((isset($GLOBALS['pred_hostname']) && $GLOBALS['pred_hostname'] == 'thishost')
314 ? ' selected="selected"' : '') . '>' . __('This Host')
315 . '</option>';
317 unset($thishost);
318 echo ' <option value="hosttable"'
319 . ((isset($GLOBALS['pred_hostname']) && $GLOBALS['pred_hostname'] == 'hosttable')
320 ? ' selected="selected"' : '') . '>' . __('Use Host Table')
321 . '</option>'
322 . ' <option value="userdefined"'
323 . ((isset($GLOBALS['pred_hostname']) && $GLOBALS['pred_hostname'] == 'userdefined')
324 ? ' selected="selected"' : '')
325 . '>' . __('Use text field') . ':</option>'
326 . ' </select>'
327 . '</span>'
328 . '<input type="text" name="hostname" maxlength="'
329 . $hostname_length . '" value="'
330 . (isset($GLOBALS['hostname']) ? $GLOBALS['hostname'] : '')
331 . '" title="' . __('Host')
332 . '" onchange="pred_hostname.value = \'userdefined\';" />'
333 . PMA_showHint(__('When Host table is used, this field is ignored and values stored in Host table are used instead.'))
334 . '</div>'
335 . '<div class="item">'
336 . '<label for="select_pred_password">'
337 . ' ' . __('Password') . ':'
338 . '</label>'
339 . '<span class="options">'
340 . ' <select name="pred_password" id="select_pred_password" title="'
341 . __('Password') . '"'
342 . ' onchange="if (this.value == \'none\') { pma_pw.value = \'\'; pma_pw2.value = \'\'; } else if (this.value == \'userdefined\') { pma_pw.focus(); pma_pw.select(); }">'
343 . ' <option value="none"';
344 if (isset($GLOBALS['username']) && $mode != 'change') {
345 echo ' selected="selected"';
347 echo '>' . __('No Password') . '</option>'
348 . ' <option value="userdefined"' . (isset($GLOBALS['username']) ? '' : ' selected="selected"') . '>' . __('Use text field') . ':</option>'
349 . ' </select>'
350 . '</span>'
351 . '<input type="password" id="text_pma_pw" name="pma_pw" title="' . __('Password') . '" onchange="pred_password.value = \'userdefined\';" />'
352 . '</div>'
353 . '<div class="item">'
354 . '<label for="text_pma_pw2">'
355 . ' ' . __('Re-type') . ':'
356 . '</label>'
357 . '<span class="options">&nbsp;</span>'
358 . '<input type="password" name="pma_pw2" id="text_pma_pw2" title="' . __('Re-type') . '" onchange="pred_password.value = \'userdefined\';" />'
359 . '</div>'
360 . '<div class="item">'
361 . '<label for="button_generate_password">'
362 . ' ' . __('Generate Password') . ':'
363 . '</label>'
364 . '<span class="options">'
365 . ' <input type="button" id="button_generate_password" value="' . __('Generate') . '" onclick="suggestPassword(this.form)" />'
366 . '</span>'
367 . '<input type="text" name="generated_pw" id="generated_pw" />'
368 . '</div>'
369 . '</fieldset>';
370 echo '<fieldset id="fieldset_user_privtable_footer" class="tblFooters">'
371 . ' <input type="submit" name="adduser_submit" id="adduser_submit" value="' . __('Go') . '" />'
372 . '</fieldset>';
373 echo '</form>';
374 echo '</div>';