3 /* vim: set expandtab sw=4 ts=4 sts=4: */
13 require_once './libraries/common.inc.php';
16 * Does the common work
18 $GLOBALS['js_include'][] = 'functions.js';
19 $GLOBALS['js_include'][] = 'mootools.js';
20 require_once './libraries/server_common.inc.php';
23 * Contains all the functions specific to synchronization
25 require './libraries/server_synchronize.lib.php';
30 require './libraries/server_links.inc.php';
33 * Enables warnings on the page
35 //$cfg['Error_Handler']['display'] = true;
36 //$cfg['Error_Handler']['gather'] = true;
39 * Save the value of token generated for this page
41 if (isset($_REQUEST['token'])) {
42 $_SESSION['token'] = $_REQUEST['token'];
45 // variable for code saving
46 $cons = array ("src", "trg");
49 * Displays the page when 'Go' is pressed
52 if ((isset($_REQUEST['submit_connect']))) {
53 foreach ($cons as $con) {
54 $
{"{$con}_host"} = $_REQUEST[$con.'_host'];
55 $
{"{$con}_username"} = $_REQUEST[$con.'_username'];
56 $
{"{$con}_password"} = $_REQUEST[$con.'_pass'];
57 $
{"{$con}_port"} = $_REQUEST[$con.'_port'];
58 $
{"{$con}_socket"} = $_REQUEST[$con.'_socket'];
59 $
{"{$con}_db"} = $_REQUEST[$con.'_db'];
60 $
{"{$con}_type"} = $_REQUEST[$con.'_type'];
63 if ($
{"{$con}_type"}=='cur') {
64 $
{"{$con}_connection"} = null;
65 $
{"{$con}_db"} = $_REQUEST[$con.'_db_sel'];
69 if (isset($
{"{$con}_socket"}) && !empty($
{"{$con}_socket"})) {
70 $
{"{$con}_url"} = ':'.$
{"{$con}_socket"};
71 $
{"{$con}_server"}['socket'] = $
{"{$con}_socket"};
73 $
{"{$con}_url"} = $
{"{$con}_host"};
74 $
{"{$con}_server"}['host'] = $
{"{$con}_host"};
75 if (isset($
{"{$con}_port"}) && !empty($
{"{$con}_port"}) && ((int)$
{"{$con}_port"}*1)>0) {
76 $
{"{$con}_url"} .= ':' . $
{"{$con}_port"};
77 $
{"{$con}_server"}['port'] = $
{"{$con}_port"};
81 $
{"{$con}_connection"} = @mysql_connect
($
{"{$con}_url"}, $
{"{$con}_username"}, $
{"{$con}_password"});
84 if ((!$src_connection && $src_type=='rmt') ||
(!$trg_connection && $trg_type=='rmt')) {
86 * Displays the connection error string if
87 * connections are not established
90 echo '<div class="error">' . "\n" ;
91 if(!$src_connection) {
92 echo $GLOBALS['strCouldNotConnectSource'].'<br />';
95 echo $GLOBALS['strCouldNotConnectTarget'];
98 unset($_REQUEST['submit_connect']);
102 * Creating the link object for both source and target databases and
103 * selecting the source and target databases using these links
105 foreach ($cons as $con) {
106 if ($
{"{$con}_connection"}!=null)
107 $
{"{$con}_link"} = PMA_DBI_connect($
{"{$con}_username"}, $
{"{$con}_password"}, $is_controluser = false, $
{"{$con}_server"});
109 $
{"{$con}_link"} = null;
110 $
{"{$con}_db_selected"} = PMA_DBI_select_db($
{"{$con}_db"}, $
{"{$con}_link"});
113 if (($src_db_selected != 1) ||
($trg_db_selected != 1)) {
115 * Displays error string if the database(s) did not exist
117 echo '<div class="error">' . "\n" ;
118 if ($src_db_selected != 1) {
119 echo sprintf($GLOBALS['strDatabaseNotExisting'], $src_db);
121 if ($trg_db_selected != 1) {
122 echo sprintf($GLOBALS['strDatabaseNotExisting'], $trg_db);
125 unset($_REQUEST['submit_connect']);
127 } else if (($src_db_selected == 1) && ($trg_db_selected == 1)) {
130 * Using PMA_DBI_get_tables() to get all the tables
131 * from target and source databases.
133 $src_tables = PMA_DBI_get_tables($src_db, $src_link);
134 $source_tables_num = sizeof($src_tables);
136 $trg_tables = PMA_DBI_get_tables($trg_db, $trg_link);
137 $target_tables_num = sizeof($trg_tables);
140 * initializing arrays to save matching and non-matching
141 * table names from target and source databases.
143 $unmatched_num_src = 0;
144 $source_tables_uncommon = array();
145 $unmatched_num_trg = 0;
146 $target_tables_uncommon = array();
147 $matching_tables = array();
148 $matching_tables_num = 0;
151 * Using PMA_getMatchingTables to find which of the tables' names match
152 * in target and source database.
154 PMA_getMatchingTables($trg_tables, $src_tables, $matching_tables, $source_tables_uncommon);
156 * Finding the uncommon tables for the target database
157 * using function PMA_getNonMatchingTargetTables()
159 PMA_getNonMatchingTargetTables($trg_tables, $matching_tables, $target_tables_uncommon);
162 * Initializing several arrays to save the data and structure
163 * difference between the source and target databases.
165 $row_count = array(); //number of rows in source table that needs to be created in target database
166 $fields_num = array(); //number of fields in each matching table
167 $delete_array = array(); //stores the primary key values for target tables that have excessive rows than corresponding source tables.
168 $insert_array = array(array(array()));// stores the primary key values for the rows in each source table that are not present in target tables.
169 $update_array = array(array(array())); //stores the primary key values, name of field to be updated, value of the field to be updated for
170 // each row of matching table.
171 $matching_tables_fields = array(); //contains the fields' names for each matching table
172 $matching_tables_keys = array(); //contains the primary keys' names for each matching table
173 $uncommon_tables_fields = array(); //coantains the fields for all the source tables that are not present in target
174 $matching_tables_num = sizeof($matching_tables);
176 $source_columns = array(); //contains the full columns' information for all the source tables' columns
177 $target_columns = array(); //contains the full columns' information for all the target tables' columns
178 $uncommon_columns = array(); //contains names of columns present in source table but absent from the corresponding target table
179 $source_indexes = array(); //contains indexes on all the source tables
180 $target_indexes = array(); //contains indexes on all the target tables
181 $add_indexes_array = array(); //contains the indexes name present in source but absent from target tables
182 $target_tables_keys = array(); //contains the keys of all the target tables
183 $alter_indexes_array = array(); //contains the names of all the indexes for each table that need to be altered in target database
184 $remove_indexes_array = array(); //contains the names of indexes that are excessive in target tables
185 $alter_str_array = array(array()); //contains the criteria for each column that needs to be altered in target tables
186 $add_column_array = array(array()); //contains the name of columns that need to be added in target tables
188 * The criteria array contains all the criteria against which columns are compared for differences.
190 $criteria = array('Field', 'Type', 'Null', 'Collation', 'Key', 'Default', 'Comment');
192 for($i=0; $i< sizeof($matching_tables); $i++
)
195 * Finding out all the differences structure, data and index diff for all the matching tables only
197 PMA_dataDiffInTables($src_db, $trg_db, $src_link, $trg_link, $matching_tables, $matching_tables_fields, $update_array, $insert_array,
198 $delete_array, $fields_num, $i, $matching_tables_keys);
200 PMA_structureDiffInTables($src_db, $trg_db, $src_link, $trg_link, $matching_tables, $source_columns,
201 $target_columns, $alter_str_array, $add_column_array, $uncommon_columns, $criteria, $target_tables_keys, $i);
203 PMA_indexesDiffInTables($src_db, $trg_db, $src_link, $trg_link, $matching_tables, $source_indexes, $target_indexes,
204 $add_indexes_array, $alter_indexes_array,$remove_indexes_array, $i);
207 for($j=0; $j< sizeof($source_tables_uncommon); $j++
)
210 * Finding out the number of rows to be added in tables that need to be added in target database
212 PMA_dataDiffInUncommonTables($source_tables_uncommon, $src_db, $src_link, $j, $row_count);
215 * Storing all arrays in session for use when page is reloaded for each button press
217 $_SESSION['matching_tables'] = $matching_tables;
218 $_SESSION['update_array'] = $update_array;
219 $_SESSION['insert_array'] = $insert_array;
220 $_SESSION['src_db'] = $src_db;
221 $_SESSION['trg_db'] = $trg_db;
222 $_SESSION['matching_fields'] = $matching_tables_fields;
223 $_SESSION['src_uncommon_tables'] = $source_tables_uncommon;
224 $_SESSION['src_username'] = $src_username ;
225 $_SESSION['trg_username'] = $trg_username;
226 $_SESSION['src_password'] = $src_password;
227 $_SESSION['trg_password'] = $trg_password;
228 $_SESSION['trg_password'] = $trg_password;
229 $_SESSION['src_server'] = $src_server;
230 $_SESSION['trg_server'] = $trg_server;
231 $_SESSION['src_type'] = $src_type;
232 $_SESSION['trg_type'] = $trg_type;
233 $_SESSION['matching_tables_keys'] = $matching_tables_keys;
234 $_SESSION['uncommon_tables_fields'] = $uncommon_tables_fields;
235 $_SESSION['uncommon_tables_row_count'] = $row_count;
236 $_SESSION['target_tables_uncommon'] = $target_tables_uncommon;
237 $_SESSION['uncommon_tables'] = $source_tables_uncommon;
238 $_SESSION['delete_array'] = $delete_array;
239 $_SESSION['uncommon_columns'] = $uncommon_columns;
240 $_SESSION['source_columns'] = $source_columns;
241 $_SESSION['alter_str_array'] = $alter_str_array;
242 $_SESSION['target_tables_keys'] = $target_tables_keys;
243 $_SESSION['add_column_array'] = $add_column_array;
244 $_SESSION['criteria'] = $criteria;
245 $_SESSION['target_tables'] = $trg_tables;
246 $_SESSION['add_indexes_array'] = $add_indexes_array;
247 $_SESSION['alter_indexes_array'] = $alter_indexes_array;
248 $_SESSION['remove_indexes_array'] = $remove_indexes_array;
249 $_SESSION['source_indexes'] = $source_indexes;
250 $_SESSION['target_indexes'] = $target_indexes;
253 * Displays the sub-heading and icons showing Structure Synchronization and Data Synchronization
255 echo '<form name="synchronize_form" id="synchronize_form" method="POST" action="server_synchronize.php">'
256 . PMA_generate_common_hidden_inputs('', '');
257 echo '<table id="serverstatustraffic" class="data" width = "50%">
260 . ($GLOBALS['cfg']['MainPageIconic']
261 ?
'<img class="icon" src="' . $pmaThemeImage . 'new_struct.jpg" width="32"'
262 . ' height="32" alt="" />' . "\n"
264 . $strStructureSyn . "\n"
265 .'</h2>' . "\n" .'</td>';
266 echo '<td> <h2>' . "\n"
267 . ($GLOBALS['cfg']['MainPageIconic']
268 ?
'<img class="icon" src="' . $pmaThemeImage . 'new_data.jpg" width="32"'
269 . ' height="32" alt="" />' . "\n"
272 . '</h2>' . "\n" .'</td>';
277 * Displays the tables containing the source tables names, their difference with the target tables and target tables names
279 echo '<div id="serverstatus" style = "overflow: auto; width: 1020px; height: 220px;
280 border-left: 1px gray solid; border-bottom: 1px gray solid;
281 padding:0px; margin-bottom: 1em "> ';
283 echo '<table id="serverstatustraffic" class="data" width = "55%" >
285 <th> Source Database: '. $src_db .'</th>
286 <th> Difference </th>
290 * Display the matching tables' names and difference, first
292 for($i = 0; $i < count($matching_tables); $i++
)
295 $num_of_insertions = 0;
297 * Calculating the number of updates for each matching table
299 if (isset($update_array[$i])) {
300 if (isset($update_array[$i][0][$matching_tables_keys[$i][0]])) {
301 if (isset($update_array[$i])) {
302 $num_of_updates = sizeof($update_array[$i]);
311 * Calculating the number of insertions for each matching table
313 if (isset($insert_array[$i])) {
314 if (isset($insert_array[$i][0][$matching_tables_keys[$i][0]])) {
315 if (isset($insert_array[$i])) {
316 $num_of_insertions = sizeof($insert_array[$i]);
318 $num_of_insertions = 0;
321 $num_of_insertions = 0;
325 * Displays the name of the matching table
327 $odd_row = !$odd_row;
328 echo '<tr height="32" class=" ';
329 echo $odd_row ?
'odd' : 'even';
331 <td>' . $matching_tables[$i]. "\n" . '</td>
332 <td align="center">';
334 * Calculating the number of alter columns, number of columns to be added, number of columns to be removed,
335 * number of index to added and renmoved.
338 $num_insert_cols = 0;
339 $num_remove_cols = 0;
341 $num_remove_index = 0;
343 if (isset($alter_str_array[$i])) {
344 $num_alter_cols = sizeof($alter_str_array[$i]);
346 if (isset($add_column_array[$i])) {
347 $num_insert_cols = sizeof($add_column_array[$i]);
349 if (isset($uncommon_columns[$i])) {
350 $num_remove_cols = sizeof($uncommon_columns[$i]);
352 if (isset($add_indexes_array[$i])) {
353 $num_add_index = sizeof($add_indexes_array[$i]);
355 if (isset($remove_indexes_array[$i])) {
356 $num_remove_index = sizeof($remove_indexes_array[$i]);
359 * Display the red button of structure synchronization if there exists any structure difference or index difference.
361 if (($num_alter_cols > 0) ||
($num_insert_cols > 0) ||
($num_remove_cols > 0) ||
($num_add_index > 0) ||
($num_remove_index > 0)) {
363 echo '<img class="icon" src="' . $pmaThemeImage . 'new_struct.jpg" width="29" height="29"
364 alt="Click to Select" onmouseover="change_Image(this);" onmouseout="change_Image(this);"
365 onClick="showDetails('."'MS".$i."'".','."'".$num_alter_cols."'".','."'".$num_insert_cols.
366 "'".','."'".$num_remove_cols."'".','."'".$num_add_index."'".','."'".$num_remove_index."'"
367 .', this ,'."'". $matching_tables[$i] ."'".')"/>'. "\n" ;
371 * Display the green button of data synchronization if there exists any data difference.
373 if (isset($update_array[$i]) ||
isset($insert_array[$i])) {
374 if (isset($update_array[$i][0][$matching_tables_keys[$i][0]]) ||
isset($insert_array[$i][0][$matching_tables_keys[$i][0]])) {
376 echo '<img class="icon" src="' . $pmaThemeImage . 'new_data.jpg" width="29" height="29"
377 alt="Click to Select" onmouseover="change_Image(this);" onmouseout="change_Image(this);"
378 onClick="showDetails('."'MD".$i."'".','."'".$num_of_updates."'".','."'".$num_of_insertions.
379 "'".','."'".null."'".','."'".null."'".','."'".null."'".', this ,'."'". $matching_tables[$i] ."'".')" />'. "\n";
386 * Displays the tables' names present in source but missing from target
388 for ($j = 0; $j < count($source_tables_uncommon); $j++
)
390 $odd_row = !$odd_row;
391 echo '<tr height="32" class=" ';
392 echo $odd_row ?
'odd' : 'even';
394 <td> + ' .$source_tables_uncommon[$j]. "\n" . '</td> ';
396 echo '<td align="center"><img class="icon" src="' . $pmaThemeImage . 'new_struct.jpg" width="29" height="29"
397 alt="Click to Select" onmouseover="change_Image(this);" onmouseout="change_Image(this);"
398 onClick="showDetails('."'US".$j."'".','."'".null."'".','."'".null."'".','."'".null."'".','."'".null."'".','."'".null."'".', this ,'
399 ."'". $source_tables_uncommon[$j] ."'".')"/>'. "\n" ;
403 echo '<img class="icon" src="' . $pmaThemeImage . 'new_data.jpg" width="29"'.' height="29"
404 alt="Click to Select" onmouseover="change_Image(this);" onmouseout="change_Image(this);"
405 onClick="showDetails('."'UD".$j."'".','."'".null."'".','."'".$row_count[$j]."'".','."'".null.
406 "'".','."'".null."'".','."'".null."'".', this ,'."'". $source_tables_uncommon[$j] ."'".')" />'. "\n";
411 foreach ($target_tables_uncommon as $tbl_nc_name)
413 $odd_row = !$odd_row;
414 echo '<tr height="32" class=" ';
415 echo $odd_row ?
'odd' : 'even';
417 <td> </td><td></td>';
421 * Displays the target tables names
424 echo '<table id="serverstatusconnections" class="data" width="43%" >
426 <th>Target Database: ' . $trg_db . '</th>
429 foreach ($matching_tables as $tbl_name)
431 $odd_row = !$odd_row;
432 echo '<tr height="32" class=" ';
433 echo $odd_row ?
'odd' : 'even';
435 <td> ' .$tbl_name . '</td>';
438 foreach ($source_tables_uncommon as $tbl_nc_name)
440 $odd_row = !$odd_row;
441 echo '<tr height="32" class=" ';
442 echo $odd_row ?
'odd' : 'even';
444 <td>' .$tbl_nc_name . "\n" . ' (Not present)</td>
447 foreach ($target_tables_uncommon as $tbl_nc_name)
449 $odd_row = !$odd_row;
450 echo '<tr height="32" class=" ';
451 echo $odd_row ?
'odd' : 'even';
453 <td> - ' .$tbl_nc_name . '</td>';
460 * This "list" div will contain a table and each row will depict information about structure/data diffrence in tables.
461 * Rows will be generated dynamically as soon as the colored buttons "D" or "S" are clicked.
464 echo '<div id="list" style = "overflow: auto; width: 1020px; height: 140px;
465 border-left: 1px gray solid; border-bottom: 1px gray solid;
466 padding:0px; margin: 0px">
470 <tr style="width: 100%;">
471 <th id="table_name" style="width: 10%;" colspan="1">'. $strTable .' </th>
472 <th id="str_diff" style="width: 65%;" colspan="6">'. $strStructureDiff .' </th>
473 <th id="data_diff" style="width: 20%;" colspan="2">'. $strDataDiff .'</th>
475 <tr style="width: 100%;">
476 <th style="width: 10%; background-color:#CCCCCC">'. $strTableName .'</th>
477 <th style="width: 10%; background-color:#CCCCCC">'. $strCreateTable .'</th>
478 <th style="width: 11%; background-color:#CCCCCC">'. $strTableAddColumn .'</th>
479 <th style="width: 13%; background-color:#CCCCCC">'. $strTableRemoveColumn .'</th>
480 <th style="width: 11%; background-color:#CCCCCC">'. $strTableAlterColumn .'</th>
481 <th style="width: 12%; background-color:#CCCCCC">'. $strTableRemoveIndex .'</th>
482 <th style="width: 11%; background-color:#CCCCCC">'. $strTableApplyIndex .'</th>
483 <th style="width: 10%; background-color:#CCCCCC">'. $strTableUpdateRow .'</th>
484 <th style="width: 10%; background-color:#CCCCCC">'. $strTableInsertRow .'</th>
491 * This fieldset displays the checkbox to confirm deletion of previous rows from target tables
494 <p><input type= "checkbox" name="delete_rows" id ="delete_rows" />' . $strTableDeleteRows . ' </p>
496 <fieldset class="tblFooters">' . "\n";
497 echo '<input type="button" name="apply_changes" value="' . $GLOBALS['strApplyChanges']
498 .'" onClick ="ApplySelectedChanges('."'". $_SESSION['token'] ."'".')" />';
499 echo '<input type="submit" name="synchronize_db" value="'. $GLOBALS['strSynchronizeDb'] .'" />'
500 . "\n" . '</fieldset>' . "\n";
507 * Display the page when 'Apply Selected Changes' is pressed
509 if (isset($_REQUEST['Table_ids'])) {
511 * Displays success message
513 echo '<div class="success">Selected target tables have been synchronized with source tables. </div>';
515 $src_db = $_SESSION['src_db'];
516 $trg_db = $_SESSION['trg_db'];
517 $update_array = $_SESSION['update_array'];
518 $insert_array = $_SESSION['insert_array'];
519 $src_username = $_SESSION['src_username'];
520 $trg_username = $_SESSION['trg_username'];
521 $src_password = $_SESSION['src_password'];
522 $trg_password = $_SESSION['trg_password'];
523 $src_server = $_SESSION['src_server'];
524 $trg_server = $_SESSION['trg_server'];
525 $src_type = $_SESSION['src_type'];
526 $trg_type = $_SESSION['trg_type'];
527 $uncommon_tables = $_SESSION['uncommon_tables'];
528 $matching_tables = $_SESSION['matching_tables'];
529 $matching_tables_keys = $_SESSION['matching_tables_keys'];
530 $matching_tables_fields = $_SESSION['matching_fields'];
531 $source_tables_uncommon = $_SESSION['src_uncommon_tables'];
532 $uncommon_tables_fields = $_SESSION['uncommon_tables_fields'];
533 $target_tables_uncommon = $_SESSION['target_tables_uncommon'];
534 $row_count = $_SESSION['uncommon_tables_row_count'];
535 $target_tables = $_SESSION['target_tables'];
537 $delete_array = $_SESSION['delete_array'];
538 $uncommon_columns = $_SESSION['uncommon_columns'];
539 $source_columns = $_SESSION['source_columns'];
540 $alter_str_array = $_SESSION['alter_str_array'];
541 $criteria = $_SESSION['criteria'];
542 $target_tables_keys = $_SESSION['target_tables_keys'];
543 $add_column_array = $_SESSION['add_column_array'];
544 $add_indexes_array = $_SESSION['add_indexes_array'];
545 $alter_indexes_array = $_SESSION['alter_indexes_array'];
546 $remove_indexes_array = $_SESSION['remove_indexes_array'];
547 $source_indexes = $_SESSION['source_indexes'];
548 $target_indexes = $_SESSION['target_indexes'];
549 $uncommon_cols = $uncommon_columns;
552 * Creating link object for source and target databases
554 foreach ($cons as $con) {
555 if ($
{"{$con}_type"}=="rmt")
556 $
{"{$con}_link"} = PMA_DBI_connect($
{"{$con}_username"}, $
{"{$con}_password"}, $is_controluser = false, $
{"{$con}_server"});
558 $
{"{$con}_link"} = null;
562 * Initializing arrays to save the table ids whose data and structure difference is to be applied
564 $matching_table_data_diff = array(); //stores id of matching table having data difference
565 $matching_table_structure_diff = array(); //stores id of matching tables having structure difference
566 $uncommon_table_structure_diff = array(); //stores id of uncommon tables having structure difference
567 $uncommon_table_data_diff = array(); //stores id of uncommon tables having data difference
569 for ($i=0; isset($_REQUEST[$i]); $i++
)
571 if (isset($_REQUEST[$i])) {
572 $table_id = split("US", $_REQUEST[$i]);
573 if (isset($table_id[1])) {
574 $uncommon_table_structure_diff[] = $table_id[1];
576 $table_id = split("UD", $_REQUEST[$i]);
577 if (isset($table_id[1])) {
578 $uncommon_table_data_diff[] = $table_id[1];
580 $table_id = split("MS", $_REQUEST[$i]);
581 if (isset($table_id[1])) {
582 $matching_table_structure_diff[] = $table_id[1];
585 $table_id = split("MD", $_REQUEST[$i]);
586 if (isset($table_id[1])) {
587 $matching_table_data_diff[] = $table_id[1];
592 * Applying the structure difference on selected matching tables
594 for($q=0 ; $q < sizeof($matching_table_structure_diff); $q++
)
596 if (isset($alter_str_array[$matching_table_structure_diff[$q]])) {
598 PMA_alterTargetTableStructure($trg_db, $trg_link, $matching_tables, $source_columns, $alter_str_array, $matching_tables_fields,
599 $criteria, $matching_tables_keys, $target_tables_keys, $matching_table_structure_diff[$q], false);
601 unset($alter_str_array[$matching_table_structure_diff[$q]]);
603 if (isset($add_column_array[$matching_table_structure_diff[$q]])) {
605 PMA_findDeleteRowsFromTargetTables($delete_array, $matching_tables, $matching_table_structure_diff[$q], $target_tables_keys,
606 $matching_tables_keys, $trg_db, $trg_link, $src_db, $src_link);
608 if (isset($delete_array[$matching_table_structure_diff[$q]])) {
610 PMA_deleteFromTargetTable($trg_db, $trg_link, $matching_tables, $matching_table_structure_diff[$q], $target_tables_keys, $delete_array, false);
612 unset($delete_array[$matching_table_structure_diff[$q]]);
614 PMA_addColumnsInTargetTable($src_db, $trg_db,$src_link, $trg_link, $matching_tables, $source_columns, $add_column_array, $matching_tables_fields,
615 $criteria, $matching_tables_keys, $target_tables_keys, $uncommon_tables,$uncommon_tables_fields, $matching_table_structure_diff[$q], $uncommon_cols, false);
617 unset($add_column_array[$matching_table_structure_diff[$q]]);
619 if (isset($uncommon_columns[$matching_table_structure_diff[$q]])) {
621 PMA_removeColumnsFromTargetTable($trg_db, $trg_link, $matching_tables, $uncommon_columns, $matching_table_structure_diff[$q], false);
623 unset($uncommon_columns[$matching_table_structure_diff[$q]]);
625 if (isset($add_indexes_array[$matching_table_structure_diff[$q]]) ||
isset($remove_indexes_array[$matching_table_structure_diff[$q]])
626 ||
isset($alter_indexes_array[$matching_table_structure_diff[$q]])) {
628 PMA_applyIndexesDiff ($trg_db, $trg_link, $matching_tables, $source_indexes, $target_indexes, $add_indexes_array, $alter_indexes_array,
629 $remove_indexes_array, $matching_table_structure_diff[$q], false);
631 unset($add_indexes_array[$matching_table_structure_diff[$q]]);
632 unset($alter_indexes_array[$matching_table_structure_diff[$q]]);
633 unset($remove_indexes_array[$matching_table_structure_diff[$q]]);
637 * Applying the data difference. First checks if structure diff is applied or not.
638 * If not, then apply structure difference first then apply data difference.
640 for($p=0; $p < sizeof($matching_table_data_diff); $p++
)
642 if ($_REQUEST['checked'] == 'true') {
644 PMA_findDeleteRowsFromTargetTables($delete_array, $matching_tables, $matching_table_data_diff[$p], $target_tables_keys,
645 $matching_tables_keys, $trg_db, $trg_link, $src_db, $src_link);
647 if (isset($delete_array[$matching_table_data_diff[$p]])) {
649 PMA_deleteFromTargetTable($trg_db, $trg_link, $matching_tables, $matching_table_data_diff[$p], $target_tables_keys, $delete_array, false);
651 unset($delete_array[$matching_table_data_diff[$p]]);
654 if (isset($alter_str_array[$matching_table_data_diff[$p]])) {
656 PMA_alterTargetTableStructure($trg_db, $trg_link, $matching_tables, $source_columns, $alter_str_array, $matching_tables_fields,
657 $criteria, $matching_tables_keys, $target_tables_keys, $matching_table_data_diff[$p], false);
659 unset($alter_str_array[$matching_table_data_diff[$p]]);
661 if (isset($add_column_array[$matching_table_data_diff[$p]])) {
663 PMA_findDeleteRowsFromTargetTables($delete_array, $matching_tables, $matching_table_data_diff[$p], $target_tables_keys,
664 $matching_tables_keys, $trg_db, $trg_link, $src_db, $src_link);
666 if (isset($delete_array[$matching_table_data_diff[$p]])) {
668 PMA_deleteFromTargetTable($trg_db, $trg_link, $matching_tables, $matching_table_data_diff[$p], $target_tables_keys, $delete_array, false);
670 unset($delete_array[$matching_table_data_diff[$p]]);
672 PMA_addColumnsInTargetTable($src_db, $trg_db,$src_link, $trg_link, $matching_tables, $source_columns, $add_column_array, $matching_tables_fields,
673 criteria
, $matching_tables_keys, $target_tables_keys, $uncommon_tables, $uncommon_tables_fields, $matching_table_data_diff[$p], $uncommon_cols, false);
675 unset($add_column_array[$matching_table_data_diff[$p]]);
677 if (isset($uncommon_columns[$matching_table_data_diff[$p]])) {
679 PMA_removeColumnsFromTargetTable($trg_db, $trg_link, $matching_tables, $uncommon_columns, $matching_table_data_diff[$p], false);
681 unset($uncommon_columns[$matching_table_data_diff[$p]]);
683 if (isset($add_indexes_array[$matching_table_structure_diff[$q]]) ||
isset($remove_indexes_array[$matching_table_structure_diff[$q]])
684 ||
isset($alter_indexes_array[$matching_table_structure_diff[$q]])) {
686 PMA_applyIndexesDiff ($trg_db, $trg_link, $matching_tables, $source_indexes, $target_indexes, $add_indexes_array, $alter_indexes_array,
687 $remove_indexes_array, $matching_table_structure_diff[$q], false);
689 unset($add_indexes_array[$matching_table_structure_diff[$q]]);
690 unset($alter_indexes_array[$matching_table_structure_diff[$q]]);
691 unset($remove_indexes_array[$matching_table_structure_diff[$q]]);
694 * Applying the data difference.
696 PMA_updateTargetTables($matching_tables, $update_array, $src_db, $trg_db, $trg_link, $matching_table_data_diff[$p], $matching_tables_keys, false);
698 PMA_insertIntoTargetTable($matching_tables, $src_db, $trg_db, $src_link, $trg_link , $matching_tables_fields, $insert_array,
699 $matching_table_data_diff[$p], $matching_tables_keys, $source_columns, $add_column_array, $criteria, $target_tables_keys,
700 $uncommon_tables, $uncommon_tables_fields, $uncommon_cols, $alter_str_array, $source_indexes, $target_indexes, $add_indexes_array,
701 $alter_indexes_array, $delete_array, $update_array, false);
704 * Updating the session variables to the latest values of the arrays.
706 $_SESSION['delete_array'] = $delete_array;
707 $_SESSION['uncommon_columns'] = $uncommon_columns;
708 $_SESSION['alter_str_array'] = $alter_str_array;
709 $_SESSION['add_column_array'] = $add_column_array;
710 $_SESSION['add_indexes_array'] = $add_indexes_array;
711 $_SESSION['remove_indexes_array'] = $remove_indexes_array;
712 $_SESSION['insert_array'] = $insert_array;
713 $_SESSION['update_array'] = $update_array;
716 * Applying structure difference to selected non-matching tables (present in Source but absent from Target).
718 for($s=0; $s < sizeof($uncommon_table_structure_diff); $s++
)
720 PMA_createTargetTables ($src_db, $trg_db, $src_link, $trg_link, $uncommon_tables, $uncommon_table_structure_diff[$s], $uncommon_tables_fields, false);
721 $_SESSION['uncommon_tables_fields'] = $uncommon_tables_fields;
723 unset($uncommon_tables[$uncommon_table_structure_diff[$s]]);
726 * Applying data difference to selected non-matching tables (present in Source but absent from Target).
727 * Before data synchronization, structure synchronization is confirmed.
729 for($r=0; $r < sizeof($uncommon_table_data_diff); $r++
)
731 if (!(in_array($uncommon_table_data_diff[$r], $uncommon_table_structure_diff))) {
732 if (isset($uncommon_tables[$uncommon_table_data_diff[$r]])) {
734 PMA_createTargetTables($src_db, $trg_db, $src_link, $trg_link, $uncommon_tables, $uncommon_table_data_diff[$r], $uncommon_tables_fields, false);
735 $_SESSION['uncommon_tables_fields'] = $uncommon_tables_fields;
737 unset($uncommon_tables[$uncommon_table_data_diff[$r]]);
740 PMA_populateTargetTables($src_db, $trg_db, $src_link, $trg_link, $source_tables_uncommon, $uncommon_table_data_diff[$r],
741 $_SESSION['uncommon_tables_fields'], false);
743 unset($row_count[$uncommon_table_data_diff[$r]]);
746 * Again all the tables from source and target database are displayed with their differences.
747 * The differences have been removed from tables that have been synchronized
749 echo '<form name="applied_difference" id="synchronize_form" method="POST" action="server_synchronize.php">'
750 . PMA_generate_common_hidden_inputs('', '');
752 echo '<div id="serverstatus" style = "overflow: auto; width: 1020px; height: 220px;
753 border-left: 1px gray solid; border-bottom: 1px gray solid;
754 padding:0px; margin-bottom: 1em"> ';
756 echo '<table id="serverstatustraffic" class="data" width= "55%">
758 <th> Source Database: '. $src_db .'</th>
759 <th> Difference </th>
762 for($i = 0; $i < count($matching_tables); $i++
)
764 $odd_row = !$odd_row;
765 echo '<tr height="32" class=" ';
766 echo $odd_row ?
'odd' : 'even';
768 <td align="center">' . $matching_tables[$i]. "\n" . '</td>
769 <td align="center">';
772 $num_insert_cols = 0;
773 $num_remove_cols = 0;
775 $num_remove_index = 0;
777 if (isset($alter_str_array[$i])) {
778 $num_alter_cols = sizeof($alter_str_array[$i]);
780 if (isset($add_column_array[$i])) {
781 $num_insert_cols = sizeof($add_column_array[$i]);
783 if (isset($uncommon_columns[$i])) {
784 $num_remove_cols = sizeof($uncommon_columns[$i]);
786 if (isset($add_indexes_array[$i])) {
787 $num_add_index = sizeof($add_indexes_array[$i]);
789 if (isset($remove_indexes_array[$i])) {
790 $num_remove_index = sizeof($remove_indexes_array[$i]);
793 if (($num_alter_cols > 0) ||
($num_insert_cols > 0) ||
($num_remove_cols > 0) ||
($num_add_index > 0) ||
($num_remove_index > 0)) {
794 echo '<img class="icon" src="' . $pmaThemeImage . 'new_struct.jpg" width="29" height="29"
795 alt="Click to Select" onmouseover="change_Image(this);" onmouseout="change_Image(this);"
796 onClick="showDetails('."'MS".$i."'".','."'".$num_alter_cols."'".','."'".$num_insert_cols."'"
797 .','."'".$num_remove_cols."'".','."'".$num_add_index."'".','."'".$num_remove_index."'".',
798 this ,'."'". $matching_tables[$i] ."'".')"/>'. "\n" ;
800 if (!(in_array($i, $matching_table_data_diff))) {
802 if (isset($update_array[$i][0][$matching_tables_keys[$i][0]])) {
803 if (isset($update_array[$i])) {
804 $num_of_updates = sizeof($update_array[$i]);
811 if (isset($insert_array[$i][0][$matching_tables_keys[$i][0]])) {
812 if (isset($insert_array[$i])) {
813 $num_of_insertions = sizeof($insert_array[$i]);
815 $num_of_insertions = 0;
818 $num_of_insertions = 0;
821 if (isset($update_array[$i][0][$matching_tables_keys[$i][0]]) ||
isset($insert_array[$i][0][$matching_tables_keys[$i][0]])) {
822 echo '<img class="icon" src="' . $pmaThemeImage . 'new_data.jpg" width="29" height="29"
823 alt="Click to Select" onmouseover="change_Image(this);" onmouseout="change_Image(this);"
824 onClick="showDetails('."'MD".$i."'".','."'".$num_of_updates."'".','."'".$num_of_insertions.
825 "'".','."'".null."'".','."'".null."'".','."'".null."'".', this ,'."'". $matching_tables[$i] ."'".')" />';
828 unset($update_array[$i]);
829 unset($insert_array[$i]);
835 * placing updated value of arrays in session
838 $_SESSION['update_array'] = $update_array;
839 $_SESSION['insert_array'] = $insert_array;
841 for ($j = 0; $j < count($source_tables_uncommon); $j++
)
843 $odd_row = !$odd_row;
844 echo '<tr height="32" class=" ';
845 echo $odd_row ?
'odd' : 'even';
847 <td align="center"> + ' .$source_tables_uncommon[$j]. "\n" . '</td>
848 <td align="center">';
850 * Display the difference only when it has not been applied
852 if (!(in_array($j, $uncommon_table_structure_diff))) {
853 if (isset($uncommon_tables[$j])) {
854 echo '<img class="icon" src="' . $pmaThemeImage .'new_struct.jpg" width="29" height="29"
855 alt="Click to Select" onmouseover="change_Image(this);" onmouseout="change_Image(this);"
856 onClick="showDetails('."'US".$j."'".','."'".null."'".','."'".null."'".','."'".null."'"
857 .','."'".null."'".','."'".null."'".', this ,'."'". $source_tables_uncommon[$j] ."'".')"/>' . "\n" .' ';
860 unset($uncommon_tables[$j]);
863 * Display the difference only when it has not been applied
865 if (!(in_array($j, $uncommon_table_data_diff))) {
866 if (isset($row_count[$j]) && ($row_count > 0))
868 echo '<img class="icon" src="' . $pmaThemeImage . 'new_data.jpg" width="29"'.' height="29"
869 alt="Click to Select" onmouseover="change_Image(this);" onmouseout="change_Image(this);"
870 onClick="showDetails('."'UD".$j."'".','."'".null."'".','."'".$row_count[$j]."'".','."'"
871 .null."'".','."'".null."'".','."'".null."'".', this ,'."'". $source_tables_uncommon[$j] ."'".')" />'. "\n";
874 unset($row_count[$j]);
881 * placing the latest values of arrays in session
884 $_SESSION['uncommon_tables'] = $uncommon_tables;
885 $_SESSION['uncommon_tables_row_count'] = $row_count;
889 * Dispalying the target database tables
891 foreach ($target_tables_uncommon as $tbl_nc_name)
893 $odd_row = !$odd_row;
894 echo '<tr height="32" class=" ';
895 echo $odd_row ?
'odd' : 'even';
897 <td> </td><td></td>';
901 echo '<table id="serverstatusconnections" class="data" width="42%" >
903 <th>Target Database: ' . $trg_db . '</th>
906 foreach ($matching_tables as $tbl_name)
908 $odd_row = !$odd_row;
909 echo '<tr height="32" class=" ';
910 echo $odd_row ?
'odd' : 'even';
912 <td> ' .$tbl_name . '</td>';
915 foreach ($source_tables_uncommon as $tbl_nc_name)
917 $odd_row = !$odd_row;
918 echo '<tr height="32" class=" ';
919 echo $odd_row ?
'odd' : 'even';
921 if (in_array($tbl_nc_name, $uncommon_tables)) {
922 echo '<td>' .$tbl_nc_name . "\n" . '(Not present) </td>';
924 echo '<td>' .$tbl_nc_name . "\n" . '</td>';
929 foreach ($target_tables_uncommon as $tbl_nc_name)
931 $odd_row = !$odd_row;
932 echo '<tr height="32" class=" ';
933 echo $odd_row ?
'odd' : 'even';
935 <td> - ' .$tbl_nc_name . '</td>';
942 * This "list" div will contain a table and each row will depict information about structure/data diffrence in tables.
943 * Rows will be generated dynamically as soon as the colored buttons "D" or "S" are clicked.
946 echo '<div id="list" style = "overflow: auto; width: 1020px; height: 140px;
947 border-left: 1px gray solid; border-bottom: 1px gray solid;
948 padding:0px; margin: 0px">';
952 <tr style="width: 100%;">
953 <th id="table_name" style="width: 10%;" colspan="1">'. $strTable .' </th>
954 <th id="str_diff" style="width: 65%;" colspan="6">'. $strStructureDiff .' </th>
955 <th id="data_diff" style="width: 20%;" colspan="2">'. $strDataDiff .'</th>
957 <tr style="width: 100%;">
958 <th style="width: 10%; background-color:#CCCCCC">'. $strTableName .'</th>
959 <th style="width: 10%; background-color:#CCCCCC">'. $strCreateTable .'</th>
960 <th style="width: 11%; background-color:#CCCCCC">'. $strTableAddColumn .'</th>
961 <th style="width: 13%; background-color:#CCCCCC">'. $strTableRemoveColumn .'</th>
962 <th style="width: 11%; background-color:#CCCCCC">'. $strTableAlterColumn .'</th>
963 <th style="width: 12%; background-color:#CCCCCC">'. $strTableRemoveIndex .'</th>
964 <th style="width: 11%; background-color:#CCCCCC">'. $strTableApplyIndex .'</th>
965 <th style="width: 10%; background-color:#CCCCCC">'. $strTableUpdateRow .'</th>
966 <th style="width: 10%; background-color:#CCCCCC">'. $strTableInsertRow .'</th>
974 * This fieldset displays the checkbox to confirm deletion of previous rows from target tables
977 <p><input type= "checkbox" name="delete_rows" id ="delete_rows" />' . $strTableDeleteRows . ' </p>
980 echo '<fieldset class="tblFooters">' . "\n";
981 echo '<input type="button" name="apply_changes" value="' . $GLOBALS['strApplyChanges'].'"
982 onClick ="ApplySelectedChanges('."'". $_SESSION['token'] ."'".')" />';
983 echo '<input type="submit" name="synchronize_db" value="'. $GLOBALS['strSynchronizeDb'] .'" />'
984 . "\n" . '</fieldset>' . "\n";
989 * Dispalys the page when 'Synchronize Databases' is pressed.
992 if (isset($_REQUEST['synchronize_db'])) {
994 $src_db = $_SESSION['src_db'];
995 $trg_db = $_SESSION['trg_db'];
996 $update_array = $_SESSION['update_array'];
997 $insert_array = $_SESSION['insert_array'];
998 $src_username = $_SESSION['src_username'];
999 $trg_username = $_SESSION['trg_username'];
1000 $src_password = $_SESSION['src_password'];
1001 $trg_password = $_SESSION['trg_password'];
1002 $matching_tables = $_SESSION['matching_tables'];
1003 $matching_tables_keys = $_SESSION['matching_tables_keys'];
1004 $matching_tables_fields = $_SESSION['matching_fields'];
1005 $source_tables_uncommon = $_SESSION['src_uncommon_tables'];
1006 $uncommon_tables_fields = $_SESSION['uncommon_tables_fields'];
1007 $target_tables_uncommon = $_SESSION['target_tables_uncommon'];
1008 $row_count = $_SESSION['uncommon_tables_row_count'];
1009 $uncommon_tables = $_SESSION['uncommon_tables'];
1010 $target_tables = $_SESSION['target_tables'];
1012 $delete_array = $_SESSION['delete_array'];
1013 $uncommon_columns = $_SESSION['uncommon_columns'];
1014 $source_columns = $_SESSION['source_columns'];
1015 $alter_str_array = $_SESSION['alter_str_array'];
1016 $criteria = $_SESSION['criteria'];
1017 $target_tables_keys = $_SESSION['target_tables_keys'];
1018 $add_column_array = $_SESSION['add_column_array'];
1019 $add_indexes_array = $_SESSION['add_indexes_array'];
1020 $alter_indexes_array = $_SESSION['alter_indexes_array'];
1021 $remove_indexes_array = $_SESSION['remove_indexes_array'];
1022 $source_indexes = $_SESSION['source_indexes'];
1023 $target_indexes = $_SESSION['target_indexes'];
1024 $uncommon_cols = $uncommon_columns;
1027 * Display success message.
1029 echo '<div class="success">Target database has been synchronized with source database. </div>';
1031 * Dispalying all the tables of source and target database and now no difference is there.
1033 echo '<div id="serverstatus" style = "overflow: auto; width: 1050px; height: 250px;
1034 border-left: 1px gray solid; border-bottom: 1px gray solid;
1035 padding:0px; margin: 0px"> ';
1037 echo '<table id="serverstatustraffic" class="data" width ="55%">
1039 <th> Source Database: '. $src_db .'</th>
1040 <th> Difference </th>
1043 for($i = 0; $i < count($matching_tables); $i++
)
1045 $odd_row = !$odd_row;
1046 echo '<tr height="32" class=" ';
1047 echo $odd_row ?
'odd' : 'even';
1049 <td>' . $matching_tables[$i]. "\n" . '</td>
1053 for ($j = 0; $j < count($source_tables_uncommon); $j++
)
1055 $odd_row = !$odd_row;
1056 echo '<tr height="32" class=" ';
1057 echo $odd_row ?
'odd' : 'even';
1059 <td> + ' .$source_tables_uncommon[$j]. "\n" . '</td> ';
1063 foreach ($target_tables_uncommon as $tbl_nc_name)
1065 $odd_row = !$odd_row;
1066 echo '<tr height="32" class=" ';
1067 echo $odd_row ?
'odd' : 'even';
1069 <td> </td><td></td>';
1073 echo '<table id="serverstatusconnections" class="data" width="42%" >
1075 <th>Target Database: ' . $trg_db . '</th>
1078 foreach ($matching_tables as $tbl_name)
1080 $odd_row = !$odd_row;
1081 echo '<tr height="32" class=" ';
1082 echo $odd_row ?
'odd' : 'even';
1084 <td> ' .$tbl_name . '</td>';
1087 foreach ($source_tables_uncommon as $tbl_nc_name)
1089 $odd_row = !$odd_row;
1090 echo '<tr height="32" class=" ';
1091 echo $odd_row ?
'odd' : 'even';
1093 <td>' .$tbl_nc_name . "\n" . ' </td>
1096 foreach ($target_tables_uncommon as $tbl_nc_name)
1098 $odd_row = !$odd_row;
1099 echo '<tr height="32" class=" ';
1100 echo $odd_row ?
'odd' : 'even';
1102 <td> ' .$tbl_nc_name . '</td>';
1105 echo '</table> </div>';
1108 * connecting the source and target servers
1110 $src_link = PMA_DBI_connect($src_username, $src_password, $is_controluser = false);
1111 $trg_link = PMA_DBI_connect($trg_username, $trg_password, $is_controluser = false);
1114 * Displaying the queries.
1116 echo '<h5>Following queries have been executed: </h5>';
1117 echo '<div id="serverstatus" style = "overflow: auto; width: 1050px; height: 180px;
1118 border-left: 1px gray solid; border-bottom: 1px gray solid; padding: 0px; margin: 0px"> ';
1120 * Applying all sorts of differences for each matching table
1122 for($p=0; $p <sizeof($matching_tables);$p++
)
1125 * If the check box is checked for deleting previous rows from the target database tables then
1126 * first find out rows to be deleted and then delete the rows.
1128 if (isset($_REQUEST['delete_rows'])) {
1130 PMA_findDeleteRowsFromTargetTables($delete_array, $matching_tables, $p, $target_tables_keys, $matching_tables_keys,
1131 $trg_db, $trg_link, $src_db, $src_link);
1133 if (isset($delete_array[$p])) {
1135 PMA_deleteFromTargetTable($trg_db, $trg_link, $matching_tables, $p, $target_tables_keys, $delete_array, true);
1136 unset($delete_array[$p]);
1139 if (isset($alter_str_array[$p])) {
1141 PMA_alterTargetTableStructure($trg_db, $trg_link, $matching_tables, $source_columns, $alter_str_array, $matching_tables_fields,
1142 $criteria, $matching_tables_keys, $target_tables_keys, $p, true);
1143 unset($alter_str_array[$p]);
1145 if (isset($add_column_array[$p])) {
1147 PMA_findDeleteRowsFromTargetTables($delete_array, $matching_tables, $p, $target_tables_keys, $matching_tables_keys,
1148 $trg_db, $trg_link, $src_db, $src_link);
1150 if (isset($delete_array[$p])) {
1151 PMA_deleteFromTargetTable($trg_db, $trg_link, $matching_tables, $p, $target_tables_keys, $delete_array, true);
1152 unset($delete_array[$p]);
1154 PMA_addColumnsInTargetTable($src_db, $trg_db, $src_link, $trg_link, $matching_tables, $source_columns, $add_column_array, $matching_tables_fields,
1155 $criteria, $matching_tables_keys, $target_tables_keys, $uncommon_tables,$uncommon_tables_fields, $p, $uncommon_cols, true);
1156 unset($add_column_array[$p]);
1158 if (isset($uncommon_columns[$p])) {
1160 PMA_removeColumnsFromTargetTable($trg_db, $trg_link, $matching_tables, $uncommon_columns, $p, true);
1161 unset($uncommon_columns[$p]);
1163 if (isset($add_indexes_array[$matching_table_structure_diff[$q]]) ||
isset($remove_indexes_array[$matching_table_structure_diff[$q]])
1164 ||
isset($alter_indexes_array[$matching_table_structure_diff[$q]])) {
1166 PMA_applyIndexesDiff ($trg_db, $trg_link, $matching_tables, $source_indexes, $target_indexes, $add_indexes_array, $alter_indexes_array,
1167 $remove_indexes_array, $matching_table_structure_diff[$q], true);
1169 unset($add_indexes_array[$matching_table_structure_diff[$q]]);
1170 unset($alter_indexes_array[$matching_table_structure_diff[$q]]);
1171 unset($remove_indexes_array[$matching_table_structure_diff[$q]]);
1174 PMA_updateTargetTables($matching_tables, $update_array, $src_db, $trg_db, $trg_link, $p, $matching_tables_keys, true);
1176 PMA_insertIntoTargetTable($matching_tables, $src_db, $trg_db, $src_link, $trg_link , $matching_tables_fields, $insert_array,$p, $matching_tables_keys,
1177 $matching_tables_keys,$source_columns, $add_column_array, $criteria, $target_tables_keys,$uncommon_tables, $uncommon_tables_fields,$uncommon_cols,
1178 $alter_str_array,$source_indexes, $target_indexes, $add_indexes_array, $alter_indexes_array, $delete_array, $update_array, true);
1182 * Creating and populating tables present in source but absent from target database.
1184 for($q=0; $q < sizeof($source_tables_uncommon) ;$q++
)
1186 if (isset($uncommon_tables[$q])) {
1187 PMA_createTargetTables($src_db, $trg_db, $src_link, $trg_link, $source_tables_uncommon, $q, $uncommon_tables_fields, true);
1189 if (isset($row_count[$q])) {
1190 PMA_populateTargetTables($src_db, $trg_db, $src_link, $trg_link, $source_tables_uncommon, $q, $uncommon_tables_fields, true);
1197 * Displays the main page when none of the following buttons is pressed
1200 if (!isset($_REQUEST['submit_connect']) && !isset($_REQUEST['synchronize_db']) && !isset($_REQUEST['Table_ids']) )
1203 * Displays the sub-page heading
1206 . ($GLOBALS['cfg']['MainPageIconic']
1207 ?
'<img class="icon" src="' . $pmaThemeImage . 's_sync.png" width="18"'
1208 .' height="18" alt="" />'
1210 . $strSynchronize . "\n"
1213 echo '<div id="serverstatus">
1214 <form name="connection_form" id="connection_form" method="POST" action="server_synchronize.php"
1215 >' // TODO: add check if all var. are filled in
1216 . PMA_generate_common_hidden_inputs('', '');
1217 echo '<fieldset>'."\n";
1218 echo '<legend>'. $GLOBALS['strSynchronize']. '</legend>'."\n";
1220 * Displays the forms
1223 $databases = PMA_DBI_get_databases_full(null, false, null, 'SCHEMA_NAME',
1226 foreach ($cons as $type) {
1227 echo '<table id="serverconnection_'.$type.'_remote" class="data">
1229 <th colspan="2">'. $GLOBALS['strDatabase_'.$type] .'</th>
1232 <td colspan="2" style="text-align: center">
1233 <select name="'.$type.'_type" id="'.$type.'_type">
1234 <option value="rmt">'.$GLOBALS['strRemoteServer'].'</option>
1235 <option value="cur">'.$GLOBALS['strCurrentServer'].'</option>
1239 <tr class="even" id="'.$type.'tr1">
1240 <td>'. $GLOBALS['strHost']. '</td>
1241 <td><input type="text" name="'.$type.'_host" /></td>
1243 <tr class="odd" id="'.$type.'tr2">
1244 <td>'. $GLOBALS['strPort']. '</td>
1245 <td><input type="text" name="'.$type.'_port" value="3306" maxlength="5" size="5" /></td>
1247 <tr class="even" id="'.$type.'tr3">
1248 <td>'. $GLOBALS['strSocket']. '</td>
1249 <td><input type="text" name="'.$type.'_socket" /></td>
1251 <tr class="odd" id="'.$type.'tr4">
1252 <td>'. $GLOBALS['strUserName']. '</td>
1253 <td><input type="text" name="'.$type.'_username" /></td>
1255 <tr class="even" id="'.$type.'tr5">
1256 <td>'. $GLOBALS['strPassword']. '</td>
1257 <td><input type="password" name="'.$type.'_pass" /> </td>
1259 <tr class="odd" id="'.$type.'tr6">
1260 <td>'. $GLOBALS['strDatabase']. '</td>
1261 <td><input type="text" name="'.$type.'_db" /></td>
1263 <tr class="even" id="'.$type.'tr7" style="display: none;">
1264 <td>'. $GLOBALS['strDatabase']. '</td>
1266 <select name="'.$type.'_db_sel">
1268 foreach ($databases as $db) {
1269 if ($db['SCHEMA_NAME'] != 'mysql'
1270 && $db['SCHEMA_NAME'] != 'information_schema')
1271 echo ' <option>'.$db['SCHEMA_NAME'].'</option>'."\n";
1279 // Add JS to show/hide rows based on the selection
1281 '$(\''.$type.'_type\').addEvent(\'change\',function() {'."\n".
1282 ' if ($(\''.$type.'tr1\').getStyle(\'display\')=="none") {'."\n".
1283 ' for (var i=1; i<7; i++)'."\n".
1284 ' $(\''.$type.'tr\'+i).tween(\'display\', \'table-row\');'."\n".
1285 ' $(\''.$type.'tr7\').tween(\'display\', \'none\');'."\n".
1288 ' for (var i=1; i<7; i++)'."\n".
1289 ' $(\''.$type.'tr\'+i).tween(\'display\', \'none\');'."\n".
1290 ' $(\''.$type.'tr7\').tween(\'display\', \'table-row\');'."\n".
1295 unset ($types, $type);
1299 <fieldset class="tblFooters">
1300 <input type="submit" name="submit_connect" value="' .$GLOBALS['strGo'] .'" id="buttonGo" />
1304 <div class="notice">' . $strSynchronizationNote . '</div>';
1308 * Displays the footer
1310 require_once './libraries/footer.inc.php';