0) { ${"{$con}_server"}['port'] = ${"{$con}_port"}; } } ${"{$con}_connection"} = PMA_DBI_connect(${"{$con}_username"}, ${"{$con}_password"}, $is_controluser = false, ${"{$con}_server"}, $auxiliary_connection = true); } // end foreach ($cons as $con) if ((! $src_connection && $src_type == 'rmt') || (! $trg_connection && $trg_type == 'rmt')) { /** * Displays the connection error string if * connections are not established */ echo '
'; if(! $src_connection && $src_type == 'rmt') { echo $GLOBALS['strCouldNotConnectSource'] . '
'; } if(! $trg_connection && $trg_type == 'rmt'){ echo $GLOBALS['strCouldNotConnectTarget']; } echo '
'; unset($_REQUEST['submit_connect']); } else { /** * Creating the link object for both source and target databases and * selecting the source and target databases using these links */ foreach ($cons as $con) { if (${"{$con}_connection"} != null) { ${"{$con}_link"} = PMA_DBI_connect(${"{$con}_username"}, ${"{$con}_password"}, $is_controluser = false, ${"{$con}_server"}); } else { ${"{$con}_link"} = null; } ${"{$con}_db_selected"} = PMA_DBI_select_db(${"{$con}_db"}, ${"{$con}_link"}); } // end foreach ($cons as $con) if (($src_db_selected != 1) || ($trg_db_selected != 1)) { /** * Displays error string if the database(s) did not exist */ echo '
'; if ($src_db_selected != 1) { echo sprintf($GLOBALS['strDatabaseNotExisting'], htmlspecialchars($src_db)); } if ($trg_db_selected != 1) { echo sprintf($GLOBALS['strDatabaseNotExisting'], htmlspecialchars($trg_db)); } echo '
'; unset($_REQUEST['submit_connect']); } else if (($src_db_selected == 1) && ($trg_db_selected == 1)) { /** * Using PMA_DBI_get_tables() to get all the tables * from target and source databases. */ $src_tables = PMA_DBI_get_tables($src_db, $src_link); $source_tables_num = sizeof($src_tables); $trg_tables = PMA_DBI_get_tables($trg_db, $trg_link); $target_tables_num = sizeof($trg_tables); /** * initializing arrays to save matching and non-matching * table names from target and source databases. */ $unmatched_num_src = 0; $source_tables_uncommon = array(); $unmatched_num_trg = 0; $target_tables_uncommon = array(); $matching_tables = array(); $matching_tables_num = 0; /** * Using PMA_getMatchingTables to find which of the tables' names match * in target and source database. */ PMA_getMatchingTables($trg_tables, $src_tables, $matching_tables, $source_tables_uncommon); /** * Finding the uncommon tables for the target database * using function PMA_getNonMatchingTargetTables() */ PMA_getNonMatchingTargetTables($trg_tables, $matching_tables, $target_tables_uncommon); /** * Initializing several arrays to save the data and structure * difference between the source and target databases. */ $row_count = array(); //number of rows in source table that needs to be created in target database $fields_num = array(); //number of fields in each matching table $delete_array = array(); //stores the primary key values for target tables that have excessive rows than corresponding source tables. $insert_array = array(array(array()));// stores the primary key values for the rows in each source table that are not present in target tables. $update_array = array(array(array())); //stores the primary key values, name of field to be updated, value of the field to be updated for // each row of matching table. $matching_tables_fields = array(); //contains the fields' names for each matching table $matching_tables_keys = array(); //contains the primary keys' names for each matching table $uncommon_tables_fields = array(); //coantains the fields for all the source tables that are not present in target $matching_tables_num = sizeof($matching_tables); $source_columns = array(); //contains the full columns' information for all the source tables' columns $target_columns = array(); //contains the full columns' information for all the target tables' columns $uncommon_columns = array(); //contains names of columns present in source table but absent from the corresponding target table $source_indexes = array(); //contains indexes on all the source tables $target_indexes = array(); //contains indexes on all the target tables $add_indexes_array = array(); //contains the indexes name present in source but absent from target tables $target_tables_keys = array(); //contains the keys of all the target tables $alter_indexes_array = array(); //contains the names of all the indexes for each table that need to be altered in target database $remove_indexes_array = array(); //contains the names of indexes that are excessive in target tables $alter_str_array = array(array()); //contains the criteria for each column that needs to be altered in target tables $add_column_array = array(array()); //contains the name of columns that need to be added in target tables /** * The criteria array contains all the criteria against which columns are compared for differences. */ $criteria = array('Field', 'Type', 'Null', 'Collation', 'Key', 'Default', 'Comment'); for($i = 0; $i < sizeof($matching_tables); $i++) { /** * Finding out all the differences structure, data and index diff for all the matching tables only */ PMA_dataDiffInTables($src_db, $trg_db, $src_link, $trg_link, $matching_tables, $matching_tables_fields, $update_array, $insert_array, $delete_array, $fields_num, $i, $matching_tables_keys); PMA_structureDiffInTables($src_db, $trg_db, $src_link, $trg_link, $matching_tables, $source_columns, $target_columns, $alter_str_array, $add_column_array, $uncommon_columns, $criteria, $target_tables_keys, $i); PMA_indexesDiffInTables($src_db, $trg_db, $src_link, $trg_link, $matching_tables, $source_indexes, $target_indexes, $add_indexes_array, $alter_indexes_array, $remove_indexes_array, $i); } for($j = 0; $j < sizeof($source_tables_uncommon); $j++) { /** * Finding out the number of rows to be added in tables that need to be added in target database */ PMA_dataDiffInUncommonTables($source_tables_uncommon, $src_db, $src_link, $j, $row_count); } /** * Storing all arrays in session for use when page is reloaded for each button press */ $_SESSION['matching_tables'] = $matching_tables; $_SESSION['update_array'] = $update_array; $_SESSION['insert_array'] = $insert_array; $_SESSION['src_db'] = $src_db; $_SESSION['trg_db'] = $trg_db; $_SESSION['matching_fields'] = $matching_tables_fields; $_SESSION['src_uncommon_tables'] = $source_tables_uncommon; $_SESSION['src_username'] = $src_username ; $_SESSION['trg_username'] = $trg_username; $_SESSION['src_password'] = $src_password; $_SESSION['trg_password'] = $trg_password; $_SESSION['trg_password'] = $trg_password; $_SESSION['src_server'] = $src_server; $_SESSION['trg_server'] = $trg_server; $_SESSION['src_type'] = $src_type; $_SESSION['trg_type'] = $trg_type; $_SESSION['matching_tables_keys'] = $matching_tables_keys; $_SESSION['uncommon_tables_fields'] = $uncommon_tables_fields; $_SESSION['uncommon_tables_row_count'] = $row_count; $_SESSION['target_tables_uncommon'] = $target_tables_uncommon; $_SESSION['uncommon_tables'] = $source_tables_uncommon; $_SESSION['delete_array'] = $delete_array; $_SESSION['uncommon_columns'] = $uncommon_columns; $_SESSION['source_columns'] = $source_columns; $_SESSION['alter_str_array'] = $alter_str_array; $_SESSION['target_tables_keys'] = $target_tables_keys; $_SESSION['add_column_array'] = $add_column_array; $_SESSION['criteria'] = $criteria; $_SESSION['target_tables'] = $trg_tables; $_SESSION['add_indexes_array'] = $add_indexes_array; $_SESSION['alter_indexes_array'] = $alter_indexes_array; $_SESSION['remove_indexes_array'] = $remove_indexes_array; $_SESSION['source_indexes'] = $source_indexes; $_SESSION['target_indexes'] = $target_indexes; /** * Displays the sub-heading and icons showing Structure Synchronization and Data Synchronization */ echo '
' . PMA_generate_common_hidden_inputs('', ''); echo ''; echo ''; echo '

