if ($sSynchronize == '1') { $bSynchronize = true; } else { $bSynchronize = false; } ////////////////////////////////////////////////// // // Parse first line, check attributes, analyse the request // if ($sCharSet == 'UTF-8') { $sUTF8Data = $sCSVData; } else { $sUTF8Data = iconv($sCharSet, 'UTF-8//IGNORE//TRANSLIT', $sCSVData); } $oCSVParser = new CSVParser($sUTF8Data, $sSep, $sQualifier); $aInputColumns = $oCSVParser->ListFields(); $iColCount = count($aInputColumns); // Check columns $aColumns = $oDataSource->GetSQLColumns(); $aDateColumns = $oDataSource->GetDateSQLColumns(); $aIsDateToTransform = array(); $aDateToTransformReport = array(); foreach ($aInputColumns as $iFieldId => $sInputColumn) { if (strlen($sDateFormat) > 0 && array_key_exists($sInputColumn, $aDateColumns)) { $aIsDateToTransform[$iFieldId] = true; $aDateToTransformReport[] = $sInputColumn; } else { $aIsDateToTransform[$iFieldId] = false; } if ($sInputColumn == 'primary_key') { $iPrimaryKeyCol = $iFieldId;
// Parse first line, check attributes, analyse the request // if ($sCharSet == 'UTF-8') { // Remove the BOM if any if (substr($sCSVData, 0, 3) == UTF8_BOM) { $sCSVData = substr($sCSVData, 3); } // Clean the input // Todo: warn the user if some characters are lost/substituted $sUTF8Data = iconv('UTF-8', 'UTF-8//IGNORE//TRANSLIT', $sCSVData); } else { $sUTF8Data = iconv($sCharSet, 'UTF-8//IGNORE//TRANSLIT', $sCSVData); } $oCSVParser = new CSVParser($sUTF8Data, $sSep, $sQualifier); // Limitation: as the attribute list is in the first line, we can not match external key by a third-party attribute $aRawFieldList = $oCSVParser->ListFields(); $iColCount = count($aRawFieldList); // Translate into internal names $aFieldList = array(); foreach ($aRawFieldList as $iFieldId => $sFieldName) { $sFieldName = trim($sFieldName); $aMatches = array(); if (preg_match('/^(.+)\\*$/', $sFieldName, $aMatches)) { // Ignore any trailing "star" (*) that simply indicates a mandatory field $sFieldName = $aMatches[1]; } else { if (preg_match('/^(.+)\\*->(.+)$/', $sFieldName, $aMatches)) { // Remove any trailing "star" character before the arrow (->) // A star character at the end can be used to indicate a mandatory field $sFieldName = $aMatches[1] . '->' . $aMatches[2]; }