Translation update done using Pootle.
[phpmyadmin/crack.git] / server_synchronize.php
blob1272dda978137613f6124c7722d429910c91eea3
1 <?php
3 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 /**
6 * @package phpMyAdmin
7 */
9 /**
12 require_once './libraries/common.inc.php';
14 /**
15 * Does the common work
17 $GLOBALS['js_include'][] = 'functions.js';
18 $GLOBALS['js_include'][] = 'server_synchronize.js';
19 require_once './libraries/server_common.inc.php';
21 /**
22 * Contains all the functions specific to synchronization
24 require './libraries/server_synchronize.lib.php';
26 /**
27 * Increases the time limit up to the configured maximum
29 @set_time_limit($cfg['ExecTimeLimit']);
31 /**
32 * Displays the links
34 require './libraries/server_links.inc.php';
36 /**
37 * Enables warnings on the page
39 //$cfg['Error_Handler']['display'] = true;
40 //$cfg['Error_Handler']['gather'] = true;
42 /**
43 * Save the value of token generated for this page
45 if (isset($_REQUEST['token'])) {
46 $_SESSION['token'] = $_REQUEST['token'];
49 // variable for code saving
50 $cons = array ("src", "trg");
52 /**
53 * Displays the page when 'Go' is pressed
56 if ((isset($_REQUEST['submit_connect']))) {
57 foreach ($cons as $con) {
58 ${"{$con}_host"} = $_REQUEST[$con . '_host'];
59 ${"{$con}_username"} = $_REQUEST[$con . '_username'];
60 ${"{$con}_password"} = $_REQUEST[$con . '_pass'];
61 ${"{$con}_port"} = $_REQUEST[$con . '_port'];
62 ${"{$con}_socket"} = $_REQUEST[$con . '_socket'];
63 ${"{$con}_db"} = $_REQUEST[$con . '_db'];
64 ${"{$con}_type"} = $_REQUEST[$con . '_type'];
66 if (${"{$con}_type"} == 'cur') {
67 ${"{$con}_connection"} = null;
68 ${"{$con}_server"} = null;
69 ${"{$con}_db"} = $_REQUEST[$con . '_db_sel'];
70 continue;
73 if (isset(${"{$con}_socket"}) && ! empty(${"{$con}_socket"})) {
74 ${"{$con}_server"}['socket'] = ${"{$con}_socket"};
75 } else {
76 ${"{$con}_server"}['host'] = ${"{$con}_host"};
77 if (isset(${"{$con}_port"}) && ! empty(${"{$con}_port"}) && ((int)${"{$con}_port"} * 1) > 0) {
78 ${"{$con}_server"}['port'] = (int)${"{$con}_port"};
82 ${"{$con}_connection"} = PMA_DBI_connect(${"{$con}_username"}, ${"{$con}_password"}, $is_controluser = false, ${"{$con}_server"}, $auxiliary_connection = true);
83 } // end foreach ($cons as $con)
85 if ((! $src_connection && $src_type != 'cur') || (! $trg_connection && $trg_type != 'cur')) {
86 /**
87 * Displays the connection error string if
88 * connections are not established
91 echo '<div class="error">';
92 if(! $src_connection && $src_type != 'cur') {
93 echo __('Could not connect to the source') . '<br />';
95 if(! $trg_connection && $trg_type != 'cur'){
96 echo __('Could not connect to the target');
98 echo '</div>';
99 unset($_REQUEST['submit_connect']);
101 } else {
103 * Creating the link object for both source and target databases and
104 * selecting the source and target databases using these links
106 foreach ($cons as $con) {
107 if (${"{$con}_connection"} != null) {
108 ${"{$con}_link"} = PMA_DBI_connect(${"{$con}_username"}, ${"{$con}_password"}, $is_controluser = false, ${"{$con}_server"});
109 } else {
110 ${"{$con}_link"} = null;
112 ${"{$con}_db_selected"} = PMA_DBI_select_db(${"{$con}_db"}, ${"{$con}_link"});
113 } // end foreach ($cons as $con)
115 if (($src_db_selected != 1) || ($trg_db_selected != 1)) {
117 * Displays error string if the database(s) did not exist
119 echo '<div class="error">';
120 if ($src_db_selected != 1) {
121 echo sprintf(__('\'%s\' database does not exist.'), htmlspecialchars($src_db));
123 if ($trg_db_selected != 1) {
124 echo sprintf(__('\'%s\' database does not exist.'), htmlspecialchars($trg_db));
126 echo '</div>';
127 unset($_REQUEST['submit_connect']);
129 } else if (($src_db_selected == 1) && ($trg_db_selected == 1)) {
132 * Using PMA_DBI_get_tables() to get all the tables
133 * from target and source databases.
135 $src_tables = PMA_DBI_get_tables($src_db, $src_link);
136 $source_tables_num = sizeof($src_tables);
138 $trg_tables = PMA_DBI_get_tables($trg_db, $trg_link);
139 $target_tables_num = sizeof($trg_tables);
142 * initializing arrays to save matching and non-matching
143 * table names from target and source databases.
145 $unmatched_num_src = 0;
146 $source_tables_uncommon = array();
147 $unmatched_num_trg = 0;
148 $target_tables_uncommon = array();
149 $matching_tables = array();
150 $matching_tables_num = 0;
153 * Using PMA_getMatchingTables to find which of the tables' names match
154 * in target and source database.
156 PMA_getMatchingTables($trg_tables, $src_tables, $matching_tables, $source_tables_uncommon);
158 * Finding the uncommon tables for the target database
159 * using function PMA_getNonMatchingTargetTables()
161 PMA_getNonMatchingTargetTables($trg_tables, $matching_tables, $target_tables_uncommon);
164 * Initializing several arrays to save the data and structure
165 * difference between the source and target databases.
167 $row_count = array(); //number of rows in source table that needs to be created in target database
168 $fields_num = array(); //number of fields in each matching table
169 $delete_array = array(); //stores the primary key values for target tables that have excessive rows than corresponding source tables.
170 $insert_array = array(array(array()));// stores the primary key values for the rows in each source table that are not present in target tables.
171 $update_array = array(array(array())); //stores the primary key values, name of field to be updated, value of the field to be updated for
172 // each row of matching table.
173 $matching_tables_fields = array(); //contains the fields' names for each matching table
174 $matching_tables_keys = array(); //contains the primary keys' names for each matching table
175 $uncommon_tables_fields = array(); //coantains the fields for all the source tables that are not present in target
176 $matching_tables_num = sizeof($matching_tables);
178 $source_columns = array(); //contains the full columns' information for all the source tables' columns
179 $target_columns = array(); //contains the full columns' information for all the target tables' columns
180 $uncommon_columns = array(); //contains names of columns present in source table but absent from the corresponding target table
181 $source_indexes = array(); //contains indexes on all the source tables
182 $target_indexes = array(); //contains indexes on all the target tables
183 $add_indexes_array = array(); //contains the indexes name present in source but absent from target tables
184 $target_tables_keys = array(); //contains the keys of all the target tables
185 $alter_indexes_array = array(); //contains the names of all the indexes for each table that need to be altered in target database
186 $remove_indexes_array = array(); //contains the names of indexes that are excessive in target tables
187 $alter_str_array = array(array()); //contains the criteria for each column that needs to be altered in target tables
188 $add_column_array = array(array()); //contains the name of columns that need to be added in target tables
190 * The criteria array contains all the criteria against which columns are compared for differences.
192 $criteria = array('Field', 'Type', 'Null', 'Collation', 'Key', 'Default', 'Comment');
194 for($i = 0; $i < sizeof($matching_tables); $i++) {
196 * Finding out all the differences structure, data and index diff for all the matching tables only
198 PMA_dataDiffInTables($src_db, $trg_db, $src_link, $trg_link, $matching_tables, $matching_tables_fields, $update_array, $insert_array,
199 $delete_array, $fields_num, $i, $matching_tables_keys);
201 PMA_structureDiffInTables($src_db, $trg_db, $src_link, $trg_link, $matching_tables, $source_columns,
202 $target_columns, $alter_str_array, $add_column_array, $uncommon_columns, $criteria, $target_tables_keys, $i);
204 PMA_indexesDiffInTables($src_db, $trg_db, $src_link, $trg_link, $matching_tables, $source_indexes, $target_indexes,
205 $add_indexes_array, $alter_indexes_array, $remove_indexes_array, $i);
208 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 = "60%">
258 <tr>
259 <td> <h2>'
260 . ($GLOBALS['cfg']['MainPageIconic']
261 ? '<img class="icon" src="' . $pmaThemeImage . 'new_struct.jpg" width="32"'
262 . ' height="32" alt="" />'
263 : '')
264 . __('Structure Synchronization')
265 .'</h2>' .'</td>';
266 echo '<td> <h2>'
267 . ($GLOBALS['cfg']['MainPageIconic']
268 ? '<img class="icon" src="' . $pmaThemeImage . 'new_data.jpg" width="32"'
269 . ' height="32" alt="" />'
270 : '')
271 . __('Data Synchronization')
272 . '</h2>' .'</td>';
273 echo '</tr>
274 </table>';
277 * Displays the tables containing the source tables names, their difference with the target tables and target tables names
279 PMA_syncDisplayHeaderSource($src_db);
280 $odd_row = false;
282 * Display the matching tables' names and difference, first
284 for($i = 0; $i < count($matching_tables); $i++) {
286 * Calculating the number of updates for each matching table
288 if (isset($update_array[$i]) && isset($update_array[$i][0]) &&
289 isset($update_array[$i][0][$matching_tables_keys[$i][0]])) {
290 $num_of_updates = sizeof($update_array[$i]);
291 } else {
292 $num_of_updates = 0;
295 * Calculating the number of insertions for each matching table
297 if (isset($insert_array[$i]) && isset($insert_array[$i][0]) &&
298 isset($insert_array[$i][0][$matching_tables_keys[$i][0]])) {
299 $num_of_insertions = sizeof($insert_array[$i]);
300 } else {
301 $num_of_insertions = 0;
304 * Displays the name of the matching table
306 $odd_row = PMA_syncDisplayBeginTableRow($odd_row);
307 echo '<td>' . htmlspecialchars($matching_tables[$i]) . '</td>
308 <td align="center">';
310 * Calculating the number of alter columns, number of columns to be added, number of columns to be removed,
311 * number of index to be added and removed.
313 $num_alter_cols = 0;
314 $num_insert_cols = 0;
315 $num_remove_cols = 0;
316 $num_add_index = 0;
317 $num_remove_index = 0;
319 if (isset($alter_str_array[$i])) {
320 $num_alter_cols = sizeof($alter_str_array[$i]);
322 if (isset($add_column_array[$i])) {
323 $num_insert_cols = sizeof($add_column_array[$i]);
325 if (isset($uncommon_columns[$i])) {
326 $num_remove_cols = sizeof($uncommon_columns[$i]);
328 if (isset($add_indexes_array[$i])) {
329 $num_add_index = sizeof($add_indexes_array[$i]);
331 if (isset($remove_indexes_array[$i])) {
332 $num_remove_index = sizeof($remove_indexes_array[$i]);
334 if (isset($alter_indexes_array[$i])) {
335 $num_add_index += sizeof($alter_indexes_array[$i]);
336 $num_remove_index += sizeof($alter_indexes_array[$i]);
339 * Display the red button of structure synchronization if there exists any structure difference or index difference.
341 if (($num_alter_cols > 0) || ($num_insert_cols > 0) || ($num_remove_cols > 0) || ($num_add_index > 0) || ($num_remove_index > 0)) {
343 echo '<img class="icon" src="' . $pmaThemeImage . 'new_struct.jpg" width="29" height="29"
344 alt="' . __('Click to select') . '" onmouseover="change_Image(this);" onmouseout="change_Image(this);"
345 onclick="showDetails(' . "'MS" . $i . "','" . $num_alter_cols . "','" .$num_insert_cols .
346 "','" . $num_remove_cols . "','" . $num_add_index . "','" . $num_remove_index . "'"
347 . ', this ,' . "'" . htmlspecialchars($matching_tables[$i]) . "'" . ')"/>';
350 * Display the green button of data synchronization if there exists any data difference.
352 if (isset($update_array[$i]) || isset($insert_array[$i])) {
353 if (isset($update_array[$i][0][$matching_tables_keys[$i][0]]) || isset($insert_array[$i][0][$matching_tables_keys[$i][0]])) {
355 echo '<img class="icon" src="' . $pmaThemeImage . 'new_data.jpg" width="29" height="29"
356 alt="' . __('Click to select') . '" onmouseover="change_Image(this);" onmouseout="change_Image(this);"
357 onclick="showDetails('. "'MD" . $i . "','" . $num_of_updates . "','" . $num_of_insertions .
358 "','" . null . "','" . null . "','" . null . "'" . ', this ,' . "'" . htmlspecialchars($matching_tables[$i]) . "'" . ')" />';
361 echo '</td>
362 </tr>';
365 * Displays the tables' names present in source but missing from target
367 for ($j = 0; $j < count($source_tables_uncommon); $j++) {
368 $odd_row = PMA_syncDisplayBeginTableRow($odd_row);
369 echo '<td> + ' . htmlspecialchars($source_tables_uncommon[$j]) . '</td> ';
371 echo '<td align="center"><img class="icon" src="' . $pmaThemeImage . 'new_struct.jpg" width="29" height="29"
372 alt="' . __('Click to select') . '" onmouseover="change_Image(this);" onmouseout="change_Image(this);"
373 onclick="showDetails(' . "'US" . $j . "','" . null . "','" . null . "','" . null . "','" . null . "','" . null . "'" . ', this ,'
374 . "'" . htmlspecialchars($source_tables_uncommon[$j]) . "'" . ')"/>';
376 if ($row_count[$j] > 0)
378 echo '<img class="icon" src="' . $pmaThemeImage . 'new_data.jpg" width="29" height="29"
379 alt="' . __('Click to select') . '" onmouseover="change_Image(this);" onmouseout="change_Image(this);"
380 onclick="showDetails(' . "'UD" . $j . "','" . null . "','" . $row_count[$j] . "','" . null .
381 "','" . null . "','" . null . "'" . ', this ,' . "'" . htmlspecialchars($source_tables_uncommon[$j]) . "'" . ')" />';
383 echo '</td>
384 </tr>';
386 foreach ($target_tables_uncommon as $tbl_nc_name) {
387 $odd_row = PMA_syncDisplayBeginTableRow($odd_row);
388 echo '<td height="32">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </td><td></td>';
389 echo '</tr>';
392 * Displays the target tables names
394 echo '</table>';
396 $odd_row = PMA_syncDisplayHeaderTargetAndMatchingTables($trg_db, $matching_tables);
397 foreach ($source_tables_uncommon as $tbl_nc_name) {
398 $odd_row = PMA_syncDisplayBeginTableRow($odd_row);
399 echo '<td height="32">' . htmlspecialchars($tbl_nc_name) . ' (' . __('not present') . ')</td>
400 </tr>';
402 foreach ($target_tables_uncommon as $tbl_nc_name) {
403 $odd_row = PMA_syncDisplayBeginTableRow($odd_row);
404 echo '<td> - ' . htmlspecialchars($tbl_nc_name) . '</td>';
405 echo '</tr>';
407 echo '</table>';
408 echo '</div>';
411 * This "list" div will contain a table and each row will depict information about structure/data diffrence in tables.
412 * Rows will be generated dynamically as soon as the colored buttons "D" or "S" are clicked.
415 echo '<div id="list" style = "overflow: auto; width: 1020px; height: 140px;
416 border-left: 1px gray solid; border-bottom: 1px gray solid;
417 padding:0px; margin: 0px">
419 <table>
420 <thead>
421 <tr style="width: 100%;">
422 <th id="table_name" style="width: 10%;" colspan="1">' . __('Table') . ' </th>
423 <th id="str_diff" style="width: 65%;" colspan="6">' . __('Structure Difference') . ' </th>
424 <th id="data_diff" style="width: 20%;" colspan="2">' . __('Data Difference') . '</th>
425 </tr>
426 <tr style="width: 100%;">
427 <th style="width: 10%;">' . __('Table name') . '</th>
428 <th style="width: 10%;">' . __('Create table'). '</th>
429 <th style="width: 11%;">' . __('Add column(s)') . '</th>
430 <th style="width: 13%;">' . __('Remove column(s)') . '</th>
431 <th style="width: 11%;">' . __('Alter column(s)') . '</th>
432 <th style="width: 12%;">' . __('Remove index(s)') . '</th>
433 <th style="width: 11%;">' . __('Apply index(s)') . '</th>
434 <th style="width: 10%;">'. __('Update row(s)') . '</th>
435 <th style="width: 10%;">' . __('Insert row(s)') . '</th>
436 </tr>
437 </thead>
438 <tbody></tbody>
439 </table>
440 </div>';
442 * This fieldset displays the checkbox to confirm deletion of previous rows from target tables
444 echo '<fieldset>
445 <p><input type= "checkbox" name="delete_rows" id ="delete_rows" /><label for="delete_rows">' . __('Would you like to delete all the previous rows from target tables?') . '</label> </p>
446 </fieldset>
447 <fieldset class="tblFooters">';
448 echo '<input type="button" name="apply_changes" value="' . __('Apply Selected Changes')
449 . '" onclick ="ApplySelectedChanges(' . "'" . htmlspecialchars($_SESSION['token']) . "'" . ')" />';
450 echo '<input type="submit" name="synchronize_db" value="' . __('Synchronize Databases') . '" />' . '</fieldset>';
451 echo '</form>';
454 } // end if ((isset($_REQUEST['submit_connect'])))
457 * Display the page when 'Apply Selected Changes' is pressed
459 if (isset($_REQUEST['Table_ids'])) {
461 * Displays success message
463 echo '<div class="success">' . __('Selected target tables have been synchronized with source tables.') . '</div>';
465 $src_db = $_SESSION['src_db'];
466 $trg_db = $_SESSION['trg_db'];
467 $update_array = $_SESSION['update_array'];
468 $insert_array = $_SESSION['insert_array'];
469 $src_username = $_SESSION['src_username'];
470 $trg_username = $_SESSION['trg_username'];
471 $src_password = $_SESSION['src_password'];
472 $trg_password = $_SESSION['trg_password'];
473 $src_server = $_SESSION['src_server'];
474 $trg_server = $_SESSION['trg_server'];
475 $src_type = $_SESSION['src_type'];
476 $trg_type = $_SESSION['trg_type'];
477 $uncommon_tables = $_SESSION['uncommon_tables'];
478 $matching_tables = $_SESSION['matching_tables'];
479 $matching_tables_keys = $_SESSION['matching_tables_keys'];
480 $matching_tables_fields = $_SESSION['matching_fields'];
481 $source_tables_uncommon = $_SESSION['src_uncommon_tables'];
482 $uncommon_tables_fields = $_SESSION['uncommon_tables_fields'];
483 $target_tables_uncommon = $_SESSION['target_tables_uncommon'];
484 $row_count = $_SESSION['uncommon_tables_row_count'];
485 $target_tables = $_SESSION['target_tables'];
487 $delete_array = $_SESSION['delete_array'];
488 $uncommon_columns = $_SESSION['uncommon_columns'];
489 $source_columns = $_SESSION['source_columns'];
490 $alter_str_array = $_SESSION['alter_str_array'];
491 $criteria = $_SESSION['criteria'];
492 $target_tables_keys = $_SESSION['target_tables_keys'];
493 $add_column_array = $_SESSION['add_column_array'];
494 $add_indexes_array = $_SESSION['add_indexes_array'];
495 $alter_indexes_array = $_SESSION['alter_indexes_array'];
496 $remove_indexes_array = $_SESSION['remove_indexes_array'];
497 $source_indexes = $_SESSION['source_indexes'];
498 $target_indexes = $_SESSION['target_indexes'];
499 $uncommon_cols = $uncommon_columns;
502 * Creating link object for source and target databases
504 foreach ($cons as $con) {
505 if (${"{$con}_type"} != "cur") {
506 ${"{$con}_link"} = PMA_DBI_connect(${"{$con}_username"}, ${"{$con}_password"}, $is_controluser = false, ${"{$con}_server"});
507 } else {
508 ${"{$con}_link"} = null;
509 // working on current server, so initialize this for tracking
510 // (does not work if user defined current server as a remote one)
511 $GLOBALS['db'] = ${"{$con}_db"};
513 } // end foreach ($cons as $con)
516 * Initializing arrays to save the table ids whose data and structure difference is to be applied
518 $matching_table_data_diff = array(); //stores id of matching table having data difference
519 $matching_table_structure_diff = array(); //stores id of matching tables having structure difference
520 $uncommon_table_structure_diff = array(); //stores id of uncommon tables having structure difference
521 $uncommon_table_data_diff = array(); //stores id of uncommon tables having data difference
523 for ($i = 0; isset($_REQUEST[$i]); $i++ ) {
524 if (isset($_REQUEST[$i])) {
525 $table_id = explode("US", $_REQUEST[$i]);
526 if (isset($table_id[1])) {
527 $uncommon_table_structure_diff[] = $table_id[1];
529 $table_id = explode("UD", $_REQUEST[$i]);
530 if (isset($table_id[1])) {
531 $uncommon_table_data_diff[] = $table_id[1];
533 $table_id = explode("MS", $_REQUEST[$i]);
534 if (isset($table_id[1])) {
535 $matching_table_structure_diff[] = $table_id[1];
538 $table_id = explode("MD", $_REQUEST[$i]);
539 if (isset($table_id[1])) {
540 $matching_table_data_diff[] = $table_id[1];
543 } // end for
545 * Applying the structure difference on selected matching tables
547 for($q = 0; $q < sizeof($matching_table_structure_diff); $q++)
549 if (isset($alter_str_array[$matching_table_structure_diff[$q]])) {
551 PMA_alterTargetTableStructure($trg_db, $trg_link, $matching_tables, $source_columns, $alter_str_array, $matching_tables_fields,
552 $criteria, $matching_tables_keys, $target_tables_keys, $matching_table_structure_diff[$q], false);
554 unset($alter_str_array[$matching_table_structure_diff[$q]]);
556 if (isset($add_column_array[$matching_table_structure_diff[$q]])) {
558 PMA_findDeleteRowsFromTargetTables($delete_array, $matching_tables, $matching_table_structure_diff[$q], $target_tables_keys,
559 $matching_tables_keys, $trg_db, $trg_link, $src_db, $src_link);
561 if (isset($delete_array[$matching_table_structure_diff[$q]])) {
563 PMA_deleteFromTargetTable($trg_db, $trg_link, $matching_tables, $matching_table_structure_diff[$q], $target_tables_keys, $delete_array, false);
565 unset($delete_array[$matching_table_structure_diff[$q]]);
567 PMA_addColumnsInTargetTable($src_db, $trg_db,$src_link, $trg_link, $matching_tables, $source_columns, $add_column_array, $matching_tables_fields,
568 $criteria, $matching_tables_keys, $target_tables_keys, $uncommon_tables,$uncommon_tables_fields, $matching_table_structure_diff[$q], $uncommon_cols, false);
570 unset($add_column_array[$matching_table_structure_diff[$q]]);
572 if (isset($uncommon_columns[$matching_table_structure_diff[$q]])) {
574 PMA_removeColumnsFromTargetTable($trg_db, $trg_link, $matching_tables, $uncommon_columns, $matching_table_structure_diff[$q], false);
576 unset($uncommon_columns[$matching_table_structure_diff[$q]]);
578 if (isset($add_indexes_array[$matching_table_structure_diff[$q]]) || isset($remove_indexes_array[$matching_table_structure_diff[$q]])
579 || isset($alter_indexes_array[$matching_table_structure_diff[$q]])) {
581 PMA_applyIndexesDiff ($trg_db, $trg_link, $matching_tables, $source_indexes, $target_indexes, $add_indexes_array, $alter_indexes_array,
582 $remove_indexes_array, $matching_table_structure_diff[$q], false);
584 unset($add_indexes_array[$matching_table_structure_diff[$q]]);
585 unset($alter_indexes_array[$matching_table_structure_diff[$q]]);
586 unset($remove_indexes_array[$matching_table_structure_diff[$q]]);
590 * Applying the data difference. First checks if structure diff is applied or not.
591 * If not, then apply structure difference first then apply data difference.
593 for($p = 0; $p < sizeof($matching_table_data_diff); $p++)
595 if ($_REQUEST['checked'] == 'true') {
597 PMA_findDeleteRowsFromTargetTables($delete_array, $matching_tables, $matching_table_data_diff[$p], $target_tables_keys,
598 $matching_tables_keys, $trg_db, $trg_link, $src_db, $src_link);
600 if (isset($delete_array[$matching_table_data_diff[$p]])) {
602 PMA_deleteFromTargetTable($trg_db, $trg_link, $matching_tables, $matching_table_data_diff[$p], $target_tables_keys, $delete_array, false);
604 unset($delete_array[$matching_table_data_diff[$p]]);
607 if (isset($alter_str_array[$matching_table_data_diff[$p]])) {
609 PMA_alterTargetTableStructure($trg_db, $trg_link, $matching_tables, $source_columns, $alter_str_array, $matching_tables_fields,
610 $criteria, $matching_tables_keys, $target_tables_keys, $matching_table_data_diff[$p], false);
612 unset($alter_str_array[$matching_table_data_diff[$p]]);
614 if (isset($add_column_array[$matching_table_data_diff[$p]])) {
616 PMA_findDeleteRowsFromTargetTables($delete_array, $matching_tables, $matching_table_data_diff[$p], $target_tables_keys,
617 $matching_tables_keys, $trg_db, $trg_link, $src_db, $src_link);
619 if (isset($delete_array[$matching_table_data_diff[$p]])) {
621 PMA_deleteFromTargetTable($trg_db, $trg_link, $matching_tables, $matching_table_data_diff[$p], $target_tables_keys, $delete_array, false);
623 unset($delete_array[$matching_table_data_diff[$p]]);
625 PMA_addColumnsInTargetTable($src_db, $trg_db,$src_link, $trg_link, $matching_tables, $source_columns, $add_column_array, $matching_tables_fields,
626 $criteria, $matching_tables_keys, $target_tables_keys, $uncommon_tables, $uncommon_tables_fields, $matching_table_data_diff[$p], $uncommon_cols, false);
628 unset($add_column_array[$matching_table_data_diff[$p]]);
630 if (isset($uncommon_columns[$matching_table_data_diff[$p]])) {
632 PMA_removeColumnsFromTargetTable($trg_db, $trg_link, $matching_tables, $uncommon_columns, $matching_table_data_diff[$p], false);
634 unset($uncommon_columns[$matching_table_data_diff[$p]]);
636 if ((isset($matching_table_structure_diff[$q]) && isset($add_indexes_array[$matching_table_structure_diff[$q]]))
637 || (isset($matching_table_structure_diff[$q]) && isset($remove_indexes_array[$matching_table_structure_diff[$q]]))
638 || (isset($matching_table_structure_diff[$q]) && isset($alter_indexes_array[$matching_table_structure_diff[$q]]))) {
640 PMA_applyIndexesDiff ($trg_db, $trg_link, $matching_tables, $source_indexes, $target_indexes, $add_indexes_array, $alter_indexes_array,
641 $remove_indexes_array, $matching_table_structure_diff[$q], false);
643 unset($add_indexes_array[$matching_table_structure_diff[$q]]);
644 unset($alter_indexes_array[$matching_table_structure_diff[$q]]);
645 unset($remove_indexes_array[$matching_table_structure_diff[$q]]);
648 * Applying the data difference.
650 PMA_updateTargetTables($matching_tables, $update_array, $src_db, $trg_db, $trg_link, $matching_table_data_diff[$p], $matching_tables_keys, false);
652 PMA_insertIntoTargetTable($matching_tables, $src_db, $trg_db, $src_link, $trg_link , $matching_tables_fields, $insert_array,
653 $matching_table_data_diff[$p], $matching_tables_keys, $source_columns, $add_column_array, $criteria, $target_tables_keys,
654 $uncommon_tables, $uncommon_tables_fields, $uncommon_cols, $alter_str_array, $source_indexes, $target_indexes, $add_indexes_array,
655 $alter_indexes_array, $delete_array, $update_array, false);
658 * Updating the session variables to the latest values of the arrays.
660 $_SESSION['delete_array'] = $delete_array;
661 $_SESSION['uncommon_columns'] = $uncommon_columns;
662 $_SESSION['alter_str_array'] = $alter_str_array;
663 $_SESSION['add_column_array'] = $add_column_array;
664 $_SESSION['add_indexes_array'] = $add_indexes_array;
665 $_SESSION['remove_indexes_array'] = $remove_indexes_array;
666 $_SESSION['insert_array'] = $insert_array;
667 $_SESSION['update_array'] = $update_array;
670 * Applying structure difference to selected non-matching tables (present in Source but absent from Target).
672 for($s = 0; $s < sizeof($uncommon_table_structure_diff); $s++)
674 PMA_createTargetTables($src_db, $trg_db, $src_link, $trg_link, $uncommon_tables, $uncommon_table_structure_diff[$s], $uncommon_tables_fields, false);
675 $_SESSION['uncommon_tables_fields'] = $uncommon_tables_fields;
677 unset($uncommon_tables[$uncommon_table_structure_diff[$s]]);
680 * Applying data difference to selected non-matching tables (present in Source but absent from Target).
681 * Before data synchronization, structure synchronization is confirmed.
683 for($r = 0; $r < sizeof($uncommon_table_data_diff); $r++)
685 if (!(in_array($uncommon_table_data_diff[$r], $uncommon_table_structure_diff))) {
686 if (isset($uncommon_tables[$uncommon_table_data_diff[$r]])) {
688 PMA_createTargetTables($src_db, $trg_db, $src_link, $trg_link, $uncommon_tables, $uncommon_table_data_diff[$r],
689 $uncommon_tables_fields, false);
690 $_SESSION['uncommon_tables_fields'] = $uncommon_tables_fields;
692 unset($uncommon_tables[$uncommon_table_data_diff[$r]]);
695 PMA_populateTargetTables($src_db, $trg_db, $src_link, $trg_link, $source_tables_uncommon, $uncommon_table_data_diff[$r],
696 $_SESSION['uncommon_tables_fields'], false);
698 unset($row_count[$uncommon_table_data_diff[$r]]);
701 * Again all the tables from source and target database are displayed with their differences.
702 * The differences have been removed from tables that have been synchronized
704 echo '<form name="applied_difference" id="synchronize_form" method="post" action="server_synchronize.php">'
705 . PMA_generate_common_hidden_inputs('', '');
707 PMA_syncDisplayHeaderSource($src_db);
708 $odd_row = false;
709 for($i = 0; $i < count($matching_tables); $i++) {
710 $odd_row = PMA_syncDisplayBeginTableRow($odd_row);
711 echo '<td align="center">' . htmlspecialchars($matching_tables[$i]) . '</td>
712 <td align="center">';
714 $num_alter_cols = 0;
715 $num_insert_cols = 0;
716 $num_remove_cols = 0;
717 $num_add_index = 0;
718 $num_remove_index = 0;
720 if (isset($alter_str_array[$i])) {
721 $num_alter_cols = sizeof($alter_str_array[$i]);
723 if (isset($add_column_array[$i])) {
724 $num_insert_cols = sizeof($add_column_array[$i]);
726 if (isset($uncommon_columns[$i])) {
727 $num_remove_cols = sizeof($uncommon_columns[$i]);
729 if (isset($add_indexes_array[$i])) {
730 $num_add_index = sizeof($add_indexes_array[$i]);
732 if (isset($remove_indexes_array[$i])) {
733 $num_remove_index = sizeof($remove_indexes_array[$i]);
736 if (($num_alter_cols > 0) || ($num_insert_cols > 0) || ($num_remove_cols > 0) || ($num_add_index > 0) || ($num_remove_index > 0)) {
737 echo '<img class="icon" src="' . $pmaThemeImage . 'new_struct.jpg" width="29" height="29"
738 alt="' . __('Click to select') . '" onmouseover="change_Image(this);" onmouseout="change_Image(this);"
739 onclick="showDetails(' . "'MS" . $i . "','" . $num_alter_cols . "','" . $num_insert_cols . "','" . $num_remove_cols . "','" . $num_add_index . "','" . $num_remove_index . "'" .',
740 this ,' . "'" . htmlspecialchars($matching_tables[$i]) . "'" . ')"/>';
742 if (!(in_array($i, $matching_table_data_diff))) {
744 if (isset($matching_tables_keys[$i][0]) && isset($update_array[$i][0][$matching_tables_keys[$i][0]])) {
745 if (isset($update_array[$i])) {
746 $num_of_updates = sizeof($update_array[$i]);
747 } else {
748 $num_of_updates = 0;
750 } else {
751 $num_of_updates = 0;
753 if (isset($matching_tables_keys[$i][0]) && isset($insert_array[$i][0][$matching_tables_keys[$i][0]])) {
754 if (isset($insert_array[$i])) {
755 $num_of_insertions = sizeof($insert_array[$i]);
756 } else {
757 $num_of_insertions = 0;
759 } else {
760 $num_of_insertions = 0;
763 if ((isset($matching_tables_keys[$i][0]) && isset($update_array[$i][0][$matching_tables_keys[$i][0]]))
764 || (isset($matching_tables_keys[$i][0]) && isset($insert_array[$i][0][$matching_tables_keys[$i][0]]))) {
765 echo '<img class="icon" src="' . $pmaThemeImage . 'new_data.jpg" width="29" height="29"
766 alt="' . __('Click to select') . '" onmouseover="change_Image(this);" onmouseout="change_Image(this);"
767 onclick="showDetails(' . "'MD" . $i . "','" . $num_of_updates . "','" . $num_of_insertions .
768 "','" . null . "','" . null . "','" . null . "'" .', this ,' . "'" . htmlspecialchars($matching_tables[$i]) . "'" . ')" />';
770 } else {
771 unset($update_array[$i]);
772 unset($insert_array[$i]);
774 echo '</td>
775 </tr>';
778 * placing updated value of arrays in session
781 $_SESSION['update_array'] = $update_array;
782 $_SESSION['insert_array'] = $insert_array;
784 for ($j = 0; $j < count($source_tables_uncommon); $j++) {
785 $odd_row = PMA_syncDisplayBeginTableRow($odd_row);
786 echo '<td align="center"> + ' . htmlspecialchars($source_tables_uncommon[$j]) . '</td>
787 <td align="center">';
789 * Display the difference only when it has not been applied
791 if (!(in_array($j, $uncommon_table_structure_diff))) {
792 if (isset($uncommon_tables[$j])) {
793 echo '<img class="icon" src="' . $pmaThemeImage . 'new_struct.jpg" width="29" height="29"
794 alt="' . __('Click to select') . '" onmouseover="change_Image(this);" onmouseout="change_Image(this);"
795 onclick="showDetails(' . "'US" . $j . "','" . null . "','" . null . "','" . null . "','" . null . "','" . null . "'" . ', this ,' . "'" . htmlspecialchars($source_tables_uncommon[$j]) . "'" . ')"/>' .' ';
797 } else {
798 unset($uncommon_tables[$j]);
801 * Display the difference only when it has not been applied
803 if (!(in_array($j, $uncommon_table_data_diff))) {
804 if (isset($row_count[$j]) && ($row_count > 0)) {
805 echo '<img class="icon" src="' . $pmaThemeImage . 'new_data.jpg" width="29" height="29"
806 alt="' . __('Click to select') . '" onmouseover="change_Image(this);" onmouseout="change_Image(this);"
807 onclick="showDetails(' . "'UD" . $j . "','" . null ."','" . $row_count[$j] ."','"
808 . null . "','" . null . "','" . null . "'" . ', this ,' . "'". htmlspecialchars($source_tables_uncommon[$j]) . "'" . ')" />';
810 } else {
811 unset($row_count[$j]);
814 echo '</td>
815 </tr>';
818 * placing the latest values of arrays in session
821 $_SESSION['uncommon_tables'] = $uncommon_tables;
822 $_SESSION['uncommon_tables_row_count'] = $row_count;
826 * Displaying the target database tables
828 foreach ($target_tables_uncommon as $tbl_nc_name) {
829 $odd_row = PMA_syncDisplayBeginTableRow($odd_row);
830 echo '<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </td><td></td>';
831 echo '</tr>';
833 echo '</table>';
834 $odd_row = PMA_syncDisplayHeaderTargetAndMatchingTables($trg_db, $matching_tables);
835 foreach ($source_tables_uncommon as $tbl_nc_name) {
836 $odd_row = PMA_syncDisplayBeginTableRow($odd_row);
837 if (in_array($tbl_nc_name, $uncommon_tables)) {
838 echo '<td>' . htmlspecialchars($tbl_nc_name) . ' (' . __('not present') . ')</td>';
839 } else {
840 echo '<td>' . htmlspecialchars($tbl_nc_name) . '</td>';
842 echo '
843 </tr>';
845 foreach ($target_tables_uncommon as $tbl_nc_name) {
846 $odd_row = PMA_syncDisplayBeginTableRow($odd_row);
847 echo '<td> - ' . htmlspecialchars($tbl_nc_name) . '</td>';
848 echo '</tr>';
850 echo '</table>
851 </div>';
854 * This "list" div will contain a table and each row will depict information about structure/data diffrence in tables.
855 * Rows will be generated dynamically as soon as the colored buttons "D" or "S" are clicked.
858 echo '<div id="list" style = "overflow: auto; width: 1020px; height: 140px;
859 border-left: 1px gray solid; border-bottom: 1px gray solid;
860 padding:0px; margin: 0px">';
862 echo '<table>
863 <thead>
864 <tr style="width: 100%;">
865 <th id="table_name" style="width: 10%;" colspan="1">' . __('Table') . ' </th>
866 <th id="str_diff" style="width: 65%;" colspan="6">' . __('Structure Difference') . ' </th>
867 <th id="data_diff" style="width: 20%;" colspan="2">' . __('Data Difference') . '</th>
868 </tr>
869 <tr style="width: 100%;">
870 <th style="width: 10%;">' . __('Table name') . '</th>
871 <th style="width: 10%;">' . __('Create table'). '</th>
872 <th style="width: 11%;">' . __('Add column(s)') . '</th>
873 <th style="width: 13%;">' . __('Remove column(s)') . '</th>
874 <th style="width: 11%;">' . __('Alter column(s)') . '</th>
875 <th style="width: 12%;">' . __('Remove index(s)') . '</th>
876 <th style="width: 11%;">' . __('Apply index(s)') . '</th>
877 <th style="width: 10%;">' . __('Update row(s)') . '</th>
878 <th style="width: 10%;">' . __('Insert row(s)') . '</th>
879 </tr>
880 </thead>
881 <tbody></tbody>
882 </table>
883 </div>';
886 * This fieldset displays the checkbox to confirm deletion of previous rows from target tables
888 echo '<fieldset>
889 <p><input type="checkbox" name="delete_rows" id ="delete_rows" /><label for="delete_rows">' . __('Would you like to delete all the previous rows from target tables?') . '</label> </p>
890 </fieldset>';
892 echo '<fieldset class="tblFooters">';
893 echo '<input type="button" name="apply_changes" value="' . __('Apply Selected Changes') . '"
894 onclick ="ApplySelectedChanges(' . "'" . htmlspecialchars($_SESSION['token']) . "'" .')" />';
895 echo '<input type="submit" name="synchronize_db" value="' . __('Synchronize Databases') . '" />'
896 . '</fieldset>';
897 echo '</form>';
901 * Displays the page when 'Synchronize Databases' is pressed.
904 if (isset($_REQUEST['synchronize_db'])) {
906 $src_db = $_SESSION['src_db'];
907 $trg_db = $_SESSION['trg_db'];
908 $update_array = $_SESSION['update_array'];
909 $insert_array = $_SESSION['insert_array'];
910 $src_username = $_SESSION['src_username'];
911 $trg_username = $_SESSION['trg_username'];
912 $src_password = $_SESSION['src_password'];
913 $trg_password = $_SESSION['trg_password'];
914 $matching_tables = $_SESSION['matching_tables'];
915 $matching_tables_keys = $_SESSION['matching_tables_keys'];
916 $matching_tables_fields = $_SESSION['matching_fields'];
917 $source_tables_uncommon = $_SESSION['src_uncommon_tables'];
918 $uncommon_tables_fields = $_SESSION['uncommon_tables_fields'];
919 $target_tables_uncommon = $_SESSION['target_tables_uncommon'];
920 $row_count = $_SESSION['uncommon_tables_row_count'];
921 $uncommon_tables = $_SESSION['uncommon_tables'];
922 $target_tables = $_SESSION['target_tables'];
924 $delete_array = $_SESSION['delete_array'];
925 $uncommon_columns = $_SESSION['uncommon_columns'];
926 $source_columns = $_SESSION['source_columns'];
927 $alter_str_array = $_SESSION['alter_str_array'];
928 $criteria = $_SESSION['criteria'];
929 $target_tables_keys = $_SESSION['target_tables_keys'];
930 $add_column_array = $_SESSION['add_column_array'];
931 $add_indexes_array = $_SESSION['add_indexes_array'];
932 $alter_indexes_array = $_SESSION['alter_indexes_array'];
933 $remove_indexes_array = $_SESSION['remove_indexes_array'];
934 $source_indexes = $_SESSION['source_indexes'];
935 $target_indexes = $_SESSION['target_indexes'];
936 $uncommon_cols = $uncommon_columns;
939 * Display success message.
941 echo '<div class="success">' . __('Target database has been synchronized with source database') . '</div>';
943 * Displaying all the tables of source and target database and now no difference is there.
945 PMA_syncDisplayHeaderSource($src_db);
947 $odd_row = false;
948 for($i = 0; $i < count($matching_tables); $i++)
950 $odd_row = PMA_syncDisplayBeginTableRow($odd_row);
951 echo '<td>' . htmlspecialchars($matching_tables[$i]) . '</td>
952 <td></td>
953 </tr>';
955 for ($j = 0; $j < count($source_tables_uncommon); $j++) {
956 $odd_row = PMA_syncDisplayBeginTableRow($odd_row);
957 echo '<td> + ' . htmlspecialchars($source_tables_uncommon[$j]) . '</td> ';
958 echo '<td></td>
959 </tr>';
961 foreach ($target_tables_uncommon as $tbl_nc_name) {
962 $odd_row = PMA_syncDisplayBeginTableRow($odd_row);
963 echo '<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </td><td></td>';
964 echo '</tr>';
966 echo '</table>';
967 $odd_row = PMA_syncDisplayHeaderTargetAndMatchingTables($trg_db, $matching_tables);
968 foreach ($source_tables_uncommon as $tbl_nc_name) {
969 $odd_row = PMA_syncDisplayBeginTableRow($odd_row);
970 echo '<td>' . htmlspecialchars($tbl_nc_name) . ' </td>
971 </tr>';
973 foreach ($target_tables_uncommon as $tbl_nc_name) {
974 $odd_row = PMA_syncDisplayBeginTableRow($odd_row);
975 echo '<td> ' . htmlspecialchars($tbl_nc_name) . '</td>';
976 echo '</tr>';
978 echo '</table> </div>';
981 * connecting the source and target servers
983 if ('cur' != $_SESSION['src_type']) {
984 $src_link = PMA_DBI_connect($src_username, $src_password, $is_controluser = false, $_SESSION['src_server']);
985 } else {
986 $src_link = $GLOBALS['userlink'];
987 // working on current server, so initialize this for tracking
988 // (does not work if user defined current server as a remote one)
989 $GLOBALS['db'] = $_SESSION['src_db'];
991 if ('cur' != $_SESSION['trg_type']) {
992 $trg_link = PMA_DBI_connect($trg_username, $trg_password, $is_controluser = false, $_SESSION['trg_server']);
993 } else {
994 $trg_link = $GLOBALS['userlink'];
995 // working on current server, so initialize this for tracking
996 $GLOBALS['db'] = $_SESSION['trg_db'];
1000 * Displaying the queries.
1002 echo '<h5>' . __('The following queries have been executed:') . '</h5>';
1003 echo '<div id="serverstatus" style = "overflow: auto; width: 1050px; height: 180px;
1004 border-left: 1px gray solid; border-bottom: 1px gray solid; padding: 0px; margin: 0px"> ';
1006 * Applying all sorts of differences for each matching table
1008 for($p = 0; $p < sizeof($matching_tables); $p++) {
1010 * If the check box is checked for deleting previous rows from the target database tables then
1011 * first find out rows to be deleted and then delete the rows.
1013 if (isset($_REQUEST['delete_rows'])) {
1014 PMA_findDeleteRowsFromTargetTables($delete_array, $matching_tables, $p, $target_tables_keys, $matching_tables_keys,
1015 $trg_db, $trg_link, $src_db, $src_link);
1017 if (isset($delete_array[$p])) {
1018 PMA_deleteFromTargetTable($trg_db, $trg_link, $matching_tables, $p, $target_tables_keys, $delete_array, true);
1019 unset($delete_array[$p]);
1022 if (isset($alter_str_array[$p])) {
1023 PMA_alterTargetTableStructure($trg_db, $trg_link, $matching_tables, $source_columns, $alter_str_array, $matching_tables_fields,
1024 $criteria, $matching_tables_keys, $target_tables_keys, $p, true);
1025 unset($alter_str_array[$p]);
1027 if (! empty($add_column_array[$p])) {
1028 PMA_findDeleteRowsFromTargetTables($delete_array, $matching_tables, $p, $target_tables_keys, $matching_tables_keys,
1029 $trg_db, $trg_link, $src_db, $src_link);
1031 if (isset($delete_array[$p])) {
1032 PMA_deleteFromTargetTable($trg_db, $trg_link, $matching_tables, $p, $target_tables_keys, $delete_array, true);
1033 unset($delete_array[$p]);
1035 PMA_addColumnsInTargetTable($src_db, $trg_db, $src_link, $trg_link, $matching_tables, $source_columns, $add_column_array,
1036 $matching_tables_fields, $criteria, $matching_tables_keys, $target_tables_keys, $uncommon_tables, $uncommon_tables_fields,
1037 $p, $uncommon_cols, true);
1038 unset($add_column_array[$p]);
1040 if (isset($uncommon_columns[$p])) {
1041 PMA_removeColumnsFromTargetTable($trg_db, $trg_link, $matching_tables, $uncommon_columns, $p, true);
1042 unset($uncommon_columns[$p]);
1044 if (isset($matching_table_structure_diff) &&
1045 (isset($add_indexes_array[$matching_table_structure_diff[$p]])
1046 || isset($remove_indexes_array[$matching_table_structure_diff[$p]])
1047 || isset($alter_indexes_array[$matching_table_structure_diff[$p]]))) {
1048 PMA_applyIndexesDiff ($trg_db, $trg_link, $matching_tables, $source_indexes, $target_indexes, $add_indexes_array, $alter_indexes_array,
1049 $remove_indexes_array, $matching_table_structure_diff[$p], true);
1051 unset($add_indexes_array[$matching_table_structure_diff[$p]]);
1052 unset($alter_indexes_array[$matching_table_structure_diff[$p]]);
1053 unset($remove_indexes_array[$matching_table_structure_diff[$p]]);
1056 PMA_updateTargetTables($matching_tables, $update_array, $src_db, $trg_db, $trg_link, $p, $matching_tables_keys, true);
1058 PMA_insertIntoTargetTable($matching_tables, $src_db, $trg_db, $src_link, $trg_link , $matching_tables_fields, $insert_array, $p,
1059 $matching_tables_keys, $matching_tables_keys, $source_columns, $add_column_array, $criteria, $target_tables_keys, $uncommon_tables,
1060 $uncommon_tables_fields,$uncommon_cols, $alter_str_array,$source_indexes, $target_indexes, $add_indexes_array,
1061 $alter_indexes_array, $delete_array, $update_array, true);
1065 * Creating and populating tables present in source but absent from target database.
1067 for($q = 0; $q < sizeof($source_tables_uncommon); $q++) {
1068 if (isset($uncommon_tables[$q])) {
1069 PMA_createTargetTables($src_db, $trg_db, $src_link, $trg_link, $source_tables_uncommon, $q, $uncommon_tables_fields, true);
1071 if (isset($row_count[$q])) {
1072 PMA_populateTargetTables($src_db, $trg_db, $src_link, $trg_link, $source_tables_uncommon, $q, $uncommon_tables_fields, true);
1075 echo "</div>";
1079 * Displays the main page when none of the following buttons is pressed
1082 if (! isset($_REQUEST['submit_connect']) && ! isset($_REQUEST['synchronize_db']) && ! isset($_REQUEST['Table_ids']) )
1085 * Displays the sub-page heading
1087 echo '<h2>' . ($GLOBALS['cfg']['MainPageIconic']
1088 ? '<img class="icon" src="' . $pmaThemeImage . 's_sync.png" width="18"'
1089 . ' height="18" alt="" />'
1090 : '')
1091 . __('Synchronize')
1092 .'</h2>';
1094 echo '<div id="serverstatus">
1095 <form name="connection_form" id="connection_form" method="post" action="server_synchronize.php"
1096 >' // TODO: add check if all var. are filled in
1097 . PMA_generate_common_hidden_inputs('', '');
1098 echo '<fieldset>';
1099 echo '<legend>' . __('Synchronize') . '</legend>';
1101 * Displays the forms
1104 $databases = PMA_DBI_get_databases_full(null, false, null, 'SCHEMA_NAME',
1105 'ASC', 0, true);
1107 foreach ($cons as $type) {
1108 if ('src' == $type) {
1109 $database_header = __('Source database');
1110 } else {
1111 $database_header = __('Target database');
1114 <table id="serverconnection_<?php echo $type; ?>_remote" class="data">
1115 <tr>
1116 <th colspan="2"><?php echo $database_header; ?></th>
1117 </tr>
1118 <tr class="odd">
1119 <td colspan="2" style="text-align: center">
1120 <select name="<?php echo $type; ?>_type" id="<?php echo $type; ?>_type" class="server_selector">
1121 <option value="rmt"><?php echo __('Enter manually'); ?></option>
1122 <option value="cur"><?php echo __('Current connection'); ?></option>
1123 <?php
1124 foreach ($GLOBALS['cfg']['Servers'] as $key => $tmp_server) {
1125 if (empty($tmp_server['host'])) {
1126 continue;
1129 if (!empty($tmp_server['verbose'])) {
1130 $label = $tmp_server['verbose'];
1131 } else {
1132 $label = $tmp_server['host'];
1133 if (!empty($tmp_server['port'])) {
1134 $label .= ':' . $tmp_server['port'];
1137 $value = $tmp_server['host'];
1138 $value .= '||||';
1139 if (empty($tmp_server['port']) && empty($tmp_server['socket'])) {
1140 $value .= '3306';
1141 } else {
1142 $value .= $tmp_server['port'];
1144 $value .= '||||';
1145 $value .= $tmp_server['socket'];
1146 $value .= '||||';
1147 $value .= $tmp_server['user'];
1148 $value .= '||||';
1149 $value .= $tmp_server['only_db'];
1150 echo '<option value="' . $value . '">'
1151 . htmlspecialchars(sprintf(__('Configuration: %s'), $label)) . '</option>' . "\n";
1152 } // end foreach
1154 </select>
1155 </td>
1156 </tr>
1157 <tr class="even toggler remote-server">
1158 <td><?php echo __('Host'); ?></td>
1159 <td><input type="text" name="<?php echo $type; ?>_host" class="server-host" /></td>
1160 </tr>
1161 <tr class="odd toggler remote-server">
1162 <td><?php echo __('Port'); ?></td>
1163 <td><input type="text" name="<?php echo $type; ?>_port" class="server-port" value="3306" maxlength="5" size="5" /></td>
1164 </tr>
1165 <tr class="even toggler remote-server">
1166 <td><?php echo __('Socket'); ?></td>
1167 <td><input type="text" name="<?php echo $type; ?>_socket" class="server-socket" /></td>
1168 </tr>
1169 <tr class="odd toggler remote-server">
1170 <td><?php echo __('User name'); ?></td>
1171 <td><input type="text" name="<?php echo $type; ?>_username" class="server-user" /></td>
1172 </tr>
1173 <tr class="even toggler remote-server">
1174 <td><?php echo __('Password'); ?></td>
1175 <td><input type="password" name="<?php echo $type; ?>_pass" class="server-pass" /> </td>
1176 </tr>
1177 <tr class="odd toggler remote-server">
1178 <td><?php echo __('Database'); ?></td>
1179 <td><input type="text" name="<?php echo $type; ?>_db" class="server-db" /></td>
1180 </tr>
1181 <tr class="even toggler current-server" style="display: none;">
1182 <td><?php echo __('Database'); ?></td>
1183 <td>
1184 <?php
1185 // these unset() do not complain if the elements do not exist
1186 unset($databases['mysql']);
1187 unset($databases['information_schema']);
1189 if (count($databases) == 0) {
1190 echo __('No databases');
1191 } else {
1192 echo '
1193 <select name="' . $type . '_db_sel">
1195 foreach ($databases as $db) {
1196 echo ' <option>' . htmlspecialchars($db['SCHEMA_NAME']) . '</option>';
1198 echo '</select>';
1200 echo '</td> </tr>
1201 </table>';
1203 unset ($types, $type);
1205 echo '
1206 </fieldset>
1207 <fieldset class="tblFooters">
1208 <input type="submit" name="submit_connect" value="' . __('Go') .'" id="buttonGo" />
1209 </fieldset>
1210 </form>
1211 </div>
1212 <div class="notice">' . __('Target database will be completely synchronized with source database. Source database will remain unchanged.') . '</div>';
1216 * Displays the footer
1218 require_once './libraries/footer.inc.php';