' . ($GLOBALS['cfg']['MainPageIconic'] ? '' : '') . $strStructureSyn .'

' .'

' . ($GLOBALS['cfg']['MainPageIconic'] ? '' : '') . $strDataSyn . '

' .'
'; /** * Displays the tables containing the source tables names, their difference with the target tables and target tables names */ PMA_syncDisplayHeaderSource($src_db); $odd_row = false; /** * Display the matching tables' names and difference, first */ for($i = 0; $i < count($matching_tables); $i++) { $num_of_updates = 0; $num_of_insertions = 0; /** * Calculating the number of updates for each matching table */ if (isset($update_array[$i])) { if (isset($update_array[$i][0][$matching_tables_keys[$i][0]])) { if (isset($update_array[$i])) { $num_of_updates = sizeof($update_array[$i]); } else { $num_of_updates = 0; } } else { $num_of_updates = 0; } } /** * Calculating the number of insertions for each matching table */ if (isset($insert_array[$i])) { if (isset($insert_array[$i][0][$matching_tables_keys[$i][0]])) { if (isset($insert_array[$i])) { $num_of_insertions = sizeof($insert_array[$i]); } else { $num_of_insertions = 0; } } else { $num_of_insertions = 0; } } /** * Displays the name of the matching table */ $odd_row = PMA_syncDisplayBeginTableRow($odd_row); echo '' . htmlspecialchars($matching_tables[$i]) . ' '; /** * Calculating the number of alter columns, number of columns to be added, number of columns to be removed, * number of index to be added and removed. */ $num_alter_cols = 0; $num_insert_cols = 0; $num_remove_cols = 0; $num_add_index = 0; $num_remove_index = 0; if (isset($alter_str_array[$i])) { $num_alter_cols = sizeof($alter_str_array[$i]); } if (isset($add_column_array[$i])) { $num_insert_cols = sizeof($add_column_array[$i]); } if (isset($uncommon_columns[$i])) { $num_remove_cols = sizeof($uncommon_columns[$i]); } if (isset($add_indexes_array[$i])) { $num_add_index = sizeof($add_indexes_array[$i]); } if (isset($remove_indexes_array[$i])) { $num_remove_index = sizeof($remove_indexes_array[$i]); } if (isset($alter_indexes_array[$i])) { $num_add_index += sizeof($alter_indexes_array[$i]); $num_remove_index += sizeof($alter_indexes_array[$i]); } /** * Display the red button of structure synchronization if there exists any structure difference or index difference. */ if (($num_alter_cols > 0) || ($num_insert_cols > 0) || ($num_remove_cols > 0) || ($num_add_index > 0) || ($num_remove_index > 0)) { echo '' . $GLOBALS['strClickToSelect'] . ''; } /** * Display the green button of data synchronization if there exists any data difference. */ if (isset($update_array[$i]) || isset($insert_array[$i])) { if (isset($update_array[$i][0][$matching_tables_keys[$i][0]]) || isset($insert_array[$i][0][$matching_tables_keys[$i][0]])) { echo '' . $GLOBALS['strClickToSelect'] . ''; } } echo ' '; } /** * Displays the tables' names present in source but missing from target */ for ($j = 0; $j < count($source_tables_uncommon); $j++) { $odd_row = PMA_syncDisplayBeginTableRow($odd_row); echo ' + ' . htmlspecialchars($source_tables_uncommon[$j]) . ' '; echo '' . $GLOBALS['strClickToSelect'] . ''; if ($row_count[$j] > 0) { echo '' . $GLOBALS['strClickToSelect'] . ''; } echo ' '; } foreach ($target_tables_uncommon as $tbl_nc_name) { $odd_row = PMA_syncDisplayBeginTableRow($odd_row); echo '      '; echo ''; } /** * Displays the target tables names */ echo ''; $odd_row = PMA_syncDisplayHeaderTargetAndMatchingTables($trg_db, $matching_tables); foreach ($source_tables_uncommon as $tbl_nc_name) { $odd_row = PMA_syncDisplayBeginTableRow($odd_row); echo '' . htmlspecialchars($tbl_nc_name) . ' (' . $GLOBALS['strNotPresent'] . ') '; } foreach ($target_tables_uncommon as $tbl_nc_name) { $odd_row = PMA_syncDisplayBeginTableRow($odd_row); echo ' - ' . htmlspecialchars($tbl_nc_name) . ''; echo ''; } echo ''; echo ''; /** * This "list" div will contain a table and each row will depict information about structure/data diffrence in tables. * Rows will be generated dynamically as soon as the colored buttons "D" or "S" are clicked. */ echo '
' . $strTable . ' ' . $strStructureDiff . ' ' . $strDataDiff . '
' . $strTableName . ' ' . $strCreateTable . ' ' . $strTableAddColumn . ' ' . $strTableRemoveColumn . ' ' . $strTableAlterColumn . ' ' . $strTableRemoveIndex . ' ' . $strTableApplyIndex . ' '. $strTableUpdateRow . ' ' . $strTableInsertRow . '
'; /** * This fieldset displays the checkbox to confirm deletion of previous rows from target tables */ echo '

