public static function duplicateInfo($work, $pma_table, $get_fields, $where_fields, $new_fields)
{
$last_id = -1;
if (!isset($GLOBALS['cfgRelation']) || !$GLOBALS['cfgRelation'][$work]) {
return true;
}
$select_parts = array();
$row_fields = array();
foreach ($get_fields as $get_field) {
$select_parts[] = Util::backquote($get_field);
$row_fields[$get_field] = 'cc';
}
$where_parts = array();
foreach ($where_fields as $_where => $_value) {
$where_parts[] = Util::backquote($_where) . ' = \'' . $GLOBALS['dbi']->escapeString($_value) . '\'';
}
$new_parts = array();
$new_value_parts = array();
foreach ($new_fields as $_where => $_value) {
$new_parts[] = Util::backquote($_where);
$new_value_parts[] = $GLOBALS['dbi']->escapeString($_value);
}
$table_copy_query = '
SELECT ' . implode(', ', $select_parts) . '
FROM ' . Util::backquote($GLOBALS['cfgRelation']['db']) . '.' . Util::backquote($GLOBALS['cfgRelation'][$pma_table]) . '
WHERE ' . implode(' AND ', $where_parts);
// must use DatabaseInterface::QUERY_STORE here, since we execute
// another query inside the loop
$table_copy_rs = PMA_queryAsControlUser($table_copy_query, true, DatabaseInterface::QUERY_STORE);
while ($table_copy_row = @$GLOBALS['dbi']->fetchAssoc($table_copy_rs)) {
$value_parts = array();
foreach ($table_copy_row as $_key => $_val) {
if (isset($row_fields[$_key]) && $row_fields[$_key] == 'cc') {
$value_parts[] = $GLOBALS['dbi']->escapeString($_val);
}
}
$new_table_query = 'INSERT IGNORE INTO ' . Util::backquote($GLOBALS['cfgRelation']['db']) . '.' . Util::backquote($GLOBALS['cfgRelation'][$pma_table]) . ' (' . implode(', ', $select_parts) . ', ' . implode(', ', $new_parts) . ') VALUES (\'' . implode('\', \'', $value_parts) . '\', \'' . implode('\', \'', $new_value_parts) . '\')';
PMA_queryAsControlUser($new_table_query);
$last_id = $GLOBALS['dbi']->insertId();
}
// end while
$GLOBALS['dbi']->freeResult($table_copy_rs);
return $last_id;
}