code cleanup
[phpmyadmin/madhuracj.git] / server_synchronize.php
blob6312467f7dc6f6fe8bc36ec18288366dd8c1a116
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 be added and removed.
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]);
347 if (isset($alter_indexes_array[$i])) {
348 $num_add_index += sizeof($alter_indexes_array[$i]);
349 $num_remove_index += sizeof($alter_indexes_array[$i]);
352 * Display the red button of structure synchronization if there exists any structure difference or index difference.
354 if (($num_alter_cols > 0) || ($num_insert_cols > 0) || ($num_remove_cols > 0) || ($num_add_index > 0) || ($num_remove_index > 0)) {
356 echo '<img class="icon" src="' . $pmaThemeImage . 'new_struct.jpg" width="29" height="29"
357 alt="' . $GLOBALS['strClickToSelect'] . '" onmouseover="change_Image(this);" onmouseout="change_Image(this);"
358 onclick="showDetails(' . "'MS" . $i . "','" . $num_alter_cols . "','" .$num_insert_cols .
359 "','" . $num_remove_cols . "','" . $num_add_index . "','" . $num_remove_index . "'"
360 . ', this ,' . "'" . htmlspecialchars($matching_tables[$i]) . "'" . ')"/>';
363 * Display the green button of data synchronization if there exists any data difference.
365 if (isset($update_array[$i]) || isset($insert_array[$i])) {
366 if (isset($update_array[$i][0][$matching_tables_keys[$i][0]]) || isset($insert_array[$i][0][$matching_tables_keys[$i][0]])) {
368 echo '<img class="icon" src="' . $pmaThemeImage . 'new_data.jpg" width="29" height="29"
369 alt="' . $GLOBALS['strClickToSelect'] . '" onmouseover="change_Image(this);" onmouseout="change_Image(this);"
370 onclick="showDetails('. "'MD" . $i . "','" . $num_of_updates . "','" . $num_of_insertions .
371 "','" . null . "','" . null . "','" . null . "'" . ', this ,' . "'" . htmlspecialchars($matching_tables[$i]) . "'" . ')" />';
374 echo '</td>
375 </tr>';
378 * Displays the tables' names present in source but missing from target
380 for ($j = 0; $j < count($source_tables_uncommon); $j++) {
381 $odd_row = PMA_syncDisplayBeginTableRow($odd_row);
382 echo '<td> + ' . htmlspecialchars($source_tables_uncommon[$j]) . '</td> ';
384 echo '<td align="center"><img class="icon" src="' . $pmaThemeImage . 'new_struct.jpg" width="29" height="29"
385 alt="' . $GLOBALS['strClickToSelect'] . '" onmouseover="change_Image(this);" onmouseout="change_Image(this);"
386 onclick="showDetails(' . "'US" . $j . "','" . null . "','" . null . "','" . null . "','" . null . "','" . null . "'" . ', this ,'
387 . "'" . htmlspecialchars($source_tables_uncommon[$j]) . "'" . ')"/>';
389 if ($row_count[$j] > 0)
391 echo '<img class="icon" src="' . $pmaThemeImage . 'new_data.jpg" width="29" height="29"
392 alt="' . $GLOBALS['strClickToSelect'] . '" onmouseover="change_Image(this);" onmouseout="change_Image(this);"
393 onclick="showDetails(' . "'UD" . $j . "','" . null . "','" . $row_count[$j] . "','" . null .
394 "','" . null . "','" . null . "'" . ', this ,' . "'" . htmlspecialchars($source_tables_uncommon[$j]) . "'" . ')" />';
396 echo '</td>
397 </tr>';
399 foreach ($target_tables_uncommon as $tbl_nc_name) {
400 $odd_row = PMA_syncDisplayBeginTableRow($odd_row);
401 echo '<td height="32">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </td><td></td>';
402 echo '</tr>';
405 * Displays the target tables names
407 echo '</table>';
409 $odd_row = PMA_syncDisplayHeaderTargetAndMatchingTables($trg_db, $matching_tables);
410 foreach ($source_tables_uncommon as $tbl_nc_name) {
411 $odd_row = PMA_syncDisplayBeginTableRow($odd_row);
412 echo '<td height="32">' . htmlspecialchars($tbl_nc_name) . ' (' . $GLOBALS['strNotPresent'] . ')</td>
413 </tr>';
415 foreach ($target_tables_uncommon as $tbl_nc_name) {
416 $odd_row = PMA_syncDisplayBeginTableRow($odd_row);
417 echo '<td> - ' . htmlspecialchars($tbl_nc_name) . '</td>';
418 echo '</tr>';
420 echo '</table>';
421 echo '</div>';
424 * This "list" div will contain a table and each row will depict information about structure/data diffrence in tables.
425 * Rows will be generated dynamically as soon as the colored buttons "D" or "S" are clicked.
428 echo '<div id="list" style = "overflow: auto; width: 1020px; height: 140px;
429 border-left: 1px gray solid; border-bottom: 1px gray solid;
430 padding:0px; margin: 0px">
432 <table>
433 <thead>
434 <tr style="width: 100%;">
435 <th id="table_name" style="width: 10%;" colspan="1">' . $strTable . ' </th>
436 <th id="str_diff" style="width: 65%;" colspan="6">' . $strStructureDiff . ' </th>
437 <th id="data_diff" style="width: 20%;" colspan="2">' . $strDataDiff . '</th>
438 </tr>
439 <tr style="width: 100%;">
440 <th style="width: 10%;">' . $strTableName . '</th>
441 <th style="width: 10%;">' . $strCreateTable . '</th>
442 <th style="width: 11%;">' . $strTableAddColumn . '</th>
443 <th style="width: 13%;">' . $strTableRemoveColumn . '</th>
444 <th style="width: 11%;">' . $strTableAlterColumn . '</th>
445 <th style="width: 12%;">' . $strTableRemoveIndex . '</th>
446 <th style="width: 11%;">' . $strTableApplyIndex . '</th>
447 <th style="width: 10%;">'. $strTableUpdateRow . '</th>
448 <th style="width: 10%;">' . $strTableInsertRow . '</th>
449 </tr>
450 </thead>
451 <tbody></tbody>
452 </table>
453 </div>';
455 * This fieldset displays the checkbox to confirm deletion of previous rows from target tables
457 echo '<fieldset>
458 <p><input type= "checkbox" name="delete_rows" id ="delete_rows" />' . $strTableDeleteRows . ' </p>
459 </fieldset>
460 <fieldset class="tblFooters">';
461 echo '<input type="button" name="apply_changes" value="' . $GLOBALS['strApplyChanges']
462 . '" onclick ="ApplySelectedChanges(' . "'" . $_SESSION['token'] . "'" . ')" />';
463 echo '<input type="submit" name="synchronize_db" value="' . $GLOBALS['strSynchronizeDb'] . '" />' . '</fieldset>';
464 echo '</form>';
467 } // end if ((isset($_REQUEST['submit_connect'])))
470 * Display the page when 'Apply Selected Changes' is pressed
472 if (isset($_REQUEST['Table_ids'])) {
474 * Displays success message
476 echo '<div class="success">' . $GLOBALS['strHaveBeenSynchronized'] . '</div>';
478 $src_db = $_SESSION['src_db'];
479 $trg_db = $_SESSION['trg_db'];
480 $update_array = $_SESSION['update_array'];
481 $insert_array = $_SESSION['insert_array'];
482 $src_username = $_SESSION['src_username'];
483 $trg_username = $_SESSION['trg_username'];
484 $src_password = $_SESSION['src_password'];
485 $trg_password = $_SESSION['trg_password'];
486 $src_server = $_SESSION['src_server'];
487 $trg_server = $_SESSION['trg_server'];
488 $src_type = $_SESSION['src_type'];
489 $trg_type = $_SESSION['trg_type'];
490 $uncommon_tables = $_SESSION['uncommon_tables'];
491 $matching_tables = $_SESSION['matching_tables'];
492 $matching_tables_keys = $_SESSION['matching_tables_keys'];
493 $matching_tables_fields = $_SESSION['matching_fields'];
494 $source_tables_uncommon = $_SESSION['src_uncommon_tables'];
495 $uncommon_tables_fields = $_SESSION['uncommon_tables_fields'];
496 $target_tables_uncommon = $_SESSION['target_tables_uncommon'];
497 $row_count = $_SESSION['uncommon_tables_row_count'];
498 $target_tables = $_SESSION['target_tables'];
500 $delete_array = $_SESSION['delete_array'];
501 $uncommon_columns = $_SESSION['uncommon_columns'];
502 $source_columns = $_SESSION['source_columns'];
503 $alter_str_array = $_SESSION['alter_str_array'];
504 $criteria = $_SESSION['criteria'];
505 $target_tables_keys = $_SESSION['target_tables_keys'];
506 $add_column_array = $_SESSION['add_column_array'];
507 $add_indexes_array = $_SESSION['add_indexes_array'];
508 $alter_indexes_array = $_SESSION['alter_indexes_array'];
509 $remove_indexes_array = $_SESSION['remove_indexes_array'];
510 $source_indexes = $_SESSION['source_indexes'];
511 $target_indexes = $_SESSION['target_indexes'];
512 $uncommon_cols = $uncommon_columns;
515 * Creating link object for source and target databases
517 foreach ($cons as $con) {
518 if (${"{$con}_type"} == "rmt") {
519 ${"{$con}_link"} = PMA_DBI_connect(${"{$con}_username"}, ${"{$con}_password"}, $is_controluser = false, ${"{$con}_server"});
520 } else {
521 ${"{$con}_link"} = null;
522 // working on current server, so initialize this for tracking
523 // (does not work if user defined current server as a remote one)
524 $GLOBALS['db'] = ${"{$con}_db"};
526 } // end foreach ($cons as $con)
529 * Initializing arrays to save the table ids whose data and structure difference is to be applied
531 $matching_table_data_diff = array(); //stores id of matching table having data difference
532 $matching_table_structure_diff = array(); //stores id of matching tables having structure difference
533 $uncommon_table_structure_diff = array(); //stores id of uncommon tables having structure difference
534 $uncommon_table_data_diff = array(); //stores id of uncommon tables having data difference
536 for ($i = 0; isset($_REQUEST[$i]); $i++ ) {
537 if (isset($_REQUEST[$i])) {
538 $table_id = split("US", $_REQUEST[$i]);
539 if (isset($table_id[1])) {
540 $uncommon_table_structure_diff[] = $table_id[1];
542 $table_id = split("UD", $_REQUEST[$i]);
543 if (isset($table_id[1])) {
544 $uncommon_table_data_diff[] = $table_id[1];
546 $table_id = split("MS", $_REQUEST[$i]);
547 if (isset($table_id[1])) {
548 $matching_table_structure_diff[] = $table_id[1];
551 $table_id = split("MD", $_REQUEST[$i]);
552 if (isset($table_id[1])) {
553 $matching_table_data_diff[] = $table_id[1];
556 } // end for
558 * Applying the structure difference on selected matching tables
560 for($q = 0 ; $q < sizeof($matching_table_structure_diff); $q++)
562 if (isset($alter_str_array[$matching_table_structure_diff[$q]])) {
564 PMA_alterTargetTableStructure($trg_db, $trg_link, $matching_tables, $source_columns, $alter_str_array, $matching_tables_fields,
565 $criteria, $matching_tables_keys, $target_tables_keys, $matching_table_structure_diff[$q], false);
567 unset($alter_str_array[$matching_table_structure_diff[$q]]);
569 if (isset($add_column_array[$matching_table_structure_diff[$q]])) {
571 PMA_findDeleteRowsFromTargetTables($delete_array, $matching_tables, $matching_table_structure_diff[$q], $target_tables_keys,
572 $matching_tables_keys, $trg_db, $trg_link, $src_db, $src_link);
574 if (isset($delete_array[$matching_table_structure_diff[$q]])) {
576 PMA_deleteFromTargetTable($trg_db, $trg_link, $matching_tables, $matching_table_structure_diff[$q], $target_tables_keys, $delete_array, false);
578 unset($delete_array[$matching_table_structure_diff[$q]]);
580 PMA_addColumnsInTargetTable($src_db, $trg_db,$src_link, $trg_link, $matching_tables, $source_columns, $add_column_array, $matching_tables_fields,
581 $criteria, $matching_tables_keys, $target_tables_keys, $uncommon_tables,$uncommon_tables_fields, $matching_table_structure_diff[$q], $uncommon_cols, false);
583 unset($add_column_array[$matching_table_structure_diff[$q]]);
585 if (isset($uncommon_columns[$matching_table_structure_diff[$q]])) {
587 PMA_removeColumnsFromTargetTable($trg_db, $trg_link, $matching_tables, $uncommon_columns, $matching_table_structure_diff[$q], false);
589 unset($uncommon_columns[$matching_table_structure_diff[$q]]);
591 if (isset($add_indexes_array[$matching_table_structure_diff[$q]]) || isset($remove_indexes_array[$matching_table_structure_diff[$q]])
592 || isset($alter_indexes_array[$matching_table_structure_diff[$q]])) {
594 PMA_applyIndexesDiff ($trg_db, $trg_link, $matching_tables, $source_indexes, $target_indexes, $add_indexes_array, $alter_indexes_array,
595 $remove_indexes_array, $matching_table_structure_diff[$q], false);
597 unset($add_indexes_array[$matching_table_structure_diff[$q]]);
598 unset($alter_indexes_array[$matching_table_structure_diff[$q]]);
599 unset($remove_indexes_array[$matching_table_structure_diff[$q]]);
603 * Applying the data difference. First checks if structure diff is applied or not.
604 * If not, then apply structure difference first then apply data difference.
606 for($p = 0; $p < sizeof($matching_table_data_diff); $p++)
608 if ($_REQUEST['checked'] == 'true') {
610 PMA_findDeleteRowsFromTargetTables($delete_array, $matching_tables, $matching_table_data_diff[$p], $target_tables_keys,
611 $matching_tables_keys, $trg_db, $trg_link, $src_db, $src_link);
613 if (isset($delete_array[$matching_table_data_diff[$p]])) {
615 PMA_deleteFromTargetTable($trg_db, $trg_link, $matching_tables, $matching_table_data_diff[$p], $target_tables_keys, $delete_array, false);
617 unset($delete_array[$matching_table_data_diff[$p]]);
620 if (isset($alter_str_array[$matching_table_data_diff[$p]])) {
622 PMA_alterTargetTableStructure($trg_db, $trg_link, $matching_tables, $source_columns, $alter_str_array, $matching_tables_fields,
623 $criteria, $matching_tables_keys, $target_tables_keys, $matching_table_data_diff[$p], false);
625 unset($alter_str_array[$matching_table_data_diff[$p]]);
627 if (isset($add_column_array[$matching_table_data_diff[$p]])) {
629 PMA_findDeleteRowsFromTargetTables($delete_array, $matching_tables, $matching_table_data_diff[$p], $target_tables_keys,
630 $matching_tables_keys, $trg_db, $trg_link, $src_db, $src_link);
632 if (isset($delete_array[$matching_table_data_diff[$p]])) {
634 PMA_deleteFromTargetTable($trg_db, $trg_link, $matching_tables, $matching_table_data_diff[$p], $target_tables_keys, $delete_array, false);
636 unset($delete_array[$matching_table_data_diff[$p]]);
638 PMA_addColumnsInTargetTable($src_db, $trg_db,$src_link, $trg_link, $matching_tables, $source_columns, $add_column_array, $matching_tables_fields,
639 $criteria, $matching_tables_keys, $target_tables_keys, $uncommon_tables, $uncommon_tables_fields, $matching_table_data_diff[$p], $uncommon_cols, false);
641 unset($add_column_array[$matching_table_data_diff[$p]]);
643 if (isset($uncommon_columns[$matching_table_data_diff[$p]])) {
645 PMA_removeColumnsFromTargetTable($trg_db, $trg_link, $matching_tables, $uncommon_columns, $matching_table_data_diff[$p], false);
647 unset($uncommon_columns[$matching_table_data_diff[$p]]);
649 if ((isset($matching_table_structure_diff[$q]) && isset($add_indexes_array[$matching_table_structure_diff[$q]]))
650 || (isset($matching_table_structure_diff[$q]) && isset($remove_indexes_array[$matching_table_structure_diff[$q]]))
651 || (isset($matching_table_structure_diff[$q]) && isset($alter_indexes_array[$matching_table_structure_diff[$q]]))) {
653 PMA_applyIndexesDiff ($trg_db, $trg_link, $matching_tables, $source_indexes, $target_indexes, $add_indexes_array, $alter_indexes_array,
654 $remove_indexes_array, $matching_table_structure_diff[$q], false);
656 unset($add_indexes_array[$matching_table_structure_diff[$q]]);
657 unset($alter_indexes_array[$matching_table_structure_diff[$q]]);
658 unset($remove_indexes_array[$matching_table_structure_diff[$q]]);
661 * Applying the data difference.
663 PMA_updateTargetTables($matching_tables, $update_array, $src_db, $trg_db, $trg_link, $matching_table_data_diff[$p], $matching_tables_keys, false);
665 PMA_insertIntoTargetTable($matching_tables, $src_db, $trg_db, $src_link, $trg_link , $matching_tables_fields, $insert_array,
666 $matching_table_data_diff[$p], $matching_tables_keys, $source_columns, $add_column_array, $criteria, $target_tables_keys,
667 $uncommon_tables, $uncommon_tables_fields, $uncommon_cols, $alter_str_array, $source_indexes, $target_indexes, $add_indexes_array,
668 $alter_indexes_array, $delete_array, $update_array, false);
671 * Updating the session variables to the latest values of the arrays.
673 $_SESSION['delete_array'] = $delete_array;
674 $_SESSION['uncommon_columns'] = $uncommon_columns;
675 $_SESSION['alter_str_array'] = $alter_str_array;
676 $_SESSION['add_column_array'] = $add_column_array;
677 $_SESSION['add_indexes_array'] = $add_indexes_array;
678 $_SESSION['remove_indexes_array'] = $remove_indexes_array;
679 $_SESSION['insert_array'] = $insert_array;
680 $_SESSION['update_array'] = $update_array;
683 * Applying structure difference to selected non-matching tables (present in Source but absent from Target).
685 for($s = 0; $s < sizeof($uncommon_table_structure_diff); $s++)
687 PMA_createTargetTables($src_db, $trg_db, $src_link, $trg_link, $uncommon_tables, $uncommon_table_structure_diff[$s], $uncommon_tables_fields, false);
688 $_SESSION['uncommon_tables_fields'] = $uncommon_tables_fields;
690 unset($uncommon_tables[$uncommon_table_structure_diff[$s]]);
693 * Applying data difference to selected non-matching tables (present in Source but absent from Target).
694 * Before data synchronization, structure synchronization is confirmed.
696 for($r = 0; $r < sizeof($uncommon_table_data_diff); $r++)
698 if (!(in_array($uncommon_table_data_diff[$r], $uncommon_table_structure_diff))) {
699 if (isset($uncommon_tables[$uncommon_table_data_diff[$r]])) {
701 PMA_createTargetTables($src_db, $trg_db, $src_link, $trg_link, $uncommon_tables, $uncommon_table_data_diff[$r], $uncommon_tables_fields, false);
702 $_SESSION['uncommon_tables_fields'] = $uncommon_tables_fields;
704 unset($uncommon_tables[$uncommon_table_data_diff[$r]]);
707 PMA_populateTargetTables($src_db, $trg_db, $src_link, $trg_link, $source_tables_uncommon, $uncommon_table_data_diff[$r],
708 $_SESSION['uncommon_tables_fields'], false);
710 unset($row_count[$uncommon_table_data_diff[$r]]);
713 * Again all the tables from source and target database are displayed with their differences.
714 * The differences have been removed from tables that have been synchronized
716 echo '<form name="applied_difference" id="synchronize_form" method="post" action="server_synchronize.php">'
717 . PMA_generate_common_hidden_inputs('', '');
719 PMA_syncDisplayHeaderSource($src_db);
720 $odd_row = false;
721 for($i = 0; $i < count($matching_tables); $i++) {
722 $odd_row = PMA_syncDisplayBeginTableRow($odd_row);
723 echo '<td align="center">' . $matching_tables[$i] . '</td>
724 <td align="center">';
726 $num_alter_cols = 0;
727 $num_insert_cols = 0;
728 $num_remove_cols = 0;
729 $num_add_index = 0;
730 $num_remove_index = 0;
732 if (isset($alter_str_array[$i])) {
733 $num_alter_cols = sizeof($alter_str_array[$i]);
735 if (isset($add_column_array[$i])) {
736 $num_insert_cols = sizeof($add_column_array[$i]);
738 if (isset($uncommon_columns[$i])) {
739 $num_remove_cols = sizeof($uncommon_columns[$i]);
741 if (isset($add_indexes_array[$i])) {
742 $num_add_index = sizeof($add_indexes_array[$i]);
744 if (isset($remove_indexes_array[$i])) {
745 $num_remove_index = sizeof($remove_indexes_array[$i]);
748 if (($num_alter_cols > 0) || ($num_insert_cols > 0) || ($num_remove_cols > 0) || ($num_add_index > 0) || ($num_remove_index > 0)) {
749 echo '<img class="icon" src="' . $pmaThemeImage . 'new_struct.jpg" width="29" height="29"
750 alt="' . $GLOBALS['strClickToSelect'] . '" onmouseover="change_Image(this);" onmouseout="change_Image(this);"
751 onclick="showDetails(' . "'MS" . $i . "','" . $num_alter_cols . "','" . $num_insert_cols . "','" . $num_remove_cols . "','" . $num_add_index . "','" . $num_remove_index . "'" .',
752 this ,' . "'" . $matching_tables[$i] . "'" . ')"/>';
754 if (!(in_array($i, $matching_table_data_diff))) {
756 if (isset($matching_tables_keys[$i][0]) && isset($update_array[$i][0][$matching_tables_keys[$i][0]])) {
757 if (isset($update_array[$i])) {
758 $num_of_updates = sizeof($update_array[$i]);
759 } else {
760 $num_of_updates = 0;
762 } else {
763 $num_of_updates = 0;
765 if (isset($matching_tables_keys[$i][0]) && isset($insert_array[$i][0][$matching_tables_keys[$i][0]])) {
766 if (isset($insert_array[$i])) {
767 $num_of_insertions = sizeof($insert_array[$i]);
768 } else {
769 $num_of_insertions = 0;
771 } else {
772 $num_of_insertions = 0;
775 if ((isset($matching_tables_keys[$i][0]) && isset($update_array[$i][0][$matching_tables_keys[$i][0]]))
776 || (isset($matching_tables_keys[$i][0]) && isset($insert_array[$i][0][$matching_tables_keys[$i][0]]))) {
777 echo '<img class="icon" src="' . $pmaThemeImage . 'new_data.jpg" width="29" height="29"
778 alt="' . $GLOBALS['strClickToSelect'] . '" onmouseover="change_Image(this);" onmouseout="change_Image(this);"
779 onclick="showDetails(' . "'MD" . $i . "','" . $num_of_updates . "','" . $num_of_insertions .
780 "','" . null . "','" . null . "','" . null . "'" .', this ,' . "'" . htmlspecialchars($matching_tables[$i]) . "'" . ')" />';
782 } else {
783 unset($update_array[$i]);
784 unset($insert_array[$i]);
786 echo '</td>
787 </tr>';
790 * placing updated value of arrays in session
793 $_SESSION['update_array'] = $update_array;
794 $_SESSION['insert_array'] = $insert_array;
796 for ($j = 0; $j < count($source_tables_uncommon); $j++) {
797 $odd_row = PMA_syncDisplayBeginTableRow($odd_row);
798 echo '<td align="center"> + ' . htmlspecialchars($source_tables_uncommon[$j]) . '</td>
799 <td align="center">';
801 * Display the difference only when it has not been applied
803 if (!(in_array($j, $uncommon_table_structure_diff))) {
804 if (isset($uncommon_tables[$j])) {
805 echo '<img class="icon" src="' . $pmaThemeImage . 'new_struct.jpg" width="29" height="29"
806 alt="' . $GLOBALS['strClickToSelect'] . '" onmouseover="change_Image(this);" onmouseout="change_Image(this);"
807 onclick="showDetails(' . "'US" . $j . "','" . null . "','" . null . "','" . null . "','" . null . "','" . null . "'" . ', this ,' . "'" . htmlspecialchars($source_tables_uncommon[$j]) . "'" . ')"/>' .' ';
809 } else {
810 unset($uncommon_tables[$j]);
813 * Display the difference only when it has not been applied
815 if (!(in_array($j, $uncommon_table_data_diff))) {
816 if (isset($row_count[$j]) && ($row_count > 0)) {
817 echo '<img class="icon" src="' . $pmaThemeImage . 'new_data.jpg" width="29" height="29"
818 alt="' . $GLOBALS['strClickToSelect'] . '" onmouseover="change_Image(this);" onmouseout="change_Image(this);"
819 onclick="showDetails(' . "'UD" . $j . "','" . null ."','" . $row_count[$j] ."','"
820 . null . "','" . null . "','" . null . "'" . ', this ,' . "'". htmlspecialchars($source_tables_uncommon[$j]) . "'" . ')" />';
822 } else {
823 unset($row_count[$j]);
826 echo '</td>
827 </tr>';
830 * placing the latest values of arrays in session
833 $_SESSION['uncommon_tables'] = $uncommon_tables;
834 $_SESSION['uncommon_tables_row_count'] = $row_count;
838 * Displaying the target database tables
840 foreach ($target_tables_uncommon as $tbl_nc_name) {
841 $odd_row = PMA_syncDisplayBeginTableRow($odd_row);
842 echo '<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </td><td></td>';
843 echo '</tr>';
845 echo '</table>';
846 $odd_row = PMA_syncDisplayHeaderTargetAndMatchingTables($trg_db, $matching_tables);
847 foreach ($source_tables_uncommon as $tbl_nc_name) {
848 $odd_row = PMA_syncDisplayBeginTableRow($odd_row);
849 if (in_array($tbl_nc_name, $uncommon_tables)) {
850 echo '<td>' . htmlspecialchars($tbl_nc_name) . ' (' . $GLOBALS['strNotPresent'] . ')</td>';
851 } else {
852 echo '<td>' . htmlspecialchars($tbl_nc_name) . '</td>';
854 echo '
855 </tr>';
857 foreach ($target_tables_uncommon as $tbl_nc_name) {
858 $odd_row = PMA_syncDisplayBeginTableRow($odd_row);
859 echo '<td> - ' . htmlspecialchars($tbl_nc_name) . '</td>';
860 echo '</tr>';
862 echo '</table>
863 </div>';
866 * This "list" div will contain a table and each row will depict information about structure/data diffrence in tables.
867 * Rows will be generated dynamically as soon as the colored buttons "D" or "S" are clicked.
870 echo '<div id="list" style = "overflow: auto; width: 1020px; height: 140px;
871 border-left: 1px gray solid; border-bottom: 1px gray solid;
872 padding:0px; margin: 0px">';
874 echo '<table>
875 <thead>
876 <tr style="width: 100%;">
877 <th id="table_name" style="width: 10%;" colspan="1">' . $strTable . ' </th>
878 <th id="str_diff" style="width: 65%;" colspan="6">' . $strStructureDiff . ' </th>
879 <th id="data_diff" style="width: 20%;" colspan="2">' . $strDataDiff . '</th>
880 </tr>
881 <tr style="width: 100%;">
882 <th style="width: 10%;">' . $strTableName . '</th>
883 <th style="width: 10%;">' . $strCreateTable . '</th>
884 <th style="width: 11%;">' . $strTableAddColumn . '</th>
885 <th style="width: 13%;">' . $strTableRemoveColumn . '</th>
886 <th style="width: 11%;">' . $strTableAlterColumn . '</th>
887 <th style="width: 12%;">' . $strTableRemoveIndex . '</th>
888 <th style="width: 11%;">' . $strTableApplyIndex . '</th>
889 <th style="width: 10%;">' . $strTableUpdateRow . '</th>
890 <th style="width: 10%;">' . $strTableInsertRow . '</th>
891 </tr>
892 </thead>
893 <tbody></tbody>
894 </table>
895 </div>';
898 * This fieldset displays the checkbox to confirm deletion of previous rows from target tables
900 echo '<fieldset>
901 <p><input type= "checkbox" name="delete_rows" id ="delete_rows" />' . $strTableDeleteRows . ' </p>
902 </fieldset>';
904 echo '<fieldset class="tblFooters">';
905 echo '<input type="button" name="apply_changes" value="' . $GLOBALS['strApplyChanges'] . '"
906 onclick ="ApplySelectedChanges(' . "'" . $_SESSION['token'] . "'" .')" />';
907 echo '<input type="submit" name="synchronize_db" value="' . $GLOBALS['strSynchronizeDb'] . '" />'
908 . '</fieldset>';
909 echo '</form>';
913 * Displays the page when 'Synchronize Databases' is pressed.
916 if (isset($_REQUEST['synchronize_db'])) {
918 $src_db = $_SESSION['src_db'];
919 $trg_db = $_SESSION['trg_db'];
920 $update_array = $_SESSION['update_array'];
921 $insert_array = $_SESSION['insert_array'];
922 $src_username = $_SESSION['src_username'];
923 $trg_username = $_SESSION['trg_username'];
924 $src_password = $_SESSION['src_password'];
925 $trg_password = $_SESSION['trg_password'];
926 $matching_tables = $_SESSION['matching_tables'];
927 $matching_tables_keys = $_SESSION['matching_tables_keys'];
928 $matching_tables_fields = $_SESSION['matching_fields'];
929 $source_tables_uncommon = $_SESSION['src_uncommon_tables'];
930 $uncommon_tables_fields = $_SESSION['uncommon_tables_fields'];
931 $target_tables_uncommon = $_SESSION['target_tables_uncommon'];
932 $row_count = $_SESSION['uncommon_tables_row_count'];
933 $uncommon_tables = $_SESSION['uncommon_tables'];
934 $target_tables = $_SESSION['target_tables'];
936 $delete_array = $_SESSION['delete_array'];
937 $uncommon_columns = $_SESSION['uncommon_columns'];
938 $source_columns = $_SESSION['source_columns'];
939 $alter_str_array = $_SESSION['alter_str_array'];
940 $criteria = $_SESSION['criteria'];
941 $target_tables_keys = $_SESSION['target_tables_keys'];
942 $add_column_array = $_SESSION['add_column_array'];
943 $add_indexes_array = $_SESSION['add_indexes_array'];
944 $alter_indexes_array = $_SESSION['alter_indexes_array'];
945 $remove_indexes_array = $_SESSION['remove_indexes_array'];
946 $source_indexes = $_SESSION['source_indexes'];
947 $target_indexes = $_SESSION['target_indexes'];
948 $uncommon_cols = $uncommon_columns;
951 * Display success message.
953 echo '<div class="success">' . $GLOBALS['strTargetDatabaseHasBeenSynchronized'] . '</div>';
955 * Displaying all the tables of source and target database and now no difference is there.
957 PMA_syncDisplayHeaderSource($src_db);
959 $odd_row = false;
960 for($i = 0; $i < count($matching_tables); $i++)
962 $odd_row = PMA_syncDisplayBeginTableRow($odd_row);
963 echo '<td>' . htmlspecialchars($matching_tables[$i]) . '</td>
964 <td></td>
965 </tr>';
967 for ($j = 0; $j < count($source_tables_uncommon); $j++) {
968 $odd_row = PMA_syncDisplayBeginTableRow($odd_row);
969 echo '<td> + ' . htmlspecialchars($source_tables_uncommon[$j]) . '</td> ';
970 echo '<td></td>
971 </tr>';
973 foreach ($target_tables_uncommon as $tbl_nc_name) {
974 $odd_row = PMA_syncDisplayBeginTableRow($odd_row);
975 echo '<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </td><td></td>';
976 echo '</tr>';
978 echo '</table>';
979 $odd_row = PMA_syncDisplayHeaderTargetAndMatchingTables($trg_db, $matching_tables);
980 foreach ($source_tables_uncommon as $tbl_nc_name) {
981 $odd_row = PMA_syncDisplayBeginTableRow($odd_row);
982 echo '<td>' . htmlspecialchars($tbl_nc_name) . ' </td>
983 </tr>';
985 foreach ($target_tables_uncommon as $tbl_nc_name) {
986 $odd_row = PMA_syncDisplayBeginTableRow($odd_row);
987 echo '<td> ' . htmlspecialchars($tbl_nc_name) . '</td>';
988 echo '</tr>';
990 echo '</table> </div>';
993 * connecting the source and target servers
995 if ('rmt' == $_SESSION['src_type']) {
996 $src_link = PMA_DBI_connect($src_username, $src_password, $is_controluser = false, $_SESSION['src_server']);
997 } else {
998 $src_link = $GLOBALS['userlink'];
999 // working on current server, so initialize this for tracking
1000 // (does not work if user defined current server as a remote one)
1001 $GLOBALS['db'] = $_SESSION['src_db'];
1003 if ('rmt' == $_SESSION['trg_type']) {
1004 $trg_link = PMA_DBI_connect($trg_username, $trg_password, $is_controluser = false, $_SESSION['trg_server']);
1005 } else {
1006 $trg_link = $GLOBALS['userlink'];
1007 // working on current server, so initialize this for tracking
1008 $GLOBALS['db'] = $_SESSION['trg_db'];
1012 * Displaying the queries.
1014 echo '<h5>' . $GLOBALS['strQueriesExecuted'] . '</h5>';
1015 echo '<div id="serverstatus" style = "overflow: auto; width: 1050px; height: 180px;
1016 border-left: 1px gray solid; border-bottom: 1px gray solid; padding: 0px; margin: 0px"> ';
1018 * Applying all sorts of differences for each matching table
1020 for($p = 0; $p <sizeof($matching_tables); $p++) {
1022 * If the check box is checked for deleting previous rows from the target database tables then
1023 * first find out rows to be deleted and then delete the rows.
1025 if (isset($_REQUEST['delete_rows'])) {
1026 PMA_findDeleteRowsFromTargetTables($delete_array, $matching_tables, $p, $target_tables_keys, $matching_tables_keys,
1027 $trg_db, $trg_link, $src_db, $src_link);
1029 if (isset($delete_array[$p])) {
1030 PMA_deleteFromTargetTable($trg_db, $trg_link, $matching_tables, $p, $target_tables_keys, $delete_array, true);
1031 unset($delete_array[$p]);
1034 if (isset($alter_str_array[$p])) {
1035 PMA_alterTargetTableStructure($trg_db, $trg_link, $matching_tables, $source_columns, $alter_str_array, $matching_tables_fields,
1036 $criteria, $matching_tables_keys, $target_tables_keys, $p, true);
1037 unset($alter_str_array[$p]);
1039 if (isset($add_column_array[$p])) {
1040 PMA_findDeleteRowsFromTargetTables($delete_array, $matching_tables, $p, $target_tables_keys, $matching_tables_keys,
1041 $trg_db, $trg_link, $src_db, $src_link);
1043 if (isset($delete_array[$p])) {
1044 PMA_deleteFromTargetTable($trg_db, $trg_link, $matching_tables, $p, $target_tables_keys, $delete_array, true);
1045 unset($delete_array[$p]);
1047 PMA_addColumnsInTargetTable($src_db, $trg_db, $src_link, $trg_link, $matching_tables, $source_columns, $add_column_array, $matching_tables_fields,
1048 $criteria, $matching_tables_keys, $target_tables_keys, $uncommon_tables,$uncommon_tables_fields, $p, $uncommon_cols, true);
1049 unset($add_column_array[$p]);
1051 if (isset($uncommon_columns[$p])) {
1052 PMA_removeColumnsFromTargetTable($trg_db, $trg_link, $matching_tables, $uncommon_columns, $p, true);
1053 unset($uncommon_columns[$p]);
1055 if (isset($matching_table_structure_diff) &&
1056 (isset($add_indexes_array[$matching_table_structure_diff[$p]])
1057 || isset($remove_indexes_array[$matching_table_structure_diff[$p]])
1058 || isset($alter_indexes_array[$matching_table_structure_diff[$p]]))) {
1059 PMA_applyIndexesDiff ($trg_db, $trg_link, $matching_tables, $source_indexes, $target_indexes, $add_indexes_array, $alter_indexes_array,
1060 $remove_indexes_array, $matching_table_structure_diff[$p], true);
1062 unset($add_indexes_array[$matching_table_structure_diff[$p]]);
1063 unset($alter_indexes_array[$matching_table_structure_diff[$p]]);
1064 unset($remove_indexes_array[$matching_table_structure_diff[$p]]);
1067 PMA_updateTargetTables($matching_tables, $update_array, $src_db, $trg_db, $trg_link, $p, $matching_tables_keys, true);
1069 PMA_insertIntoTargetTable($matching_tables, $src_db, $trg_db, $src_link, $trg_link , $matching_tables_fields, $insert_array,$p, $matching_tables_keys,
1070 $matching_tables_keys,$source_columns, $add_column_array, $criteria, $target_tables_keys,$uncommon_tables, $uncommon_tables_fields,$uncommon_cols,
1071 $alter_str_array,$source_indexes, $target_indexes, $add_indexes_array, $alter_indexes_array, $delete_array, $update_array, true);
1075 * Creating and populating tables present in source but absent from target database.
1077 for($q = 0; $q < sizeof($source_tables_uncommon) ;$q++) {
1078 if (isset($uncommon_tables[$q])) {
1079 PMA_createTargetTables($src_db, $trg_db, $src_link, $trg_link, $source_tables_uncommon, $q, $uncommon_tables_fields, true);
1081 if (isset($row_count[$q])) {
1082 PMA_populateTargetTables($src_db, $trg_db, $src_link, $trg_link, $source_tables_uncommon, $q, $uncommon_tables_fields, true);
1085 echo "</div>";
1089 * Displays the main page when none of the following buttons is pressed
1092 if (! isset($_REQUEST['submit_connect']) && ! isset($_REQUEST['synchronize_db']) && ! isset($_REQUEST['Table_ids']) )
1094 /**
1095 * Displays the sub-page heading
1097 echo '<h2>' . ($GLOBALS['cfg']['MainPageIconic']
1098 ? '<img class="icon" src="' . $pmaThemeImage . 's_sync.png" width="18"'
1099 . ' height="18" alt="" />'
1100 : '')
1101 . $strSynchronize
1102 .'</h2>';
1104 echo '<div id="serverstatus">
1105 <form name="connection_form" id="connection_form" method="post" action="server_synchronize.php"
1106 >' // TODO: add check if all var. are filled in
1107 . PMA_generate_common_hidden_inputs('', '');
1108 echo '<fieldset>';
1109 echo '<legend>' . $GLOBALS['strSynchronize'] . '</legend>';
1111 * Displays the forms
1114 $databases = PMA_DBI_get_databases_full(null, false, null, 'SCHEMA_NAME',
1115 'ASC', 0, true);
1117 foreach ($cons as $type) {
1118 echo '<table id="serverconnection_' . $type . '_remote" class="data">
1119 <tr>
1120 <th colspan="2">' . $GLOBALS['strDatabase_'.$type] . '</th>
1121 </tr>
1122 <tr class="odd">
1123 <td colspan="2" style="text-align: center">
1124 <select name="' . $type . '_type" id="' . $type . '_type">
1125 <option value="rmt">' . $GLOBALS['strRemoteServer'] . '</option>
1126 <option value="cur">' . $GLOBALS['strCurrentServer'] . '</option>
1127 </select>
1128 </td>
1129 </tr>
1130 <tr class="even" id="' . $type . 'tr1">
1131 <td>' . $GLOBALS['strHost'] . '</td>
1132 <td><input type="text" name="' . $type . '_host" /></td>
1133 </tr>
1134 <tr class="odd" id="' . $type . 'tr2">
1135 <td>' . $GLOBALS['strPort'] . '</td>
1136 <td><input type="text" name="' . $type . '_port" value="3306" maxlength="5" size="5" /></td>
1137 </tr>
1138 <tr class="even" id="' . $type . 'tr3">
1139 <td>' . $GLOBALS['strSocket'] . '</td>
1140 <td><input type="text" name="' . $type . '_socket" /></td>
1141 </tr>
1142 <tr class="odd" id="'.$type.'tr4">
1143 <td>' . $GLOBALS['strUserName']. '</td>
1144 <td><input type="text" name="'. $type . '_username" /></td>
1145 </tr>
1146 <tr class="even" id="' . $type . 'tr5">
1147 <td>' . $GLOBALS['strPassword'] . '</td>
1148 <td><input type="password" name="' . $type . '_pass" /> </td>
1149 </tr>
1150 <tr class="odd" id="' . $type . 'tr6">
1151 <td>' . $GLOBALS['strDatabase'] . '</td>
1152 <td><input type="text" name="' . $type . '_db" /></td>
1153 </tr>
1154 <tr class="even" id="' . $type . 'tr7" style="display: none;">
1155 <td>' . $GLOBALS['strDatabase'] . '</td>
1156 <td>';
1157 // these unset() do not complain if the elements do not exist
1158 unset($databases['mysql']);
1159 unset($databases['information_schema']);
1160 if (count($databases) == 0) {
1161 echo $GLOBALS['strNoDatabases'];
1162 } else {
1163 echo '
1164 <select name="' . $type . '_db_sel">
1166 foreach ($databases as $db) {
1167 echo ' <option>' . $db['SCHEMA_NAME'] . '</option>';
1169 echo '</select>';
1171 echo '</td> </tr>
1172 </table>';
1174 // Add JS to show/hide rows based on the selection
1175 PMA_js(''.
1176 '$(\'' . $type . '_type\').addEvent(\'change\',function() {' .
1177 ' if ($(\'' . $type . 'tr1\').getStyle(\'display\')=="none") {' .
1178 ' for (var i=1; i<7; i++)' .
1179 ' $(\'' . $type . 'tr\'+i).tween(\'display\', \'table-row\');' .
1180 ' $(\'' . $type . 'tr7\').tween(\'display\', \'none\');' .
1181 ' }' .
1182 ' else {' .
1183 ' for (var i=1; i<7; i++)'.
1184 ' $(\'' . $type . 'tr\'+i).tween(\'display\', \'none\');' .
1185 ' $(\'' . $type . 'tr7\').tween(\'display\', \'table-row\');'.
1186 ' }' .
1187 '});'
1190 unset ($types, $type);
1192 echo '
1193 </fieldset>
1194 <fieldset class="tblFooters">
1195 <input type="submit" name="submit_connect" value="' . $GLOBALS['strGo'] .'" id="buttonGo" />
1196 </fieldset>
1197 </form>
1198 </div>
1199 <div class="notice">' . $strSynchronizationNote . '</div>';
1203 * Displays the footer
1205 require_once './libraries/footer.inc.php';