From d7824332a6159ec8972d67ef499f56edc4ea1997 Mon Sep 17 00:00:00 2001 From: Flatlogic Bot Date: Thu, 20 Nov 2025 22:14:33 +0000 Subject: [PATCH] versao aprimorada 2 --- add_installation.php | 39 +++++++++++++++++-- .../003_add_image_path_to_installations.sql | 1 + index.php | 25 +++++++++++- 3 files changed, 60 insertions(+), 5 deletions(-) create mode 100644 db/migrations/003_add_image_path_to_installations.sql diff --git a/add_installation.php b/add_installation.php index 7eb7700..c0636f0 100644 --- a/add_installation.php +++ b/add_installation.php @@ -10,6 +10,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { $voltage = trim($_POST['voltage'] ?? null); $phase_neutral_ground = trim($_POST['phase_neutral_ground'] ?? null); $breaker_output = trim($_POST['breaker_output'] ?? null); + $image_path = null; if (empty($client_name) || empty($address) || empty($technician_name)) { $_SESSION['message'] = 'Please fill all required fields.'; @@ -18,12 +19,44 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { exit; } + // Handle file upload + if (isset($_FILES['installation_image']) && $_FILES['installation_image']['error'] === UPLOAD_ERR_OK) { + $upload_dir = __DIR__ . '/assets/uploads/'; + if (!is_dir($upload_dir)) { + mkdir($upload_dir, 0775, true); + } + + $file_tmp_path = $_FILES['installation_image']['tmp_name']; + $file_name = $_FILES['installation_image']['name']; + $file_ext = strtolower(pathinfo($file_name, PATHINFO_EXTENSION)); + $allowed_ext = ['jpg', 'jpeg', 'png', 'gif']; + + if (in_array($file_ext, $allowed_ext)) { + $new_file_name = time() . '_' . basename($file_name); + $dest_path = $upload_dir . $new_file_name; + + if (move_uploaded_file($file_tmp_path, $dest_path)) { + $image_path = 'assets/uploads/' . $new_file_name; + } else { + $_SESSION['message'] = 'Failed to move uploaded file.'; + $_SESSION['message_type'] = 'danger'; + header('Location: index.php'); + exit; + } + } else { + $_SESSION['message'] = 'Invalid file type. Only JPG, JPEG, PNG, and GIF are allowed.'; + $_SESSION['message_type'] = 'danger'; + header('Location: index.php'); + exit; + } + } + try { $pdo = db(); $stmt = $pdo->prepare( - "INSERT INTO installations (client_name, address, technician_name, observations, voltage, phase_neutral_ground, breaker_output) VALUES (?, ?, ?, ?, ?, ?, ?)" + "INSERT INTO installations (client_name, address, technician_name, observations, voltage, phase_neutral_ground, breaker_output, image_path) VALUES (?, ?, ?, ?, ?, ?, ?, ?)" ); - $stmt->execute([$client_name, $address, $technician_name, $observations, $voltage, $phase_neutral_ground, $breaker_output]); + $stmt->execute([$client_name, $address, $technician_name, $observations, $voltage, $phase_neutral_ground, $breaker_output, $image_path]); $_SESSION['message'] = 'Installation registered successfully!'; $_SESSION['message_type'] = 'success'; @@ -35,4 +68,4 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { } header('Location: index.php'); -exit; +exit; \ No newline at end of file diff --git a/db/migrations/003_add_image_path_to_installations.sql b/db/migrations/003_add_image_path_to_installations.sql new file mode 100644 index 0000000..72ecea9 --- /dev/null +++ b/db/migrations/003_add_image_path_to_installations.sql @@ -0,0 +1 @@ +ALTER TABLE installations ADD COLUMN image_path VARCHAR(255) NULL DEFAULT NULL; \ No newline at end of file diff --git a/index.php b/index.php index d2b590a..2cbfa34 100644 --- a/index.php +++ b/index.php @@ -169,9 +169,13 @@ try { + + + + @@ -179,14 +183,26 @@ try { - + + + + +
Image Client Address TechnicianVoltagePhase/NeutralBreaker Date Actions
No installations found.No installations found.
+ + + Installation Image + + + N/A + + @@ -212,7 +228,7 @@ try {