Translation update done using Pootle.
[phpmyadmin/dkf.git] / server_synchronize.php
blobc5d80772835764526e495be3d2eb884140c1b842
1 <?php
3 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 /**
6 * @version $Id$
7 * @package phpMyAdmin
8 */
10 /**
13 require_once './libraries/common.inc.php';
15 /**
16 * Does the common work
18 $GLOBALS['js_include'][] = 'functions.js';
19 $GLOBALS['js_include'][] = 'server_synchronize.js';
20 require_once './libraries/server_common.inc.php';
22 /**
23 * Contains all the functions specific to synchronization
25 require './libraries/server_synchronize.lib.php';
27 /**
28 * Increases the time limit up to the configured maximum
30 @set_time_limit($cfg['ExecTimeLimit']);
32 /**
33 * Displays the links
35 require './libraries/server_links.inc.php';
37 /**
38 * Enables warnings on the page
40 //$cfg['Error_Handler']['display'] = true;
41 //$cfg['Error_Handler']['gather'] = true;
43 /**
44 * Save the value of token generated for this page
46 if (isset($_REQUEST['token'])) {
47 $_SESSION['token'] = $_REQUEST['token'];
50 // variable for code saving
51 $cons = array ("src", "trg");
53 /**
54 * Displays the page when 'Go' is pressed
57 if ((isset($_REQUEST['submit_connect']))) {
58 foreach ($cons as $con) {
59 ${"{$con}_host"} = $_REQUEST[$con . '_host'];
60 ${"{$con}_username"} = $_REQUEST[$con . '_username'];
61 ${"{$con}_password"} = $_REQUEST[$con . '_pass'];
62 ${"{$con}_port"} = $_REQUEST[$con . '_port'];
63 ${"{$con}_socket"} = $_REQUEST[$con . '_socket'];
64 ${"{$con}_db"} = $_REQUEST[$con . '_db'];
65 ${"{$con}_type"} = $_REQUEST[$con . '_type'];
67 if (${"{$con}_type"} == 'cur') {
68 ${"{$con}_connection"} = null;
69 ${"{$con}_server"} = null;
70 ${"{$con}_db"} = $_REQUEST[$con . '_db_sel'];
71 continue;
74 if (isset(${"{$con}_socket"}) && ! empty(${"{$con}_socket"})) {
75 ${"{$con}_server"}['socket'] = ${"{$con}_socket"};
76 } else {
77 ${"{$con}_server"}['host'] = ${"{$con}_host"};
78 if (isset(${"{$con}_port"}) && ! empty(${"{$con}_port"}) && ((int)${"{$con}_port"} * 1) > 0) {
79 ${"{$con}_server"}['port'] = (int)${"{$con}_port"};
83 ${"{$con}_connection"} = PMA_DBI_connect(${"{$con}_username"}, ${"{$con}_password"}, $is_controluser = false, ${"{$con}_server"}, $auxiliary_connection = true);
84 } // end foreach ($cons as $con)
86 if ((! $src_connection && $src_type != 'cur') || (! $trg_connection && $trg_type != 'cur')) {
87 /**
88 * Displays the connection error string if
89 * connections are not established
92 echo '<div class="error">';
93 if(! $src_connection && $src_type != 'cur') {
94 echo __('Could not connect to the source') . '<br />';
96 if(! $trg_connection && $trg_type != 'cur'){
97 echo __('Could not connect to the target');
99 echo '</div>';
100 unset($_REQUEST['submit_connect']);
102 } else {
104 * Creating the link object for both source and target databases and
105 * selecting the source and target databases using these links
107 foreach ($cons as $con) {
108 if (${"{$con}_connection"} != null) {
109 ${"{$con}_link"} = PMA_DBI_connect(${"{$con}_username"}, ${"{$con}_password"}, $is_controluser = false, ${"{$con}_server"});
110 } else {
111 ${"{$con}_link"} = null;
113 ${"{$con}_db_selected"} = PMA_DBI_select_db(${"{$con}_db"}, ${"{$con}_link"});
114 } // end foreach ($cons as $con)
116 if (($src_db_selected != 1) || ($trg_db_selected != 1)) {
118 * Displays error string if the database(s) did not exist
120 echo '<div class="error">';
121 if ($src_db_selected != 1) {
122 echo sprintf(__('\'%s\' database does not exist.'), htmlspecialchars($src_db));
124 if ($trg_db_selected != 1) {
125 echo sprintf(__('\'%s\' database does not exist.'), htmlspecialchars($trg_db));
127 echo '</div>';
128 unset($_REQUEST['submit_connect']);
130 } else if (($src_db_selected == 1) && ($trg_db_selected == 1)) {
133 * Using PMA_DBI_get_tables() to get all the tables
134 * from target and source databases.
136 $src_tables = PMA_DBI_get_tables($src_db, $src_link);
137 $source_tables_num = sizeof($src_tables);
139 $trg_tables = PMA_DBI_get_tables($trg_db, $trg_link);
140 $target_tables_num = sizeof($trg_tables);
143 * initializing arrays to save matching and non-matching
144 * table names from target and source databases.
146 $unmatched_num_src = 0;
147 $source_tables_uncommon = array();
148 $unmatched_num_trg = 0;
149 $target_tables_uncommon = array();
150 $matching_tables = array();
151 $matching_tables_num = 0;
154 * Using PMA_getMatchingTables to find which of the tables' names match
155 * in target and source database.
157 PMA_getMatchingTables($trg_tables, $src_tables, $matching_tables, $source_tables_uncommon);
159 * Finding the uncommon tables for the target database
160 * using function PMA_getNonMatchingTargetTables()
162 PMA_getNonMatchingTargetTables($trg_tables, $matching_tables, $target_tables_uncommon);
165 * Initializing several arrays to save the data and structure
166 * difference between the source and target databases.
168 $row_count = array(); //number of rows in source table that needs to be created in target database
169 $fields_num = array(); //number of fields in each matching table
170 $delete_array = array(); //stores the primary key values for target tables that have excessive rows than corresponding source tables.
171 $insert_array = array(array(array()));// stores the primary key values for the rows in each source table that are not present in target tables.
172 $update_array = array(array(array())); //stores the primary key values, name of field to be updated, value of the field to be updated for
173 // each row of matching table.
174 $matching_tables_fields = array(); //contains the fields' names for each matching table
175 $matching_tables_keys = array(); //contains the primary keys' names for each matching table
176 $uncommon_tables_fields = array(); //coantains the fields for all the source tables that are not present in target
177 $matching_tables_num = sizeof($matching_tables);
179 $source_columns = array(); //contains the full columns' information for all the source tables' columns
180 $target_columns = array(); //contains the full columns' information for all the target tables' columns
181 $uncommon_columns = array(); //contains names of columns present in source table but absent from the corresponding target table
182 $source_indexes = array(); //contains indexes on all the source tables
183 $target_indexes = array(); //contains indexes on all the target tables
184 $add_indexes_array = array(); //contains the indexes name present in source but absent from target tables
185 $target_tables_keys = array(); //contains the keys of all the target tables
186 $alter_indexes_array = array(); //contains the names of all the indexes for each table that need to be altered in target database
187 $remove_indexes_array = array(); //contains the names of indexes that are excessive in target tables
188 $alter_str_array = array(array()); //contains the criteria for each column that needs to be altered in target tables
189 $add_column_array = array(array()); //contains the name of columns that need to be added in target tables
191 * The criteria array contains all the criteria against which columns are compared for differences.
193 $criteria = array('Field', 'Type', 'Null', 'Collation', 'Key', 'Default', 'Comment');
195 for($i = 0; $i < sizeof($matching_tables); $i++) {
197 * Finding out all the differences structure, data and index diff for all the matching tables only
199 PMA_dataDiffInTables($src_db, $trg_db, $src_link, $trg_link, $matching_tables, $matching_tables_fields, $update_array, $insert_array,
200 $delete_array, $fields_num, $i, $matching_tables_keys);
202 PMA_structureDiffInTables($src_db, $trg_db, $src_link, $trg_link, $matching_tables, $source_columns,
203 $target_columns, $alter_str_array, $add_column_array, $uncommon_columns, $criteria, $target_tables_keys, $i);
205 PMA_indexesDiffInTables($src_db, $trg_db, $src_link, $trg_link, $matching_tables, $source_indexes, $target_indexes,
206 $add_indexes_array, $alter_indexes_array, $remove_indexes_array, $i);
209 for($j = 0; $j < sizeof($source_tables_uncommon); $j++) {
211 * Finding out the number of rows to be added in tables that need to be added in target database
213 PMA_dataDiffInUncommonTables($source_tables_uncommon, $src_db, $src_link, $j, $row_count);
216 * Storing all arrays in session for use when page is reloaded for each button press
218 $_SESSION['matching_tables'] = $matching_tables;
219 $_SESSION['update_array'] = $update_array;
220 $_SESSION['insert_array'] = $insert_array;
221 $_SESSION['src_db'] = $src_db;
222 $_SESSION['trg_db'] = $trg_db;
223 $_SESSION['matching_fields'] = $matching_tables_fields;
224 $_SESSION['src_uncommon_tables'] = $source_tables_uncommon;
225 $_SESSION['src_username'] = $src_username ;
226 $_SESSION['trg_username'] = $trg_username;
227 $_SESSION['src_password'] = $src_password;
228 $_SESSION['trg_password'] = $trg_password;
229 $_SESSION['trg_password'] = $trg_password;
230 $_SESSION['src_server'] = $src_server;
231 $_SESSION['trg_server'] = $trg_server;
232 $_SESSION['src_type'] = $src_type;
233 $_SESSION['trg_type'] = $trg_type;
234 $_SESSION['matching_tables_keys'] = $matching_tables_keys;
235 $_SESSION['uncommon_tables_fields'] = $uncommon_tables_fields;
236 $_SESSION['uncommon_tables_row_count'] = $row_count;
237 $_SESSION['target_tables_uncommon'] = $target_tables_uncommon;
238 $_SESSION['uncommon_tables'] = $source_tables_uncommon;
239 $_SESSION['delete_array'] = $delete_array;
240 $_SESSION['uncommon_columns'] = $uncommon_columns;
241 $_SESSION['source_columns'] = $source_columns;
242 $_SESSION['alter_str_array'] = $alter_str_array;
243 $_SESSION['target_tables_keys'] = $target_tables_keys;
244 $_SESSION['add_column_array'] = $add_column_array;
245 $_SESSION['criteria'] = $criteria;
246 $_SESSION['target_tables'] = $trg_tables;
247 $_SESSION['add_indexes_array'] = $add_indexes_array;
248 $_SESSION['alter_indexes_array'] = $alter_indexes_array;
249 $_SESSION['remove_indexes_array'] = $remove_indexes_array;
250 $_SESSION['source_indexes'] = $source_indexes;
251 $_SESSION['target_indexes'] = $target_indexes;
254 * Displays the sub-heading and icons showing Structure Synchronization and Data Synchronization
256 echo '<form name="synchronize_form" id="synchronize_form" method="post" action="server_synchronize.php">'
257 . PMA_generate_common_hidden_inputs('', '');
258 echo '<table id="serverstatustraffic" class="data" width = "60%">
259 <tr>
260 <td> <h2>'
261 . ($GLOBALS['cfg']['MainPageIconic']
262 ? '<img class="icon" src="' . $pmaThemeImage . 'new_struct.jpg" width="32"'
263 . ' height="32" alt="" />'
264 : '')
265 . __('Structure Synchronization')
266 .'</h2>' .'</td>';
267 echo '<td> <h2>'
268 . ($GLOBALS['cfg']['MainPageIconic']
269 ? '<img class="icon" src="' . $pmaThemeImage . 'new_data.jpg" width="32"'
270 . ' height="32" alt="" />'
271 : '')
272 . __('Data Synchronization')
273 . '</h2>' .'</td>';
274 echo '</tr>
275 </table>';
278 * Displays the tables containing the source tables names, their difference with the target tables and target tables names
280 PMA_syncDisplayHeaderSource($src_db);
281 $odd_row = false;
283 * Display the matching tables' names and difference, first
285 for($i = 0; $i < count($matching_tables); $i++) {
287 * Calculating the number of updates for each matching table
289 if (isset($update_array[$i]) && isset($update_array[$i][0]) &&
290 isset($update_array[$i][0][$matching_tables_keys[$i][0]])) {
291 $num_of_updates = sizeof($update_array[$i]);
292 } else {
293 $num_of_updates = 0;
296 * Calculating the number of insertions for each matching table
298 if (isset($insert_array[$i]) && isset($insert_array[$i][0]) &&
299 isset($insert_array[$i][0][$matching_tables_keys[$i][0]])) {
300 $num_of_insertions = sizeof($insert_array[$i]);
301 } else {
302 $num_of_insertions = 0;
305 * Displays the name of the matching table
307 $odd_row = PMA_syncDisplayBeginTableRow($odd_row);
308 echo '<td>' . htmlspecialchars($matching_tables[$i]) . '</td>
309 <td align="center">';
311 * Calculating the number of alter columns, number of columns to be added, number of columns to be removed,
312 * number of index to be added and removed.
314 $num_alter_cols = 0;
315 $num_insert_cols = 0;
316 $num_remove_cols = 0;
317 $num_add_index = 0;
318 $num_remove_index = 0;
320 if (isset($alter_str_array[$i])) {
321 $num_alter_cols = sizeof($alter_str_array[$i]);
323 if (isset($add_column_array[$i])) {
324 $num_insert_cols = sizeof($add_column_array[$i]);
326 if (isset($uncommon_columns[$i])) {
327 $num_remove_cols = sizeof($uncommon_columns[$i]);
329 if (isset($add_indexes_array[$i])) {
330 $num_add_index = sizeof($add_indexes_array[$i]);
332 if (isset($remove_indexes_array[$i])) {
333 $num_remove_index = sizeof($remove_indexes_array[$i]);
335 if (isset($alter_indexes_array[$i])) {
336 $num_add_index += sizeof($alter_indexes_array[$i]);
337 $num_remove_index += sizeof($alter_indexes_array[$i]);
340 * Display the red button of structure synchronization if there exists any structure difference or index difference.
342 if (($num_alter_cols > 0) || ($num_insert_cols > 0) || ($num_remove_cols > 0) || ($num_add_index > 0) || ($num_remove_index > 0)) {
344 echo '<img class="icon" src="' . $pmaThemeImage . 'new_struct.jpg" width="29" height="29"
345 alt="' . __('Click to select') . '" onmouseover="change_Image(this);" onmouseout="change_Image(this);"
346 onclick="showDetails(' . "'MS" . $i . "','" . $num_alter_cols . "','" .$num_insert_cols .
347 "','" . $num_remove_cols . "','" . $num_add_index . "','" . $num_remove_index . "'"
348 . ', this ,' . "'" . htmlspecialchars($matching_tables[$i]) . "'" . ')"/>';
351 * Display the green button of data synchronization if there exists any data difference.
353 if (isset($update_array[$i]) || isset($insert_array[$i])) {
354 if (isset($update_array[$i][0][$matching_tables_keys[$i][0]]) || isset($insert_array[$i][0][$matching_tables_keys[$i][0]])) {
356 echo '<img class="icon" src="' . $pmaThemeImage . 'new_data.jpg" width="29" height="29"
357 alt="' . __('Click to select') . '" onmouseover="change_Image(this);" onmouseout="change_Image(this);"
358 onclick="showDetails('. "'MD" . $i . "','" . $num_of_updates . "','" . $num_of_insertions .
359 "','" . null . "','" . null . "','" . null . "'" . ', this ,' . "'" . htmlspecialchars($matching_tables[$i]) . "'" . ')" />';
362 echo '</td>
363 </tr>';
366 * Displays the tables' names present in source but missing from target
368 for ($j = 0; $j < count($source_tables_uncommon); $j++) {
369 $odd_row = PMA_syncDisplayBeginTableRow($odd_row);
370 echo '<td> + ' . htmlspecialchars($source_tables_uncommon[$j]) . '</td> ';
372 echo '<td align="center"><img class="icon" src="' . $pmaThemeImage . 'new_struct.jpg" width="29" height="29"
373 alt="' . __('Click to select') . '" onmouseover="change_Image(this);" onmouseout="change_Image(this);"
374 onclick="showDetails(' . "'US" . $j . "','" . null . "','" . null . "','" . null . "','" . null . "','" . null . "'" . ', this ,'
375 . "'" . htmlspecialchars($source_tables_uncommon[$j]) . "'" . ')"/>';
377 if ($row_count[$j] > 0)
379 echo '<img class="icon" src="' . $pmaThemeImage . 'new_data.jpg" width="29" height="29"
380 alt="' . __('Click to select') . '" onmouseover="change_Image(this);" onmouseout="change_Image(this);"
381 onclick="showDetails(' . "'UD" . $j . "','" . null . "','" . $row_count[$j] . "','" . null .
382 "','" . null . "','" . null . "'" . ', this ,' . "'" . htmlspecialchars($source_tables_uncommon[$j]) . "'" . ')" />';
384 echo '</td>
385 </tr>';
387 foreach ($target_tables_uncommon as $tbl_nc_name) {
388 $odd_row = PMA_syncDisplayBeginTableRow($odd_row);
389 echo '<td height="32">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </td><td></td>';
390 echo '</tr>';
393 * Displays the target tables names
395 echo '</table>';
397 $odd_row = PMA_syncDisplayHeaderTargetAndMatchingTables($trg_db, $matching_tables);
398 foreach ($source_tables_uncommon as $tbl_nc_name) {
399 $odd_row = PMA_syncDisplayBeginTableRow($odd_row);
400 echo '<td height="32">' . htmlspecialchars($tbl_nc_name) . ' (' . __('not present') . ')</td>
401 </tr>';
403 foreach ($target_tables_uncommon as $tbl_nc_name) {
404 $odd_row = PMA_syncDisplayBeginTableRow($odd_row);
405 echo '<td> - ' . htmlspecialchars($tbl_nc_name) . '</td>';
406 echo '</tr>';
408 echo '</table>';
409 echo '</div>';
412 * This "list" div will contain a table and each row will depict information about structure/data diffrence in tables.
413 * Rows will be generated dynamically as soon as the colored buttons "D" or "S" are clicked.
416 echo '<div id="list" style = "overflow: auto; width: 1020px; height: 140px;
417 border-left: 1px gray solid; border-bottom: 1px gray solid;
418 padding:0px; margin: 0px">
420 <table>
421 <thead>
422 <tr style="width: 100%;">
423 <th id="table_name" style="width: 10%;" colspan="1">' . __('Table') . ' </th>
424 <th id="str_diff" style="width: 65%;" colspan="6">' . __('Structure Difference') . ' </th>
425 <th id="data_diff" style="width: 20%;" colspan="2">' . __('Data Difference') . '</th>
426 </tr>
427 <tr style="width: 100%;">
428 <th style="width: 10%;">' . __('Table name') . '</th>
429 <th style="width: 10%;">' . __('Create table'). '</th>
430 <th style="width: 11%;">' . __('Add column(s)') . '</th>
431 <th style="width: 13%;">' . __('Remove column(s)') . '</th>
432 <th style="width: 11%;">' . __('Alter column(s)') . '</th>
433 <th style="width: 12%;">' . __('Remove index(s)') . '</th>
434 <th style="width: 11%;">' . __('Apply index(s)') . '</th>
435 <th style="width: 10%;">'. __('Update row(s)') . '</th>
436 <th style="width: 10%;">' . __('Insert row(s)') . '</th>
437 </tr>
438 </thead>
439 <tbody></tbody>
440 </table>
441 </div>';
443 * This fieldset displays the checkbox to confirm deletion of previous rows from target tables
445 echo '<fieldset>
446 <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>
447 </fieldset>
448 <fieldset class="tblFooters">';
449 echo '<input type="button" name="apply_changes" value="' . __('Apply Selected Changes')
450 . '" onclick ="ApplySelectedChanges(' . "'" . htmlspecialchars($_SESSION['token']) . "'" . ')" />';
451 echo '<input type="submit" name="synchronize_db" value="' . __('Synchronize Databases') . '" />' . '</fieldset>';
452 echo '</form>';
455 } // end if ((isset($_REQUEST['submit_connect'])))
458 * Display the page when 'Apply Selected Changes' is pressed
460 if (isset($_REQUEST['Table_ids'])) {
462 * Displays success message
464 echo '<div class="success">' . __('Selected target tables have been synchronized with source tables.') . '</div>';
466 $src_db = $_SESSION['src_db'];
467 $trg_db = $_SESSION['trg_db'];
468 $update_array = $_SESSION['update_array'];
469 $insert_array = $_SESSION['insert_array'];
470 $src_username = $_SESSION['src_username'];
471 $trg_username = $_SESSION['trg_username'];
472 $src_password = $_SESSION['src_password'];
473 $trg_password = $_SESSION['trg_password'];
474 $src_server = $_SESSION['src_server'];
475 $trg_server = $_SESSION['trg_server'];
476 $src_type = $_SESSION['src_type'];
477 $trg_type = $_SESSION['trg_type'];
478 $uncommon_tables = $_SESSION['uncommon_tables'];
479 $matching_tables = $_SESSION['matching_tables'];
480 $matching_tables_keys = $_SESSION['matching_tables_keys'];
481 $matching_tables_fields = $_SESSION['matching_fields'];
482 $source_tables_uncommon = $_SESSION['src_uncommon_tables'];
483 $uncommon_tables_fields = $_SESSION['uncommon_tables_fields'];
484 $target_tables_uncommon = $_SESSION['target_tables_uncommon'];
485 $row_count = $_SESSION['uncommon_tables_row_count'];
486 $target_tables = $_SESSION['target_tables'];
488 $delete_array = $_SESSION['delete_array'];
489 $uncommon_columns = $_SESSION['uncommon_columns'];
490 $source_columns = $_SESSION['source_columns'];
491 $alter_str_array = $_SESSION['alter_str_array'];
492 $criteria = $_SESSION['criteria'];
493 $target_tables_keys = $_SESSION['target_tables_keys'];
494 $add_column_array = $_SESSION['add_column_array'];
495 $add_indexes_array = $_SESSION['add_indexes_array'];
496 $alter_indexes_array = $_SESSION['alter_indexes_array'];
497 $remove_indexes_array = $_SESSION['remove_indexes_array'];
498 $source_indexes = $_SESSION['source_indexes'];
499 $target_indexes = $_SESSION['target_indexes'];
500 $uncommon_cols = $uncommon_columns;
503 * Creating link object for source and target databases
505 foreach ($cons as $con) {
506 if (${"{$con}_type"} != "cur") {
507 ${"{$con}_link"} = PMA_DBI_connect(${"{$con}_username"}, ${"{$con}_password"}, $is_controluser = false, ${"{$con}_server"});
508 } else {
509 ${"{$con}_link"} = null;
510 // working on current server, so initialize this for tracking
511 // (does not work if user defined current server as a remote one)
512 $GLOBALS['db'] = ${"{$con}_db"};
514 } // end foreach ($cons as $con)
517 * Initializing arrays to save the table ids whose data and structure difference is to be applied
519 $matching_table_data_diff = array(); //stores id of matching table having data difference
520 $matching_table_structure_diff = array(); //stores id of matching tables having structure difference
521 $uncommon_table_structure_diff = array(); //stores id of uncommon tables having structure difference
522 $uncommon_table_data_diff = array(); //stores id of uncommon tables having data difference
524 for ($i = 0; isset($_REQUEST[$i]); $i++ ) {
525 if (isset($_REQUEST[$i])) {
526 $table_id = explode("US", $_REQUEST[$i]);
527 if (isset($table_id[1])) {
528 $uncommon_table_structure_diff[] = $table_id[1];
530 $table_id = explode("UD", $_REQUEST[$i]);
531 if (isset($table_id[1])) {
532 $uncommon_table_data_diff[] = $table_id[1];
534 $table_id = explode("MS", $_REQUEST[$i]);
535 if (isset($table_id[1])) {
536 $matching_table_structure_diff[] = $table_id[1];
539 $table_id = explode("MD", $_REQUEST[$i]);
540 if (isset($table_id[1])) {
541 $matching_table_data_diff[] = $table_id[1];
544 } // end for
546 * Applying the structure difference on selected matching tables
548 for($q = 0; $q < sizeof($matching_table_structure_diff); $q++)
550 if (isset($alter_str_array[$matching_table_structure_diff[$q]])) {
552 PMA_alterTargetTableStructure($trg_db, $trg_link, $matching_tables, $source_columns, $alter_str_array, $matching_tables_fields,
553 $criteria, $matching_tables_keys, $target_tables_keys, $matching_table_structure_diff[$q], false);
555 unset($alter_str_array[$matching_table_structure_diff[$q]]);
557 if (isset($add_column_array[$matching_table_structure_diff[$q]])) {
559 PMA_findDeleteRowsFromTargetTables($delete_array, $matching_tables, $matching_table_structure_diff[$q], $target_tables_keys,
560 $matching_tables_keys, $trg_db, $trg_link, $src_db, $src_link);
562 if (isset($delete_array[$matching_table_structure_diff[$q]])) {
564 PMA_deleteFromTargetTable($trg_db, $trg_link, $matching_tables, $matching_table_structure_diff[$q], $target_tables_keys, $delete_array, false);
566 unset($delete_array[$matching_table_structure_diff[$q]]);
568 PMA_addColumnsInTargetTable($src_db, $trg_db,$src_link, $trg_link, $matching_tables, $source_columns, $add_column_array, $matching_tables_fields,
569 $criteria, $matching_tables_keys, $target_tables_keys, $uncommon_tables,$uncommon_tables_fields, $matching_table_structure_diff[$q], $uncommon_cols, false);
571 unset($add_column_array[$matching_table_structure_diff[$q]]);
573 if (isset($uncommon_columns[$matching_table_structure_diff[$q]])) {
575 PMA_removeColumnsFromTargetTable($trg_db, $trg_link, $matching_tables, $uncommon_columns, $matching_table_structure_diff[$q], false);
577 unset($uncommon_columns[$matching_table_structure_diff[$q]]);
579 if (isset($add_indexes_array[$matching_table_structure_diff[$q]]) || isset($remove_indexes_array[$matching_table_structure_diff[$q]])
580 || isset($alter_indexes_array[$matching_table_structure_diff[$q]])) {
582 PMA_applyIndexesDiff ($trg_db, $trg_link, $matching_tables, $source_indexes, $target_indexes, $add_indexes_array, $alter_indexes_array,
583 $remove_indexes_array, $matching_table_structure_diff[$q], false);
585 unset($add_indexes_array[$matching_table_structure_diff[$q]]);
586 unset($alter_indexes_array[$matching_table_structure_diff[$q]]);
587 unset($remove_indexes_array[$matching_table_structure_diff[$q]]);
591 * Applying the data difference. First checks if structure diff is applied or not.
592 * If not, then apply structure difference first then apply data difference.
594 for($p = 0; $p < sizeof($matching_table_data_diff); $p++)
596 if ($_REQUEST['checked'] == 'true') {
598 PMA_findDeleteRowsFromTargetTables($delete_array, $matching_tables, $matching_table_data_diff[$p], $target_tables_keys,
599 $matching_tables_keys, $trg_db, $trg_link, $src_db, $src_link);
601 if (isset($delete_array[$matching_table_data_diff[$p]])) {
603 PMA_deleteFromTargetTable($trg_db, $trg_link, $matching_tables, $matching_table_data_diff[$p], $target_tables_keys, $delete_array, false);
605 unset($delete_array[$matching_table_data_diff[$p]]);
608 if (isset($alter_str_array[$matching_table_data_diff[$p]])) {
610 PMA_alterTargetTableStructure($trg_db, $trg_link, $matching_tables, $source_columns, $alter_str_array, $matching_tables_fields,
611 $criteria, $matching_tables_keys, $target_tables_keys, $matching_table_data_diff[$p], false);
613 unset($alter_str_array[$matching_table_data_diff[$p]]);
615 if (isset($add_column_array[$matching_table_data_diff[$p]])) {
617 PMA_findDeleteRowsFromTargetTables($delete_array, $matching_tables, $matching_table_data_diff[$p], $target_tables_keys,
618 $matching_tables_keys, $trg_db, $trg_link, $src_db, $src_link);
620 if (isset($delete_array[$matching_table_data_diff[$p]])) {
622 PMA_deleteFromTargetTable($trg_db, $trg_link, $matching_tables, $matching_table_data_diff[$p], $target_tables_keys, $delete_array, false);
624 unset($delete_array[$matching_table_data_diff[$p]]);
626 PMA_addColumnsInTargetTable($src_db, $trg_db,$src_link, $trg_link, $matching_tables, $source_columns, $add_column_array, $matching_tables_fields,
627 $criteria, $matching_tables_keys, $target_tables_keys, $uncommon_tables, $uncommon_tables_fields, $matching_table_data_diff[$p], $uncommon_cols, false);
629 unset($add_column_array[$matching_table_data_diff[$p]]);
631 if (isset($uncommon_columns[$matching_table_data_diff[$p]])) {
633 PMA_removeColumnsFromTargetTable($trg_db, $trg_link, $matching_tables, $uncommon_columns, $matching_table_data_diff[$p], false);
635 unset($uncommon_columns[$matching_table_data_diff[$p]]);
637 if ((isset($matching_table_structure_diff[$q]) && isset($add_indexes_array[$matching_table_structure_diff[$q]]))
638 || (isset($matching_table_structure_diff[$q]) && isset($remove_indexes_array[$matching_table_structure_diff[$q]]))
639 || (isset($matching_table_structure_diff[$q]) && isset($alter_indexes_array[$matching_table_structure_diff[$q]]))) {
641 PMA_applyIndexesDiff ($trg_db, $trg_link, $matching_tables, $source_indexes, $target_indexes, $add_indexes_array, $alter_indexes_array,
642 $remove_indexes_array, $matching_table_structure_diff[$q], false);
644 unset($add_indexes_array[$matching_table_structure_diff[$q]]);
645 unset($alter_indexes_array[$matching_table_structure_diff[$q]]);
646 unset($remove_indexes_array[$matching_table_structure_diff[$q]]);
649 * Applying the data difference.
651 PMA_updateTargetTables($matching_tables, $update_array, $src_db, $trg_db, $trg_link, $matching_table_data_diff[$p], $matching_tables_keys, false);
653 PMA_insertIntoTargetTable($matching_tables, $src_db, $trg_db, $src_link, $trg_link , $matching_tables_fields, $insert_array,
654 $matching_table_data_diff[$p], $matching_tables_keys, $source_columns, $add_column_array, $criteria, $target_tables_keys,
655 $uncommon_tables, $uncommon_tables_fields, $uncommon_cols, $alter_str_array, $source_indexes, $target_indexes, $add_indexes_array,
656 $alter_indexes_array, $delete_array, $update_array, false);
659 * Updating the session variables to the latest values of the arrays.
661 $_SESSION['delete_array'] = $delete_array;
662 $_SESSION['uncommon_columns'] = $uncommon_columns;
663 $_SESSION['alter_str_array'] = $alter_str_array;
664 $_SESSION['add_column_array'] = $add_column_array;
665 $_SESSION['add_indexes_array'] = $add_indexes_array;
666 $_SESSION['remove_indexes_array'] = $remove_indexes_array;
667 $_SESSION['insert_array'] = $insert_array;
668 $_SESSION['update_array'] = $update_array;
671 * Applying structure difference to selected non-matching tables (present in Source but absent from Target).
673 for($s = 0; $s < sizeof($uncommon_table_structure_diff); $s++)
675 PMA_createTargetTables($src_db, $trg_db, $src_link, $trg_link, $uncommon_tables, $uncommon_table_structure_diff[$s], $uncommon_tables_fields, false);
676 $_SESSION['uncommon_tables_fields'] = $uncommon_tables_fields;
678 unset($uncommon_tables[$uncommon_table_structure_diff[$s]]);
681 * Applying data difference to selected non-matching tables (present in Source but absent from Target).
682 * Before data synchronization, structure synchronization is confirmed.
684 for($r = 0; $r < sizeof($uncommon_table_data_diff); $r++)
686 if (!(in_array($uncommon_table_data_diff[$r], $uncommon_table_structure_diff))) {
687 if (isset($uncommon_tables[$uncommon_table_data_diff[$r]])) {
689 PMA_createTargetTables($src_db, $trg_db, $src_link, $trg_link, $uncommon_tables, $uncommon_table_data_diff[$r],
690 $uncommon_tables_fields, false);
691 $_SESSION['uncommon_tables_fields'] = $uncommon_tables_fields;
693 unset($uncommon_tables[$uncommon_table_data_diff[$r]]);
696 PMA_populateTargetTables($src_db, $trg_db, $src_link, $trg_link, $source_tables_uncommon, $uncommon_table_data_diff[$r],
697 $_SESSION['uncommon_tables_fields'], false);
699 unset($row_count[$uncommon_table_data_diff[$r]]);
702 * Again all the tables from source and target database are displayed with their differences.
703 * The differences have been removed from tables that have been synchronized
705 echo '<form name="applied_difference" id="synchronize_form" method="post" action="server_synchronize.php">'
706 . PMA_generate_common_hidden_inputs('', '');
708 PMA_syncDisplayHeaderSource($src_db);
709 $odd_row = false;
710 for($i = 0; $i < count($matching_tables); $i++) {
711 $odd_row = PMA_syncDisplayBeginTableRow($odd_row);
712 echo '<td align="center">' . htmlspecialchars($matching_tables[$i]) . '</td>
713 <td align="center">';
715 $num_alter_cols = 0;
716 $num_insert_cols = 0;
717 $num_remove_cols = 0;
718 $num_add_index = 0;
719 $num_remove_index = 0;
721 if (isset($alter_str_array[$i])) {
722 $num_alter_cols = sizeof($alter_str_array[$i]);
724 if (isset($add_column_array[$i])) {
725 $num_insert_cols = sizeof($add_column_array[$i]);
727 if (isset($uncommon_columns[$i])) {
728 $num_remove_cols = sizeof($uncommon_columns[$i]);
730 if (isset($add_indexes_array[$i])) {
731 $num_add_index = sizeof($add_indexes_array[$i]);
733 if (isset($remove_indexes_array[$i])) {
734 $num_remove_index = sizeof($remove_indexes_array[$i]);
737 if (($num_alter_cols > 0) || ($num_insert_cols > 0) || ($num_remove_cols > 0) || ($num_add_index > 0) || ($num_remove_index > 0)) {
738 echo '<img class="icon" src="' . $pmaThemeImage . 'new_struct.jpg" width="29" height="29"
739 alt="' . __('Click to select') . '" onmouseover="change_Image(this);" onmouseout="change_Image(this);"
740 onclick="showDetails(' . "'MS" . $i . "','" . $num_alter_cols . "','" . $num_insert_cols . "','" . $num_remove_cols . "','" . $num_add_index . "','" . $num_remove_index . "'" .',
741 this ,' . "'" . htmlspecialchars($matching_tables[$i]) . "'" . ')"/>';
743 if (!(in_array($i, $matching_table_data_diff))) {
745 if (isset($matching_tables_keys[$i][0]) && isset($update_array[$i][0][$matching_tables_keys[$i][0]])) {
746 if (isset($update_array[$i])) {
747 $num_of_updates = sizeof($update_array[$i]);
748 } else {
749 $num_of_updates = 0;
751 } else {
752 $num_of_updates = 0;
754 if (isset($matching_tables_keys[$i][0]) && isset($insert_array[$i][0][$matching_tables_keys[$i][0]])) {
755 if (isset($insert_array[$i])) {
756 $num_of_insertions = sizeof($insert_array[$i]);
757 } else {
758 $num_of_insertions = 0;
760 } else {
761 $num_of_insertions = 0;
764 if ((isset($matching_tables_keys[$i][0]) && isset($update_array[$i][0][$matching_tables_keys[$i][0]]))
765 || (isset($matching_tables_keys[$i][0]) && isset($insert_array[$i][0][$matching_tables_keys[$i][0]]))) {
766 echo '<img class="icon" src="' . $pmaThemeImage . 'new_data.jpg" width="29" height="29"
767 alt="' . __('Click to select') . '" onmouseover="change_Image(this);" onmouseout="change_Image(this);"
768 onclick="showDetails(' . "'MD" . $i . "','" . $num_of_updates . "','" . $num_of_insertions .
769 "','" . null . "','" . null . "','" . null . "'" .', this ,' . "'" . htmlspecialchars($matching_tables[$i]) . "'" . ')" />';
771 } else {
772 unset($update_array[$i]);
773 unset($insert_array[$i]);
775 echo '</td>
776 </tr>';
779 * placing updated value of arrays in session
782 $_SESSION['update_array'] = $update_array;
783 $_SESSION['insert_array'] = $insert_array;
785 for ($j = 0; $j < count($source_tables_uncommon); $j++) {
786 $odd_row = PMA_syncDisplayBeginTableRow($odd_row);
787 echo '<td align="center"> + ' . htmlspecialchars($source_tables_uncommon[$j]) . '</td>
788 <td align="center">';
790 * Display the difference only when it has not been applied
792 if (!(in_array($j, $uncommon_table_structure_diff))) {
793 if (isset($uncommon_tables[$j])) {
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(' . "'US" . $j . "','" . null . "','" . null . "','" . null . "','" . null . "','" . null . "'" . ', this ,' . "'" . htmlspecialchars($source_tables_uncommon[$j]) . "'" . ')"/>' .' ';
798 } else {
799 unset($uncommon_tables[$j]);
802 * Display the difference only when it has not been applied
804 if (!(in_array($j, $uncommon_table_data_diff))) {
805 if (isset($row_count[$j]) && ($row_count > 0)) {
806 echo '<img class="icon" src="' . $pmaThemeImage . 'new_data.jpg" width="29" height="29"
807 alt="' . __('Click to select') . '" onmouseover="change_Image(this);" onmouseout="change_Image(this);"
808 onclick="showDetails(' . "'UD" . $j . "','" . null ."','" . $row_count[$j] ."','"
809 . null . "','" . null . "','" . null . "'" . ', this ,' . "'". htmlspecialchars($source_tables_uncommon[$j]) . "'" . ')" />';
811 } else {
812 unset($row_count[$j]);
815 echo '</td>
816 </tr>';
819 * placing the latest values of arrays in session
822 $_SESSION['uncommon_tables'] = $uncommon_tables;
823 $_SESSION['uncommon_tables_row_count'] = $row_count;
827 * Displaying the target database tables
829 foreach ($target_tables_uncommon as $tbl_nc_name) {
830 $odd_row = PMA_syncDisplayBeginTableRow($odd_row);
831 echo '<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </td><td></td>';
832 echo '</tr>';
834 echo '</table>';
835 $odd_row = PMA_syncDisplayHeaderTargetAndMatchingTables($trg_db, $matching_tables);
836 foreach ($source_tables_uncommon as $tbl_nc_name) {
837 $odd_row = PMA_syncDisplayBeginTableRow($odd_row);
838 if (in_array($tbl_nc_name, $uncommon_tables)) {
839 echo '<td>' . htmlspecialchars($tbl_nc_name) . ' (' . __('not present') . ')</td>';
840 } else {
841 echo '<td>' . htmlspecialchars($tbl_nc_name) . '</td>';
843 echo '
844 </tr>';
846 foreach ($target_tables_uncommon as $tbl_nc_name) {
847 $odd_row = PMA_syncDisplayBeginTableRow($odd_row);
848 echo '<td> - ' . htmlspecialchars($tbl_nc_name) . '</td>';
849 echo '</tr>';
851 echo '</table>
852 </div>';
855 * This "list" div will contain a table and each row will depict information about structure/data diffrence in tables.
856 * Rows will be generated dynamically as soon as the colored buttons "D" or "S" are clicked.
859 echo '<div id="list" style = "overflow: auto; width: 1020px; height: 140px;
860 border-left: 1px gray solid; border-bottom: 1px gray solid;
861 padding:0px; margin: 0px">';
863 echo '<table>
864 <thead>
865 <tr style="width: 100%;">
866 <th id="table_name" style="width: 10%;" colspan="1">' . __('Table') . ' </th>
867 <th id="str_diff" style="width: 65%;" colspan="6">' . __('Structure Difference') . ' </th>
868 <th id="data_diff" style="width: 20%;" colspan="2">' . __('Data Difference') . '</th>
869 </tr>
870 <tr style="width: 100%;">
871 <th style="width: 10%;">' . __('Table name') . '</th>
872 <th style="width: 10%;">' . __('Create table'). '</th>
873 <th style="width: 11%;">' . __('Add column(s)') . '</th>
874 <th style="width: 13%;">' . __('Remove column(s)') . '</th>
875 <th style="width: 11%;">' . __('Alter column(s)') . '</th>
876 <th style="width: 12%;">' . __('Remove index(s)') . '</th>
877 <th style="width: 11%;">' . __('Apply index(s)') . '</th>
878 <th style="width: 10%;">' . __('Update row(s)') . '</th>
879 <th style="width: 10%;">' . __('Insert row(s)') . '</th>
880 </tr>
881 </thead>
882 <tbody></tbody>
883 </table>
884 </div>';
887 * This fieldset displays the checkbox to confirm deletion of previous rows from target tables
889 echo '<fieldset>
890 <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>
891 </fieldset>';
893 echo '<fieldset class="tblFooters">';
894 echo '<input type="button" name="apply_changes" value="' . __('Apply Selected Changes') . '"
895 onclick ="ApplySelectedChanges(' . "'" . htmlspecialchars($_SESSION['token']) . "'" .')" />';
896 echo '<input type="submit" name="synchronize_db" value="' . __('Synchronize Databases') . '" />'
897 . '</fieldset>';
898 echo '</form>';
902 * Displays the page when 'Synchronize Databases' is pressed.
905 if (isset($_REQUEST['synchronize_db'])) {
907 $src_db = $_SESSION['src_db'];
908 $trg_db = $_SESSION['trg_db'];
909 $update_array = $_SESSION['update_array'];
910 $insert_array = $_SESSION['insert_array'];
911 $src_username = $_SESSION['src_username'];
912 $trg_username = $_SESSION['trg_username'];
913 $src_password = $_SESSION['src_password'];
914 $trg_password = $_SESSION['trg_password'];
915 $matching_tables = $_SESSION['matching_tables'];
916 $matching_tables_keys = $_SESSION['matching_tables_keys'];
917 $matching_tables_fields = $_SESSION['matching_fields'];
918 $source_tables_uncommon = $_SESSION['src_uncommon_tables'];
919 $uncommon_tables_fields = $_SESSION['uncommon_tables_fields'];
920 $target_tables_uncommon = $_SESSION['target_tables_uncommon'];
921 $row_count = $_SESSION['uncommon_tables_row_count'];
922 $uncommon_tables = $_SESSION['uncommon_tables'];
923 $target_tables = $_SESSION['target_tables'];
925 $delete_array = $_SESSION['delete_array'];
926 $uncommon_columns = $_SESSION['uncommon_columns'];
927 $source_columns = $_SESSION['source_columns'];
928 $alter_str_array = $_SESSION['alter_str_array'];
929 $criteria = $_SESSION['criteria'];
930 $target_tables_keys = $_SESSION['target_tables_keys'];
931 $add_column_array = $_SESSION['add_column_array'];
932 $add_indexes_array = $_SESSION['add_indexes_array'];
933 $alter_indexes_array = $_SESSION['alter_indexes_array'];
934 $remove_indexes_array = $_SESSION['remove_indexes_array'];
935 $source_indexes = $_SESSION['source_indexes'];
936 $target_indexes = $_SESSION['target_indexes'];
937 $uncommon_cols = $uncommon_columns;
940 * Display success message.
942 echo '<div class="success">' . __('Target database has been synchronized with source database') . '</div>';
944 * Displaying all the tables of source and target database and now no difference is there.
946 PMA_syncDisplayHeaderSource($src_db);
948 $odd_row = false;
949 for($i = 0; $i < count($matching_tables); $i++)
951 $odd_row = PMA_syncDisplayBeginTableRow($odd_row);
952 echo '<td>' . htmlspecialchars($matching_tables[$i]) . '</td>
953 <td></td>
954 </tr>';
956 for ($j = 0; $j < count($source_tables_uncommon); $j++) {
957 $odd_row = PMA_syncDisplayBeginTableRow($odd_row);
958 echo '<td> + ' . htmlspecialchars($source_tables_uncommon[$j]) . '</td> ';
959 echo '<td></td>
960 </tr>';
962 foreach ($target_tables_uncommon as $tbl_nc_name) {
963 $odd_row = PMA_syncDisplayBeginTableRow($odd_row);
964 echo '<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </td><td></td>';
965 echo '</tr>';
967 echo '</table>';
968 $odd_row = PMA_syncDisplayHeaderTargetAndMatchingTables($trg_db, $matching_tables);
969 foreach ($source_tables_uncommon as $tbl_nc_name) {
970 $odd_row = PMA_syncDisplayBeginTableRow($odd_row);
971 echo '<td>' . htmlspecialchars($tbl_nc_name) . ' </td>
972 </tr>';
974 foreach ($target_tables_uncommon as $tbl_nc_name) {
975 $odd_row = PMA_syncDisplayBeginTableRow($odd_row);
976 echo '<td> ' . htmlspecialchars($tbl_nc_name) . '</td>';
977 echo '</tr>';
979 echo '</table> </div>';
982 * connecting the source and target servers
984 if ('cur' != $_SESSION['src_type']) {
985 $src_link = PMA_DBI_connect($src_username, $src_password, $is_controluser = false, $_SESSION['src_server']);
986 } else {
987 $src_link = $GLOBALS['userlink'];
988 // working on current server, so initialize this for tracking
989 // (does not work if user defined current server as a remote one)
990 $GLOBALS['db'] = $_SESSION['src_db'];
992 if ('cur' != $_SESSION['trg_type']) {
993 $trg_link = PMA_DBI_connect($trg_username, $trg_password, $is_controluser = false, $_SESSION['trg_server']);
994 } else {
995 $trg_link = $GLOBALS['userlink'];
996 // working on current server, so initialize this for tracking
997 $GLOBALS['db'] = $_SESSION['trg_db'];
1001 * Displaying the queries.
1003 echo '<h5>' . __('The following queries have been executed:') . '</h5>';
1004 echo '<div id="serverstatus" style = "overflow: auto; width: 1050px; height: 180px;
1005 border-left: 1px gray solid; border-bottom: 1px gray solid; padding: 0px; margin: 0px"> ';
1007 * Applying all sorts of differences for each matching table
1009 for($p = 0; $p < sizeof($matching_tables); $p++) {
1011 * If the check box is checked for deleting previous rows from the target database tables then
1012 * first find out rows to be deleted and then delete the rows.
1014 if (isset($_REQUEST['delete_rows'])) {
1015 PMA_findDeleteRowsFromTargetTables($delete_array, $matching_tables, $p, $target_tables_keys, $matching_tables_keys,
1016 $trg_db, $trg_link, $src_db, $src_link);
1018 if (isset($delete_array[$p])) {
1019 PMA_deleteFromTargetTable($trg_db, $trg_link, $matching_tables, $p, $target_tables_keys, $delete_array, true);
1020 unset($delete_array[$p]);
1023 if (isset($alter_str_array[$p])) {
1024 PMA_alterTargetTableStructure($trg_db, $trg_link, $matching_tables, $source_columns, $alter_str_array, $matching_tables_fields,
1025 $criteria, $matching_tables_keys, $target_tables_keys, $p, true);
1026 unset($alter_str_array[$p]);
1028 if (! empty($add_column_array[$p])) {
1029 PMA_findDeleteRowsFromTargetTables($delete_array, $matching_tables, $p, $target_tables_keys, $matching_tables_keys,
1030 $trg_db, $trg_link, $src_db, $src_link);
1032 if (isset($delete_array[$p])) {
1033 PMA_deleteFromTargetTable($trg_db, $trg_link, $matching_tables, $p, $target_tables_keys, $delete_array, true);
1034 unset($delete_array[$p]);
1036 PMA_addColumnsInTargetTable($src_db, $trg_db, $src_link, $trg_link, $matching_tables, $source_columns, $add_column_array,
1037 $matching_tables_fields, $criteria, $matching_tables_keys, $target_tables_keys, $uncommon_tables, $uncommon_tables_fields,
1038 $p, $uncommon_cols, true);
1039 unset($add_column_array[$p]);
1041 if (isset($uncommon_columns[$p])) {
1042 PMA_removeColumnsFromTargetTable($trg_db, $trg_link, $matching_tables, $uncommon_columns, $p, true);
1043 unset($uncommon_columns[$p]);
1045 if (isset($matching_table_structure_diff) &&
1046 (isset($add_indexes_array[$matching_table_structure_diff[$p]])
1047 || isset($remove_indexes_array[$matching_table_structure_diff[$p]])
1048 || isset($alter_indexes_array[$matching_table_structure_diff[$p]]))) {
1049 PMA_applyIndexesDiff ($trg_db, $trg_link, $matching_tables, $source_indexes, $target_indexes, $add_indexes_array, $alter_indexes_array,
1050 $remove_indexes_array, $matching_table_structure_diff[$p], true);
1052 unset($add_indexes_array[$matching_table_structure_diff[$p]]);
1053 unset($alter_indexes_array[$matching_table_structure_diff[$p]]);
1054 unset($remove_indexes_array[$matching_table_structure_diff[$p]]);
1057 PMA_updateTargetTables($matching_tables, $update_array, $src_db, $trg_db, $trg_link, $p, $matching_tables_keys, true);
1059 PMA_insertIntoTargetTable($matching_tables, $src_db, $trg_db, $src_link, $trg_link , $matching_tables_fields, $insert_array, $p,
1060 $matching_tables_keys, $matching_tables_keys, $source_columns, $add_column_array, $criteria, $target_tables_keys, $uncommon_tables,
1061 $uncommon_tables_fields,$uncommon_cols, $alter_str_array,$source_indexes, $target_indexes, $add_indexes_array,
1062 $alter_indexes_array, $delete_array, $update_array, true);
1066 * Creating and populating tables present in source but absent from target database.
1068 for($q = 0; $q < sizeof($source_tables_uncommon); $q++) {
1069 if (isset($uncommon_tables[$q])) {
1070 PMA_createTargetTables($src_db, $trg_db, $src_link, $trg_link, $source_tables_uncommon, $q, $uncommon_tables_fields, true);
1072 if (isset($row_count[$q])) {
1073 PMA_populateTargetTables($src_db, $trg_db, $src_link, $trg_link, $source_tables_uncommon, $q, $uncommon_tables_fields, true);
1076 echo "</div>";
1080 * Displays the main page when none of the following buttons is pressed
1083 if (! isset($_REQUEST['submit_connect']) && ! isset($_REQUEST['synchronize_db']) && ! isset($_REQUEST['Table_ids']) )
1086 * Displays the sub-page heading
1088 echo '<h2>' . ($GLOBALS['cfg']['MainPageIconic']
1089 ? '<img class="icon" src="' . $pmaThemeImage . 's_sync.png" width="18"'
1090 . ' height="18" alt="" />'
1091 : '')
1092 . __('Synchronize')
1093 .'</h2>';
1095 echo '<div id="serverstatus">
1096 <form name="connection_form" id="connection_form" method="post" action="server_synchronize.php"
1097 >' // TODO: add check if all var. are filled in
1098 . PMA_generate_common_hidden_inputs('', '');
1099 echo '<fieldset>';
1100 echo '<legend>' . __('Synchronize') . '</legend>';
1102 * Displays the forms
1105 $databases = PMA_DBI_get_databases_full(null, false, null, 'SCHEMA_NAME',
1106 'ASC', 0, true);
1108 foreach ($cons as $type) {
1109 if ('src' == $type) {
1110 $database_header = __('Source database');
1111 } else {
1112 $database_header = __('Target database');
1115 <table id="serverconnection_<?php echo $type; ?>_remote" class="data">
1116 <tr>
1117 <th colspan="2"><?php echo $database_header; ?></th>
1118 </tr>
1119 <tr class="odd">
1120 <td colspan="2" style="text-align: center">
1121 <select name="<?php echo $type; ?>_type" id="<?php echo $type; ?>_type" class="server_selector">
1122 <option value="rmt"><?php echo __('Enter manually'); ?></option>
1123 <option value="cur"><?php echo __('Current connection'); ?></option>
1124 <?php
1125 foreach ($GLOBALS['cfg']['Servers'] as $key => $tmp_server) {
1126 if (empty($tmp_server['host'])) {
1127 continue;
1130 if (!empty($tmp_server['verbose'])) {
1131 $label = $tmp_server['verbose'];
1132 } else {
1133 $label = $tmp_server['host'];
1134 if (!empty($tmp_server['port'])) {
1135 $label .= ':' . $tmp_server['port'];
1138 $value = $tmp_server['host'];
1139 $value .= '||||';
1140 if (empty($tmp_server['port']) && empty($tmp_server['socket'])) {
1141 $value .= '3306';
1142 } else {
1143 $value .= $tmp_server['port'];
1145 $value .= '||||';
1146 $value .= $tmp_server['socket'];
1147 $value .= '||||';
1148 $value .= $tmp_server['user'];
1149 $value .= '||||';
1150 $value .= $tmp_server['only_db'];
1151 echo '<option value="' . $value . '">'
1152 . htmlspecialchars(sprintf(__('Configuration: %s'), $label)) . '</option>' . "\n";
1153 } // end foreach
1155 </select>
1156 </td>
1157 </tr>
1158 <tr class="even toggler remote-server">
1159 <td><?php echo __('Host'); ?></td>
1160 <td><input type="text" name="<?php echo $type; ?>_host" class="server-host" /></td>
1161 </tr>
1162 <tr class="odd toggler remote-server">
1163 <td><?php echo __('Port'); ?></td>
1164 <td><input type="text" name="<?php echo $type; ?>_port" class="server-port" value="3306" maxlength="5" size="5" /></td>
1165 </tr>
1166 <tr class="even toggler remote-server">
1167 <td><?php echo __('Socket'); ?></td>
1168 <td><input type="text" name="<?php echo $type; ?>_socket" class="server-socket" /></td>
1169 </tr>
1170 <tr class="odd toggler remote-server">
1171 <td><?php echo __('User name'); ?></td>
1172 <td><input type="text" name="<?php echo $type; ?>_username" class="server-user" /></td>
1173 </tr>
1174 <tr class="even toggler remote-server">
1175 <td><?php echo __('Password'); ?></td>
1176 <td><input type="password" name="<?php echo $type; ?>_pass" class="server-pass" /> </td>
1177 </tr>
1178 <tr class="odd toggler remote-server">
1179 <td><?php echo __('Database'); ?></td>
1180 <td><input type="text" name="<?php echo $type; ?>_db" class="server-db" /></td>
1181 </tr>
1182 <tr class="even toggler current-server" style="display: none;">
1183 <td><?php echo __('Database'); ?></td>
1184 <td>
1185 <?php
1186 // these unset() do not complain if the elements do not exist
1187 unset($databases['mysql']);
1188 unset($databases['information_schema']);
1190 if (count($databases) == 0) {
1191 echo __('No databases');
1192 } else {
1193 echo '
1194 <select name="' . $type . '_db_sel">
1196 foreach ($databases as $db) {
1197 echo ' <option>' . htmlspecialchars($db['SCHEMA_NAME']) . '</option>';
1199 echo '</select>';
1201 echo '</td> </tr>
1202 </table>';
1204 unset ($types, $type);
1206 echo '
1207 </fieldset>
1208 <fieldset class="tblFooters">
1209 <input type="submit" name="submit_connect" value="' . __('Go') .'" id="buttonGo" />
1210 </fieldset>
1211 </form>
1212 </div>
1213 <div class="notice">' . __('Target database will be completely synchronized with source database. Source database will remain unchanged.') . '</div>';
1217 * Displays the footer
1219 require_once './libraries/footer.inc.php';