| Server IP : 173.209.174.21 / Your IP : 216.73.216.89 Web Server : Apache/2.4.58 (Ubuntu) System : Linux wcfs-server 6.8.0-124-generic #124-Ubuntu SMP PREEMPT_DYNAMIC Tue May 26 13:00:45 UTC 2026 x86_64 User : nodor ( 1000) PHP Version : 8.3.6 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /var/www/wcfs/tabs/ |
Upload File : |
<?php include 'protect.php'; ?>
<?php
function load_account_map($file) {
$map = [];
if (($handle = fopen($file, 'r')) !== false) {
while (($data = fgetcsv($handle)) !== false) {
if (count($data) >= 2) {
$map[trim($data[0])] = trim($data[1]);
}
}
fclose($handle);
}
return $map;
}
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_FILES['fuel_file'])) {
$fuelFile = $_FILES['fuel_file']['tmp_name'];
$acctMapFile = $_FILES['map_file']['tmp_name'];
$output = fopen('php://output', 'w');
// Static product ID map
$productMap = [
'01' => 'Unleaded',
'02' => 'Unleaded Plus',
'06' => 'Road Diesel',
'07' => 'Farm Diesel'
];
// Load account mappings from uploaded file
$acctMap = file_exists($acctMapFile) ? load_account_map($acctMapFile) : [];
// Set headers to prompt download
header('Content-Type: text/csv');
header('Content-Disposition: attachment; filename="mapped_fuel_data.csv"');
if (($handle = fopen($fuelFile, 'r')) !== false) {
$headers = fgetcsv($handle);
fputcsv($output, $headers);
$prodIdIndex = array_search('ProdId', $headers);
$acctNameIndex = array_search('AcctName', $headers);
while (($data = fgetcsv($handle)) !== false) {
// Replace ProdId
if (isset($data[$prodIdIndex]) && isset($productMap[$data[$prodIdIndex]])) {
$data[$prodIdIndex] = $productMap[$data[$prodIdIndex]];
}
// Replace AcctName
if (isset($data[$acctNameIndex]) && isset($acctMap[$data[$acctNameIndex]])) {
$data[$acctNameIndex] = $acctMap[$data[$acctNameIndex]];
}
fputcsv($output, $data);
}
fclose($handle);
}
exit;
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Fuel CSV Mapper with Account Upload</title>
<style>
body { font-family: Arial, sans-serif; margin: 50px auto; max-width: 600px; text-align: center; }
input[type="file"], button { margin: 10px 0; padding: 8px; }
</style>
</head>
<body>
<h2>Fuel CSV Mapper Tool</h2>
<form action="fuel_mapper.php" method="POST" enctype="multipart/form-data">
<label>Select Fuel CSV:</label><br>
<input type="file" name="fuel_file" accept=".csv" required><br><br>
<label>Upload Account Mapping CSV (e.g. "AcctName,CustomerName"):</label><br>
<input type="file" name="map_file" accept=".csv"><br><br>
<button type="submit">Upload and Convert</button>
</form>
</body>
</html>