Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| cf45a5bc31 | |||
| 9826331545 | |||
| 62bf4ebd92 | |||
| 6e465e3010 | |||
| 8b08969c69 |
+12
@@ -51,4 +51,16 @@ public/userarea/class/curl_request_debug.log
|
|||||||
# Ignora cartella photostrf in public/userarea
|
# Ignora cartella photostrf in public/userarea
|
||||||
/public/userarea/photostrf/
|
/public/userarea/photostrf/
|
||||||
public/userarea/customfield_values_response.json
|
public/userarea/customfield_values_response.json
|
||||||
|
/public/userarea/logaspi/
|
||||||
|
|
||||||
|
public/userarea/logsapi/campione_762_1.json
|
||||||
|
public/userarea/logsapi/campione_763_1.json
|
||||||
|
public/userarea/logsapi/campione_762_2.json
|
||||||
|
public/userarea/logsapi/campione_763_2.json
|
||||||
|
public/userarea/logsapi/commessaweb_create_762.json
|
||||||
|
public/userarea/logsapi/commessaweb_create_763.json
|
||||||
|
public/userarea/logsapi/commessaweb_customfields_762.json
|
||||||
|
public/userarea/logsapi/commessaweb_customfields_763.json
|
||||||
|
public/userarea/logsapi/commessaweb_invia_762.json
|
||||||
|
public/userarea/logsapi/commessaweb_invia_763.json
|
||||||
|
public/userarea/logsapi/last_auth_url.txt
|
||||||
|
|||||||
@@ -32,4 +32,3 @@ $langdatatables = [
|
|||||||
"paginate_next" => "Next",
|
"paginate_next" => "Next",
|
||||||
"paginate_previous" => "Previous"
|
"paginate_previous" => "Previous"
|
||||||
];
|
];
|
||||||
$quotationstitle = "Quotations";
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
require_once dirname(__DIR__, 3) . '/vendor/autoload.php'; // Torna al livello di public
|
require_once dirname(__DIR__, 3) . '/vendor/autoload.php';
|
||||||
|
|
||||||
use Dotenv\Dotenv;
|
use Dotenv\Dotenv;
|
||||||
|
|
||||||
@@ -13,7 +13,7 @@ class VisualLimsApiClient
|
|||||||
|
|
||||||
private function __construct()
|
private function __construct()
|
||||||
{
|
{
|
||||||
$dotenv = Dotenv::createImmutable(dirname(__DIR__, 3)); // Torna al livello di public
|
$dotenv = Dotenv::createImmutable(dirname(__DIR__, 3)); // Corretto per C:\xampp8-2-12\htdocs\trf_certest\.env
|
||||||
$dotenv->load();
|
$dotenv->load();
|
||||||
|
|
||||||
$this->baseUrl = $_ENV['API_BASE_URL'];
|
$this->baseUrl = $_ENV['API_BASE_URL'];
|
||||||
@@ -87,6 +87,7 @@ class VisualLimsApiClient
|
|||||||
$token = $this->getToken();
|
$token = $this->getToken();
|
||||||
$url = "{$this->baseUrl}/api/odata/{$endpoint}";
|
$url = "{$this->baseUrl}/api/odata/{$endpoint}";
|
||||||
|
|
||||||
|
|
||||||
$ch = curl_init($url);
|
$ch = curl_init($url);
|
||||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||||
curl_setopt($ch, CURLOPT_HTTPHEADER, [
|
curl_setopt($ch, CURLOPT_HTTPHEADER, [
|
||||||
@@ -120,4 +121,88 @@ class VisualLimsApiClient
|
|||||||
|
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function post($endpoint, $payload)
|
||||||
|
{
|
||||||
|
$token = $this->getToken();
|
||||||
|
$url = "{$this->baseUrl}/api/odata/{$endpoint}"; // Corretto per /api/odata/CommessaWeb
|
||||||
|
file_put_contents(__DIR__ . '/url_debug.log', date('Y-m-d H:i:s') . " - POST URL: {$url}\n", FILE_APPEND);
|
||||||
|
$ch = curl_init($url);
|
||||||
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||||
|
curl_setopt($ch, CURLOPT_POST, true);
|
||||||
|
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($payload));
|
||||||
|
curl_setopt($ch, CURLOPT_HTTPHEADER, [
|
||||||
|
"Authorization: Bearer {$token}",
|
||||||
|
"Content-Type: application/json",
|
||||||
|
"Accept: application/json"
|
||||||
|
]);
|
||||||
|
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
||||||
|
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
|
||||||
|
curl_setopt($ch, CURLOPT_VERBOSE, true);
|
||||||
|
$log = fopen(__DIR__ . '/curl_request_debug.log', 'w') ?: fopen('php://stderr', 'w');
|
||||||
|
curl_setopt($ch, CURLOPT_STDERR, $log);
|
||||||
|
|
||||||
|
$response = curl_exec($ch);
|
||||||
|
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||||
|
$curl_error = curl_error($ch);
|
||||||
|
fclose($log);
|
||||||
|
curl_close($ch);
|
||||||
|
|
||||||
|
if ($response === false) {
|
||||||
|
throw new Exception("Errore nella richiesta POST: {$curl_error}");
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($http_code >= 400) {
|
||||||
|
throw new Exception("Errore nella richiesta POST: HTTP {$http_code}, Risposta: " . substr($response, 0, 1000));
|
||||||
|
}
|
||||||
|
|
||||||
|
$data = json_decode($response, true);
|
||||||
|
if (json_last_error() !== JSON_ERROR_NONE) {
|
||||||
|
throw new Exception("Risposta non JSON valida: " . substr($response, 0, 1000));
|
||||||
|
}
|
||||||
|
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function patch($endpoint, $payload)
|
||||||
|
{
|
||||||
|
$token = $this->getToken();
|
||||||
|
$url = "{$this->baseUrl}/api/odata/{$endpoint}"; // Corretto per /api/odata/CommessaWeb({key})
|
||||||
|
|
||||||
|
$ch = curl_init($url);
|
||||||
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||||
|
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PATCH');
|
||||||
|
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($payload));
|
||||||
|
curl_setopt($ch, CURLOPT_HTTPHEADER, [
|
||||||
|
"Authorization: Bearer {$token}",
|
||||||
|
"Content-Type: application/json",
|
||||||
|
"Accept: application/json"
|
||||||
|
]);
|
||||||
|
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
||||||
|
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
|
||||||
|
curl_setopt($ch, CURLOPT_VERBOSE, true);
|
||||||
|
$log = fopen(__DIR__ . '/curl_request_debug.log', 'w') ?: fopen('php://stderr', 'w');
|
||||||
|
curl_setopt($ch, CURLOPT_STDERR, $log);
|
||||||
|
|
||||||
|
$response = curl_exec($ch);
|
||||||
|
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||||
|
$curl_error = curl_error($ch);
|
||||||
|
fclose($log);
|
||||||
|
curl_close($ch);
|
||||||
|
|
||||||
|
if ($response === false) {
|
||||||
|
throw new Exception("Errore nella richiesta PATCH: {$curl_error}");
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($http_code >= 400) {
|
||||||
|
throw new Exception("Errore nella richiesta PATCH: HTTP {$http_code}, Risposta: " . substr($response, 0, 1000));
|
||||||
|
}
|
||||||
|
|
||||||
|
$data = json_decode($response, true);
|
||||||
|
if (json_last_error() !== JSON_ERROR_NONE) {
|
||||||
|
throw new Exception("Risposta non JSON valida: " . substr($response, 0, 1000));
|
||||||
|
}
|
||||||
|
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,28 +0,0 @@
|
|||||||
<?php
|
|
||||||
header('Content-Type: application/json');
|
|
||||||
include('include/headscript.php');
|
|
||||||
|
|
||||||
$dbHandler = DBHandlerSelect::getInstance();
|
|
||||||
$pdo = $dbHandler->getConnection();
|
|
||||||
|
|
||||||
$data = json_decode(file_get_contents('php://input'), true);
|
|
||||||
|
|
||||||
$partId = $data['part_id'] ?? null;
|
|
||||||
|
|
||||||
if (!$partId) {
|
|
||||||
echo json_encode(['success' => false, 'message' => 'ID parte mancante']);
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
$stmt = $pdo->prepare("DELETE FROM identification_parts WHERE id = :part_id");
|
|
||||||
$stmt->execute([':part_id' => $partId]);
|
|
||||||
$rowCount = $stmt->rowCount();
|
|
||||||
if ($rowCount > 0) {
|
|
||||||
echo json_encode(['success' => true, 'message' => 'Parte eliminata con successo']);
|
|
||||||
} else {
|
|
||||||
echo json_encode(['success' => false, 'message' => 'Nessuna parte trovata con ID ' . $partId]);
|
|
||||||
}
|
|
||||||
} catch (PDOException $e) {
|
|
||||||
echo json_encode(['success' => false, 'message' => 'Errore nell\'eliminazione: ' . $e->getMessage()]);
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,239 @@
|
|||||||
|
document.addEventListener("DOMContentLoaded", () => {
|
||||||
|
console.log("export_to_lims.js loaded");
|
||||||
|
|
||||||
|
// Debug: verifica che i pulsanti siano trovati
|
||||||
|
const exportButtons = document.querySelectorAll(".export-lims-btn");
|
||||||
|
console.log(`Found ${exportButtons.length} export-lims-btn buttons`);
|
||||||
|
|
||||||
|
if (exportButtons.length === 0) {
|
||||||
|
console.warn("No .export-lims-btn buttons found in the DOM");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
exportButtons.forEach((btn) => {
|
||||||
|
btn.addEventListener("click", (e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
const rowIndex = btn.dataset.row;
|
||||||
|
const iddatadb = btn.dataset.iddatadb;
|
||||||
|
console.log(
|
||||||
|
`Export to LIMS clicked for row ${rowIndex}, iddatadb: ${iddatadb}`,
|
||||||
|
);
|
||||||
|
|
||||||
|
// Mostra il modale di conferma
|
||||||
|
const confirmModalElement =
|
||||||
|
document.getElementById("exportConfirmModal");
|
||||||
|
if (!confirmModalElement) {
|
||||||
|
console.error("exportConfirmModal not found in the DOM");
|
||||||
|
alert("Errore: Modale di conferma non trovato");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const confirmModal = new bootstrap.Modal(confirmModalElement, {
|
||||||
|
keyboard: false,
|
||||||
|
});
|
||||||
|
document.getElementById("exportIddatadb").textContent = iddatadb;
|
||||||
|
confirmModal.show();
|
||||||
|
|
||||||
|
// Gestisci il click su "Conferma"
|
||||||
|
const confirmBtn = document.getElementById("exportConfirmBtn");
|
||||||
|
if (!confirmBtn) {
|
||||||
|
console.error("exportConfirmBtn not found in the DOM");
|
||||||
|
confirmModal.hide();
|
||||||
|
alert("Errore: Pulsante di conferma non trovato");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const confirmHandler = async () => {
|
||||||
|
console.log(`Confirmed export for iddatadb: ${iddatadb}`);
|
||||||
|
confirmModal.hide();
|
||||||
|
|
||||||
|
const formData = new FormData();
|
||||||
|
formData.append("iddatadb", iddatadb);
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await fetch("export_to_lims.php", {
|
||||||
|
method: "POST",
|
||||||
|
body: formData,
|
||||||
|
});
|
||||||
|
if (!response.ok)
|
||||||
|
throw new Error(
|
||||||
|
`HTTP error! status: ${response.status}`,
|
||||||
|
);
|
||||||
|
const data = await response.json();
|
||||||
|
|
||||||
|
console.log("Export response:", data);
|
||||||
|
|
||||||
|
// Mostra il modale di risposta
|
||||||
|
const responseModalElement = document.getElementById(
|
||||||
|
"exportResponseModal",
|
||||||
|
);
|
||||||
|
if (!responseModalElement) {
|
||||||
|
console.error(
|
||||||
|
"exportResponseModal not found in the DOM",
|
||||||
|
);
|
||||||
|
alert("Errore: Modale di risposta non trovato");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const responseModal = new bootstrap.Modal(
|
||||||
|
responseModalElement,
|
||||||
|
{
|
||||||
|
keyboard: false,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
const responseMessage = document.getElementById(
|
||||||
|
"exportResponseMessage",
|
||||||
|
);
|
||||||
|
if (data.success) {
|
||||||
|
responseMessage.innerHTML = `${data.message.replace(/\n/g, "<br>")}<br>ID CommessaWeb: ${data.idcommessaweb}`;
|
||||||
|
document.getElementById(
|
||||||
|
"exportResponseModalLabel",
|
||||||
|
).textContent = "Esportazione Completata";
|
||||||
|
responseModal.show();
|
||||||
|
|
||||||
|
// Aggiorna la UI per riflettere lo stato 'To LIMS'
|
||||||
|
const statusCell = btn
|
||||||
|
.closest(".grid-row")
|
||||||
|
.querySelector(
|
||||||
|
'.grid-cell[data-col="status"] .status-badge',
|
||||||
|
);
|
||||||
|
if (statusCell) {
|
||||||
|
statusCell.classList.remove("status-i", "status-P");
|
||||||
|
statusCell.classList.add("status-l");
|
||||||
|
statusCell.textContent = "To LIMS";
|
||||||
|
}
|
||||||
|
|
||||||
|
// Gestisci la chiusura del modale di risposta
|
||||||
|
responseModalElement.addEventListener(
|
||||||
|
"hidden.bs.modal",
|
||||||
|
() => {
|
||||||
|
console.log(
|
||||||
|
"exportResponseModal closed, cleaning up",
|
||||||
|
);
|
||||||
|
// Rimuovi tutti i backdrop residui
|
||||||
|
document
|
||||||
|
.querySelectorAll(".modal-backdrop")
|
||||||
|
.forEach((backdrop) => {
|
||||||
|
console.log(
|
||||||
|
"Removing backdrop:",
|
||||||
|
backdrop,
|
||||||
|
);
|
||||||
|
backdrop.remove();
|
||||||
|
});
|
||||||
|
// Ripristina il body
|
||||||
|
document.body.classList.remove("modal-open");
|
||||||
|
document.body.style.paddingRight = "";
|
||||||
|
// Nascondi l'overlay
|
||||||
|
const overlay = document.querySelector(
|
||||||
|
".overlay.toggle-icon",
|
||||||
|
);
|
||||||
|
if (overlay) {
|
||||||
|
overlay.style.display = "none";
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{ once: true },
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
responseMessage.textContent = `Errore durante la generazione dei payload: ${data.message}`;
|
||||||
|
document.getElementById(
|
||||||
|
"exportResponseModalLabel",
|
||||||
|
).textContent = "Errore Esportazione";
|
||||||
|
responseModal.show();
|
||||||
|
|
||||||
|
// Gestisci la chiusura del modale di risposta anche in caso di errore
|
||||||
|
responseModalElement.addEventListener(
|
||||||
|
"hidden.bs.modal",
|
||||||
|
() => {
|
||||||
|
console.log(
|
||||||
|
"exportResponseModal closed, cleaning up",
|
||||||
|
);
|
||||||
|
// Rimuovi tutti i backdrop residui
|
||||||
|
document
|
||||||
|
.querySelectorAll(".modal-backdrop")
|
||||||
|
.forEach((backdrop) => {
|
||||||
|
console.log(
|
||||||
|
"Removing backdrop:",
|
||||||
|
backdrop,
|
||||||
|
);
|
||||||
|
backdrop.remove();
|
||||||
|
});
|
||||||
|
// Ripristina il body
|
||||||
|
document.body.classList.remove("modal-open");
|
||||||
|
document.body.style.paddingRight = "";
|
||||||
|
// Nascondi l'overlay
|
||||||
|
const overlay = document.querySelector(
|
||||||
|
".overlay.toggle-icon",
|
||||||
|
);
|
||||||
|
if (overlay) {
|
||||||
|
overlay.style.display = "none";
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{ once: true },
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Export error:", error);
|
||||||
|
const responseModalElement = document.getElementById(
|
||||||
|
"exportResponseModal",
|
||||||
|
);
|
||||||
|
if (!responseModalElement) {
|
||||||
|
console.error(
|
||||||
|
"exportResponseModal not found in the DOM",
|
||||||
|
);
|
||||||
|
alert("Errore: Modale di risposta non trovato");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const responseModal = new bootstrap.Modal(
|
||||||
|
responseModalElement,
|
||||||
|
{
|
||||||
|
keyboard: false,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
document.getElementById(
|
||||||
|
"exportResponseMessage",
|
||||||
|
).textContent =
|
||||||
|
`Errore durante la generazione dei payload: ${error.message}`;
|
||||||
|
document.getElementById(
|
||||||
|
"exportResponseModalLabel",
|
||||||
|
).textContent = "Errore Esportazione";
|
||||||
|
responseModal.show();
|
||||||
|
|
||||||
|
// Gestisci la chiusura del modale di risposta in caso di errore
|
||||||
|
responseModalElement.addEventListener(
|
||||||
|
"hidden.bs.modal",
|
||||||
|
() => {
|
||||||
|
console.log(
|
||||||
|
"exportResponseModal closed, cleaning up",
|
||||||
|
);
|
||||||
|
// Rimuovi tutti i backdrop residui
|
||||||
|
document
|
||||||
|
.querySelectorAll(".modal-backdrop")
|
||||||
|
.forEach((backdrop) => {
|
||||||
|
console.log("Removing backdrop:", backdrop);
|
||||||
|
backdrop.remove();
|
||||||
|
});
|
||||||
|
// Ripristina il body
|
||||||
|
document.body.classList.remove("modal-open");
|
||||||
|
document.body.style.paddingRight = "";
|
||||||
|
// Nascondi l'overlay
|
||||||
|
const overlay = document.querySelector(
|
||||||
|
".overlay.toggle-icon",
|
||||||
|
);
|
||||||
|
if (overlay) {
|
||||||
|
overlay.style.display = "none";
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{ once: true },
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Rimuovi il listener dopo l'esecuzione
|
||||||
|
confirmBtn.removeEventListener("click", confirmHandler);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Rimuovi eventuali listener precedenti
|
||||||
|
confirmBtn.removeEventListener("click", confirmHandler);
|
||||||
|
confirmBtn.addEventListener("click", confirmHandler);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,290 @@
|
|||||||
|
<?php
|
||||||
|
// File: export_to_lims.php
|
||||||
|
ini_set('display_errors', '1');
|
||||||
|
error_reporting(E_ALL);
|
||||||
|
ini_set('log_errors', 1);
|
||||||
|
ini_set('error_log', __DIR__ . '/logsapi/export_lims_error.log');
|
||||||
|
|
||||||
|
// Includi il file con la connessione al database e Dotenv
|
||||||
|
require_once __DIR__ . '/include/headscript.php';
|
||||||
|
require_once dirname(__DIR__, 2) . '/vendor/autoload.php';
|
||||||
|
require_once __DIR__ . '/class/VisualLimsApiClient.class.php';
|
||||||
|
|
||||||
|
use Dotenv\Dotenv;
|
||||||
|
|
||||||
|
// Carica il file .env
|
||||||
|
$dotenv = Dotenv::createImmutable(dirname(__DIR__, 2)); // Torna al livello di public
|
||||||
|
$dotenv->load();
|
||||||
|
|
||||||
|
// Leggi la variabile SIMULATE_EXPORT_LIMS
|
||||||
|
$simulate = filter_var($_ENV['SIMULATE_EXPORT_LIMS'] ?? true, FILTER_VALIDATE_BOOLEAN);
|
||||||
|
|
||||||
|
header('Content-Type: application/json');
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Verifica che la richiesta sia POST e contenga iddatadb
|
||||||
|
if ($_SERVER['REQUEST_METHOD'] !== 'POST' || !isset($_POST['iddatadb'])) {
|
||||||
|
throw new Exception('Richiesta non valida: iddatadb mancante');
|
||||||
|
}
|
||||||
|
|
||||||
|
$iddatadb = (int)$_POST['iddatadb'];
|
||||||
|
|
||||||
|
// Crea la cartella logsapi se non esiste
|
||||||
|
$logDir = __DIR__ . '/logsapi';
|
||||||
|
if (!is_dir($logDir)) {
|
||||||
|
mkdir($logDir, 0755, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ottieni connessione al database
|
||||||
|
$db = DBHandlerSelect::getInstance();
|
||||||
|
$pdo = $db->getConnection();
|
||||||
|
|
||||||
|
// Step 1: Creazione payload per CommessaWeb
|
||||||
|
$queryCommessa = "
|
||||||
|
SELECT
|
||||||
|
d.iddatadb,
|
||||||
|
e.idclient AS Cliente,
|
||||||
|
e.idschema AS SchemaCustomField
|
||||||
|
FROM datadb d
|
||||||
|
LEFT JOIN excel_templates e ON d.templateid = e.id
|
||||||
|
WHERE d.iddatadb = :iddatadb
|
||||||
|
";
|
||||||
|
|
||||||
|
$stmtCommessa = $pdo->prepare($queryCommessa);
|
||||||
|
$stmtCommessa->execute(['iddatadb' => $iddatadb]);
|
||||||
|
$recordCommessa = $stmtCommessa->fetch(PDO::FETCH_ASSOC);
|
||||||
|
|
||||||
|
if (!$recordCommessa) {
|
||||||
|
throw new Exception("Nessun record trovato per iddatadb: {$iddatadb}");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Validazione payload
|
||||||
|
if (empty($recordCommessa['Cliente']) || empty($recordCommessa['SchemaCustomField'])) {
|
||||||
|
throw new Exception("Dati mancanti per CommessaWeb: Cliente o SchemaCustomField non validi");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Payload per creazione CommessaWeb
|
||||||
|
$payloadCommessa = [
|
||||||
|
'Cliente' => (int)$recordCommessa['Cliente'],
|
||||||
|
'SchemaCustomField' => (int)$recordCommessa['SchemaCustomField'],
|
||||||
|
'Richiedente' => 'Richiedente test',
|
||||||
|
'Descrizione' => 'esempio Claudio'
|
||||||
|
];
|
||||||
|
|
||||||
|
// Step 2: Creazione payload per campi custom (CommesseCustomFields)
|
||||||
|
$queryCustomFields = "
|
||||||
|
SELECT
|
||||||
|
tm.field_id AS IdCommesseCustomFields,
|
||||||
|
idd.field_value AS Valore
|
||||||
|
FROM import_data_details idd
|
||||||
|
JOIN template_mapping tm ON idd.mapping_id = tm.id
|
||||||
|
WHERE idd.id = :iddatadb
|
||||||
|
";
|
||||||
|
|
||||||
|
$stmtCustomFields = $pdo->prepare($queryCustomFields);
|
||||||
|
$stmtCustomFields->execute(['iddatadb' => $iddatadb]);
|
||||||
|
$customFields = $stmtCustomFields->fetchAll(PDO::FETCH_ASSOC);
|
||||||
|
|
||||||
|
$commesseCustomFields = [];
|
||||||
|
foreach ($customFields as $field) {
|
||||||
|
$commesseCustomFields[] = [
|
||||||
|
'IdCommesseCustomFields' => (int)$field['IdCommesseCustomFields'],
|
||||||
|
'Valore' => $field['Valore'] ?? ''
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
$payloadCustomFields = [
|
||||||
|
'CommesseCustomFields' => $commesseCustomFields
|
||||||
|
];
|
||||||
|
|
||||||
|
// Step 3: Creazione payload per Campioni (da identification_parts)
|
||||||
|
$queryCampioni = "
|
||||||
|
SELECT
|
||||||
|
part_number,
|
||||||
|
idmatrice AS Matrice,
|
||||||
|
part_description AS NoteWeb
|
||||||
|
FROM identification_parts
|
||||||
|
WHERE iddatadb = :iddatadb
|
||||||
|
";
|
||||||
|
|
||||||
|
$stmtCampioni = $pdo->prepare($queryCampioni);
|
||||||
|
$stmtCampioni->execute(['iddatadb' => $iddatadb]);
|
||||||
|
$campioni = $stmtCampioni->fetchAll(PDO::FETCH_ASSOC);
|
||||||
|
|
||||||
|
$payloadsCampioni = [];
|
||||||
|
foreach ($campioni as $campione) {
|
||||||
|
if (empty($campione['Matrice'])) {
|
||||||
|
throw new Exception("Matrice non valida per campione: {$campione['part_number']}");
|
||||||
|
}
|
||||||
|
$payloadCampione = [
|
||||||
|
'Commessa' => null, // Sarà impostato dopo
|
||||||
|
'Matrice' => (int)$campione['Matrice'],
|
||||||
|
'SottoMatrice' => null,
|
||||||
|
'SchemaCustomField' => 1,
|
||||||
|
'NoteWeb' => $campione['NoteWeb'] ?? ''
|
||||||
|
];
|
||||||
|
$payloadsCampioni[] = $payloadCampione;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Step 4: Creazione payload per InviaCommessa
|
||||||
|
$payloadInviaCommessa = [];
|
||||||
|
|
||||||
|
// Variabile per idcommessaweb
|
||||||
|
$idcommessaweb = null;
|
||||||
|
$commessaweb = '';
|
||||||
|
|
||||||
|
if ($simulate) {
|
||||||
|
// Flusso simulato
|
||||||
|
$idcommessaweb = 10176; // Fittizio per il test
|
||||||
|
|
||||||
|
// Salva idcommessaweb in datadb
|
||||||
|
$updateStmt = $pdo->prepare("UPDATE datadb SET idcommessaweb = :idcommessaweb WHERE iddatadb = :iddatadb");
|
||||||
|
$updateStmt->execute(['idcommessaweb' => $idcommessaweb, 'iddatadb' => $iddatadb]);
|
||||||
|
|
||||||
|
// Salva i payload in file JSON
|
||||||
|
$outputFileCommessa = $logDir . "/commessaweb_create_{$iddatadb}.json";
|
||||||
|
file_put_contents($outputFileCommessa, json_encode($payloadCommessa, JSON_PRETTY_PRINT));
|
||||||
|
|
||||||
|
$outputFileCustomFields = $logDir . "/commessaweb_customfields_{$iddatadb}.json";
|
||||||
|
file_put_contents($outputFileCustomFields, json_encode($payloadCustomFields, JSON_PRETTY_PRINT));
|
||||||
|
|
||||||
|
foreach ($payloadsCampioni as $index => $payloadCampione) {
|
||||||
|
$payloadCampione['Commessa'] = $idcommessaweb;
|
||||||
|
$outputFileCampione = $logDir . "/campione_{$iddatadb}_{$campioni[$index]['part_number']}.json";
|
||||||
|
file_put_contents($outputFileCampione, json_encode($payloadCampione, JSON_PRETTY_PRINT));
|
||||||
|
}
|
||||||
|
|
||||||
|
$outputFileInviaCommessa = $logDir . "/commessaweb_invia_{$iddatadb}.json";
|
||||||
|
file_put_contents($outputFileInviaCommessa, json_encode($payloadInviaCommessa, JSON_PRETTY_PRINT));
|
||||||
|
|
||||||
|
// Aggiorna lo status a 'l' (To LIMS)
|
||||||
|
$updateStmt = $pdo->prepare("UPDATE datadb SET status = 'l' WHERE iddatadb = :iddatadb");
|
||||||
|
$updateStmt->execute(['iddatadb' => $iddatadb]);
|
||||||
|
|
||||||
|
// Risposta di successo (simulazione)
|
||||||
|
echo json_encode([
|
||||||
|
'success' => true,
|
||||||
|
'mode' => 'simulated',
|
||||||
|
'message' => "Payload generati e salvati in {$outputFileCommessa}, {$outputFileCustomFields}, file campioni e {$outputFileInviaCommessa}",
|
||||||
|
'idcommessaweb' => $idcommessaweb,
|
||||||
|
'commessaweb' => $commessaweb,
|
||||||
|
'payload_commessa' => $payloadCommessa,
|
||||||
|
'payload_customfields' => $payloadCustomFields,
|
||||||
|
'payload_campioni' => $payloadsCampioni,
|
||||||
|
'payload_invia_commessa' => $payloadInviaCommessa
|
||||||
|
]);
|
||||||
|
} else {
|
||||||
|
// Flusso reale
|
||||||
|
$apiClient = VisualLimsApiClient::getInstance();
|
||||||
|
|
||||||
|
// Step 1: Crea CommessaWeb
|
||||||
|
try {
|
||||||
|
$response = $apiClient->post('CommessaWeb', $payloadCommessa);
|
||||||
|
if (!isset($response['IdCommessa']) || !isset($response['CodiceCommessa'])) {
|
||||||
|
throw new Exception("Risposta API non valida: IdCommessa o CodiceCommessa mancanti: " . json_encode($response));
|
||||||
|
}
|
||||||
|
$idcommessaweb = (int)$response['IdCommessa'];
|
||||||
|
$commessaweb = $response['CodiceCommessa'];
|
||||||
|
error_log(date('Y-m-d H:i:s') . " - CommessaWeb creata: idcommessaweb {$idcommessaweb}, codice {$commessaweb} per iddatadb {$iddatadb}\n", 3, $logDir . '/export_lims_success.log');
|
||||||
|
// Salva payload CommessaWeb
|
||||||
|
$outputFileCommessa = $logDir . "/commessaweb_create_{$iddatadb}_{$idcommessaweb}.json";
|
||||||
|
file_put_contents($outputFileCommessa, json_encode($payloadCommessa, JSON_PRETTY_PRINT));
|
||||||
|
error_log(date('Y-m-d H:i:s') . " - Payload CommessaWeb salvato in {$outputFileCommessa}\n", 3, $logDir . '/export_lims_success.log');
|
||||||
|
} catch (Exception $e) {
|
||||||
|
error_log(date('Y-m-d H:i:s') . " - Errore nella creazione della CommessaWeb: " . $e->getMessage() . "\n", 3, $logDir . '/export_lims_error.log');
|
||||||
|
throw new Exception("Errore nella creazione della CommessaWeb: " . $e->getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Salva idcommessaweb e commessaweb in datadb
|
||||||
|
$updateStmt = $pdo->prepare("UPDATE datadb SET idcommessaweb = :idcommessaweb, commessaweb = :commessaweb WHERE iddatadb = :iddatadb");
|
||||||
|
$updateStmt->execute([
|
||||||
|
'idcommessaweb' => $idcommessaweb,
|
||||||
|
'commessaweb' => $commessaweb,
|
||||||
|
'iddatadb' => $iddatadb
|
||||||
|
]);
|
||||||
|
|
||||||
|
// Step 2: Crea Campioni
|
||||||
|
try {
|
||||||
|
foreach ($payloadsCampioni as $index => $payloadCampione) {
|
||||||
|
$payloadCampione['Commessa'] = $idcommessaweb;
|
||||||
|
// Salva payload Campione
|
||||||
|
$outputFileCampione = $logDir . "/campione_{$iddatadb}_{$idcommessaweb}_{$campioni[$index]['part_number']}.json";
|
||||||
|
file_put_contents($outputFileCampione, json_encode($payloadCampione, JSON_PRETTY_PRINT));
|
||||||
|
error_log(date('Y-m-d H:i:s') . " - Payload Campione salvato in {$outputFileCampione}\n", 3, $logDir . '/export_lims_success.log');
|
||||||
|
$apiClient->post('Campione', $payloadCampione);
|
||||||
|
$payloadsCampioni[$index] = $payloadCampione; // Aggiorna il payload con Commessa
|
||||||
|
error_log(date('Y-m-d H:i:s') . " - Campione creato: part_number {$campioni[$index]['part_number']} per idcommessaweb {$idcommessaweb}\n", 3, $logDir . '/export_lims_success.log');
|
||||||
|
}
|
||||||
|
} catch (Exception $e) {
|
||||||
|
error_log(date('Y-m-d H:i:s') . " - Errore nella creazione dei Campioni: " . $e->getMessage() . "\n", 3, $logDir . '/export_lims_error.log');
|
||||||
|
throw new Exception("Errore nella creazione dei Campioni: " . $e->getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Step 3: Aggiorna CommesseCustomFields
|
||||||
|
try {
|
||||||
|
// Salva payload CustomFields
|
||||||
|
$outputFileCustomFields = $logDir . "/commessaweb_customfields_{$iddatadb}_{$idcommessaweb}.json";
|
||||||
|
file_put_contents($outputFileCustomFields, json_encode($payloadCustomFields, JSON_PRETTY_PRINT));
|
||||||
|
error_log(date('Y-m-d H:i:s') . " - PayloadCustomFields per idcommessaweb {$idcommessaweb}: " . json_encode($payloadCustomFields, JSON_PRETTY_PRINT) . "\n", 3, $logDir . '/export_lims_success.log');
|
||||||
|
error_log(date('Y-m-d H:i:s') . " - Payload CustomFields salvato in {$outputFileCustomFields}\n", 3, $logDir . '/export_lims_success.log');
|
||||||
|
$apiClient->patch("CommessaWeb({$idcommessaweb})", $payloadCustomFields);
|
||||||
|
error_log(date('Y-m-d H:i:s') . " - CommesseCustomFields aggiornati per idcommessaweb {$idcommessaweb}\n", 3, $logDir . '/export_lims_success.log');
|
||||||
|
} catch (Exception $e) {
|
||||||
|
error_log(date('Y-m-d H:i:s') . " - Errore nell'aggiornamento CommesseCustomFields: " . $e->getMessage() . "\n", 3, $logDir . '/export_lims_error.log');
|
||||||
|
throw new Exception("Errore nell'aggiornamento CommesseCustomFields: " . $e->getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Step 4: Invia Commessa
|
||||||
|
try {
|
||||||
|
// Salva payload InviaCommessa
|
||||||
|
$outputFileInviaCommessa = $logDir . "/commessaweb_invia_{$iddatadb}_{$idcommessaweb}.json";
|
||||||
|
file_put_contents($outputFileInviaCommessa, json_encode($payloadInviaCommessa, JSON_PRETTY_PRINT));
|
||||||
|
error_log(date('Y-m-d H:i:s') . " - Payload InviaCommessa salvato in {$outputFileInviaCommessa}\n", 3, $logDir . '/export_lims_success.log');
|
||||||
|
$apiClient->post("CommessaWeb({$idcommessaweb})/InviaCommessa", $payloadInviaCommessa);
|
||||||
|
error_log(date('Y-m-d H:i:s') . " - Commessa inviata: idcommessaweb {$idcommessaweb}\n", 3, $logDir . '/export_lims_success.log');
|
||||||
|
} catch (Exception $e) {
|
||||||
|
error_log(date('Y-m-d H:i:s') . " - Errore nell'invio della Commessa: " . $e->getMessage() . "\n", 3, $logDir . '/export_lims_error.log');
|
||||||
|
throw new Exception("Errore nell'invio della Commessa: " . $e->getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Step 5: Recupera il numero commessaweb
|
||||||
|
try {
|
||||||
|
$commessaData = $apiClient->get("CommessaWeb({$idcommessaweb})");
|
||||||
|
$commessaweb = $commessaData['CodiceCommessaWeb'] ?? $commessaweb; // Usa CodiceCommessaWeb o fallback
|
||||||
|
if ($commessaweb) {
|
||||||
|
$updateStmt = $pdo->prepare("UPDATE datadb SET commessaweb = :commessaweb WHERE iddatadb = :iddatadb");
|
||||||
|
$updateStmt->execute(['commessaweb' => $commessaweb, 'iddatadb' => $iddatadb]);
|
||||||
|
}
|
||||||
|
error_log(date('Y-m-d H:i:s') . " - CommessaWeb recuperata: codice {$commessaweb} per idcommessaweb {$idcommessaweb}\n", 3, $logDir . '/export_lims_success.log');
|
||||||
|
} catch (Exception $e) {
|
||||||
|
error_log(date('Y-m-d H:i:s') . " - Errore nel recupero della CommessaWeb: " . $e->getMessage() . "\n", 3, $logDir . '/export_lims_error.log');
|
||||||
|
throw new Exception("Errore nel recupero della CommessaWeb: " . $e->getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Aggiorna lo status a 'l' (To LIMS)
|
||||||
|
$updateStmt = $pdo->prepare("UPDATE datadb SET status = 'l' WHERE iddatadb = :iddatadb");
|
||||||
|
$updateStmt->execute(['iddatadb' => $iddatadb]);
|
||||||
|
|
||||||
|
// Risposta di successo (flusso reale)
|
||||||
|
echo json_encode([
|
||||||
|
'success' => true,
|
||||||
|
'mode' => 'real',
|
||||||
|
'message' => "Dati inviati al LIMS con successo",
|
||||||
|
'idcommessaweb' => $idcommessaweb,
|
||||||
|
'commessaweb' => $commessaweb,
|
||||||
|
'payload_commessa' => $payloadCommessa,
|
||||||
|
'payload_customfields' => $payloadCustomFields,
|
||||||
|
'payload_campioni' => $payloadsCampioni,
|
||||||
|
'payload_invia_commessa' => $payloadInviaCommessa
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
} catch (Exception $e) {
|
||||||
|
// Log dell'errore
|
||||||
|
file_put_contents($logDir . '/export_lims_error.log', date('Y-m-d H:i:s') . ' - Flusso ' . ($simulate ? 'simulato' : 'reale') . ' fallito: ' . $e->getMessage() . PHP_EOL, FILE_APPEND);
|
||||||
|
http_response_code(500);
|
||||||
|
echo json_encode([
|
||||||
|
'success' => false,
|
||||||
|
'mode' => $simulate ? 'simulated' : 'real',
|
||||||
|
'message' => 'Errore: ' . $e->getMessage()
|
||||||
|
]);
|
||||||
|
}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
<?php
|
||||||
|
require_once dirname(__DIR__, 2) . '/vendor/autoload.php';
|
||||||
|
require_once dirname(__FILE__) . '/class/VisualLimsApiClient.class.php';
|
||||||
|
|
||||||
|
header('Content-Type: application/json');
|
||||||
|
|
||||||
|
ini_set('display_errors', '0');
|
||||||
|
error_reporting(E_ALL);
|
||||||
|
|
||||||
|
try {
|
||||||
|
$api = VisualLimsApiClient::getInstance();
|
||||||
|
|
||||||
|
// Endpoint per recuperare le Matrici
|
||||||
|
$endpoint = 'Matrice';
|
||||||
|
|
||||||
|
// (Opzionale) aggiungi parametri, ad esempio $top per limitare i risultati
|
||||||
|
$options = []; // oppure ad esempio: ['$top' => 100]
|
||||||
|
|
||||||
|
// Debug: salva URL usato
|
||||||
|
$base_url = 'https://93.43.5.102/limsapi/api/odata/';
|
||||||
|
$query = http_build_query($options);
|
||||||
|
$full_url = $base_url . $endpoint . ($query ? '?' . $query : '');
|
||||||
|
file_put_contents(__DIR__ . '/last_url.txt', $full_url . PHP_EOL, FILE_APPEND);
|
||||||
|
|
||||||
|
// Chiamata API
|
||||||
|
$data = $api->get($endpoint, $options);
|
||||||
|
|
||||||
|
// Salva il JSON in locale
|
||||||
|
file_put_contents(__DIR__ . '/matrici_response.json', json_encode($data, JSON_PRETTY_PRINT));
|
||||||
|
|
||||||
|
echo json_encode($data);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
file_put_contents(__DIR__ . '/error_log.txt', date('Y-m-d H:i:s') . ' - ' . $e->getMessage() . PHP_EOL, FILE_APPEND);
|
||||||
|
http_response_code(500);
|
||||||
|
echo json_encode(['error' => $e->getMessage()]);
|
||||||
|
}
|
||||||
@@ -405,6 +405,16 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
|
|||||||
.save-all-btn:hover {
|
.save-all-btn:hover {
|
||||||
background-color: #218838;
|
background-color: #218838;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#exportConfirmModal,
|
||||||
|
#exportResponseModal {
|
||||||
|
z-index: 1300 !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
#exportConfirmModal .modal-backdrop,
|
||||||
|
#exportResponseModal .modal-backdrop {
|
||||||
|
z-index: 1299 !important;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
<title>Edit Imported Data - <?= htmlspecialchars($titlewebsite, ENT_QUOTES, 'UTF-8'); ?></title>
|
<title>Edit Imported Data - <?= htmlspecialchars($titlewebsite, ENT_QUOTES, 'UTF-8'); ?></title>
|
||||||
</head>
|
</head>
|
||||||
@@ -708,6 +718,7 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
|
|||||||
<script src="photos.js"></script>
|
<script src="photos.js"></script>
|
||||||
<script src="parts.js"></script>
|
<script src="parts.js"></script>
|
||||||
<script src="tracking.js"></script>
|
<script src="tracking.js"></script>
|
||||||
|
<script src="export_to_lims.js"></script>
|
||||||
<script>
|
<script>
|
||||||
document.addEventListener("DOMContentLoaded", function() {
|
document.addEventListener("DOMContentLoaded", function() {
|
||||||
console.log("Page loaded, initializing event listeners");
|
console.log("Page loaded, initializing event listeners");
|
||||||
@@ -900,6 +911,8 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
window.addEventListener("beforeunload", function(e) {
|
window.addEventListener("beforeunload", function(e) {
|
||||||
if (hasChanges) {
|
if (hasChanges) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
@@ -907,6 +920,26 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Gestisci la chiusura dei modali per rimuovere i backdrop
|
||||||
|
document.querySelectorAll('#exportConfirmModal, #exportResponseModal').forEach(modal => {
|
||||||
|
modal.addEventListener('hidden.bs.modal', () => {
|
||||||
|
console.log(`Modal ${modal.id} closed, removing backdrops`);
|
||||||
|
// Rimuovi tutti i backdrop residui
|
||||||
|
document.querySelectorAll('.modal-backdrop').forEach(backdrop => {
|
||||||
|
console.log('Removing backdrop:', backdrop);
|
||||||
|
backdrop.remove();
|
||||||
|
});
|
||||||
|
// Ripristina il body
|
||||||
|
document.body.classList.remove('modal-open');
|
||||||
|
document.body.style.paddingRight = '';
|
||||||
|
// Assicurati che l'overlay sia nascosto
|
||||||
|
const overlay = document.querySelector('.overlay.toggle-icon');
|
||||||
|
if (overlay) {
|
||||||
|
overlay.style.display = 'none';
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
<script>
|
<script>
|
||||||
document.addEventListener("DOMContentLoaded", function() {
|
document.addEventListener("DOMContentLoaded", function() {
|
||||||
@@ -1066,6 +1099,43 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
|
|||||||
populateDropdowns();
|
populateDropdowns();
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
<!-- Modale di conferma per l'esportazione -->
|
||||||
|
<div class="modal fade" id="exportConfirmModal" tabindex="-1" aria-labelledby="exportConfirmModalLabel" aria-hidden="true">
|
||||||
|
<div class="modal-dialog">
|
||||||
|
<div class="modal-content">
|
||||||
|
<div class="modal-header">
|
||||||
|
<h5 class="modal-title" id="exportConfirmModalLabel">Conferma Esportazione</h5>
|
||||||
|
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||||
|
</div>
|
||||||
|
<div class="modal-body">
|
||||||
|
<p id="exportConfirmMessage">Confermi l'esportazione al LIMS per iddatadb <span id="exportIddatadb"></span>?</p>
|
||||||
|
</div>
|
||||||
|
<div class="modal-footer">
|
||||||
|
<button type="button" class="btn btn-secondary btn-sm" data-bs-dismiss="modal">Annulla</button>
|
||||||
|
<button type="button" class="btn btn-primary btn-sm" id="exportConfirmBtn">Conferma</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Modale di risposta per l'esportazione -->
|
||||||
|
<div class="modal fade" id="exportResponseModal" tabindex="-1" aria-labelledby="exportResponseModalLabel" aria-hidden="true">
|
||||||
|
<div class="modal-dialog">
|
||||||
|
<div class="modal-content">
|
||||||
|
<div class="modal-header">
|
||||||
|
<h5 class="modal-title" id="exportResponseModalLabel">Risultato Esportazione</h5>
|
||||||
|
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||||
|
</div>
|
||||||
|
<div class="modal-body">
|
||||||
|
<p id="exportResponseMessage"></p>
|
||||||
|
</div>
|
||||||
|
<div class="modal-footer">
|
||||||
|
<button type="button" class="btn btn-primary btn-sm" data-bs-dismiss="modal">Chiudi</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
@@ -41,21 +41,7 @@
|
|||||||
</li>
|
</li>
|
||||||
|
|
||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>-->
|
||||||
<li>
|
|
||||||
<a href="javascript:;" class="has-arrow">
|
|
||||||
<div class="parent-icon"><i class="bx bx-category"></i>
|
|
||||||
</div>
|
|
||||||
<div class="menu-title">Other Functions</div>
|
|
||||||
</a>
|
|
||||||
<ul>
|
|
||||||
<li> <a href="quotations.php"><i class='bx bx-radio-circle'></i><?php echo $quotationstitle; ?></a>
|
|
||||||
</li>
|
|
||||||
|
|
||||||
|
|
||||||
</ul>
|
|
||||||
</li>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,23 +0,0 @@
|
|||||||
<?php
|
|
||||||
header('Content-Type: application/json');
|
|
||||||
include('include/headscript.php');
|
|
||||||
|
|
||||||
$dbHandler = DBHandlerSelect::getInstance();
|
|
||||||
$pdo = $dbHandler->getConnection();
|
|
||||||
|
|
||||||
$idquotations = $_GET['idquotations'] ?? null;
|
|
||||||
|
|
||||||
if (!$idquotations) {
|
|
||||||
echo json_encode(['success' => false, 'message' => 'ID quotations mancante']);
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
$stmt = $pdo->prepare("SELECT id, idquotations, part_number, part_description FROM identification_parts WHERE idquotations = :idquotations ORDER BY part_number ASC");
|
|
||||||
$stmt->execute([':idquotations' => $idquotations]);
|
|
||||||
$parts = $stmt->fetchAll();
|
|
||||||
|
|
||||||
echo json_encode(['success' => true, 'parts' => $parts]);
|
|
||||||
} catch (PDOException $e) {
|
|
||||||
echo json_encode(['success' => false, 'message' => 'Errore nel caricamento: ' . $e->getMessage()]);
|
|
||||||
}
|
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
<?php
|
|
||||||
// load_photo_quotation.php
|
|
||||||
header('Content-Type: application/json');
|
|
||||||
|
|
||||||
include('include/headscript.php');
|
|
||||||
|
|
||||||
$dbHandler = DBHandlerSelect::getInstance();
|
|
||||||
$pdo = $dbHandler->getConnection();
|
|
||||||
|
|
||||||
$idquotations = isset($_GET['idquotations']) ? intval($_GET['idquotations']) : null;
|
|
||||||
|
|
||||||
if (!$idquotations) {
|
|
||||||
echo json_encode(['success' => false, 'message' => 'ID quotation mancante']);
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
// Seleziona le foto per il dato idquotations dalla tabella datadb_photos
|
|
||||||
$stmt = $pdo->prepare("SELECT id, file_path FROM datadb_photos WHERE idquotations = ?");
|
|
||||||
$stmt->execute([$idquotations]);
|
|
||||||
$photos = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
||||||
|
|
||||||
if ($photos && count($photos) > 0) {
|
|
||||||
$photoPaths = array_map(function ($photo) {
|
|
||||||
return '../photostrf/' . $photo['file_path'];
|
|
||||||
}, $photos);
|
|
||||||
echo json_encode(['success' => true, 'photos' => $photoPaths]);
|
|
||||||
} else {
|
|
||||||
echo json_encode(['success' => false, 'message' => 'Nessuna foto trovata']);
|
|
||||||
}
|
|
||||||
} catch (PDOException $e) {
|
|
||||||
echo json_encode(['success' => false, 'message' => 'Errore nel caricamento: ' . $e->getMessage()]);
|
|
||||||
}
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
<!-- Modal modificato con pulsante per riconoscimento vocale e download -->
|
<!-- Modal modificato con pulsante per riconoscimento vocale -->
|
||||||
<div class="modal fade" id="partsModal" tabindex="-1" aria-labelledby="partsModalLabel" aria-hidden="true">
|
<div class="modal fade" id="partsModal" tabindex="-1" aria-labelledby="partsModalLabel" aria-hidden="true">
|
||||||
<div class="modal-dialog modal-xl" style="max-width: 80% !important; width: 80% !important;">
|
<div class="modal-dialog modal-xl" style="max-width: 80% !important; width: 80% !important;">
|
||||||
<div class="modal-content">
|
<div class="modal-content">
|
||||||
@@ -44,14 +44,13 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="col-md-6">
|
<div class="col-md-6">
|
||||||
<h6>Foto del Campione</h6>
|
<h6>Foto del Campione</h6>
|
||||||
<div style="display: flex; align-items: center; margin-bottom: 10px;">
|
<div id="photoSelectorContainer" style="display: none;">
|
||||||
<button type="button" class="btn btn-primary btn-sm" id="downloadPhotoBtn" style="padding: 0.1rem 0.5rem; font-size: 0.8rem; margin-right: 10px;"><i class="fas fa-download"></i> </button>
|
<!-- Dropdown or buttons for photo selection will appear here -->
|
||||||
<div id="photoSelectorContainer" style="display: none;"></div>
|
|
||||||
</div>
|
</div>
|
||||||
<div style="position: relative; width: 100%; min-height: 400px;">
|
<div style="position: relative; width: 100%; min-height: 400px;">
|
||||||
<img id="samplePhoto" src="" alt="Foto del campione" style="max-width: 100%; max-height: 100%; object-fit: contain; position: absolute; top: 0; left: 0;">
|
<img id="samplePhoto" src="" alt="Foto del campione" style="max-width: 100%; max-height: 100%; object-fit: contain; position: absolute; top: 0; left: 0;">
|
||||||
<canvas id="photoCanvas" style="position: absolute; top: 0; left: 0; width: 100%; height: 100%;"></canvas>
|
<canvas id="photoCanvas" style="position: absolute; top: 0; left: 0; width: 100%; height: 100%;"></canvas>
|
||||||
<canvas id="overlayCanvas" style="position: absolute; top: 0; left: 0; width: 100%; height: 100%; z-index: 1000;"></canvas> <!-- Nuovo canvas per Fabric.js -->
|
<div id="descriptionList" class="draggable-description" style="display: none;"></div>
|
||||||
<div id="markerContainer"></div>
|
<div id="markerContainer"></div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -98,14 +97,6 @@
|
|||||||
font-size: 0.6rem !important;
|
font-size: 0.6rem !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
#partsModal {
|
|
||||||
z-index: 1060 !important;
|
|
||||||
}
|
|
||||||
|
|
||||||
#partsModal .modal-backdrop {
|
|
||||||
z-index: 1055 !important;
|
|
||||||
}
|
|
||||||
|
|
||||||
#partsModal .modal-content {
|
#partsModal .modal-content {
|
||||||
width: 100% !important;
|
width: 100% !important;
|
||||||
max-width: 100% !important;
|
max-width: 100% !important;
|
||||||
@@ -136,33 +127,12 @@
|
|||||||
position: absolute;
|
position: absolute;
|
||||||
background: rgba(255, 255, 255, 0.8);
|
background: rgba(255, 255, 255, 0.8);
|
||||||
padding: 5px;
|
padding: 5px;
|
||||||
|
font-size: 10px;
|
||||||
font-family: Arial, sans-serif;
|
font-family: Arial, sans-serif;
|
||||||
color: #000000;
|
color: #000000;
|
||||||
cursor: move;
|
cursor: move;
|
||||||
user-select: none;
|
user-select: none;
|
||||||
z-index: 1000;
|
z-index: 1000;
|
||||||
min-width: 100px;
|
|
||||||
min-height: 50px;
|
|
||||||
overflow: visible;
|
|
||||||
border: 1px solid #ccc;
|
|
||||||
}
|
|
||||||
|
|
||||||
.draggable-description.active-interaction {
|
|
||||||
border: 2px dashed #000;
|
|
||||||
}
|
|
||||||
|
|
||||||
.draggable-description div {
|
|
||||||
white-space: nowrap;
|
|
||||||
}
|
|
||||||
|
|
||||||
.resize-handle {
|
|
||||||
position: absolute;
|
|
||||||
bottom: 0;
|
|
||||||
right: 0;
|
|
||||||
width: 10px;
|
|
||||||
height: 10px;
|
|
||||||
background: #888;
|
|
||||||
cursor: se-resize;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.draggable-marker {
|
.draggable-marker {
|
||||||
@@ -192,17 +162,21 @@
|
|||||||
font-size: 0.8rem;
|
font-size: 0.8rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Normale Save button */
|
||||||
#savePhotoBtn {
|
#savePhotoBtn {
|
||||||
transition: all 0.3s ease-in-out;
|
transition: all 0.3s ease-in-out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Unsaved changes */
|
||||||
#savePhotoBtn.unsaved {
|
#savePhotoBtn.unsaved {
|
||||||
background-color: #dc3545 !important;
|
background-color: #dc3545 !important;
|
||||||
|
/* Rosso */
|
||||||
border-color: #dc3545 !important;
|
border-color: #dc3545 !important;
|
||||||
color: white !important;
|
color: white !important;
|
||||||
animation: pulse 1.2s infinite;
|
animation: pulse 1.2s infinite;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Animazione pulsante */
|
||||||
@keyframes pulse {
|
@keyframes pulse {
|
||||||
0% {
|
0% {
|
||||||
box-shadow: 0 0 0 0 rgba(220, 53, 69, 0.7);
|
box-shadow: 0 0 0 0 rgba(220, 53, 69, 0.7);
|
||||||
@@ -217,6 +191,7 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Stile per il selettore personalizzato dei colori */
|
||||||
.color-picker-container {
|
.color-picker-container {
|
||||||
position: relative;
|
position: relative;
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
|
|||||||
+649
-1010
File diff suppressed because it is too large
Load Diff
+19
-32
@@ -1,21 +1,19 @@
|
|||||||
document.addEventListener("DOMContentLoaded", function () {
|
document.addEventListener("DOMContentLoaded", function () {
|
||||||
// Funzione per caricare il contenuto del popup
|
// Funzione per caricare il contenuto del popup
|
||||||
async function loadPopupContent(iddatadb, idquotations) {
|
async function loadPopupContent(iddatadb) {
|
||||||
const popupContent = document.getElementById("popupContent");
|
const popupContent = document.getElementById("popupContent");
|
||||||
if (!popupContent) {
|
if (!popupContent) {
|
||||||
console.error("Elemento popupContent non trovato");
|
console.error("Elemento popupContent non trovato");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
const endpoint = idquotations
|
const response = await fetch(
|
||||||
? `photos_popup.php?idquotations=${idquotations}`
|
`photos_popup.php?iddatadb=${iddatadb}`,
|
||||||
: `photos_popup.php?iddatadb=${iddatadb}`;
|
);
|
||||||
console.log("Caricamento popup da:", endpoint);
|
|
||||||
const response = await fetch(endpoint);
|
|
||||||
if (!response.ok)
|
if (!response.ok)
|
||||||
throw new Error("Errore nella risposta del server");
|
throw new Error("Errore nella risposta del server");
|
||||||
popupContent.innerHTML = await response.text();
|
popupContent.innerHTML = await response.text();
|
||||||
attachPhotoEventListeners(iddatadb, idquotations);
|
attachPhotoEventListeners(iddatadb);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
popupContent.innerHTML = `<p>Errore durante il caricamento: ${error.message}</p>`;
|
popupContent.innerHTML = `<p>Errore durante il caricamento: ${error.message}</p>`;
|
||||||
console.error("Errore in loadPopupContent:", error);
|
console.error("Errore in loadPopupContent:", error);
|
||||||
@@ -23,7 +21,7 @@ document.addEventListener("DOMContentLoaded", function () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Funzione per gestire la webcam
|
// Funzione per gestire la webcam
|
||||||
function setupWebcam(iddatadb, idquotations) {
|
function setupWebcam(iddatadb) {
|
||||||
const openWebcamBtn = document.getElementById("openWebcamBtn");
|
const openWebcamBtn = document.getElementById("openWebcamBtn");
|
||||||
const webcamArea = document.getElementById("webcamArea");
|
const webcamArea = document.getElementById("webcamArea");
|
||||||
const webcamVideo = document.getElementById("webcamVideo");
|
const webcamVideo = document.getElementById("webcamVideo");
|
||||||
@@ -160,7 +158,7 @@ document.addEventListener("DOMContentLoaded", function () {
|
|||||||
if (loader) {
|
if (loader) {
|
||||||
loader.style.display = "flex";
|
loader.style.display = "flex";
|
||||||
}
|
}
|
||||||
await handleFiles([file], iddatadb, idquotations);
|
await handleFiles([file], iddatadb);
|
||||||
if (stream) {
|
if (stream) {
|
||||||
stream.getTracks().forEach((track) => track.stop());
|
stream.getTracks().forEach((track) => track.stop());
|
||||||
stream = null;
|
stream = null;
|
||||||
@@ -173,7 +171,7 @@ document.addEventListener("DOMContentLoaded", function () {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async function handleFiles(files, iddatadb, idquotations) {
|
async function handleFiles(files, iddatadb) {
|
||||||
const loader = document.getElementById("loader");
|
const loader = document.getElementById("loader");
|
||||||
if (!loader) {
|
if (!loader) {
|
||||||
console.error("Elemento loader non trovato");
|
console.error("Elemento loader non trovato");
|
||||||
@@ -195,12 +193,7 @@ document.addEventListener("DOMContentLoaded", function () {
|
|||||||
|
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
formData.append("photo", file);
|
formData.append("photo", file);
|
||||||
if (idquotations) {
|
formData.append("iddatadb", iddatadb);
|
||||||
formData.append("idquotations", idquotations);
|
|
||||||
} else {
|
|
||||||
formData.append("iddatadb", iddatadb);
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch("upload_photo.php", {
|
const response = await fetch("upload_photo.php", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
@@ -208,7 +201,7 @@ document.addEventListener("DOMContentLoaded", function () {
|
|||||||
});
|
});
|
||||||
const result = await response.json();
|
const result = await response.json();
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
loadPopupContent(iddatadb, idquotations);
|
loadPopupContent(iddatadb);
|
||||||
} else {
|
} else {
|
||||||
alert("Errore durante il caricamento: " + result.message);
|
alert("Errore durante il caricamento: " + result.message);
|
||||||
}
|
}
|
||||||
@@ -220,7 +213,7 @@ document.addEventListener("DOMContentLoaded", function () {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function attachPhotoEventListeners(iddatadb, idquotations) {
|
function attachPhotoEventListeners(iddatadb) {
|
||||||
const dropArea = document.getElementById("dropArea");
|
const dropArea = document.getElementById("dropArea");
|
||||||
const photoInput = document.getElementById("photoInput");
|
const photoInput = document.getElementById("photoInput");
|
||||||
const photosModal = document.getElementById("photosModal");
|
const photosModal = document.getElementById("photosModal");
|
||||||
@@ -264,7 +257,7 @@ document.addEventListener("DOMContentLoaded", function () {
|
|||||||
(e) => {
|
(e) => {
|
||||||
const files = e.dataTransfer.files;
|
const files = e.dataTransfer.files;
|
||||||
if (files.length > 0) {
|
if (files.length > 0) {
|
||||||
handleFiles(files, iddatadb, idquotations);
|
handleFiles(files, iddatadb);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
false,
|
false,
|
||||||
@@ -283,7 +276,7 @@ document.addEventListener("DOMContentLoaded", function () {
|
|||||||
(e) => {
|
(e) => {
|
||||||
const files = e.target.files;
|
const files = e.target.files;
|
||||||
if (files.length > 0) {
|
if (files.length > 0) {
|
||||||
handleFiles(files, iddatadb, idquotations);
|
handleFiles(files, iddatadb);
|
||||||
}
|
}
|
||||||
e.target.value = "";
|
e.target.value = "";
|
||||||
},
|
},
|
||||||
@@ -305,7 +298,7 @@ document.addEventListener("DOMContentLoaded", function () {
|
|||||||
});
|
});
|
||||||
const result = await response.json();
|
const result = await response.json();
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
loadPopupContent(iddatadb, idquotations);
|
loadPopupContent(iddatadb);
|
||||||
} else {
|
} else {
|
||||||
alert(
|
alert(
|
||||||
"Errore durante l'eliminazione: " +
|
"Errore durante l'eliminazione: " +
|
||||||
@@ -343,7 +336,7 @@ document.addEventListener("DOMContentLoaded", function () {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
setupWebcam(iddatadb, idquotations);
|
setupWebcam(iddatadb);
|
||||||
|
|
||||||
const createCollageBtn = document.getElementById("createCollageBtn");
|
const createCollageBtn = document.getElementById("createCollageBtn");
|
||||||
if (createCollageBtn) {
|
if (createCollageBtn) {
|
||||||
@@ -876,9 +869,9 @@ document.addEventListener("DOMContentLoaded", function () {
|
|||||||
type: "image/jpeg",
|
type: "image/jpeg",
|
||||||
});
|
});
|
||||||
|
|
||||||
await handleFiles([file], iddatadb, idquotations);
|
await handleFiles([file], iddatadb);
|
||||||
document.getElementById("collageModal").style.display = "none";
|
document.getElementById("collageModal").style.display = "none";
|
||||||
loadPopupContent(iddatadb, idquotations);
|
loadPopupContent(iddatadb);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -999,14 +992,8 @@ document.addEventListener("DOMContentLoaded", function () {
|
|||||||
if (photosButtons.length && photosModal && closeBtn) {
|
if (photosButtons.length && photosModal && closeBtn) {
|
||||||
photosButtons.forEach((button) => {
|
photosButtons.forEach((button) => {
|
||||||
button.addEventListener("click", function () {
|
button.addEventListener("click", function () {
|
||||||
const iddatadb = this.getAttribute("data-iddatadb") || null;
|
const iddatadb = this.getAttribute("data-iddatadb");
|
||||||
const idquotations =
|
loadPopupContent(iddatadb);
|
||||||
this.getAttribute("data-idquotations") || null;
|
|
||||||
console.log("Apertura modale foto con:", {
|
|
||||||
iddatadb,
|
|
||||||
idquotations,
|
|
||||||
});
|
|
||||||
loadPopupContent(iddatadb, idquotations);
|
|
||||||
photosModal.style.display = "block";
|
photosModal.style.display = "block";
|
||||||
document.querySelector(".overlay").style.display = "none";
|
document.querySelector(".overlay").style.display = "none";
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -17,131 +17,69 @@ use Endroid\QrCode\QrCode;
|
|||||||
use Endroid\QrCode\RoundBlockSizeMode;
|
use Endroid\QrCode\RoundBlockSizeMode;
|
||||||
use Endroid\QrCode\Writer\PngWriter;
|
use Endroid\QrCode\Writer\PngWriter;
|
||||||
|
|
||||||
// Abilita logging per debug
|
|
||||||
ini_set('display_errors', 1);
|
|
||||||
ini_set('display_startup_errors', 1);
|
|
||||||
error_reporting(E_ALL);
|
|
||||||
ini_set('log_errors', 1);
|
|
||||||
ini_set('error_log', __DIR__ . '/photos_popup_debug.log');
|
|
||||||
|
|
||||||
// Log iniziale
|
|
||||||
error_log("Richiesta a photos_popup.php: " . print_r($_GET, true));
|
|
||||||
|
|
||||||
// Carica le variabili d'ambiente
|
// Carica le variabili d'ambiente
|
||||||
try {
|
try {
|
||||||
$dotenv = Dotenv\Dotenv::createImmutable(__DIR__ . '/../../');
|
$dotenv = Dotenv\Dotenv::createImmutable(__DIR__ . '/../../');
|
||||||
$dotenv->load();
|
$dotenv->load();
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
error_log("Errore nel caricamento del file .env: " . $e->getMessage());
|
error_log("Errore nel caricamento del file .env: " . $e->getMessage());
|
||||||
?>
|
echo json_encode(['error' => 'Errore nel caricamento del file di configurazione']);
|
||||||
<div class="popup-content">
|
|
||||||
<p>Errore: Impossibile caricare il file di configurazione.</p>
|
|
||||||
</div>
|
|
||||||
<?php
|
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Verifica che BASE_URL sia definito
|
// Verifica che BASE_URL sia definito
|
||||||
if (!isset($_ENV['BASE_URL'])) {
|
if (!isset($_ENV['BASE_URL'])) {
|
||||||
error_log("Errore: la variabile BASE_URL non è definita nel file .env");
|
error_log("Errore: la variabile BASE_URL non è definita nel file .env");
|
||||||
?>
|
echo json_encode(['error' => 'Variabile BASE_URL non definita']);
|
||||||
<div class="popup-content">
|
|
||||||
<p>Errore: Variabile BASE_URL non definita.</p>
|
|
||||||
</div>
|
|
||||||
<?php
|
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
$db = DBHandlerSelect::getInstance();
|
$db = DBHandlerSelect::getInstance();
|
||||||
$pdo = $db->getConnection();
|
$pdo = $db->getConnection();
|
||||||
|
|
||||||
// Verifica che almeno uno degli ID sia passato
|
// Verifica che l'iddatadb sia stato passato
|
||||||
$iddatadb = isset($_GET['iddatadb']) && !empty($_GET['iddatadb']) ? intval($_GET['iddatadb']) : null;
|
if (!isset($_GET['iddatadb']) || empty($_GET['iddatadb'])) {
|
||||||
$idquotations = isset($_GET['idquotations']) && !empty($_GET['idquotations']) ? intval($_GET['idquotations']) : null;
|
echo json_encode(['error' => 'ID riga non fornito']);
|
||||||
|
|
||||||
if (!$iddatadb && !$idquotations) {
|
|
||||||
error_log("Errore: ID riga o ID quotations non fornito");
|
|
||||||
?>
|
|
||||||
<div class="popup-content">
|
|
||||||
<p>Errore: ID riga o ID quotations non fornito.</p>
|
|
||||||
</div>
|
|
||||||
<?php
|
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($iddatadb && $idquotations) {
|
$iddatadb = intval($_GET['iddatadb']);
|
||||||
error_log("Errore: Non è possibile specificare sia iddatadb che idquotations");
|
|
||||||
?>
|
// Recupera i dettagli della riga (idriga e sample_code)
|
||||||
<div class="popup-content">
|
$stmt = $pdo->prepare("SELECT iddatadb, sample_code FROM datadb WHERE iddatadb = ?");
|
||||||
<p>Errore: Non è possibile specificare sia iddatadb che idquotations.</p>
|
$stmt->execute([$iddatadb]);
|
||||||
</div>
|
$row = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||||
<?php
|
|
||||||
|
if (!$row) {
|
||||||
|
echo json_encode(['error' => 'Riga non trovata']);
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Determina quale ID e tabella usare
|
$idriga = $row['iddatadb'];
|
||||||
$paramName = $iddatadb ? 'iddatadb' : 'id'; // Usa 'id' per quotations
|
$sampleCode = $row['sample_code'] ?? 'Non disponibile';
|
||||||
$paramValue = $iddatadb ?: $idquotations;
|
|
||||||
$table = $iddatadb ? 'datadb' : 'quotations';
|
|
||||||
$field = $iddatadb ? 'sample_code' : 'description'; // Usa 'description' per quotations
|
|
||||||
$photoTable = 'datadb_photos'; // Usa sempre datadb_photos
|
|
||||||
$photoParamName = $iddatadb ? 'iddatadb' : 'idquotations'; // Usa 'idquotations' per datadb_photos
|
|
||||||
|
|
||||||
// Recupera i dettagli della riga
|
|
||||||
try {
|
|
||||||
$stmt = $pdo->prepare("SELECT {$paramName}, {$field} FROM {$table} WHERE {$paramName} = ?");
|
|
||||||
$stmt->execute([$paramValue]);
|
|
||||||
$row = $stmt->fetch(PDO::FETCH_ASSOC);
|
|
||||||
|
|
||||||
if (!$row) {
|
|
||||||
error_log("Errore: Riga non trovata per {$paramName} = {$paramValue}");
|
|
||||||
?>
|
|
||||||
<div class="popup-content">
|
|
||||||
<p>Errore: Riga non trovata.</p>
|
|
||||||
</div>
|
|
||||||
<?php
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
} catch (Exception $e) {
|
|
||||||
error_log("Errore query dettagli riga: " . $e->getMessage());
|
|
||||||
?>
|
|
||||||
<div class="popup-content">
|
|
||||||
<p>Errore: Impossibile recuperare i dettagli della riga.</p>
|
|
||||||
</div>
|
|
||||||
<?php
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
$id = $row[$paramName];
|
|
||||||
$code = $row[$field] ?? 'Non disponibile';
|
|
||||||
|
|
||||||
// Recupera le foto associate alla riga
|
// Recupera le foto associate alla riga
|
||||||
try {
|
$stmt = $pdo->prepare("SELECT id, file_path, file_name, description, uploaded_at FROM datadb_photos WHERE iddatadb = ? ORDER BY uploaded_at DESC");
|
||||||
$stmt = $pdo->prepare("SELECT id, file_path, file_name, description, uploaded_at FROM {$photoTable} WHERE {$photoParamName} = ? ORDER BY uploaded_at DESC");
|
$stmt->execute([$iddatadb]);
|
||||||
$stmt->execute([$paramValue]);
|
$photos = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||||
$photos = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
||||||
} catch (Exception $e) {
|
|
||||||
error_log("Errore query foto: " . $e->getMessage());
|
|
||||||
$photos = []; // Imposta array vuoto in caso di errore
|
|
||||||
}
|
|
||||||
|
|
||||||
// Definisci il percorso base per le foto
|
// Definisci il percorso base per le foto
|
||||||
$photoBasePath = '../photostrf/';
|
$photoBasePath = '../photostrf/';
|
||||||
|
|
||||||
// Usa la variabile d'ambiente BASE_URL
|
// Usa la variabile d'ambiente BASE_URL
|
||||||
$baseUrl = rtrim($_ENV['BASE_URL'], '/');
|
$baseUrl = rtrim($_ENV['BASE_URL'], '/'); // Rimuove eventuali slash finali
|
||||||
$uploadUrl = $iddatadb
|
$uploadUrl = $baseUrl . "/upload_photos_mobile.php?iddatadb=" . $iddatadb;
|
||||||
? $baseUrl . "/upload_photos_mobile.php?iddatadb=" . $iddatadb
|
|
||||||
: $baseUrl . "/upload_photos_mobile.php?idquotations=" . $idquotations;
|
|
||||||
|
|
||||||
// Genera il QR code con endroid/qr-code 6.0.6
|
// Genera il QR code con endroid/qr-code 6.0.6
|
||||||
$qrCodeDir = '../photostrf/qrcodes/';
|
$qrCodeDir = '../photostrf/qrcodes/';
|
||||||
if (!is_dir($qrCodeDir)) {
|
if (!is_dir($qrCodeDir)) {
|
||||||
mkdir($qrCodeDir, 0755, true);
|
mkdir($qrCodeDir, 0755, true);
|
||||||
}
|
}
|
||||||
$qrCodeFile = $qrCodeDir . "qrcode_{$id}.png";
|
$qrCodeFile = $qrCodeDir . "qrcode_{$iddatadb}.png";
|
||||||
|
|
||||||
$writer = new PngWriter();
|
$writer = new PngWriter();
|
||||||
|
|
||||||
|
// Crea il QR code usando il costruttore
|
||||||
$qrCode = new QrCode(
|
$qrCode = new QrCode(
|
||||||
data: $uploadUrl,
|
data: $uploadUrl,
|
||||||
encoding: new Encoding('UTF-8'),
|
encoding: new Encoding('UTF-8'),
|
||||||
@@ -165,13 +103,13 @@ $result->saveToFile($qrCodeFile);
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<h3>Manage Photos</h3>
|
<h3>Manage Photos</h3>
|
||||||
<p><strong>ID:</strong> <?= htmlspecialchars($id) ?></p>
|
<p><strong>ID Row:</strong> <?= htmlspecialchars($idriga) ?></p>
|
||||||
<p><strong>Code:</strong> <?= htmlspecialchars($code) ?></p>
|
<p><strong>Sample Code:</strong> <?= htmlspecialchars($sampleCode) ?></p>
|
||||||
|
|
||||||
<!-- QR Code per il caricamento da mobile -->
|
<!-- QR Code per il caricamento da mobile -->
|
||||||
<div style="text-align: center; margin-bottom: 20px;">
|
<div style="text-align: center; margin-bottom: 20px;">
|
||||||
<p>Scan the QR Code with the mobile to take photo with camera:</p>
|
<p>Scan the QR Code with the mobile to take photo with camera:</p>
|
||||||
<img src="../photostrf/qrcodes/qrcode_<?= htmlspecialchars($id) ?>.png" alt="QR Code" style="max-width: 150px;">
|
<img src="../photostrf/qrcodes/qrcode_<?= $iddatadb ?>.png" alt="QR Code" style="max-width: 150px;">
|
||||||
<p style="margin-top: 10px;">
|
<p style="margin-top: 10px;">
|
||||||
<a href="<?= htmlspecialchars($uploadUrl) ?>" target="_blank"><?= htmlspecialchars($uploadUrl) ?></a>
|
<a href="<?= htmlspecialchars($uploadUrl) ?>" target="_blank"><?= htmlspecialchars($uploadUrl) ?></a>
|
||||||
</p>
|
</p>
|
||||||
@@ -198,7 +136,7 @@ $result->saveToFile($qrCodeFile);
|
|||||||
<!-- Elenco delle foto -->
|
<!-- Elenco delle foto -->
|
||||||
<div id="photosList">
|
<div id="photosList">
|
||||||
<?php if (empty($photos)): ?>
|
<?php if (empty($photos)): ?>
|
||||||
<p>Nessuna foto presente.</p>
|
<p>No Photos present.</p>
|
||||||
<?php else: ?>
|
<?php else: ?>
|
||||||
<?php foreach ($photos as $photo): ?>
|
<?php foreach ($photos as $photo): ?>
|
||||||
<?php
|
<?php
|
||||||
@@ -254,7 +192,7 @@ $result->saveToFile($qrCodeFile);
|
|||||||
<button id="addToCanvasBtn">Aggiungi Selezionate al Canvas</button>
|
<button id="addToCanvasBtn">Aggiungi Selezionate al Canvas</button>
|
||||||
|
|
||||||
<!-- Canvas per editing -->
|
<!-- Canvas per editing -->
|
||||||
<canvas id="collageCanvas" width="960" height="720" style="border: 1px solid #ccc; margin-top: 20px;"></canvas>
|
<canvas id="collageCanvas" width="800" height="600" style="border: 1px solid #ccc; margin-top: 20px;"></canvas>
|
||||||
|
|
||||||
<!-- Pannello dei livelli -->
|
<!-- Pannello dei livelli -->
|
||||||
<div id="layersPanel" style="width: 120px; max-height: 600px; overflow-y: auto; background: #f8f9fa; padding: 10px; position: absolute; right: 0; top: 60px;">
|
<div id="layersPanel" style="width: 120px; max-height: 600px; overflow-y: auto; background: #f8f9fa; padding: 10px; position: absolute; right: 0; top: 60px;">
|
||||||
|
|||||||
@@ -93,7 +93,6 @@ if (isset($_GET['edit_id'])) {
|
|||||||
<?php include('cssinclude.php'); ?>
|
<?php include('cssinclude.php'); ?>
|
||||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css" integrity="sha512-DTOQO9RWCH3ppGqcWaEA1BIZOC6xxalwEsw9c2QQeAIftl+Vegovlnee1c9QX4TctnWMn13TZye+giMm8e2Lw==" crossorigin="anonymous" referrerpolicy="no-referrer" />
|
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css" integrity="sha512-DTOQO9RWCH3ppGqcWaEA1BIZOC6xxalwEsw9c2QQeAIftl+Vegovlnee1c9QX4TctnWMn13TZye+giMm8e2Lw==" crossorigin="anonymous" referrerpolicy="no-referrer" />
|
||||||
<link rel="stylesheet" href="https://cdn.datatables.net/1.13.4/css/jquery.dataTables.min.css">
|
<link rel="stylesheet" href="https://cdn.datatables.net/1.13.4/css/jquery.dataTables.min.css">
|
||||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/fabric.js/5.3.1/fabric.min.js"></script>
|
|
||||||
<style>
|
<style>
|
||||||
/* Stili simili alla pagina fornita, adattati */
|
/* Stili simili alla pagina fornita, adattati */
|
||||||
.cell-changed {
|
.cell-changed {
|
||||||
@@ -175,43 +174,6 @@ if (isset($_GET['edit_id'])) {
|
|||||||
.quotation-actions {
|
.quotation-actions {
|
||||||
margin-top: 20px;
|
margin-top: 20px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.modal {
|
|
||||||
display: none;
|
|
||||||
position: fixed;
|
|
||||||
z-index: 1050;
|
|
||||||
left: 0;
|
|
||||||
top: 0;
|
|
||||||
width: 100%;
|
|
||||||
height: 100%;
|
|
||||||
overflow: auto;
|
|
||||||
background-color: rgba(0, 0, 0, 0.5);
|
|
||||||
}
|
|
||||||
|
|
||||||
.modal-content {
|
|
||||||
background-color: #fefefe;
|
|
||||||
margin: 15% auto;
|
|
||||||
padding: 20px;
|
|
||||||
border: 1px solid #888;
|
|
||||||
width: 80%;
|
|
||||||
max-width: 600px;
|
|
||||||
border-radius: 8px;
|
|
||||||
position: relative;
|
|
||||||
}
|
|
||||||
|
|
||||||
.close-btn {
|
|
||||||
color: #aaa;
|
|
||||||
float: right;
|
|
||||||
font-size: 28px;
|
|
||||||
font-weight: bold;
|
|
||||||
cursor: pointer;
|
|
||||||
}
|
|
||||||
|
|
||||||
.close-btn:hover,
|
|
||||||
.close-btn:focus {
|
|
||||||
color: #000;
|
|
||||||
text-decoration: none;
|
|
||||||
}
|
|
||||||
</style>
|
</style>
|
||||||
<title>Gestione Quotations - <?= htmlspecialchars($titlewebsite, ENT_QUOTES, 'UTF-8'); ?></title>
|
<title>Gestione Quotations - <?= htmlspecialchars($titlewebsite, ENT_QUOTES, 'UTF-8'); ?></title>
|
||||||
</head>
|
</head>
|
||||||
@@ -250,8 +212,8 @@ if (isset($_GET['edit_id'])) {
|
|||||||
</form>
|
</form>
|
||||||
<div class="quotation-actions">
|
<div class="quotation-actions">
|
||||||
<h6 class="mb-3">Azioni</h6>
|
<h6 class="mb-3">Azioni</h6>
|
||||||
<button type="button" class="photos-btn action-btn" data-row="<?= $index ?>" data-idquotations="<?= $editQuotation['id'] ?>" style="background: #007bff; color: white; border: none; padding: 8px 12px; border-radius: 5px; cursor: pointer; flex: 1;"><i class="fas fa-camera"></i></button>
|
<button type="button" class="photos-btn action-btn" data-idquotations="<?= $editQuotation['id'] ?>" title="Photos"><i class="fas fa-camera"></i></button>
|
||||||
<button class="parts-btn" data-iddatadb="" data-idquotations="456" data-row="0">Parti</button>
|
<button type="button" class="parts-btn action-btn" data-idquotations="<?= $editQuotation['id'] ?>" title="Parts"><i class="fas fa-puzzle-piece"></i></button>
|
||||||
</div>
|
</div>
|
||||||
<?php else: ?>
|
<?php else: ?>
|
||||||
<!-- Lista Quotations -->
|
<!-- Lista Quotations -->
|
||||||
@@ -280,12 +242,11 @@ if (isset($_GET['edit_id'])) {
|
|||||||
<td>
|
<td>
|
||||||
<input type="text" name="customer" class="cell-input manual-input form-control" value="<?= htmlspecialchars($row['customer']) ?>">
|
<input type="text" name="customer" class="cell-input manual-input form-control" value="<?= htmlspecialchars($row['customer']) ?>">
|
||||||
</td>
|
</td>
|
||||||
<!-- In quotations.php, nella tabella delle quotations -->
|
|
||||||
<td>
|
<td>
|
||||||
<button type="button" class="save-btn action-btn edit-btn" data-id="<?= $row['id'] ?>" title="Salva Modifiche"><i class="fas fa-save"></i></button>
|
<button type="button" class="save-btn action-btn edit-btn" data-id="<?= $row['id'] ?>" title="Salva Modifiche"><i class="fas fa-save"></i></button>
|
||||||
<button type="button" class="delete-btn action-btn" data-id="<?= $row['id'] ?>" title="Cancella" data-bs-toggle="modal" data-bs-target="#deleteModal"><i class="fas fa-trash"></i></button>
|
<button type="button" class="delete-btn action-btn" data-id="<?= $row['id'] ?>" title="Cancella" data-bs-toggle="modal" data-bs-target="#deleteModal"><i class="fas fa-trash"></i></button>
|
||||||
<button type="button" class="photos-btn action-btn" data-entity-type="quotation" data-idquotations="<?= $row['id'] ?>" title="Photos"><i class="fas fa-camera"></i></button>
|
<button type="button" class="photos-btn action-btn" data-idquotations="<?= $row['id'] ?>" title="Photos"><i class="fas fa-camera"></i></button>
|
||||||
<button type="button" class="parts-btn action-btn" data-entity-type="quotation" data-idquotations="<?= $row['id'] ?>" title="Parts"><i class="fas fa-puzzle-piece"></i></button>
|
<button type="button" class="parts-btn action-btn" data-idquotations="<?= $row['id'] ?>" title="Parts"><i class="fas fa-puzzle-piece"></i></button>
|
||||||
<a href="quotations.php?edit_id=<?= $row['id'] ?>" class="btn btn-secondary action-btn" title="Modifica Dettagliata"><i class="fas fa-edit"></i></a>
|
<a href="quotations.php?edit_id=<?= $row['id'] ?>" class="btn btn-secondary action-btn" title="Modifica Dettagliata"><i class="fas fa-edit"></i></a>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
@@ -415,15 +376,6 @@ if (isset($_GET['edit_id'])) {
|
|||||||
// I bottoni photos e parts usano gli script esistenti (photos.js, parts.js), passando data-idquotations
|
// I bottoni photos e parts usano gli script esistenti (photos.js, parts.js), passando data-idquotations
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<!-- Modale per le foto in quotations.php -->
|
|
||||||
<div class="modal" id="photosModal">
|
|
||||||
<div class="modal-content">
|
|
||||||
<span class="close-btn">×</span>
|
|
||||||
<div class="popup-content"></div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
@@ -1,63 +0,0 @@
|
|||||||
<?php
|
|
||||||
header('Content-Type: application/json');
|
|
||||||
include('include/headscript.php');
|
|
||||||
|
|
||||||
$dbHandler = DBHandlerSelect::getInstance();
|
|
||||||
$pdo = $dbHandler->getConnection();
|
|
||||||
|
|
||||||
$data = json_decode(file_get_contents('php://input'), true);
|
|
||||||
|
|
||||||
$idquotations = $data['idquotations'] ?? null;
|
|
||||||
$parts = $data['parts'] ?? [];
|
|
||||||
|
|
||||||
if (!$idquotations || empty($parts)) {
|
|
||||||
echo json_encode(['success' => false, 'message' => 'Dati mancanti']);
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
$pdo->beginTransaction();
|
|
||||||
|
|
||||||
// Elimina tutte le parti esistenti per idquotations
|
|
||||||
$stmt = $pdo->prepare("DELETE FROM identification_parts WHERE idquotations = :idquotations");
|
|
||||||
$stmt->execute([':idquotations' => $idquotations]);
|
|
||||||
|
|
||||||
// Prepara l'inserimento delle nuove parti
|
|
||||||
$stmt = $pdo->prepare("
|
|
||||||
INSERT INTO identification_parts
|
|
||||||
(idquotations, part_number, part_description, mix, created_at, updated_at)
|
|
||||||
VALUES (:idquotations, :part_number, :part_description, :mix, NOW(), NOW())
|
|
||||||
");
|
|
||||||
|
|
||||||
$part_ids = [];
|
|
||||||
foreach ($parts as $part) {
|
|
||||||
$partNumber = $part['part_number'] ?? null;
|
|
||||||
$partDescription = $part['part_description'] ?? '';
|
|
||||||
$mix = $part['mix'] ?? 'N';
|
|
||||||
|
|
||||||
if (!$partNumber || !$partDescription) {
|
|
||||||
throw new PDOException("Numero parte o descrizione mancante per parte: " . json_encode($part));
|
|
||||||
}
|
|
||||||
|
|
||||||
$stmt->execute([
|
|
||||||
':idquotations' => $idquotations,
|
|
||||||
':part_number' => $partNumber,
|
|
||||||
':part_description' => $partDescription,
|
|
||||||
':mix' => $mix
|
|
||||||
]);
|
|
||||||
$part_ids[] = $pdo->lastInsertId();
|
|
||||||
}
|
|
||||||
|
|
||||||
$pdo->commit();
|
|
||||||
echo json_encode([
|
|
||||||
'success' => true,
|
|
||||||
'part_ids' => $part_ids,
|
|
||||||
'message' => 'Parti rinumerate con successo'
|
|
||||||
]);
|
|
||||||
} catch (PDOException $e) {
|
|
||||||
$pdo->rollBack();
|
|
||||||
echo json_encode([
|
|
||||||
'success' => false,
|
|
||||||
'message' => 'Errore nel salvataggio: ' . $e->getMessage()
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
@@ -1,59 +0,0 @@
|
|||||||
<?php
|
|
||||||
header('Content-Type: application/json');
|
|
||||||
|
|
||||||
include('include/headscript.php');
|
|
||||||
error_reporting(E_ALL);
|
|
||||||
ini_set('display_errors', 1);
|
|
||||||
|
|
||||||
$dataURL = $_POST['dataURL'] ?? null;
|
|
||||||
$filename = $_POST['filename'] ?? null;
|
|
||||||
$idquotations = $_POST['idquotations'] ?? null;
|
|
||||||
|
|
||||||
if (!$dataURL || !$filename || !$idquotations) {
|
|
||||||
echo json_encode(['success' => false, 'message' => 'Dati mancanti']);
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
// Verifica che idquotations esista nella tabella quotations
|
|
||||||
$dbHandler = DBHandlerSelect::getInstance();
|
|
||||||
$pdo = $dbHandler->getConnection();
|
|
||||||
$stmt = $pdo->prepare("SELECT idquotations FROM quotations WHERE idquotations = :idquotations");
|
|
||||||
$stmt->execute([':idquotations' => $idquotations]);
|
|
||||||
if (!$stmt->fetch()) {
|
|
||||||
echo json_encode(['success' => false, 'message' => 'idquotations non valido']);
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Salva l'immagine
|
|
||||||
$data = explode(',', $dataURL)[1];
|
|
||||||
$decodedData = base64_decode($data);
|
|
||||||
|
|
||||||
$dirPath = '../photostrf/annotated';
|
|
||||||
if (!file_exists($dirPath)) {
|
|
||||||
mkdir($dirPath, 0777, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
$filePath = $dirPath . '/' . $filename;
|
|
||||||
file_put_contents($filePath, $decodedData);
|
|
||||||
|
|
||||||
// Registra nel database
|
|
||||||
$stmt = $pdo->prepare("
|
|
||||||
INSERT INTO datadb_photos (idquotations, file_path, file_name, uploaded_at, uploaded_by)
|
|
||||||
VALUES (:idquotations, :file_path, :file_name, NOW(), :uploaded_by)
|
|
||||||
");
|
|
||||||
$stmt->execute([
|
|
||||||
':idquotations' => $idquotations,
|
|
||||||
':file_path' => $filePath,
|
|
||||||
':file_name' => $filename,
|
|
||||||
':uploaded_by' => $iduserlogin
|
|
||||||
]);
|
|
||||||
|
|
||||||
echo json_encode([
|
|
||||||
'success' => true,
|
|
||||||
'file_path' => $filePath,
|
|
||||||
'message' => 'Foto salvata con successo e registrata nel DB'
|
|
||||||
]);
|
|
||||||
} catch (Exception $e) {
|
|
||||||
echo json_encode(['success' => false, 'message' => 'Errore: ' . $e->getMessage()]);
|
|
||||||
}
|
|
||||||
@@ -1,60 +0,0 @@
|
|||||||
<?php
|
|
||||||
header('Content-Type: application/json');
|
|
||||||
include('include/headscript.php');
|
|
||||||
|
|
||||||
$dbHandler = DBHandlerSelect::getInstance();
|
|
||||||
$pdo = $dbHandler->getConnection();
|
|
||||||
|
|
||||||
$data = json_decode(file_get_contents('php://input'), true);
|
|
||||||
|
|
||||||
$idquotations = $data['idquotations'] ?? null;
|
|
||||||
$parts = $data['parts'] ?? [];
|
|
||||||
|
|
||||||
if (!$idquotations || empty($parts)) {
|
|
||||||
echo json_encode(['success' => false, 'message' => 'Dati mancanti']);
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
$part = $parts[0];
|
|
||||||
$partId = $part['id'] ?? null;
|
|
||||||
$partNumber = $part['part_number'] ?? null;
|
|
||||||
$partDescription = $part['part_description'] ?? '';
|
|
||||||
$mix = $part['mix'] ?? 'N';
|
|
||||||
|
|
||||||
if ($partDescription) {
|
|
||||||
try {
|
|
||||||
if ($partId) {
|
|
||||||
// UPDATE se esiste già la parte
|
|
||||||
$stmt = $pdo->prepare("UPDATE identification_parts
|
|
||||||
SET part_number = :part_number,
|
|
||||||
part_description = :part_description,
|
|
||||||
mix = :mix,
|
|
||||||
updated_at = NOW()
|
|
||||||
WHERE id = :id");
|
|
||||||
$stmt->execute([
|
|
||||||
':id' => $partId,
|
|
||||||
':part_number' => $partNumber,
|
|
||||||
':part_description' => $partDescription,
|
|
||||||
':mix' => $mix
|
|
||||||
]);
|
|
||||||
echo json_encode(['success' => true, 'part_id' => $partId, 'part_number' => $partNumber, 'message' => 'Parte aggiornata con successo']);
|
|
||||||
} else {
|
|
||||||
// INSERT se è nuova
|
|
||||||
$stmt = $pdo->prepare("INSERT INTO identification_parts
|
|
||||||
(idquotations, part_number, part_description, mix, created_at, updated_at)
|
|
||||||
VALUES (:idquotations, :part_number, :part_description, :mix, NOW(), NOW())");
|
|
||||||
$stmt->execute([
|
|
||||||
':idquotations' => $idquotations,
|
|
||||||
':part_number' => $partNumber,
|
|
||||||
':part_description' => $partDescription,
|
|
||||||
':mix' => $mix
|
|
||||||
]);
|
|
||||||
$newId = $pdo->lastInsertId();
|
|
||||||
echo json_encode(['success' => true, 'part_id' => $newId, 'part_number' => $partNumber, 'message' => 'Parte salvata con successo']);
|
|
||||||
}
|
|
||||||
} catch (PDOException $e) {
|
|
||||||
echo json_encode(['success' => false, 'message' => 'Errore nel salvataggio: ' . $e->getMessage()]);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
echo json_encode(['success' => false, 'message' => 'Descrizione mancante']);
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,58 @@
|
|||||||
|
<?php
|
||||||
|
// File: test_auth.php
|
||||||
|
ini_set('display_errors', '0');
|
||||||
|
error_reporting(E_ALL);
|
||||||
|
ini_set('log_errors', 1);
|
||||||
|
|
||||||
|
// Includi le dipendenze
|
||||||
|
require_once dirname(__DIR__, 2) . '/vendor/autoload.php';
|
||||||
|
require_once __DIR__ . '/class/VisualLimsApiClient.class.php';
|
||||||
|
|
||||||
|
header('Content-Type: application/json');
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Crea la cartella logsapi se non esiste
|
||||||
|
$logDir = __DIR__ . '/logsapi';
|
||||||
|
if (!is_dir($logDir)) {
|
||||||
|
mkdir($logDir, 0755, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Istanzia il client API (autenticazione automatica tramite .env)
|
||||||
|
$api = VisualLimsApiClient::getInstance();
|
||||||
|
|
||||||
|
// Esegui una chiamata di test per verificare l'autenticazione
|
||||||
|
$endpoint = 'SchemaCustomField';
|
||||||
|
$options = []; // Nessun filtro per il test
|
||||||
|
$data = $api->get($endpoint, $options);
|
||||||
|
|
||||||
|
// Debug: salva URL usato
|
||||||
|
$base_url = 'https://93.43.5.102/limsapi/api/odata/';
|
||||||
|
$query = http_build_query($options);
|
||||||
|
$full_url = $base_url . $endpoint . ($query ? '?' . $query : '');
|
||||||
|
file_put_contents($logDir . '/last_auth_url.txt', $full_url . PHP_EOL, FILE_APPEND);
|
||||||
|
|
||||||
|
// Nota: getToken() è privato, quindi non possiamo accedervi direttamente
|
||||||
|
// Supponiamo che l'autenticazione sia avvenuta correttamente se la GET ha successo
|
||||||
|
$token = null; // Non possiamo accedere al token direttamente
|
||||||
|
$auth_success = true; // La GET ha successo, quindi l'autenticazione funziona
|
||||||
|
|
||||||
|
// Salva un file di conferma dell'autenticazione
|
||||||
|
$outputFile = $logDir . '/auth_token.json';
|
||||||
|
file_put_contents($outputFile, json_encode(['auth_success' => true, 'token' => 'Not directly accessible (private method)'], JSON_PRETTY_PRINT));
|
||||||
|
|
||||||
|
// Risposta di successo
|
||||||
|
echo json_encode([
|
||||||
|
'success' => true,
|
||||||
|
'message' => "Autenticazione completata con successo, dettagli salvati in {$outputFile}",
|
||||||
|
'auth_success' => $auth_success,
|
||||||
|
'schema_data' => $data // Dati di esempio dalla GET
|
||||||
|
]);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
// Log dell'errore
|
||||||
|
file_put_contents($logDir . '/auth_error.log', date('Y-m-d H:i:s') . ' - ' . $e->getMessage() . PHP_EOL, FILE_APPEND);
|
||||||
|
http_response_code(500);
|
||||||
|
echo json_encode([
|
||||||
|
'success' => false,
|
||||||
|
'message' => 'Errore durante l\'autenticazione: ' . $e->getMessage()
|
||||||
|
]);
|
||||||
|
}
|
||||||
@@ -4,23 +4,13 @@ include('include/headscript.php');
|
|||||||
|
|
||||||
header('Content-Type: application/json');
|
header('Content-Type: application/json');
|
||||||
|
|
||||||
if ($_SERVER['REQUEST_METHOD'] !== 'POST' || !isset($_FILES['photo']) || (!isset($_POST['iddatadb']) && !isset($_POST['idquotations']))) {
|
if ($_SERVER['REQUEST_METHOD'] !== 'POST' || !isset($_FILES['photo']) || !isset($_POST['iddatadb'])) {
|
||||||
echo json_encode(['success' => false, 'message' => 'Richiesta non valida']);
|
echo json_encode(['success' => false, 'message' => 'Richiesta non valida']);
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
$iddatadb = isset($_POST['iddatadb']) ? intval($_POST['iddatadb']) : null;
|
$iddatadb = intval($_POST['iddatadb']);
|
||||||
$idquotations = isset($_POST['idquotations']) ? intval($_POST['idquotations']) : null;
|
$photo = $_FILES['photo'];
|
||||||
|
|
||||||
if ($iddatadb && $idquotations) {
|
|
||||||
echo json_encode(['success' => false, 'message' => 'Non è possibile specificare sia iddatadb che idquotations']);
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!$iddatadb && !$idquotations) {
|
|
||||||
echo json_encode(['success' => false, 'message' => 'ID TRF o ID quotations mancante']);
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Verifica che l'utente loggato esista in auth_users
|
// Verifica che l'utente loggato esista in auth_users
|
||||||
$db = DBHandlerSelect::getInstance();
|
$db = DBHandlerSelect::getInstance();
|
||||||
@@ -35,28 +25,6 @@ if (!$userExists) {
|
|||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Verifica l'esistenza dell'ID nella tabella corrispondente
|
|
||||||
try {
|
|
||||||
if ($iddatadb) {
|
|
||||||
$stmt = $pdo->prepare("SELECT iddatadb FROM datadb WHERE iddatadb = ?");
|
|
||||||
$stmt->execute([$iddatadb]);
|
|
||||||
if (!$stmt->fetch()) {
|
|
||||||
echo json_encode(['success' => false, 'message' => 'iddatadb non valido']);
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$stmt = $pdo->prepare("SELECT id FROM quotations WHERE id = ?");
|
|
||||||
$stmt->execute([$idquotations]);
|
|
||||||
if (!$stmt->fetch()) {
|
|
||||||
echo json_encode(['success' => false, 'message' => 'idquotations non valido']);
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (PDOException $e) {
|
|
||||||
echo json_encode(['success' => false, 'message' => 'Errore nella validazione: ' . $e->getMessage()]);
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Usa un percorso assoluto per la cartella photostrf
|
// Usa un percorso assoluto per la cartella photostrf
|
||||||
$uploadDir = realpath(__DIR__ . '/../photostrf') . '/';
|
$uploadDir = realpath(__DIR__ . '/../photostrf') . '/';
|
||||||
if (!is_dir($uploadDir)) {
|
if (!is_dir($uploadDir)) {
|
||||||
@@ -73,7 +41,6 @@ if (!is_writable($uploadDir)) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Verifica che il file sia un'immagine (inclusi HEIC/HEIF)
|
// Verifica che il file sia un'immagine (inclusi HEIC/HEIF)
|
||||||
$photo = $_FILES['photo'];
|
|
||||||
$allowedTypes = ['image/jpeg', 'image/png', 'image/gif', 'image/heic', 'image/heif'];
|
$allowedTypes = ['image/jpeg', 'image/png', 'image/gif', 'image/heic', 'image/heif'];
|
||||||
if (!in_array($photo['type'], $allowedTypes)) {
|
if (!in_array($photo['type'], $allowedTypes)) {
|
||||||
echo json_encode(['success' => false, 'message' => 'Il file deve essere un\'immagine (JPEG, PNG, GIF, HEIC)']);
|
echo json_encode(['success' => false, 'message' => 'Il file deve essere un\'immagine (JPEG, PNG, GIF, HEIC)']);
|
||||||
@@ -86,11 +53,10 @@ if (!file_exists($photo['tmp_name']) || !is_uploaded_file($photo['tmp_name'])) {
|
|||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Rinomina il file: id-timestamp-nomeoriginale.estensione
|
// Rinomina il file: idriga-timestamp-nomeoriginale.estensione
|
||||||
$timestamp = date('YmdHis');
|
$timestamp = date('YmdHis');
|
||||||
$originalName = pathinfo($photo['name'], PATHINFO_FILENAME);
|
$originalName = pathinfo($photo['name'], PATHINFO_FILENAME);
|
||||||
$extension = strtolower(pathinfo($photo['name'], PATHINFO_EXTENSION));
|
$extension = strtolower(pathinfo($photo['name'], PATHINFO_EXTENSION));
|
||||||
$id = $iddatadb ?: $idquotations;
|
|
||||||
|
|
||||||
// Se il file è HEIC/HEIF, convertilo in JPEG
|
// Se il file è HEIC/HEIF, convertilo in JPEG
|
||||||
if (in_array($photo['type'], ['image/heic', 'image/heif'])) {
|
if (in_array($photo['type'], ['image/heic', 'image/heif'])) {
|
||||||
@@ -108,11 +74,11 @@ if (in_array($photo['type'], ['image/heic', 'image/heif'])) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Crea un nuovo nome per il file JPEG
|
// Crea un nuovo nome per il file JPEG
|
||||||
$newFileName = "{$id}-{$timestamp}-{$originalName}.jpg";
|
$newFileName = "{$iddatadb}-{$timestamp}-{$originalName}.jpg";
|
||||||
$destination = $uploadDir . $newFileName;
|
$destination = $uploadDir . $newFileName;
|
||||||
|
|
||||||
// Salva l'immagine come JPEG
|
// Salva l'immagine come JPEG
|
||||||
if (!imagejpeg($image, $destination, 90)) {
|
if (!imagejpeg($image, $destination, 90)) { // 90 è la qualità JPEG
|
||||||
imagedestroy($image);
|
imagedestroy($image);
|
||||||
echo json_encode(['success' => false, 'message' => 'Errore durante la conversione del file HEIC in JPEG']);
|
echo json_encode(['success' => false, 'message' => 'Errore durante la conversione del file HEIC in JPEG']);
|
||||||
exit;
|
exit;
|
||||||
@@ -122,7 +88,7 @@ if (in_array($photo['type'], ['image/heic', 'image/heif'])) {
|
|||||||
imagedestroy($image);
|
imagedestroy($image);
|
||||||
} else {
|
} else {
|
||||||
// Per i formati non HEIC, usa il nome e l'estensione originali
|
// Per i formati non HEIC, usa il nome e l'estensione originali
|
||||||
$newFileName = "{$id}-{$timestamp}-{$originalName}.{$extension}";
|
$newFileName = "{$iddatadb}-{$timestamp}-{$originalName}.{$extension}";
|
||||||
$destination = $uploadDir . $newFileName;
|
$destination = $uploadDir . $newFileName;
|
||||||
|
|
||||||
// Salva il file
|
// Salva il file
|
||||||
@@ -139,12 +105,7 @@ error_log("Destination: $destination");
|
|||||||
error_log("Temp file: " . $photo['tmp_name']);
|
error_log("Temp file: " . $photo['tmp_name']);
|
||||||
|
|
||||||
// Salva il riferimento nel database
|
// Salva il riferimento nel database
|
||||||
try {
|
$stmt = $pdo->prepare("INSERT INTO datadb_photos (iddatadb, file_path, file_name, uploaded_by) VALUES (?, ?, ?, ?)");
|
||||||
$stmt = $pdo->prepare("INSERT INTO datadb_photos (iddatadb, idquotations, file_path, file_name, uploaded_by) VALUES (?, ?, ?, ?, ?)");
|
$stmt->execute([$iddatadb, $newFileName, $newFileName, $iduserlogin]);
|
||||||
$stmt->execute([$iddatadb, $idquotations, $newFileName, $newFileName, $iduserlogin]);
|
|
||||||
} catch (PDOException $e) {
|
|
||||||
echo json_encode(['success' => false, 'message' => 'Errore durante il salvataggio nel database: ' . $e->getMessage()]);
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
echo json_encode(['success' => true, 'message' => 'Foto caricata con successo']);
|
echo json_encode(['success' => true, 'message' => 'Foto caricata con successo']);
|
||||||
|
|||||||
@@ -5,41 +5,24 @@ include('include/headscript.php');
|
|||||||
$db = DBHandlerSelect::getInstance();
|
$db = DBHandlerSelect::getInstance();
|
||||||
$pdo = $db->getConnection();
|
$pdo = $db->getConnection();
|
||||||
|
|
||||||
// Verifica che almeno uno degli ID sia passato
|
// Verifica che l'iddatadb sia stato passato
|
||||||
$iddatadb = isset($_GET['iddatadb']) && !empty($_GET['iddatadb']) ? intval($_GET['iddatadb']) : null;
|
if (!isset($_GET['iddatadb']) || empty($_GET['iddatadb'])) {
|
||||||
$idquotations = isset($_GET['idquotations']) && !empty($_GET['idquotations']) ? intval($_GET['idquotations']) : null;
|
die('ID riga non fornito');
|
||||||
|
|
||||||
if (!$iddatadb && !$idquotations) {
|
|
||||||
die('ID riga o ID quotations non fornito');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($iddatadb && $idquotations) {
|
$iddatadb = intval($_GET['iddatadb']);
|
||||||
die('Non è possibile specificare sia iddatadb che idquotations');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Verifica che l'utente loggato esista
|
// Recupera i dettagli della riga (idriga e sample_code)
|
||||||
$stmt = $pdo->prepare("SELECT id FROM auth_users WHERE id = ?");
|
$stmt = $pdo->prepare("SELECT iddatadb, sample_code FROM datadb WHERE iddatadb = ?");
|
||||||
$stmt->execute([$iduserlogin]);
|
$stmt->execute([$iddatadb]);
|
||||||
if (!$stmt->fetch(PDO::FETCH_ASSOC)) {
|
|
||||||
die('Utente non valido');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Determina quale ID usare e verifica l'esistenza
|
|
||||||
$paramName = $iddatadb ? 'iddatadb' : 'idquotations';
|
|
||||||
$paramValue = $iddatadb ?: $idquotations;
|
|
||||||
$table = $iddatadb ? 'datadb' : 'quotations';
|
|
||||||
$field = $iddatadb ? 'sample_code' : 'quotation_code';
|
|
||||||
|
|
||||||
$stmt = $pdo->prepare("SELECT {$paramName}, {$field} FROM {$table} WHERE {$paramName} = ?");
|
|
||||||
$stmt->execute([$paramValue]);
|
|
||||||
$row = $stmt->fetch(PDO::FETCH_ASSOC);
|
$row = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||||
|
|
||||||
if (!$row) {
|
if (!$row) {
|
||||||
die('Riga non trovata');
|
die('Riga non trovata');
|
||||||
}
|
}
|
||||||
|
|
||||||
$id = $row[$paramName];
|
$idriga = $row['iddatadb'];
|
||||||
$code = $row[$field] ?? 'Non disponibile';
|
$sampleCode = $row['sample_code'] ?? 'Non disponibile';
|
||||||
?>
|
?>
|
||||||
|
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
@@ -49,23 +32,17 @@ $code = $row[$field] ?? 'Non disponibile';
|
|||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<title>Carica Foto da Mobile</title>
|
<title>Carica Foto da Mobile</title>
|
||||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
|
|
||||||
<style>
|
<style>
|
||||||
body {
|
body {
|
||||||
font-family: Arial, sans-serif;
|
font-family: Arial, sans-serif;
|
||||||
padding: 20px;
|
padding: 20px;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
background: #f4f4f4;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.upload-area {
|
.upload-area {
|
||||||
border: 2px dashed #ccc;
|
border: 2px dashed #ccc;
|
||||||
padding: 20px;
|
padding: 20px;
|
||||||
margin: 20px auto;
|
margin: 20px 0;
|
||||||
max-width: 500px;
|
|
||||||
background: white;
|
|
||||||
border-radius: 8px;
|
|
||||||
cursor: pointer;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.upload-area.highlight {
|
.upload-area.highlight {
|
||||||
@@ -79,121 +56,57 @@ $code = $row[$field] ?? 'Non disponibile';
|
|||||||
margin-bottom: 10px;
|
margin-bottom: 10px;
|
||||||
border-bottom: 1px solid #eee;
|
border-bottom: 1px solid #eee;
|
||||||
padding-bottom: 10px;
|
padding-bottom: 10px;
|
||||||
max-width: 500px;
|
|
||||||
margin-left: auto;
|
|
||||||
margin-right: auto;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.photo-item img {
|
.photo-item img {
|
||||||
max-width: 100px;
|
max-width: 100px;
|
||||||
max-height: 100px;
|
max-height: 100px;
|
||||||
margin-right: 10px;
|
margin-right: 10px;
|
||||||
border-radius: 4px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.loader {
|
|
||||||
display: none;
|
|
||||||
position: fixed;
|
|
||||||
top: 0;
|
|
||||||
left: 0;
|
|
||||||
width: 100%;
|
|
||||||
height: 100%;
|
|
||||||
background: rgba(0, 0, 0, 0.5);
|
|
||||||
z-index: 1000;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
justify-content: center;
|
|
||||||
color: white;
|
|
||||||
}
|
|
||||||
|
|
||||||
.loader i {
|
|
||||||
font-size: 40px;
|
|
||||||
margin-bottom: 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.error-message {
|
|
||||||
color: red;
|
|
||||||
margin: 10px 0;
|
|
||||||
display: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
button.delete-photo-btn {
|
|
||||||
background: none;
|
|
||||||
border: none;
|
|
||||||
color: #dc3545;
|
|
||||||
cursor: pointer;
|
|
||||||
font-size: 18px;
|
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
<h2>Carica Foto per ID: <?= htmlspecialchars($id) ?></h2>
|
<h2>Carica Foto per ID Riga: <?= htmlspecialchars($idriga) ?></h2>
|
||||||
<p><strong>Codice:</strong> <?= htmlspecialchars($code) ?></p>
|
<p><strong>Sample Code:</strong> <?= htmlspecialchars($sampleCode) ?></p>
|
||||||
<div class="loader" id="loader">
|
|
||||||
<div>
|
|
||||||
<i class="fas fa-spinner fa-spin"></i>
|
|
||||||
<p>Caricamento in corso...</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="error-message" id="errorMessage"></div>
|
|
||||||
<div class="upload-area" id="uploadArea">
|
<div class="upload-area" id="uploadArea">
|
||||||
<p>Scatta una foto o seleziona immagini</p>
|
<p>Scatta una foto o seleziona un'immagine</p>
|
||||||
<input type="file" id="photoInput" accept="image/*" capture="camera" multiple style="display: none;">
|
<input type="file" id="photoInput" accept="image/*" capture="camera">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="photosList">
|
||||||
|
<!-- Le foto verranno caricate dinamicamente -->
|
||||||
</div>
|
</div>
|
||||||
<div id="photosList"></div>
|
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
const uploadArea = document.getElementById('uploadArea');
|
const uploadArea = document.getElementById('uploadArea');
|
||||||
const photoInput = document.getElementById('photoInput');
|
const photoInput = document.getElementById('photoInput');
|
||||||
const photosList = document.getElementById('photosList');
|
const photosList = document.getElementById('photosList');
|
||||||
const loader = document.getElementById('loader');
|
|
||||||
const errorMessage = document.getElementById('errorMessage');
|
|
||||||
const iddatadb = '<?= $iddatadb ?>';
|
|
||||||
const idquotations = '<?= $idquotations ?>';
|
|
||||||
const endpoint = idquotations ? 'load_photo_quotation.php' : 'load_photo.php';
|
|
||||||
const dataParam = idquotations ? {
|
|
||||||
idquotations: idquotations
|
|
||||||
} : {
|
|
||||||
iddatadb: iddatadb
|
|
||||||
};
|
|
||||||
|
|
||||||
// Carica le foto esistenti all'avvio
|
// Carica le foto esistenti all'avvio
|
||||||
loadPhotos();
|
loadPhotos();
|
||||||
|
|
||||||
// Gestione drag-and-drop
|
// Gestione del click sull'area di upload
|
||||||
uploadArea.addEventListener('dragover', (e) => {
|
uploadArea.addEventListener('click', () => {
|
||||||
e.preventDefault();
|
photoInput.click();
|
||||||
uploadArea.classList.add('highlight');
|
|
||||||
});
|
|
||||||
uploadArea.addEventListener('dragleave', () => {
|
|
||||||
uploadArea.classList.remove('highlight');
|
|
||||||
});
|
|
||||||
uploadArea.addEventListener('drop', (e) => {
|
|
||||||
e.preventDefault();
|
|
||||||
uploadArea.classList.remove('highlight');
|
|
||||||
handleFiles(e.dataTransfer.files);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Gestione click sull'area di upload
|
// Gestione del caricamento delle foto
|
||||||
uploadArea.addEventListener('click', () => photoInput.click());
|
photoInput.addEventListener('change', () => {
|
||||||
|
handleFiles(photoInput.files);
|
||||||
// Gestione caricamento foto
|
});
|
||||||
photoInput.addEventListener('change', () => handleFiles(photoInput.files));
|
|
||||||
|
|
||||||
async function handleFiles(files) {
|
async function handleFiles(files) {
|
||||||
loader.style.display = 'flex';
|
|
||||||
errorMessage.style.display = 'none';
|
|
||||||
for (const file of files) {
|
for (const file of files) {
|
||||||
if (!file.type.startsWith('image/')) {
|
if (!file.type.startsWith('image/')) {
|
||||||
showError('Per favore, carica solo immagini!');
|
alert('Per favore, carica solo immagini!');
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
formData.append('photo', file);
|
formData.append('photo', file);
|
||||||
if (iddatadb) formData.append('iddatadb', iddatadb);
|
formData.append('iddatadb', '<?= $iddatadb ?>');
|
||||||
if (idquotations) formData.append('idquotations', idquotations);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch('upload_photo.php', {
|
const response = await fetch('upload_photo.php', {
|
||||||
@@ -201,86 +114,32 @@ $code = $row[$field] ?? 'Non disponibile';
|
|||||||
body: formData
|
body: formData
|
||||||
});
|
});
|
||||||
const result = await response.json();
|
const result = await response.json();
|
||||||
if (!result.success) {
|
|
||||||
showError('Errore durante il caricamento: ' + result.message);
|
if (result.success) {
|
||||||
|
loadPhotos(); // Ricarica le foto
|
||||||
|
} else {
|
||||||
|
alert('Errore durante il caricamento: ' + result.message);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
showError('Errore di rete: ' + error.message);
|
alert('Errore durante il caricamento: ' + error.message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
loadPhotos();
|
|
||||||
loader.style.display = 'none';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Funzione per caricare le foto esistenti
|
||||||
async function loadPhotos() {
|
async function loadPhotos() {
|
||||||
loader.style.display = 'flex';
|
|
||||||
errorMessage.style.display = 'none';
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch(`${endpoint}?${new URLSearchParams(dataParam)}`);
|
const response = await fetch(`photos_popup.php?iddatadb=<?= $iddatadb ?>`);
|
||||||
const result = await response.json();
|
const html = await response.text();
|
||||||
photosList.innerHTML = '';
|
const parser = new DOMParser();
|
||||||
if (result.success && result.photos && result.photos.length > 0) {
|
const doc = parser.parseFromString(html, 'text/html');
|
||||||
for (const photo of result.photos) {
|
const photosListContent = doc.querySelector('#photosList').innerHTML;
|
||||||
const photoName = photo.split('/').pop();
|
photosList.innerHTML = photosListContent;
|
||||||
const photoItem = document.createElement('div');
|
|
||||||
photoItem.className = 'photo-item';
|
|
||||||
photoItem.innerHTML = `
|
|
||||||
<img src="${photo}" alt="${photoName}">
|
|
||||||
<div style="flex: 1; text-align: left;">
|
|
||||||
<strong>Nome:</strong> ${photoName}<br>
|
|
||||||
<strong>Caricata il:</strong> Non disponibile
|
|
||||||
</div>
|
|
||||||
<button class="delete-photo-btn" data-photo-path="${photo}">
|
|
||||||
<i class="fas fa-trash"></i>
|
|
||||||
</button>`;
|
|
||||||
photosList.appendChild(photoItem);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
photosList.innerHTML = '<p>Nessuna foto presente.</p>';
|
|
||||||
}
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
showError('Errore durante il caricamento delle foto: ' + error.message);
|
photosList.innerHTML = `<p>Errore durante il caricamento delle foto: ${error.message}</p>`;
|
||||||
}
|
}
|
||||||
loader.style.display = 'none';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function showError(message) {
|
|
||||||
errorMessage.textContent = message;
|
|
||||||
errorMessage.style.display = 'block';
|
|
||||||
setTimeout(() => errorMessage.style.display = 'none', 5000);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Gestione eliminazione foto
|
|
||||||
photosList.addEventListener('click', async (e) => {
|
|
||||||
if (e.target.closest('.delete-photo-btn')) {
|
|
||||||
const button = e.target.closest('.delete-photo-btn');
|
|
||||||
const photoPath = button.dataset.photoPath;
|
|
||||||
if (confirm('Sei sicuro di voler eliminare questa foto?')) {
|
|
||||||
loader.style.display = 'flex';
|
|
||||||
try {
|
|
||||||
const response = await fetch('delete_photo.php', {
|
|
||||||
method: 'POST',
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/json'
|
|
||||||
},
|
|
||||||
body: JSON.stringify({
|
|
||||||
file_path: photoPath
|
|
||||||
})
|
|
||||||
});
|
|
||||||
const result = await response.json();
|
|
||||||
if (result.success) {
|
|
||||||
loadPhotos();
|
|
||||||
} else {
|
|
||||||
showError('Errore durante l\'eliminazione: ' + result.message);
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
showError('Errore durante l\'eliminazione: ' + error.message);
|
|
||||||
}
|
|
||||||
loader.style.display = 'none';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
Reference in New Issue
Block a user