'; echo ''; echo '' . '
'; echo '
'; } } } // end if ((isset($_REQUEST['submit_connect']))) /** * Display the page when 'Apply Selected Changes' is pressed */ if (isset($_REQUEST['Table_ids'])) { /** * Displays success message */ echo '
' . $GLOBALS['strHaveBeenSynchronized'] . '
'; $src_db = $_SESSION['src_db']; $trg_db = $_SESSION['trg_db']; $update_array = $_SESSION['update_array']; $insert_array = $_SESSION['insert_array']; $src_username = $_SESSION['src_username']; $trg_username = $_SESSION['trg_username']; $src_password = $_SESSION['src_password']; $trg_password = $_SESSION['trg_password']; $src_server = $_SESSION['src_server']; $trg_server = $_SESSION['trg_server']; $src_type = $_SESSION['src_type']; $trg_type = $_SESSION['trg_type']; $uncommon_tables = $_SESSION['uncommon_tables']; $matching_tables = $_SESSION['matching_tables']; $matching_tables_keys = $_SESSION['matching_tables_keys']; $matching_tables_fields = $_SESSION['matching_fields']; $source_tables_uncommon = $_SESSION['src_uncommon_tables']; $uncommon_tables_fields = $_SESSION['uncommon_tables_fields']; $target_tables_uncommon = $_SESSION['target_tables_uncommon']; $row_count = $_SESSION['uncommon_tables_row_count']; $target_tables = $_SESSION['target_tables']; $delete_array = $_SESSION['delete_array']; $uncommon_columns = $_SESSION['uncommon_columns']; $source_columns = $_SESSION['source_columns']; $alter_str_array = $_SESSION['alter_str_array']; $criteria = $_SESSION['criteria']; $target_tables_keys = $_SESSION['target_tables_keys']; $add_column_array = $_SESSION['add_column_array']; $add_indexes_array = $_SESSION['add_indexes_array']; $alter_indexes_array = $_SESSION['alter_indexes_array']; $remove_indexes_array = $_SESSION['remove_indexes_array']; $source_indexes = $_SESSION['source_indexes']; $target_indexes = $_SESSION['target_indexes']; $uncommon_cols = $uncommon_columns; /** * Creating link object for source and target databases */ foreach ($cons as $con) { if (${"{$con}_type"} == "rmt") { ${"{$con}_link"} = PMA_DBI_connect(${"{$con}_username"}, ${"{$con}_password"}, $is_controluser = false, ${"{$con}_server"}); } else { ${"{$con}_link"} = null; // working on current server, so initialize this for tracking // (does not work if user defined current server as a remote one) $GLOBALS['db'] = ${"{$con}_db"}; } } // end foreach ($cons as $con) /** * Initializing arrays to save the table ids whose data and structure difference is to be applied */ $matching_table_data_diff = array(); //stores id of matching table having data difference $matching_table_structure_diff = array(); //stores id of matching tables having structure difference $uncommon_table_structure_diff = array(); //stores id of uncommon tables having structure difference $uncommon_table_data_diff = array(); //stores id of uncommon tables having data difference for ($i = 0; isset($_REQUEST[$i]); $i++ ) { if (isset($_REQUEST[$i])) { $table_id = explode("US", $_REQUEST[$i]); if (isset($table_id[1])) { $uncommon_table_structure_diff[] = $table_id[1]; } $table_id = explode("UD", $_REQUEST[$i]); if (isset($table_id[1])) { $uncommon_table_data_diff[] = $table_id[1]; } $table_id = explode("MS", $_REQUEST[$i]); if (isset($table_id[1])) { $matching_table_structure_diff[] = $table_id[1]; } $table_id = explode("MD", $_REQUEST[$i]); if (isset($table_id[1])) { $matching_table_data_diff[] = $table_id[1]; } } } // end for /** * Applying the structure difference on selected matching tables */ for($q = 0; $q < sizeof($matching_table_structure_diff); $q++) { if (isset($alter_str_array[$matching_table_structure_diff[$q]])) { PMA_alterTargetTableStructure($trg_db, $trg_link, $matching_tables, $source_columns, $alter_str_array, $matching_tables_fields, $criteria, $matching_tables_keys, $target_tables_keys, $matching_table_structure_diff[$q], false); unset($alter_str_array[$matching_table_structure_diff[$q]]); } if (isset($add_column_array[$matching_table_structure_diff[$q]])) { PMA_findDeleteRowsFromTargetTables($delete_array, $matching_tables, $matching_table_structure_diff[$q], $target_tables_keys, $matching_tables_keys, $trg_db, $trg_link, $src_db, $src_link); if (isset($delete_array[$matching_table_structure_diff[$q]])) { PMA_deleteFromTargetTable($trg_db, $trg_link, $matching_tables, $matching_table_structure_diff[$q], $target_tables_keys, $delete_array, false); unset($delete_array[$matching_table_structure_diff[$q]]); } PMA_addColumnsInTargetTable($src_db, $trg_db,$src_link, $trg_link, $matching_tables, $source_columns, $add_column_array, $matching_tables_fields, $criteria, $matching_tables_keys, $target_tables_keys, $uncommon_tables,$uncommon_tables_fields, $matching_table_structure_diff[$q], $uncommon_cols, false); unset($add_column_array[$matching_table_structure_diff[$q]]); } if (isset($uncommon_columns[$matching_table_structure_diff[$q]])) { PMA_removeColumnsFromTargetTable($trg_db, $trg_link, $matching_tables, $uncommon_columns, $matching_table_structure_diff[$q], false); unset($uncommon_columns[$matching_table_structure_diff[$q]]); } if (isset($add_indexes_array[$matching_table_structure_diff[$q]]) || isset($remove_indexes_array[$matching_table_structure_diff[$q]]) || isset($alter_indexes_array[$matching_table_structure_diff[$q]])) { PMA_applyIndexesDiff ($trg_db, $trg_link, $matching_tables, $source_indexes, $target_indexes, $add_indexes_array, $alter_indexes_array, $remove_indexes_array, $matching_table_structure_diff[$q], false); unset($add_indexes_array[$matching_table_structure_diff[$q]]); unset($alter_indexes_array[$matching_table_structure_diff[$q]]); unset($remove_indexes_array[$matching_table_structure_diff[$q]]); } } /** * Applying the data difference. First checks if structure diff is applied or not. * If not, then apply structure difference first then apply data difference. */ for($p = 0; $p < sizeof($matching_table_data_diff); $p++) { if ($_REQUEST['checked'] == 'true') { PMA_findDeleteRowsFromTargetTables($delete_array, $matching_tables, $matching_table_data_diff[$p], $target_tables_keys, $matching_tables_keys, $trg_db, $trg_link, $src_db, $src_link); if (isset($delete_array[$matching_table_data_diff[$p]])) { PMA_deleteFromTargetTable($trg_db, $trg_link, $matching_tables, $matching_table_data_diff[$p], $target_tables_keys, $delete_array, false); unset($delete_array[$matching_table_data_diff[$p]]); } } if (isset($alter_str_array[$matching_table_data_diff[$p]])) { PMA_alterTargetTableStructure($trg_db, $trg_link, $matching_tables, $source_columns, $alter_str_array, $matching_tables_fields, $criteria, $matching_tables_keys, $target_tables_keys, $matching_table_data_diff[$p], false); unset($alter_str_array[$matching_table_data_diff[$p]]); } if (isset($add_column_array[$matching_table_data_diff[$p]])) { PMA_findDeleteRowsFromTargetTables($delete_array, $matching_tables, $matching_table_data_diff[$p], $target_tables_keys, $matching_tables_keys, $trg_db, $trg_link, $src_db, $src_link); if (isset($delete_array[$matching_table_data_diff[$p]])) { PMA_deleteFromTargetTable($trg_db, $trg_link, $matching_tables, $matching_table_data_diff[$p], $target_tables_keys, $delete_array, false); unset($delete_array[$matching_table_data_diff[$p]]); } PMA_addColumnsInTargetTable($src_db, $trg_db,$src_link, $trg_link, $matching_tables, $source_columns, $add_column_array, $matching_tables_fields, $criteria, $matching_tables_keys, $target_tables_keys, $uncommon_tables, $uncommon_tables_fields, $matching_table_data_diff[$p], $uncommon_cols, false); unset($add_column_array[$matching_table_data_diff[$p]]); } if (isset($uncommon_columns[$matching_table_data_diff[$p]])) { PMA_removeColumnsFromTargetTable($trg_db, $trg_link, $matching_tables, $uncommon_columns, $matching_table_data_diff[$p], false); unset($uncommon_columns[$matching_table_data_diff[$p]]); } if ((isset($matching_table_structure_diff[$q]) && isset($add_indexes_array[$matching_table_structure_diff[$q]])) || (isset($matching_table_structure_diff[$q]) && isset($remove_indexes_array[$matching_table_structure_diff[$q]])) || (isset($matching_table_structure_diff[$q]) && isset($alter_indexes_array[$matching_table_structure_diff[$q]]))) { PMA_applyIndexesDiff ($trg_db, $trg_link, $matching_tables, $source_indexes, $target_indexes, $add_indexes_array, $alter_indexes_array, $remove_indexes_array, $matching_table_structure_diff[$q], false); unset($add_indexes_array[$matching_table_structure_diff[$q]]); unset($alter_indexes_array[$matching_table_structure_diff[$q]]); unset($remove_indexes_array[$matching_table_structure_diff[$q]]); } /** * Applying the data difference. */ PMA_updateTargetTables($matching_tables, $update_array, $src_db, $trg_db, $trg_link, $matching_table_data_diff[$p], $matching_tables_keys, false); PMA_insertIntoTargetTable($matching_tables, $src_db, $trg_db, $src_link, $trg_link , $matching_tables_fields, $insert_array, $matching_table_data_diff[$p], $matching_tables_keys, $source_columns, $add_column_array, $criteria, $target_tables_keys, $uncommon_tables, $uncommon_tables_fields, $uncommon_cols, $alter_str_array, $source_indexes, $target_indexes, $add_indexes_array, $alter_indexes_array, $delete_array, $update_array, false); } /** * Updating the session variables to the latest values of the arrays. */ $_SESSION['delete_array'] = $delete_array; $_SESSION['uncommon_columns'] = $uncommon_columns; $_SESSION['alter_str_array'] = $alter_str_array; $_SESSION['add_column_array'] = $add_column_array; $_SESSION['add_indexes_array'] = $add_indexes_array; $_SESSION['remove_indexes_array'] = $remove_indexes_array; $_SESSION['insert_array'] = $insert_array; $_SESSION['update_array'] = $update_array; /** * Applying structure difference to selected non-matching tables (present in Source but absent from Target). */ for($s = 0; $s < sizeof($uncommon_table_structure_diff); $s++) { PMA_createTargetTables($src_db, $trg_db, $src_link, $trg_link, $uncommon_tables, $uncommon_table_structure_diff[$s], $uncommon_tables_fields, false); $_SESSION['uncommon_tables_fields'] = $uncommon_tables_fields; unset($uncommon_tables[$uncommon_table_structure_diff[$s]]); } /** * Applying data difference to selected non-matching tables (present in Source but absent from Target). * Before data synchronization, structure synchronization is confirmed. */ for($r = 0; $r < sizeof($uncommon_table_data_diff); $r++) { if (!(in_array($uncommon_table_data_diff[$r], $uncommon_table_structure_diff))) { if (isset($uncommon_tables[$uncommon_table_data_diff[$r]])) { PMA_createTargetTables($src_db, $trg_db, $src_link, $trg_link, $uncommon_tables, $uncommon_table_data_diff[$r], $uncommon_tables_fields, false); $_SESSION['uncommon_tables_fields'] = $uncommon_tables_fields; unset($uncommon_tables[$uncommon_table_data_diff[$r]]); } } PMA_populateTargetTables($src_db, $trg_db, $src_link, $trg_link, $source_tables_uncommon, $uncommon_table_data_diff[$r], $_SESSION['uncommon_tables_fields'], false); unset($row_count[$uncommon_table_data_diff[$r]]); } /** * Again all the tables from source and target database are displayed with their differences. * The differences have been removed from tables that have been synchronized */ echo '
' . PMA_generate_common_hidden_inputs('', ''); PMA_syncDisplayHeaderSource($src_db); $odd_row = false; for($i = 0; $i < count($matching_tables); $i++) { $odd_row = PMA_syncDisplayBeginTableRow($odd_row); echo '' . htmlspecialchars($matching_tables[$i]) . ' '; $num_alter_cols = 0; $num_insert_cols = 0; $num_remove_cols = 0; $num_add_index = 0; $num_remove_index = 0; if (isset($alter_str_array[$i])) { $num_alter_cols = sizeof($alter_str_array[$i]); } if (isset($add_column_array[$i])) { $num_insert_cols = sizeof($add_column_array[$i]); } if (isset($uncommon_columns[$i])) { $num_remove_cols = sizeof($uncommon_columns[$i]); } if (isset($add_indexes_array[$i])) { $num_add_index = sizeof($add_indexes_array[$i]); } if (isset($remove_indexes_array[$i])) { $num_remove_index = sizeof($remove_indexes_array[$i]); } if (($num_alter_cols > 0) || ($num_insert_cols > 0) || ($num_remove_cols > 0) || ($num_add_index > 0) || ($num_remove_index > 0)) { echo '' . $GLOBALS['strClickToSelect'] . ''; } if (!(in_array($i, $matching_table_data_diff))) { if (isset($matching_tables_keys[$i][0]) && isset($update_array[$i][0][$matching_tables_keys[$i][0]])) { if (isset($update_array[$i])) { $num_of_updates = sizeof($update_array[$i]); } else { $num_of_updates = 0; } } else { $num_of_updates = 0; } if (isset($matching_tables_keys[$i][0]) && isset($insert_array[$i][0][$matching_tables_keys[$i][0]])) { if (isset($insert_array[$i])) { $num_of_insertions = sizeof($insert_array[$i]); } else { $num_of_insertions = 0; } } else { $num_of_insertions = 0; } if ((isset($matching_tables_keys[$i][0]) && isset($update_array[$i][0][$matching_tables_keys[$i][0]])) || (isset($matching_tables_keys[$i][0]) && isset($insert_array[$i][0][$matching_tables_keys[$i][0]]))) { echo '' . $GLOBALS['strClickToSelect'] . ''; } } else { unset($update_array[$i]); unset($insert_array[$i]); } echo ' '; } /** * placing updated value of arrays in session * */ $_SESSION['update_array'] = $update_array; $_SESSION['insert_array'] = $insert_array; for ($j = 0; $j < count($source_tables_uncommon); $j++) { $odd_row = PMA_syncDisplayBeginTableRow($odd_row); echo ' + ' . htmlspecialchars($source_tables_uncommon[$j]) . ' '; /** * Display the difference only when it has not been applied */ if (!(in_array($j, $uncommon_table_structure_diff))) { if (isset($uncommon_tables[$j])) { echo '' . $GLOBALS['strClickToSelect'] . '' .' '; } } else { unset($uncommon_tables[$j]); } /** * Display the difference only when it has not been applied */ if (!(in_array($j, $uncommon_table_data_diff))) { if (isset($row_count[$j]) && ($row_count > 0)) { echo '' . $GLOBALS['strClickToSelect'] . ''; } } else { unset($row_count[$j]); } echo ' '; } /** * placing the latest values of arrays in session */ $_SESSION['uncommon_tables'] = $uncommon_tables; $_SESSION['uncommon_tables_row_count'] = $row_count; /** * Displaying the target database tables */ foreach ($target_tables_uncommon as $tbl_nc_name) { $odd_row = PMA_syncDisplayBeginTableRow($odd_row); echo '      '; echo ''; } echo ''; $odd_row = PMA_syncDisplayHeaderTargetAndMatchingTables($trg_db, $matching_tables); foreach ($source_tables_uncommon as $tbl_nc_name) { $odd_row = PMA_syncDisplayBeginTableRow($odd_row); if (in_array($tbl_nc_name, $uncommon_tables)) { echo '' . htmlspecialchars($tbl_nc_name) . ' (' . $GLOBALS['strNotPresent'] . ')'; } else { echo '' . htmlspecialchars($tbl_nc_name) . ''; } echo ' '; } foreach ($target_tables_uncommon as $tbl_nc_name) { $odd_row = PMA_syncDisplayBeginTableRow($odd_row); echo ' - ' . htmlspecialchars($tbl_nc_name) . ''; echo ''; } echo ' '; /** * This "list" div will contain a table and each row will depict information about structure/data diffrence in tables. * Rows will be generated dynamically as soon as the colored buttons "D" or "S" are clicked. */ echo '
'; echo '
' . $strTable . ' ' . $strStructureDiff . ' ' . $strDataDiff . '
' . $strTableName . ' ' . $strCreateTable . ' ' . $strTableAddColumn . ' ' . $strTableRemoveColumn . ' ' . $strTableAlterColumn . ' ' . $strTableRemoveIndex . ' ' . $strTableApplyIndex . ' ' . $strTableUpdateRow . ' ' . $strTableInsertRow . '
'; /** * This fieldset displays the checkbox to confirm deletion of previous rows from target tables */ echo '

