API TO TEMP UPDATE

This commit is contained in:
Claudio 2024-11-06 11:31:24 +01:00
parent ca405f4bd2
commit f9f9d45f08
13 changed files with 19 additions and 20 deletions

View File

@ -11,6 +11,9 @@ if ($conn->connect_error) {
// Check if POST request was received // Check if POST request was received
if ($_SERVER['REQUEST_METHOD'] === 'POST') { if ($_SERVER['REQUEST_METHOD'] === 'POST') {
// Array to collect messages about file processing
$file_messages = [];
// Receive JSON from the laboratory via a field in the form (e.g., 'json_data') // Receive JSON from the laboratory via a field in the form (e.g., 'json_data')
if (isset($_POST['json_data'])) { if (isset($_POST['json_data'])) {
$json_data = $_POST['json_data']; $json_data = $_POST['json_data'];
@ -108,6 +111,11 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
// Handle file uploads if they exist // Handle file uploads if they exist
if (!empty($_FILES)) { if (!empty($_FILES)) {
include('process_files.php'); // Include file processing logic here include('process_files.php'); // Include file processing logic here
// Retrieve any messages added in process_files.php for files
if (!empty($GLOBALS['file_messages'])) {
$file_messages = $GLOBALS['file_messages'];
}
} }
// Set a session variable to notify the report import // Set a session variable to notify the report import
@ -124,7 +132,8 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
"product_refnumber" => $product_refnumber, // Product number "product_refnumber" => $product_refnumber, // Product number
"report_number" => $report_number, // Report number "report_number" => $report_number, // Report number
"rating" => $rating, // Report rating "rating" => $rating, // Report rating
"saved_at" => $saved_at // Save date "saved_at" => $saved_at, // Save date
"file_messages" => $file_messages // Include file messages
]); ]);
} else { } else {
echo json_encode([ echo json_encode([

View File

@ -1,4 +1,7 @@
<?php <?php
// Initialize an array to store file messages
$GLOBALS['file_messages'] = [];
// Check if there are any files uploaded // Check if there are any files uploaded
if (!empty($_FILES)) { if (!empty($_FILES)) {
// Define the directory where files will be stored // Define the directory where files will be stored
@ -28,29 +31,16 @@ if (!empty($_FILES)) {
$stmt = $conn->prepare("INSERT INTO report_files (uuid, original_filename, stored_filename, filepath, file_comment) VALUES (?, ?, ?, ?, ?)"); $stmt = $conn->prepare("INSERT INTO report_files (uuid, original_filename, stored_filename, filepath, file_comment) VALUES (?, ?, ?, ?, ?)");
$stmt->bind_param("sssss", $uuid, $original_filename, $stored_filename, $filepath, $file_comment); $stmt->bind_param("sssss", $uuid, $original_filename, $stored_filename, $filepath, $file_comment);
if (!$stmt->execute()) { if ($stmt->execute()) {
echo json_encode([ $GLOBALS['file_messages'][] = "File $original_filename uploaded and information saved.";
"status" => "error", } else {
"message" => "Failed to save file information for $original_filename." $GLOBALS['file_messages'][] = "Failed to save file information for $original_filename.";
]);
continue;
} }
echo json_encode([
"status" => "success",
"message" => "File $original_filename uploaded and information saved."
]);
} else { } else {
echo json_encode([ $GLOBALS['file_messages'][] = "Failed to move file $original_filename.";
"status" => "error",
"message" => "Failed to move file $original_filename."
]);
} }
} else { } else {
echo json_encode([ $GLOBALS['file_messages'][] = "Error uploading file $original_filename. Error code: " . $file['error'];
"status" => "error",
"message" => "Error uploading file $original_filename. Error code: " . $file['error']
]);
} }
} }
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 39 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 56 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 162 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 39 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 56 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 162 KiB