| 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/thelittlebigshow/self-hosted/ |
Upload File : |
<?php
include 'protect.php';
include 'db.php';
include 'store_settings.php';
require_once __DIR__ . '/qbo_name_map_helpers.php';
require_once __DIR__ . '/scheduled_export_helpers.php';
$month = trim((string) ($_REQUEST['month'] ?? ''));
$includeArchived = !empty($_REQUEST['include_archived']);
$mapQboNames = !empty($_REQUEST['map_qbo_names']);
if (!preg_match('/^\d{4}-\d{2}$/', $month)) {
http_response_code(400);
echo 'Please choose a valid export month.';
exit;
}
$qboNameMap = [];
if ($mapQboNames) {
try {
$mappingFile = $_FILES['mapping_file'] ?? [];
if (($mappingFile['error'] ?? UPLOAD_ERR_NO_FILE) === UPLOAD_ERR_NO_FILE) {
$qboNameMap = qboNameMapLoadSaved($conn);
} else {
qboNameMapStoreUploadedFile($conn, $mappingFile);
$qboNameMap = qboNameMapLoadSaved($conn);
}
} catch (Throwable $e) {
http_response_code(400);
echo htmlspecialchars($e->getMessage(), ENT_QUOTES, 'UTF-8');
exit;
}
}
$safeStore = preg_replace('/[^A-Za-z0-9_-]+/', '_', (string) ($_SESSION['store_name'] ?? $_SESSION['store_db'] ?? 'store'));
$filename = $safeStore . '_transactions_' . $month . ($mapQboNames ? '_qbo_mapped' : '') . '.csv';
$csvContent = exportCsvStringForMonth($conn, $month, $includeArchived, $mapQboNames);
header('Content-Type: text/csv; charset=UTF-8');
header('Content-Disposition: attachment; filename="' . $filename . '"');
echo $csvContent;
exit;