Use PMA_DBI_get_columns in odt export
[phpmyadmin.git] / server_synchronize.php
blob9ff9cd4e87f625080761ff8744a11dc5b3f9dc5b
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'][] = 'server_synchronize.js';
18 require_once './libraries/server_common.inc.php';
20 /**
21 * Contains all the functions specific to synchronization
23 require './libraries/server_synchronize.lib.php';
25 /**
26 * Increases the time limit up to the configured maximum
28 @set_time_limit($cfg['ExecTimeLimit']);
30 /**
31 * Displays the links
33 require './libraries/server_links.inc.php';
35 /**
36 * Enables warnings on the page
38 //$cfg['Error_Handler']['display'] = true;
39 //$cfg['Error_Handler']['gather'] = true;
41 /**
42 * Save the value of token generated for this page
44 if (isset($_REQUEST['token'])) {
45 $_SESSION['token'] = $_REQUEST['token'];
48 // variable for code saving
49 $cons = array ("src", "trg");
51 /**
52 * Displays the page when 'Go' is pressed
55 if ((isset($_REQUEST['submit_connect']))) {
56 foreach ($cons as $con) {
57 ${"{$con}_host"} = $_REQUEST[$con . '_host'];
58 ${"{$con}_username"} = $_REQUEST[$con . '_username'];
59 ${"{$con}_password"} = $_REQUEST[$con . '_pass'];
60 ${"{$con}_port"} = $_REQUEST[$con . '_port'];
61 ${"{$con}_socket"} = $_REQUEST[$con . '_socket'];
62 ${"{$con}_db"} = $_REQUEST[$con . '_db'];
63 ${"{$con}_type"} = $_REQUEST[$con . '_type'];
65 if (${"{$con}_type"} == 'cur') {
66 ${"{$con}_connection"} = null;
67 ${"{$con}_server"} = null;
68 ${"{$con}_db"} = $_REQUEST[$con . '_db_sel'];
69 continue;
72 if (isset(${"{$con}_socket"}) && ! empty(${"{$con}_socket"})) {
73 ${"{$con}_server"}['socket'] = ${"{$con}_socket"};
74 } else {
75 ${"{$con}_server"}['host'] = ${"{$con}_host"};
76 if (isset(${"{$con}_port"}) && ! empty(${"{$con}_port"}) && ((int)${"{$con}_port"} * 1) > 0) {
77 ${"{$con}_server"}['port'] = (int)${"{$con}_port"};
81 ${"{$con}_connection"} = PMA_DBI_connect(${"{$con}_username"}, ${"{$con}_password"}, $is_controluser = false, ${"{$con}_server"}, $auxiliary_connection = true);
82 } // end foreach ($cons as $con)
84 if ((! $src_connection && $src_type != 'cur') || (! $trg_connection && $trg_type != 'cur')) {
85 /**
86 * Displays the connection error string if
87 * connections are not established
90 echo '<div class="error">';
91 if(! $src_connection && $src_type != 'cur') {
92 echo __('Could not connect to the source') . '<br />';
94 if(! $trg_connection && $trg_type != 'cur'){
95 echo __('Could not connect to the target');
97 echo '</div>';
98 unset($_REQUEST['submit_connect']);
100 } else {
102 * Creating the link object for both source and target databases and
103 * selecting the source and target databases using these links
105 foreach ($cons as $con) {
106 if (${"{$con}_connection"} != null) {
107 ${"{$con}_link"} = PMA_DBI_connect(${"{$con}_username"}, ${"{$con}_password"}, $is_controluser = false, ${"{$con}_server"});
108 } else {
109 ${"{$con}_link"} = null;
111 ${"{$con}_db_selected"} = PMA_DBI_select_db(${"{$con}_db"}, ${"{$con}_link"});
112 } // end foreach ($cons as $con)
114 if (($src_db_selected != 1) || ($trg_db_selected != 1)) {
116 * Displays error string if the database(s) did not exist
118 echo '<div class="error">';
119 if ($src_db_selected != 1) {
120 echo sprintf(__('\'%s\' database does not exist.'), htmlspecialchars($src_db));
122 if ($trg_db_selected != 1) {
123 echo sprintf(__('\'%s\' database does not exist.'), htmlspecialchars($trg_db));
125 echo '</div>';
126 unset($_REQUEST['submit_connect']);
128 } else if (($src_db_selected == 1) && ($trg_db_selected == 1)) {
131 * Using PMA_DBI_get_tables() to get all the tables
132 * from target and source databases.
134 $src_tables = PMA_DBI_get_tables($src_db, $src_link);
135 $source_tables_num = sizeof($src_tables);
137 $trg_tables = PMA_DBI_get_tables($trg_db, $trg_link);
138 $target_tables_num = sizeof($trg_tables);
141 * initializing arrays to save matching and non-matching
142 * table names from target and source databases.
144 $unmatched_num_src = 0;
145 $source_tables_uncommon = array();
146 $unmatched_num_trg = 0;
147 $target_tables_uncommon = array();
148 $matching_tables = array();
149 $matching_tables_num = 0;
152 * Using PMA_getMatchingTables to find which of the tables' names match
153 * in target and source database.
155 PMA_getMatchingTables($trg_tables, $src_tables, $matching_tables, $source_tables_uncommon);
157 * Finding the uncommon tables for the target database
158 * using function PMA_getNonMatchingTargetTables()
160 PMA_getNonMatchingTargetTables($trg_tables, $matching_tables, $target_tables_uncommon);
163 * Initializing several arrays to save the data and structure
164 * difference between the source and target databases.
166 $row_count = array(); //number of rows in source table that needs to be created in target database
167 $fields_num = array(); //number of fields in each matching table
168 $delete_array = array(); //stores the primary key values for target tables that have excessive rows than corresponding source tables.
169 $insert_array = array(array(array()));// stores the primary key values for the rows in each source table that are not present in target tables.
170 $update_array = array(array(array())); //stores the primary key values, name of field to be updated, value of the field to be updated for
171 // each row of matching table.
172 $matching_tables_fields = array(); //contains the fields' names for each matching table
173 $matching_tables_keys = array(); //contains the primary keys' names for each matching table
174 $uncommon_tables_fields = array(); //coantains the fields for all the source tables that are not present in target
175 $matching_tables_num = sizeof($matching_tables);
177 $source_columns = array(); //contains the full columns' information for all the source tables' columns
178 $target_columns = array(); //contains the full columns' information for all the target tables' columns
179 $uncommon_columns = array(); //contains names of columns present in source table but absent from the corresponding target table
180 $source_indexes = array(); //contains indexes on all the source tables
181 $target_indexes = array(); //contains indexes on all the target tables
182 $add_indexes_array = array(); //contains the indexes name present in source but absent from target tables
183 $target_tables_keys = array(); //contains the keys of all the target tables
184 $alter_indexes_array = array(); //contains the names of all the indexes for each table that need to be altered in target database
185 $remove_indexes_array = array(); //contains the names of indexes that are excessive in target tables
186 $alter_str_array = array(array()); //contains the criteria for each column that needs to be altered in target tables
187 $add_column_array = array(array()); //contains the name of columns that need to be added in target tables
189 * The criteria array contains all the criteria against which columns are compared for differences.
191 $criteria = array('Field', 'Type', 'Null', 'Collation', 'Key', 'Default', 'Comment');
193 for($i = 0; $i < sizeof($matching_tables); $i++) {
195 * Finding out all the differences structure, data and index diff for all the matching tables only
197 PMA_dataDiffInTables($src_db, $trg_db, $src_link, $trg_link, $matching_tables, $matching_tables_fields, $update_array, $insert_array,
198 $delete_array, $fields_num, $i, $matching_tables_keys);
200 PMA_structureDiffInTables($src_db, $trg_db, $src_link, $trg_link, $matching_tables, $source_columns,
201 $target_columns, $alter_str_array, $add_column_array, $uncommon_columns, $criteria, $target_tables_keys, $i);
203 PMA_indexesDiffInTables($src_db, $trg_db, $src_link, $trg_link, $matching_tables, $source_indexes, $target_indexes,
204 $add_indexes_array, $alter_indexes_array, $remove_indexes_array, $i);
207 for($j = 0; $j < sizeof($source_tables_uncommon); $j++) {
209 * Finding out the number of rows to be added in tables that need to be added in target database
211 PMA_dataDiffInUncommonTables($source_tables_uncommon, $src_db, $src_link, $j, $row_count);
214 * Storing all arrays in session for use when page is reloaded for each button press
216 $_SESSION['matching_tables'] = $matching_tables;
217 $_SESSION['update_array'] = $update_array;
218 $_SESSION['insert_array'] = $insert_array;
219 $_SESSION['src_db'] = $src_db;
220 $_SESSION['trg_db'] = $trg_db;
221 $_SESSION['matching_fields'] = $matching_tables_fields;
222 $_SESSION['src_uncommon_tables'] = $source_tables_uncommon;
223 $_SESSION['src_username'] = $src_username ;
224 $_SESSION['trg_username'] = $trg_username;
225 $_SESSION['src_password'] = $src_password;
226 $_SESSION['trg_password'] = $trg_password;
227 $_SESSION['trg_password'] = $trg_password;
228 $_SESSION['src_server'] = $src_server;
229 $_SESSION['trg_server'] = $trg_server;
230 $_SESSION['src_type'] = $src_type;
231 $_SESSION['trg_type'] = $trg_type;
232 $_SESSION['matching_tables_keys'] = $matching_tables_keys;
233 $_SESSION['uncommon_tables_fields'] = $uncommon_tables_fields;
234 $_SESSION['uncommon_tables_row_count'] = $row_count;
235 $_SESSION['target_tables_uncommon'] = $target_tables_uncommon;
236 $_SESSION['uncommon_tables'] = $source_tables_uncommon;
237 $_SESSION['delete_array'] = $delete_array;
238 $_SESSION['uncommon_columns'] = $uncommon_columns;
239 $_SESSION['source_columns'] = $source_columns;
240 $_SESSION['alter_str_array'] = $alter_str_array;
241 $_SESSION['target_tables_keys'] = $target_tables_keys;
242 $_SESSION['add_column_array'] = $add_column_array;
243 $_SESSION['criteria'] = $criteria;
244 $_SESSION['target_tables'] = $trg_tables;
245 $_SESSION['add_indexes_array'] = $add_indexes_array;
246 $_SESSION['alter_indexes_array'] = $alter_indexes_array;
247 $_SESSION['remove_indexes_array'] = $remove_indexes_array;
248 $_SESSION['source_indexes'] = $source_indexes;
249 $_SESSION['target_indexes'] = $target_indexes;
252 * Displays the sub-heading and icons showing Structure Synchronization and Data Synchronization
254 echo '<form name="synchronize_form" id="synchronize_form" method="post" action="server_synchronize.php">'
255 . PMA_generate_common_hidden_inputs('', '');
256 echo '<table id="serverstatustraffic" class="data" width = "40%">
257 <tr>
258 <td>'
259 . '<img class="icon" src="' . $pmaThemeImage . 'new_struct.jpg" width="32"'
260 . ' height="32" alt="" />'
261 . __('Structure Synchronization')
262 .'</td>';
263 echo '<td>'
264 . '<img class="icon" src="' . $pmaThemeImage . 'new_data.jpg" width="32"'
265 . ' height="32" alt="" />'
266 . __('Data Synchronization')
267 . '</td>';
268 echo '</tr>
269 </table>';
272 * Displays the tables containing the source tables names, their difference with the target tables and target tables names
274 PMA_syncDisplayHeaderSource($src_db);
275 $odd_row = false;
278 * Display the matching tables' names and difference, first
280 for($i = 0; $i < count($matching_tables); $i++) {
282 * Calculating the number of updates for each matching table
284 if (isset($update_array[$i]) && isset($update_array[$i][0]) &&
285 isset($update_array[$i][0][$matching_tables_keys[$i][0]])) {
286 $num_of_updates = sizeof($update_array[$i]);
287 } else {
288 $num_of_updates = 0;
291 * Calculating the number of insertions for each matching table
293 if (isset($insert_array[$i]) && isset($insert_array[$i][0]) &&
294 isset($insert_array[$i][0][$matching_tables_keys[$i][0]])) {
295 $num_of_insertions = sizeof($insert_array[$i]);
296 } else {
297 $num_of_insertions = 0;
300 * Displays the name of the matching table
302 $odd_row = PMA_syncDisplayBeginTableRow($odd_row);
303 echo '<td>' . htmlspecialchars($matching_tables[$i]) . '</td>
304 <td align="center">';
306 * Calculating the number of alter columns, number of columns to be added, number of columns to be removed,
307 * number of index to be added and removed.
309 $num_alter_cols = 0;
310 $num_insert_cols = 0;
311 $num_remove_cols = 0;
312 $num_add_index = 0;
313 $num_remove_index = 0;
315 if (isset($alter_str_array[$i])) {
316 $num_alter_cols = sizeof($alter_str_array[$i]);
318 if (isset($add_column_array[$i])) {
319 $num_insert_cols = sizeof($add_column_array[$i]);
321 if (isset($uncommon_columns[$i])) {
322 $num_remove_cols = sizeof($uncommon_columns[$i]);
324 if (isset($add_indexes_array[$i])) {
325 $num_add_index = sizeof($add_indexes_array[$i]);
327 if (isset($remove_indexes_array[$i])) {
328 $num_remove_index = sizeof($remove_indexes_array[$i]);
330 if (isset($alter_indexes_array[$i])) {
331 $num_add_index += sizeof($alter_indexes_array[$i]);
332 $num_remove_index += sizeof($alter_indexes_array[$i]);
335 * Display the red button of structure synchronization if there exists any structure difference or index difference.
337 if (($num_alter_cols > 0) || ($num_insert_cols > 0) || ($num_remove_cols > 0) || ($num_add_index > 0) || ($num_remove_index > 0)) {
339 echo '<img class="icon struct_img" src="' . $pmaThemeImage . 'new_struct.jpg" width="29" height="29"
340 alt="' . __('Click to select') . '"
341 onclick="showDetails(' . "'MS" . $i . "','" . $num_alter_cols . "','" .$num_insert_cols .
342 "','" . $num_remove_cols . "','" . $num_add_index . "','" . $num_remove_index . "'"
343 . ', this ,' . "'" . htmlspecialchars($matching_tables[$i]) . "'" . ')"/>';
346 * Display the green button of data synchronization if there exists any data difference.
348 if (isset($update_array[$i]) || isset($insert_array[$i])) {
349 if (isset($update_array[$i][0][$matching_tables_keys[$i][0]]) || isset($insert_array[$i][0][$matching_tables_keys[$i][0]])) {
351 echo '<img class="icon data_img" src="' . $pmaThemeImage . 'new_data.jpg" width="29" height="29"
352 alt="' . __('Click to select') . '"
353 onclick="showDetails('. "'MD" . $i . "','" . $num_of_updates . "','" . $num_of_insertions .
354 "','" . null . "','" . null . "','" . null . "'" . ', this ,' . "'" . htmlspecialchars($matching_tables[$i]) . "'" . ')" />';
357 echo '</td>
358 </tr>';
361 * Displays the tables' names present in source but missing from target
363 for ($j = 0; $j < count($source_tables_uncommon); $j++) {
364 $odd_row = PMA_syncDisplayBeginTableRow($odd_row);
365 echo '<td> + ' . htmlspecialchars($source_tables_uncommon[$j]) . '</td> ';
367 echo '<td align="center"><img class="icon struct_img" src="' . $pmaThemeImage . 'new_struct.jpg" width="29" height="29"
368 alt="' . __('Click to select') . '"
369 onclick="showDetails(' . "'US" . $j . "','" . null . "','" . null . "','" . null . "','" . null . "','" . null . "'" . ', this ,'
370 . "'" . htmlspecialchars($source_tables_uncommon[$j]) . "'" . ')"/>';
372 if ($row_count[$j] > 0)
374 echo '<img class="icon data_img" src="' . $pmaThemeImage . 'new_data.jpg" width="29" height="29"
375 alt="' . __('Click to select') . '"
376 onclick="showDetails(' . "'UD" . $j . "','" . null . "','" . $row_count[$j] . "','" . null .
377 "','" . null . "','" . null . "'" . ', this ,' . "'" . htmlspecialchars($source_tables_uncommon[$j]) . "'" . ')" />';
379 echo '</td>
380 </tr>';
382 foreach ($target_tables_uncommon as $tbl_nc_name) {
383 $odd_row = PMA_syncDisplayBeginTableRow($odd_row);
384 echo '<td height="32">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </td><td></td>';
385 echo '</tr>';
388 * Displays the target tables names
390 echo '</table>';
392 $odd_row = PMA_syncDisplayHeaderTargetAndMatchingTables($trg_db, $matching_tables);
393 foreach ($source_tables_uncommon as $tbl_nc_name) {
394 $odd_row = PMA_syncDisplayBeginTableRow($odd_row);
395 echo '<td height="32">' . htmlspecialchars($tbl_nc_name) . ' (' . __('not present') . ')</td>
396 </tr>';
398 foreach ($target_tables_uncommon as $tbl_nc_name) {
399 $odd_row = PMA_syncDisplayBeginTableRow($odd_row);
400 echo '<td> - ' . htmlspecialchars($tbl_nc_name) . '</td>';
401 echo '</tr>';
403 echo '</table>';
404 echo '</div>';
407 * This "list" div will contain a table and each row will depict information about structure/data diffrence in tables.
408 * Rows will be generated dynamically as soon as the colored buttons "D" or "S" are clicked.
411 echo '<div id="list" style = "overflow: auto; width: 1020px; height: 140px;
412 border-left: 1px gray solid; border-bottom: 1px gray solid;
413 padding:0px; margin: 0px">
415 <table>
416 <thead>
417 <tr style="width: 100%;">
418 <th id="table_name" style="width: 10%;" colspan="1">' . __('Table') . ' </th>
419 <th id="str_diff" style="width: 65%;" colspan="6">' . __('Structure Difference') . ' </th>
420 <th id="data_diff" style="width: 20%;" colspan="2">' . __('Data Difference') . '</th>
421 </tr>
422 <tr style="width: 100%;">
423 <th style="width: 10%;">' . __('Table name') . '</th>
424 <th style="width: 10%;">' . __('Create table'). '</th>
425 <th style="width: 11%;">' . __('Add column(s)') . '</th>
426 <th style="width: 13%;">' . __('Remove column(s)') . '</th>
427 <th style="width: 11%;">' . __('Alter column(s)') . '</th>
428 <th style="width: 12%;">' . __('Remove index(s)') . '</th>
429 <th style="width: 11%;">' . __('Apply index(s)') . '</th>
430 <th style="width: 10%;">'. __('Update row(s)') . '</th>
431 <th style="width: 10%;">' . __('Insert row(s)') . '</th>
432 </tr>
433 </thead>
434 <tbody></tbody>
435 </table>
436 </div>';
438 * This fieldset displays the checkbox to confirm deletion of previous rows from target tables
440 echo '<fieldset>
441 <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>
442 </fieldset>
443 <fieldset class="tblFooters">';
444 echo '<input type="button" name="apply_changes" value="' . __('Apply Selected Changes')
445 . '" onclick ="ApplySelectedChanges(' . "'" . htmlspecialchars($_SESSION['token']) . "'" . ')" />';
446 echo '<input type="submit" name="synchronize_db" value="' . __('Synchronize Databases') . '" />' . '</fieldset>';
447 echo '</form>';
450 } // end if ((isset($_REQUEST['submit_connect'])))
453 * Display the page when 'Apply Selected Changes' is pressed
455 if (isset($_REQUEST['Table_ids'])) {
457 * Displays success message
459 echo '<div class="success">' . __('Selected target tables have been synchronized with source tables.') . '</div>';
461 $src_db = $_SESSION['src_db'];
462 $trg_db = $_SESSION['trg_db'];
463 $update_array = $_SESSION['update_array'];
464 $insert_array = $_SESSION['insert_array'];
465 $src_username = $_SESSION['src_username'];
466 $trg_username = $_SESSION['trg_username'];
467 $src_password = $_SESSION['src_password'];
468 $trg_password = $_SESSION['trg_password'];
469 $src_server = $_SESSION['src_server'];
470 $trg_server = $_SESSION['trg_server'];
471 $src_type = $_SESSION['src_type'];
472 $trg_type = $_SESSION['trg_type'];
473 $uncommon_tables = $_SESSION['uncommon_tables'];
474 $matching_tables = $_SESSION['matching_tables'];
475 $matching_tables_keys = $_SESSION['matching_tables_keys'];
476 $matching_tables_fields = $_SESSION['matching_fields'];
477 $source_tables_uncommon = $_SESSION['src_uncommon_tables'];
478 $uncommon_tables_fields = $_SESSION['uncommon_tables_fields'];
479 $target_tables_uncommon = $_SESSION['target_tables_uncommon'];
480 $row_count = $_SESSION['uncommon_tables_row_count'];
481 $target_tables = $_SESSION['target_tables'];
483 $delete_array = $_SESSION['delete_array'];
484 $uncommon_columns = $_SESSION['uncommon_columns'];
485 $source_columns = $_SESSION['source_columns'];
486 $alter_str_array = $_SESSION['alter_str_array'];
487 $criteria = $_SESSION['criteria'];
488 $target_tables_keys = $_SESSION['target_tables_keys'];
489 $add_column_array = $_SESSION['add_column_array'];
490 $add_indexes_array = $_SESSION['add_indexes_array'];
491 $alter_indexes_array = $_SESSION['alter_indexes_array'];
492 $remove_indexes_array = $_SESSION['remove_indexes_array'];
493 $source_indexes = $_SESSION['source_indexes'];
494 $target_indexes = $_SESSION['target_indexes'];
495 $uncommon_cols = $uncommon_columns;
498 * Creating link object for source and target databases
500 foreach ($cons as $con) {
501 if (${"{$con}_type"} != "cur") {
502 ${"{$con}_link"} = PMA_DBI_connect(${"{$con}_username"}, ${"{$con}_password"}, $is_controluser = false, ${"{$con}_server"});
503 } else {
504 ${"{$con}_link"} = null;
505 // working on current server, so initialize this for tracking
506 // (does not work if user defined current server as a remote one)
507 $GLOBALS['db'] = ${"{$con}_db"};
509 } // end foreach ($cons as $con)
512 * Initializing arrays to save the table ids whose data and structure difference is to be applied
514 $matching_table_data_diff = array(); //stores id of matching table having data difference
515 $matching_table_structure_diff = array(); //stores id of matching tables having structure difference
516 $uncommon_table_structure_diff = array(); //stores id of uncommon tables having structure difference
517 $uncommon_table_data_diff = array(); //stores id of uncommon tables having data difference
519 for ($i = 0; isset($_REQUEST[$i]); $i++ ) {
520 if (isset($_REQUEST[$i])) {
521 $table_id = explode("US", $_REQUEST[$i]);
522 if (isset($table_id[1])) {
523 $uncommon_table_structure_diff[] = $table_id[1];
525 $table_id = explode("UD", $_REQUEST[$i]);
526 if (isset($table_id[1])) {
527 $uncommon_table_data_diff[] = $table_id[1];
529 $table_id = explode("MS", $_REQUEST[$i]);
530 if (isset($table_id[1])) {
531 $matching_table_structure_diff[] = $table_id[1];
534 $table_id = explode("MD", $_REQUEST[$i]);
535 if (isset($table_id[1])) {
536 $matching_table_data_diff[] = $table_id[1];
539 } // end for
541 * Applying the structure difference on selected matching tables
543 for($q = 0; $q < sizeof($matching_table_structure_diff); $q++)
545 if (isset($alter_str_array[$matching_table_structure_diff[$q]])) {
547 PMA_alterTargetTableStructure($trg_db, $trg_link, $matching_tables, $source_columns, $alter_str_array, $matching_tables_fields,
548 $criteria, $matching_tables_keys, $target_tables_keys, $matching_table_structure_diff[$q], false);
550 unset($alter_str_array[$matching_table_structure_diff[$q]]);
552 if (isset($add_column_array[$matching_table_structure_diff[$q]])) {
554 PMA_findDeleteRowsFromTargetTables($delete_array, $matching_tables, $matching_table_structure_diff[$q], $target_tables_keys,
555 $matching_tables_keys, $trg_db, $trg_link, $src_db, $src_link);
557 if (isset($delete_array[$matching_table_structure_diff[$q]])) {
559 PMA_deleteFromTargetTable($trg_db, $trg_link, $matching_tables, $matching_table_structure_diff[$q], $target_tables_keys, $delete_array, false);
561 unset($delete_array[$matching_table_structure_diff[$q]]);
563 PMA_addColumnsInTargetTable($src_db, $trg_db,$src_link, $trg_link, $matching_tables, $source_columns, $add_column_array, $matching_tables_fields,
564 $criteria, $matching_tables_keys, $target_tables_keys, $uncommon_tables,$uncommon_tables_fields, $matching_table_structure_diff[$q], $uncommon_cols, false);
566 unset($add_column_array[$matching_table_structure_diff[$q]]);
568 if (isset($uncommon_columns[$matching_table_structure_diff[$q]])) {
570 PMA_removeColumnsFromTargetTable($trg_db, $trg_link, $matching_tables, $uncommon_columns, $matching_table_structure_diff[$q], false);
572 unset($uncommon_columns[$matching_table_structure_diff[$q]]);
574 if (isset($add_indexes_array[$matching_table_structure_diff[$q]]) || isset($remove_indexes_array[$matching_table_structure_diff[$q]])
575 || isset($alter_indexes_array[$matching_table_structure_diff[$q]])) {
577 PMA_applyIndexesDiff ($trg_db, $trg_link, $matching_tables, $source_indexes, $target_indexes, $add_indexes_array, $alter_indexes_array,
578 $remove_indexes_array, $matching_table_structure_diff[$q], false);
580 unset($add_indexes_array[$matching_table_structure_diff[$q]]);
581 unset($alter_indexes_array[$matching_table_structure_diff[$q]]);
582 unset($remove_indexes_array[$matching_table_structure_diff[$q]]);
586 * Applying the data difference. First checks if structure diff is applied or not.
587 * If not, then apply structure difference first then apply data difference.
589 for($p = 0; $p < sizeof($matching_table_data_diff); $p++)
591 if ($_REQUEST['checked'] == 'true') {
593 PMA_findDeleteRowsFromTargetTables($delete_array, $matching_tables, $matching_table_data_diff[$p], $target_tables_keys,
594 $matching_tables_keys, $trg_db, $trg_link, $src_db, $src_link);
596 if (isset($delete_array[$matching_table_data_diff[$p]])) {
598 PMA_deleteFromTargetTable($trg_db, $trg_link, $matching_tables, $matching_table_data_diff[$p], $target_tables_keys, $delete_array, false);
600 unset($delete_array[$matching_table_data_diff[$p]]);
603 if (isset($alter_str_array[$matching_table_data_diff[$p]])) {
605 PMA_alterTargetTableStructure($trg_db, $trg_link, $matching_tables, $source_columns, $alter_str_array, $matching_tables_fields,
606 $criteria, $matching_tables_keys, $target_tables_keys, $matching_table_data_diff[$p], false);
608 unset($alter_str_array[$matching_table_data_diff[$p]]);
610 if (isset($add_column_array[$matching_table_data_diff[$p]])) {
612 PMA_findDeleteRowsFromTargetTables($delete_array, $matching_tables, $matching_table_data_diff[$p], $target_tables_keys,
613 $matching_tables_keys, $trg_db, $trg_link, $src_db, $src_link);
615 if (isset($delete_array[$matching_table_data_diff[$p]])) {
617 PMA_deleteFromTargetTable($trg_db, $trg_link, $matching_tables, $matching_table_data_diff[$p], $target_tables_keys, $delete_array, false);
619 unset($delete_array[$matching_table_data_diff[$p]]);
621 PMA_addColumnsInTargetTable($src_db, $trg_db,$src_link, $trg_link, $matching_tables, $source_columns, $add_column_array, $matching_tables_fields,
622 $criteria, $matching_tables_keys, $target_tables_keys, $uncommon_tables, $uncommon_tables_fields, $matching_table_data_diff[$p], $uncommon_cols, false);
624 unset($add_column_array[$matching_table_data_diff[$p]]);
626 if (isset($uncommon_columns[$matching_table_data_diff[$p]])) {
628 PMA_removeColumnsFromTargetTable($trg_db, $trg_link, $matching_tables, $uncommon_columns, $matching_table_data_diff[$p], false);
630 unset($uncommon_columns[$matching_table_data_diff[$p]]);
632 if ((isset($matching_table_structure_diff[$q]) && isset($add_indexes_array[$matching_table_structure_diff[$q]]))
633 || (isset($matching_table_structure_diff[$q]) && isset($remove_indexes_array[$matching_table_structure_diff[$q]]))
634 || (isset($matching_table_structure_diff[$q]) && isset($alter_indexes_array[$matching_table_structure_diff[$q]]))) {
636 PMA_applyIndexesDiff ($trg_db, $trg_link, $matching_tables, $source_indexes, $target_indexes, $add_indexes_array, $alter_indexes_array,
637 $remove_indexes_array, $matching_table_structure_diff[$q], false);
639 unset($add_indexes_array[$matching_table_structure_diff[$q]]);
640 unset($alter_indexes_array[$matching_table_structure_diff[$q]]);
641 unset($remove_indexes_array[$matching_table_structure_diff[$q]]);
644 * Applying the data difference.
646 PMA_updateTargetTables($matching_tables, $update_array, $src_db, $trg_db, $trg_link, $matching_table_data_diff[$p], $matching_tables_keys, false);
648 PMA_insertIntoTargetTable($matching_tables, $src_db, $trg_db, $src_link, $trg_link , $matching_tables_fields, $insert_array,
649 $matching_table_data_diff[$p], $matching_tables_keys, $source_columns, $add_column_array, $criteria, $target_tables_keys,
650 $uncommon_tables, $uncommon_tables_fields, $uncommon_cols, $alter_str_array, $source_indexes, $target_indexes, $add_indexes_array,
651 $alter_indexes_array, $delete_array, $update_array, false);
654 * Updating the session variables to the latest values of the arrays.
656 $_SESSION['delete_array'] = $delete_array;
657 $_SESSION['uncommon_columns'] = $uncommon_columns;
658 $_SESSION['alter_str_array'] = $alter_str_array;
659 $_SESSION['add_column_array'] = $add_column_array;
660 $_SESSION['add_indexes_array'] = $add_indexes_array;
661 $_SESSION['remove_indexes_array'] = $remove_indexes_array;
662 $_SESSION['insert_array'] = $insert_array;
663 $_SESSION['update_array'] = $update_array;
666 * Applying structure difference to selected non-matching tables (present in Source but absent from Target).
668 for($s = 0; $s < sizeof($uncommon_table_structure_diff); $s++)
670 PMA_createTargetTables($src_db, $trg_db, $src_link, $trg_link, $uncommon_tables, $uncommon_table_structure_diff[$s], $uncommon_tables_fields, false);
671 $_SESSION['uncommon_tables_fields'] = $uncommon_tables_fields;
673 unset($uncommon_tables[$uncommon_table_structure_diff[$s]]);
676 * Applying data difference to selected non-matching tables (present in Source but absent from Target).
677 * Before data synchronization, structure synchronization is confirmed.
679 for($r = 0; $r < sizeof($uncommon_table_data_diff); $r++)
681 if (!(in_array($uncommon_table_data_diff[$r], $uncommon_table_structure_diff))) {
682 if (isset($uncommon_tables[$uncommon_table_data_diff[$r]])) {
684 PMA_createTargetTables($src_db, $trg_db, $src_link, $trg_link, $uncommon_tables, $uncommon_table_data_diff[$r],
685 $uncommon_tables_fields, false);
686 $_SESSION['uncommon_tables_fields'] = $uncommon_tables_fields;
688 unset($uncommon_tables[$uncommon_table_data_diff[$r]]);
691 PMA_populateTargetTables($src_db, $trg_db, $src_link, $trg_link, $source_tables_uncommon, $uncommon_table_data_diff[$r],
692 $_SESSION['uncommon_tables_fields'], false);
694 unset($row_count[$uncommon_table_data_diff[$r]]);
697 * Again all the tables from source and target database are displayed with their differences.
698 * The differences have been removed from tables that have been synchronized
700 echo '<form name="applied_difference" id="synchronize_form" method="post" action="server_synchronize.php">'
701 . PMA_generate_common_hidden_inputs('', '');
703 PMA_syncDisplayHeaderSource($src_db);
704 $odd_row = false;
705 for($i = 0; $i < count($matching_tables); $i++) {
706 $odd_row = PMA_syncDisplayBeginTableRow($odd_row);
707 echo '<td align="center">' . htmlspecialchars($matching_tables[$i]) . '</td>
708 <td align="center">';
710 $num_alter_cols = 0;
711 $num_insert_cols = 0;
712 $num_remove_cols = 0;
713 $num_add_index = 0;
714 $num_remove_index = 0;
716 if (isset($alter_str_array[$i])) {
717 $num_alter_cols = sizeof($alter_str_array[$i]);
719 if (isset($add_column_array[$i])) {
720 $num_insert_cols = sizeof($add_column_array[$i]);
722 if (isset($uncommon_columns[$i])) {
723 $num_remove_cols = sizeof($uncommon_columns[$i]);
725 if (isset($add_indexes_array[$i])) {
726 $num_add_index = sizeof($add_indexes_array[$i]);
728 if (isset($remove_indexes_array[$i])) {
729 $num_remove_index = sizeof($remove_indexes_array[$i]);
732 if (($num_alter_cols > 0) || ($num_insert_cols > 0) || ($num_remove_cols > 0) || ($num_add_index > 0) || ($num_remove_index > 0)) {
733 echo '<img class="icon struct_img" src="' . $pmaThemeImage . 'new_struct.jpg" width="29" height="29"
734 alt="' . __('Click to select') . '"
735 onclick="showDetails(' . "'MS" . $i . "','" . $num_alter_cols . "','" . $num_insert_cols . "','" . $num_remove_cols . "','" . $num_add_index . "','" . $num_remove_index . "'" .',
736 this ,' . "'" . htmlspecialchars($matching_tables[$i]) . "'" . ')"/>';
738 if (!(in_array($i, $matching_table_data_diff))) {
740 if (isset($matching_tables_keys[$i][0]) && isset($update_array[$i][0][$matching_tables_keys[$i][0]])) {
741 if (isset($update_array[$i])) {
742 $num_of_updates = sizeof($update_array[$i]);
743 } else {
744 $num_of_updates = 0;
746 } else {
747 $num_of_updates = 0;
749 if (isset($matching_tables_keys[$i][0]) && isset($insert_array[$i][0][$matching_tables_keys[$i][0]])) {
750 if (isset($insert_array[$i])) {
751 $num_of_insertions = sizeof($insert_array[$i]);
752 } else {
753 $num_of_insertions = 0;
755 } else {
756 $num_of_insertions = 0;
759 if ((isset($matching_tables_keys[$i][0]) && isset($update_array[$i][0][$matching_tables_keys[$i][0]]))
760 || (isset($matching_tables_keys[$i][0]) && isset($insert_array[$i][0][$matching_tables_keys[$i][0]]))) {
761 echo '<img class="icon data_img" src="' . $pmaThemeImage . 'new_data.jpg" width="29" height="29"
762 alt="' . __('Click to select') . '"
763 onclick="showDetails(' . "'MD" . $i . "','" . $num_of_updates . "','" . $num_of_insertions .
764 "','" . null . "','" . null . "','" . null . "'" .', this ,' . "'" . htmlspecialchars($matching_tables[$i]) . "'" . ')" />';
766 } else {
767 unset($update_array[$i]);
768 unset($insert_array[$i]);
770 echo '</td>
771 </tr>';
774 * placing updated value of arrays in session
777 $_SESSION['update_array'] = $update_array;
778 $_SESSION['insert_array'] = $insert_array;
780 for ($j = 0; $j < count($source_tables_uncommon); $j++) {
781 $odd_row = PMA_syncDisplayBeginTableRow($odd_row);
782 echo '<td align="center"> + ' . htmlspecialchars($source_tables_uncommon[$j]) . '</td>
783 <td align="center">';
785 * Display the difference only when it has not been applied
787 if (!(in_array($j, $uncommon_table_structure_diff))) {
788 if (isset($uncommon_tables[$j])) {
789 echo '<img class="icon struct_img" src="' . $pmaThemeImage . 'new_struct.jpg" width="29" height="29"
790 alt="' . __('Click to select') . '"
791 onclick="showDetails(' . "'US" . $j . "','" . null . "','" . null . "','" . null . "','" . null . "','" . null . "'" . ', this ,' . "'" . htmlspecialchars($source_tables_uncommon[$j]) . "'" . ')"/>' .' ';
793 } else {
794 unset($uncommon_tables[$j]);
797 * Display the difference only when it has not been applied
799 if (!(in_array($j, $uncommon_table_data_diff))) {
800 if (isset($row_count[$j]) && ($row_count > 0)) {
801 echo '<img class="icon data_img" src="' . $pmaThemeImage . 'new_data.jpg" width="29" height="29"
802 alt="' . __('Click to select') . '"
803 onclick="showDetails(' . "'UD" . $j . "','" . null ."','" . $row_count[$j] ."','"
804 . null . "','" . null . "','" . null . "'" . ', this ,' . "'". htmlspecialchars($source_tables_uncommon[$j]) . "'" . ')" />';
806 } else {
807 unset($row_count[$j]);
810 echo '</td>
811 </tr>';
814 * placing the latest values of arrays in session
817 $_SESSION['uncommon_tables'] = $uncommon_tables;
818 $_SESSION['uncommon_tables_row_count'] = $row_count;
822 * Displaying the target database tables
824 foreach ($target_tables_uncommon as $tbl_nc_name) {
825 $odd_row = PMA_syncDisplayBeginTableRow($odd_row);
826 echo '<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </td><td></td>';
827 echo '</tr>';
829 echo '</table>';
830 $odd_row = PMA_syncDisplayHeaderTargetAndMatchingTables($trg_db, $matching_tables);
831 foreach ($source_tables_uncommon as $tbl_nc_name) {
832 $odd_row = PMA_syncDisplayBeginTableRow($odd_row);
833 if (in_array($tbl_nc_name, $uncommon_tables)) {
834 echo '<td>' . htmlspecialchars($tbl_nc_name) . ' (' . __('not present') . ')</td>';
835 } else {
836 echo '<td>' . htmlspecialchars($tbl_nc_name) . '</td>';
838 echo '
839 </tr>';
841 foreach ($target_tables_uncommon as $tbl_nc_name) {
842 $odd_row = PMA_syncDisplayBeginTableRow($odd_row);
843 echo '<td> - ' . htmlspecialchars($tbl_nc_name) . '</td>';
844 echo '</tr>';
846 echo '</table>
847 </div>';
850 * This "list" div will contain a table and each row will depict information about structure/data diffrence in tables.
851 * Rows will be generated dynamically as soon as the colored buttons "D" or "S" are clicked.
854 echo '<div id="list" style = "overflow: auto; width: 1020px; height: 140px;
855 border-left: 1px gray solid; border-bottom: 1px gray solid;
856 padding:0px; margin: 0px">';
858 echo '<table>
859 <thead>
860 <tr style="width: 100%;">
861 <th id="table_name" style="width: 10%;" colspan="1">' . __('Table') . ' </th>
862 <th id="str_diff" style="width: 65%;" colspan="6">' . __('Structure Difference') . ' </th>
863 <th id="data_diff" style="width: 20%;" colspan="2">' . __('Data Difference') . '</th>
864 </tr>
865 <tr style="width: 100%;">
866 <th style="width: 10%;">' . __('Table name') . '</th>
867 <th style="width: 10%;">' . __('Create table'). '</th>
868 <th style="width: 11%;">' . __('Add column(s)') . '</th>
869 <th style="width: 13%;">' . __('Remove column(s)') . '</th>
870 <th style="width: 11%;">' . __('Alter column(s)') . '</th>
871 <th style="width: 12%;">' . __('Remove index(s)') . '</th>
872 <th style="width: 11%;">' . __('Apply index(s)') . '</th>
873 <th style="width: 10%;">' . __('Update row(s)') . '</th>
874 <th style="width: 10%;">' . __('Insert row(s)') . '</th>
875 </tr>
876 </thead>
877 <tbody></tbody>
878 </table>
879 </div>';
882 * This fieldset displays the checkbox to confirm deletion of previous rows from target tables
884 echo '<fieldset>
885 <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>
886 </fieldset>';
888 echo '<fieldset class="tblFooters">';
889 echo '<input type="button" name="apply_changes" value="' . __('Apply Selected Changes') . '"
890 onclick ="ApplySelectedChanges(' . "'" . htmlspecialchars($_SESSION['token']) . "'" .')" />';
891 echo '<input type="submit" name="synchronize_db" value="' . __('Synchronize Databases') . '" />'
892 . '</fieldset>';
893 echo '</form>';
897 * Displays the page when 'Synchronize Databases' is pressed.
900 if (isset($_REQUEST['synchronize_db'])) {
902 $src_db = $_SESSION['src_db'];
903 $trg_db = $_SESSION['trg_db'];
904 $update_array = $_SESSION['update_array'];
905 $insert_array = $_SESSION['insert_array'];
906 $src_username = $_SESSION['src_username'];
907 $trg_username = $_SESSION['trg_username'];
908 $src_password = $_SESSION['src_password'];
909 $trg_password = $_SESSION['trg_password'];
910 $matching_tables = $_SESSION['matching_tables'];
911 $matching_tables_keys = $_SESSION['matching_tables_keys'];
912 $matching_tables_fields = $_SESSION['matching_fields'];
913 $source_tables_uncommon = $_SESSION['src_uncommon_tables'];
914 $uncommon_tables_fields = $_SESSION['uncommon_tables_fields'];
915 $target_tables_uncommon = $_SESSION['target_tables_uncommon'];
916 $row_count = $_SESSION['uncommon_tables_row_count'];
917 $uncommon_tables = $_SESSION['uncommon_tables'];
918 $target_tables = $_SESSION['target_tables'];
920 $delete_array = $_SESSION['delete_array'];
921 $uncommon_columns = $_SESSION['uncommon_columns'];
922 $source_columns = $_SESSION['source_columns'];
923 $alter_str_array = $_SESSION['alter_str_array'];
924 $criteria = $_SESSION['criteria'];
925 $target_tables_keys = $_SESSION['target_tables_keys'];
926 $add_column_array = $_SESSION['add_column_array'];
927 $add_indexes_array = $_SESSION['add_indexes_array'];
928 $alter_indexes_array = $_SESSION['alter_indexes_array'];
929 $remove_indexes_array = $_SESSION['remove_indexes_array'];
930 $source_indexes = $_SESSION['source_indexes'];
931 $target_indexes = $_SESSION['target_indexes'];
932 $uncommon_cols = $uncommon_columns;
935 * Display success message.
937 echo '<div class="success">' . __('Target database has been synchronized with source database') . '</div>';
939 * Displaying all the tables of source and target database and now no difference is there.
941 PMA_syncDisplayHeaderSource($src_db);
943 $odd_row = false;
944 for($i = 0; $i < count($matching_tables); $i++)
946 $odd_row = PMA_syncDisplayBeginTableRow($odd_row);
947 echo '<td>' . htmlspecialchars($matching_tables[$i]) . '</td>
948 <td></td>
949 </tr>';
951 for ($j = 0; $j < count($source_tables_uncommon); $j++) {
952 $odd_row = PMA_syncDisplayBeginTableRow($odd_row);
953 echo '<td> + ' . htmlspecialchars($source_tables_uncommon[$j]) . '</td> ';
954 echo '<td></td>
955 </tr>';
957 foreach ($target_tables_uncommon as $tbl_nc_name) {
958 $odd_row = PMA_syncDisplayBeginTableRow($odd_row);
959 echo '<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </td><td></td>';
960 echo '</tr>';
962 echo '</table>';
963 $odd_row = PMA_syncDisplayHeaderTargetAndMatchingTables($trg_db, $matching_tables);
964 foreach ($source_tables_uncommon as $tbl_nc_name) {
965 $odd_row = PMA_syncDisplayBeginTableRow($odd_row);
966 echo '<td>' . htmlspecialchars($tbl_nc_name) . ' </td>
967 </tr>';
969 foreach ($target_tables_uncommon as $tbl_nc_name) {
970 $odd_row = PMA_syncDisplayBeginTableRow($odd_row);
971 echo '<td> ' . htmlspecialchars($tbl_nc_name) . '</td>';
972 echo '</tr>';
974 echo '</table> </div>';
977 * connecting the source and target servers
979 if ('cur' != $_SESSION['src_type']) {
980 $src_link = PMA_DBI_connect($src_username, $src_password, $is_controluser = false, $_SESSION['src_server']);
981 } else {
982 $src_link = $GLOBALS['userlink'];
983 // working on current server, so initialize this for tracking
984 // (does not work if user defined current server as a remote one)
985 $GLOBALS['db'] = $_SESSION['src_db'];
987 if ('cur' != $_SESSION['trg_type']) {
988 $trg_link = PMA_DBI_connect($trg_username, $trg_password, $is_controluser = false, $_SESSION['trg_server']);
989 } else {
990 $trg_link = $GLOBALS['userlink'];
991 // working on current server, so initialize this for tracking
992 $GLOBALS['db'] = $_SESSION['trg_db'];
996 * Displaying the queries.
998 echo '<h5>' . __('The following queries have been executed:') . '</h5>';
999 echo '<div id="serverstatus" style = "overflow: auto; width: 1050px; height: 180px;
1000 border-left: 1px gray solid; border-bottom: 1px gray solid; padding: 0px; margin: 0px"> ';
1002 * Applying all sorts of differences for each matching table
1004 for($p = 0; $p < sizeof($matching_tables); $p++) {
1006 * If the check box is checked for deleting previous rows from the target database tables then
1007 * first find out rows to be deleted and then delete the rows.
1009 if (isset($_REQUEST['delete_rows'])) {
1010 PMA_findDeleteRowsFromTargetTables($delete_array, $matching_tables, $p, $target_tables_keys, $matching_tables_keys,
1011 $trg_db, $trg_link, $src_db, $src_link);
1013 if (isset($delete_array[$p])) {
1014 PMA_deleteFromTargetTable($trg_db, $trg_link, $matching_tables, $p, $target_tables_keys, $delete_array, true);
1015 unset($delete_array[$p]);
1018 if (isset($alter_str_array[$p])) {
1019 PMA_alterTargetTableStructure($trg_db, $trg_link, $matching_tables, $source_columns, $alter_str_array, $matching_tables_fields,
1020 $criteria, $matching_tables_keys, $target_tables_keys, $p, true);
1021 unset($alter_str_array[$p]);
1023 if (! empty($add_column_array[$p])) {
1024 PMA_findDeleteRowsFromTargetTables($delete_array, $matching_tables, $p, $target_tables_keys, $matching_tables_keys,
1025 $trg_db, $trg_link, $src_db, $src_link);
1027 if (isset($delete_array[$p])) {
1028 PMA_deleteFromTargetTable($trg_db, $trg_link, $matching_tables, $p, $target_tables_keys, $delete_array, true);
1029 unset($delete_array[$p]);
1031 PMA_addColumnsInTargetTable($src_db, $trg_db, $src_link, $trg_link, $matching_tables, $source_columns, $add_column_array,
1032 $matching_tables_fields, $criteria, $matching_tables_keys, $target_tables_keys, $uncommon_tables, $uncommon_tables_fields,
1033 $p, $uncommon_cols, true);
1034 unset($add_column_array[$p]);
1036 if (isset($uncommon_columns[$p])) {
1037 PMA_removeColumnsFromTargetTable($trg_db, $trg_link, $matching_tables, $uncommon_columns, $p, true);
1038 unset($uncommon_columns[$p]);
1040 if (isset($matching_table_structure_diff) &&
1041 (isset($add_indexes_array[$matching_table_structure_diff[$p]])
1042 || isset($remove_indexes_array[$matching_table_structure_diff[$p]])
1043 || isset($alter_indexes_array[$matching_table_structure_diff[$p]]))) {
1044 PMA_applyIndexesDiff ($trg_db, $trg_link, $matching_tables, $source_indexes, $target_indexes, $add_indexes_array, $alter_indexes_array,
1045 $remove_indexes_array, $matching_table_structure_diff[$p], true);
1047 unset($add_indexes_array[$matching_table_structure_diff[$p]]);
1048 unset($alter_indexes_array[$matching_table_structure_diff[$p]]);
1049 unset($remove_indexes_array[$matching_table_structure_diff[$p]]);
1052 PMA_updateTargetTables($matching_tables, $update_array, $src_db, $trg_db, $trg_link, $p, $matching_tables_keys, true);
1054 PMA_insertIntoTargetTable($matching_tables, $src_db, $trg_db, $src_link, $trg_link , $matching_tables_fields, $insert_array, $p,
1055 $matching_tables_keys, $matching_tables_keys, $source_columns, $add_column_array, $criteria, $target_tables_keys, $uncommon_tables,
1056 $uncommon_tables_fields,$uncommon_cols, $alter_str_array,$source_indexes, $target_indexes, $add_indexes_array,
1057 $alter_indexes_array, $delete_array, $update_array, true);
1061 * Creating and populating tables present in source but absent from target database.
1063 for($q = 0; $q < sizeof($source_tables_uncommon); $q++) {
1064 if (isset($uncommon_tables[$q])) {
1065 PMA_createTargetTables($src_db, $trg_db, $src_link, $trg_link, $source_tables_uncommon, $q, $uncommon_tables_fields, true);
1067 if (isset($row_count[$q])) {
1068 PMA_populateTargetTables($src_db, $trg_db, $src_link, $trg_link, $source_tables_uncommon, $q, $uncommon_tables_fields, true);
1071 echo "</div>";
1075 * Displays the main page when none of the following buttons is pressed
1078 if (! isset($_REQUEST['submit_connect']) && ! isset($_REQUEST['synchronize_db']) && ! isset($_REQUEST['Table_ids']) )
1081 * Displays the sub-page heading
1083 echo '<h2>' . ($GLOBALS['cfg']['MainPageIconic']
1084 ? '<img class="icon" src="' . $pmaThemeImage . 's_sync.png" width="18"'
1085 . ' height="18" alt="" />'
1086 : '')
1087 . __('Synchronize')
1088 .'</h2>';
1090 echo '<div id="serverstatus">
1091 <form name="connection_form" id="connection_form" method="post" action="server_synchronize.php"
1092 >' // TODO: add check if all var. are filled in
1093 . PMA_generate_common_hidden_inputs('', '');
1094 echo '<fieldset>';
1095 echo '<legend>' . __('Synchronize') . '</legend>';
1097 * Displays the forms
1100 $databases = PMA_DBI_get_databases_full(null, false, null, 'SCHEMA_NAME',
1101 'ASC', 0, true);
1103 if ($GLOBALS['cfg']['AllowArbitraryServer'] === false) {
1104 $possibly_readonly = ' readonly="readonly"';
1105 } else {
1106 $possibly_readonly = '';
1109 foreach ($cons as $type) {
1110 if ('src' == $type) {
1111 $database_header = __('Source database');
1112 } else {
1113 $database_header = __('Target database');
1116 $database_header .= PMA_showHint(PMA_sanitize(sprintf('%sAllowArbitraryServer%s', '[a@./Documentation.html#AllowArbitraryServer@_blank]', '[/a]')));
1118 <table id="serverconnection_<?php echo $type; ?>_remote" class="data">
1119 <caption class="tblHeaders"><?php echo $database_header; ?></caption>
1120 <tr class="odd">
1121 <td colspan="2" style="text-align: center">
1122 <select name="<?php echo $type; ?>_type" id="<?php echo $type; ?>_type" class="server_selector">
1123 <?php
1124 if ($GLOBALS['cfg']['AllowArbitraryServer']) {
1125 $preselected_option = 'rmt';
1126 echo '<option value="rmt" selected="selected">' . __('Enter manually') . '</option>';
1127 } else {
1128 $preselected_option = 'cur';
1130 echo '<option value="cur"';
1131 if ('cur' == $preselected_option) {
1132 echo ' selected="selected"';
1134 echo '>' . __('Current connection') . '</option>';
1136 foreach ($GLOBALS['cfg']['Servers'] as $key => $tmp_server) {
1137 if (empty($tmp_server['host'])) {
1138 continue;
1141 if (!empty($tmp_server['verbose'])) {
1142 $label = $tmp_server['verbose'];
1143 } else {
1144 $label = $tmp_server['host'];
1145 if (!empty($tmp_server['port'])) {
1146 $label .= ':' . $tmp_server['port'];
1149 $value = $tmp_server['host'];
1150 $value .= '||||';
1151 if (empty($tmp_server['port']) && empty($tmp_server['socket'])) {
1152 $value .= '3306';
1153 } else {
1154 $value .= $tmp_server['port'];
1156 $value .= '||||';
1157 $value .= $tmp_server['socket'];
1158 $value .= '||||';
1159 $value .= $tmp_server['user'];
1160 $value .= '||||';
1161 $value .= $tmp_server['only_db'];
1162 echo '<option value="' . $value . '" >'
1163 . htmlspecialchars(sprintf(__('Configuration: %s'), $label)) . '</option>';
1164 } // end foreach
1166 </select>
1167 </td>
1168 </tr>
1169 <tr class="even toggler remote-server">
1170 <td><?php echo __('Server'); ?></td>
1171 <td><input type="text" name="<?php echo $type; ?>_host" class="server-host" <?php echo $possibly_readonly; ?>/></td>
1172 </tr>
1173 <tr class="odd toggler remote-server">
1174 <td><?php echo __('Port'); ?></td>
1175 <td><input type="text" name="<?php echo $type; ?>_port" class="server-port" <?php echo $possibly_readonly; ?> value="3306" maxlength="5" size="5" /></td>
1176 </tr>
1177 <tr class="even toggler remote-server">
1178 <td><?php echo __('Socket'); ?></td>
1179 <td><input type="text" name="<?php echo $type; ?>_socket" class="server-socket" <?php echo $possibly_readonly; ?>/></td>
1180 </tr>
1181 <tr class="odd toggler remote-server">
1182 <td><?php echo __('User name'); ?></td>
1183 <td><input type="text" name="<?php echo $type; ?>_username" class="server-user" /></td>
1184 </tr>
1185 <tr class="even toggler remote-server">
1186 <td><?php echo __('Password'); ?></td>
1187 <td><input type="password" name="<?php echo $type; ?>_pass" class="server-pass" /> </td>
1188 </tr>
1189 <tr class="odd toggler remote-server">
1190 <td><?php echo __('Database'); ?></td>
1191 <td><input type="text" name="<?php echo $type; ?>_db" class="server-db" /></td>
1192 </tr>
1193 <tr class="even toggler current-server" style="display: none;">
1194 <td><?php echo __('Database'); ?></td>
1195 <td>
1196 <?php
1197 // these unset() do not complain if the elements do not exist
1198 unset($databases['mysql']);
1199 unset($databases['information_schema']);
1201 if (count($databases) == 0) {
1202 echo __('No databases');
1203 } else {
1204 echo '
1205 <select name="' . $type . '_db_sel">
1207 foreach ($databases as $db) {
1208 echo ' <option>' . htmlspecialchars($db['SCHEMA_NAME']) . '</option>';
1210 echo '</select>';
1212 echo '</td> </tr>
1213 </table>';
1215 unset ($types, $type);
1217 echo '
1218 </fieldset>
1219 <fieldset class="tblFooters">
1220 <input type="submit" name="submit_connect" value="' . __('Go') .'" id="buttonGo" />
1221 </fieldset>
1222 </form>
1223 </div>
1224 <div class="notice">' . __('Target database will be completely synchronized with source database. Source database will remain unchanged.') . '</div>';
1228 * Displays the footer
1230 require './libraries/footer.inc.php';