loreal-global-kickoff/get-csv-preview.php
DJP df403363a9 Add file preview selector and download all functionality
Title Changes:
- App title: "L'Oréal OMG Assistant Global"
- Tab 1: "Master Global Asset Submission"
- Upload button: "Approve & Upload to OMG"

Preview Enhancements:
- Dropdown selector to preview all 16 CSV files individually
- Shows filename with ISO code (e.g., "en-GB - OMG1601654_...")
- Switch between files to view complete data for each
- Show ALL rows (not just first 20)

Download Features:
- "Download Current File" - Download the currently previewed CSV
- "Download All Files (ZIP)" - Download all 16 CSVs as a ZIP archive
- get-csv-preview.php: Endpoint to fetch any file for preview
- download-all-csv.php: Creates ZIP with all CSVs

UX Improvements:
- File selector styled with brand colors
- Clear labeling of which file is being previewed
- Easy navigation between all regional CSVs
- Test before upload with full data visibility

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-17 17:27:25 -05:00

53 lines
1.3 KiB
PHP

<?php
/**
* Get CSV Preview for Specific File Index
*/
session_start();
header('Content-Type: application/json');
try {
// Check if processed data exists
if (!isset($_SESSION['processed_csv'])) {
echo json_encode([
'success' => false,
'error' => 'No processed data found'
]);
exit;
}
$fileIndex = isset($_GET['fileIndex']) ? (int)$_GET['fileIndex'] : 0;
$processedData = $_SESSION['processed_csv'];
if (!isset($processedData['files'][$fileIndex])) {
echo json_encode([
'success' => false,
'error' => 'Invalid file index'
]);
exit;
}
require_once __DIR__ . '/vendor/autoload.php';
$csvFile = $processedData['files'][$fileIndex];
// Parse CSV and return all rows
$csvReader = \League\Csv\Reader::createFromString($csvFile['content']);
$csvReader->setHeaderOffset(0);
$previewRows = iterator_to_array($csvReader->getRecords());
echo json_encode([
'success' => true,
'filename' => $csvFile['filename'],
'isoCode' => $csvFile['isoCode'],
'preview' => $previewRows,
'rowCount' => count($previewRows)
]);
} catch (Exception $e) {
echo json_encode([
'success' => false,
'error' => $e->getMessage()
]);
}