';
// Don't auto-assign two times the same column
$alreadyFound = [];
foreach ($columnNames as $key => $oneColumn) {
$columnNames[$key] = strtolower(trim($columnNames[$key], '\'" '));
$customValue = '';
// If we assigned the column then changed the charset option (reloading the page), keep the assigned value
$selectedField = acym_getVar('cmd', 'fieldAssignment'.$key, '');
// Auto-detect the column assignment
if (empty($selectedField) && $selectedField !== 0) {
// If the column name matches one of the AcyMailing fields, take this field
if (isset($cleanFields[$columnNames[$key]])) {
$selectedField = $columnNames[$key];
} elseif (in_array($columnNames[$key], $cleanFields)) {
$selectedField = array_search(strtolower($columnNames[$key]), $cleanFields);
} else {
$selectedField = '0';
}
// Detect if it's the mail field, if there are only two columns and it isn't the email one, it is the name column
if (!$selectedField && !empty($firstValueLine)) {
if (isset($firstValueLine[$key]) && strpos($firstValueLine[$key], '@')) {
$selectedField = 'email';
} elseif ($nbColumns === 2) {
$selectedField = 'name';
}
}
if (in_array($selectedField, $alreadyFound)) {
$selectedField = '0';
}
} elseif ($selectedField == 2) {
// If custom field, fill in the input with the right value
$customValue = acym_getVar('cmd', 'newcustom'.$key);
}
$alreadyFound[] = $selectedField;
echo '';
acym_select(
$fieldAssignment,
'fieldAssignment'.$key,
$selectedField,
['class' => 'fieldAssignment'],
'value',
'text',
null,
false,
true
);
echo ' ';
}
echo ' |
';
// If the first imported line is the header, display a line to show it...
if (!$noHeader) {
echo '