'; echo '
'; echo ''; echo '' . '
'; echo '
'; } /** * Displays the page when 'Synchronize Databases' is pressed. */ if (isset($_REQUEST['synchronize_db'])) { $src_db = $_SESSION['src_db']; $trg_db = $_SESSION['trg_db']; $update_array = $_SESSION['update_array']; $insert_array = $_SESSION['insert_array']; $src_username = $_SESSION['src_username']; $trg_username = $_SESSION['trg_username']; $src_password = $_SESSION['src_password']; $trg_password = $_SESSION['trg_password']; $matching_tables = $_SESSION['matching_tables']; $matching_tables_keys = $_SESSION['matching_tables_keys']; $matching_tables_fields = $_SESSION['matching_fields']; $source_tables_uncommon = $_SESSION['src_uncommon_tables']; $uncommon_tables_fields = $_SESSION['uncommon_tables_fields']; $target_tables_uncommon = $_SESSION['target_tables_uncommon']; $row_count = $_SESSION['uncommon_tables_row_count']; $uncommon_tables = $_SESSION['uncommon_tables']; $target_tables = $_SESSION['target_tables']; $delete_array = $_SESSION['delete_array']; $uncommon_columns = $_SESSION['uncommon_columns']; $source_columns = $_SESSION['source_columns']; $alter_str_array = $_SESSION['alter_str_array']; $criteria = $_SESSION['criteria']; $target_tables_keys = $_SESSION['target_tables_keys']; $add_column_array = $_SESSION['add_column_array']; $add_indexes_array = $_SESSION['add_indexes_array']; $alter_indexes_array = $_SESSION['alter_indexes_array']; $remove_indexes_array = $_SESSION['remove_indexes_array']; $source_indexes = $_SESSION['source_indexes']; $target_indexes = $_SESSION['target_indexes']; $uncommon_cols = $uncommon_columns; /** * Display success message. */ echo '
' . $GLOBALS['strTargetDatabaseHasBeenSynchronized'] . '
'; /** * Displaying all the tables of source and target database and now no difference is there. */ PMA_syncDisplayHeaderSource($src_db); $odd_row = false; for($i = 0; $i < count($matching_tables); $i++) { $odd_row = PMA_syncDisplayBeginTableRow($odd_row); echo '' . htmlspecialchars($matching_tables[$i]) . ' '; } for ($j = 0; $j < count($source_tables_uncommon); $j++) { $odd_row = PMA_syncDisplayBeginTableRow($odd_row); echo ' + ' . htmlspecialchars($source_tables_uncommon[$j]) . ' '; echo ' '; } foreach ($target_tables_uncommon as $tbl_nc_name) { $odd_row = PMA_syncDisplayBeginTableRow($odd_row); echo '      '; echo ''; } echo ''; $odd_row = PMA_syncDisplayHeaderTargetAndMatchingTables($trg_db, $matching_tables); foreach ($source_tables_uncommon as $tbl_nc_name) { $odd_row = PMA_syncDisplayBeginTableRow($odd_row); echo '' . htmlspecialchars($tbl_nc_name) . ' '; } foreach ($target_tables_uncommon as $tbl_nc_name) { $odd_row = PMA_syncDisplayBeginTableRow($odd_row); echo ' ' . htmlspecialchars($tbl_nc_name) . ''; echo ''; } echo ' '; /** * connecting the source and target servers */ if ('rmt' == $_SESSION['src_type']) { $src_link = PMA_DBI_connect($src_username, $src_password, $is_controluser = false, $_SESSION['src_server']); } else { $src_link = $GLOBALS['userlink']; // working on current server, so initialize this for tracking // (does not work if user defined current server as a remote one) $GLOBALS['db'] = $_SESSION['src_db']; } if ('rmt' == $_SESSION['trg_type']) { $trg_link = PMA_DBI_connect($trg_username, $trg_password, $is_controluser = false, $_SESSION['trg_server']); } else { $trg_link = $GLOBALS['userlink']; // working on current server, so initialize this for tracking $GLOBALS['db'] = $_SESSION['trg_db']; } /** * Displaying the queries. */ echo '
' . $GLOBALS['strQueriesExecuted'] . '
'; echo '
'; /** * Applying all sorts of differences for each matching table */ for($p = 0; $p < sizeof($matching_tables); $p++) { /** * If the check box is checked for deleting previous rows from the target database tables then * first find out rows to be deleted and then delete the rows. */ if (isset($_REQUEST['delete_rows'])) { PMA_findDeleteRowsFromTargetTables($delete_array, $matching_tables, $p, $target_tables_keys, $matching_tables_keys, $trg_db, $trg_link, $src_db, $src_link); if (isset($delete_array[$p])) { PMA_deleteFromTargetTable($trg_db, $trg_link, $matching_tables, $p, $target_tables_keys, $delete_array, true); unset($delete_array[$p]); } } if (isset($alter_str_array[$p])) { PMA_alterTargetTableStructure($trg_db, $trg_link, $matching_tables, $source_columns, $alter_str_array, $matching_tables_fields, $criteria, $matching_tables_keys, $target_tables_keys, $p, true); unset($alter_str_array[$p]); } if (! empty($add_column_array[$p])) { PMA_findDeleteRowsFromTargetTables($delete_array, $matching_tables, $p, $target_tables_keys, $matching_tables_keys, $trg_db, $trg_link, $src_db, $src_link); if (isset($delete_array[$p])) { PMA_deleteFromTargetTable($trg_db, $trg_link, $matching_tables, $p, $target_tables_keys, $delete_array, true); unset($delete_array[$p]); } PMA_addColumnsInTargetTable($src_db, $trg_db, $src_link, $trg_link, $matching_tables, $source_columns, $add_column_array, $matching_tables_fields, $criteria, $matching_tables_keys, $target_tables_keys, $uncommon_tables, $uncommon_tables_fields, $p, $uncommon_cols, true); unset($add_column_array[$p]); } if (isset($uncommon_columns[$p])) { PMA_removeColumnsFromTargetTable($trg_db, $trg_link, $matching_tables, $uncommon_columns, $p, true); unset($uncommon_columns[$p]); } if (isset($matching_table_structure_diff) && (isset($add_indexes_array[$matching_table_structure_diff[$p]]) || isset($remove_indexes_array[$matching_table_structure_diff[$p]]) || isset($alter_indexes_array[$matching_table_structure_diff[$p]]))) { PMA_applyIndexesDiff ($trg_db, $trg_link, $matching_tables, $source_indexes, $target_indexes, $add_indexes_array, $alter_indexes_array, $remove_indexes_array, $matching_table_structure_diff[$p], true); unset($add_indexes_array[$matching_table_structure_diff[$p]]); unset($alter_indexes_array[$matching_table_structure_diff[$p]]); unset($remove_indexes_array[$matching_table_structure_diff[$p]]); } PMA_updateTargetTables($matching_tables, $update_array, $src_db, $trg_db, $trg_link, $p, $matching_tables_keys, true); PMA_insertIntoTargetTable($matching_tables, $src_db, $trg_db, $src_link, $trg_link , $matching_tables_fields, $insert_array, $p, $matching_tables_keys, $matching_tables_keys, $source_columns, $add_column_array, $criteria, $target_tables_keys, $uncommon_tables, $uncommon_tables_fields,$uncommon_cols, $alter_str_array,$source_indexes, $target_indexes, $add_indexes_array, $alter_indexes_array, $delete_array, $update_array, true); } /** * Creating and populating tables present in source but absent from target database. */ for($q = 0; $q < sizeof($source_tables_uncommon); $q++) { if (isset($uncommon_tables[$q])) { PMA_createTargetTables($src_db, $trg_db, $src_link, $trg_link, $source_tables_uncommon, $q, $uncommon_tables_fields, true); } if (isset($row_count[$q])) { PMA_populateTargetTables($src_db, $trg_db, $src_link, $trg_link, $source_tables_uncommon, $q, $uncommon_tables_fields, true); } } echo "
"; } /** * Displays the main page when none of the following buttons is pressed */ if (! isset($_REQUEST['submit_connect']) && ! isset($_REQUEST['synchronize_db']) && ! isset($_REQUEST['Table_ids']) ) { /** * Displays the sub-page heading */ echo '

