$query
".$connect->ErrorMsg());
$optionElements = '';
while ($row = $result->FetchRow())
{
$optionElements .= "\t\t\t\n";
}
$importoldresponsesoutput = "";
$importoldresponsesoutput .= "
\n";
$importoldresponsesoutput .= "
| ".$clang->gT("Import responses from an old (deactivated) survey table into an active survey")." |
";
}
elseif (isset($surveyid) && $surveyid && isset($oldtable))
{
// options (UI not implemented)
$dontimportfields = array(
'id' //,'otherfield'
);
$presetfields = array( // quote all strings so we can allow NULL
//'4X13X951'=>"'Y'"
//'id' => "NULL"
);
$importidrange = false; //array('first'=>3,'last'=>10);
$activetable = "{$dbprefix}survey_$surveyid";
// fields we can import
$importablefields = array();
$query = "SHOW COLUMNS FROM {$activetable}";
$result = db_execute_assoc($query) or safe_die("Error:
$query
".$connect->ErrorMsg());
while ($row = $result->FetchRow())
{
if (!in_array($row['Field'],$dontimportfields))
{
$importablefields[] = $row['Field'];
}
}
// fields we can supply
$availablefields = array();
$query = "SHOW COLUMNS FROM {$oldtable}";
$result = db_execute_assoc($query) or safe_die("Error:
$query
".$connect->ErrorMsg());
while ($row = $result->FetchRow())
{
$availablefields[] = $row['Field'];
}
foreach ($presetfields as $field => $value)
{
if (!in_array($field,$availablefields))
{
$availablefields[] = $field;
}
}
$fieldstoimport = array_intersect($importablefields,$availablefields);
// data sources for each field (field of oldtable or preset value)
$sourcefields = array();
foreach ($fieldstoimport as $field)
{
$sourcefields[] = array_key_exists($field,$presetfields)?
$presetfields[$field]
: ($oldtable.'.'.$field);
}
$query = "INSERT INTO {$activetable} (\n\t".join("\t, ",$fieldstoimport)."\n) "
."SELECT\n\t".join("\t,",$sourcefields)."\n"
."FROM {$oldtable}";
if (is_array($importidrange))
{
$query .= " WHERE {$oldtable}.id >= {$importidrange['first']} "
." AND {$oldtable}.id <= {$importidrange['last']}";
}
$result = $connect->Execute($query) or safe_die("Error:
$query
".$connect->ErrorMsg());
header("Location: $scriptname?action=browse&sid=$surveyid");
}
?>