code cleanup
[phpmyadmin/madhuracj.git] / server_synchronize.php
blob0a6025f126f59cad649c6fae414505177101e551
1 <?php
3 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 /**
6 * @version $Id$
7 * @package phpMyAdmin
8 */
10 /**
13 require_once './libraries/common.inc.php';
15 /**
16 * Does the common work
17 */
18 $GLOBALS['js_include'][] = 'functions.js';
19 $GLOBALS['js_include'][] = 'mootools.js';
20 require_once './libraries/server_common.inc.php';
22 /**
23 * Contains all the functions specific to synchronization
25 require './libraries/server_synchronize.lib.php';
27 /**
28 * Increases the time limit up to the configured maximum
30 @set_time_limit($cfg['ExecTimeLimit']);
32 /**
33 * Displays the links
35 require './libraries/server_links.inc.php';
37 /**
38 * Enables warnings on the page
40 //$cfg['Error_Handler']['display'] = true;
41 //$cfg['Error_Handler']['gather'] = true;
43 /**
44 * Save the value of token generated for this page
46 if (isset($_REQUEST['token'])) {
47 $_SESSION['token'] = $_REQUEST['token'];
50 // variable for code saving
51 $cons = array ("src", "trg");
53 /**
54 * Displays the page when 'Go' is pressed
57 if ((isset($_REQUEST['submit_connect']))) {
58 foreach ($cons as $con) {
59 ${"{$con}_host"} = $_REQUEST[$con . '_host'];
60 ${"{$con}_username"} = $_REQUEST[$con . '_username'];
61 ${"{$con}_password"} = $_REQUEST[$con . '_pass'];
62 ${"{$con}_port"} = $_REQUEST[$con . '_port'];
63 ${"{$con}_socket"} = $_REQUEST[$con . '_socket'];
64 ${"{$con}_db"} = $_REQUEST[$con . '_db'];
65 ${"{$con}_type"} = $_REQUEST[$con . '_type'];
67 if (${"{$con}_type"} == 'cur') {
68 ${"{$con}_connection"} = null;
69 ${"{$con}_server"} = null;
70 ${"{$con}_db"} = $_REQUEST[$con . '_db_sel'];
71 continue;
74 if (isset(${"{$con}_socket"}) && ! empty(${"{$con}_socket"})) {
75 ${"{$con}_server"}['socket'] = ${"{$con}_socket"};
76 } else {
77 ${"{$con}_server"}['host'] = ${"{$con}_host"};
78 if (isset(${"{$con}_port"}) && ! empty(${"{$con}_port"}) && ((int)${"{$con}_port"} * 1) > 0) {
79 ${"{$con}_server"}['port'] = ${"{$con}_port"};
83 ${"{$con}_connection"} = PMA_DBI_connect(${"{$con}_username"}, ${"{$con}_password"}, $is_controluser = false, ${"{$con}_server"}, $auxiliary_connection = true);
84 } // end foreach ($cons as $con)
86 if ((! $src_connection && $src_type == 'rmt') || (! $trg_connection && $trg_type == 'rmt')) {
87 /**
88 * Displays the connection error string if
89 * connections are not established
92 echo '<div class="error">';
93 if(! $src_connection && $src_type == 'rmt') {
94 echo $GLOBALS['strCouldNotConnectSource'] . '<br />';
96 if(! $trg_connection && $trg_type == 'rmt'){
97 echo $GLOBALS['strCouldNotConnectTarget'];
99 echo '</div>';
100 unset($_REQUEST['submit_connect']);
102 } else {
104 * Creating the link object for both source and target databases and
105 * selecting the source and target databases using these links
107 foreach ($cons as $con) {
108 if (${"{$con}_connection"} != null) {
109 ${"{$con}_link"} = PMA_DBI_connect(${"{$con}_username"}, ${"{$con}_password"}, $is_controluser = false, ${"{$con}_server"});
110 } else {
111 ${"{$con}_link"} = null;
113 ${"{$con}_db_selected"} = PMA_DBI_select_db(${"{$con}_db"}, ${"{$con}_link"});
114 } // end foreach ($cons as $con)
116 if (($src_db_selected != 1) || ($trg_db_selected != 1)) {
118 * Displays error string if the database(s) did not exist
120 echo '<div class="error">';
121 if ($src_db_selected != 1) {
122 echo sprintf($GLOBALS['strDatabaseNotExisting'], htmlspecialchars($src_db));
124 if ($trg_db_selected != 1) {
125 echo sprintf($GLOBALS['strDatabaseNotExisting'], htmlspecialchars($trg_db));
127 echo '</div>';
128 unset($_REQUEST['submit_connect']);
130 } else if (($src_db_selected == 1) && ($trg_db_selected == 1)) {
133 * Using PMA_DBI_get_tables() to get all the tables
134 * from target and source databases.
136 $src_tables = PMA_DBI_get_tables($src_db, $src_link);
137 $source_tables_num = sizeof($src_tables);
139 $trg_tables = PMA_DBI_get_tables($trg_db, $trg_link);
140 $target_tables_num = sizeof($trg_tables);
143 * initializing arrays to save matching and non-matching
144 * table names from target and source databases.
146 $unmatched_num_src = 0;
147 $source_tables_uncommon = array();
148 $unmatched_num_trg = 0;
149 $target_tables_uncommon = array();
150 $matching_tables = array();
151 $matching_tables_num = 0;
154 * Using PMA_getMatchingTables to find which of the tables' names match
155 * in target and source database.
157 PMA_getMatchingTables($trg_tables, $src_tables, $matching_tables, $source_tables_uncommon);
159 * Finding the uncommon tables for the target database
160 * using function PMA_getNonMatchingTargetTables()
162 PMA_getNonMatchingTargetTables($trg_tables, $matching_tables, $target_tables_uncommon);
165 * Initializing several arrays to save the data and structure
166 * difference between the source and target databases.
168 $row_count = array(); //number of rows in source table that needs to be created in target database
169 $fields_num = array(); //number of fields in each matching table
170 $delete_array = array(); //stores the primary key values for target tables that have excessive rows than corresponding source tables.
171 $insert_array = array(array(array()));// stores the primary key values for the rows in each source table that are not present in target tables.
172 $update_array = array(array(array())); //stores the primary key values, name of field to be updated, value of the field to be updated for
173 // each row of matching table.
174 $matching_tables_fields = array(); //contains the fields' names for each matching table
175 $matching_tables_keys = array(); //contains the primary keys' names for each matching table
176 $uncommon_tables_fields = array(); //coantains the fields for all the source tables that are not present in target
177 $matching_tables_num = sizeof($matching_tables);
179 $source_columns = array(); //contains the full columns' information for all the source tables' columns
180 $target_columns = array(); //contains the full columns' information for all the target tables' columns
181 $uncommon_columns = array(); //contains names of columns present in source table but absent from the corresponding target table
182 $source_indexes = array(); //contains indexes on all the source tables
183 $target_indexes = array(); //contains indexes on all the target tables
184 $add_indexes_array = array(); //contains the indexes name present in source but absent from target tables
185 $target_tables_keys = array(); //contains the keys of all the target tables
186 $alter_indexes_array = array(); //contains the names of all the indexes for each table that need to be altered in target database
187 $remove_indexes_array = array(); //contains the names of indexes that are excessive in target tables
188 $alter_str_array = array(array()); //contains the criteria for each column that needs to be altered in target tables
189 $add_column_array = array(array()); //contains the name of columns that need to be added in target tables
191 * The criteria array contains all the criteria against which columns are compared for differences.
193 $criteria = array('Field', 'Type', 'Null', 'Collation', 'Key', 'Default', 'Comment');
195 for($i = 0; $i < sizeof($matching_tables); $i++) {
197 * Finding out all the differences structure, data and index diff for all the matching tables only
199 PMA_dataDiffInTables($src_db, $trg_db, $src_link, $trg_link, $matching_tables, $matching_tables_fields, $update_array, $insert_array,
200 $delete_array, $fields_num, $i, $matching_tables_keys);
202 PMA_structureDiffInTables($src_db, $trg_db, $src_link, $trg_link, $matching_tables, $source_columns,
203 $target_columns, $alter_str_array, $add_column_array, $uncommon_columns, $criteria, $target_tables_keys, $i);
205 PMA_indexesDiffInTables($src_db, $trg_db, $src_link, $trg_link, $matching_tables, $source_indexes, $target_indexes,
206 $add_indexes_array, $alter_indexes_array,$remove_indexes_array, $i);
209 for($j = 0; $j < sizeof($source_tables_uncommon); $j++) {
211 * Finding out the number of rows to be added in tables that need to be added in target database
213 PMA_dataDiffInUncommonTables($source_tables_uncommon, $src_db, $src_link, $j, $row_count);
216 * Storing all arrays in session for use when page is reloaded for each button press
218 $_SESSION['matching_tables'] = $matching_tables;
219 $_SESSION['update_array'] = $update_array;
220 $_SESSION['insert_array'] = $insert_array;
221 $_SESSION['src_db'] = $src_db;
222 $_SESSION['trg_db'] = $trg_db;
223 $_SESSION['matching_fields'] = $matching_tables_fields;
224 $_SESSION['src_uncommon_tables'] = $source_tables_uncommon;
225 $_SESSION['src_username'] = $src_username ;
226 $_SESSION['trg_username'] = $trg_username;
227 $_SESSION['src_password'] = $src_password;
228 $_SESSION['trg_password'] = $trg_password;
229 $_SESSION['trg_password'] = $trg_password;
230 $_SESSION['src_server'] = $src_server;
231 $_SESSION['trg_server'] = $trg_server;
232 $_SESSION['src_type'] = $src_type;
233 $_SESSION['trg_type'] = $trg_type;
234 $_SESSION['matching_tables_keys'] = $matching_tables_keys;
235 $_SESSION['uncommon_tables_fields'] = $uncommon_tables_fields;
236 $_SESSION['uncommon_tables_row_count'] = $row_count;
237 $_SESSION['target_tables_uncommon'] = $target_tables_uncommon;
238 $_SESSION['uncommon_tables'] = $source_tables_uncommon;
239 $_SESSION['delete_array'] = $delete_array;
240 $_SESSION['uncommon_columns'] = $uncommon_columns;
241 $_SESSION['source_columns'] = $source_columns;
242 $_SESSION['alter_str_array'] = $alter_str_array;
243 $_SESSION['target_tables_keys'] = $target_tables_keys;
244 $_SESSION['add_column_array'] = $add_column_array;
245 $_SESSION['criteria'] = $criteria;
246 $_SESSION['target_tables'] = $trg_tables;
247 $_SESSION['add_indexes_array'] = $add_indexes_array;
248 $_SESSION['alter_indexes_array'] = $alter_indexes_array;
249 $_SESSION['remove_indexes_array'] = $remove_indexes_array;
250 $_SESSION['source_indexes'] = $source_indexes;
251 $_SESSION['target_indexes'] = $target_indexes;
254 * Displays the sub-heading and icons showing Structure Synchronization and Data Synchronization
256 echo '<form name="synchronize_form" id="synchronize_form" method="post" action="server_synchronize.php">'
257 . PMA_generate_common_hidden_inputs('', '');
258 echo '<table class="data" width = "50%">
259 <tr>
260 <td> <h2>'
261 . ($GLOBALS['cfg']['MainPageIconic']
262 ? '<img class="icon" src="' . $pmaThemeImage . 'new_struct.jpg" width="32"'
263 . ' height="32" alt="" />'
264 : '')
265 . $strStructureSyn
266 .'</h2>' .'</td>';
267 echo '<td> <h2>'
268 . ($GLOBALS['cfg']['MainPageIconic']
269 ? '<img class="icon" src="' . $pmaThemeImage . 'new_data.jpg" width="32"'
270 . ' height="32" alt="" />'
271 : '')
272 . $strDataSyn
273 . '</h2>' .'</td>';
274 echo '</tr>
275 </table>';
278 * Displays the tables containing the source tables names, their difference with the target tables and target tables names
280 PMA_syncDisplayHeaderSource($src_db);
281 $odd_row = false;
283 * Display the matching tables' names and difference, first
285 for($i = 0; $i < count($matching_tables); $i++) {
286 $num_of_updates = 0;
287 $num_of_insertions = 0;
289 * Calculating the number of updates for each matching table
291 if (isset($update_array[$i])) {
292 if (isset($update_array[$i][0][$matching_tables_keys[$i][0]])) {
293 if (isset($update_array[$i])) {
294 $num_of_updates = sizeof($update_array[$i]);
295 } else {
296 $num_of_updates = 0;
298 } else {
299 $num_of_updates = 0;
303 * Calculating the number of insertions for each matching table
305 if (isset($insert_array[$i])) {
306 if (isset($insert_array[$i][0][$matching_tables_keys[$i][0]])) {
307 if (isset($insert_array[$i])) {
308 $num_of_insertions = sizeof($insert_array[$i]);
309 } else {
310 $num_of_insertions = 0;
312 } else {
313 $num_of_insertions = 0;
317 * Displays the name of the matching table
319 $odd_row = PMA_syncDisplayBeginTableRow($odd_row);
320 echo '<td>' . htmlspecialchars($matching_tables[$i]) . '</td>
321 <td align="center">';
323 * Calculating the number of alter columns, number of columns to be added, number of columns to be removed,
324 * number of index to added and renmoved.
326 $num_alter_cols = 0;
327 $num_insert_cols = 0;
328 $num_remove_cols = 0;
329 $num_add_index = 0;
330 $num_remove_index = 0;
332 if (isset($alter_str_array[$i])) {
333 $num_alter_cols = sizeof($alter_str_array[$i]);
335 if (isset($add_column_array[$i])) {
336 $num_insert_cols = sizeof($add_column_array[$i]);
338 if (isset($uncommon_columns[$i])) {
339 $num_remove_cols = sizeof($uncommon_columns[$i]);
341 if (isset($add_indexes_array[$i])) {
342 $num_add_index = sizeof($add_indexes_array[$i]);
344 if (isset($remove_indexes_array[$i])) {
345 $num_remove_index = sizeof($remove_indexes_array[$i]);
348 * Display the red button of structure synchronization if there exists any structure difference or index difference.
350 if (($num_alter_cols > 0) || ($num_insert_cols > 0) || ($num_remove_cols > 0) || ($num_add_index > 0) || ($num_remove_index > 0)) {
352 echo '<img class="icon" src="' . $pmaThemeImage . 'new_struct.jpg" width="29" height="29"
353 alt="' . $GLOBALS['strClickToSelect'] . '" onmouseover="change_Image(this);" onmouseout="change_Image(this);"
354 onclick="showDetails(' . "'MS" . $i . "','" . $num_alter_cols . "','" .$num_insert_cols .
355 "','" . $num_remove_cols . "','" . $num_add_index . "','" . $num_remove_index . "'"
356 . ', this ,' . "'" . htmlspecialchars($matching_tables[$i]) . "'" . ')"/>';
359 * Display the green button of data synchronization if there exists any data difference.
361 if (isset($update_array[$i]) || isset($insert_array[$i])) {
362 if (isset($update_array[$i][0][$matching_tables_keys[$i][0]]) || isset($insert_array[$i][0][$matching_tables_keys[$i][0]])) {
364 echo '<img class="icon" src="' . $pmaThemeImage . 'new_data.jpg" width="29" height="29"
365 alt="' . $GLOBALS['strClickToSelect'] . '" onmouseover="change_Image(this);" onmouseout="change_Image(this);"
366 onclick="showDetails('. "'MD" . $i . "','" . $num_of_updates . "','" . $num_of_insertions .
367 "','" . null . "','" . null . "','" . null . "'" . ', this ,' . "'" . htmlspecialchars($matching_tables[$i]) . "'" . ')" />';
370 echo '</td>
371 </tr>';
374 * Displays the tables' names present in source but missing from target
376 for ($j = 0; $j < count($source_tables_uncommon); $j++) {
377 $odd_row = PMA_syncDisplayBeginTableRow($odd_row);
378 echo '<td> + ' . htmlspecialchars($source_tables_uncommon[$j]) . '</td> ';
380 echo '<td align="center"><img class="icon" src="' . $pmaThemeImage . 'new_struct.jpg" width="29" height="29"
381 alt="' . $GLOBALS['strClickToSelect'] . '" onmouseover="change_Image(this);" onmouseout="change_Image(this);"
382 onclick="showDetails(' . "'US" . $j . "','" . null . "','" . null . "','" . null . "','" . null . "','" . null . "'" . ', this ,'
383 . "'" . htmlspecialchars($source_tables_uncommon[$j]) . "'" . ')"/>';
385 if ($row_count[$j] > 0)
387 echo '<img class="icon" src="' . $pmaThemeImage . 'new_data.jpg" width="29" height="29"
388 alt="' . $GLOBALS['strClickToSelect'] . '" onmouseover="change_Image(this);" onmouseout="change_Image(this);"
389 onclick="showDetails(' . "'UD" . $j . "','" . null . "','" . $row_count[$j] . "','" . null .
390 "','" . null . "','" . null . "'" . ', this ,' . "'" . htmlspecialchars($source_tables_uncommon[$j]) . "'" . ')" />';
392 echo '</td>
393 </tr>';
395 foreach ($target_tables_uncommon as $tbl_nc_name) {
396 $odd_row = PMA_syncDisplayBeginTableRow($odd_row);
397 echo '<td height="32">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </td><td></td>';
398 echo '</tr>';
401 * Displays the target tables names
403 echo '</table>';
405 $odd_row = PMA_syncDisplayHeaderTargetAndMatchingTables($trg_db, $matching_tables);
406 foreach ($source_tables_uncommon as $tbl_nc_name) {
407 $odd_row = PMA_syncDisplayBeginTableRow($odd_row);
408 echo '<td height="32">' . htmlspecialchars($tbl_nc_name) . ' (' . $GLOBALS['strNotPresent'] . ')</td>
409 </tr>';
411 foreach ($target_tables_uncommon as $tbl_nc_name) {
412 $odd_row = PMA_syncDisplayBeginTableRow($odd_row);
413 echo '<td> - ' . htmlspecialchars($tbl_nc_name) . '</td>';
414 echo '</tr>';
416 echo '</table>';
417 echo '</div>';
420 * This "list" div will contain a table and each row will depict information about structure/data diffrence in tables.
421 * Rows will be generated dynamically as soon as the colored buttons "D" or "S" are clicked.
424 echo '<div id="list" style = "overflow: auto; width: 1020px; height: 140px;
425 border-left: 1px gray solid; border-bottom: 1px gray solid;
426 padding:0px; margin: 0px">
428 <table>
429 <thead>
430 <tr style="width: 100%;">
431 <th id="table_name" style="width: 10%;" colspan="1">' . $strTable . ' </th>
432 <th id="str_diff" style="width: 65%;" colspan="6">' . $strStructureDiff . ' </th>
433 <th id="data_diff" style="width: 20%;" colspan="2">' . $strDataDiff . '</th>
434 </tr>
435 <tr style="width: 100%;">
436 <th style="width: 10%;">' . $strTableName . '</th>
437 <th style="width: 10%;">' . $strCreateTable . '</th>
438 <th style="width: 11%;">' . $strTableAddColumn . '</th>
439 <th style="width: 13%;">' . $strTableRemoveColumn . '</th>
440 <th style="width: 11%;">' . $strTableAlterColumn . '</th>
441 <th style="width: 12%;">' . $strTableRemoveIndex . '</th>
442 <th style="width: 11%;">' . $strTableApplyIndex . '</th>
443 <th style="width: 10%;">'. $strTableUpdateRow . '</th>
444 <th style="width: 10%;">' . $strTableInsertRow . '</th>
445 </tr>
446 </thead>
447 <tbody></tbody>
448 </table>
449 </div>';
451 * This fieldset displays the checkbox to confirm deletion of previous rows from target tables
453 echo '<fieldset>
454 <p><input type= "checkbox" name="delete_rows" id ="delete_rows" />' . $strTableDeleteRows . ' </p>
455 </fieldset>
456 <fieldset class="tblFooters">';
457 echo '<input type="button" name="apply_changes" value="' . $GLOBALS['strApplyChanges']
458 . '" onclick ="ApplySelectedChanges(' . "'" . $_SESSION['token'] . "'" . ')" />';
459 echo '<input type="submit" name="synchronize_db" value="' . $GLOBALS['strSynchronizeDb'] . '" />' . '</fieldset>';
460 echo '</form>';
463 } // end if ((isset($_REQUEST['submit_connect'])))
466 * Display the page when 'Apply Selected Changes' is pressed
468 if (isset($_REQUEST['Table_ids'])) {
470 * Displays success message
472 echo '<div class="success">' . $GLOBALS['strHaveBeenSynchronized'] . '</div>';
474 $src_db = $_SESSION['src_db'];
475 $trg_db = $_SESSION['trg_db'];
476 $update_array = $_SESSION['update_array'];
477 $insert_array = $_SESSION['insert_array'];
478 $src_username = $_SESSION['src_username'];
479 $trg_username = $_SESSION['trg_username'];
480 $src_password = $_SESSION['src_password'];
481 $trg_password = $_SESSION['trg_password'];
482 $src_server = $_SESSION['src_server'];
483 $trg_server = $_SESSION['trg_server'];
484 $src_type = $_SESSION['src_type'];
485 $trg_type = $_SESSION['trg_type'];
486 $uncommon_tables = $_SESSION['uncommon_tables'];
487 $matching_tables = $_SESSION['matching_tables'];
488 $matching_tables_keys = $_SESSION['matching_tables_keys'];
489 $matching_tables_fields = $_SESSION['matching_fields'];
490 $source_tables_uncommon = $_SESSION['src_uncommon_tables'];
491 $uncommon_tables_fields = $_SESSION['uncommon_tables_fields'];
492 $target_tables_uncommon = $_SESSION['target_tables_uncommon'];
493 $row_count = $_SESSION['uncommon_tables_row_count'];
494 $target_tables = $_SESSION['target_tables'];
496 $delete_array = $_SESSION['delete_array'];
497 $uncommon_columns = $_SESSION['uncommon_columns'];
498 $source_columns = $_SESSION['source_columns'];
499 $alter_str_array = $_SESSION['alter_str_array'];
500 $criteria = $_SESSION['criteria'];
501 $target_tables_keys = $_SESSION['target_tables_keys'];
502 $add_column_array = $_SESSION['add_column_array'];
503 $add_indexes_array = $_SESSION['add_indexes_array'];
504 $alter_indexes_array = $_SESSION['alter_indexes_array'];
505 $remove_indexes_array = $_SESSION['remove_indexes_array'];
506 $source_indexes = $_SESSION['source_indexes'];
507 $target_indexes = $_SESSION['target_indexes'];
508 $uncommon_cols = $uncommon_columns;
511 * Creating link object for source and target databases
513 foreach ($cons as $con) {
514 if (${"{$con}_type"} == "rmt") {
515 ${"{$con}_link"} = PMA_DBI_connect(${"{$con}_username"}, ${"{$con}_password"}, $is_controluser = false, ${"{$con}_server"});
516 } else {
517 ${"{$con}_link"} = null;
518 // working on current server, so initialize this for tracking
519 // (does not work if user defined current server as a remote one)
520 $GLOBALS['db'] = ${"{$con}_db"};
522 } // end foreach ($cons as $con)
525 * Initializing arrays to save the table ids whose data and structure difference is to be applied
527 $matching_table_data_diff = array(); //stores id of matching table having data difference
528 $matching_table_structure_diff = array(); //stores id of matching tables having structure difference
529 $uncommon_table_structure_diff = array(); //stores id of uncommon tables having structure difference
530 $uncommon_table_data_diff = array(); //stores id of uncommon tables having data difference
532 for ($i = 0; isset($_REQUEST[$i]); $i++ ) {
533 if (isset($_REQUEST[$i])) {
534 $table_id = split("US", $_REQUEST[$i]);
535 if (isset($table_id[1])) {
536 $uncommon_table_structure_diff[] = $table_id[1];
538 $table_id = split("UD", $_REQUEST[$i]);
539 if (isset($table_id[1])) {
540 $uncommon_table_data_diff[] = $table_id[1];
542 $table_id = split("MS", $_REQUEST[$i]);
543 if (isset($table_id[1])) {
544 $matching_table_structure_diff[] = $table_id[1];
547 $table_id = split("MD", $_REQUEST[$i]);
548 if (isset($table_id[1])) {
549 $matching_table_data_diff[] = $table_id[1];
552 } // end for
554 * Applying the structure difference on selected matching tables
556 for($q = 0 ; $q < sizeof($matching_table_structure_diff); $q++)
558 if (isset($alter_str_array[$matching_table_structure_diff[$q]])) {
560 PMA_alterTargetTableStructure($trg_db, $trg_link, $matching_tables, $source_columns, $alter_str_array, $matching_tables_fields,
561 $criteria, $matching_tables_keys, $target_tables_keys, $matching_table_structure_diff[$q], false);
563 unset($alter_str_array[$matching_table_structure_diff[$q]]);
565 if (isset($add_column_array[$matching_table_structure_diff[$q]])) {
567 PMA_findDeleteRowsFromTargetTables($delete_array, $matching_tables, $matching_table_structure_diff[$q], $target_tables_keys,
568 $matching_tables_keys, $trg_db, $trg_link, $src_db, $src_link);
570 if (isset($delete_array[$matching_table_structure_diff[$q]])) {
572 PMA_deleteFromTargetTable($trg_db, $trg_link, $matching_tables, $matching_table_structure_diff[$q], $target_tables_keys, $delete_array, false);
574 unset($delete_array[$matching_table_structure_diff[$q]]);
576 PMA_addColumnsInTargetTable($src_db, $trg_db,$src_link, $trg_link, $matching_tables, $source_columns, $add_column_array, $matching_tables_fields,
577 $criteria, $matching_tables_keys, $target_tables_keys, $uncommon_tables,$uncommon_tables_fields, $matching_table_structure_diff[$q], $uncommon_cols, false);
579 unset($add_column_array[$matching_table_structure_diff[$q]]);
581 if (isset($uncommon_columns[$matching_table_structure_diff[$q]])) {
583 PMA_removeColumnsFromTargetTable($trg_db, $trg_link, $matching_tables, $uncommon_columns, $matching_table_structure_diff[$q], false);
585 unset($uncommon_columns[$matching_table_structure_diff[$q]]);
587 if (isset($add_indexes_array[$matching_table_structure_diff[$q]]) || isset($remove_indexes_array[$matching_table_structure_diff[$q]])
588 || isset($alter_indexes_array[$matching_table_structure_diff[$q]])) {
590 PMA_applyIndexesDiff ($trg_db, $trg_link, $matching_tables, $source_indexes, $target_indexes, $add_indexes_array, $alter_indexes_array,
591 $remove_indexes_array, $matching_table_structure_diff[$q], false);
593 unset($add_indexes_array[$matching_table_structure_diff[$q]]);
594 unset($alter_indexes_array[$matching_table_structure_diff[$q]]);
595 unset($remove_indexes_array[$matching_table_structure_diff[$q]]);
599 * Applying the data difference. First checks if structure diff is applied or not.
600 * If not, then apply structure difference first then apply data difference.
602 for($p = 0; $p < sizeof($matching_table_data_diff); $p++)
604 if ($_REQUEST['checked'] == 'true') {
606 PMA_findDeleteRowsFromTargetTables($delete_array, $matching_tables, $matching_table_data_diff[$p], $target_tables_keys,
607 $matching_tables_keys, $trg_db, $trg_link, $src_db, $src_link);
609 if (isset($delete_array[$matching_table_data_diff[$p]])) {
611 PMA_deleteFromTargetTable($trg_db, $trg_link, $matching_tables, $matching_table_data_diff[$p], $target_tables_keys, $delete_array, false);
613 unset($delete_array[$matching_table_data_diff[$p]]);
616 if (isset($alter_str_array[$matching_table_data_diff[$p]])) {
618 PMA_alterTargetTableStructure($trg_db, $trg_link, $matching_tables, $source_columns, $alter_str_array, $matching_tables_fields,
619 $criteria, $matching_tables_keys, $target_tables_keys, $matching_table_data_diff[$p], false);
621 unset($alter_str_array[$matching_table_data_diff[$p]]);
623 if (isset($add_column_array[$matching_table_data_diff[$p]])) {
625 PMA_findDeleteRowsFromTargetTables($delete_array, $matching_tables, $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]])) {
630 PMA_deleteFromTargetTable($trg_db, $trg_link, $matching_tables, $matching_table_data_diff[$p], $target_tables_keys, $delete_array, false);
632 unset($delete_array[$matching_table_data_diff[$p]]);
634 PMA_addColumnsInTargetTable($src_db, $trg_db,$src_link, $trg_link, $matching_tables, $source_columns, $add_column_array, $matching_tables_fields,
635 $criteria, $matching_tables_keys, $target_tables_keys, $uncommon_tables, $uncommon_tables_fields, $matching_table_data_diff[$p], $uncommon_cols, false);
637 unset($add_column_array[$matching_table_data_diff[$p]]);
639 if (isset($uncommon_columns[$matching_table_data_diff[$p]])) {
641 PMA_removeColumnsFromTargetTable($trg_db, $trg_link, $matching_tables, $uncommon_columns, $matching_table_data_diff[$p], false);
643 unset($uncommon_columns[$matching_table_data_diff[$p]]);
645 if ((isset($matching_table_structure_diff[$q]) && isset($add_indexes_array[$matching_table_structure_diff[$q]]))
646 || (isset($matching_table_structure_diff[$q]) && isset($remove_indexes_array[$matching_table_structure_diff[$q]]))
647 || (isset($matching_table_structure_diff[$q]) && isset($alter_indexes_array[$matching_table_structure_diff[$q]]))) {
649 PMA_applyIndexesDiff ($trg_db, $trg_link, $matching_tables, $source_indexes, $target_indexes, $add_indexes_array, $alter_indexes_array,
650 $remove_indexes_array, $matching_table_structure_diff[$q], false);
652 unset($add_indexes_array[$matching_table_structure_diff[$q]]);
653 unset($alter_indexes_array[$matching_table_structure_diff[$q]]);
654 unset($remove_indexes_array[$matching_table_structure_diff[$q]]);
657 * Applying the data difference.
659 PMA_updateTargetTables($matching_tables, $update_array, $src_db, $trg_db, $trg_link, $matching_table_data_diff[$p], $matching_tables_keys, false);
661 PMA_insertIntoTargetTable($matching_tables, $src_db, $trg_db, $src_link, $trg_link , $matching_tables_fields, $insert_array,
662 $matching_table_data_diff[$p], $matching_tables_keys, $source_columns, $add_column_array, $criteria, $target_tables_keys,
663 $uncommon_tables, $uncommon_tables_fields, $uncommon_cols, $alter_str_array, $source_indexes, $target_indexes, $add_indexes_array,
664 $alter_indexes_array, $delete_array, $update_array, false);
667 * Updating the session variables to the latest values of the arrays.
669 $_SESSION['delete_array'] = $delete_array;
670 $_SESSION['uncommon_columns'] = $uncommon_columns;
671 $_SESSION['alter_str_array'] = $alter_str_array;
672 $_SESSION['add_column_array'] = $add_column_array;
673 $_SESSION['add_indexes_array'] = $add_indexes_array;
674 $_SESSION['remove_indexes_array'] = $remove_indexes_array;
675 $_SESSION['insert_array'] = $insert_array;
676 $_SESSION['update_array'] = $update_array;
679 * Applying structure difference to selected non-matching tables (present in Source but absent from Target).
681 for($s = 0; $s < sizeof($uncommon_table_structure_diff); $s++)
683 PMA_createTargetTables($src_db, $trg_db, $src_link, $trg_link, $uncommon_tables, $uncommon_table_structure_diff[$s], $uncommon_tables_fields, false);
684 $_SESSION['uncommon_tables_fields'] = $uncommon_tables_fields;
686 unset($uncommon_tables[$uncommon_table_structure_diff[$s]]);
689 * Applying data difference to selected non-matching tables (present in Source but absent from Target).
690 * Before data synchronization, structure synchronization is confirmed.
692 for($r = 0; $r < sizeof($uncommon_table_data_diff); $r++)
694 if (!(in_array($uncommon_table_data_diff[$r], $uncommon_table_structure_diff))) {
695 if (isset($uncommon_tables[$uncommon_table_data_diff[$r]])) {
697 PMA_createTargetTables($src_db, $trg_db, $src_link, $trg_link, $uncommon_tables, $uncommon_table_data_diff[$r], $uncommon_tables_fields, false);
698 $_SESSION['uncommon_tables_fields'] = $uncommon_tables_fields;
700 unset($uncommon_tables[$uncommon_table_data_diff[$r]]);
703 PMA_populateTargetTables($src_db, $trg_db, $src_link, $trg_link, $source_tables_uncommon, $uncommon_table_data_diff[$r],
704 $_SESSION['uncommon_tables_fields'], false);
706 unset($row_count[$uncommon_table_data_diff[$r]]);
709 * Again all the tables from source and target database are displayed with their differences.
710 * The differences have been removed from tables that have been synchronized
712 echo '<form name="applied_difference" id="synchronize_form" method="post" action="server_synchronize.php">'
713 . PMA_generate_common_hidden_inputs('', '');
715 PMA_syncDisplayHeaderSource($src_db);
716 $odd_row = false;
717 for($i = 0; $i < count($matching_tables); $i++) {
718 $odd_row = PMA_syncDisplayBeginTableRow($odd_row);
719 echo '<td align="center">' . $matching_tables[$i] . '</td>
720 <td align="center">';
722 $num_alter_cols = 0;
723 $num_insert_cols = 0;
724 $num_remove_cols = 0;
725 $num_add_index = 0;
726 $num_remove_index = 0;
728 if (isset($alter_str_array[$i])) {
729 $num_alter_cols = sizeof($alter_str_array[$i]);
731 if (isset($add_column_array[$i])) {
732 $num_insert_cols = sizeof($add_column_array[$i]);
734 if (isset($uncommon_columns[$i])) {
735 $num_remove_cols = sizeof($uncommon_columns[$i]);
737 if (isset($add_indexes_array[$i])) {
738 $num_add_index = sizeof($add_indexes_array[$i]);
740 if (isset($remove_indexes_array[$i])) {
741 $num_remove_index = sizeof($remove_indexes_array[$i]);
744 if (($num_alter_cols > 0) || ($num_insert_cols > 0) || ($num_remove_cols > 0) || ($num_add_index > 0) || ($num_remove_index > 0)) {
745 echo '<img class="icon" src="' . $pmaThemeImage . 'new_struct.jpg" width="29" height="29"
746 alt="' . $GLOBALS['strClickToSelect'] . '" onmouseover="change_Image(this);" onmouseout="change_Image(this);"
747 onclick="showDetails(' . "'MS" . $i . "','" . $num_alter_cols . "','" . $num_insert_cols . "','" . $num_remove_cols . "','" . $num_add_index . "','" . $num_remove_index . "'" .',
748 this ,' . "'" . $matching_tables[$i] . "'" . ')"/>';
750 if (!(in_array($i, $matching_table_data_diff))) {
752 if (isset($matching_tables_keys[$i][0]) && isset($update_array[$i][0][$matching_tables_keys[$i][0]])) {
753 if (isset($update_array[$i])) {
754 $num_of_updates = sizeof($update_array[$i]);
755 } else {
756 $num_of_updates = 0;
758 } else {
759 $num_of_updates = 0;
761 if (isset($matching_tables_keys[$i][0]) && isset($insert_array[$i][0][$matching_tables_keys[$i][0]])) {
762 if (isset($insert_array[$i])) {
763 $num_of_insertions = sizeof($insert_array[$i]);
764 } else {
765 $num_of_insertions = 0;
767 } else {
768 $num_of_insertions = 0;
771 if ((isset($matching_tables_keys[$i][0]) && isset($update_array[$i][0][$matching_tables_keys[$i][0]]))
772 || (isset($matching_tables_keys[$i][0]) && isset($insert_array[$i][0][$matching_tables_keys[$i][0]]))) {
773 echo '<img class="icon" src="' . $pmaThemeImage . 'new_data.jpg" width="29" height="29"
774 alt="' . $GLOBALS['strClickToSelect'] . '" onmouseover="change_Image(this);" onmouseout="change_Image(this);"
775 onclick="showDetails(' . "'MD" . $i . "','" . $num_of_updates . "','" . $num_of_insertions .
776 "','" . null . "','" . null . "','" . null . "'" .', this ,' . "'" . htmlspecialchars($matching_tables[$i]) . "'" . ')" />';
778 } else {
779 unset($update_array[$i]);
780 unset($insert_array[$i]);
782 echo '</td>
783 </tr>';
786 * placing updated value of arrays in session
789 $_SESSION['update_array'] = $update_array;
790 $_SESSION['insert_array'] = $insert_array;
792 for ($j = 0; $j < count($source_tables_uncommon); $j++) {
793 $odd_row = PMA_syncDisplayBeginTableRow($odd_row);
794 echo '<td align="center"> + ' . htmlspecialchars($source_tables_uncommon[$j]) . '</td>
795 <td align="center">';
797 * Display the difference only when it has not been applied
799 if (!(in_array($j, $uncommon_table_structure_diff))) {
800 if (isset($uncommon_tables[$j])) {
801 echo '<img class="icon" src="' . $pmaThemeImage . 'new_struct.jpg" width="29" height="29"
802 alt="' . $GLOBALS['strClickToSelect'] . '" onmouseover="change_Image(this);" onmouseout="change_Image(this);"
803 onclick="showDetails(' . "'US" . $j . "','" . null . "','" . null . "','" . null . "','" . null . "','" . null . "'" . ', this ,' . "'" . htmlspecialchars($source_tables_uncommon[$j]) . "'" . ')"/>' .' ';
805 } else {
806 unset($uncommon_tables[$j]);
809 * Display the difference only when it has not been applied
811 if (!(in_array($j, $uncommon_table_data_diff))) {
812 if (isset($row_count[$j]) && ($row_count > 0)) {
813 echo '<img class="icon" src="' . $pmaThemeImage . 'new_data.jpg" width="29" height="29"
814 alt="' . $GLOBALS['strClickToSelect'] . '" onmouseover="change_Image(this);" onmouseout="change_Image(this);"
815 onclick="showDetails(' . "'UD" . $j . "','" . null ."','" . $row_count[$j] ."','"
816 . null . "','" . null . "','" . null . "'" . ', this ,' . "'". htmlspecialchars($source_tables_uncommon[$j]) . "'" . ')" />';
818 } else {
819 unset($row_count[$j]);
822 echo '</td>
823 </tr>';
826 * placing the latest values of arrays in session
829 $_SESSION['uncommon_tables'] = $uncommon_tables;
830 $_SESSION['uncommon_tables_row_count'] = $row_count;
834 * Displaying the target database tables
836 foreach ($target_tables_uncommon as $tbl_nc_name) {
837 $odd_row = PMA_syncDisplayBeginTableRow($odd_row);
838 echo '<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </td><td></td>';
839 echo '</tr>';
841 echo '</table>';
842 $odd_row = PMA_syncDisplayHeaderTargetAndMatchingTables($trg_db, $matching_tables);
843 foreach ($source_tables_uncommon as $tbl_nc_name) {
844 $odd_row = PMA_syncDisplayBeginTableRow($odd_row);
845 if (in_array($tbl_nc_name, $uncommon_tables)) {
846 echo '<td>' . htmlspecialchars($tbl_nc_name) . ' (' . $GLOBALS['strNotPresent'] . ')</td>';
847 } else {
848 echo '<td>' . htmlspecialchars($tbl_nc_name) . '</td>';
850 echo '
851 </tr>';
853 foreach ($target_tables_uncommon as $tbl_nc_name) {
854 $odd_row = PMA_syncDisplayBeginTableRow($odd_row);
855 echo '<td> - ' . htmlspecialchars($tbl_nc_name) . '</td>';
856 echo '</tr>';
858 echo '</table>
859 </div>';
862 * This "list" div will contain a table and each row will depict information about structure/data diffrence in tables.
863 * Rows will be generated dynamically as soon as the colored buttons "D" or "S" are clicked.
866 echo '<div id="list" style = "overflow: auto; width: 1020px; height: 140px;
867 border-left: 1px gray solid; border-bottom: 1px gray solid;
868 padding:0px; margin: 0px">';
870 echo '<table>
871 <thead>
872 <tr style="width: 100%;">
873 <th id="table_name" style="width: 10%;" colspan="1">' . $strTable . ' </th>
874 <th id="str_diff" style="width: 65%;" colspan="6">' . $strStructureDiff . ' </th>
875 <th id="data_diff" style="width: 20%;" colspan="2">' . $strDataDiff . '</th>
876 </tr>
877 <tr style="width: 100%;">
878 <th style="width: 10%;">' . $strTableName . '</th>
879 <th style="width: 10%;">' . $strCreateTable . '</th>
880 <th style="width: 11%;">' . $strTableAddColumn . '</th>
881 <th style="width: 13%;">' . $strTableRemoveColumn . '</th>
882 <th style="width: 11%;">' . $strTableAlterColumn . '</th>
883 <th style="width: 12%;">' . $strTableRemoveIndex . '</th>
884 <th style="width: 11%;">' . $strTableApplyIndex . '</th>
885 <th style="width: 10%;">' . $strTableUpdateRow . '</th>
886 <th style="width: 10%;">' . $strTableInsertRow . '</th>
887 </tr>
888 </thead>
889 <tbody></tbody>
890 </table>
891 </div>';
894 * This fieldset displays the checkbox to confirm deletion of previous rows from target tables
896 echo '<fieldset>
897 <p><input type= "checkbox" name="delete_rows" id ="delete_rows" />' . $strTableDeleteRows . ' </p>
898 </fieldset>';
900 echo '<fieldset class="tblFooters">';
901 echo '<input type="button" name="apply_changes" value="' . $GLOBALS['strApplyChanges'] . '"
902 onclick ="ApplySelectedChanges(' . "'" . $_SESSION['token'] . "'" .')" />';
903 echo '<input type="submit" name="synchronize_db" value="' . $GLOBALS['strSynchronizeDb'] . '" />'
904 . '</fieldset>';
905 echo '</form>';
909 * Displays the page when 'Synchronize Databases' is pressed.
912 if (isset($_REQUEST['synchronize_db'])) {
914 $src_db = $_SESSION['src_db'];
915 $trg_db = $_SESSION['trg_db'];
916 $update_array = $_SESSION['update_array'];
917 $insert_array = $_SESSION['insert_array'];
918 $src_username = $_SESSION['src_username'];
919 $trg_username = $_SESSION['trg_username'];
920 $src_password = $_SESSION['src_password'];
921 $trg_password = $_SESSION['trg_password'];
922 $matching_tables = $_SESSION['matching_tables'];
923 $matching_tables_keys = $_SESSION['matching_tables_keys'];
924 $matching_tables_fields = $_SESSION['matching_fields'];
925 $source_tables_uncommon = $_SESSION['src_uncommon_tables'];
926 $uncommon_tables_fields = $_SESSION['uncommon_tables_fields'];
927 $target_tables_uncommon = $_SESSION['target_tables_uncommon'];
928 $row_count = $_SESSION['uncommon_tables_row_count'];
929 $uncommon_tables = $_SESSION['uncommon_tables'];
930 $target_tables = $_SESSION['target_tables'];
932 $delete_array = $_SESSION['delete_array'];
933 $uncommon_columns = $_SESSION['uncommon_columns'];
934 $source_columns = $_SESSION['source_columns'];
935 $alter_str_array = $_SESSION['alter_str_array'];
936 $criteria = $_SESSION['criteria'];
937 $target_tables_keys = $_SESSION['target_tables_keys'];
938 $add_column_array = $_SESSION['add_column_array'];
939 $add_indexes_array = $_SESSION['add_indexes_array'];
940 $alter_indexes_array = $_SESSION['alter_indexes_array'];
941 $remove_indexes_array = $_SESSION['remove_indexes_array'];
942 $source_indexes = $_SESSION['source_indexes'];
943 $target_indexes = $_SESSION['target_indexes'];
944 $uncommon_cols = $uncommon_columns;
947 * Display success message.
949 echo '<div class="success">' . $GLOBALS['strTargetDatabaseHasBeenSynchronized'] . '</div>';
951 * Displaying all the tables of source and target database and now no difference is there.
953 PMA_syncDisplayHeaderSource($src_db);
955 $odd_row = false;
956 for($i = 0; $i < count($matching_tables); $i++)
958 $odd_row = PMA_syncDisplayBeginTableRow($odd_row);
959 echo '<td>' . htmlspecialchars($matching_tables[$i]) . '</td>
960 <td></td>
961 </tr>';
963 for ($j = 0; $j < count($source_tables_uncommon); $j++) {
964 $odd_row = PMA_syncDisplayBeginTableRow($odd_row);
965 echo '<td> + ' . htmlspecialchars($source_tables_uncommon[$j]) . '</td> ';
966 echo '<td></td>
967 </tr>';
969 foreach ($target_tables_uncommon as $tbl_nc_name) {
970 $odd_row = PMA_syncDisplayBeginTableRow($odd_row);
971 echo '<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </td><td></td>';
972 echo '</tr>';
974 echo '</table>';
975 $odd_row = PMA_syncDisplayHeaderTargetAndMatchingTables($trg_db, $matching_tables);
976 foreach ($source_tables_uncommon as $tbl_nc_name) {
977 $odd_row = PMA_syncDisplayBeginTableRow($odd_row);
978 echo '<td>' . htmlspecialchars($tbl_nc_name) . ' </td>
979 </tr>';
981 foreach ($target_tables_uncommon as $tbl_nc_name) {
982 $odd_row = PMA_syncDisplayBeginTableRow($odd_row);
983 echo '<td> ' . htmlspecialchars($tbl_nc_name) . '</td>';
984 echo '</tr>';
986 echo '</table> </div>';
989 * connecting the source and target servers
991 if ('rmt' == $_SESSION['src_type']) {
992 $src_link = PMA_DBI_connect($src_username, $src_password, $is_controluser = false, $_SESSION['src_server']);
993 } else {
994 $src_link = $GLOBALS['userlink'];
995 // working on current server, so initialize this for tracking
996 // (does not work if user defined current server as a remote one)
997 $GLOBALS['db'] = $_SESSION['src_db'];
999 if ('rmt' == $_SESSION['trg_type']) {
1000 $trg_link = PMA_DBI_connect($trg_username, $trg_password, $is_controluser = false, $_SESSION['trg_server']);
1001 } else {
1002 $trg_link = $GLOBALS['userlink'];
1003 // working on current server, so initialize this for tracking
1004 $GLOBALS['db'] = $_SESSION['trg_db'];
1008 * Displaying the queries.
1010 echo '<h5>' . $GLOBALS['strQueriesExecuted'] . '</h5>';
1011 echo '<div id="serverstatus" style = "overflow: auto; width: 1050px; height: 180px;
1012 border-left: 1px gray solid; border-bottom: 1px gray solid; padding: 0px; margin: 0px"> ';
1014 * Applying all sorts of differences for each matching table
1016 for($p = 0; $p <sizeof($matching_tables); $p++) {
1018 * If the check box is checked for deleting previous rows from the target database tables then
1019 * first find out rows to be deleted and then delete the rows.
1021 if (isset($_REQUEST['delete_rows'])) {
1022 PMA_findDeleteRowsFromTargetTables($delete_array, $matching_tables, $p, $target_tables_keys, $matching_tables_keys,
1023 $trg_db, $trg_link, $src_db, $src_link);
1025 if (isset($delete_array[$p])) {
1026 PMA_deleteFromTargetTable($trg_db, $trg_link, $matching_tables, $p, $target_tables_keys, $delete_array, true);
1027 unset($delete_array[$p]);
1030 if (isset($alter_str_array[$p])) {
1031 PMA_alterTargetTableStructure($trg_db, $trg_link, $matching_tables, $source_columns, $alter_str_array, $matching_tables_fields,
1032 $criteria, $matching_tables_keys, $target_tables_keys, $p, true);
1033 unset($alter_str_array[$p]);
1035 if (isset($add_column_array[$p])) {
1036 PMA_findDeleteRowsFromTargetTables($delete_array, $matching_tables, $p, $target_tables_keys, $matching_tables_keys,
1037 $trg_db, $trg_link, $src_db, $src_link);
1039 if (isset($delete_array[$p])) {
1040 PMA_deleteFromTargetTable($trg_db, $trg_link, $matching_tables, $p, $target_tables_keys, $delete_array, true);
1041 unset($delete_array[$p]);
1043 PMA_addColumnsInTargetTable($src_db, $trg_db, $src_link, $trg_link, $matching_tables, $source_columns, $add_column_array, $matching_tables_fields,
1044 $criteria, $matching_tables_keys, $target_tables_keys, $uncommon_tables,$uncommon_tables_fields, $p, $uncommon_cols, true);
1045 unset($add_column_array[$p]);
1047 if (isset($uncommon_columns[$p])) {
1048 PMA_removeColumnsFromTargetTable($trg_db, $trg_link, $matching_tables, $uncommon_columns, $p, true);
1049 unset($uncommon_columns[$p]);
1051 if (isset($matching_table_structure_diff) &&
1052 (isset($add_indexes_array[$matching_table_structure_diff[$p]])
1053 || isset($remove_indexes_array[$matching_table_structure_diff[$p]])
1054 || isset($alter_indexes_array[$matching_table_structure_diff[$p]]))) {
1055 PMA_applyIndexesDiff ($trg_db, $trg_link, $matching_tables, $source_indexes, $target_indexes, $add_indexes_array, $alter_indexes_array,
1056 $remove_indexes_array, $matching_table_structure_diff[$p], true);
1058 unset($add_indexes_array[$matching_table_structure_diff[$p]]);
1059 unset($alter_indexes_array[$matching_table_structure_diff[$p]]);
1060 unset($remove_indexes_array[$matching_table_structure_diff[$p]]);
1063 PMA_updateTargetTables($matching_tables, $update_array, $src_db, $trg_db, $trg_link, $p, $matching_tables_keys, true);
1065 PMA_insertIntoTargetTable($matching_tables, $src_db, $trg_db, $src_link, $trg_link , $matching_tables_fields, $insert_array,$p, $matching_tables_keys,
1066 $matching_tables_keys,$source_columns, $add_column_array, $criteria, $target_tables_keys,$uncommon_tables, $uncommon_tables_fields,$uncommon_cols,
1067 $alter_str_array,$source_indexes, $target_indexes, $add_indexes_array, $alter_indexes_array, $delete_array, $update_array, true);
1071 * Creating and populating tables present in source but absent from target database.
1073 for($q = 0; $q < sizeof($source_tables_uncommon) ;$q++) {
1074 if (isset($uncommon_tables[$q])) {
1075 PMA_createTargetTables($src_db, $trg_db, $src_link, $trg_link, $source_tables_uncommon, $q, $uncommon_tables_fields, true);
1077 if (isset($row_count[$q])) {
1078 PMA_populateTargetTables($src_db, $trg_db, $src_link, $trg_link, $source_tables_uncommon, $q, $uncommon_tables_fields, true);
1081 echo "</div>";
1085 * Displays the main page when none of the following buttons is pressed
1088 if (! isset($_REQUEST['submit_connect']) && ! isset($_REQUEST['synchronize_db']) && ! isset($_REQUEST['Table_ids']) )
1090 /**
1091 * Displays the sub-page heading
1093 echo '<h2>' . ($GLOBALS['cfg']['MainPageIconic']
1094 ? '<img class="icon" src="' . $pmaThemeImage . 's_sync.png" width="18"'
1095 . ' height="18" alt="" />'
1096 : '')
1097 . $strSynchronize
1098 .'</h2>';
1100 echo '<div id="serverstatus">
1101 <form name="connection_form" id="connection_form" method="post" action="server_synchronize.php"
1102 >' // TODO: add check if all var. are filled in
1103 . PMA_generate_common_hidden_inputs('', '');
1104 echo '<fieldset>';
1105 echo '<legend>' . $GLOBALS['strSynchronize'] . '</legend>';
1107 * Displays the forms
1110 $databases = PMA_DBI_get_databases_full(null, false, null, 'SCHEMA_NAME',
1111 'ASC', 0, true);
1113 foreach ($cons as $type) {
1114 echo '<table id="serverconnection_' . $type . '_remote" class="data">
1115 <tr>
1116 <th colspan="2">' . $GLOBALS['strDatabase_'.$type] . '</th>
1117 </tr>
1118 <tr class="odd">
1119 <td colspan="2" style="text-align: center">
1120 <select name="' . $type . '_type" id="' . $type . '_type">
1121 <option value="rmt">' . $GLOBALS['strRemoteServer'] . '</option>
1122 <option value="cur">' . $GLOBALS['strCurrentServer'] . '</option>
1123 </select>
1124 </td>
1125 </tr>
1126 <tr class="even" id="' . $type . 'tr1">
1127 <td>' . $GLOBALS['strHost'] . '</td>
1128 <td><input type="text" name="' . $type . '_host" /></td>
1129 </tr>
1130 <tr class="odd" id="' . $type . 'tr2">
1131 <td>' . $GLOBALS['strPort'] . '</td>
1132 <td><input type="text" name="' . $type . '_port" value="3306" maxlength="5" size="5" /></td>
1133 </tr>
1134 <tr class="even" id="' . $type . 'tr3">
1135 <td>' . $GLOBALS['strSocket'] . '</td>
1136 <td><input type="text" name="' . $type . '_socket" /></td>
1137 </tr>
1138 <tr class="odd" id="'.$type.'tr4">
1139 <td>' . $GLOBALS['strUserName']. '</td>
1140 <td><input type="text" name="'. $type . '_username" /></td>
1141 </tr>
1142 <tr class="even" id="' . $type . 'tr5">
1143 <td>' . $GLOBALS['strPassword'] . '</td>
1144 <td><input type="password" name="' . $type . '_pass" /> </td>
1145 </tr>
1146 <tr class="odd" id="' . $type . 'tr6">
1147 <td>' . $GLOBALS['strDatabase'] . '</td>
1148 <td><input type="text" name="' . $type . '_db" /></td>
1149 </tr>
1150 <tr class="even" id="' . $type . 'tr7" style="display: none;">
1151 <td>' . $GLOBALS['strDatabase'] . '</td>
1152 <td>';
1153 // these unset() do not complain if the elements do not exist
1154 unset($databases['mysql']);
1155 unset($databases['information_schema']);
1156 if (count($databases) == 0) {
1157 echo $GLOBALS['strNoDatabases'];
1158 } else {
1159 echo '
1160 <select name="' . $type . '_db_sel">
1162 foreach ($databases as $db) {
1163 echo ' <option>' . $db['SCHEMA_NAME'] . '</option>';
1165 echo '</select>';
1167 echo '</td> </tr>
1168 </table>';
1170 // Add JS to show/hide rows based on the selection
1171 PMA_js(''.
1172 '$(\'' . $type . '_type\').addEvent(\'change\',function() {' .
1173 ' if ($(\'' . $type . 'tr1\').getStyle(\'display\')=="none") {' .
1174 ' for (var i=1; i<7; i++)' .
1175 ' $(\'' . $type . 'tr\'+i).tween(\'display\', \'table-row\');' .
1176 ' $(\'' . $type . 'tr7\').tween(\'display\', \'none\');' .
1177 ' }' .
1178 ' else {' .
1179 ' for (var i=1; i<7; i++)'.
1180 ' $(\'' . $type . 'tr\'+i).tween(\'display\', \'none\');' .
1181 ' $(\'' . $type . 'tr7\').tween(\'display\', \'table-row\');'.
1182 ' }' .
1183 '});'
1186 unset ($types, $type);
1188 echo '
1189 </fieldset>
1190 <fieldset class="tblFooters">
1191 <input type="submit" name="submit_connect" value="' . $GLOBALS['strGo'] .'" id="buttonGo" />
1192 </fieldset>
1193 </form>
1194 </div>
1195 <div class="notice">' . $strSynchronizationNote . '</div>';
1199 * Displays the footer
1201 require_once './libraries/footer.inc.php';