' . ($GLOBALS['cfg']['MainPageIconic'] ? '' : '') . $strSynchronize .'

'; echo '
' // TODO: add check if all var. are filled in . PMA_generate_common_hidden_inputs('', ''); echo '
'; echo '' . $GLOBALS['strSynchronize'] . ''; /** * Displays the forms */ $databases = PMA_DBI_get_databases_full(null, false, null, 'SCHEMA_NAME', 'ASC', 0, true); foreach ($cons as $type) { echo '
' . $GLOBALS['strDatabase_'.$type] . '
' . $GLOBALS['strHost'] . '
' . $GLOBALS['strPort'] . '
' . $GLOBALS['strSocket'] . '
' . $GLOBALS['strUserName']. '
' . $GLOBALS['strPassword'] . '
' . $GLOBALS['strDatabase'] . '
'; // Add JS to show/hide rows based on the selection PMA_js(''. '$(\'' . $type . '_type\').addEvent(\'change\',function() {' . ' if ($(\'' . $type . 'tr1\').getStyle(\'display\')=="none") {' . ' for (var i=1; i<7; i++)' . ' $(\'' . $type . 'tr\'+i).tween(\'display\', \'table-row\');' . ' $(\'' . $type . 'tr7\').tween(\'display\', \'none\');' . ' }' . ' else {' . ' for (var i=1; i<7; i++)'. ' $(\'' . $type . 'tr\'+i).tween(\'display\', \'none\');' . ' $(\'' . $type . 'tr7\').tween(\'display\', \'table-row\');'. ' }' . '});' ); } unset ($types, $type); echo '
' . $strSynchronizationNote . '
'; } /** * Displays the footer */ require_once './libraries/footer.inc.php'; ?>