No need to use PMA_DBI_get_table_indexes_sql() here, use PMA_DBI_get_table_indexes()
[phpmyadmin.git] / server_synchronize.php
blob3cd11a020752f4f0467d89070a4fd4ba7543bdd5
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 ${"{$con}_version"} = PMA_DBI_fetch_value('SELECT VERSION()', 0, 0, ${"{$con}_link"});
113 ${"{$con}_is_drizzle"} = (bool)preg_match('/\d{4}\./', ${"{$con}_version"});
114 } // end foreach ($cons as $con)
116 if (($src_db_selected != 1) || ($trg_db_selected != 1)) {
118 * Displays error string if the database(s) did not exist
120 echo '<div class="error">';
121 if ($src_db_selected != 1) {
122 echo sprintf(__('\'%s\' database does not exist.'), htmlspecialchars($src_db));
124 if ($trg_db_selected != 1) {
125 echo sprintf(__('\'%s\' database does not exist.'), htmlspecialchars($trg_db));
127 echo '</div>';
128 unset($_REQUEST['submit_connect']);
130 } else if (($src_db_selected == 1) && ($trg_db_selected == 1)) {
133 * Using PMA_DBI_get_tables() to get all the tables
134 * from target and source databases.
136 $src_tables = PMA_DBI_get_tables($src_db, $src_link);
137 $source_tables_num = sizeof($src_tables);
139 $trg_tables = PMA_DBI_get_tables($trg_db, $trg_link);
140 $target_tables_num = sizeof($trg_tables);
143 * initializing arrays to save matching and non-matching
144 * table names from target and source databases.
146 $unmatched_num_src = 0;
147 $source_tables_uncommon = array();
148 $unmatched_num_trg = 0;
149 $target_tables_uncommon = array();
150 $matching_tables = array();
151 $matching_tables_num = 0;
154 * Using PMA_getMatchingTables to find which of the tables' names match
155 * in target and source database.
157 PMA_getMatchingTables($trg_tables, $src_tables, $matching_tables, $source_tables_uncommon);
159 * Finding the uncommon tables for the target database
160 * using function PMA_getNonMatchingTargetTables()
162 PMA_getNonMatchingTargetTables($trg_tables, $matching_tables, $target_tables_uncommon);
165 * Initializing several arrays to save the data and structure
166 * difference between the source and target databases.
168 $row_count = array(); //number of rows in source table that needs to be created in target database
169 $fields_num = array(); //number of fields in each matching table
170 $delete_array = array(); //stores the primary key values for target tables that have excessive rows than corresponding source tables.
171 $insert_array = array(array(array()));// stores the primary key values for the rows in each source table that are not present in target tables.
172 $update_array = array(array(array())); //stores the primary key values, name of field to be updated, value of the field to be updated for
173 // each row of matching table.
174 $matching_tables_fields = array(); //contains the fields' names for each matching table
175 $matching_tables_keys = array(); //contains the primary keys' names for each matching table
176 $uncommon_tables_fields = array(); //coantains the fields for all the source tables that are not present in target
177 $matching_tables_num = sizeof($matching_tables);
179 $source_columns = array(); //contains the full columns' information for all the source tables' columns
180 $target_columns = array(); //contains the full columns' information for all the target tables' columns
181 $uncommon_columns = array(); //contains names of columns present in source table but absent from the corresponding target table
182 $source_indexes = array(); //contains indexes on all the source tables
183 $target_indexes = array(); //contains indexes on all the target tables
184 $add_indexes_array = array(); //contains the indexes name present in source but absent from target tables
185 $target_tables_keys = array(); //contains the keys of all the target tables
186 $alter_indexes_array = array(); //contains the names of all the indexes for each table that need to be altered in target database
187 $remove_indexes_array = array(); //contains the names of indexes that are excessive in target tables
188 $alter_str_array = array(array()); //contains the criteria for each column that needs to be altered in target tables
189 $add_column_array = array(array()); //contains the name of columns that need to be added in target tables
191 * The criteria array contains all the criteria against which columns are compared for differences.
193 $criteria = array('Field', 'Type', 'Null', 'Collation', 'Key', 'Default', 'Comment');
195 for ($i = 0; $i < sizeof($matching_tables); $i++) {
197 * Finding out all the differences structure, data and index diff for all the matching tables only
199 PMA_dataDiffInTables($src_db, $trg_db, $src_link, $trg_link, $matching_tables, $matching_tables_fields, $update_array, $insert_array,
200 $delete_array, $fields_num, $i, $matching_tables_keys);
202 PMA_structureDiffInTables($src_db, $trg_db, $src_link, $trg_link, $matching_tables, $source_columns,
203 $target_columns, $alter_str_array, $add_column_array, $uncommon_columns, $criteria, $target_tables_keys, $i);
205 PMA_indexesDiffInTables($src_db, $trg_db, $src_link, $trg_link, $matching_tables, $source_indexes, $target_indexes,
206 $add_indexes_array, $alter_indexes_array, $remove_indexes_array, $i);
209 for ($j = 0; $j < sizeof($source_tables_uncommon); $j++) {
211 * Finding out the number of rows to be added in tables that need to be added in target database
213 PMA_dataDiffInUncommonTables($source_tables_uncommon, $src_db, $src_link, $j, $row_count);
217 * Storing all arrays in session for use when page is reloaded for each button press
219 $_SESSION['matching_tables'] = $matching_tables;
220 $_SESSION['update_array'] = $update_array;
221 $_SESSION['insert_array'] = $insert_array;
222 $_SESSION['src_db'] = $src_db;
223 $_SESSION['trg_db'] = $trg_db;
224 $_SESSION['matching_fields'] = $matching_tables_fields;
225 $_SESSION['src_uncommon_tables'] = $source_tables_uncommon;
226 $_SESSION['src_username'] = $src_username ;
227 $_SESSION['trg_username'] = $trg_username;
228 $_SESSION['src_password'] = $src_password;
229 $_SESSION['trg_password'] = $trg_password;
230 $_SESSION['trg_password'] = $trg_password;
231 $_SESSION['src_server'] = $src_server;
232 $_SESSION['trg_server'] = $trg_server;
233 $_SESSION['src_type'] = $src_type;
234 $_SESSION['trg_type'] = $trg_type;
235 $_SESSION['matching_tables_keys'] = $matching_tables_keys;
236 $_SESSION['uncommon_tables_fields'] = $uncommon_tables_fields;
237 $_SESSION['uncommon_tables_row_count'] = $row_count;
238 $_SESSION['target_tables_uncommon'] = $target_tables_uncommon;
239 $_SESSION['uncommon_tables'] = $source_tables_uncommon;
240 $_SESSION['delete_array'] = $delete_array;
241 $_SESSION['uncommon_columns'] = $uncommon_columns;
242 $_SESSION['source_columns'] = $source_columns;
243 $_SESSION['alter_str_array'] = $alter_str_array;
244 $_SESSION['target_tables_keys'] = $target_tables_keys;
245 $_SESSION['add_column_array'] = $add_column_array;
246 $_SESSION['criteria'] = $criteria;
247 $_SESSION['target_tables'] = $trg_tables;
248 $_SESSION['add_indexes_array'] = $add_indexes_array;
249 $_SESSION['alter_indexes_array'] = $alter_indexes_array;
250 $_SESSION['remove_indexes_array'] = $remove_indexes_array;
251 $_SESSION['source_indexes'] = $source_indexes;
252 $_SESSION['target_indexes'] = $target_indexes;
255 * Displays the sub-heading and icons showing Structure Synchronization and Data Synchronization
258 <form name="synchronize_form" id="synchronize_form" method="post" action="server_synchronize.php">
259 <?php echo PMA_generate_common_hidden_inputs('', ''); ?>
260 <table width="40%">
261 <tr>
262 <td>
263 <img class="icon" src="<?php echo $pmaThemeImage; ?>new_struct.png" width="16" height="16" alt="" />
264 <?php echo __('Structure Synchronization'); ?>
265 </td>
266 <td>
267 <img class="icon" src="<?php echo $pmaThemeImage; ?>new_data.png" width="16" height="16" alt="" />
268 <?php echo __('Data Synchronization'); ?>
269 </td>
270 </tr>
271 </table>
272 <?php
274 * Displays the tables containing the source tables names, their difference with the target tables and target tables names
276 PMA_syncDisplayHeaderCompare($src_db, $trg_db);
277 $rows = array();
280 * Display the matching tables' names and difference, first
282 for ($i = 0; $i < count($matching_tables); $i++) {
284 * Calculating the number of updates for each matching table
286 if (isset($update_array[$i]) && isset($update_array[$i][0])
287 && !empty($matching_tables_keys[$i][0])
288 && isset($update_array[$i][0][$matching_tables_keys[$i][0]])) {
289 $num_of_updates = sizeof($update_array[$i]);
290 } else {
291 $num_of_updates = 0;
294 * Calculating the number of insertions for each matching table
296 if (isset($insert_array[$i]) && isset($insert_array[$i][0])
297 && !empty($matching_tables_keys[$i])
298 && isset($insert_array[$i][0][$matching_tables_keys[$i][0]])) {
299 $num_of_insertions = sizeof($insert_array[$i]);
300 } else {
301 $num_of_insertions = 0;
305 * Calculating the number of alter columns, number of columns to be added, number of columns to be removed,
306 * number of index to be added and removed.
308 $num_alter_cols = 0;
309 $num_insert_cols = 0;
310 $num_remove_cols = 0;
311 $num_add_index = 0;
312 $num_remove_index = 0;
314 if (isset($alter_str_array[$i])) {
315 $num_alter_cols = sizeof($alter_str_array[$i]);
317 if (isset($add_column_array[$i])) {
318 $num_insert_cols = sizeof($add_column_array[$i]);
320 if (isset($uncommon_columns[$i])) {
321 $num_remove_cols = sizeof($uncommon_columns[$i]);
323 if (isset($add_indexes_array[$i])) {
324 $num_add_index = sizeof($add_indexes_array[$i]);
326 if (isset($remove_indexes_array[$i])) {
327 $num_remove_index = sizeof($remove_indexes_array[$i]);
329 if (isset($alter_indexes_array[$i])) {
330 $num_add_index += sizeof($alter_indexes_array[$i]);
331 $num_remove_index += sizeof($alter_indexes_array[$i]);
334 $btn_structure_params = null;
335 $btn_data_params = null;
338 * Display the red button of structure synchronization if there exists any structure difference or index difference.
340 if (($num_alter_cols > 0) || ($num_insert_cols > 0) || ($num_remove_cols > 0) || ($num_add_index > 0) || ($num_remove_index > 0)) {
341 $btn_structure_params = array($i, $num_alter_cols, $num_insert_cols,
342 $num_remove_cols, $num_add_index, $num_remove_index);
346 * Display the green button of data synchronization if there exists any data difference.
348 if ((isset($update_array[$i]) || isset($insert_array[$i])) && !empty($matching_tables_keys[$i])) {
349 if (isset($update_array[$i][0][$matching_tables_keys[$i][0]]) || isset($insert_array[$i][0][$matching_tables_keys[$i][0]])) {
350 $btn_data_params = array($i, $num_of_updates, $num_of_insertions, null, null, null);
354 $rows[] = array(
355 'src_table_name' => $matching_tables[$i],
356 'dst_table_name' => $matching_tables[$i],
357 'btn_type' => 'M',
358 'btn_structure' => $btn_structure_params,
359 'btn_data' => $btn_data_params
363 * Displays the tables' names present in source but missing from target
365 for ($j = 0; $j < count($source_tables_uncommon); $j++) {
366 $row = array(
367 'src_table_name' => '+ ' . $source_tables_uncommon[$j],
368 'dst_table_name' => $source_tables_uncommon[$j] . ' (' . __('not present') . ')',
369 'btn_type' => 'U',
370 'btn_structure' => array($j, null, null, null, null, null),
371 'btn_data' => null
373 if ($row_count[$j] > 0) {
374 $row['btn_data'] = array($j, null, $row_count[$j], null, null, null);
376 $rows[] = $row;
378 foreach ($target_tables_uncommon as $tbl_nc_name) {
379 $rows[] = array(
380 'src_table_name' => '',
381 'dst_table_name' => $tbl_nc_name);
384 * Displays the target tables names
386 PMA_syncDisplayDataCompare($rows);
387 echo '</table>
388 </div>
389 </fieldset>';
392 * This "list" div will contain a table and each row will depict information about structure/data diffrence in tables.
393 * Rows will be generated dynamically as soon as the colored buttons "D" or "S" are clicked.
396 echo '<fieldset style="padding:0"><div id="list" style="overflow:auto; height:140px; padding:1em">
398 <table>
399 <thead>
400 <tr style="width: 100%;">
401 <th id="table_name" style="width: 10%;" colspan="1">' . __('Table') . ' </th>
402 <th id="str_diff" style="width: 65%;" colspan="6">' . __('Structure Difference') . ' </th>
403 <th id="data_diff" style="width: 20%;" colspan="2">' . __('Data Difference') . '</th>
404 </tr>
405 <tr style="width: 100%;">
406 <th style="width: 10%;">' . __('Table name') . '</th>
407 <th style="width: 10%;">' . __('Create table'). '</th>
408 <th style="width: 11%;">' . __('Add column(s)') . '</th>
409 <th style="width: 13%;">' . __('Remove column(s)') . '</th>
410 <th style="width: 11%;">' . __('Alter column(s)') . '</th>
411 <th style="width: 12%;">' . __('Remove index(s)') . '</th>
412 <th style="width: 11%;">' . __('Apply index(s)') . '</th>
413 <th style="width: 10%;">'. __('Update row(s)') . '</th>
414 <th style="width: 10%;">' . __('Insert row(s)') . '</th>
415 </tr>
416 </thead>
417 <tbody></tbody>
418 </table>
419 </div></fieldset>';
421 * This fieldset displays the checkbox to confirm deletion of previous rows from target tables
423 echo '<fieldset>
424 <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>
425 </fieldset>
426 <fieldset class="tblFooters">';
427 echo '<input type="button" name="apply_changes" value="' . __('Apply Selected Changes')
428 . '" onclick ="ApplySelectedChanges(' . "'" . htmlspecialchars($_SESSION['token']) . "'" . ')" />';
429 echo '<input type="submit" name="synchronize_db" value="' . __('Synchronize Databases') . '" />' . '</fieldset>';
430 echo '</form>';
433 } // end if ((isset($_REQUEST['submit_connect'])))
436 * Display the page when 'Apply Selected Changes' is pressed
438 if (isset($_REQUEST['Table_ids'])) {
440 * Displays success message
442 echo '<div class="success">' . __('Selected target tables have been synchronized with source tables.') . '</div>';
444 $src_db = $_SESSION['src_db'];
445 $trg_db = $_SESSION['trg_db'];
446 $update_array = $_SESSION['update_array'];
447 $insert_array = $_SESSION['insert_array'];
448 $src_username = $_SESSION['src_username'];
449 $trg_username = $_SESSION['trg_username'];
450 $src_password = $_SESSION['src_password'];
451 $trg_password = $_SESSION['trg_password'];
452 $src_server = $_SESSION['src_server'];
453 $trg_server = $_SESSION['trg_server'];
454 $src_type = $_SESSION['src_type'];
455 $trg_type = $_SESSION['trg_type'];
456 $uncommon_tables = $_SESSION['uncommon_tables'];
457 $matching_tables = $_SESSION['matching_tables'];
458 $matching_tables_keys = $_SESSION['matching_tables_keys'];
459 $matching_tables_fields = $_SESSION['matching_fields'];
460 $source_tables_uncommon = $_SESSION['src_uncommon_tables'];
461 $uncommon_tables_fields = $_SESSION['uncommon_tables_fields'];
462 $target_tables_uncommon = $_SESSION['target_tables_uncommon'];
463 $row_count = $_SESSION['uncommon_tables_row_count'];
464 $target_tables = $_SESSION['target_tables'];
466 $delete_array = $_SESSION['delete_array'];
467 $uncommon_columns = $_SESSION['uncommon_columns'];
468 $source_columns = $_SESSION['source_columns'];
469 $alter_str_array = $_SESSION['alter_str_array'];
470 $criteria = $_SESSION['criteria'];
471 $target_tables_keys = $_SESSION['target_tables_keys'];
472 $add_column_array = $_SESSION['add_column_array'];
473 $add_indexes_array = $_SESSION['add_indexes_array'];
474 $alter_indexes_array = $_SESSION['alter_indexes_array'];
475 $remove_indexes_array = $_SESSION['remove_indexes_array'];
476 $source_indexes = $_SESSION['source_indexes'];
477 $target_indexes = $_SESSION['target_indexes'];
478 $uncommon_cols = $uncommon_columns;
481 * Creating link object for source and target databases
483 foreach ($cons as $con) {
484 if (${"{$con}_type"} != "cur") {
485 ${"{$con}_link"} = PMA_DBI_connect(${"{$con}_username"}, ${"{$con}_password"}, $is_controluser = false, ${"{$con}_server"});
486 } else {
487 ${"{$con}_link"} = null;
488 // working on current server, so initialize this for tracking
489 // (does not work if user defined current server as a remote one)
490 $GLOBALS['db'] = ${"{$con}_db"};
492 } // end foreach ($cons as $con)
495 * Initializing arrays to save the table ids whose data and structure difference is to be applied
497 $matching_table_data_diff = array(); //stores id of matching table having data difference
498 $matching_table_structure_diff = array(); //stores id of matching tables having structure difference
499 $uncommon_table_structure_diff = array(); //stores id of uncommon tables having structure difference
500 $uncommon_table_data_diff = array(); //stores id of uncommon tables having data difference
502 for ($i = 0; isset($_REQUEST[$i]); $i++ ) {
503 if (isset($_REQUEST[$i])) {
504 $table_id = explode("US", $_REQUEST[$i]);
505 if (isset($table_id[1])) {
506 $uncommon_table_structure_diff[] = $table_id[1];
508 $table_id = explode("UD", $_REQUEST[$i]);
509 if (isset($table_id[1])) {
510 $uncommon_table_data_diff[] = $table_id[1];
512 $table_id = explode("MS", $_REQUEST[$i]);
513 if (isset($table_id[1])) {
514 $matching_table_structure_diff[] = $table_id[1];
517 $table_id = explode("MD", $_REQUEST[$i]);
518 if (isset($table_id[1])) {
519 $matching_table_data_diff[] = $table_id[1];
522 } // end for
524 * Applying the structure difference on selected matching tables
526 for ($q = 0; $q < sizeof($matching_table_structure_diff); $q++)
528 if (isset($alter_str_array[$matching_table_structure_diff[$q]])) {
530 PMA_alterTargetTableStructure($trg_db, $trg_link, $matching_tables, $source_columns, $alter_str_array, $matching_tables_fields,
531 $criteria, $matching_tables_keys, $target_tables_keys, $matching_table_structure_diff[$q], false);
533 unset($alter_str_array[$matching_table_structure_diff[$q]]);
535 if (isset($add_column_array[$matching_table_structure_diff[$q]])) {
537 PMA_findDeleteRowsFromTargetTables($delete_array, $matching_tables, $matching_table_structure_diff[$q], $target_tables_keys,
538 $matching_tables_keys, $trg_db, $trg_link, $src_db, $src_link);
540 if (isset($delete_array[$matching_table_structure_diff[$q]])) {
542 PMA_deleteFromTargetTable($trg_db, $trg_link, $matching_tables, $matching_table_structure_diff[$q], $target_tables_keys, $delete_array, false);
544 unset($delete_array[$matching_table_structure_diff[$q]]);
546 PMA_addColumnsInTargetTable($src_db, $trg_db,$src_link, $trg_link, $matching_tables, $source_columns, $add_column_array, $matching_tables_fields,
547 $criteria, $matching_tables_keys, $target_tables_keys, $uncommon_tables,$uncommon_tables_fields, $matching_table_structure_diff[$q], $uncommon_cols, false);
549 unset($add_column_array[$matching_table_structure_diff[$q]]);
551 if (isset($uncommon_columns[$matching_table_structure_diff[$q]])) {
553 PMA_removeColumnsFromTargetTable($trg_db, $trg_link, $matching_tables, $uncommon_columns, $matching_table_structure_diff[$q], false);
555 unset($uncommon_columns[$matching_table_structure_diff[$q]]);
557 if (isset($add_indexes_array[$matching_table_structure_diff[$q]]) || isset($remove_indexes_array[$matching_table_structure_diff[$q]])
558 || isset($alter_indexes_array[$matching_table_structure_diff[$q]])) {
560 PMA_applyIndexesDiff ($trg_db, $trg_link, $matching_tables, $source_indexes, $target_indexes, $add_indexes_array, $alter_indexes_array,
561 $remove_indexes_array, $matching_table_structure_diff[$q], false);
563 unset($add_indexes_array[$matching_table_structure_diff[$q]]);
564 unset($alter_indexes_array[$matching_table_structure_diff[$q]]);
565 unset($remove_indexes_array[$matching_table_structure_diff[$q]]);
569 * Applying the data difference. First checks if structure diff is applied or not.
570 * If not, then apply structure difference first then apply data difference.
572 for ($p = 0; $p < sizeof($matching_table_data_diff); $p++)
574 if ($_REQUEST['checked'] == 'true') {
576 PMA_findDeleteRowsFromTargetTables($delete_array, $matching_tables, $matching_table_data_diff[$p], $target_tables_keys,
577 $matching_tables_keys, $trg_db, $trg_link, $src_db, $src_link);
579 if (isset($delete_array[$matching_table_data_diff[$p]])) {
581 PMA_deleteFromTargetTable($trg_db, $trg_link, $matching_tables, $matching_table_data_diff[$p], $target_tables_keys, $delete_array, false);
583 unset($delete_array[$matching_table_data_diff[$p]]);
586 if (isset($alter_str_array[$matching_table_data_diff[$p]])) {
588 PMA_alterTargetTableStructure($trg_db, $trg_link, $matching_tables, $source_columns, $alter_str_array, $matching_tables_fields,
589 $criteria, $matching_tables_keys, $target_tables_keys, $matching_table_data_diff[$p], false);
591 unset($alter_str_array[$matching_table_data_diff[$p]]);
593 if (isset($add_column_array[$matching_table_data_diff[$p]])) {
595 PMA_findDeleteRowsFromTargetTables($delete_array, $matching_tables, $matching_table_data_diff[$p], $target_tables_keys,
596 $matching_tables_keys, $trg_db, $trg_link, $src_db, $src_link);
598 if (isset($delete_array[$matching_table_data_diff[$p]])) {
600 PMA_deleteFromTargetTable($trg_db, $trg_link, $matching_tables, $matching_table_data_diff[$p], $target_tables_keys, $delete_array, false);
602 unset($delete_array[$matching_table_data_diff[$p]]);
604 PMA_addColumnsInTargetTable($src_db, $trg_db,$src_link, $trg_link, $matching_tables, $source_columns, $add_column_array, $matching_tables_fields,
605 $criteria, $matching_tables_keys, $target_tables_keys, $uncommon_tables, $uncommon_tables_fields, $matching_table_data_diff[$p], $uncommon_cols, false);
607 unset($add_column_array[$matching_table_data_diff[$p]]);
609 if (isset($uncommon_columns[$matching_table_data_diff[$p]])) {
611 PMA_removeColumnsFromTargetTable($trg_db, $trg_link, $matching_tables, $uncommon_columns, $matching_table_data_diff[$p], false);
613 unset($uncommon_columns[$matching_table_data_diff[$p]]);
615 if ((isset($matching_table_structure_diff[$q]) && isset($add_indexes_array[$matching_table_structure_diff[$q]]))
616 || (isset($matching_table_structure_diff[$q]) && isset($remove_indexes_array[$matching_table_structure_diff[$q]]))
617 || (isset($matching_table_structure_diff[$q]) && isset($alter_indexes_array[$matching_table_structure_diff[$q]]))) {
619 PMA_applyIndexesDiff ($trg_db, $trg_link, $matching_tables, $source_indexes, $target_indexes, $add_indexes_array, $alter_indexes_array,
620 $remove_indexes_array, $matching_table_structure_diff[$q], false);
622 unset($add_indexes_array[$matching_table_structure_diff[$q]]);
623 unset($alter_indexes_array[$matching_table_structure_diff[$q]]);
624 unset($remove_indexes_array[$matching_table_structure_diff[$q]]);
627 * Applying the data difference.
629 PMA_updateTargetTables($matching_tables, $update_array, $src_db, $trg_db, $trg_link, $matching_table_data_diff[$p], $matching_tables_keys, false);
631 PMA_insertIntoTargetTable($matching_tables, $src_db, $trg_db, $src_link, $trg_link , $matching_tables_fields, $insert_array,
632 $matching_table_data_diff[$p], $matching_tables_keys, $source_columns, $add_column_array, $criteria, $target_tables_keys,
633 $uncommon_tables, $uncommon_tables_fields, $uncommon_cols, $alter_str_array, $source_indexes, $target_indexes, $add_indexes_array,
634 $alter_indexes_array, $delete_array, $update_array, false);
637 * Updating the session variables to the latest values of the arrays.
639 $_SESSION['delete_array'] = $delete_array;
640 $_SESSION['uncommon_columns'] = $uncommon_columns;
641 $_SESSION['alter_str_array'] = $alter_str_array;
642 $_SESSION['add_column_array'] = $add_column_array;
643 $_SESSION['add_indexes_array'] = $add_indexes_array;
644 $_SESSION['remove_indexes_array'] = $remove_indexes_array;
645 $_SESSION['insert_array'] = $insert_array;
646 $_SESSION['update_array'] = $update_array;
649 * Applying structure difference to selected non-matching tables (present in Source but absent from Target).
651 for ($s = 0; $s < sizeof($uncommon_table_structure_diff); $s++)
653 PMA_createTargetTables($src_db, $trg_db, $src_link, $trg_link, $uncommon_tables, $uncommon_table_structure_diff[$s], $uncommon_tables_fields, false);
654 $_SESSION['uncommon_tables_fields'] = $uncommon_tables_fields;
656 unset($uncommon_tables[$uncommon_table_structure_diff[$s]]);
659 * Applying data difference to selected non-matching tables (present in Source but absent from Target).
660 * Before data synchronization, structure synchronization is confirmed.
662 for ($r = 0; $r < sizeof($uncommon_table_data_diff); $r++)
664 if (!(in_array($uncommon_table_data_diff[$r], $uncommon_table_structure_diff))) {
665 if (isset($uncommon_tables[$uncommon_table_data_diff[$r]])) {
667 PMA_createTargetTables($src_db, $trg_db, $src_link, $trg_link, $uncommon_tables, $uncommon_table_data_diff[$r],
668 $uncommon_tables_fields, false);
669 $_SESSION['uncommon_tables_fields'] = $uncommon_tables_fields;
671 unset($uncommon_tables[$uncommon_table_data_diff[$r]]);
674 PMA_populateTargetTables($src_db, $trg_db, $src_link, $trg_link, $source_tables_uncommon, $uncommon_table_data_diff[$r],
675 $_SESSION['uncommon_tables_fields'], false);
677 unset($row_count[$uncommon_table_data_diff[$r]]);
680 * Again all the tables from source and target database are displayed with their differences.
681 * The differences have been removed from tables that have been synchronized
683 echo '<form name="applied_difference" id="synchronize_form" method="post" action="server_synchronize.php">'
684 . PMA_generate_common_hidden_inputs('', '');
686 PMA_syncDisplayHeaderCompare($src_db, $trg_db);
687 $rows = array();
688 for ($i = 0; $i < count($matching_tables); $i++) {
689 $num_alter_cols = 0;
690 $num_insert_cols = 0;
691 $num_remove_cols = 0;
692 $num_add_index = 0;
693 $num_remove_index = 0;
695 if (isset($alter_str_array[$i])) {
696 $num_alter_cols = sizeof($alter_str_array[$i]);
698 if (isset($add_column_array[$i])) {
699 $num_insert_cols = sizeof($add_column_array[$i]);
701 if (isset($uncommon_columns[$i])) {
702 $num_remove_cols = sizeof($uncommon_columns[$i]);
704 if (isset($add_indexes_array[$i])) {
705 $num_add_index = sizeof($add_indexes_array[$i]);
707 if (isset($remove_indexes_array[$i])) {
708 $num_remove_index = sizeof($remove_indexes_array[$i]);
711 $btn_structure_params = null;
712 $btn_data_params = null;
714 if (($num_alter_cols > 0) || ($num_insert_cols > 0) || ($num_remove_cols > 0) || ($num_add_index > 0) || ($num_remove_index > 0)) {
715 $btn_structure_params = array($i, $num_alter_cols, $num_insert_cols,
716 $num_remove_cols, $num_add_index, $num_remove_index);
718 if (!(in_array($i, $matching_table_data_diff))) {
720 if (isset($matching_tables_keys[$i][0]) && isset($update_array[$i][0][$matching_tables_keys[$i][0]])) {
721 if (isset($update_array[$i])) {
722 $num_of_updates = sizeof($update_array[$i]);
723 } else {
724 $num_of_updates = 0;
726 } else {
727 $num_of_updates = 0;
729 if (isset($matching_tables_keys[$i][0]) && isset($insert_array[$i][0][$matching_tables_keys[$i][0]])) {
730 if (isset($insert_array[$i])) {
731 $num_of_insertions = sizeof($insert_array[$i]);
732 } else {
733 $num_of_insertions = 0;
735 } else {
736 $num_of_insertions = 0;
739 if ((isset($matching_tables_keys[$i][0]) && isset($update_array[$i][0][$matching_tables_keys[$i][0]]))
740 || (isset($matching_tables_keys[$i][0]) && isset($insert_array[$i][0][$matching_tables_keys[$i][0]]))) {
741 $btn_data_params = array($i, $num_of_updates, $num_of_insertions,
742 null, null, null);
744 } else {
745 unset($update_array[$i]);
746 unset($insert_array[$i]);
748 $rows[] = array(
749 'src_table_name' => $matching_tables[$i],
750 'dst_table_name' => $matching_tables[$i],
751 'btn_type' => 'M',
752 'btn_structure' => $btn_structure_params,
753 'btn_data' => $btn_data_params
757 * placing updated value of arrays in session
760 $_SESSION['update_array'] = $update_array;
761 $_SESSION['insert_array'] = $insert_array;
763 for ($j = 0; $j < count($source_tables_uncommon); $j++) {
764 $btn_structure_params = null;
765 $btn_data_params = null;
768 * Display the difference only when it has not been applied
770 if (!(in_array($j, $uncommon_table_structure_diff))) {
771 if (isset($uncommon_tables[$j])) {
772 $btn_structure_params = array($j, null, null, null, null, null);
774 $dst_table_name = $source_tables_uncommon[$j] . ' (' . __('not present') . ')';
775 } else {
776 unset($uncommon_tables[$j]);
777 $dst_table_name = $source_tables_uncommon[$j];
780 * Display the difference only when it has not been applied
782 if (!(in_array($j, $uncommon_table_data_diff))) {
783 if (isset($row_count[$j]) && ($row_count[$j] > 0)) {
784 $btn_data_params = array($j, null, $row_count[$j], null, null, null);
786 } else {
787 unset($row_count[$j]);
790 $rows[] = array(
791 'src_table_name' => $source_tables_uncommon[$j],
792 'dst_table_name' => $dst_table_name,
793 'btn_type' => 'U',
794 'btn_structure' => $btn_structure_params,
795 'btn_data' => $btn_data_params
799 * placing the latest values of arrays in session
802 $_SESSION['uncommon_tables'] = $uncommon_tables;
803 $_SESSION['uncommon_tables_row_count'] = $row_count;
807 * Displaying the target database tables
809 foreach ($target_tables_uncommon as $tbl_nc_name) {
810 $rows[] = array(
811 'src_table_name' => '',
812 'dst_table_name' => $tbl_nc_name);
814 PMA_syncDisplayDataCompare($rows);
815 echo '</table>
816 </div>
817 </fieldset>';
820 * This "list" div will contain a table and each row will depict information about structure/data diffrence in tables.
821 * Rows will be generated dynamically as soon as the colored buttons "D" or "S" are clicked.
824 echo '<fieldset style="padding:0"><div id="list" style = "overflow:auto; height:140px; padding:1em">';
825 echo '<table>
826 <thead>
827 <tr style="width: 100%;">
828 <th id="table_name" style="width: 10%;" colspan="1">' . __('Table') . ' </th>
829 <th id="str_diff" style="width: 65%;" colspan="6">' . __('Structure Difference') . ' </th>
830 <th id="data_diff" style="width: 20%;" colspan="2">' . __('Data Difference') . '</th>
831 </tr>
832 <tr style="width: 100%;">
833 <th style="width: 10%;">' . __('Table name') . '</th>
834 <th style="width: 10%;">' . __('Create table'). '</th>
835 <th style="width: 11%;">' . __('Add column(s)') . '</th>
836 <th style="width: 13%;">' . __('Remove column(s)') . '</th>
837 <th style="width: 11%;">' . __('Alter column(s)') . '</th>
838 <th style="width: 12%;">' . __('Remove index(s)') . '</th>
839 <th style="width: 11%;">' . __('Apply index(s)') . '</th>
840 <th style="width: 10%;">' . __('Update row(s)') . '</th>
841 <th style="width: 10%;">' . __('Insert row(s)') . '</th>
842 </tr>
843 </thead>
844 <tbody></tbody>
845 </table>
846 </div></fieldset>';
849 * This fieldset displays the checkbox to confirm deletion of previous rows from target tables
851 echo '<fieldset>
852 <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>
853 </fieldset>';
855 echo '<fieldset class="tblFooters">';
856 echo '<input type="button" name="apply_changes" value="' . __('Apply Selected Changes') . '"
857 onclick ="ApplySelectedChanges(' . "'" . htmlspecialchars($_SESSION['token']) . "'" .')" />';
858 echo '<input type="submit" name="synchronize_db" value="' . __('Synchronize Databases') . '" />'
859 . '</fieldset>';
860 echo '</form>';
864 * Displays the page when 'Synchronize Databases' is pressed.
867 if (isset($_REQUEST['synchronize_db'])) {
869 $src_db = $_SESSION['src_db'];
870 $trg_db = $_SESSION['trg_db'];
871 $update_array = $_SESSION['update_array'];
872 $insert_array = $_SESSION['insert_array'];
873 $src_username = $_SESSION['src_username'];
874 $trg_username = $_SESSION['trg_username'];
875 $src_password = $_SESSION['src_password'];
876 $trg_password = $_SESSION['trg_password'];
877 $matching_tables = $_SESSION['matching_tables'];
878 $matching_tables_keys = $_SESSION['matching_tables_keys'];
879 $matching_tables_fields = $_SESSION['matching_fields'];
880 $source_tables_uncommon = $_SESSION['src_uncommon_tables'];
881 $uncommon_tables_fields = $_SESSION['uncommon_tables_fields'];
882 $target_tables_uncommon = $_SESSION['target_tables_uncommon'];
883 $row_count = $_SESSION['uncommon_tables_row_count'];
884 $uncommon_tables = $_SESSION['uncommon_tables'];
885 $target_tables = $_SESSION['target_tables'];
887 $delete_array = $_SESSION['delete_array'];
888 $uncommon_columns = $_SESSION['uncommon_columns'];
889 $source_columns = $_SESSION['source_columns'];
890 $alter_str_array = $_SESSION['alter_str_array'];
891 $criteria = $_SESSION['criteria'];
892 $target_tables_keys = $_SESSION['target_tables_keys'];
893 $add_column_array = $_SESSION['add_column_array'];
894 $add_indexes_array = $_SESSION['add_indexes_array'];
895 $alter_indexes_array = $_SESSION['alter_indexes_array'];
896 $remove_indexes_array = $_SESSION['remove_indexes_array'];
897 $source_indexes = $_SESSION['source_indexes'];
898 $target_indexes = $_SESSION['target_indexes'];
899 $uncommon_cols = $uncommon_columns;
902 * Display success message.
904 echo '<div class="success">' . __('Target database has been synchronized with source database') . '</div>';
906 * Displaying all the tables of source and target database and now no difference is there.
908 PMA_syncDisplayHeaderCompare($src_db, $trg_db);
909 $rows = array();
910 for ($i = 0; $i < count($matching_tables); $i++)
912 $rows[] = array(
913 'src_table_name' => $matching_tables[$i],
914 'dst_table_name' => $matching_tables[$i]);
916 foreach ($source_tables_uncommon as $tbl_nc_name) {
917 $rows[] = array(
918 'src_table_name' => '+ ' . $tbl_nc_name,
919 'dst_table_name' => $tbl_nc_name);
921 foreach ($target_tables_uncommon as $tbl_nc_name) {
922 $rows[] = array(
923 'src_table_name' => '',
924 'dst_table_name' => $tbl_nc_name);
926 PMA_syncDisplayDataCompare($rows);
927 echo '</table>
928 </div>
929 </fieldset>';
932 * connecting the source and target servers
934 if ('cur' != $_SESSION['src_type']) {
935 $src_link = PMA_DBI_connect($src_username, $src_password, $is_controluser = false, $_SESSION['src_server']);
936 $src_version = PMA_DBI_fetch_value('SELECT VERSION()', 0, 0, $src_link);
937 $src_is_drizzle = (bool)preg_match('/\d{4}\./', $src_version);
938 } else {
939 $src_link = $GLOBALS['userlink'];
940 $src_version = PMA_MYSQL_STR_VERSION;
941 $src_is_drizzle = PMA_DRIZZLE;
942 // working on current server, so initialize this for tracking
943 // (does not work if user defined current server as a remote one)
944 $GLOBALS['db'] = $_SESSION['src_db'];
946 if ('cur' != $_SESSION['trg_type']) {
947 $trg_link = PMA_DBI_connect($trg_username, $trg_password, $is_controluser = false, $_SESSION['trg_server']);
948 $trg_version = PMA_DBI_fetch_value('SELECT VERSION()', 0, 0, $trg_link);
949 $trg_is_drizzle = (bool)preg_match('/\d{4}\./', $trg_version);
950 } else {
951 $trg_link = $GLOBALS['userlink'];
952 $trg_version = PMA_MYSQL_STR_VERSION;
953 $trg_is_drizzle = PMA_DRIZZLE;
954 // working on current server, so initialize this for tracking
955 $GLOBALS['db'] = $_SESSION['trg_db'];
959 * Displaying the queries.
961 echo '<fieldset><legend>' . __('Executed queries') . '</legend>';
963 * Applying all sorts of differences for each matching table
965 for ($p = 0; $p < sizeof($matching_tables); $p++) {
967 * If the check box is checked for deleting previous rows from the target database tables then
968 * first find out rows to be deleted and then delete the rows.
970 if (isset($_REQUEST['delete_rows'])) {
971 PMA_findDeleteRowsFromTargetTables($delete_array, $matching_tables, $p, $target_tables_keys, $matching_tables_keys,
972 $trg_db, $trg_link, $src_db, $src_link);
974 if (isset($delete_array[$p])) {
975 PMA_deleteFromTargetTable($trg_db, $trg_link, $matching_tables, $p, $target_tables_keys, $delete_array, true);
976 unset($delete_array[$p]);
979 if (isset($alter_str_array[$p])) {
980 PMA_alterTargetTableStructure($trg_db, $trg_link, $matching_tables, $source_columns, $alter_str_array, $matching_tables_fields,
981 $criteria, $matching_tables_keys, $target_tables_keys, $p, true);
982 unset($alter_str_array[$p]);
984 if (! empty($add_column_array[$p])) {
985 PMA_findDeleteRowsFromTargetTables($delete_array, $matching_tables, $p, $target_tables_keys, $matching_tables_keys,
986 $trg_db, $trg_link, $src_db, $src_link);
988 if (isset($delete_array[$p])) {
989 PMA_deleteFromTargetTable($trg_db, $trg_link, $matching_tables, $p, $target_tables_keys, $delete_array, true);
990 unset($delete_array[$p]);
992 PMA_addColumnsInTargetTable($src_db, $trg_db, $src_link, $trg_link, $matching_tables, $source_columns, $add_column_array,
993 $matching_tables_fields, $criteria, $matching_tables_keys, $target_tables_keys, $uncommon_tables, $uncommon_tables_fields,
994 $p, $uncommon_cols, true);
995 unset($add_column_array[$p]);
997 if (isset($uncommon_columns[$p])) {
998 PMA_removeColumnsFromTargetTable($trg_db, $trg_link, $matching_tables, $uncommon_columns, $p, true);
999 unset($uncommon_columns[$p]);
1001 if (isset($matching_table_structure_diff) &&
1002 (isset($add_indexes_array[$matching_table_structure_diff[$p]])
1003 || isset($remove_indexes_array[$matching_table_structure_diff[$p]])
1004 || isset($alter_indexes_array[$matching_table_structure_diff[$p]]))) {
1005 PMA_applyIndexesDiff ($trg_db, $trg_link, $matching_tables, $source_indexes, $target_indexes, $add_indexes_array, $alter_indexes_array,
1006 $remove_indexes_array, $matching_table_structure_diff[$p], true);
1008 unset($add_indexes_array[$matching_table_structure_diff[$p]]);
1009 unset($alter_indexes_array[$matching_table_structure_diff[$p]]);
1010 unset($remove_indexes_array[$matching_table_structure_diff[$p]]);
1013 PMA_updateTargetTables($matching_tables, $update_array, $src_db, $trg_db, $trg_link, $p, $matching_tables_keys, true);
1015 PMA_insertIntoTargetTable($matching_tables, $src_db, $trg_db, $src_link, $trg_link , $matching_tables_fields, $insert_array, $p,
1016 $matching_tables_keys, $matching_tables_keys, $source_columns, $add_column_array, $criteria, $target_tables_keys, $uncommon_tables,
1017 $uncommon_tables_fields,$uncommon_cols, $alter_str_array,$source_indexes, $target_indexes, $add_indexes_array,
1018 $alter_indexes_array, $delete_array, $update_array, true);
1022 * Creating and populating tables present in source but absent from target database.
1024 for ($q = 0; $q < sizeof($source_tables_uncommon); $q++) {
1025 if (isset($uncommon_tables[$q])) {
1026 PMA_createTargetTables($src_db, $trg_db, $src_link, $trg_link, $source_tables_uncommon, $q, $uncommon_tables_fields, true);
1028 if (isset($row_count[$q])) {
1029 PMA_populateTargetTables($src_db, $trg_db, $src_link, $trg_link, $source_tables_uncommon, $q, $uncommon_tables_fields, true);
1032 echo "</fieldset>";
1036 * Displays the main page when none of the following buttons is pressed
1039 if (! isset($_REQUEST['submit_connect']) && ! isset($_REQUEST['synchronize_db']) && ! isset($_REQUEST['Table_ids']) )
1042 * Displays the sub-page heading
1044 echo '<h2>' . ($GLOBALS['cfg']['MainPageIconic']
1045 ? '<img class="icon ic_s_sync" src="themes/dot.gif" alt="" />'
1046 : '')
1047 . __('Synchronize')
1048 .'</h2>';
1050 echo '<div id="serverstatus">
1051 <form name="connection_form" id="connection_form" method="post" action="server_synchronize.php"
1052 >' // TODO: add check if all var. are filled in
1053 . PMA_generate_common_hidden_inputs('', '');
1054 echo '<fieldset>';
1055 echo '<legend>' . __('Synchronize') . '</legend>';
1057 * Displays the forms
1060 $databases = PMA_DBI_get_databases_full(null, false, null, 'SCHEMA_NAME',
1061 'ASC', 0, true);
1063 if ($GLOBALS['cfg']['AllowArbitraryServer'] === false) {
1064 $possibly_readonly = ' readonly="readonly"';
1065 } else {
1066 $possibly_readonly = '';
1069 foreach ($cons as $type) {
1070 if ('src' == $type) {
1071 $database_header = __('Source database');
1072 } else {
1073 $database_header = __('Target database');
1076 $database_header .= PMA_showHint(PMA_sanitize(sprintf('%sAllowArbitraryServer%s', '[a@./Documentation.html#AllowArbitraryServer@_blank]', '[/a]')));
1078 <table id="serverconnection_<?php echo $type; ?>_remote" class="data noclick">
1079 <caption class="tblHeaders"><?php echo $database_header; ?></caption>
1080 <tr class="odd">
1081 <td colspan="2" style="text-align: center">
1082 <select name="<?php echo $type; ?>_type" id="<?php echo $type; ?>_type" class="server_selector">
1083 <?php
1084 if ($GLOBALS['cfg']['AllowArbitraryServer']) {
1085 $preselected_option = 'rmt';
1086 echo '<option value="rmt" selected="selected">' . __('Enter manually') . '</option>';
1087 } else {
1088 $preselected_option = 'cur';
1090 echo '<option value="cur"';
1091 if ('cur' == $preselected_option) {
1092 echo ' selected="selected"';
1094 echo '>' . __('Current connection') . '</option>';
1096 $loaded_dbi = $GLOBALS['cfg']['Server']['extension'];
1097 foreach ($GLOBALS['cfg']['Servers'] as $key => $tmp_server) {
1098 if (empty($tmp_server['host']) && empty($tmp_server['socket'])) {
1099 continue;
1102 if (!empty($tmp_server['verbose'])) {
1103 $label = $tmp_server['verbose'];
1104 } else {
1105 $label = $tmp_server['host'];
1106 if (!empty($tmp_server['port'])) {
1107 $label .= ':' . $tmp_server['port'];
1111 if ($loaded_dbi == 'drizzle' && $tmp_server['extension'] != 'drizzle'
1112 || $loaded_dbi != 'drizzle' && $tmp_server['extension'] == 'drizzle') {
1113 // incompatible connection protocols
1114 $disabled = ' disabled="disabled"';
1115 $value = '';
1116 } else {
1117 $disabled = '';
1118 $value = $tmp_server['host'];
1119 $value .= '||||';
1120 if (empty($tmp_server['port']) && empty($tmp_server['socket'])) {
1121 $value .= '3306';
1122 } else {
1123 $value .= $tmp_server['port'];
1125 $value .= '||||';
1126 $value .= $tmp_server['socket'];
1127 $value .= '||||';
1128 $value .= $tmp_server['user'];
1129 $value .= '||||';
1130 $value .= $tmp_server['only_db'];
1133 echo '<option value="' . $value . '"' . $disabled . '>'
1134 . sprintf(__('Configuration: %s'), htmlspecialchars($label)) . '</option>';
1135 } // end foreach
1137 </select>
1138 </td>
1139 </tr>
1140 <tr class="even toggler remote-server">
1141 <td><?php echo __('Server'); ?></td>
1142 <td><input type="text" name="<?php echo $type; ?>_host" class="server-host" <?php echo $possibly_readonly; ?>/></td>
1143 </tr>
1144 <tr class="odd toggler remote-server">
1145 <td><?php echo __('Port'); ?></td>
1146 <td><input type="text" name="<?php echo $type; ?>_port" class="server-port" <?php echo $possibly_readonly; ?> value="3306" maxlength="5" size="5" /></td>
1147 </tr>
1148 <tr class="even toggler remote-server">
1149 <td><?php echo __('Socket'); ?></td>
1150 <td><input type="text" name="<?php echo $type; ?>_socket" class="server-socket" <?php echo $possibly_readonly; ?>/></td>
1151 </tr>
1152 <tr class="odd toggler remote-server">
1153 <td><?php echo __('User name'); ?></td>
1154 <td><input type="text" name="<?php echo $type; ?>_username" class="server-user" /></td>
1155 </tr>
1156 <tr class="even toggler remote-server">
1157 <td><?php echo __('Password'); ?></td>
1158 <td><input type="password" name="<?php echo $type; ?>_pass" class="server-pass" /> </td>
1159 </tr>
1160 <tr class="odd toggler remote-server">
1161 <td><?php echo __('Database'); ?></td>
1162 <td><input type="text" name="<?php echo $type; ?>_db" class="server-db" /></td>
1163 </tr>
1164 <tr class="even toggler current-server" style="display: none;">
1165 <td><?php echo __('Database'); ?></td>
1166 <td>
1167 <?php
1168 // these unset() do not complain if the elements do not exist
1169 unset($databases['mysql']);
1170 unset($databases['information_schema']);
1172 if (count($databases) == 0) {
1173 echo __('No databases');
1174 } else {
1175 echo '
1176 <select name="' . $type . '_db_sel">
1178 foreach ($databases as $db) {
1179 echo ' <option>' . htmlspecialchars($db['SCHEMA_NAME']) . '</option>';
1181 echo '</select>';
1183 echo '</td> </tr>
1184 </table>';
1186 unset ($types, $type);
1188 echo '
1189 </fieldset>
1190 <fieldset class="tblFooters">
1191 <input type="submit" name="submit_connect" value="' . __('Go') .'" id="buttonGo" />
1192 </fieldset>
1193 </form>
1194 </div>
1195 <div class="notice">' . __('Target database will be completely synchronized with source database. Source database will remain unchanged.') . '</div>';
1199 * Displays the footer
1201 require './libraries/footer.inc.php';