From a6518d21e122468ac503b4e8f4b0db723d8af6e7 Mon Sep 17 00:00:00 2001
From: Kipjr <12066560+Kipjr@users.noreply.github.com>
Date: Thu, 12 Sep 2024 09:35:12 +0200
Subject: [PATCH 1/3] add ./bar/tmp for csv and chown www-data
---
src/Dockerfile | 1 +
1 file changed, 1 insertion(+)
diff --git a/src/Dockerfile b/src/Dockerfile
index d02875c..dcff7de 100644
--- a/src/Dockerfile
+++ b/src/Dockerfile
@@ -12,6 +12,7 @@ ENV DEPLOY_ENV=production
RUN mkdir /docker-entrypoint-initdb.d && \
cp /var/www/html/data/marktwerking.structure.sql /docker-entrypoint-initdb.d/ && \
cp /usr/local/etc/php/php.ini-${DEPLOY_ENV} /usr/local/etc/php/php.ini && \
+ chown www-data:root /var/www/html/bar/tmp && \
sed -ri ' \
s!^(\s*CustomLog)\s+\S+!\1 /proc/self/fd/1!g; \
s!^(\s*ErrorLog)\s+\S+!\1 /proc/self/fd/2!g; \
From e576aaf5c95e980f16215ae6ac9bb8362515bd48 Mon Sep 17 00:00:00 2001
From: Kipjr <12066560+Kipjr@users.noreply.github.com>
Date: Thu, 12 Sep 2024 09:35:36 +0200
Subject: [PATCH 2/3] Add link to menu
---
src/html/bar/index.php | 1 +
1 file changed, 1 insertion(+)
diff --git a/src/html/bar/index.php b/src/html/bar/index.php
index e4b51f0..82ee0c1 100644
--- a/src/html/bar/index.php
+++ b/src/html/bar/index.php
@@ -120,6 +120,7 @@
- Beamer
+ - Export data
- Financial
- Settings
- Uitloggen
From 93e87214feb76ea15c318f2877a04a6eba812392 Mon Sep 17 00:00:00 2001
From: Kipjr <12066560+Kipjr@users.noreply.github.com>
Date: Thu, 12 Sep 2024 09:36:04 +0200
Subject: [PATCH 3/3] Download Marktwerking export
---
src/html/bar/download.php | 75 +++++++++++++++++++++++++++++++++++++++
1 file changed, 75 insertions(+)
create mode 100644 src/html/bar/download.php
diff --git a/src/html/bar/download.php b/src/html/bar/download.php
new file mode 100644
index 0000000..03fac81
--- /dev/null
+++ b/src/html/bar/download.php
@@ -0,0 +1,75 @@
+
+CSV Data Preview";
+echo "";
+
+foreach($sql as $query){
+
+ // Match table name from query
+ preg_match('/from\s+(\S+)/i', $query, $matches);
+ $tableName = $matches[1];
+
+ // Create a temporary file
+ $filepath = tempnam(__DIR__ . "/tmp",$tableName . "_csv_");
+ $tmpFile = basename($filepath);
+
+ // Store temporary file path to download later
+ $csvFiles[] = $tmpFile;
+
+ // Open the temporary file for writing
+ $output = fopen($filepath, 'w');
+
+ // Execute query
+ $stmt = $pdo->prepare($query);
+ $stmt->execute();
+ $result = $stmt->fetchAll(PDO::FETCH_ASSOC);
+
+ // Write column headers to the CSV
+ if (!empty($result)) {
+ fputcsv($output, array_keys($result[0]));
+ }
+
+ // Write each row to the CSV
+ foreach ($result as $row) {
+ fputcsv($output, $row);
+ }
+
+ // Close the temporary file
+ fclose($output);
+
+ // Display the CSV content in the browser as a preview
+ echo "Table: $tableName
";
+ echo "
";
+
+ // Open the file for reading and output its contents
+ $csvData = file_get_contents($filepath);
+ echo nl2br($csvData); // Display CSV data
+
+ echo "
";
+
+ // Provide a link to download the file
+ echo '
Download ' . $tableName . ' CSV';
+}
+
+echo "";
+?>
\ No newline at end of file