Upgraded phpmyadmin to 4.0.4 (All Languages) - No modifications yet
[openemr.git] / phpmyadmin / libraries / replication_gui.lib.php
blob3743f39fe68407b8332e3241fc728cda0fa7e71f
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
45 * @return void
48 function PMA_replication_gui_changemaster($submitname)
51 list($username_length, $hostname_length) = PMA_replication_get_username_hostname_length();
53 echo '<form method="post" action="server_replication.php">';
54 echo PMA_generate_common_hidden_inputs('', '');
55 echo ' <fieldset id="fieldset_add_user_login">';
56 echo ' <legend>' . __('Slave configuration') . ' - ' . __('Change or reconfigure master server') . '</legend>';
57 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 />';
58 echo '<pre>server-id=' . time() . '</pre>';
59 echo ' <div class="item">';
60 echo ' <label for="text_username">' . __('User name') . ':</label>';
61 echo ' <input type="text" name="username" id="text_username" maxlength="'. $username_length . '" title="' . __('User name') . '" />';
62 echo ' </div>';
63 echo ' <div class="item">';
64 echo ' <label for="text_pma_pw">' . __('Password') .' :</label>';
65 echo ' <input type="password" id="text_pma_pw" name="pma_pw" title="' . __('Password') . '" />';
66 echo ' </div>';
67 echo ' <div class="item">';
68 echo ' <label for="text_hostname">' . __('Host') . ' :</label>';
69 echo ' <input type="text" id="text_hostname" name="hostname" maxlength="' . $hostname_length . '" value="" />';
70 echo ' </div>';
71 echo ' <div class="item">';
72 echo ' <label for="text_port">' . __('Port') . ':</label>';
73 echo ' <input type="text" id="text_port" name="port" maxlength="6" value="3306" />';
74 echo ' </div>';
75 echo ' </fieldset>';
76 echo ' <fieldset id="fieldset_user_privtable_footer" class="tblFooters">';
77 echo ' <input type="hidden" name="sr_take_action" value="true" />';
78 echo ' <input type="hidden" name="' . $submitname . '" value="1" />';
79 echo ' <input type="submit" id="confslave_submit" value="' . __('Go') . '" />';
80 echo ' </fieldset>';
81 echo '</form>';
84 /**
85 * This function prints out table with replication status.
87 * @param string $type either master or slave
88 * @param boolean $hidden if true, then default style is set to hidden, default value false
89 * @param boolen $title if true, then title is displayed, default true
91 * @return void
93 function PMA_replication_print_status_table($type, $hidden = false, $title = true)
95 global ${"{$type}_variables"};
96 global ${"{$type}_variables_alerts"};
97 global ${"{$type}_variables_oks"};
98 global ${"server_{$type}_replication"};
99 global ${"strReplicationStatus_{$type}"};
101 // TODO check the Masters server id?
102 // seems to default to '1' when queried via SHOW VARIABLES , but resulted in error on the master when slave connects
103 // [ERROR] Error reading packet from server: Misconfigured master - server id was not set ( server_errno=1236)
104 // [ERROR] Got fatal error 1236: 'Misconfigured master - server id was not set' from master when reading data from binary log
106 //$server_id = PMA_DBI_fetch_value("SHOW VARIABLES LIKE 'server_id'", 0, 1);
108 echo '<div id="replication_' . $type . '_section" style="' . ($hidden ? 'display: none;' : '') . '"> ';
110 if ($title) {
111 if ($type == 'master') {
112 echo '<h4><a name="replication_' . $type . '"></a>' . __('Master status') . '</h4>';
113 } else {
114 echo '<h4><a name="replication_' . $type . '"></a>' . __('Slave status') . '</h4>';
116 } else {
117 echo '<br />';
120 echo ' <table id="server' . $type . 'replicationsummary" class="data"> ';
121 echo ' <thead>';
122 echo ' <tr>';
123 echo ' <th>' . __('Variable') . '</th>';
124 echo ' <th>' . __('Value') . '</th>';
125 echo ' </tr>';
126 echo ' </thead>';
127 echo ' <tbody>';
129 $odd_row = true;
130 foreach (${"{$type}_variables"} as $variable) {
131 echo ' <tr class="' . ($odd_row ? 'odd' : 'even') . '">';
132 echo ' <td class="name">';
133 echo $variable;
134 echo ' </td>';
135 echo ' <td class="value">';
138 // TODO change to regexp or something, to allow for negative match
139 if (isset(${"{$type}_variables_alerts"}[$variable])
140 && ${"{$type}_variables_alerts"}[$variable] == ${"server_{$type}_replication"}[0][$variable]
142 echo '<span class="attention">';
144 } elseif (isset(${"{$type}_variables_oks"}[$variable])
145 && ${"{$type}_variables_oks"}[$variable] == ${"server_{$type}_replication"}[0][$variable]
147 echo '<span class="allfine">';
148 } else {
149 echo '<span>';
151 // allow wrapping long table lists into multiple lines
152 static $variables_wrap = array(
153 'Replicate_Do_DB', 'Replicate_Ignore_DB',
154 'Replicate_Do_Table', 'Replicate_Ignore_Table',
155 'Replicate_Wild_Do_Table', 'Replicate_Wild_Ignore_Table');
156 if (in_array($variable, $variables_wrap)) {
157 echo str_replace(',', ', ', ${"server_{$type}_replication"}[0][$variable]);
158 } else {
159 echo ${"server_{$type}_replication"}[0][$variable];
161 echo '</span>';
163 echo ' </td>';
164 echo ' </tr>';
166 $odd_row = ! $odd_row;
169 echo ' </tbody>';
170 echo ' </table>';
171 echo ' <br />';
172 echo '</div>';
177 * Prints table with slave users connected to this master
179 * @param boolean $hidden - if true, then default style is set to hidden, default value false
181 * @return void
183 function PMA_replication_print_slaves_table($hidden = false)
186 // Fetch data
187 $data = PMA_DBI_fetch_result('SHOW SLAVE HOSTS', null, null);
189 echo ' <br />';
190 echo ' <div id="replication_slaves_section" style="' . ($hidden ? 'display: none;' : '') . '"> ';
191 echo ' <table class="data">';
192 echo ' <thead>';
193 echo ' <tr>';
194 echo ' <th>' . __('Server ID') . '</th>';
195 echo ' <th>' . __('Host') . '</th>';
196 echo ' </tr>';
197 echo ' </thead>';
198 echo ' <tbody>';
200 $odd_row = true;
201 foreach ($data as $slave) {
202 echo ' <tr class="' . ($odd_row ? 'odd' : 'even') . '">';
203 echo ' <td class="value">' . $slave['Server_id'] . '</td>';
204 echo ' <td class="value">' . $slave['Host'] . '</td>';
205 echo ' </tr>';
207 $odd_row = ! $odd_row;
210 echo ' </tbody>';
211 echo ' </table>';
212 echo ' <br />';
213 PMA_Message::notice(__('Only slaves started with the --report-host=host_name option are visible in this list.'))->display();
214 echo ' <br />';
215 echo ' </div>';
219 * get the correct username and hostname lengths for this MySQL server
221 * @return array username length, hostname length
224 function PMA_replication_get_username_hostname_length()
226 $fields_info = PMA_DBI_get_columns('mysql', 'user');
227 $username_length = 16;
228 $hostname_length = 41;
229 foreach ($fields_info as $val) {
230 if ($val['Field'] == 'User') {
231 strtok($val['Type'], '()');
232 $v = strtok('()');
233 if (is_int($v)) {
234 $username_length = $v;
236 } elseif ($val['Field'] == 'Host') {
237 strtok($val['Type'], '()');
238 $v = strtok('()');
239 if (is_int($v)) {
240 $hostname_length = $v;
244 return array($username_length, $hostname_length);
248 * Print code to add a replication slave user to the master
250 * @return void
252 function PMA_replication_gui_master_addslaveuser()
255 list($username_length, $hostname_length) = PMA_replication_get_username_hostname_length();
257 if (isset($GLOBALS['username']) && strlen($GLOBALS['username']) === 0) {
258 $GLOBALS['pred_username'] = 'any';
260 echo '<div id="master_addslaveuser_gui">';
261 echo '<form autocomplete="off" method="post" action="server_privileges.php" onsubmit="return checkAddUser(this);">';
262 echo PMA_generate_common_hidden_inputs('', '');
263 echo '<fieldset id="fieldset_add_user_login">'
264 . '<legend>'.__('Add slave replication user').'</legend>'
265 . '<input type="hidden" name="grant_count" value="25" />'
266 . '<input type="hidden" name="createdb" id="createdb_0" value="0" />'
267 . '<input id="checkbox_Repl_slave_priv" type="hidden" title="Needed for the replication slaves." value="Y" name="Repl_slave_priv"/>'
268 . '<input id="checkbox_Repl_client_priv" type="hidden" title="Needed for the replication slaves." value="Y" name="Repl_client_priv"/>'
269 . ''
270 . '<input type="hidden" name="sr_take_action" value="true" />'
271 . '<div class="item">'
272 . '<label for="select_pred_username">'
273 . ' ' . __('User name') . ':'
274 . '</label>'
275 . '<span class="options">'
276 . ' <select name="pred_username" id="select_pred_username" title="' . __('User name') . '"'
277 . ' onchange="if (this.value == \'any\') { username.value = \'\'; } else if (this.value == \'userdefined\') { username.focus(); username.select(); }">'
278 . ' <option value="any"' . ((isset($GLOBALS['pred_username']) && $GLOBALS['pred_username'] == 'any') ? ' selected="selected"' : '') . '>' . __('Any user') . '</option>'
279 . ' <option value="userdefined"' . ((! isset($GLOBALS['pred_username']) || $GLOBALS['pred_username'] == 'userdefined') ? ' selected="selected"' : '') . '>' . __('Use text field') . ':</option>'
280 . ' </select>'
281 . '</span>'
282 . '<input type="text" name="username" maxlength="'
283 . $username_length . '" title="' . __('User name') . '"'
284 . (empty($GLOBALS['username'])
285 ? ''
286 : ' value="' . (isset($GLOBALS['new_username'])
287 ? $GLOBALS['new_username']
288 : $GLOBALS['username']) . '"')
289 . ' onchange="pred_username.value = \'userdefined\';" />'
290 . '</div>'
291 . '<div class="item">'
292 . '<label for="select_pred_hostname">'
293 . ' ' . __('Host') . ':'
294 . '</label>'
295 . '<span class="options">'
296 . ' <select name="pred_hostname" id="select_pred_hostname" title="' . __('Host') . '"';
297 $_current_user = PMA_DBI_fetch_value('SELECT USER();');
298 if (! empty($_current_user)) {
299 $thishost = str_replace("'", '', substr($_current_user, (strrpos($_current_user, '@') + 1)));
300 if ($thishost == 'localhost' || $thishost == '127.0.0.1') {
301 unset($thishost);
304 echo ' onchange="if (this.value == \'any\') { hostname.value = \'%\'; } else if (this.value == \'localhost\') { hostname.value = \'localhost\'; } '
305 . (empty($thishost) ? '' : 'else if (this.value == \'thishost\') { hostname.value = \'' . addslashes(htmlspecialchars($thishost)) . '\'; } ')
306 . 'else if (this.value == \'hosttable\') { hostname.value = \'\'; } else if (this.value == \'userdefined\') { hostname.focus(); hostname.select(); }">' . "\n";
307 unset($_current_user);
309 // when we start editing a user, $GLOBALS['pred_hostname'] is not defined
310 if (! isset($GLOBALS['pred_hostname']) && isset($GLOBALS['hostname'])) {
311 switch (strtolower($GLOBALS['hostname'])) {
312 case 'localhost':
313 case '127.0.0.1':
314 $GLOBALS['pred_hostname'] = 'localhost';
315 break;
316 case '%':
317 $GLOBALS['pred_hostname'] = 'any';
318 break;
319 default:
320 $GLOBALS['pred_hostname'] = 'userdefined';
321 break;
324 echo ' <option value="any"'
325 . ((isset($GLOBALS['pred_hostname']) && $GLOBALS['pred_hostname'] == 'any')
326 ? ' selected="selected"' : '') . '>' . __('Any host')
327 . '</option>'
328 . ' <option value="localhost"'
329 . ((isset($GLOBALS['pred_hostname']) && $GLOBALS['pred_hostname'] == 'localhost')
330 ? ' selected="selected"' : '') . '>' . __('Local')
331 . '</option>';
333 if (!empty($thishost)) {
334 echo ' <option value="thishost"'
335 . ((isset($GLOBALS['pred_hostname']) && $GLOBALS['pred_hostname'] == 'thishost')
336 ? ' selected="selected"' : '') . '>' . __('This Host')
337 . '</option>';
339 unset($thishost);
340 echo ' <option value="hosttable"'
341 . ((isset($GLOBALS['pred_hostname']) && $GLOBALS['pred_hostname'] == 'hosttable')
342 ? ' selected="selected"' : '') . '>' . __('Use Host Table')
343 . '</option>'
344 . ' <option value="userdefined"'
345 . ((isset($GLOBALS['pred_hostname']) && $GLOBALS['pred_hostname'] == 'userdefined')
346 ? ' selected="selected"' : '')
347 . '>' . __('Use text field') . ':</option>'
348 . ' </select>'
349 . '</span>'
350 . '<input type="text" name="hostname" maxlength="'
351 . $hostname_length . '" value="'
352 . (isset($GLOBALS['hostname']) ? $GLOBALS['hostname'] : '')
353 . '" title="' . __('Host')
354 . '" onchange="pred_hostname.value = \'userdefined\';" />'
355 . PMA_Util::showHint(
356 __('When Host table is used, this field is ignored and values stored in Host table are used instead.')
358 . '</div>'
359 . '<div class="item">'
360 . '<label for="select_pred_password">'
361 . ' ' . __('Password') . ':'
362 . '</label>'
363 . '<span class="options">'
364 . ' <select name="pred_password" id="select_pred_password" title="'
365 . __('Password') . '"'
366 . ' onchange="if (this.value == \'none\') { pma_pw.value = \'\'; pma_pw2.value = \'\'; } else if (this.value == \'userdefined\') { pma_pw.focus(); pma_pw.select(); }">'
367 . ' <option value="none"';
368 if (isset($GLOBALS['username'])) {
369 echo ' selected="selected"';
371 echo '>' . __('No Password') . '</option>'
372 . ' <option value="userdefined"' . (isset($GLOBALS['username']) ? '' : ' selected="selected"') . '>' . __('Use text field') . ':</option>'
373 . ' </select>'
374 . '</span>'
375 . '<input type="password" id="text_pma_pw" name="pma_pw" title="' . __('Password') . '" onchange="pred_password.value = \'userdefined\';" />'
376 . '</div>'
377 . '<div class="item">'
378 . '<label for="text_pma_pw2">'
379 . ' ' . __('Re-type') . ':'
380 . '</label>'
381 . '<span class="options">&nbsp;</span>'
382 . '<input type="password" name="pma_pw2" id="text_pma_pw2" title="' . __('Re-type') . '" onchange="pred_password.value = \'userdefined\';" />'
383 . '</div>'
384 . '<div class="item">'
385 . '<label for="button_generate_password">'
386 . ' ' . __('Generate Password') . ':'
387 . '</label>'
388 . '<span class="options">'
389 . ' <input type="button" class="button" id="button_generate_password" value="' . __('Generate') . '" onclick="suggestPassword(this.form)" />'
390 . '</span>'
391 . '<input type="text" name="generated_pw" id="generated_pw" />'
392 . '</div>'
393 . '</fieldset>';
394 echo '<fieldset id="fieldset_user_privtable_footer" class="tblFooters">'
395 . ' <input type="hidden" name="adduser_submit" value="1" />'
396 . ' <input type="submit" id="adduser_submit" value="' . __('Go') . '" />'
397 . '</fieldset>';
398 echo '</form>';
399 echo '</div>';