Necesitas un array separado para las etiquetas de las columnas así:
Code: Select all@@csvFilename = '';
@@csvLink = '';
if (isset(@=productsList) and is_array(@=productsList) and count(@=productsList)) {
$aCsv = array();
//set the first row in the CSV file to the IDs of the grid fields
$aColumnHeaders = array_keys(@=productsList[1]);
$aHeaderLabels = array("Field 1", "Field 1 Label", "Field 2", "Field 2 Label", "Field 3", "Field 3 Label");
$line = '';
foreach ($aHeaderLabels as $fieldId) {
$line .= (empty($line) ? '' : ';') . $fieldId;
}
$aCsv[] = $line;
//set each data row in CSV file:
foreach (@=productsList as $aRow) {
$line = '';
foreach ($aColumnHeaders as $fieldId) {
$val = $aRow[$fieldId];
if (is_array($val) or is_object($val)) {
$val = json_encode($val);
}
//sanitize CSV data to handle double quotation marks, commas, semicolons,
//spaces and new lines
$val = str_replace('"', '""', $val);
if (preg_match('/[,;"\n\r]/', $val) or trim($val) != $val) {
$val = '"' . $val . '"';
}
$line .= (empty($line) ? '' : ';') . $val;
}
$aCsv[] = $line;
}
//create a temporary output file:
$path = tempnam(sys_get_temp_dir(), "products_") . ".csv";
file_put_contents($path, implode("\n", $aCsv));
$inpDocId = '91773886359113840b60ec5038468317'; //set to ID of the Input Document
//upload temp CSV file to PM:
@@fileId = PMFAddInputDocument($inpDocId, null, 1, 'INPUT', 'CSV file of products',
'add', @@APPLICATION, @%INDEX, @@TASK, @@USER_LOGGED, 'file', $path);
unlink($filename); //delete temporary CSV file
if (empty(@@fileId)) {
$g = new G();
$g->SendMessageText("Unable to upload CSV file to current case.", "ERROR");
}
else {
@@csvLink = (G::is_https() ? 'https://' : 'http://') .
$_SERVER['SERVER_NAME'].':'.$_SERVER['SERVER_PORT'].'/sys' .
@@SYS_SYS.'/en/neoclassic/cases/cases_ShowDocument?a='.@@fileId;
@@csvFilename = pathinfo($path, PATHINFO_BASENAME);
}
}