} } elseif ($fieldinfo == "email") { if ($type == "csv") { $firstline .= "\"" . $elang->gT("Email Address") . "\"{$separator}"; } else { $firstline .= $elang->gT("Email Address") . "{$separator}"; } } elseif ($fieldinfo == "token") { if ($type == "csv") { $firstline .= "\"" . $elang->gT("Token") . "\"{$separator}"; } else { $firstline .= $elang->gT("Token") . "{$separator}"; } } elseif (substr($fieldinfo, 0, 10) == "attribute_") { if ($type == "csv") { $firstline .= CSVEscape($fieldinfo) . "{$separator}"; } else { $firstline .= $attributeFieldAndNames[$fieldinfo] . "{$separator}"; } } elseif ($fieldinfo == "id") { if ($type == "csv") { $firstline .= "\"id\"{$separator}"; } else { $firstline .= "id{$separator}"; } } elseif ($fieldinfo == "datestamp") { if ($type == "csv") { $firstline .= "\"" . $elang->gT("Date Last Action") . "\"{$separator}"; } else { $firstline .= $elang->gT("Date Last Action") . "{$separator}"; }
/** * Returns the value with all necessary escaping needed to place it into a CSV string. * * @param string $value * @return string */ protected function csvEscape($value) { return CSVEscape($value); }
function BuildCSVFromQuery($Query) { global $dbprefix, $connect; $QueryResult = db_execute_assoc($Query) or safe_die("ERROR: {$QueryResult}<br />" . $connect->ErrorMsg()); //safe preg_match('/FROM (\\w+)( |,)/i', $Query, $MatchResults); $TableName = $MatchResults[1]; if ($dbprefix) { $TableName = substr($TableName, strlen($dbprefix), strlen($TableName)); } $Output = "\n#\n# " . strtoupper($TableName) . " TABLE\n#\n"; $HeaderDone = false; $ColumnNames = ""; while ($Row = $QueryResult->FetchRow()) { if (!$HeaderDone) { foreach ($Row as $Key => $Value) { $ColumnNames .= CSVEscape($Key) . ","; //Add all the column names together } $ColumnNames = substr($ColumnNames, 0, -1); //strip off last comma space $Output .= "{$ColumnNames}\n"; $HeaderDone = true; } $ColumnValues = ""; foreach ($Row as $Key => $Value) { $Value = str_replace("\r\n", "\n", $Value); $Value = str_replace("\r", "\n", $Value); $ColumnValues .= CSVEscape($Value) . ","; } $ColumnValues = substr($ColumnValues, 0, -1); //strip off last comma space $Output .= str_replace("\n", "\\n", "{$ColumnValues}") . "\n"; } return $Output; }