diff --git a/public/photostrf/296-20250509071709-images.jpg b/public/photostrf/296-20250509071709-images.jpg new file mode 100644 index 0000000..78882ed Binary files /dev/null and b/public/photostrf/296-20250509071709-images.jpg differ diff --git a/public/photostrf/298-20250509072550-images.jpg b/public/photostrf/298-20250509072550-images.jpg new file mode 100644 index 0000000..78882ed Binary files /dev/null and b/public/photostrf/298-20250509072550-images.jpg differ diff --git a/public/photostrf/300-20250509081112-images.jpg b/public/photostrf/300-20250509081112-images.jpg new file mode 100644 index 0000000..78882ed Binary files /dev/null and b/public/photostrf/300-20250509081112-images.jpg differ diff --git a/public/photostrf/302-20250509081917-images.jpg b/public/photostrf/302-20250509081917-images.jpg new file mode 100644 index 0000000..78882ed Binary files /dev/null and b/public/photostrf/302-20250509081917-images.jpg differ diff --git a/public/photostrf/304-20250509082403-images.jpg b/public/photostrf/304-20250509082403-images.jpg new file mode 100644 index 0000000..78882ed Binary files /dev/null and b/public/photostrf/304-20250509082403-images.jpg differ diff --git a/public/photostrf/306-20250509083003-images.jpg b/public/photostrf/306-20250509083003-images.jpg new file mode 100644 index 0000000..78882ed Binary files /dev/null and b/public/photostrf/306-20250509083003-images.jpg differ diff --git a/public/photostrf/308-20250509084245-images.jpg b/public/photostrf/308-20250509084245-images.jpg new file mode 100644 index 0000000..78882ed Binary files /dev/null and b/public/photostrf/308-20250509084245-images.jpg differ diff --git a/public/photostrf/310-20250509085003-images.jpg b/public/photostrf/310-20250509085003-images.jpg new file mode 100644 index 0000000..78882ed Binary files /dev/null and b/public/photostrf/310-20250509085003-images.jpg differ diff --git a/public/photostrf/312-20250509090555-images.jpg b/public/photostrf/312-20250509090555-images.jpg new file mode 100644 index 0000000..78882ed Binary files /dev/null and b/public/photostrf/312-20250509090555-images.jpg differ diff --git a/public/photostrf/314-20250509112753-images.jpg b/public/photostrf/314-20250509112753-images.jpg new file mode 100644 index 0000000..78882ed Binary files /dev/null and b/public/photostrf/314-20250509112753-images.jpg differ diff --git a/public/photostrf/annotated/aaaaphoto_296_2025-05-09T07-18-45-278Z_2025-05-09T07-18-45-278Z.png b/public/photostrf/annotated/aaaaphoto_296_2025-05-09T07-18-45-278Z_2025-05-09T07-18-45-278Z.png new file mode 100644 index 0000000..92cf250 Binary files /dev/null and b/public/photostrf/annotated/aaaaphoto_296_2025-05-09T07-18-45-278Z_2025-05-09T07-18-45-278Z.png differ diff --git a/public/photostrf/annotated/eeephoto_312_2025-05-09T09-09-18-509Z_2025-05-09T09-09-18-509Z.png b/public/photostrf/annotated/eeephoto_312_2025-05-09T09-09-18-509Z_2025-05-09T09-09-18-509Z.png new file mode 100644 index 0000000..c2c57f7 Binary files /dev/null and b/public/photostrf/annotated/eeephoto_312_2025-05-09T09-09-18-509Z_2025-05-09T09-09-18-509Z.png differ diff --git a/public/photostrf/annotated/photo_314_2025-05-09T13-07-08-581Z_2025-05-09T13-07-08-581Z.png b/public/photostrf/annotated/photo_314_2025-05-09T13-07-08-581Z_2025-05-09T13-07-08-581Z.png new file mode 100644 index 0000000..b46e56b Binary files /dev/null and b/public/photostrf/annotated/photo_314_2025-05-09T13-07-08-581Z_2025-05-09T13-07-08-581Z.png differ diff --git a/public/photostrf/qrcodes/qrcode_296.png b/public/photostrf/qrcodes/qrcode_296.png new file mode 100644 index 0000000..d77fe98 Binary files /dev/null and b/public/photostrf/qrcodes/qrcode_296.png differ diff --git a/public/photostrf/qrcodes/qrcode_298.png b/public/photostrf/qrcodes/qrcode_298.png new file mode 100644 index 0000000..4b73509 Binary files /dev/null and b/public/photostrf/qrcodes/qrcode_298.png differ diff --git a/public/photostrf/qrcodes/qrcode_300.png b/public/photostrf/qrcodes/qrcode_300.png new file mode 100644 index 0000000..4b5b3bf Binary files /dev/null and b/public/photostrf/qrcodes/qrcode_300.png differ diff --git a/public/photostrf/qrcodes/qrcode_302.png b/public/photostrf/qrcodes/qrcode_302.png new file mode 100644 index 0000000..9893564 Binary files /dev/null and b/public/photostrf/qrcodes/qrcode_302.png differ diff --git a/public/photostrf/qrcodes/qrcode_304.png b/public/photostrf/qrcodes/qrcode_304.png new file mode 100644 index 0000000..ea409d8 Binary files /dev/null and b/public/photostrf/qrcodes/qrcode_304.png differ diff --git a/public/photostrf/qrcodes/qrcode_306.png b/public/photostrf/qrcodes/qrcode_306.png new file mode 100644 index 0000000..8b831c9 Binary files /dev/null and b/public/photostrf/qrcodes/qrcode_306.png differ diff --git a/public/photostrf/qrcodes/qrcode_308.png b/public/photostrf/qrcodes/qrcode_308.png new file mode 100644 index 0000000..45512e7 Binary files /dev/null and b/public/photostrf/qrcodes/qrcode_308.png differ diff --git a/public/photostrf/qrcodes/qrcode_310.png b/public/photostrf/qrcodes/qrcode_310.png new file mode 100644 index 0000000..15d4047 Binary files /dev/null and b/public/photostrf/qrcodes/qrcode_310.png differ diff --git a/public/photostrf/qrcodes/qrcode_312.png b/public/photostrf/qrcodes/qrcode_312.png new file mode 100644 index 0000000..16d257e Binary files /dev/null and b/public/photostrf/qrcodes/qrcode_312.png differ diff --git a/public/photostrf/qrcodes/qrcode_314.png b/public/photostrf/qrcodes/qrcode_314.png new file mode 100644 index 0000000..2895bf1 Binary files /dev/null and b/public/photostrf/qrcodes/qrcode_314.png differ diff --git a/public/userarea/imported_trf/1-20250509104938-MONCLER TRF - 21.11.2024_CHIARA_SS25_2C PER PELLI.xlsx b/public/userarea/imported_trf/1-20250509104938-MONCLER TRF - 21.11.2024_CHIARA_SS25_2C PER PELLI.xlsx new file mode 100644 index 0000000..8c3b7e0 Binary files /dev/null and b/public/userarea/imported_trf/1-20250509104938-MONCLER TRF - 21.11.2024_CHIARA_SS25_2C PER PELLI.xlsx differ diff --git a/public/userarea/imported_trf/1-20250509132735-MONCLER TRF - 21.11.2024_CHIARA_SS25_2C PER PELLI.xlsx b/public/userarea/imported_trf/1-20250509132735-MONCLER TRF - 21.11.2024_CHIARA_SS25_2C PER PELLI.xlsx new file mode 100644 index 0000000..8c3b7e0 Binary files /dev/null and b/public/userarea/imported_trf/1-20250509132735-MONCLER TRF - 21.11.2024_CHIARA_SS25_2C PER PELLI.xlsx differ diff --git a/public/userarea/load_photo.php b/public/userarea/load_photo.php new file mode 100644 index 0000000..34ca8e2 --- /dev/null +++ b/public/userarea/load_photo.php @@ -0,0 +1,29 @@ +getConnection(); + +$iddatadb = $_GET['iddatadb'] ?? null; + +if (!$iddatadb) { + echo json_encode(['success' => false, 'message' => 'ID TRF mancante']); + exit; +} + +try { + $stmt = $pdo->prepare("SELECT file_path FROM datadb_photos WHERE iddatadb = :iddatadb LIMIT 1"); + $stmt->execute([':iddatadb' => $iddatadb]); + $photo = $stmt->fetch(PDO::FETCH_ASSOC); + + if ($photo && $photo['file_path']) { + $fullPath = '../photostrf/' . $photo['file_path']; // Assumi che le foto siano nella cartella photostrf + echo json_encode(['success' => true, 'file_path' => $fullPath]); + } else { + echo json_encode(['success' => false, 'message' => 'Nessuna foto trovata']); + } +} catch (PDOException $e) { + echo json_encode(['success' => false, 'message' => 'Errore nel caricamento: ' . $e->getMessage()]); +} diff --git a/public/userarea/modal_parts.php b/public/userarea/modal_parts.php index d0c12b4..6ea998c 100644 --- a/public/userarea/modal_parts.php +++ b/public/userarea/modal_parts.php @@ -7,29 +7,47 @@ @@ -50,7 +68,6 @@ #partsTable th { padding: 0.2rem; vertical-align: middle; - /* Allinea verticalmente il contenuto */ } #partsTable input { @@ -71,4 +88,49 @@ width: 100% !important; max-width: 100% !important; } + + #partsList .list-group-item { + cursor: pointer; + transition: background-color 0.2s; + } + + #partsList .list-group-item:hover { + background-color: #f5f5f5; + } + + .draggable-description { + position: absolute; + background: rgba(255, 255, 255, 0.8); + padding: 5px; + font-size: 10px; + font-family: Arial, sans-serif; + color: #000000; + cursor: move; + user-select: none; + z-index: 1000; + } + + .draggable-marker { + position: absolute; + width: 16px; + height: 16px; + background: rgba(255, 0, 0, 0.5); + border: 1px solid #ff0000; + border-radius: 50%; + color: #ffffff; + text-align: center; + line-height: 16px; + font-size: 8px; + cursor: move; + user-select: none; + z-index: 1000; + } + + #markerContainer { + position: absolute; + top: 0; + left: 0; + width: 100%; + height: 100%; + } \ No newline at end of file diff --git a/public/userarea/parts.js b/public/userarea/parts.js index cc43652..9427811 100644 --- a/public/userarea/parts.js +++ b/public/userarea/parts.js @@ -17,11 +17,55 @@ $(document).ready(function () { $("#trfHeader").text(`${iddatadb} - ${importRef} - ${description}`); $("#partsModal").data("iddatadb", iddatadb); + loadPhoto(iddatadb); loadExistingParts(iddatadb); $("#partsModal").modal("show"); }); + function loadPhoto(iddatadb) { + $.ajax({ + url: "load_photo.php", + method: "GET", + data: { iddatadb: iddatadb }, + success: function (response) { + if (response.success && response.file_path) { + const img = $("#samplePhoto"); + img.attr("src", response.file_path); + img.on("load", function () { + const container = img.parent(); + const canvas = document.getElementById("photoCanvas"); + const containerWidth = container.width(); + const containerHeight = container.height(); + const scaleX = containerWidth / img[0].naturalWidth; + const scaleY = containerHeight / img[0].naturalHeight; + const scale = Math.min(scaleX, scaleY); + canvas.width = img[0].naturalWidth * scale; + canvas.height = img[0].naturalHeight * scale; + canvas.style.width = `${containerWidth}px`; + canvas.style.height = `${containerHeight}px`; + const ctx = canvas.getContext("2d"); + ctx.clearRect(0, 0, canvas.width, canvas.height); + ctx.drawImage( + img.get(0), + 0, + 0, + canvas.width, + canvas.height, + ); + updateMarkers(); + }); + } else { + $("#samplePhoto").attr("src", ""); + alert("Nessuna foto trovata per questo TRF."); + } + }, + error: function (xhr, status, error) { + alert("Errore nel caricamento della foto: " + error); + }, + }); + } + function addNewRow(nextPartNumber) { const newRow = ` @@ -62,6 +106,7 @@ $(document).ready(function () { .get(), ); addNewRow(maxPartNumber + 1); + updatePartsList(); }); $(document).on("click", ".remove-row", function (e) { @@ -71,7 +116,8 @@ $(document).ready(function () { const partId = $row.data("part-id"); console.log("ID parte da eliminare:", partId); - if (partId !== "new") { + if (partId !== "new" && partId !== undefined && partId !== null) { + console.log("Procedo con la cancellazione dal database"); $.ajax({ url: "delete_part.php", method: "POST", @@ -88,6 +134,8 @@ $(document).ready(function () { if (response.success) { $row.remove(); updateRowButtons(); + updatePartsList(); + clearCanvasMarkers(); } else { alert("Errore nell'eliminazione: " + response.message); } @@ -105,8 +153,12 @@ $(document).ready(function () { }, }); } else { + console.log( + 'Riga non salvata nel database (partId = "new" o non definito), rimuovo solo visivamente', + ); $row.remove(); updateRowButtons(); + updatePartsList(); } }); @@ -140,8 +192,16 @@ $(document).ready(function () { contentType: "application/json", success: function (response) { if (response.success) { + if (response.part_id) { + $row.data("part-id", response.part_id); + console.log( + "Aggiornato partId della riga:", + response.part_id, + ); + } $saveLoading.hide(); $saveStatus.show(); + updatePartsList(); setTimeout(() => $saveStatus.hide(), 2000); } else { alert("Errore nel salvataggio: " + response.message); @@ -184,6 +244,7 @@ $(document).ready(function () { addNewRow(1); } updateRowButtons(); + updatePartsList(); } else { alert( "Errore nel caricamento delle parti: " + @@ -199,6 +260,308 @@ $(document).ready(function () { }); } + function updatePartsList() { + $("#partsList").empty(); + $("#partsTableBody tr").each(function () { + const partNumber = $(this).find(".part-number").val(); + const partDescription = $(this).find(".part-description").val(); + if (partNumber && partDescription) { + const listItem = `
  • ${partNumber} - ${partDescription}
  • `; + $("#partsList").append(listItem); + } + }); + } + + let selectedPartNumber = null; + let markers = []; + let descriptionPosition = { x: 10, y: 10 }; + let hasDescriptions = false; + + $("#partsList").on("click", "li", function () { + selectedPartNumber = $(this).data("part-number"); + console.log("Part number selezionato:", selectedPartNumber); + $(this).addClass("active").siblings().removeClass("active"); + }); + + const canvas = document.getElementById("photoCanvas"); + const ctx = canvas.getContext("2d"); + + $("#markerContainer").on("click", function (e) { + console.log("Click sul markerContainer rilevato"); // Debug + if (selectedPartNumber !== null) { + const img = $("#samplePhoto"); + const canvas = document.getElementById("photoCanvas"); + const rect = canvas.getBoundingClientRect(); + const container = img.parent(); + const containerWidth = container.width(); + const containerHeight = container.height(); + const scaleX = containerWidth / img.get(0).naturalWidth; + const scaleY = containerHeight / img.get(0).naturalHeight; + const scale = Math.min(scaleX, scaleY); + const x = (e.clientX - rect.left) / scale; + const y = (e.clientY - rect.top) / scale; + + console.log("Coordinate cliccate (x, y):", x, y); // Debug + + const existingMarker = markers.find( + (m) => m.partNumber == selectedPartNumber, + ); + if (existingMarker) { + existingMarker.x = x; + existingMarker.y = y; + } else { + markers.push({ partNumber: selectedPartNumber, x, y }); + } + console.log("Markers aggiornati:", markers); // Debug + updateMarkers(); + if (hasDescriptions) { + drawDescriptions(descriptionPosition.x, descriptionPosition.y); + } + selectedPartNumber = null; + $("#partsList li").removeClass("active"); + } else { + console.log("Nessun part number selezionato"); // Debug + } + }); + function updateMarkers() { + const img = $("#samplePhoto"); + const container = img.parent(); + const containerWidth = container.width(); + const containerHeight = container.height(); + const scaleX = containerWidth / img.get(0).naturalWidth; + const scaleY = containerHeight / img.get(0).naturalHeight; + const scale = Math.min(scaleX, scaleY); + + const markerContainer = $("#markerContainer"); + markerContainer.empty(); + + markers.forEach((marker) => { + const scaledX = marker.x * scale; + const scaledY = marker.y * scale; + console.log( + "Aggiungo marker:", + marker.partNumber, + "a posizione (scaledX, scaledY):", + scaledX, + scaledY, + ); // Debug + const $marker = $( + `
    ${marker.partNumber}
    `, + ).css({ + left: scaledX - 8 + "px", + top: scaledY - 8 + "px", + }); + markerContainer.append($marker); + makeDraggable($marker, marker, scale); + }); + } + + function makeDraggable($element, item, scale) { + let isDragging = false; + let currentX = parseFloat($element.css("left")) || 0; + let currentY = parseFloat($element.css("top")) || 0; + let initialX, initialY; + + $element.on("mousedown", function (e) { + e.preventDefault(); + isDragging = true; + initialX = e.clientX - currentX; + initialY = e.clientY - currentY; + $element.css("z-index", 1001); + }); + + $(document).on("mousemove", function (e) { + if (isDragging) { + e.preventDefault(); + currentX = e.clientX - initialX; + currentY = e.clientY - initialY; + const container = $("#photoCanvas").parent(); + const containerWidth = container.width(); + const containerHeight = container.height(); + const maxX = containerWidth - $element.width(); + const maxY = containerHeight - $element.height(); + + currentX = Math.max(0, Math.min(currentX, maxX)); + currentY = Math.max(0, Math.min(currentY, maxY)); + + $element.css({ + left: currentX + "px", + top: currentY + "px", + }); + + if (item.partNumber) { + // È un marker + item.x = (currentX + 8) / scale; + item.y = (currentY + 8) / scale; + } else { + // È la lista + descriptionPosition.x = (currentX + 5) / scale; + descriptionPosition.y = (currentY + 5) / scale; + } + } + }); + + $(document).on("mouseup", function () { + isDragging = false; + $element.css("z-index", 1000); + }); + } + + function drawDescriptions(x, y) { + const img = $("#samplePhoto"); + const container = img.parent(); + const containerWidth = container.width(); + const containerHeight = container.height(); + const scaleX = containerWidth / img.get(0).naturalWidth; + const scaleY = containerHeight / img.get(0).naturalHeight; + const scale = Math.min(scaleX, scaleY); + + const partsList = []; + $("#partsTableBody tr").each(function () { + const partNumber = $(this).find(".part-number").val(); + const partDescription = $(this).find(".part-description").val(); + if (partNumber && partDescription) { + partsList.push(`${partNumber} ${partDescription}`); + } + }); + + const descriptionList = $("#descriptionList"); + descriptionList.empty(); + descriptionList.css({ + display: "block", + top: y * scale + "px", + left: x * scale + "px", + width: "200px", + }); + partsList.forEach((part) => { + descriptionList.append(`
    ${part}
    `); + }); + + updateMarkers(); + } + + function clearCanvasMarkers() { + markers = []; + hasDescriptions = false; + $("#descriptionList").css("display", "none"); + $("#markerContainer").empty(); + const canvas = document.getElementById("photoCanvas"); + const img = $("#samplePhoto"); + const ctx = canvas.getContext("2d"); + const container = img.parent(); + const containerWidth = container.width(); + const containerHeight = container.height(); + const scaleX = containerWidth / img.get(0).naturalWidth; + const scaleY = containerHeight / img.get(0).naturalHeight; + const scale = Math.min(scaleX, scaleY); + + canvas.width = img.get(0).naturalWidth * scale; + canvas.height = img.get(0).naturalHeight * scale; + ctx.clearRect(0, 0, canvas.width, canvas.height); + ctx.drawImage(img.get(0), 0, 0, canvas.width, canvas.height); + } + + $("#addDescriptionsBtn").on("click", function () { + hasDescriptions = true; + descriptionPosition = { x: 10, y: 10 }; + drawDescriptions(descriptionPosition.x, descriptionPosition.y); + makeDraggable( + $("#descriptionList"), + descriptionPosition, + Math.min( + $("#photoCanvas").parent().width() / + $("#samplePhoto").get(0).naturalWidth, + $("#photoCanvas").parent().height() / + $("#samplePhoto").get(0).naturalHeight, + ), + ); + }); + + $("#removeAnnotationsBtn").on("click", function () { + clearCanvasMarkers(); + }); + + $("#savePhotoBtn").on("click", function () { + const canvas = document.getElementById("photoCanvas"); + const img = $("#samplePhoto"); + const ctx = canvas.getContext("2d"); + + canvas.width = img.get(0).naturalWidth; + canvas.height = img.get(0).naturalHeight; + ctx.drawImage(img.get(0), 0, 0); + + const partsList = []; + $("#partsTableBody tr").each(function () { + const partNumber = $(this).find(".part-number").val(); + const partDescription = $(this).find(".part-description").val(); + if (partNumber && partDescription) { + partsList.push(`${partNumber} ${partDescription}`); + } + }); + + if (hasDescriptions) { + ctx.fillStyle = "rgba(255, 255, 255, 0.8)"; + ctx.fillRect( + descriptionPosition.x, + descriptionPosition.y, + 200, + partsList.length * 12 + 10, + ); + ctx.fillStyle = "#000000"; + ctx.font = "10px Arial"; + partsList.forEach((part, index) => { + ctx.fillText( + part, + descriptionPosition.x + 5, + descriptionPosition.y + 12 + index * 12, + ); + }); + } + + markers.forEach((marker) => { + ctx.beginPath(); + ctx.arc(marker.x, marker.y, 8, 0, 2 * Math.PI); + ctx.fillStyle = "rgba(255, 0, 0, 0.5)"; + ctx.fill(); + ctx.strokeStyle = "#ff0000"; + ctx.lineWidth = 1; + ctx.stroke(); + ctx.fillStyle = "#ffffff"; + ctx.font = "bold 8px Arial"; + ctx.textAlign = "center"; + ctx.textBaseline = "middle"; + ctx.fillText(marker.partNumber, marker.x, marker.y); + }); + + const dataURL = canvas.toDataURL("image/png"); + const timestamp = new Date().toISOString().replace(/[:.]/g, "-"); + const defaultName = `photo_${$("#partsModal").data("iddatadb")}_${timestamp}.png`; + const newName = prompt( + "Inserisci il nome del file (senza estensione):", + defaultName.split(".png")[0], + ); + if (newName) { + const finalName = newName + "_" + timestamp + ".png"; + $.ajax({ + url: "save_annotated_photo.php", + method: "POST", + data: { dataURL: dataURL, filename: finalName }, + success: function (response) { + if (response.success) { + alert( + "Foto salvata con successo: " + response.file_path, + ); + } else { + alert("Errore nel salvataggio: " + response.message); + } + }, + error: function (xhr, status, error) { + alert("Errore nel salvataggio della foto: " + error); + }, + }); + } + }); + $(document).on("mouseenter", "tr", function () { console.log("Mouse entrato su riga"); }); diff --git a/public/userarea/save_annotated_photo.php b/public/userarea/save_annotated_photo.php new file mode 100644 index 0000000..244d36b --- /dev/null +++ b/public/userarea/save_annotated_photo.php @@ -0,0 +1,25 @@ + false, 'message' => 'Dati mancanti']); + exit; +} + +try { + $data = explode(',', $dataURL)[1]; + $decodedData = base64_decode($data); + $filePath = '../photostrf/annotated/' . $filename; // Crea una sottocartella 'annotated' per le foto modificate + if (!file_exists('../photostrf/annotated')) { + mkdir('../photostrf/annotated', 0777, true); + } + file_put_contents($filePath, $decodedData); + echo json_encode(['success' => true, 'file_path' => $filePath, 'message' => 'Foto salvata con successo']); +} catch (Exception $e) { + echo json_encode(['success' => false, 'message' => 'Errore nel salvataggio: ' . $e->getMessage()]); +}