'text/plain',
'txt' => 'text/plain',
'xls' => 'application/vnd.ms-excel',
'xml' => 'application/xml'
);
if (isset($_POST['format']) && isset($exportFormatAR[$_POST['format']])) {
$format = $_POST['format'];
} else {
$format = 'csv';
}
// set filename
$fileName = 'openconf';
if (preg_match("/^\w+$/", $GLOBALS['OC_configAR']['OC_confName'])) {
$fileName .= '-' . $GLOBALS['OC_configAR']['OC_confName'];
}
$fileName .= '-' . oc_strtolower($scope) . '-' . date('YmdHi') . '.' . $format;
// send out headers
oc_sendNoCacheHeaders();
header('Content-Type: ' . $exportFormatAR[$format]);
header('Content-Disposition: attachment; filename="' . $fileName . '"');
// export file
switch ($format) {
case 'xls': // *****************************************************************
print '
';
// Title Row
print '';
foreach ($exportFieldsAR as $f) {
print '' . (isset($fieldNameAR[$f]) ? $fieldNameAR[$f] : ucwords(preg_replace("/_/", " ", trim($f, "_")))) . ' | ';
}
print '
';
// Iterate through records
while ($l = ocsql_fetch_array($dbR)) {
print '';
foreach ($exportFieldsAR as $f) {
if (preg_match("/^_/", $f)) {
if (isset($extraAR[$l['id']][$f])) {
$val = $extraAR[$l['id']][$f];
} else {
$val ='';
}
} else {
$val = oc_getFieldValue($fieldAR, $l, $f);
}
print '' . htmlspecialchars($val) . ' | ';
}
print '
';
}
print '
';
break;
case 'xml': // *****************************************************************
print '
';
// Iterate through records
while ($l = ocsql_fetch_array($dbR)) {
print " \n";
foreach ($exportFieldsAR as $f) {
$tag = (isset($fieldNameAR[$f]) ? $fieldNameAR[$f] : ucwords(preg_replace("/_/", " ", trim($f, "_"))));
$tag = preg_replace("/[^\w]/", "", $tag);
if (preg_match("/^_/", $f)) {
if (isset($extraAR[$l['id']][$f])) {
$val = $extraAR[$l['id']][$f];
} else {
$val ='';
}
} else {
$val = oc_getFieldValue($fieldAR, $l, $f);
}
if ($val == '') {
print " <$tag />\n";
} else {
print " <$tag>" . htmlspecialchars($val) . "$tag>\n";
}
}
print " \n";
}
print '';
break;
default: // *****************************************************************
if ($format == 'txt') {
$delim = "\t";
} else {
$delim = ',';
}
// Title Row
$titlerow = '';
foreach ($exportFieldsAR as $f) {
$titlerow .= '"' . (isset($fieldNameAR[$f]) ? $fieldNameAR[$f] : preg_replace("/_/", " ", trim($f, "_"))) . '"' . $delim;
}
print oc_strtoupper(rtrim($titlerow, $delim)) . "\r\n";
// Iterate through records
while ($l = ocsql_fetch_array($dbR)) {
$row = '';
// Add non-author/extra fields to row
foreach ($exportFieldsAR as $f) {
if (preg_match("/^_/", $f)) {
$row .= '"' . (isset($extraAR[$l['id']][$f]) ? str_replace("\"", "\"\"", $extraAR[$l['id']][$f]) : '') . '"' . $delim;
} else {
$row .= '"' . str_replace("\"", "\"\"", oc_getFieldValue($fieldAR, $l, $f)) . '"' . $delim;
}
}
$row = preg_replace("/\015(\012)?/", "\012", $row);
print rtrim($row, $delim) . "\015\012";
}
break;
}
// exit so not additional code is executed
exit;
} // oc_export f'n