3.3.7-rc1 release
[phpmyadmin/madhuracj.git] / server_synchronize.php
bloba3c32660d9b4b6bb29fdfb5faaaad3727e37084a
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 id="serverstatustraffic" class="data" width = "60%">
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" /><label for="delete_rows">' . $strTableDeleteRows . '</label> </p>
459 </fieldset>
460 <fieldset class="tblFooters">';
461 echo '<input type="button" name="apply_changes" value="' . $GLOBALS['strApplyChanges']
462 . '" onclick ="ApplySelectedChanges(' . "'" . htmlspecialchars($_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 = explode("US", $_REQUEST[$i]);
539 if (isset($table_id[1])) {
540 $uncommon_table_structure_diff[] = $table_id[1];
542 $table_id = explode("UD", $_REQUEST[$i]);
543 if (isset($table_id[1])) {
544 $uncommon_table_data_diff[] = $table_id[1];
546 $table_id = explode("MS", $_REQUEST[$i]);
547 if (isset($table_id[1])) {
548 $matching_table_structure_diff[] = $table_id[1];
551 $table_id = explode("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],
702 $uncommon_tables_fields, false);
703 $_SESSION['uncommon_tables_fields'] = $uncommon_tables_fields;
705 unset($uncommon_tables[$uncommon_table_data_diff[$r]]);
708 PMA_populateTargetTables($src_db, $trg_db, $src_link, $trg_link, $source_tables_uncommon, $uncommon_table_data_diff[$r],
709 $_SESSION['uncommon_tables_fields'], false);
711 unset($row_count[$uncommon_table_data_diff[$r]]);
714 * Again all the tables from source and target database are displayed with their differences.
715 * The differences have been removed from tables that have been synchronized
717 echo '<form name="applied_difference" id="synchronize_form" method="post" action="server_synchronize.php">'
718 . PMA_generate_common_hidden_inputs('', '');
720 PMA_syncDisplayHeaderSource($src_db);
721 $odd_row = false;
722 for($i = 0; $i < count($matching_tables); $i++) {
723 $odd_row = PMA_syncDisplayBeginTableRow($odd_row);
724 echo '<td align="center">' . htmlspecialchars($matching_tables[$i]) . '</td>
725 <td align="center">';
727 $num_alter_cols = 0;
728 $num_insert_cols = 0;
729 $num_remove_cols = 0;
730 $num_add_index = 0;
731 $num_remove_index = 0;
733 if (isset($alter_str_array[$i])) {
734 $num_alter_cols = sizeof($alter_str_array[$i]);
736 if (isset($add_column_array[$i])) {
737 $num_insert_cols = sizeof($add_column_array[$i]);
739 if (isset($uncommon_columns[$i])) {
740 $num_remove_cols = sizeof($uncommon_columns[$i]);
742 if (isset($add_indexes_array[$i])) {
743 $num_add_index = sizeof($add_indexes_array[$i]);
745 if (isset($remove_indexes_array[$i])) {
746 $num_remove_index = sizeof($remove_indexes_array[$i]);
749 if (($num_alter_cols > 0) || ($num_insert_cols > 0) || ($num_remove_cols > 0) || ($num_add_index > 0) || ($num_remove_index > 0)) {
750 echo '<img class="icon" src="' . $pmaThemeImage . 'new_struct.jpg" width="29" height="29"
751 alt="' . $GLOBALS['strClickToSelect'] . '" onmouseover="change_Image(this);" onmouseout="change_Image(this);"
752 onclick="showDetails(' . "'MS" . $i . "','" . $num_alter_cols . "','" . $num_insert_cols . "','" . $num_remove_cols . "','" . $num_add_index . "','" . $num_remove_index . "'" .',
753 this ,' . "'" . htmlspecialchars($matching_tables[$i]) . "'" . ')"/>';
755 if (!(in_array($i, $matching_table_data_diff))) {
757 if (isset($matching_tables_keys[$i][0]) && isset($update_array[$i][0][$matching_tables_keys[$i][0]])) {
758 if (isset($update_array[$i])) {
759 $num_of_updates = sizeof($update_array[$i]);
760 } else {
761 $num_of_updates = 0;
763 } else {
764 $num_of_updates = 0;
766 if (isset($matching_tables_keys[$i][0]) && isset($insert_array[$i][0][$matching_tables_keys[$i][0]])) {
767 if (isset($insert_array[$i])) {
768 $num_of_insertions = sizeof($insert_array[$i]);
769 } else {
770 $num_of_insertions = 0;
772 } else {
773 $num_of_insertions = 0;
776 if ((isset($matching_tables_keys[$i][0]) && isset($update_array[$i][0][$matching_tables_keys[$i][0]]))
777 || (isset($matching_tables_keys[$i][0]) && isset($insert_array[$i][0][$matching_tables_keys[$i][0]]))) {
778 echo '<img class="icon" src="' . $pmaThemeImage . 'new_data.jpg" width="29" height="29"
779 alt="' . $GLOBALS['strClickToSelect'] . '" onmouseover="change_Image(this);" onmouseout="change_Image(this);"
780 onclick="showDetails(' . "'MD" . $i . "','" . $num_of_updates . "','" . $num_of_insertions .
781 "','" . null . "','" . null . "','" . null . "'" .', this ,' . "'" . htmlspecialchars($matching_tables[$i]) . "'" . ')" />';
783 } else {
784 unset($update_array[$i]);
785 unset($insert_array[$i]);
787 echo '</td>
788 </tr>';
791 * placing updated value of arrays in session
794 $_SESSION['update_array'] = $update_array;
795 $_SESSION['insert_array'] = $insert_array;
797 for ($j = 0; $j < count($source_tables_uncommon); $j++) {
798 $odd_row = PMA_syncDisplayBeginTableRow($odd_row);
799 echo '<td align="center"> + ' . htmlspecialchars($source_tables_uncommon[$j]) . '</td>
800 <td align="center">';
802 * Display the difference only when it has not been applied
804 if (!(in_array($j, $uncommon_table_structure_diff))) {
805 if (isset($uncommon_tables[$j])) {
806 echo '<img class="icon" src="' . $pmaThemeImage . 'new_struct.jpg" width="29" height="29"
807 alt="' . $GLOBALS['strClickToSelect'] . '" onmouseover="change_Image(this);" onmouseout="change_Image(this);"
808 onclick="showDetails(' . "'US" . $j . "','" . null . "','" . null . "','" . null . "','" . null . "','" . null . "'" . ', this ,' . "'" . htmlspecialchars($source_tables_uncommon[$j]) . "'" . ')"/>' .' ';
810 } else {
811 unset($uncommon_tables[$j]);
814 * Display the difference only when it has not been applied
816 if (!(in_array($j, $uncommon_table_data_diff))) {
817 if (isset($row_count[$j]) && ($row_count > 0)) {
818 echo '<img class="icon" src="' . $pmaThemeImage . 'new_data.jpg" width="29" height="29"
819 alt="' . $GLOBALS['strClickToSelect'] . '" onmouseover="change_Image(this);" onmouseout="change_Image(this);"
820 onclick="showDetails(' . "'UD" . $j . "','" . null ."','" . $row_count[$j] ."','"
821 . null . "','" . null . "','" . null . "'" . ', this ,' . "'". htmlspecialchars($source_tables_uncommon[$j]) . "'" . ')" />';
823 } else {
824 unset($row_count[$j]);
827 echo '</td>
828 </tr>';
831 * placing the latest values of arrays in session
834 $_SESSION['uncommon_tables'] = $uncommon_tables;
835 $_SESSION['uncommon_tables_row_count'] = $row_count;
839 * Displaying the target database tables
841 foreach ($target_tables_uncommon as $tbl_nc_name) {
842 $odd_row = PMA_syncDisplayBeginTableRow($odd_row);
843 echo '<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </td><td></td>';
844 echo '</tr>';
846 echo '</table>';
847 $odd_row = PMA_syncDisplayHeaderTargetAndMatchingTables($trg_db, $matching_tables);
848 foreach ($source_tables_uncommon as $tbl_nc_name) {
849 $odd_row = PMA_syncDisplayBeginTableRow($odd_row);
850 if (in_array($tbl_nc_name, $uncommon_tables)) {
851 echo '<td>' . htmlspecialchars($tbl_nc_name) . ' (' . $GLOBALS['strNotPresent'] . ')</td>';
852 } else {
853 echo '<td>' . htmlspecialchars($tbl_nc_name) . '</td>';
855 echo '
856 </tr>';
858 foreach ($target_tables_uncommon as $tbl_nc_name) {
859 $odd_row = PMA_syncDisplayBeginTableRow($odd_row);
860 echo '<td> - ' . htmlspecialchars($tbl_nc_name) . '</td>';
861 echo '</tr>';
863 echo '</table>
864 </div>';
867 * This "list" div will contain a table and each row will depict information about structure/data diffrence in tables.
868 * Rows will be generated dynamically as soon as the colored buttons "D" or "S" are clicked.
871 echo '<div id="list" style = "overflow: auto; width: 1020px; height: 140px;
872 border-left: 1px gray solid; border-bottom: 1px gray solid;
873 padding:0px; margin: 0px">';
875 echo '<table>
876 <thead>
877 <tr style="width: 100%;">
878 <th id="table_name" style="width: 10%;" colspan="1">' . $strTable . ' </th>
879 <th id="str_diff" style="width: 65%;" colspan="6">' . $strStructureDiff . ' </th>
880 <th id="data_diff" style="width: 20%;" colspan="2">' . $strDataDiff . '</th>
881 </tr>
882 <tr style="width: 100%;">
883 <th style="width: 10%;">' . $strTableName . '</th>
884 <th style="width: 10%;">' . $strCreateTable . '</th>
885 <th style="width: 11%;">' . $strTableAddColumn . '</th>
886 <th style="width: 13%;">' . $strTableRemoveColumn . '</th>
887 <th style="width: 11%;">' . $strTableAlterColumn . '</th>
888 <th style="width: 12%;">' . $strTableRemoveIndex . '</th>
889 <th style="width: 11%;">' . $strTableApplyIndex . '</th>
890 <th style="width: 10%;">' . $strTableUpdateRow . '</th>
891 <th style="width: 10%;">' . $strTableInsertRow . '</th>
892 </tr>
893 </thead>
894 <tbody></tbody>
895 </table>
896 </div>';
899 * This fieldset displays the checkbox to confirm deletion of previous rows from target tables
901 echo '<fieldset>
902 <p><input type="checkbox" name="delete_rows" id ="delete_rows" /><label for="delete_rows">' . $strTableDeleteRows . '</label> </p>
903 </fieldset>';
905 echo '<fieldset class="tblFooters">';
906 echo '<input type="button" name="apply_changes" value="' . $GLOBALS['strApplyChanges'] . '"
907 onclick ="ApplySelectedChanges(' . "'" . htmlspecialchars($_SESSION['token']) . "'" .')" />';
908 echo '<input type="submit" name="synchronize_db" value="' . $GLOBALS['strSynchronizeDb'] . '" />'
909 . '</fieldset>';
910 echo '</form>';
914 * Displays the page when 'Synchronize Databases' is pressed.
917 if (isset($_REQUEST['synchronize_db'])) {
919 $src_db = $_SESSION['src_db'];
920 $trg_db = $_SESSION['trg_db'];
921 $update_array = $_SESSION['update_array'];
922 $insert_array = $_SESSION['insert_array'];
923 $src_username = $_SESSION['src_username'];
924 $trg_username = $_SESSION['trg_username'];
925 $src_password = $_SESSION['src_password'];
926 $trg_password = $_SESSION['trg_password'];
927 $matching_tables = $_SESSION['matching_tables'];
928 $matching_tables_keys = $_SESSION['matching_tables_keys'];
929 $matching_tables_fields = $_SESSION['matching_fields'];
930 $source_tables_uncommon = $_SESSION['src_uncommon_tables'];
931 $uncommon_tables_fields = $_SESSION['uncommon_tables_fields'];
932 $target_tables_uncommon = $_SESSION['target_tables_uncommon'];
933 $row_count = $_SESSION['uncommon_tables_row_count'];
934 $uncommon_tables = $_SESSION['uncommon_tables'];
935 $target_tables = $_SESSION['target_tables'];
937 $delete_array = $_SESSION['delete_array'];
938 $uncommon_columns = $_SESSION['uncommon_columns'];
939 $source_columns = $_SESSION['source_columns'];
940 $alter_str_array = $_SESSION['alter_str_array'];
941 $criteria = $_SESSION['criteria'];
942 $target_tables_keys = $_SESSION['target_tables_keys'];
943 $add_column_array = $_SESSION['add_column_array'];
944 $add_indexes_array = $_SESSION['add_indexes_array'];
945 $alter_indexes_array = $_SESSION['alter_indexes_array'];
946 $remove_indexes_array = $_SESSION['remove_indexes_array'];
947 $source_indexes = $_SESSION['source_indexes'];
948 $target_indexes = $_SESSION['target_indexes'];
949 $uncommon_cols = $uncommon_columns;
952 * Display success message.
954 echo '<div class="success">' . $GLOBALS['strTargetDatabaseHasBeenSynchronized'] . '</div>';
956 * Displaying all the tables of source and target database and now no difference is there.
958 PMA_syncDisplayHeaderSource($src_db);
960 $odd_row = false;
961 for($i = 0; $i < count($matching_tables); $i++)
963 $odd_row = PMA_syncDisplayBeginTableRow($odd_row);
964 echo '<td>' . htmlspecialchars($matching_tables[$i]) . '</td>
965 <td></td>
966 </tr>';
968 for ($j = 0; $j < count($source_tables_uncommon); $j++) {
969 $odd_row = PMA_syncDisplayBeginTableRow($odd_row);
970 echo '<td> + ' . htmlspecialchars($source_tables_uncommon[$j]) . '</td> ';
971 echo '<td></td>
972 </tr>';
974 foreach ($target_tables_uncommon as $tbl_nc_name) {
975 $odd_row = PMA_syncDisplayBeginTableRow($odd_row);
976 echo '<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </td><td></td>';
977 echo '</tr>';
979 echo '</table>';
980 $odd_row = PMA_syncDisplayHeaderTargetAndMatchingTables($trg_db, $matching_tables);
981 foreach ($source_tables_uncommon as $tbl_nc_name) {
982 $odd_row = PMA_syncDisplayBeginTableRow($odd_row);
983 echo '<td>' . htmlspecialchars($tbl_nc_name) . ' </td>
984 </tr>';
986 foreach ($target_tables_uncommon as $tbl_nc_name) {
987 $odd_row = PMA_syncDisplayBeginTableRow($odd_row);
988 echo '<td> ' . htmlspecialchars($tbl_nc_name) . '</td>';
989 echo '</tr>';
991 echo '</table> </div>';
994 * connecting the source and target servers
996 if ('rmt' == $_SESSION['src_type']) {
997 $src_link = PMA_DBI_connect($src_username, $src_password, $is_controluser = false, $_SESSION['src_server']);
998 } else {
999 $src_link = $GLOBALS['userlink'];
1000 // working on current server, so initialize this for tracking
1001 // (does not work if user defined current server as a remote one)
1002 $GLOBALS['db'] = $_SESSION['src_db'];
1004 if ('rmt' == $_SESSION['trg_type']) {
1005 $trg_link = PMA_DBI_connect($trg_username, $trg_password, $is_controluser = false, $_SESSION['trg_server']);
1006 } else {
1007 $trg_link = $GLOBALS['userlink'];
1008 // working on current server, so initialize this for tracking
1009 $GLOBALS['db'] = $_SESSION['trg_db'];
1013 * Displaying the queries.
1015 echo '<h5>' . $GLOBALS['strQueriesExecuted'] . '</h5>';
1016 echo '<div id="serverstatus" style = "overflow: auto; width: 1050px; height: 180px;
1017 border-left: 1px gray solid; border-bottom: 1px gray solid; padding: 0px; margin: 0px"> ';
1019 * Applying all sorts of differences for each matching table
1021 for($p = 0; $p < sizeof($matching_tables); $p++) {
1023 * If the check box is checked for deleting previous rows from the target database tables then
1024 * first find out rows to be deleted and then delete the rows.
1026 if (isset($_REQUEST['delete_rows'])) {
1027 PMA_findDeleteRowsFromTargetTables($delete_array, $matching_tables, $p, $target_tables_keys, $matching_tables_keys,
1028 $trg_db, $trg_link, $src_db, $src_link);
1030 if (isset($delete_array[$p])) {
1031 PMA_deleteFromTargetTable($trg_db, $trg_link, $matching_tables, $p, $target_tables_keys, $delete_array, true);
1032 unset($delete_array[$p]);
1035 if (isset($alter_str_array[$p])) {
1036 PMA_alterTargetTableStructure($trg_db, $trg_link, $matching_tables, $source_columns, $alter_str_array, $matching_tables_fields,
1037 $criteria, $matching_tables_keys, $target_tables_keys, $p, true);
1038 unset($alter_str_array[$p]);
1040 if (! empty($add_column_array[$p])) {
1041 PMA_findDeleteRowsFromTargetTables($delete_array, $matching_tables, $p, $target_tables_keys, $matching_tables_keys,
1042 $trg_db, $trg_link, $src_db, $src_link);
1044 if (isset($delete_array[$p])) {
1045 PMA_deleteFromTargetTable($trg_db, $trg_link, $matching_tables, $p, $target_tables_keys, $delete_array, true);
1046 unset($delete_array[$p]);
1048 PMA_addColumnsInTargetTable($src_db, $trg_db, $src_link, $trg_link, $matching_tables, $source_columns, $add_column_array,
1049 $matching_tables_fields, $criteria, $matching_tables_keys, $target_tables_keys, $uncommon_tables, $uncommon_tables_fields,
1050 $p, $uncommon_cols, true);
1051 unset($add_column_array[$p]);
1053 if (isset($uncommon_columns[$p])) {
1054 PMA_removeColumnsFromTargetTable($trg_db, $trg_link, $matching_tables, $uncommon_columns, $p, true);
1055 unset($uncommon_columns[$p]);
1057 if (isset($matching_table_structure_diff) &&
1058 (isset($add_indexes_array[$matching_table_structure_diff[$p]])
1059 || isset($remove_indexes_array[$matching_table_structure_diff[$p]])
1060 || isset($alter_indexes_array[$matching_table_structure_diff[$p]]))) {
1061 PMA_applyIndexesDiff ($trg_db, $trg_link, $matching_tables, $source_indexes, $target_indexes, $add_indexes_array, $alter_indexes_array,
1062 $remove_indexes_array, $matching_table_structure_diff[$p], true);
1064 unset($add_indexes_array[$matching_table_structure_diff[$p]]);
1065 unset($alter_indexes_array[$matching_table_structure_diff[$p]]);
1066 unset($remove_indexes_array[$matching_table_structure_diff[$p]]);
1069 PMA_updateTargetTables($matching_tables, $update_array, $src_db, $trg_db, $trg_link, $p, $matching_tables_keys, true);
1071 PMA_insertIntoTargetTable($matching_tables, $src_db, $trg_db, $src_link, $trg_link , $matching_tables_fields, $insert_array, $p,
1072 $matching_tables_keys, $matching_tables_keys, $source_columns, $add_column_array, $criteria, $target_tables_keys, $uncommon_tables,
1073 $uncommon_tables_fields,$uncommon_cols, $alter_str_array,$source_indexes, $target_indexes, $add_indexes_array,
1074 $alter_indexes_array, $delete_array, $update_array, true);
1078 * Creating and populating tables present in source but absent from target database.
1080 for($q = 0; $q < sizeof($source_tables_uncommon); $q++) {
1081 if (isset($uncommon_tables[$q])) {
1082 PMA_createTargetTables($src_db, $trg_db, $src_link, $trg_link, $source_tables_uncommon, $q, $uncommon_tables_fields, true);
1084 if (isset($row_count[$q])) {
1085 PMA_populateTargetTables($src_db, $trg_db, $src_link, $trg_link, $source_tables_uncommon, $q, $uncommon_tables_fields, true);
1088 echo "</div>";
1092 * Displays the main page when none of the following buttons is pressed
1095 if (! isset($_REQUEST['submit_connect']) && ! isset($_REQUEST['synchronize_db']) && ! isset($_REQUEST['Table_ids']) )
1097 /**
1098 * Displays the sub-page heading
1100 echo '<h2>' . ($GLOBALS['cfg']['MainPageIconic']
1101 ? '<img class="icon" src="' . $pmaThemeImage . 's_sync.png" width="18"'
1102 . ' height="18" alt="" />'
1103 : '')
1104 . $strSynchronize
1105 .'</h2>';
1107 echo '<div id="serverstatus">
1108 <form name="connection_form" id="connection_form" method="post" action="server_synchronize.php"
1109 >' // TODO: add check if all var. are filled in
1110 . PMA_generate_common_hidden_inputs('', '');
1111 echo '<fieldset>';
1112 echo '<legend>' . $GLOBALS['strSynchronize'] . '</legend>';
1114 * Displays the forms
1117 $databases = PMA_DBI_get_databases_full(null, false, null, 'SCHEMA_NAME',
1118 'ASC', 0, true);
1120 foreach ($cons as $type) {
1121 echo '<table id="serverconnection_' . $type . '_remote" class="data">
1122 <tr>
1123 <th colspan="2">' . $GLOBALS['strDatabase_'.$type] . '</th>
1124 </tr>
1125 <tr class="odd">
1126 <td colspan="2" style="text-align: center">
1127 <select name="' . $type . '_type" id="' . $type . '_type">
1128 <option value="rmt">' . $GLOBALS['strRemoteServer'] . '</option>
1129 <option value="cur">' . $GLOBALS['strCurrentServer'] . '</option>
1130 </select>
1131 </td>
1132 </tr>
1133 <tr class="even" id="' . $type . 'tr1">
1134 <td>' . $GLOBALS['strHost'] . '</td>
1135 <td><input type="text" name="' . $type . '_host" /></td>
1136 </tr>
1137 <tr class="odd" id="' . $type . 'tr2">
1138 <td>' . $GLOBALS['strPort'] . '</td>
1139 <td><input type="text" name="' . $type . '_port" value="3306" maxlength="5" size="5" /></td>
1140 </tr>
1141 <tr class="even" id="' . $type . 'tr3">
1142 <td>' . $GLOBALS['strSocket'] . '</td>
1143 <td><input type="text" name="' . $type . '_socket" /></td>
1144 </tr>
1145 <tr class="odd" id="'.$type.'tr4">
1146 <td>' . $GLOBALS['strUserName']. '</td>
1147 <td><input type="text" name="'. $type . '_username" /></td>
1148 </tr>
1149 <tr class="even" id="' . $type . 'tr5">
1150 <td>' . $GLOBALS['strPassword'] . '</td>
1151 <td><input type="password" name="' . $type . '_pass" /> </td>
1152 </tr>
1153 <tr class="odd" id="' . $type . 'tr6">
1154 <td>' . $GLOBALS['strDatabase'] . '</td>
1155 <td><input type="text" name="' . $type . '_db" /></td>
1156 </tr>
1157 <tr class="even" id="' . $type . 'tr7" style="display: none;">
1158 <td>' . $GLOBALS['strDatabase'] . '</td>
1159 <td>';
1160 // these unset() do not complain if the elements do not exist
1161 unset($databases['mysql']);
1162 unset($databases['information_schema']);
1164 if (count($databases) == 0) {
1165 echo $GLOBALS['strNoDatabases'];
1166 } else {
1167 echo '
1168 <select name="' . $type . '_db_sel">
1170 foreach ($databases as $db) {
1171 echo ' <option>' . htmlspecialchars($db['SCHEMA_NAME']) . '</option>';
1173 echo '</select>';
1175 echo '</td> </tr>
1176 </table>';
1178 // Add JS to show/hide rows based on the selection
1179 PMA_js(''.
1180 '$(\'' . $type . '_type\').addEvent(\'change\',function() {' .
1181 ' if ($(\'' . $type . 'tr1\').getStyle(\'display\')=="none") {' .
1182 ' for (var i=1; i<7; i++)' .
1183 ' $(\'' . $type . 'tr\'+i).tween(\'display\', \'table-row\');' .
1184 ' $(\'' . $type . 'tr7\').tween(\'display\', \'none\');' .
1185 ' }' .
1186 ' else {' .
1187 ' for (var i=1; i<7; i++)'.
1188 ' $(\'' . $type . 'tr\'+i).tween(\'display\', \'none\');' .
1189 ' $(\'' . $type . 'tr7\').tween(\'display\', \'table-row\');'.
1190 ' }' .
1191 '});'
1194 unset ($types, $type);
1196 echo '
1197 </fieldset>
1198 <fieldset class="tblFooters">
1199 <input type="submit" name="submit_connect" value="' . $GLOBALS['strGo'] .'" id="buttonGo" />
1200 </fieldset>
1201 </form>
1202 </div>
1203 <div class="notice">' . $strSynchronizationNote . '</div>';
1207 * Displays the footer
1209 require_once './libraries/footer.inc.php';