Fixed descriptions of geometry types - these are column types, not OpenGIS objects
[phpmyadmin.git] / server_synchronize.php
blobd6948664d62bbdbbeb45a35753948e2e70fda426
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(
85 ${"{$con}_username"},
86 ${"{$con}_password"}, $is_controluser = false,
87 ${"{$con}_server"}, $auxiliary_connection = true
89 } // end foreach ($cons as $con)
91 if ((! $src_connection && $src_type != 'cur')
92 || (! $trg_connection && $trg_type != 'cur')
93 ) {
94 /**
95 * Displays the connection error string if
96 * connections are not established
99 echo '<div class="error">';
100 if (! $src_connection && $src_type != 'cur') {
101 echo __('Could not connect to the source') . '<br />';
103 if (! $trg_connection && $trg_type != 'cur') {
104 echo __('Could not connect to the target');
106 echo '</div>';
107 unset($_REQUEST['submit_connect']);
109 } else {
111 * Creating the link object for both source and target databases and
112 * selecting the source and target databases using these links
114 foreach ($cons as $con) {
115 if (${"{$con}_connection"} != null) {
116 ${"{$con}_link"} = PMA_DBI_connect(
117 ${"{$con}_username"},
118 ${"{$con}_password"}, $is_controluser = false, ${"{$con}_server"}
120 } else {
121 ${"{$con}_link"} = null;
123 ${"{$con}_db_selected"} = PMA_DBI_select_db(${"{$con}_db"}, ${"{$con}_link"});
124 ${"{$con}_version"} = PMA_DBI_fetch_value('SELECT VERSION()', 0, 0, ${"{$con}_link"});
125 ${"{$con}_is_drizzle"} = (bool)preg_match('/\d{4}\./', ${"{$con}_version"});
126 } // end foreach ($cons as $con)
128 if (($src_db_selected != 1) || ($trg_db_selected != 1)) {
130 * Displays error string if the database(s) did not exist
132 echo '<div class="error">';
133 if ($src_db_selected != 1) {
134 echo sprintf(__('\'%s\' database does not exist.'), htmlspecialchars($src_db));
136 if ($trg_db_selected != 1) {
137 echo sprintf(__('\'%s\' database does not exist.'), htmlspecialchars($trg_db));
139 echo '</div>';
140 unset($_REQUEST['submit_connect']);
142 } else if (($src_db_selected == 1) && ($trg_db_selected == 1)) {
145 * Using PMA_DBI_get_tables() to get all the tables
146 * from target and source databases.
148 $src_tables = PMA_DBI_get_tables($src_db, $src_link);
149 $source_tables_num = sizeof($src_tables);
151 $trg_tables = PMA_DBI_get_tables($trg_db, $trg_link);
152 $target_tables_num = sizeof($trg_tables);
155 * initializing arrays to save matching and non-matching
156 * table names from target and source databases.
158 $unmatched_num_src = 0;
159 $source_tables_uncommon = array();
160 $unmatched_num_trg = 0;
161 $target_tables_uncommon = array();
162 $matching_tables = array();
163 $matching_tables_num = 0;
166 * Using PMA_getMatchingTables to find which of the tables' names match
167 * in target and source database.
169 PMA_getMatchingTables($trg_tables, $src_tables, $matching_tables, $source_tables_uncommon);
171 * Finding the uncommon tables for the target database
172 * using function PMA_getNonMatchingTargetTables()
174 PMA_getNonMatchingTargetTables($trg_tables, $matching_tables, $target_tables_uncommon);
177 * Initializing several arrays to save the data and structure
178 * difference between the source and target databases.
180 $row_count = array(); //number of rows in source table that needs to be created in target database
181 $fields_num = array(); //number of fields in each matching table
182 $delete_array = array(); //stores the primary key values for target tables that have excessive rows than corresponding source tables.
183 $insert_array = array(array(array()));// stores the primary key values for the rows in each source table that are not present in target tables.
184 $update_array = array(array(array())); //stores the primary key values, name of field to be updated, value of the field to be updated for
185 // each row of matching table.
186 $matching_tables_fields = array(); //contains the fields' names for each matching table
187 $matching_tables_keys = array(); //contains the primary keys' names for each matching table
188 $uncommon_tables_fields = array(); //coantains the fields for all the source tables that are not present in target
189 $matching_tables_num = sizeof($matching_tables);
191 $source_columns = array(); //contains the full columns' information for all the source tables' columns
192 $target_columns = array(); //contains the full columns' information for all the target tables' columns
193 $uncommon_columns = array(); //contains names of columns present in source table but absent from the corresponding target table
194 $source_indexes = array(); //contains indexes on all the source tables
195 $target_indexes = array(); //contains indexes on all the target tables
196 $add_indexes_array = array(); //contains the indexes name present in source but absent from target tables
197 $target_tables_keys = array(); //contains the keys of all the target tables
198 $alter_indexes_array = array(); //contains the names of all the indexes for each table that need to be altered in target database
199 $remove_indexes_array = array(); //contains the names of indexes that are excessive in target tables
200 $alter_str_array = array(array()); //contains the criteria for each column that needs to be altered in target tables
201 $add_column_array = array(array()); //contains the name of columns that need to be added in target tables
203 * The criteria array contains all the criteria against which columns are compared for differences.
205 $criteria = array('Field', 'Type', 'Null', 'Collation', 'Key', 'Default', 'Comment');
207 for ($i = 0; $i < sizeof($matching_tables); $i++) {
209 * Finding out all the differences structure, data and index diff
210 * for all the matching tables only
212 PMA_dataDiffInTables(
213 $src_db, $trg_db, $src_link, $trg_link,
214 $matching_tables, $matching_tables_fields, $update_array,
215 $insert_array, $delete_array, $fields_num, $i,
216 $matching_tables_keys
219 PMA_structureDiffInTables(
220 $src_db, $trg_db, $src_link, $trg_link,
221 $matching_tables, $source_columns, $target_columns,
222 $alter_str_array, $add_column_array, $uncommon_columns,
223 $criteria, $target_tables_keys, $i
226 PMA_indexesDiffInTables(
227 $src_db, $trg_db, $src_link, $trg_link,
228 $matching_tables, $source_indexes, $target_indexes,
229 $add_indexes_array, $alter_indexes_array, $remove_indexes_array, $i
233 for ($j = 0; $j < sizeof($source_tables_uncommon); $j++) {
235 * Finding out the number of rows to be added in tables
236 * that need to be added in target database
238 PMA_dataDiffInUncommonTables(
239 $source_tables_uncommon, $src_db,
240 $src_link, $j, $row_count
245 * Storing all arrays in session for use when page is reloaded
246 * for each button press
248 $_SESSION['matching_tables'] = $matching_tables;
249 $_SESSION['update_array'] = $update_array;
250 $_SESSION['insert_array'] = $insert_array;
251 $_SESSION['src_db'] = $src_db;
252 $_SESSION['trg_db'] = $trg_db;
253 $_SESSION['matching_fields'] = $matching_tables_fields;
254 $_SESSION['src_uncommon_tables'] = $source_tables_uncommon;
255 $_SESSION['src_username'] = $src_username ;
256 $_SESSION['trg_username'] = $trg_username;
257 $_SESSION['src_password'] = $src_password;
258 $_SESSION['trg_password'] = $trg_password;
259 $_SESSION['trg_password'] = $trg_password;
260 $_SESSION['src_server'] = $src_server;
261 $_SESSION['trg_server'] = $trg_server;
262 $_SESSION['src_type'] = $src_type;
263 $_SESSION['trg_type'] = $trg_type;
264 $_SESSION['matching_tables_keys'] = $matching_tables_keys;
265 $_SESSION['uncommon_tables_fields'] = $uncommon_tables_fields;
266 $_SESSION['uncommon_tables_row_count'] = $row_count;
267 $_SESSION['target_tables_uncommon'] = $target_tables_uncommon;
268 $_SESSION['uncommon_tables'] = $source_tables_uncommon;
269 $_SESSION['delete_array'] = $delete_array;
270 $_SESSION['uncommon_columns'] = $uncommon_columns;
271 $_SESSION['source_columns'] = $source_columns;
272 $_SESSION['alter_str_array'] = $alter_str_array;
273 $_SESSION['target_tables_keys'] = $target_tables_keys;
274 $_SESSION['add_column_array'] = $add_column_array;
275 $_SESSION['criteria'] = $criteria;
276 $_SESSION['target_tables'] = $trg_tables;
277 $_SESSION['add_indexes_array'] = $add_indexes_array;
278 $_SESSION['alter_indexes_array'] = $alter_indexes_array;
279 $_SESSION['remove_indexes_array'] = $remove_indexes_array;
280 $_SESSION['source_indexes'] = $source_indexes;
281 $_SESSION['target_indexes'] = $target_indexes;
284 * Displays the sub-heading and icons showing Structure Synchronization
285 * and Data Synchronization
288 <form name="synchronize_form" id="synchronize_form" method="post" action="server_synchronize.php">
289 <?php echo PMA_generate_common_hidden_inputs('', ''); ?>
290 <table width="40%">
291 <tr>
292 <td>
293 <img class="icon" src="<?php echo $pmaThemeImage; ?>new_struct.png" width="16" height="16" alt="" />
294 <?php echo __('Structure Synchronization'); ?>
295 </td>
296 <td>
297 <img class="icon" src="<?php echo $pmaThemeImage; ?>new_data.png" width="16" height="16" alt="" />
298 <?php echo __('Data Synchronization'); ?>
299 </td>
300 </tr>
301 </table>
302 <?php
304 * Displays the tables containing the source tables names,
305 * their difference with the target tables and target tables names.
307 PMA_syncDisplayHeaderCompare($src_db, $trg_db);
308 $rows = array();
311 * Display the matching tables' names and difference, first
313 for ($i = 0; $i < count($matching_tables); $i++) {
315 * Calculating the number of updates for each matching table
317 if (isset($update_array[$i]) && isset($update_array[$i][0])
318 && ! empty($matching_tables_keys[$i][0])
319 && isset($update_array[$i][0][$matching_tables_keys[$i][0]])
321 $num_of_updates = sizeof($update_array[$i]);
322 } else {
323 $num_of_updates = 0;
326 * Calculating the number of insertions for each matching table
328 if (isset($insert_array[$i]) && isset($insert_array[$i][0])
329 && ! empty($matching_tables_keys[$i])
330 && isset($insert_array[$i][0][$matching_tables_keys[$i][0]])
332 $num_of_insertions = sizeof($insert_array[$i]);
333 } else {
334 $num_of_insertions = 0;
338 * Calculating the number of alter columns, number of columns to be
339 * added, number of columns to be removed,
340 * number of index to be added and removed.
342 $num_alter_cols = 0;
343 $num_insert_cols = 0;
344 $num_remove_cols = 0;
345 $num_add_index = 0;
346 $num_remove_index = 0;
348 if (isset($alter_str_array[$i])) {
349 $num_alter_cols = sizeof($alter_str_array[$i]);
351 if (isset($add_column_array[$i])) {
352 $num_insert_cols = sizeof($add_column_array[$i]);
354 if (isset($uncommon_columns[$i])) {
355 $num_remove_cols = sizeof($uncommon_columns[$i]);
357 if (isset($add_indexes_array[$i])) {
358 $num_add_index = sizeof($add_indexes_array[$i]);
360 if (isset($remove_indexes_array[$i])) {
361 $num_remove_index = sizeof($remove_indexes_array[$i]);
363 if (isset($alter_indexes_array[$i])) {
364 $num_add_index += sizeof($alter_indexes_array[$i]);
365 $num_remove_index += sizeof($alter_indexes_array[$i]);
368 $btn_structure_params = null;
369 $btn_data_params = null;
372 * Display the red button of structure synchronization if there
373 * exists any structure difference or index difference.
375 if (($num_alter_cols > 0)
376 || ($num_insert_cols > 0)
377 || ($num_remove_cols > 0)
378 || ($num_add_index > 0)
379 || ($num_remove_index > 0)
381 $btn_structure_params = array($i, $num_alter_cols, $num_insert_cols,
382 $num_remove_cols, $num_add_index, $num_remove_index);
386 * Display the green button of data synchronization if there exists
387 * any data difference.
389 if ((isset($update_array[$i])
390 || isset($insert_array[$i]))
391 && ! empty($matching_tables_keys[$i])
393 if (isset($update_array[$i][0][$matching_tables_keys[$i][0]])
394 || isset($insert_array[$i][0][$matching_tables_keys[$i][0]])
396 $btn_data_params = array($i, $num_of_updates,
397 $num_of_insertions, null, null, null);
401 $rows[] = array(
402 'src_table_name' => $matching_tables[$i],
403 'dst_table_name' => $matching_tables[$i],
404 'btn_type' => 'M',
405 'btn_structure' => $btn_structure_params,
406 'btn_data' => $btn_data_params
410 * Displays the tables' names present in source but missing from target
412 for ($j = 0; $j < count($source_tables_uncommon); $j++) {
413 $row = array(
414 'src_table_name' => '+ ' . $source_tables_uncommon[$j],
415 'dst_table_name' => $source_tables_uncommon[$j] . ' (' . __('not present') . ')',
416 'btn_type' => 'U',
417 'btn_structure' => array($j, null, null, null, null, null),
418 'btn_data' => null
420 if ($row_count[$j] > 0) {
421 $row['btn_data'] = array($j, null, $row_count[$j], null, null, null);
423 $rows[] = $row;
425 foreach ($target_tables_uncommon as $tbl_nc_name) {
426 $rows[] = array(
427 'src_table_name' => '',
428 'dst_table_name' => $tbl_nc_name);
431 * Displays the target tables names
433 PMA_syncDisplayDataCompare($rows);
434 echo '</table>
435 </div>
436 </fieldset>';
439 * This "list" div will contain a table and each row will depict
440 * information about structure/data difference in tables.
441 * Rows will be generated dynamically as soon as the colored
442 * buttons "D" or "S" are clicked.
445 echo '<fieldset style="padding:0"><div id="list" style="overflow:auto; height:140px; padding:1em">
447 <table>
448 <thead>
449 <tr style="width: 100%;">
450 <th id="table_name" style="width: 10%;" colspan="1">' . __('Table') . ' </th>
451 <th id="str_diff" style="width: 65%;" colspan="6">' . __('Structure Difference') . ' </th>
452 <th id="data_diff" style="width: 20%;" colspan="2">' . __('Data Difference') . '</th>
453 </tr>
454 <tr style="width: 100%;">
455 <th style="width: 10%;">' . __('Table name') . '</th>
456 <th style="width: 10%;">' . __('Create table'). '</th>
457 <th style="width: 11%;">' . __('Add column(s)') . '</th>
458 <th style="width: 13%;">' . __('Remove column(s)') . '</th>
459 <th style="width: 11%;">' . __('Alter column(s)') . '</th>
460 <th style="width: 12%;">' . __('Remove index(s)') . '</th>
461 <th style="width: 11%;">' . __('Apply index(s)') . '</th>
462 <th style="width: 10%;">'. __('Update row(s)') . '</th>
463 <th style="width: 10%;">' . __('Insert row(s)') . '</th>
464 </tr>
465 </thead>
466 <tbody></tbody>
467 </table>
468 </div></fieldset>';
470 * This fieldset displays the checkbox to confirm deletion of previous rows from target tables
472 echo '<fieldset>
473 <p><input type= "checkbox" name="delete_rows" id ="delete_rows" /><label for="delete_rows">'
474 . __('Would you like to delete all the previous rows from target tables?')
475 . '</label> </p>
476 </fieldset>
477 <fieldset class="tblFooters">';
478 echo '<input type="button" name="apply_changes" value="'
479 . __('Apply Selected Changes')
480 . '" onclick ="ApplySelectedChanges('
481 . "'" . htmlspecialchars($_SESSION['token']) . "'" . ')" />';
482 echo '<input type="submit" name="synchronize_db" value="'
483 . __('Synchronize Databases') . '" />' . '</fieldset>';
484 echo '</form>';
487 } // end if ((isset($_REQUEST['submit_connect'])))
490 * Display the page when 'Apply Selected Changes' is pressed
492 if (isset($_REQUEST['Table_ids'])) {
494 * Displays success message
496 echo '<div class="success">'
497 . __('Selected target tables have been synchronized with source tables.')
498 . '</div>';
500 $src_db = $_SESSION['src_db'];
501 $trg_db = $_SESSION['trg_db'];
502 $update_array = $_SESSION['update_array'];
503 $insert_array = $_SESSION['insert_array'];
504 $src_username = $_SESSION['src_username'];
505 $trg_username = $_SESSION['trg_username'];
506 $src_password = $_SESSION['src_password'];
507 $trg_password = $_SESSION['trg_password'];
508 $src_server = $_SESSION['src_server'];
509 $trg_server = $_SESSION['trg_server'];
510 $src_type = $_SESSION['src_type'];
511 $trg_type = $_SESSION['trg_type'];
512 $uncommon_tables = $_SESSION['uncommon_tables'];
513 $matching_tables = $_SESSION['matching_tables'];
514 $matching_tables_keys = $_SESSION['matching_tables_keys'];
515 $matching_tables_fields = $_SESSION['matching_fields'];
516 $source_tables_uncommon = $_SESSION['src_uncommon_tables'];
517 $uncommon_tables_fields = $_SESSION['uncommon_tables_fields'];
518 $target_tables_uncommon = $_SESSION['target_tables_uncommon'];
519 $row_count = $_SESSION['uncommon_tables_row_count'];
520 $target_tables = $_SESSION['target_tables'];
522 $delete_array = $_SESSION['delete_array'];
523 $uncommon_columns = $_SESSION['uncommon_columns'];
524 $source_columns = $_SESSION['source_columns'];
525 $alter_str_array = $_SESSION['alter_str_array'];
526 $criteria = $_SESSION['criteria'];
527 $target_tables_keys = $_SESSION['target_tables_keys'];
528 $add_column_array = $_SESSION['add_column_array'];
529 $add_indexes_array = $_SESSION['add_indexes_array'];
530 $alter_indexes_array = $_SESSION['alter_indexes_array'];
531 $remove_indexes_array = $_SESSION['remove_indexes_array'];
532 $source_indexes = $_SESSION['source_indexes'];
533 $target_indexes = $_SESSION['target_indexes'];
534 $uncommon_cols = $uncommon_columns;
537 * Creating link object for source and target databases
539 foreach ($cons as $con) {
540 if (${"{$con}_type"} != "cur") {
541 ${"{$con}_link"} = PMA_DBI_connect(
542 ${"{$con}_username"},
543 ${"{$con}_password"}, $is_controluser = false, ${"{$con}_server"}
545 } else {
546 ${"{$con}_link"} = null;
547 // working on current server, so initialize this for tracking
548 // (does not work if user defined current server as a remote one)
549 $GLOBALS['db'] = ${"{$con}_db"};
551 } // end foreach ($cons as $con)
554 * Initializing arrays to save the table ids whose data and structure difference is to be applied
556 $matching_table_data_diff = array(); //stores id of matching table having data difference
557 $matching_table_structure_diff = array(); //stores id of matching tables having structure difference
558 $uncommon_table_structure_diff = array(); //stores id of uncommon tables having structure difference
559 $uncommon_table_data_diff = array(); //stores id of uncommon tables having data difference
561 for ($i = 0; isset($_REQUEST[$i]); $i++ ) {
562 if (isset($_REQUEST[$i])) {
563 $table_id = explode("US", $_REQUEST[$i]);
564 if (isset($table_id[1])) {
565 $uncommon_table_structure_diff[] = $table_id[1];
567 $table_id = explode("UD", $_REQUEST[$i]);
568 if (isset($table_id[1])) {
569 $uncommon_table_data_diff[] = $table_id[1];
571 $table_id = explode("MS", $_REQUEST[$i]);
572 if (isset($table_id[1])) {
573 $matching_table_structure_diff[] = $table_id[1];
576 $table_id = explode("MD", $_REQUEST[$i]);
577 if (isset($table_id[1])) {
578 $matching_table_data_diff[] = $table_id[1];
581 } // end for
583 * Applying the structure difference on selected matching tables
585 for ($q = 0; $q < sizeof($matching_table_structure_diff); $q++) {
586 if (isset($alter_str_array[$matching_table_structure_diff[$q]])) {
587 PMA_alterTargetTableStructure(
588 $trg_db, $trg_link, $matching_tables,
589 $source_columns, $alter_str_array, $matching_tables_fields,
590 $criteria, $matching_tables_keys, $target_tables_keys,
591 $matching_table_structure_diff[$q], false
594 unset($alter_str_array[$matching_table_structure_diff[$q]]);
596 if (isset($add_column_array[$matching_table_structure_diff[$q]])) {
597 PMA_findDeleteRowsFromTargetTables(
598 $delete_array, $matching_tables,
599 $matching_table_structure_diff[$q], $target_tables_keys,
600 $matching_tables_keys, $trg_db, $trg_link, $src_db, $src_link
603 if (isset($delete_array[$matching_table_structure_diff[$q]])) {
604 PMA_deleteFromTargetTable(
605 $trg_db, $trg_link, $matching_tables,
606 $matching_table_structure_diff[$q], $target_tables_keys,
607 $delete_array, false
610 unset($delete_array[$matching_table_structure_diff[$q]]);
612 PMA_addColumnsInTargetTable(
613 $src_db, $trg_db, $src_link, $trg_link,
614 $matching_tables, $source_columns, $add_column_array,
615 $matching_tables_fields, $criteria, $matching_tables_keys,
616 $target_tables_keys, $uncommon_tables, $uncommon_tables_fields,
617 $matching_table_structure_diff[$q], $uncommon_cols, false
620 unset($add_column_array[$matching_table_structure_diff[$q]]);
622 if (isset($uncommon_columns[$matching_table_structure_diff[$q]])) {
623 PMA_removeColumnsFromTargetTable(
624 $trg_db, $trg_link, $matching_tables,
625 $uncommon_columns, $matching_table_structure_diff[$q], false
628 unset($uncommon_columns[$matching_table_structure_diff[$q]]);
630 if (isset($add_indexes_array[$matching_table_structure_diff[$q]])
631 || isset($remove_indexes_array[$matching_table_structure_diff[$q]])
632 || isset($alter_indexes_array[$matching_table_structure_diff[$q]])
634 PMA_applyIndexesDiff(
635 $trg_db, $trg_link, $matching_tables,
636 $source_indexes, $target_indexes, $add_indexes_array,
637 $alter_indexes_array, $remove_indexes_array,
638 $matching_table_structure_diff[$q], false
641 unset($add_indexes_array[$matching_table_structure_diff[$q]]);
642 unset($alter_indexes_array[$matching_table_structure_diff[$q]]);
643 unset($remove_indexes_array[$matching_table_structure_diff[$q]]);
647 * Applying the data difference. First checks if structure diff is applied or not.
648 * If not, then apply structure difference first then apply data difference.
650 for ($p = 0; $p < sizeof($matching_table_data_diff); $p++) {
651 if ($_REQUEST['checked'] == 'true') {
652 PMA_findDeleteRowsFromTargetTables(
653 $delete_array, $matching_tables,
654 $matching_table_data_diff[$p], $target_tables_keys,
655 $matching_tables_keys, $trg_db, $trg_link, $src_db, $src_link
658 if (isset($delete_array[$matching_table_data_diff[$p]])) {
659 PMA_deleteFromTargetTable(
660 $trg_db, $trg_link, $matching_tables,
661 $matching_table_data_diff[$p], $target_tables_keys,
662 $delete_array, false
665 unset($delete_array[$matching_table_data_diff[$p]]);
668 if (isset($alter_str_array[$matching_table_data_diff[$p]])) {
669 PMA_alterTargetTableStructure(
670 $trg_db, $trg_link, $matching_tables,
671 $source_columns, $alter_str_array, $matching_tables_fields,
672 $criteria, $matching_tables_keys, $target_tables_keys,
673 $matching_table_data_diff[$p], false
676 unset($alter_str_array[$matching_table_data_diff[$p]]);
678 if (isset($add_column_array[$matching_table_data_diff[$p]])) {
679 PMA_findDeleteRowsFromTargetTables(
680 $delete_array, $matching_tables,
681 $matching_table_data_diff[$p], $target_tables_keys,
682 $matching_tables_keys, $trg_db, $trg_link, $src_db, $src_link
685 if (isset($delete_array[$matching_table_data_diff[$p]])) {
686 PMA_deleteFromTargetTable(
687 $trg_db, $trg_link, $matching_tables,
688 $matching_table_data_diff[$p], $target_tables_keys,
689 $delete_array, false
692 unset($delete_array[$matching_table_data_diff[$p]]);
694 PMA_addColumnsInTargetTable(
695 $src_db, $trg_db, $src_link, $trg_link,
696 $matching_tables, $source_columns, $add_column_array,
697 $matching_tables_fields, $criteria, $matching_tables_keys,
698 $target_tables_keys, $uncommon_tables, $uncommon_tables_fields,
699 $matching_table_data_diff[$p], $uncommon_cols, false
702 unset($add_column_array[$matching_table_data_diff[$p]]);
704 if (isset($uncommon_columns[$matching_table_data_diff[$p]])) {
705 PMA_removeColumnsFromTargetTable(
706 $trg_db, $trg_link, $matching_tables,
707 $uncommon_columns, $matching_table_data_diff[$p], false
710 unset($uncommon_columns[$matching_table_data_diff[$p]]);
712 if ((isset($matching_table_structure_diff[$q])
713 && isset($add_indexes_array[$matching_table_structure_diff[$q]]))
714 || (isset($matching_table_structure_diff[$q])
715 && isset($remove_indexes_array[$matching_table_structure_diff[$q]]))
716 || (isset($matching_table_structure_diff[$q])
717 && isset($alter_indexes_array[$matching_table_structure_diff[$q]]))
719 PMA_applyIndexesDiff(
720 $trg_db, $trg_link, $matching_tables,
721 $source_indexes, $target_indexes, $add_indexes_array,
722 $alter_indexes_array, $remove_indexes_array,
723 $matching_table_structure_diff[$q], false
726 unset($add_indexes_array[$matching_table_structure_diff[$q]]);
727 unset($alter_indexes_array[$matching_table_structure_diff[$q]]);
728 unset($remove_indexes_array[$matching_table_structure_diff[$q]]);
731 * Applying the data difference.
733 PMA_updateTargetTables(
734 $matching_tables, $update_array, $src_db, $trg_db,
735 $trg_link, $matching_table_data_diff[$p], $matching_tables_keys, false
738 PMA_insertIntoTargetTable(
739 $matching_tables, $src_db, $trg_db, $src_link,
740 $trg_link, $matching_tables_fields, $insert_array,
741 $matching_table_data_diff[$p], $matching_tables_keys, $source_columns,
742 $add_column_array, $criteria, $target_tables_keys, $uncommon_tables,
743 $uncommon_tables_fields, $uncommon_cols, $alter_str_array,
744 $source_indexes, $target_indexes, $add_indexes_array,
745 $alter_indexes_array, $delete_array, $update_array, false
749 * Updating the session variables to the latest values of the arrays.
751 $_SESSION['delete_array'] = $delete_array;
752 $_SESSION['uncommon_columns'] = $uncommon_columns;
753 $_SESSION['alter_str_array'] = $alter_str_array;
754 $_SESSION['add_column_array'] = $add_column_array;
755 $_SESSION['add_indexes_array'] = $add_indexes_array;
756 $_SESSION['remove_indexes_array'] = $remove_indexes_array;
757 $_SESSION['insert_array'] = $insert_array;
758 $_SESSION['update_array'] = $update_array;
761 * Applying structure difference to selected non-matching tables
762 * (present in Source but absent from Target).
764 for ($s = 0; $s < sizeof($uncommon_table_structure_diff); $s++) {
765 PMA_createTargetTables(
766 $src_db, $trg_db, $src_link, $trg_link,
767 $uncommon_tables, $uncommon_table_structure_diff[$s],
768 $uncommon_tables_fields, false
770 $_SESSION['uncommon_tables_fields'] = $uncommon_tables_fields;
772 unset($uncommon_tables[$uncommon_table_structure_diff[$s]]);
775 * Applying data difference to selected non-matching tables
776 * (present in Source but absent from Target).
777 * Before data synchronization, structure synchronization is confirmed.
779 for ($r = 0; $r < sizeof($uncommon_table_data_diff); $r++) {
780 if (!(in_array($uncommon_table_data_diff[$r], $uncommon_table_structure_diff))) {
781 if (isset($uncommon_tables[$uncommon_table_data_diff[$r]])) {
782 PMA_createTargetTables(
783 $src_db, $trg_db, $src_link, $trg_link,
784 $uncommon_tables, $uncommon_table_data_diff[$r],
785 $uncommon_tables_fields, false
787 $_SESSION['uncommon_tables_fields'] = $uncommon_tables_fields;
789 unset($uncommon_tables[$uncommon_table_data_diff[$r]]);
792 PMA_populateTargetTables(
793 $src_db, $trg_db, $src_link, $trg_link,
794 $source_tables_uncommon, $uncommon_table_data_diff[$r],
795 $_SESSION['uncommon_tables_fields'], false
798 unset($row_count[$uncommon_table_data_diff[$r]]);
801 * Again all the tables from source and target database are displayed with their differences.
802 * The differences have been removed from tables that have been synchronized
804 echo '<form name="applied_difference" id="synchronize_form" method="post" action="server_synchronize.php">'
805 . PMA_generate_common_hidden_inputs('', '');
807 PMA_syncDisplayHeaderCompare($src_db, $trg_db);
808 $rows = array();
809 for ($i = 0; $i < count($matching_tables); $i++) {
810 $num_alter_cols = 0;
811 $num_insert_cols = 0;
812 $num_remove_cols = 0;
813 $num_add_index = 0;
814 $num_remove_index = 0;
816 if (isset($alter_str_array[$i])) {
817 $num_alter_cols = sizeof($alter_str_array[$i]);
819 if (isset($add_column_array[$i])) {
820 $num_insert_cols = sizeof($add_column_array[$i]);
822 if (isset($uncommon_columns[$i])) {
823 $num_remove_cols = sizeof($uncommon_columns[$i]);
825 if (isset($add_indexes_array[$i])) {
826 $num_add_index = sizeof($add_indexes_array[$i]);
828 if (isset($remove_indexes_array[$i])) {
829 $num_remove_index = sizeof($remove_indexes_array[$i]);
832 $btn_structure_params = null;
833 $btn_data_params = null;
835 if (($num_alter_cols > 0)
836 || ($num_insert_cols > 0)
837 || ($num_remove_cols > 0)
838 || ($num_add_index > 0)
839 || ($num_remove_index > 0)
841 $btn_structure_params = array($i, $num_alter_cols, $num_insert_cols,
842 $num_remove_cols, $num_add_index, $num_remove_index);
844 if (! (in_array($i, $matching_table_data_diff))) {
845 if (isset($matching_tables_keys[$i][0])
846 && isset($update_array[$i][0][$matching_tables_keys[$i][0]])
848 if (isset($update_array[$i])) {
849 $num_of_updates = sizeof($update_array[$i]);
850 } else {
851 $num_of_updates = 0;
853 } else {
854 $num_of_updates = 0;
856 if (isset($matching_tables_keys[$i][0])
857 && isset($insert_array[$i][0][$matching_tables_keys[$i][0]])
859 if (isset($insert_array[$i])) {
860 $num_of_insertions = sizeof($insert_array[$i]);
861 } else {
862 $num_of_insertions = 0;
864 } else {
865 $num_of_insertions = 0;
868 if ((isset($matching_tables_keys[$i][0])
869 && isset($update_array[$i][0][$matching_tables_keys[$i][0]]))
870 || (isset($matching_tables_keys[$i][0])
871 && isset($insert_array[$i][0][$matching_tables_keys[$i][0]]))
873 $btn_data_params = array($i, $num_of_updates, $num_of_insertions,
874 null, null, null);
876 } else {
877 unset($update_array[$i]);
878 unset($insert_array[$i]);
880 $rows[] = array(
881 'src_table_name' => $matching_tables[$i],
882 'dst_table_name' => $matching_tables[$i],
883 'btn_type' => 'M',
884 'btn_structure' => $btn_structure_params,
885 'btn_data' => $btn_data_params
889 * placing updated value of arrays in session
892 $_SESSION['update_array'] = $update_array;
893 $_SESSION['insert_array'] = $insert_array;
895 for ($j = 0; $j < count($source_tables_uncommon); $j++) {
896 $btn_structure_params = null;
897 $btn_data_params = null;
900 * Display the difference only when it has not been applied
902 if (!(in_array($j, $uncommon_table_structure_diff))) {
903 if (isset($uncommon_tables[$j])) {
904 $btn_structure_params = array($j, null, null, null, null, null);
906 $dst_table_name = $source_tables_uncommon[$j] . ' (' . __('not present') . ')';
907 } else {
908 unset($uncommon_tables[$j]);
909 $dst_table_name = $source_tables_uncommon[$j];
912 * Display the difference only when it has not been applied
914 if (!(in_array($j, $uncommon_table_data_diff))) {
915 if (isset($row_count[$j]) && ($row_count[$j] > 0)) {
916 $btn_data_params = array($j, null, $row_count[$j], null, null, null);
918 } else {
919 unset($row_count[$j]);
922 $rows[] = array(
923 'src_table_name' => $source_tables_uncommon[$j],
924 'dst_table_name' => $dst_table_name,
925 'btn_type' => 'U',
926 'btn_structure' => $btn_structure_params,
927 'btn_data' => $btn_data_params
931 * placing the latest values of arrays in session
934 $_SESSION['uncommon_tables'] = $uncommon_tables;
935 $_SESSION['uncommon_tables_row_count'] = $row_count;
939 * Displaying the target database tables
941 foreach ($target_tables_uncommon as $tbl_nc_name) {
942 $rows[] = array(
943 'src_table_name' => '',
944 'dst_table_name' => $tbl_nc_name);
946 PMA_syncDisplayDataCompare($rows);
947 echo '</table>
948 </div>
949 </fieldset>';
952 * This "list" div will contain a table and each row will depict information about
953 * structure/data difference in tables.
954 * Rows will be generated dynamically as soon as the colored buttons "D" or "S"
955 * are clicked.
958 echo '<fieldset style="padding:0"><div id="list" style = "overflow:auto; height:140px; padding:1em">';
959 echo '<table>
960 <thead>
961 <tr style="width: 100%;">
962 <th id="table_name" style="width: 10%;" colspan="1">' . __('Table') . ' </th>
963 <th id="str_diff" style="width: 65%;" colspan="6">' . __('Structure Difference') . ' </th>
964 <th id="data_diff" style="width: 20%;" colspan="2">' . __('Data Difference') . '</th>
965 </tr>
966 <tr style="width: 100%;">
967 <th style="width: 10%;">' . __('Table name') . '</th>
968 <th style="width: 10%;">' . __('Create table'). '</th>
969 <th style="width: 11%;">' . __('Add column(s)') . '</th>
970 <th style="width: 13%;">' . __('Remove column(s)') . '</th>
971 <th style="width: 11%;">' . __('Alter column(s)') . '</th>
972 <th style="width: 12%;">' . __('Remove index(s)') . '</th>
973 <th style="width: 11%;">' . __('Apply index(s)') . '</th>
974 <th style="width: 10%;">' . __('Update row(s)') . '</th>
975 <th style="width: 10%;">' . __('Insert row(s)') . '</th>
976 </tr>
977 </thead>
978 <tbody></tbody>
979 </table>
980 </div></fieldset>';
983 * This fieldset displays the checkbox to confirm deletion of previous rows from target tables
985 echo '<fieldset>
986 <p><input type="checkbox" name="delete_rows" id ="delete_rows" /><label for="delete_rows">'
987 . __('Would you like to delete all the previous rows from target tables?') . '</label> </p>
988 </fieldset>';
990 echo '<fieldset class="tblFooters">';
991 echo '<input type="button" name="apply_changes" value="'
992 . __('Apply Selected Changes') . '" onclick ="ApplySelectedChanges('
993 . "'" . htmlspecialchars($_SESSION['token']) . "'" .')" />';
994 echo '<input type="submit" name="synchronize_db" value="'
995 . __('Synchronize Databases') . '" />'
996 . '</fieldset>';
997 echo '</form>';
1001 * Displays the page when 'Synchronize Databases' is pressed.
1004 if (isset($_REQUEST['synchronize_db'])) {
1006 $src_db = $_SESSION['src_db'];
1007 $trg_db = $_SESSION['trg_db'];
1008 $update_array = $_SESSION['update_array'];
1009 $insert_array = $_SESSION['insert_array'];
1010 $src_username = $_SESSION['src_username'];
1011 $trg_username = $_SESSION['trg_username'];
1012 $src_password = $_SESSION['src_password'];
1013 $trg_password = $_SESSION['trg_password'];
1014 $matching_tables = $_SESSION['matching_tables'];
1015 $matching_tables_keys = $_SESSION['matching_tables_keys'];
1016 $matching_tables_fields = $_SESSION['matching_fields'];
1017 $source_tables_uncommon = $_SESSION['src_uncommon_tables'];
1018 $uncommon_tables_fields = $_SESSION['uncommon_tables_fields'];
1019 $target_tables_uncommon = $_SESSION['target_tables_uncommon'];
1020 $row_count = $_SESSION['uncommon_tables_row_count'];
1021 $uncommon_tables = $_SESSION['uncommon_tables'];
1022 $target_tables = $_SESSION['target_tables'];
1024 $delete_array = $_SESSION['delete_array'];
1025 $uncommon_columns = $_SESSION['uncommon_columns'];
1026 $source_columns = $_SESSION['source_columns'];
1027 $alter_str_array = $_SESSION['alter_str_array'];
1028 $criteria = $_SESSION['criteria'];
1029 $target_tables_keys = $_SESSION['target_tables_keys'];
1030 $add_column_array = $_SESSION['add_column_array'];
1031 $add_indexes_array = $_SESSION['add_indexes_array'];
1032 $alter_indexes_array = $_SESSION['alter_indexes_array'];
1033 $remove_indexes_array = $_SESSION['remove_indexes_array'];
1034 $source_indexes = $_SESSION['source_indexes'];
1035 $target_indexes = $_SESSION['target_indexes'];
1036 $uncommon_cols = $uncommon_columns;
1039 * Display success message.
1041 echo '<div class="success">'
1042 . __('Target database has been synchronized with source database')
1043 . '</div>';
1045 * Displaying all the tables of source and target database
1046 * and now no difference is there.
1048 PMA_syncDisplayHeaderCompare($src_db, $trg_db);
1049 $rows = array();
1050 for ($i = 0; $i < count($matching_tables); $i++) {
1051 $rows[] = array(
1052 'src_table_name' => $matching_tables[$i],
1053 'dst_table_name' => $matching_tables[$i]);
1055 foreach ($source_tables_uncommon as $tbl_nc_name) {
1056 $rows[] = array(
1057 'src_table_name' => '+ ' . $tbl_nc_name,
1058 'dst_table_name' => $tbl_nc_name);
1060 foreach ($target_tables_uncommon as $tbl_nc_name) {
1061 $rows[] = array(
1062 'src_table_name' => '',
1063 'dst_table_name' => $tbl_nc_name);
1065 PMA_syncDisplayDataCompare($rows);
1066 echo '</table>
1067 </div>
1068 </fieldset>';
1071 * connecting the source and target servers
1073 if ('cur' != $_SESSION['src_type']) {
1074 $src_link = PMA_DBI_connect($src_username, $src_password, $is_controluser = false, $_SESSION['src_server']);
1075 $src_version = PMA_DBI_fetch_value('SELECT VERSION()', 0, 0, $src_link);
1076 $src_is_drizzle = (bool)preg_match('/\d{4}\./', $src_version);
1077 } else {
1078 $src_link = $GLOBALS['userlink'];
1079 $src_version = PMA_MYSQL_STR_VERSION;
1080 $src_is_drizzle = PMA_DRIZZLE;
1081 // working on current server, so initialize this for tracking
1082 // (does not work if user defined current server as a remote one)
1083 $GLOBALS['db'] = $_SESSION['src_db'];
1085 if ('cur' != $_SESSION['trg_type']) {
1086 $trg_link = PMA_DBI_connect($trg_username, $trg_password, $is_controluser = false, $_SESSION['trg_server']);
1087 $trg_version = PMA_DBI_fetch_value('SELECT VERSION()', 0, 0, $trg_link);
1088 $trg_is_drizzle = (bool)preg_match('/\d{4}\./', $trg_version);
1089 } else {
1090 $trg_link = $GLOBALS['userlink'];
1091 $trg_version = PMA_MYSQL_STR_VERSION;
1092 $trg_is_drizzle = PMA_DRIZZLE;
1093 // working on current server, so initialize this for tracking
1094 $GLOBALS['db'] = $_SESSION['trg_db'];
1098 * Displaying the queries.
1100 echo '<fieldset><legend>' . __('Executed queries') . '</legend>';
1102 * Applying all sorts of differences for each matching table
1104 for ($p = 0; $p < sizeof($matching_tables); $p++) {
1106 * If the check box is checked for deleting previous rows from the target database tables then
1107 * first find out rows to be deleted and then delete the rows.
1109 if (isset($_REQUEST['delete_rows'])) {
1110 PMA_findDeleteRowsFromTargetTables(
1111 $delete_array, $matching_tables, $p,
1112 $target_tables_keys, $matching_tables_keys,
1113 $trg_db, $trg_link, $src_db, $src_link
1116 if (isset($delete_array[$p])) {
1117 PMA_deleteFromTargetTable(
1118 $trg_db, $trg_link, $matching_tables, $p,
1119 $target_tables_keys, $delete_array, true
1121 unset($delete_array[$p]);
1124 if (isset($alter_str_array[$p])) {
1125 PMA_alterTargetTableStructure(
1126 $trg_db, $trg_link, $matching_tables,
1127 $source_columns, $alter_str_array, $matching_tables_fields,
1128 $criteria, $matching_tables_keys, $target_tables_keys, $p, true
1130 unset($alter_str_array[$p]);
1132 if (! empty($add_column_array[$p])) {
1133 PMA_findDeleteRowsFromTargetTables(
1134 $delete_array, $matching_tables, $p,
1135 $target_tables_keys, $matching_tables_keys,
1136 $trg_db, $trg_link, $src_db, $src_link
1139 if (isset($delete_array[$p])) {
1140 PMA_deleteFromTargetTable(
1141 $trg_db, $trg_link, $matching_tables, $p,
1142 $target_tables_keys, $delete_array, true
1144 unset($delete_array[$p]);
1146 PMA_addColumnsInTargetTable(
1147 $src_db, $trg_db, $src_link, $trg_link,
1148 $matching_tables, $source_columns, $add_column_array,
1149 $matching_tables_fields, $criteria, $matching_tables_keys,
1150 $target_tables_keys, $uncommon_tables, $uncommon_tables_fields,
1151 $p, $uncommon_cols, true
1153 unset($add_column_array[$p]);
1155 if (isset($uncommon_columns[$p])) {
1156 PMA_removeColumnsFromTargetTable(
1157 $trg_db, $trg_link, $matching_tables,
1158 $uncommon_columns, $p, true
1160 unset($uncommon_columns[$p]);
1162 if (isset($matching_table_structure_diff)
1163 && (isset($add_indexes_array[$matching_table_structure_diff[$p]])
1164 || isset($remove_indexes_array[$matching_table_structure_diff[$p]])
1165 || isset($alter_indexes_array[$matching_table_structure_diff[$p]]))
1167 PMA_applyIndexesDiff(
1168 $trg_db, $trg_link, $matching_tables,
1169 $source_indexes, $target_indexes, $add_indexes_array,
1170 $alter_indexes_array, $remove_indexes_array,
1171 $matching_table_structure_diff[$p], true
1174 unset($add_indexes_array[$matching_table_structure_diff[$p]]);
1175 unset($alter_indexes_array[$matching_table_structure_diff[$p]]);
1176 unset($remove_indexes_array[$matching_table_structure_diff[$p]]);
1179 PMA_updateTargetTables(
1180 $matching_tables, $update_array, $src_db, $trg_db,
1181 $trg_link, $p, $matching_tables_keys, true
1184 PMA_insertIntoTargetTable(
1185 $matching_tables, $src_db, $trg_db, $src_link,
1186 $trg_link, $matching_tables_fields, $insert_array, $p,
1187 $matching_tables_keys, $matching_tables_keys, $source_columns,
1188 $add_column_array, $criteria, $target_tables_keys, $uncommon_tables,
1189 $uncommon_tables_fields, $uncommon_cols, $alter_str_array, $source_indexes,
1190 $target_indexes, $add_indexes_array,
1191 $alter_indexes_array, $delete_array, $update_array, true
1196 * Creating and populating tables present in source but absent
1197 * from target database.
1199 for ($q = 0; $q < sizeof($source_tables_uncommon); $q++) {
1200 if (isset($uncommon_tables[$q])) {
1201 PMA_createTargetTables(
1202 $src_db, $trg_db, $src_link, $trg_link,
1203 $source_tables_uncommon, $q, $uncommon_tables_fields, true
1206 if (isset($row_count[$q])) {
1207 PMA_populateTargetTables(
1208 $src_db, $trg_db, $src_link, $trg_link,
1209 $source_tables_uncommon, $q, $uncommon_tables_fields, true
1213 echo "</fieldset>";
1217 * Displays the main page when none of the following buttons is pressed
1220 if (! isset($_REQUEST['submit_connect'])
1221 && ! isset($_REQUEST['synchronize_db'])
1222 && ! isset($_REQUEST['Table_ids'])
1225 * Displays the sub-page heading
1227 echo '<h2>' . PMA_getImage('s_sync.png') . __('Synchronize') .'</h2>';
1229 echo '<div id="serverstatus">
1230 <form name="connection_form" id="connection_form" method="post" action="server_synchronize.php"
1231 >' // TODO: add check if all var. are filled in
1232 . PMA_generate_common_hidden_inputs('', '');
1233 echo '<fieldset>';
1234 echo '<legend>' . __('Synchronize') . '</legend>';
1236 * Displays the forms
1239 $databases = PMA_DBI_get_databases_full(
1240 null, false, null, 'SCHEMA_NAME',
1241 'ASC', 0, true
1244 $databases_to_hide = array(
1245 'information_schema',
1246 'mysql'
1248 if (PMA_DRIZZLE) {
1249 $databases_to_hide[] = 'data_dictionary';
1252 if ($GLOBALS['cfg']['AllowArbitraryServer'] === false) {
1253 $possibly_readonly = ' readonly="readonly"';
1254 } else {
1255 $possibly_readonly = '';
1258 foreach ($cons as $type) {
1259 if ('src' == $type) {
1260 $database_header = __('Source database');
1261 } else {
1262 $database_header = __('Target database');
1265 $database_header .= PMA_showHint(
1266 PMA_sanitize(
1267 sprintf(
1268 '%sAllowArbitraryServer%s',
1269 '[a@./Documentation.html#AllowArbitraryServer@_blank]', '[/a]'
1274 <table id="serverconnection_<?php echo $type; ?>_remote" class="data noclick">
1275 <caption class="tblHeaders"><?php echo $database_header; ?></caption>
1276 <tr class="odd">
1277 <td colspan="2" style="text-align: center">
1278 <select name="<?php echo $type; ?>_type" id="<?php echo $type; ?>_type" class="server_selector">
1279 <?php
1280 if ($GLOBALS['cfg']['AllowArbitraryServer']) {
1281 $preselected_option = 'rmt';
1282 echo '<option value="rmt" selected="selected">' . __('Enter manually') . '</option>';
1283 } else {
1284 $preselected_option = 'cur';
1286 echo '<option value="cur"';
1287 if ('cur' == $preselected_option) {
1288 echo ' selected="selected"';
1290 echo '>' . __('Current connection') . '</option>';
1292 $loaded_dbi = $GLOBALS['cfg']['Server']['extension'];
1293 foreach ($GLOBALS['cfg']['Servers'] as $key => $tmp_server) {
1294 if (empty($tmp_server['host']) && empty($tmp_server['socket'])) {
1295 continue;
1298 if (! empty($tmp_server['verbose'])) {
1299 $label = $tmp_server['verbose'];
1300 } else {
1301 $label = $tmp_server['host'];
1302 if (! empty($tmp_server['port'])) {
1303 $label .= ':' . $tmp_server['port'];
1307 if ($loaded_dbi == 'drizzle' && $tmp_server['extension'] != 'drizzle'
1308 || $loaded_dbi != 'drizzle' && $tmp_server['extension'] == 'drizzle'
1310 // incompatible connection protocols
1311 $disabled = ' disabled="disabled"';
1312 $value = '';
1313 } else {
1314 $disabled = '';
1315 $value = $tmp_server['host'];
1316 $value .= '||||';
1317 if (empty($tmp_server['port']) && empty($tmp_server['socket'])) {
1318 $value .= '3306';
1319 } else {
1320 $value .= $tmp_server['port'];
1322 $value .= '||||';
1323 $value .= $tmp_server['socket'];
1324 $value .= '||||';
1325 $value .= $tmp_server['user'];
1326 $value .= '||||';
1327 $value .= $tmp_server['only_db'];
1330 echo '<option value="' . $value . '"' . $disabled . '>'
1331 . sprintf(__('Configuration: %s'), htmlspecialchars($label)) . '</option>';
1332 } // end foreach
1334 </select>
1335 </td>
1336 </tr>
1337 <tr class="even toggler remote-server vmiddle">
1338 <td><label for="<?php echo $type; ?>_host"><?php echo __('Server'); ?></label></td>
1339 <td><input type="text" name="<?php echo $type; ?>_host" id="<?php echo $type; ?>_host" class="server-host" <?php echo $possibly_readonly; ?>/></td>
1340 </tr>
1341 <tr class="odd toggler remote-server vmiddle">
1342 <td><label for="<?php echo $type; ?>_port"><?php echo __('Port'); ?></label></td>
1343 <td><input type="text" name="<?php echo $type; ?>_port" id="<?php echo $type; ?>_port" class="server-port" <?php echo $possibly_readonly; ?> value="3306" maxlength="5" size="5" /></td>
1344 </tr>
1345 <tr class="even toggler remote-server vmiddle">
1346 <td><label for="<?php echo $type; ?>_socket"><?php echo __('Socket'); ?></label></td>
1347 <td><input type="text" name="<?php echo $type; ?>_socket" id="<?php echo $type; ?>_socket" class="server-socket" <?php echo $possibly_readonly; ?>/></td>
1348 </tr>
1349 <tr class="odd toggler remote-server vmiddle">
1350 <td><label for="<?php echo $type; ?>_username"><?php echo __('User name'); ?></label></td>
1351 <td><input type="text" name="<?php echo $type; ?>_username" id="<?php echo $type; ?>_username" class="server-user" /></td>
1352 </tr>
1353 <tr class="even toggler remote-server vmiddle">
1354 <td><label for="<?php echo $type; ?>_pass"><?php echo __('Password'); ?></label></td>
1355 <td><input type="password" name="<?php echo $type; ?>_pass" id="<?php echo $type; ?>_pass" class="server-pass" /> </td>
1356 </tr>
1357 <tr class="odd toggler remote-server vmiddle">
1358 <td><label for="<?php echo $type; ?>_db"><?php echo __('Database'); ?></label></td>
1359 <td><input type="text" name="<?php echo $type; ?>_db" id="<?php echo $type; ?>_db" class="server-db" /></td>
1360 </tr>
1361 <tr class="even toggler current-server vmiddle" style="display: none;">
1362 <td><label for="<?php echo $type; ?>_db_sel"><?php echo __('Database'); ?></label></td>
1363 <td>
1364 <?php
1365 $options_list = '';
1366 foreach ($databases as $array_key => $db) {
1367 if (in_array($db['SCHEMA_NAME'], $databases_to_hide)) {
1368 unset($databases[$array_key]);
1369 } else {
1370 $options_list .= '<option>' . htmlspecialchars($db['SCHEMA_NAME']) . '</option>';
1374 if (count($databases) == 0) {
1375 echo __('No databases');
1376 } else {
1377 echo '<select name="' . $type . '_db_sel" id="' . $type . '_db_sel">'
1378 . $options_list
1379 . '</select>';
1380 unset($options_list);
1382 echo '</td> </tr>
1383 </table>';
1385 unset ($types, $type);
1387 echo '
1388 </fieldset>
1389 <fieldset class="tblFooters">
1390 <input type="submit" name="submit_connect" value="' . __('Go') .'" id="buttonGo" />
1391 </fieldset>
1392 </form>
1393 </div>
1394 <div class="notice">' . __('Target database will be completely synchronized with source database. Source database will remain unchanged.') . '</div>';
1398 * Displays the footer
1400 require 'libraries/footer.inc.php';