From a3fa722e5fb556c794f91a1449bd2b5986db3f8f Mon Sep 17 00:00:00 2001 From: Flatlogic Bot Date: Mon, 27 Oct 2025 12:46:17 +0000 Subject: [PATCH] c3 --- analysis.php | 79 ++++++++----------- config.php | 20 +++++ dashboard.php | 1 + .../001_create_uploaded_files_table.sql | 11 +++ header.php | 2 +- index.php | 1 + login.php | 3 +- upload.php | 41 ++++++++-- 8 files changed, 103 insertions(+), 55 deletions(-) create mode 100644 config.php create mode 100644 db/migrations/001_create_uploaded_files_table.sql diff --git a/analysis.php b/analysis.php index 1153c69..4882666 100644 --- a/analysis.php +++ b/analysis.php @@ -1,4 +1,6 @@ -
Aggregated Emissions Data
+
Submitted Reports
- - - - - - + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + query('SELECT id, original_filename, upload_time, status, uploaded_by FROM uploaded_files ORDER BY upload_time DESC'); + $files = $stmt->fetchAll(); + + if (empty($files)): + ?> + + + + + + + + + + + + '; + } + ?>
Facility NameRegionPollutantTotal EmissionsUnitYearIDOriginal FilenameUpload TimeStatusUploaded By
West Burton Power StationUKD1Carbon Dioxide (CO2)1,500,000Tonnes2024
Drax Power StationUKE2Carbon Dioxide (CO2)1,250,000Tonnes2024
Rugeley Power StationUKG2Nitrogen Oxides (NOx)80,000Kilograms2024
Fiddlers Ferry Power StationUKD2Methane (CH4)5,500Kilograms2024
Cottam Development CentreUKF1Carbon Dioxide (CO2)950,000Tonnes2024
No files have been uploaded yet.
Error fetching data: ' . htmlspecialchars($e->getMessage()) . '
diff --git a/config.php b/config.php new file mode 100644 index 0000000..ffb5283 --- /dev/null +++ b/config.php @@ -0,0 +1,20 @@ + \ No newline at end of file diff --git a/dashboard.php b/dashboard.php index 6982b8c..b18c5bf 100644 --- a/dashboard.php +++ b/dashboard.php @@ -1,4 +1,5 @@ + diff --git a/index.php b/index.php index 5029e8d..9dedd62 100644 --- a/index.php +++ b/index.php @@ -1,4 +1,5 @@
- +
diff --git a/upload.php b/upload.php index 4bc27be..bb462ca 100644 --- a/upload.php +++ b/upload.php @@ -1,4 +1,6 @@ Success! Your file "' . htmlspecialchars(basename($file['name'])) . '" has been uploaded and is pending validation.'; - $message_type = 'success'; + // Ensure the uploads directory exists and is writable. + if (!is_dir(UPLOADS_PATH)) { + mkdir(UPLOADS_PATH, 0755, true); + } + + // Create a unique filename to prevent overwrites and sanitize the original name. + $original_filename = basename($file['name']); + $safe_filename = preg_replace("/[^a-zA-Z0-9-_\.]/", "", $original_filename); + $unique_id = uniqid(); + $new_filename = $unique_id . '_' . $safe_filename; + $destination = UPLOADS_PATH . '/' . $new_filename; + + // Move the file to the permanent location. + if (move_uploaded_file($file['tmp_name'], $destination)) { + // Insert a record into the database + try { + $pdo = db(); + $stmt = $pdo->prepare( + 'INSERT INTO uploaded_files (original_filename, new_filename, uploaded_by) VALUES (?, ?, ?)' + ); + $stmt->execute([$original_filename, $new_filename, $_SESSION['user_email']]); + $message = 'Success! Your file "' . htmlspecialchars($original_filename) . '" has been uploaded and is pending validation.'; + $message_type = 'success'; + } catch (PDOException $e) { + // If DB insert fails, it's critical to let the user know. + $message = 'File uploaded, but failed to record the submission. Please contact support.'; + $message_type = 'danger'; + // Optionally, log the detailed error: error_log($e->getMessage()); + } + } else { + $message = 'An error occurred while saving the file. Please try again.'; + $message_type = 'danger'; + } } } }