Update references to SQL files
[phpmyadmin.git] / server_synchronize.php
blobc37a9e0c487765fa8b5101b894fe8ac6b40162ac
1 <?php
3 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 /**
6 * @package PhpMyAdmin
7 */
9 /**
12 require_once './libraries/common.inc.php';
14 /**
15 * Does the common work
17 $GLOBALS['js_include'][] = 'server_synchronize.js';
18 require_once './libraries/server_common.inc.php';
20 /**
21 * Contains all the functions specific to synchronization
23 require './libraries/server_synchronize.lib.php';
25 /**
26 * Increases the time limit up to the configured maximum
28 @set_time_limit($cfg['ExecTimeLimit']);
30 /**
31 * Displays the links
33 require './libraries/server_links.inc.php';
35 /**
36 * Enables warnings on the page
38 //$cfg['Error_Handler']['display'] = true;
39 //$cfg['Error_Handler']['gather'] = true;
41 /**
42 * Save the value of token generated for this page
44 if (isset($_REQUEST['token'])) {
45 $_SESSION['token'] = $_REQUEST['token'];
48 // variable for code saving
49 $cons = array ("src", "trg");
51 /**
52 * Displays the page when 'Go' is pressed
55 if ((isset($_REQUEST['submit_connect']))) {
56 foreach ($cons as $con) {
57 ${"{$con}_host"} = $_REQUEST[$con . '_host'];
58 ${"{$con}_username"} = $_REQUEST[$con . '_username'];
59 ${"{$con}_password"} = $_REQUEST[$con . '_pass'];
60 ${"{$con}_port"} = $_REQUEST[$con . '_port'];
61 ${"{$con}_socket"} = $_REQUEST[$con . '_socket'];
62 ${"{$con}_db"} = $_REQUEST[$con . '_db'];
63 ${"{$con}_type"} = $_REQUEST[$con . '_type'];
65 if (${"{$con}_type"} == 'cur') {
66 ${"{$con}_connection"} = null;
67 ${"{$con}_server"} = null;
68 ${"{$con}_db"} = $_REQUEST[$con . '_db_sel'];
69 continue;
72 if (isset(${"{$con}_socket"}) && ! empty(${"{$con}_socket"})) {
73 ${"{$con}_server"}['socket'] = ${"{$con}_socket"};
74 } else {
75 ${"{$con}_server"}['host'] = ${"{$con}_host"};
76 if (isset(${"{$con}_port"})
77 && ! empty(${"{$con}_port"})
78 && ((int)${"{$con}_port"} * 1) > 0
79 ) {
80 ${"{$con}_server"}['port'] = (int)${"{$con}_port"};
84 ${"{$con}_connection"} = PMA_DBI_connect(${"{$con}_username"},
85 ${"{$con}_password"}, $is_controluser = false,
86 ${"{$con}_server"}, $auxiliary_connection = true);
87 } // end foreach ($cons as $con)
89 if ((! $src_connection && $src_type != 'cur')
90 || (! $trg_connection && $trg_type != 'cur')
91 ) {
92 /**
93 * Displays the connection error string if
94 * connections are not established
97 echo '<div class="error">';
98 if (! $src_connection && $src_type != 'cur') {
99 echo __('Could not connect to the source') . '<br />';
101 if (! $trg_connection && $trg_type != 'cur') {
102 echo __('Could not connect to the target');
104 echo '</div>';
105 unset($_REQUEST['submit_connect']);
107 } else {
109 * Creating the link object for both source and target databases and
110 * selecting the source and target databases using these links
112 foreach ($cons as $con) {
113 if (${"{$con}_connection"} != null) {
114 ${"{$con}_link"} = PMA_DBI_connect(${"{$con}_username"},
115 ${"{$con}_password"}, $is_controluser = false, ${"{$con}_server"});
116 } else {
117 ${"{$con}_link"} = null;
119 ${"{$con}_db_selected"} = PMA_DBI_select_db(${"{$con}_db"}, ${"{$con}_link"});
120 ${"{$con}_version"} = PMA_DBI_fetch_value('SELECT VERSION()', 0, 0, ${"{$con}_link"});
121 ${"{$con}_is_drizzle"} = (bool)preg_match('/\d{4}\./', ${"{$con}_version"});
122 } // end foreach ($cons as $con)
124 if (($src_db_selected != 1) || ($trg_db_selected != 1)) {
126 * Displays error string if the database(s) did not exist
128 echo '<div class="error">';
129 if ($src_db_selected != 1) {
130 echo sprintf(__('\'%s\' database does not exist.'), htmlspecialchars($src_db));
132 if ($trg_db_selected != 1) {
133 echo sprintf(__('\'%s\' database does not exist.'), htmlspecialchars($trg_db));
135 echo '</div>';
136 unset($_REQUEST['submit_connect']);
138 } else if (($src_db_selected == 1) && ($trg_db_selected == 1)) {
141 * Using PMA_DBI_get_tables() to get all the tables
142 * from target and source databases.
144 $src_tables = PMA_DBI_get_tables($src_db, $src_link);
145 $source_tables_num = sizeof($src_tables);
147 $trg_tables = PMA_DBI_get_tables($trg_db, $trg_link);
148 $target_tables_num = sizeof($trg_tables);
151 * initializing arrays to save matching and non-matching
152 * table names from target and source databases.
154 $unmatched_num_src = 0;
155 $source_tables_uncommon = array();
156 $unmatched_num_trg = 0;
157 $target_tables_uncommon = array();
158 $matching_tables = array();
159 $matching_tables_num = 0;
162 * Using PMA_getMatchingTables to find which of the tables' names match
163 * in target and source database.
165 PMA_getMatchingTables($trg_tables, $src_tables, $matching_tables, $source_tables_uncommon);
167 * Finding the uncommon tables for the target database
168 * using function PMA_getNonMatchingTargetTables()
170 PMA_getNonMatchingTargetTables($trg_tables, $matching_tables, $target_tables_uncommon);
173 * Initializing several arrays to save the data and structure
174 * difference between the source and target databases.
176 $row_count = array(); //number of rows in source table that needs to be created in target database
177 $fields_num = array(); //number of fields in each matching table
178 $delete_array = array(); //stores the primary key values for target tables that have excessive rows than corresponding source tables.
179 $insert_array = array(array(array()));// stores the primary key values for the rows in each source table that are not present in target tables.
180 $update_array = array(array(array())); //stores the primary key values, name of field to be updated, value of the field to be updated for
181 // each row of matching table.
182 $matching_tables_fields = array(); //contains the fields' names for each matching table
183 $matching_tables_keys = array(); //contains the primary keys' names for each matching table
184 $uncommon_tables_fields = array(); //coantains the fields for all the source tables that are not present in target
185 $matching_tables_num = sizeof($matching_tables);
187 $source_columns = array(); //contains the full columns' information for all the source tables' columns
188 $target_columns = array(); //contains the full columns' information for all the target tables' columns
189 $uncommon_columns = array(); //contains names of columns present in source table but absent from the corresponding target table
190 $source_indexes = array(); //contains indexes on all the source tables
191 $target_indexes = array(); //contains indexes on all the target tables
192 $add_indexes_array = array(); //contains the indexes name present in source but absent from target tables
193 $target_tables_keys = array(); //contains the keys of all the target tables
194 $alter_indexes_array = array(); //contains the names of all the indexes for each table that need to be altered in target database
195 $remove_indexes_array = array(); //contains the names of indexes that are excessive in target tables
196 $alter_str_array = array(array()); //contains the criteria for each column that needs to be altered in target tables
197 $add_column_array = array(array()); //contains the name of columns that need to be added in target tables
199 * The criteria array contains all the criteria against which columns are compared for differences.
201 $criteria = array('Field', 'Type', 'Null', 'Collation', 'Key', 'Default', 'Comment');
203 for ($i = 0; $i < sizeof($matching_tables); $i++) {
205 * Finding out all the differences structure, data and index diff
206 * for all the matching tables only
208 PMA_dataDiffInTables($src_db, $trg_db, $src_link, $trg_link,
209 $matching_tables, $matching_tables_fields, $update_array,
210 $insert_array, $delete_array, $fields_num, $i,
211 $matching_tables_keys);
213 PMA_structureDiffInTables($src_db, $trg_db, $src_link, $trg_link,
214 $matching_tables, $source_columns, $target_columns,
215 $alter_str_array, $add_column_array, $uncommon_columns,
216 $criteria, $target_tables_keys, $i);
218 PMA_indexesDiffInTables($src_db, $trg_db, $src_link, $trg_link,
219 $matching_tables, $source_indexes, $target_indexes,
220 $add_indexes_array, $alter_indexes_array, $remove_indexes_array, $i);
223 for ($j = 0; $j < sizeof($source_tables_uncommon); $j++) {
225 * Finding out the number of rows to be added in tables
226 * that need to be added in target database
228 PMA_dataDiffInUncommonTables($source_tables_uncommon, $src_db,
229 $src_link, $j, $row_count);
233 * Storing all arrays in session for use when page is reloaded
234 * for each button press
236 $_SESSION['matching_tables'] = $matching_tables;
237 $_SESSION['update_array'] = $update_array;
238 $_SESSION['insert_array'] = $insert_array;
239 $_SESSION['src_db'] = $src_db;
240 $_SESSION['trg_db'] = $trg_db;
241 $_SESSION['matching_fields'] = $matching_tables_fields;
242 $_SESSION['src_uncommon_tables'] = $source_tables_uncommon;
243 $_SESSION['src_username'] = $src_username ;
244 $_SESSION['trg_username'] = $trg_username;
245 $_SESSION['src_password'] = $src_password;
246 $_SESSION['trg_password'] = $trg_password;
247 $_SESSION['trg_password'] = $trg_password;
248 $_SESSION['src_server'] = $src_server;
249 $_SESSION['trg_server'] = $trg_server;
250 $_SESSION['src_type'] = $src_type;
251 $_SESSION['trg_type'] = $trg_type;
252 $_SESSION['matching_tables_keys'] = $matching_tables_keys;
253 $_SESSION['uncommon_tables_fields'] = $uncommon_tables_fields;
254 $_SESSION['uncommon_tables_row_count'] = $row_count;
255 $_SESSION['target_tables_uncommon'] = $target_tables_uncommon;
256 $_SESSION['uncommon_tables'] = $source_tables_uncommon;
257 $_SESSION['delete_array'] = $delete_array;
258 $_SESSION['uncommon_columns'] = $uncommon_columns;
259 $_SESSION['source_columns'] = $source_columns;
260 $_SESSION['alter_str_array'] = $alter_str_array;
261 $_SESSION['target_tables_keys'] = $target_tables_keys;
262 $_SESSION['add_column_array'] = $add_column_array;
263 $_SESSION['criteria'] = $criteria;
264 $_SESSION['target_tables'] = $trg_tables;
265 $_SESSION['add_indexes_array'] = $add_indexes_array;
266 $_SESSION['alter_indexes_array'] = $alter_indexes_array;
267 $_SESSION['remove_indexes_array'] = $remove_indexes_array;
268 $_SESSION['source_indexes'] = $source_indexes;
269 $_SESSION['target_indexes'] = $target_indexes;
272 * Displays the sub-heading and icons showing Structure Synchronization
273 * and Data Synchronization
276 <form name="synchronize_form" id="synchronize_form" method="post" action="server_synchronize.php">
277 <?php echo PMA_generate_common_hidden_inputs('', ''); ?>
278 <table width="40%">
279 <tr>
280 <td>
281 <img class="icon" src="<?php echo $pmaThemeImage; ?>new_struct.png" width="16" height="16" alt="" />
282 <?php echo __('Structure Synchronization'); ?>
283 </td>
284 <td>
285 <img class="icon" src="<?php echo $pmaThemeImage; ?>new_data.png" width="16" height="16" alt="" />
286 <?php echo __('Data Synchronization'); ?>
287 </td>
288 </tr>
289 </table>
290 <?php
292 * Displays the tables containing the source tables names,
293 * their difference with the target tables and target tables names.
295 PMA_syncDisplayHeaderCompare($src_db, $trg_db);
296 $rows = array();
299 * Display the matching tables' names and difference, first
301 for ($i = 0; $i < count($matching_tables); $i++) {
303 * Calculating the number of updates for each matching table
305 if (isset($update_array[$i]) && isset($update_array[$i][0])
306 && !empty($matching_tables_keys[$i][0])
307 && isset($update_array[$i][0][$matching_tables_keys[$i][0]])) {
308 $num_of_updates = sizeof($update_array[$i]);
309 } else {
310 $num_of_updates = 0;
313 * Calculating the number of insertions for each matching table
315 if (isset($insert_array[$i]) && isset($insert_array[$i][0])
316 && !empty($matching_tables_keys[$i])
317 && isset($insert_array[$i][0][$matching_tables_keys[$i][0]])) {
318 $num_of_insertions = sizeof($insert_array[$i]);
319 } else {
320 $num_of_insertions = 0;
324 * Calculating the number of alter columns, number of columns to be
325 * added, number of columns to be removed,
326 * number of index to be added and removed.
328 $num_alter_cols = 0;
329 $num_insert_cols = 0;
330 $num_remove_cols = 0;
331 $num_add_index = 0;
332 $num_remove_index = 0;
334 if (isset($alter_str_array[$i])) {
335 $num_alter_cols = sizeof($alter_str_array[$i]);
337 if (isset($add_column_array[$i])) {
338 $num_insert_cols = sizeof($add_column_array[$i]);
340 if (isset($uncommon_columns[$i])) {
341 $num_remove_cols = sizeof($uncommon_columns[$i]);
343 if (isset($add_indexes_array[$i])) {
344 $num_add_index = sizeof($add_indexes_array[$i]);
346 if (isset($remove_indexes_array[$i])) {
347 $num_remove_index = sizeof($remove_indexes_array[$i]);
349 if (isset($alter_indexes_array[$i])) {
350 $num_add_index += sizeof($alter_indexes_array[$i]);
351 $num_remove_index += sizeof($alter_indexes_array[$i]);
354 $btn_structure_params = null;
355 $btn_data_params = null;
358 * Display the red button of structure synchronization if there
359 * exists any structure difference or index difference.
361 if (($num_alter_cols > 0)
362 || ($num_insert_cols > 0)
363 || ($num_remove_cols > 0)
364 || ($num_add_index > 0)
365 || ($num_remove_index > 0)
367 $btn_structure_params = array($i, $num_alter_cols, $num_insert_cols,
368 $num_remove_cols, $num_add_index, $num_remove_index);
372 * Display the green button of data synchronization if there exists
373 * any data difference.
375 if ((isset($update_array[$i])
376 || isset($insert_array[$i]))
377 && !empty($matching_tables_keys[$i])
379 if (isset($update_array[$i][0][$matching_tables_keys[$i][0]])
380 || isset($insert_array[$i][0][$matching_tables_keys[$i][0]])
382 $btn_data_params = array($i, $num_of_updates,
383 $num_of_insertions, null, null, null);
387 $rows[] = array(
388 'src_table_name' => $matching_tables[$i],
389 'dst_table_name' => $matching_tables[$i],
390 'btn_type' => 'M',
391 'btn_structure' => $btn_structure_params,
392 'btn_data' => $btn_data_params
396 * Displays the tables' names present in source but missing from target
398 for ($j = 0; $j < count($source_tables_uncommon); $j++) {
399 $row = array(
400 'src_table_name' => '+ ' . $source_tables_uncommon[$j],
401 'dst_table_name' => $source_tables_uncommon[$j] . ' (' . __('not present') . ')',
402 'btn_type' => 'U',
403 'btn_structure' => array($j, null, null, null, null, null),
404 'btn_data' => null
406 if ($row_count[$j] > 0) {
407 $row['btn_data'] = array($j, null, $row_count[$j], null, null, null);
409 $rows[] = $row;
411 foreach ($target_tables_uncommon as $tbl_nc_name) {
412 $rows[] = array(
413 'src_table_name' => '',
414 'dst_table_name' => $tbl_nc_name);
417 * Displays the target tables names
419 PMA_syncDisplayDataCompare($rows);
420 echo '</table>
421 </div>
422 </fieldset>';
425 * This "list" div will contain a table and each row will depict
426 * information about structure/data difference in tables.
427 * Rows will be generated dynamically as soon as the colored
428 * buttons "D" or "S" are clicked.
431 echo '<fieldset style="padding:0"><div id="list" style="overflow:auto; height:140px; padding:1em">
433 <table>
434 <thead>
435 <tr style="width: 100%;">
436 <th id="table_name" style="width: 10%;" colspan="1">' . __('Table') . ' </th>
437 <th id="str_diff" style="width: 65%;" colspan="6">' . __('Structure Difference') . ' </th>
438 <th id="data_diff" style="width: 20%;" colspan="2">' . __('Data Difference') . '</th>
439 </tr>
440 <tr style="width: 100%;">
441 <th style="width: 10%;">' . __('Table name') . '</th>
442 <th style="width: 10%;">' . __('Create table'). '</th>
443 <th style="width: 11%;">' . __('Add column(s)') . '</th>
444 <th style="width: 13%;">' . __('Remove column(s)') . '</th>
445 <th style="width: 11%;">' . __('Alter column(s)') . '</th>
446 <th style="width: 12%;">' . __('Remove index(s)') . '</th>
447 <th style="width: 11%;">' . __('Apply index(s)') . '</th>
448 <th style="width: 10%;">'. __('Update row(s)') . '</th>
449 <th style="width: 10%;">' . __('Insert row(s)') . '</th>
450 </tr>
451 </thead>
452 <tbody></tbody>
453 </table>
454 </div></fieldset>';
456 * This fieldset displays the checkbox to confirm deletion of previous rows from target tables
458 echo '<fieldset>
459 <p><input type= "checkbox" name="delete_rows" id ="delete_rows" /><label for="delete_rows">'
460 . __('Would you like to delete all the previous rows from target tables?')
461 . '</label> </p>
462 </fieldset>
463 <fieldset class="tblFooters">';
464 echo '<input type="button" name="apply_changes" value="'
465 . __('Apply Selected Changes')
466 . '" onclick ="ApplySelectedChanges('
467 . "'" . htmlspecialchars($_SESSION['token']) . "'" . ')" />';
468 echo '<input type="submit" name="synchronize_db" value="'
469 . __('Synchronize Databases') . '" />' . '</fieldset>';
470 echo '</form>';
473 } // end if ((isset($_REQUEST['submit_connect'])))
476 * Display the page when 'Apply Selected Changes' is pressed
478 if (isset($_REQUEST['Table_ids'])) {
480 * Displays success message
482 echo '<div class="success">'
483 . __('Selected target tables have been synchronized with source tables.')
484 . '</div>';
486 $src_db = $_SESSION['src_db'];
487 $trg_db = $_SESSION['trg_db'];
488 $update_array = $_SESSION['update_array'];
489 $insert_array = $_SESSION['insert_array'];
490 $src_username = $_SESSION['src_username'];
491 $trg_username = $_SESSION['trg_username'];
492 $src_password = $_SESSION['src_password'];
493 $trg_password = $_SESSION['trg_password'];
494 $src_server = $_SESSION['src_server'];
495 $trg_server = $_SESSION['trg_server'];
496 $src_type = $_SESSION['src_type'];
497 $trg_type = $_SESSION['trg_type'];
498 $uncommon_tables = $_SESSION['uncommon_tables'];
499 $matching_tables = $_SESSION['matching_tables'];
500 $matching_tables_keys = $_SESSION['matching_tables_keys'];
501 $matching_tables_fields = $_SESSION['matching_fields'];
502 $source_tables_uncommon = $_SESSION['src_uncommon_tables'];
503 $uncommon_tables_fields = $_SESSION['uncommon_tables_fields'];
504 $target_tables_uncommon = $_SESSION['target_tables_uncommon'];
505 $row_count = $_SESSION['uncommon_tables_row_count'];
506 $target_tables = $_SESSION['target_tables'];
508 $delete_array = $_SESSION['delete_array'];
509 $uncommon_columns = $_SESSION['uncommon_columns'];
510 $source_columns = $_SESSION['source_columns'];
511 $alter_str_array = $_SESSION['alter_str_array'];
512 $criteria = $_SESSION['criteria'];
513 $target_tables_keys = $_SESSION['target_tables_keys'];
514 $add_column_array = $_SESSION['add_column_array'];
515 $add_indexes_array = $_SESSION['add_indexes_array'];
516 $alter_indexes_array = $_SESSION['alter_indexes_array'];
517 $remove_indexes_array = $_SESSION['remove_indexes_array'];
518 $source_indexes = $_SESSION['source_indexes'];
519 $target_indexes = $_SESSION['target_indexes'];
520 $uncommon_cols = $uncommon_columns;
523 * Creating link object for source and target databases
525 foreach ($cons as $con) {
526 if (${"{$con}_type"} != "cur") {
527 ${"{$con}_link"} = PMA_DBI_connect(${"{$con}_username"},
528 ${"{$con}_password"}, $is_controluser = false, ${"{$con}_server"});
529 } else {
530 ${"{$con}_link"} = null;
531 // working on current server, so initialize this for tracking
532 // (does not work if user defined current server as a remote one)
533 $GLOBALS['db'] = ${"{$con}_db"};
535 } // end foreach ($cons as $con)
538 * Initializing arrays to save the table ids whose data and structure difference is to be applied
540 $matching_table_data_diff = array(); //stores id of matching table having data difference
541 $matching_table_structure_diff = array(); //stores id of matching tables having structure difference
542 $uncommon_table_structure_diff = array(); //stores id of uncommon tables having structure difference
543 $uncommon_table_data_diff = array(); //stores id of uncommon tables having data difference
545 for ($i = 0; isset($_REQUEST[$i]); $i++ ) {
546 if (isset($_REQUEST[$i])) {
547 $table_id = explode("US", $_REQUEST[$i]);
548 if (isset($table_id[1])) {
549 $uncommon_table_structure_diff[] = $table_id[1];
551 $table_id = explode("UD", $_REQUEST[$i]);
552 if (isset($table_id[1])) {
553 $uncommon_table_data_diff[] = $table_id[1];
555 $table_id = explode("MS", $_REQUEST[$i]);
556 if (isset($table_id[1])) {
557 $matching_table_structure_diff[] = $table_id[1];
560 $table_id = explode("MD", $_REQUEST[$i]);
561 if (isset($table_id[1])) {
562 $matching_table_data_diff[] = $table_id[1];
565 } // end for
567 * Applying the structure difference on selected matching tables
569 for ($q = 0; $q < sizeof($matching_table_structure_diff); $q++) {
570 if (isset($alter_str_array[$matching_table_structure_diff[$q]])) {
571 PMA_alterTargetTableStructure($trg_db, $trg_link, $matching_tables,
572 $source_columns, $alter_str_array, $matching_tables_fields,
573 $criteria, $matching_tables_keys, $target_tables_keys,
574 $matching_table_structure_diff[$q], false);
576 unset($alter_str_array[$matching_table_structure_diff[$q]]);
578 if (isset($add_column_array[$matching_table_structure_diff[$q]])) {
579 PMA_findDeleteRowsFromTargetTables($delete_array, $matching_tables,
580 $matching_table_structure_diff[$q], $target_tables_keys,
581 $matching_tables_keys, $trg_db, $trg_link, $src_db, $src_link);
583 if (isset($delete_array[$matching_table_structure_diff[$q]])) {
584 PMA_deleteFromTargetTable($trg_db, $trg_link, $matching_tables,
585 $matching_table_structure_diff[$q], $target_tables_keys,
586 $delete_array, false);
588 unset($delete_array[$matching_table_structure_diff[$q]]);
590 PMA_addColumnsInTargetTable($src_db, $trg_db, $src_link, $trg_link,
591 $matching_tables, $source_columns, $add_column_array,
592 $matching_tables_fields, $criteria, $matching_tables_keys,
593 $target_tables_keys, $uncommon_tables, $uncommon_tables_fields,
594 $matching_table_structure_diff[$q], $uncommon_cols, false);
596 unset($add_column_array[$matching_table_structure_diff[$q]]);
598 if (isset($uncommon_columns[$matching_table_structure_diff[$q]])) {
599 PMA_removeColumnsFromTargetTable($trg_db, $trg_link, $matching_tables,
600 $uncommon_columns, $matching_table_structure_diff[$q], false);
602 unset($uncommon_columns[$matching_table_structure_diff[$q]]);
604 if (isset($add_indexes_array[$matching_table_structure_diff[$q]])
605 || isset($remove_indexes_array[$matching_table_structure_diff[$q]])
606 || isset($alter_indexes_array[$matching_table_structure_diff[$q]])
608 PMA_applyIndexesDiff ($trg_db, $trg_link, $matching_tables,
609 $source_indexes, $target_indexes, $add_indexes_array,
610 $alter_indexes_array, $remove_indexes_array,
611 $matching_table_structure_diff[$q], false);
613 unset($add_indexes_array[$matching_table_structure_diff[$q]]);
614 unset($alter_indexes_array[$matching_table_structure_diff[$q]]);
615 unset($remove_indexes_array[$matching_table_structure_diff[$q]]);
619 * Applying the data difference. First checks if structure diff is applied or not.
620 * If not, then apply structure difference first then apply data difference.
622 for ($p = 0; $p < sizeof($matching_table_data_diff); $p++) {
623 if ($_REQUEST['checked'] == 'true') {
624 PMA_findDeleteRowsFromTargetTables($delete_array, $matching_tables,
625 $matching_table_data_diff[$p], $target_tables_keys,
626 $matching_tables_keys, $trg_db, $trg_link, $src_db, $src_link);
628 if (isset($delete_array[$matching_table_data_diff[$p]])) {
629 PMA_deleteFromTargetTable($trg_db, $trg_link, $matching_tables,
630 $matching_table_data_diff[$p], $target_tables_keys,
631 $delete_array, false);
633 unset($delete_array[$matching_table_data_diff[$p]]);
636 if (isset($alter_str_array[$matching_table_data_diff[$p]])) {
637 PMA_alterTargetTableStructure($trg_db, $trg_link, $matching_tables,
638 $source_columns, $alter_str_array, $matching_tables_fields,
639 $criteria, $matching_tables_keys, $target_tables_keys,
640 $matching_table_data_diff[$p], false);
642 unset($alter_str_array[$matching_table_data_diff[$p]]);
644 if (isset($add_column_array[$matching_table_data_diff[$p]])) {
645 PMA_findDeleteRowsFromTargetTables($delete_array, $matching_tables,
646 $matching_table_data_diff[$p], $target_tables_keys,
647 $matching_tables_keys, $trg_db, $trg_link, $src_db, $src_link);
649 if (isset($delete_array[$matching_table_data_diff[$p]])) {
650 PMA_deleteFromTargetTable($trg_db, $trg_link, $matching_tables,
651 $matching_table_data_diff[$p], $target_tables_keys,
652 $delete_array, false);
654 unset($delete_array[$matching_table_data_diff[$p]]);
656 PMA_addColumnsInTargetTable($src_db, $trg_db, $src_link, $trg_link,
657 $matching_tables, $source_columns, $add_column_array,
658 $matching_tables_fields, $criteria, $matching_tables_keys,
659 $target_tables_keys, $uncommon_tables, $uncommon_tables_fields,
660 $matching_table_data_diff[$p], $uncommon_cols, false);
662 unset($add_column_array[$matching_table_data_diff[$p]]);
664 if (isset($uncommon_columns[$matching_table_data_diff[$p]])) {
665 PMA_removeColumnsFromTargetTable($trg_db, $trg_link, $matching_tables,
666 $uncommon_columns, $matching_table_data_diff[$p], false);
668 unset($uncommon_columns[$matching_table_data_diff[$p]]);
670 if ((isset($matching_table_structure_diff[$q])
671 && isset($add_indexes_array[$matching_table_structure_diff[$q]]))
672 || (isset($matching_table_structure_diff[$q])
673 && isset($remove_indexes_array[$matching_table_structure_diff[$q]]))
674 || (isset($matching_table_structure_diff[$q])
675 && isset($alter_indexes_array[$matching_table_structure_diff[$q]]))
677 PMA_applyIndexesDiff ($trg_db, $trg_link, $matching_tables,
678 $source_indexes, $target_indexes, $add_indexes_array,
679 $alter_indexes_array, $remove_indexes_array,
680 $matching_table_structure_diff[$q], false);
682 unset($add_indexes_array[$matching_table_structure_diff[$q]]);
683 unset($alter_indexes_array[$matching_table_structure_diff[$q]]);
684 unset($remove_indexes_array[$matching_table_structure_diff[$q]]);
687 * Applying the data difference.
689 PMA_updateTargetTables($matching_tables, $update_array, $src_db, $trg_db,
690 $trg_link, $matching_table_data_diff[$p], $matching_tables_keys, false);
692 PMA_insertIntoTargetTable($matching_tables, $src_db, $trg_db, $src_link,
693 $trg_link, $matching_tables_fields, $insert_array,
694 $matching_table_data_diff[$p], $matching_tables_keys, $source_columns,
695 $add_column_array, $criteria, $target_tables_keys, $uncommon_tables,
696 $uncommon_tables_fields, $uncommon_cols, $alter_str_array,
697 $source_indexes, $target_indexes, $add_indexes_array,
698 $alter_indexes_array, $delete_array, $update_array, false);
701 * Updating the session variables to the latest values of the arrays.
703 $_SESSION['delete_array'] = $delete_array;
704 $_SESSION['uncommon_columns'] = $uncommon_columns;
705 $_SESSION['alter_str_array'] = $alter_str_array;
706 $_SESSION['add_column_array'] = $add_column_array;
707 $_SESSION['add_indexes_array'] = $add_indexes_array;
708 $_SESSION['remove_indexes_array'] = $remove_indexes_array;
709 $_SESSION['insert_array'] = $insert_array;
710 $_SESSION['update_array'] = $update_array;
713 * Applying structure difference to selected non-matching tables
714 * (present in Source but absent from Target).
716 for ($s = 0; $s < sizeof($uncommon_table_structure_diff); $s++) {
717 PMA_createTargetTables($src_db, $trg_db, $src_link, $trg_link,
718 $uncommon_tables, $uncommon_table_structure_diff[$s],
719 $uncommon_tables_fields, false);
720 $_SESSION['uncommon_tables_fields'] = $uncommon_tables_fields;
722 unset($uncommon_tables[$uncommon_table_structure_diff[$s]]);
725 * Applying data difference to selected non-matching tables
726 * (present in Source but absent from Target).
727 * Before data synchronization, structure synchronization is confirmed.
729 for ($r = 0; $r < sizeof($uncommon_table_data_diff); $r++) {
730 if (!(in_array($uncommon_table_data_diff[$r], $uncommon_table_structure_diff))) {
731 if (isset($uncommon_tables[$uncommon_table_data_diff[$r]])) {
732 PMA_createTargetTables($src_db, $trg_db, $src_link, $trg_link,
733 $uncommon_tables, $uncommon_table_data_diff[$r],
734 $uncommon_tables_fields, false);
735 $_SESSION['uncommon_tables_fields'] = $uncommon_tables_fields;
737 unset($uncommon_tables[$uncommon_table_data_diff[$r]]);
740 PMA_populateTargetTables($src_db, $trg_db, $src_link, $trg_link,
741 $source_tables_uncommon, $uncommon_table_data_diff[$r],
742 $_SESSION['uncommon_tables_fields'], false);
744 unset($row_count[$uncommon_table_data_diff[$r]]);
747 * Again all the tables from source and target database are displayed with their differences.
748 * The differences have been removed from tables that have been synchronized
750 echo '<form name="applied_difference" id="synchronize_form" method="post" action="server_synchronize.php">'
751 . PMA_generate_common_hidden_inputs('', '');
753 PMA_syncDisplayHeaderCompare($src_db, $trg_db);
754 $rows = array();
755 for ($i = 0; $i < count($matching_tables); $i++) {
756 $num_alter_cols = 0;
757 $num_insert_cols = 0;
758 $num_remove_cols = 0;
759 $num_add_index = 0;
760 $num_remove_index = 0;
762 if (isset($alter_str_array[$i])) {
763 $num_alter_cols = sizeof($alter_str_array[$i]);
765 if (isset($add_column_array[$i])) {
766 $num_insert_cols = sizeof($add_column_array[$i]);
768 if (isset($uncommon_columns[$i])) {
769 $num_remove_cols = sizeof($uncommon_columns[$i]);
771 if (isset($add_indexes_array[$i])) {
772 $num_add_index = sizeof($add_indexes_array[$i]);
774 if (isset($remove_indexes_array[$i])) {
775 $num_remove_index = sizeof($remove_indexes_array[$i]);
778 $btn_structure_params = null;
779 $btn_data_params = null;
781 if (($num_alter_cols > 0)
782 || ($num_insert_cols > 0)
783 || ($num_remove_cols > 0)
784 || ($num_add_index > 0)
785 || ($num_remove_index > 0)
787 $btn_structure_params = array($i, $num_alter_cols, $num_insert_cols,
788 $num_remove_cols, $num_add_index, $num_remove_index);
790 if (!(in_array($i, $matching_table_data_diff))) {
791 if (isset($matching_tables_keys[$i][0])
792 && isset($update_array[$i][0][$matching_tables_keys[$i][0]])
794 if (isset($update_array[$i])) {
795 $num_of_updates = sizeof($update_array[$i]);
796 } else {
797 $num_of_updates = 0;
799 } else {
800 $num_of_updates = 0;
802 if (isset($matching_tables_keys[$i][0])
803 && isset($insert_array[$i][0][$matching_tables_keys[$i][0]])
805 if (isset($insert_array[$i])) {
806 $num_of_insertions = sizeof($insert_array[$i]);
807 } else {
808 $num_of_insertions = 0;
810 } else {
811 $num_of_insertions = 0;
814 if ((isset($matching_tables_keys[$i][0])
815 && isset($update_array[$i][0][$matching_tables_keys[$i][0]]))
816 || (isset($matching_tables_keys[$i][0])
817 && isset($insert_array[$i][0][$matching_tables_keys[$i][0]]))
819 $btn_data_params = array($i, $num_of_updates, $num_of_insertions,
820 null, null, null);
822 } else {
823 unset($update_array[$i]);
824 unset($insert_array[$i]);
826 $rows[] = array(
827 'src_table_name' => $matching_tables[$i],
828 'dst_table_name' => $matching_tables[$i],
829 'btn_type' => 'M',
830 'btn_structure' => $btn_structure_params,
831 'btn_data' => $btn_data_params
835 * placing updated value of arrays in session
838 $_SESSION['update_array'] = $update_array;
839 $_SESSION['insert_array'] = $insert_array;
841 for ($j = 0; $j < count($source_tables_uncommon); $j++) {
842 $btn_structure_params = null;
843 $btn_data_params = null;
846 * Display the difference only when it has not been applied
848 if (!(in_array($j, $uncommon_table_structure_diff))) {
849 if (isset($uncommon_tables[$j])) {
850 $btn_structure_params = array($j, null, null, null, null, null);
852 $dst_table_name = $source_tables_uncommon[$j] . ' (' . __('not present') . ')';
853 } else {
854 unset($uncommon_tables[$j]);
855 $dst_table_name = $source_tables_uncommon[$j];
858 * Display the difference only when it has not been applied
860 if (!(in_array($j, $uncommon_table_data_diff))) {
861 if (isset($row_count[$j]) && ($row_count[$j] > 0)) {
862 $btn_data_params = array($j, null, $row_count[$j], null, null, null);
864 } else {
865 unset($row_count[$j]);
868 $rows[] = array(
869 'src_table_name' => $source_tables_uncommon[$j],
870 'dst_table_name' => $dst_table_name,
871 'btn_type' => 'U',
872 'btn_structure' => $btn_structure_params,
873 'btn_data' => $btn_data_params
877 * placing the latest values of arrays in session
880 $_SESSION['uncommon_tables'] = $uncommon_tables;
881 $_SESSION['uncommon_tables_row_count'] = $row_count;
885 * Displaying the target database tables
887 foreach ($target_tables_uncommon as $tbl_nc_name) {
888 $rows[] = array(
889 'src_table_name' => '',
890 'dst_table_name' => $tbl_nc_name);
892 PMA_syncDisplayDataCompare($rows);
893 echo '</table>
894 </div>
895 </fieldset>';
898 * This "list" div will contain a table and each row will depict information about
899 * structure/data difference in tables.
900 * Rows will be generated dynamically as soon as the colored buttons "D" or "S"
901 * are clicked.
904 echo '<fieldset style="padding:0"><div id="list" style = "overflow:auto; height:140px; padding:1em">';
905 echo '<table>
906 <thead>
907 <tr style="width: 100%;">
908 <th id="table_name" style="width: 10%;" colspan="1">' . __('Table') . ' </th>
909 <th id="str_diff" style="width: 65%;" colspan="6">' . __('Structure Difference') . ' </th>
910 <th id="data_diff" style="width: 20%;" colspan="2">' . __('Data Difference') . '</th>
911 </tr>
912 <tr style="width: 100%;">
913 <th style="width: 10%;">' . __('Table name') . '</th>
914 <th style="width: 10%;">' . __('Create table'). '</th>
915 <th style="width: 11%;">' . __('Add column(s)') . '</th>
916 <th style="width: 13%;">' . __('Remove column(s)') . '</th>
917 <th style="width: 11%;">' . __('Alter column(s)') . '</th>
918 <th style="width: 12%;">' . __('Remove index(s)') . '</th>
919 <th style="width: 11%;">' . __('Apply index(s)') . '</th>
920 <th style="width: 10%;">' . __('Update row(s)') . '</th>
921 <th style="width: 10%;">' . __('Insert row(s)') . '</th>
922 </tr>
923 </thead>
924 <tbody></tbody>
925 </table>
926 </div></fieldset>';
929 * This fieldset displays the checkbox to confirm deletion of previous rows from target tables
931 echo '<fieldset>
932 <p><input type="checkbox" name="delete_rows" id ="delete_rows" /><label for="delete_rows">'
933 . __('Would you like to delete all the previous rows from target tables?') . '</label> </p>
934 </fieldset>';
936 echo '<fieldset class="tblFooters">';
937 echo '<input type="button" name="apply_changes" value="'
938 . __('Apply Selected Changes') . '" onclick ="ApplySelectedChanges('
939 . "'" . htmlspecialchars($_SESSION['token']) . "'" .')" />';
940 echo '<input type="submit" name="synchronize_db" value="'
941 . __('Synchronize Databases') . '" />'
942 . '</fieldset>';
943 echo '</form>';
947 * Displays the page when 'Synchronize Databases' is pressed.
950 if (isset($_REQUEST['synchronize_db'])) {
952 $src_db = $_SESSION['src_db'];
953 $trg_db = $_SESSION['trg_db'];
954 $update_array = $_SESSION['update_array'];
955 $insert_array = $_SESSION['insert_array'];
956 $src_username = $_SESSION['src_username'];
957 $trg_username = $_SESSION['trg_username'];
958 $src_password = $_SESSION['src_password'];
959 $trg_password = $_SESSION['trg_password'];
960 $matching_tables = $_SESSION['matching_tables'];
961 $matching_tables_keys = $_SESSION['matching_tables_keys'];
962 $matching_tables_fields = $_SESSION['matching_fields'];
963 $source_tables_uncommon = $_SESSION['src_uncommon_tables'];
964 $uncommon_tables_fields = $_SESSION['uncommon_tables_fields'];
965 $target_tables_uncommon = $_SESSION['target_tables_uncommon'];
966 $row_count = $_SESSION['uncommon_tables_row_count'];
967 $uncommon_tables = $_SESSION['uncommon_tables'];
968 $target_tables = $_SESSION['target_tables'];
970 $delete_array = $_SESSION['delete_array'];
971 $uncommon_columns = $_SESSION['uncommon_columns'];
972 $source_columns = $_SESSION['source_columns'];
973 $alter_str_array = $_SESSION['alter_str_array'];
974 $criteria = $_SESSION['criteria'];
975 $target_tables_keys = $_SESSION['target_tables_keys'];
976 $add_column_array = $_SESSION['add_column_array'];
977 $add_indexes_array = $_SESSION['add_indexes_array'];
978 $alter_indexes_array = $_SESSION['alter_indexes_array'];
979 $remove_indexes_array = $_SESSION['remove_indexes_array'];
980 $source_indexes = $_SESSION['source_indexes'];
981 $target_indexes = $_SESSION['target_indexes'];
982 $uncommon_cols = $uncommon_columns;
985 * Display success message.
987 echo '<div class="success">'
988 . __('Target database has been synchronized with source database')
989 . '</div>';
991 * Displaying all the tables of source and target database
992 * and now no difference is there.
994 PMA_syncDisplayHeaderCompare($src_db, $trg_db);
995 $rows = array();
996 for ($i = 0; $i < count($matching_tables); $i++) {
997 $rows[] = array(
998 'src_table_name' => $matching_tables[$i],
999 'dst_table_name' => $matching_tables[$i]);
1001 foreach ($source_tables_uncommon as $tbl_nc_name) {
1002 $rows[] = array(
1003 'src_table_name' => '+ ' . $tbl_nc_name,
1004 'dst_table_name' => $tbl_nc_name);
1006 foreach ($target_tables_uncommon as $tbl_nc_name) {
1007 $rows[] = array(
1008 'src_table_name' => '',
1009 'dst_table_name' => $tbl_nc_name);
1011 PMA_syncDisplayDataCompare($rows);
1012 echo '</table>
1013 </div>
1014 </fieldset>';
1017 * connecting the source and target servers
1019 if ('cur' != $_SESSION['src_type']) {
1020 $src_link = PMA_DBI_connect($src_username, $src_password, $is_controluser = false, $_SESSION['src_server']);
1021 $src_version = PMA_DBI_fetch_value('SELECT VERSION()', 0, 0, $src_link);
1022 $src_is_drizzle = (bool)preg_match('/\d{4}\./', $src_version);
1023 } else {
1024 $src_link = $GLOBALS['userlink'];
1025 $src_version = PMA_MYSQL_STR_VERSION;
1026 $src_is_drizzle = PMA_DRIZZLE;
1027 // working on current server, so initialize this for tracking
1028 // (does not work if user defined current server as a remote one)
1029 $GLOBALS['db'] = $_SESSION['src_db'];
1031 if ('cur' != $_SESSION['trg_type']) {
1032 $trg_link = PMA_DBI_connect($trg_username, $trg_password, $is_controluser = false, $_SESSION['trg_server']);
1033 $trg_version = PMA_DBI_fetch_value('SELECT VERSION()', 0, 0, $trg_link);
1034 $trg_is_drizzle = (bool)preg_match('/\d{4}\./', $trg_version);
1035 } else {
1036 $trg_link = $GLOBALS['userlink'];
1037 $trg_version = PMA_MYSQL_STR_VERSION;
1038 $trg_is_drizzle = PMA_DRIZZLE;
1039 // working on current server, so initialize this for tracking
1040 $GLOBALS['db'] = $_SESSION['trg_db'];
1044 * Displaying the queries.
1046 echo '<fieldset><legend>' . __('Executed queries') . '</legend>';
1048 * Applying all sorts of differences for each matching table
1050 for ($p = 0; $p < sizeof($matching_tables); $p++) {
1052 * If the check box is checked for deleting previous rows from the target database tables then
1053 * first find out rows to be deleted and then delete the rows.
1055 if (isset($_REQUEST['delete_rows'])) {
1056 PMA_findDeleteRowsFromTargetTables($delete_array, $matching_tables, $p,
1057 $target_tables_keys, $matching_tables_keys,
1058 $trg_db, $trg_link, $src_db, $src_link);
1060 if (isset($delete_array[$p])) {
1061 PMA_deleteFromTargetTable($trg_db, $trg_link, $matching_tables, $p,
1062 $target_tables_keys, $delete_array, true);
1063 unset($delete_array[$p]);
1066 if (isset($alter_str_array[$p])) {
1067 PMA_alterTargetTableStructure($trg_db, $trg_link, $matching_tables,
1068 $source_columns, $alter_str_array, $matching_tables_fields,
1069 $criteria, $matching_tables_keys, $target_tables_keys, $p, true);
1070 unset($alter_str_array[$p]);
1072 if (! empty($add_column_array[$p])) {
1073 PMA_findDeleteRowsFromTargetTables($delete_array, $matching_tables, $p,
1074 $target_tables_keys, $matching_tables_keys,
1075 $trg_db, $trg_link, $src_db, $src_link);
1077 if (isset($delete_array[$p])) {
1078 PMA_deleteFromTargetTable($trg_db, $trg_link, $matching_tables, $p,
1079 $target_tables_keys, $delete_array, true);
1080 unset($delete_array[$p]);
1082 PMA_addColumnsInTargetTable($src_db, $trg_db, $src_link, $trg_link,
1083 $matching_tables, $source_columns, $add_column_array,
1084 $matching_tables_fields, $criteria, $matching_tables_keys,
1085 $target_tables_keys, $uncommon_tables, $uncommon_tables_fields,
1086 $p, $uncommon_cols, true);
1087 unset($add_column_array[$p]);
1089 if (isset($uncommon_columns[$p])) {
1090 PMA_removeColumnsFromTargetTable($trg_db, $trg_link, $matching_tables,
1091 $uncommon_columns, $p, true);
1092 unset($uncommon_columns[$p]);
1094 if (isset($matching_table_structure_diff)
1095 && (isset($add_indexes_array[$matching_table_structure_diff[$p]])
1096 || isset($remove_indexes_array[$matching_table_structure_diff[$p]])
1097 || isset($alter_indexes_array[$matching_table_structure_diff[$p]]))
1099 PMA_applyIndexesDiff ($trg_db, $trg_link, $matching_tables,
1100 $source_indexes, $target_indexes, $add_indexes_array,
1101 $alter_indexes_array, $remove_indexes_array,
1102 $matching_table_structure_diff[$p], true);
1104 unset($add_indexes_array[$matching_table_structure_diff[$p]]);
1105 unset($alter_indexes_array[$matching_table_structure_diff[$p]]);
1106 unset($remove_indexes_array[$matching_table_structure_diff[$p]]);
1109 PMA_updateTargetTables($matching_tables, $update_array, $src_db, $trg_db,
1110 $trg_link, $p, $matching_tables_keys, true);
1112 PMA_insertIntoTargetTable(
1113 $matching_tables, $src_db, $trg_db, $src_link,
1114 $trg_link, $matching_tables_fields, $insert_array, $p,
1115 $matching_tables_keys, $matching_tables_keys, $source_columns,
1116 $add_column_array, $criteria, $target_tables_keys, $uncommon_tables,
1117 $uncommon_tables_fields, $uncommon_cols, $alter_str_array, $source_indexes,
1118 $target_indexes, $add_indexes_array,
1119 $alter_indexes_array, $delete_array, $update_array, true
1124 * Creating and populating tables present in source but absent
1125 * from target database.
1127 for ($q = 0; $q < sizeof($source_tables_uncommon); $q++) {
1128 if (isset($uncommon_tables[$q])) {
1129 PMA_createTargetTables($src_db, $trg_db, $src_link, $trg_link,
1130 $source_tables_uncommon, $q, $uncommon_tables_fields, true);
1132 if (isset($row_count[$q])) {
1133 PMA_populateTargetTables($src_db, $trg_db, $src_link, $trg_link,
1134 $source_tables_uncommon, $q, $uncommon_tables_fields, true);
1137 echo "</fieldset>";
1141 * Displays the main page when none of the following buttons is pressed
1144 if (! isset($_REQUEST['submit_connect'])
1145 && ! isset($_REQUEST['synchronize_db'])
1146 && ! isset($_REQUEST['Table_ids'])
1149 * Displays the sub-page heading
1151 echo '<h2>' . ($GLOBALS['cfg']['MainPageIconic']
1152 ? PMA_getImage('s_sync.png')
1153 : '')
1154 . __('Synchronize')
1155 .'</h2>';
1157 echo '<div id="serverstatus">
1158 <form name="connection_form" id="connection_form" method="post" action="server_synchronize.php"
1159 >' // TODO: add check if all var. are filled in
1160 . PMA_generate_common_hidden_inputs('', '');
1161 echo '<fieldset>';
1162 echo '<legend>' . __('Synchronize') . '</legend>';
1164 * Displays the forms
1167 $databases = PMA_DBI_get_databases_full(null, false, null, 'SCHEMA_NAME',
1168 'ASC', 0, true);
1170 $databases_to_hide = array(
1171 'information_schema',
1172 'mysql'
1174 if (PMA_DRIZZLE) {
1175 $databases_to_hide[] = 'data_dictionary';
1178 if ($GLOBALS['cfg']['AllowArbitraryServer'] === false) {
1179 $possibly_readonly = ' readonly="readonly"';
1180 } else {
1181 $possibly_readonly = '';
1184 foreach ($cons as $type) {
1185 if ('src' == $type) {
1186 $database_header = __('Source database');
1187 } else {
1188 $database_header = __('Target database');
1191 $database_header .= PMA_showHint(PMA_sanitize(sprintf('%sAllowArbitraryServer%s',
1192 '[a@./Documentation.html#AllowArbitraryServer@_blank]', '[/a]')));
1194 <table id="serverconnection_<?php echo $type; ?>_remote" class="data noclick">
1195 <caption class="tblHeaders"><?php echo $database_header; ?></caption>
1196 <tr class="odd">
1197 <td colspan="2" style="text-align: center">
1198 <select name="<?php echo $type; ?>_type" id="<?php echo $type; ?>_type" class="server_selector">
1199 <?php
1200 if ($GLOBALS['cfg']['AllowArbitraryServer']) {
1201 $preselected_option = 'rmt';
1202 echo '<option value="rmt" selected="selected">' . __('Enter manually') . '</option>';
1203 } else {
1204 $preselected_option = 'cur';
1206 echo '<option value="cur"';
1207 if ('cur' == $preselected_option) {
1208 echo ' selected="selected"';
1210 echo '>' . __('Current connection') . '</option>';
1212 $loaded_dbi = $GLOBALS['cfg']['Server']['extension'];
1213 foreach ($GLOBALS['cfg']['Servers'] as $key => $tmp_server) {
1214 if (empty($tmp_server['host']) && empty($tmp_server['socket'])) {
1215 continue;
1218 if (!empty($tmp_server['verbose'])) {
1219 $label = $tmp_server['verbose'];
1220 } else {
1221 $label = $tmp_server['host'];
1222 if (!empty($tmp_server['port'])) {
1223 $label .= ':' . $tmp_server['port'];
1227 if ($loaded_dbi == 'drizzle' && $tmp_server['extension'] != 'drizzle'
1228 || $loaded_dbi != 'drizzle' && $tmp_server['extension'] == 'drizzle') {
1229 // incompatible connection protocols
1230 $disabled = ' disabled="disabled"';
1231 $value = '';
1232 } else {
1233 $disabled = '';
1234 $value = $tmp_server['host'];
1235 $value .= '||||';
1236 if (empty($tmp_server['port']) && empty($tmp_server['socket'])) {
1237 $value .= '3306';
1238 } else {
1239 $value .= $tmp_server['port'];
1241 $value .= '||||';
1242 $value .= $tmp_server['socket'];
1243 $value .= '||||';
1244 $value .= $tmp_server['user'];
1245 $value .= '||||';
1246 $value .= $tmp_server['only_db'];
1249 echo '<option value="' . $value . '"' . $disabled . '>'
1250 . sprintf(__('Configuration: %s'), htmlspecialchars($label)) . '</option>';
1251 } // end foreach
1253 </select>
1254 </td>
1255 </tr>
1256 <tr class="even toggler remote-server">
1257 <td><?php echo __('Server'); ?></td>
1258 <td><input type="text" name="<?php echo $type; ?>_host" class="server-host" <?php echo $possibly_readonly; ?>/></td>
1259 </tr>
1260 <tr class="odd toggler remote-server">
1261 <td><?php echo __('Port'); ?></td>
1262 <td><input type="text" name="<?php echo $type; ?>_port" class="server-port" <?php echo $possibly_readonly; ?> value="3306" maxlength="5" size="5" /></td>
1263 </tr>
1264 <tr class="even toggler remote-server">
1265 <td><?php echo __('Socket'); ?></td>
1266 <td><input type="text" name="<?php echo $type; ?>_socket" class="server-socket" <?php echo $possibly_readonly; ?>/></td>
1267 </tr>
1268 <tr class="odd toggler remote-server">
1269 <td><?php echo __('User name'); ?></td>
1270 <td><input type="text" name="<?php echo $type; ?>_username" class="server-user" /></td>
1271 </tr>
1272 <tr class="even toggler remote-server">
1273 <td><?php echo __('Password'); ?></td>
1274 <td><input type="password" name="<?php echo $type; ?>_pass" class="server-pass" /> </td>
1275 </tr>
1276 <tr class="odd toggler remote-server">
1277 <td><?php echo __('Database'); ?></td>
1278 <td><input type="text" name="<?php echo $type; ?>_db" class="server-db" /></td>
1279 </tr>
1280 <tr class="even toggler current-server" style="display: none;">
1281 <td><?php echo __('Database'); ?></td>
1282 <td>
1283 <?php
1284 $options_list = '';
1285 foreach ($databases as $array_key => $db) {
1286 if (in_array($db['SCHEMA_NAME'], $databases_to_hide)) {
1287 unset($databases[$array_key]);
1288 } else {
1289 $options_list .= '<option>' . htmlspecialchars($db['SCHEMA_NAME']) . '</option>';
1293 if (count($databases) == 0) {
1294 echo __('No databases');
1295 } else {
1296 echo '<select name="' . $type . '_db_sel">'
1297 . $options_list
1298 . '</select>';
1299 unset($options_list);
1301 echo '</td> </tr>
1302 </table>';
1304 unset ($types, $type);
1306 echo '
1307 </fieldset>
1308 <fieldset class="tblFooters">
1309 <input type="submit" name="submit_connect" value="' . __('Go') .'" id="buttonGo" />
1310 </fieldset>
1311 </form>
1312 </div>
1313 <div class="notice">' . __('Target database will be completely synchronized with source database. Source database will remain unchanged.') . '</div>';
1317 * Displays the footer
1319 require './libraries/footer.inc.php';