Skip to content

Commit

Permalink
Issue #141 fix: Fixed issue that was creating extra columns if comma …
Browse files Browse the repository at this point in the history
…present in heading titles (#142)

* Issue #141 fix: Fixed issue that was creating extra columns if comma present in heading titles

* Issue #141 chore: Remove encoding as it is not needed
  • Loading branch information
praneettekdi authored and manojLondhe committed Aug 8, 2019
1 parent ff5b3c3 commit cfcf123
Showing 1 changed file with 18 additions and 21 deletions.
39 changes: 18 additions & 21 deletions tjreports/site/controllers/reports.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ public function csvexport()
$columns = $model->columns;
$colToshow = $model->getState('colToshow');

$csvData = null;
$csvData_arr = $colTitleArray = array();
$colTitleArray = array();

foreach ($colToshow as $index => $detail)
{
Expand Down Expand Up @@ -111,19 +110,23 @@ public function csvexport()
}
}

$csvData .= implode(',', $colTitleArray);
$csvData .= "\n";
echo $csvData;

$csvData = '';
$pluginTitle = $reportData->title;
$filename = strtolower($pluginTitle) . "_report_" . date("Y-m-d_H-i", time());

// Create a file pointer connected to the output stream
$output = fopen('php://output', 'w');

// Put CSV headings first
fputcsv($output, $colTitleArray);

// Set CSV headers
header("Content-type: text/csv");
header("Content-Disposition: attachment; filename=" . $filename . ".csv");
header("Pragma: no-cache");
header("Expires: 0");
header('Pragma: no-cache');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Content-Description: File Transfer');
header('Content-Type: text/csv;');
header('Content-Disposition: attachment; filename=' . $filename . '.csv');
header('Content-Transfer-Encoding: binary');

// Loop through items
foreach ((array) $items as $itemKey => $item)
Expand All @@ -136,25 +139,19 @@ public function csvexport()
{
foreach ($key as $subkey => $subVal)
{
$final_text_value = $this->filterValue($item[$arrayKey][$subkey]);

// Add data in the Quotes and asign it in the csv array
$itemCSV[] = '"' . $final_text_value . '"';
$itemCSV[] = $this->filterValue($item[$arrayKey][$subkey]);
}
}
else
{
$final_text_value = $this->filterValue($item[$key]);

// Add data in the Quotes and asign it in the csv array
$itemCSV[] = '"' . $final_text_value . '"';
$itemCSV[] = $this->filterValue($item[$key]);
}
}

// TRIGGER After csv body add extra fields
echo implode(',', $itemCSV) . "\n";
fputcsv($output, $itemCSV);
}

fclose($output);
jexit();
}

Expand Down

0 comments on commit cfcf123

Please sign in to comment.