From 1884cfcf1e114c449c81ff70f61cf870373ac9d1 Mon Sep 17 00:00:00 2001 From: Marc Delisle Date: Sat, 5 Dec 2009 14:54:08 +0000 Subject: [PATCH] code cleanup --- libraries/server_synchronize.lib.php | 2 +- server_synchronize.php | 283 +++++++++++++-------------- 2 files changed, 138 insertions(+), 147 deletions(-) diff --git a/libraries/server_synchronize.lib.php b/libraries/server_synchronize.lib.php index 4bd06bc7c..23cd6785e 100644 --- a/libraries/server_synchronize.lib.php +++ b/libraries/server_synchronize.lib.php @@ -1417,7 +1417,7 @@ function PMA_syncDisplayHeaderTargetAndMatchingTables($trg_db, $matching_tables) $odd_row = false; foreach ($matching_tables as $tbl_name) { $odd_row = PMA_syncDisplayBeginTableRow($odd_row); - echo ' ' .$tbl_name . ''; + echo ' ' . htmlspecialchars($tbl_name) . ''; echo ''; } return $odd_row; diff --git a/server_synchronize.php b/server_synchronize.php index 05fb12d88..0a6025f12 100644 --- a/server_synchronize.php +++ b/server_synchronize.php @@ -56,18 +56,18 @@ $cons = array ("src", "trg"); if ((isset($_REQUEST['submit_connect']))) { foreach ($cons as $con) { - ${"{$con}_host"} = $_REQUEST[$con.'_host']; - ${"{$con}_username"} = $_REQUEST[$con.'_username']; - ${"{$con}_password"} = $_REQUEST[$con.'_pass']; - ${"{$con}_port"} = $_REQUEST[$con.'_port']; - ${"{$con}_socket"} = $_REQUEST[$con.'_socket']; - ${"{$con}_db"} = $_REQUEST[$con.'_db']; - ${"{$con}_type"} = $_REQUEST[$con.'_type']; + ${"{$con}_host"} = $_REQUEST[$con . '_host']; + ${"{$con}_username"} = $_REQUEST[$con . '_username']; + ${"{$con}_password"} = $_REQUEST[$con . '_pass']; + ${"{$con}_port"} = $_REQUEST[$con . '_port']; + ${"{$con}_socket"} = $_REQUEST[$con . '_socket']; + ${"{$con}_db"} = $_REQUEST[$con . '_db']; + ${"{$con}_type"} = $_REQUEST[$con . '_type']; if (${"{$con}_type"} == 'cur') { ${"{$con}_connection"} = null; ${"{$con}_server"} = null; - ${"{$con}_db"} = $_REQUEST[$con.'_db_sel']; + ${"{$con}_db"} = $_REQUEST[$con . '_db_sel']; continue; } @@ -89,9 +89,9 @@ if ((isset($_REQUEST['submit_connect']))) { * connections are not established */ - echo '
' . "\n" ; + echo '
'; if(! $src_connection && $src_type == 'rmt') { - echo $GLOBALS['strCouldNotConnectSource'].'
'; + echo $GLOBALS['strCouldNotConnectSource'] . '
'; } if(! $trg_connection && $trg_type == 'rmt'){ echo $GLOBALS['strCouldNotConnectTarget']; @@ -117,12 +117,12 @@ if ((isset($_REQUEST['submit_connect']))) { /** * Displays error string if the database(s) did not exist */ - echo '
' . "\n" ; + echo '
'; if ($src_db_selected != 1) { - echo sprintf($GLOBALS['strDatabaseNotExisting'], $src_db); + echo sprintf($GLOBALS['strDatabaseNotExisting'], htmlspecialchars($src_db)); } if ($trg_db_selected != 1) { - echo sprintf($GLOBALS['strDatabaseNotExisting'], $trg_db); + echo sprintf($GLOBALS['strDatabaseNotExisting'], htmlspecialchars($trg_db)); } echo '
'; unset($_REQUEST['submit_connect']); @@ -255,22 +255,22 @@ if ((isset($_REQUEST['submit_connect']))) { */ echo '
' . PMA_generate_common_hidden_inputs('', ''); - echo ' + echo '
- '; - echo ''; + echo ''; + . $strDataSyn + . '' .''; echo '

' . "\n" +

' . ($GLOBALS['cfg']['MainPageIconic'] ? '' . "\n" + . ' height="32" alt="" />' : '') - . $strStructureSyn . "\n" - .'

' . "\n" .'

' . "\n" + . $strStructureSyn + .'

' .'

' . ($GLOBALS['cfg']['MainPageIconic'] ? '' . "\n" + . ' height="32" alt="" />' : '') - . $strDataSyn . "\n" - . '

' . "\n" .'
'; @@ -317,7 +317,7 @@ if ((isset($_REQUEST['submit_connect']))) { * Displays the name of the matching table */ $odd_row = PMA_syncDisplayBeginTableRow($odd_row); - echo '' . $matching_tables[$i]. "\n" . ' + echo '' . htmlspecialchars($matching_tables[$i]) . ' '; /** * Calculating the number of alter columns, number of columns to be added, number of columns to be removed, @@ -347,14 +347,13 @@ if ((isset($_REQUEST['submit_connect']))) { /** * 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)) { + if (($num_alter_cols > 0) || ($num_insert_cols > 0) || ($num_remove_cols > 0) || ($num_add_index > 0) || ($num_remove_index > 0)) { echo '' . $GLOBALS['strClickToSelect'] . ''. "\n" ; - + onclick="showDetails(' . "'MS" . $i . "','" . $num_alter_cols . "','" .$num_insert_cols . + "','" . $num_remove_cols . "','" . $num_add_index . "','" . $num_remove_index . "'" + . ', this ,' . "'" . htmlspecialchars($matching_tables[$i]) . "'" . ')"/>'; } /** * Display the green button of data synchronization if there exists any data difference. @@ -364,8 +363,8 @@ if ((isset($_REQUEST['submit_connect']))) { echo '' . $GLOBALS['strClickToSelect'] . ''. "\n"; + onclick="showDetails('. "'MD" . $i . "','" . $num_of_updates . "','" . $num_of_insertions . + "','" . null . "','" . null . "','" . null . "'" . ', this ,' . "'" . htmlspecialchars($matching_tables[$i]) . "'" . ')" />'; } } echo ' @@ -376,26 +375,26 @@ if ((isset($_REQUEST['submit_connect']))) { */ for ($j = 0; $j < count($source_tables_uncommon); $j++) { $odd_row = PMA_syncDisplayBeginTableRow($odd_row); - echo ' + ' .$source_tables_uncommon[$j]. "\n" . ' '; + echo ' + ' . htmlspecialchars($source_tables_uncommon[$j]) . ' '; echo '' . $GLOBALS['strClickToSelect'] . ''. "\n" ; + onclick="showDetails(' . "'US" . $j . "','" . null . "','" . null . "','" . null . "','" . null . "','" . null . "'" . ', this ,' + . "'" . htmlspecialchars($source_tables_uncommon[$j]) . "'" . ')"/>'; if ($row_count[$j] > 0) { - echo '' . $GLOBALS['strClickToSelect'] . ''. "\n"; + onclick="showDetails(' . "'UD" . $j . "','" . null . "','" . $row_count[$j] . "','" . null . + "','" . null . "','" . null . "'" . ', this ,' . "'" . htmlspecialchars($source_tables_uncommon[$j]) . "'" . ')" />'; } echo ' '; } foreach ($target_tables_uncommon as $tbl_nc_name) { $odd_row = PMA_syncDisplayBeginTableRow($odd_row); - echo '      '; + echo '      '; echo ''; } /** @@ -406,12 +405,12 @@ if ((isset($_REQUEST['submit_connect']))) { $odd_row = PMA_syncDisplayHeaderTargetAndMatchingTables($trg_db, $matching_tables); foreach ($source_tables_uncommon as $tbl_nc_name) { $odd_row = PMA_syncDisplayBeginTableRow($odd_row); - echo '' .$tbl_nc_name . "\n" . ' (' . $GLOBALS['strNotPresent'] . ') + echo '' . htmlspecialchars($tbl_nc_name) . ' (' . $GLOBALS['strNotPresent'] . ') '; } foreach ($target_tables_uncommon as $tbl_nc_name) { $odd_row = PMA_syncDisplayBeginTableRow($odd_row); - echo ' - ' .$tbl_nc_name . ''; + echo ' - ' . htmlspecialchars($tbl_nc_name) . ''; echo ''; } echo ''; @@ -429,20 +428,20 @@ if ((isset($_REQUEST['submit_connect']))) { - - - + + + - - - - - - - - - + + + + + + + + + @@ -454,11 +453,10 @@ if ((isset($_REQUEST['submit_connect']))) { echo '

' . $strTableDeleteRows . '

-
' . "\n"; +
'; echo ''; - echo '' - . "\n" . '
' . "\n"; + . '" onclick ="ApplySelectedChanges(' . "'" . $_SESSION['token'] . "'" . ')" />'; + echo '' . '
'; echo ''; } } @@ -513,7 +511,7 @@ if (isset($_REQUEST['Table_ids'])) { * Creating link object for source and target databases */ foreach ($cons as $con) { - if (${"{$con}_type"}=="rmt") { + if (${"{$con}_type"} == "rmt") { ${"{$con}_link"} = PMA_DBI_connect(${"{$con}_username"}, ${"{$con}_password"}, $is_controluser = false, ${"{$con}_server"}); } else { ${"{$con}_link"} = null; @@ -718,7 +716,7 @@ if (isset($_REQUEST['Table_ids'])) { $odd_row = false; for($i = 0; $i < count($matching_tables); $i++) { $odd_row = PMA_syncDisplayBeginTableRow($odd_row); - echo ' + echo ' + echo ''; + echo ''; } else { - echo ''; + echo ''; } echo ' '; } foreach ($target_tables_uncommon as $tbl_nc_name) { $odd_row = PMA_syncDisplayBeginTableRow($odd_row); - echo ''; + echo ''; echo ''; } echo '
'. $strTable .' '. $strStructureDiff .' '. $strDataDiff .'' . $strTable . ' ' . $strStructureDiff . ' ' . $strDataDiff . '
'. $strTableName .''. $strCreateTable .''. $strTableAddColumn .''. $strTableRemoveColumn .''. $strTableAlterColumn .''. $strTableRemoveIndex .''. $strTableApplyIndex .''. $strTableUpdateRow .''. $strTableInsertRow .'' . $strTableName . '' . $strCreateTable . '' . $strTableAddColumn . '' . $strTableRemoveColumn . '' . $strTableAlterColumn . '' . $strTableRemoveIndex . '' . $strTableApplyIndex . ''. $strTableUpdateRow . '' . $strTableInsertRow . '
' . $matching_tables[$i]. "\n" . '' . $matching_tables[$i] . ' '; $num_alter_cols = 0; @@ -743,12 +741,11 @@ if (isset($_REQUEST['Table_ids'])) { $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)) { + if (($num_alter_cols > 0) || ($num_insert_cols > 0) || ($num_remove_cols > 0) || ($num_add_index > 0) || ($num_remove_index > 0)) { echo '' . $GLOBALS['strClickToSelect'] . ''. "\n" ; + onclick="showDetails(' . "'MS" . $i . "','" . $num_alter_cols . "','" . $num_insert_cols . "','" . $num_remove_cols . "','" . $num_add_index . "','" . $num_remove_index . "'" .', + this ,' . "'" . $matching_tables[$i] . "'" . ')"/>'; } if (!(in_array($i, $matching_table_data_diff))) { @@ -775,8 +772,8 @@ if (isset($_REQUEST['Table_ids'])) { || (isset($matching_tables_keys[$i][0]) && isset($insert_array[$i][0][$matching_tables_keys[$i][0]]))) { echo '' . $GLOBALS['strClickToSelect'] . ''; + onclick="showDetails(' . "'MD" . $i . "','" . $num_of_updates . "','" . $num_of_insertions . + "','" . null . "','" . null . "','" . null . "'" .', this ,' . "'" . htmlspecialchars($matching_tables[$i]) . "'" . ')" />'; } } else { unset($update_array[$i]); @@ -794,17 +791,16 @@ if (isset($_REQUEST['Table_ids'])) { for ($j = 0; $j < count($source_tables_uncommon); $j++) { $odd_row = PMA_syncDisplayBeginTableRow($odd_row); - echo ' + ' .$source_tables_uncommon[$j]. "\n" . ' + ' . 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'] . '' . "\n" .' '; + onclick="showDetails(' . "'US" . $j . "','" . null . "','" . null . "','" . null . "','" . null . "','" . null . "'" . ', this ,' . "'" . htmlspecialchars($source_tables_uncommon[$j]) . "'" . ')"/>' .' '; } } else { unset($uncommon_tables[$j]); @@ -814,10 +810,10 @@ if (isset($_REQUEST['Table_ids'])) { */ if (!(in_array($j, $uncommon_table_data_diff))) { if (isset($row_count[$j]) && ($row_count > 0)) { - echo '' . $GLOBALS['strClickToSelect'] . ''. "\n"; + onclick="showDetails(' . "'UD" . $j . "','" . null ."','" . $row_count[$j] ."','" + . null . "','" . null . "','" . null . "'" . ', this ,' . "'". htmlspecialchars($source_tables_uncommon[$j]) . "'" . ')" />'; } } else { unset($row_count[$j]); @@ -847,16 +843,16 @@ if (isset($_REQUEST['Table_ids'])) { foreach ($source_tables_uncommon as $tbl_nc_name) { $odd_row = PMA_syncDisplayBeginTableRow($odd_row); if (in_array($tbl_nc_name, $uncommon_tables)) { - echo '' .$tbl_nc_name . "\n" . ' (' . $GLOBALS['strNotPresent'] . ')' . htmlspecialchars($tbl_nc_name) . ' (' . $GLOBALS['strNotPresent'] . ')' .$tbl_nc_name . "\n" . '' . htmlspecialchars($tbl_nc_name) . '
- ' .$tbl_nc_name . ' - ' . htmlspecialchars($tbl_nc_name) . '
@@ -874,20 +870,20 @@ if (isset($_REQUEST['Table_ids'])) { echo ' - - - + + + - - - - - - - - - + + + + + + + + + @@ -901,11 +897,11 @@ if (isset($_REQUEST['Table_ids'])) {

' . $strTableDeleteRows . '

'; - echo '
' . "\n"; - echo ''; - echo '' - . "\n" . '
' . "\n"; + echo '
'; + echo ''; + echo '' + . '
'; echo ''; } @@ -960,13 +956,13 @@ if (isset($_REQUEST['synchronize_db'])) { for($i = 0; $i < count($matching_tables); $i++) { $odd_row = PMA_syncDisplayBeginTableRow($odd_row); - echo ' + echo ''; } for ($j = 0; $j < count($source_tables_uncommon); $j++) { $odd_row = PMA_syncDisplayBeginTableRow($odd_row); - echo ' '; + echo ' '; echo ''; } @@ -979,12 +975,12 @@ if (isset($_REQUEST['synchronize_db'])) { $odd_row = PMA_syncDisplayHeaderTargetAndMatchingTables($trg_db, $matching_tables); foreach ($source_tables_uncommon as $tbl_nc_name) { $odd_row = PMA_syncDisplayBeginTableRow($odd_row); - echo ' + echo ''; } foreach ($target_tables_uncommon as $tbl_nc_name) { $odd_row = PMA_syncDisplayBeginTableRow($odd_row); - echo ''; + echo ''; echo ''; } echo '
'. $strTable .' '. $strStructureDiff .' '. $strDataDiff .'' . $strTable . ' ' . $strStructureDiff . ' ' . $strDataDiff . '
'. $strTableName .''. $strCreateTable .''. $strTableAddColumn .''. $strTableRemoveColumn .''. $strTableAlterColumn .''. $strTableRemoveIndex .''. $strTableApplyIndex .''. $strTableUpdateRow .''. $strTableInsertRow .'' . $strTableName . '' . $strCreateTable . '' . $strTableAddColumn . '' . $strTableRemoveColumn . '' . $strTableAlterColumn . '' . $strTableRemoveIndex . '' . $strTableApplyIndex . '' . $strTableUpdateRow . '' . $strTableInsertRow . '
' . $matching_tables[$i]. "\n" . '' . htmlspecialchars($matching_tables[$i]) . '
+ ' .$source_tables_uncommon[$j]. "\n" . ' + ' . htmlspecialchars($source_tables_uncommon[$j]) . '
' .$tbl_nc_name . "\n" . ' ' . htmlspecialchars($tbl_nc_name) . '
' .$tbl_nc_name . ' ' . htmlspecialchars($tbl_nc_name) . '
'; @@ -1032,13 +1028,11 @@ if (isset($_REQUEST['synchronize_db'])) { } } 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 (isset($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); @@ -1051,7 +1045,6 @@ if (isset($_REQUEST['synchronize_db'])) { 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]); } @@ -1059,7 +1052,6 @@ if (isset($_REQUEST['synchronize_db'])) { (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); @@ -1093,71 +1085,70 @@ if (isset($_REQUEST['synchronize_db'])) { * 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']) ) + if (! isset($_REQUEST['submit_connect']) && ! isset($_REQUEST['synchronize_db']) && ! isset($_REQUEST['Table_ids']) ) { /** * Displays the sub-page heading */ - echo '

' . "\n" - . ($GLOBALS['cfg']['MainPageIconic'] + echo '

' . ($GLOBALS['cfg']['MainPageIconic'] ? '' + . ' height="18" alt="" />' : '') - . $strSynchronize . "\n" - .'

' . "\n"; + . $strSynchronize + .''; echo '
' // TODO: add check if all var. are filled in . PMA_generate_common_hidden_inputs('', ''); - echo '
'."\n"; - echo ''. $GLOBALS['strSynchronize']. ''."\n"; + echo '
'; + echo '' . $GLOBALS['strSynchronize'] . ''; /** - * Displays the forms - */ + * Displays the forms + */ $databases = PMA_DBI_get_databases_full(null, false, null, 'SCHEMA_NAME', 'ASC', 0, true); foreach ($cons as $type) { - echo ' + echo '
- + - - - + + + - - - + + + - - - + + + - - + + - - - + + + - - - + + + - - + +
'. $GLOBALS['strDatabase_'.$type] .'' . $GLOBALS['strDatabase_'.$type] . '
- + +
'. $GLOBALS['strHost']. '
' . $GLOBALS['strHost'] . '
'. $GLOBALS['strPort']. '
' . $GLOBALS['strPort'] . '
'. $GLOBALS['strSocket']. '
' . $GLOBALS['strSocket'] . '
'. $GLOBALS['strUserName']. '' . $GLOBALS['strUserName']. '
'. $GLOBALS['strPassword']. '
' . $GLOBALS['strPassword'] . '
'. $GLOBALS['strDatabase']. '
' . $GLOBALS['strDatabase'] . '