Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 6a652af086 | |||
| 1303cff9fd | |||
| 6b2bd0964b | |||
| 0d2cf13524 | |||
| f6ef9c39d2 | |||
| 7e4ed56f28 | |||
| 06dd7883c2 | |||
| 22e4e652b5 | |||
| d8eca66747 |
@@ -0,0 +1,36 @@
|
||||
* Trying 93.43.5.102:443...
|
||||
* Connected to 93.43.5.102 (93.43.5.102) port 443
|
||||
* ALPN: curl offers h2,http/1.1
|
||||
* SSL connection using TLSv1.2 / ECDHE-RSA-AES256-GCM-SHA384
|
||||
* ALPN: server accepted h2
|
||||
* Server certificate:
|
||||
* subject: C=FR; ST=Île-de-France; O=Bureau Veritas; CN=bvcpsitaly-elims.it
|
||||
* start date: Feb 17 00:00:00 2025 GMT
|
||||
* expire date: Feb 17 23:59:59 2026 GMT
|
||||
* issuer: C=US; O=Corporation Service Company; CN=Corporation Service Company RSA OV SSL CA
|
||||
* SSL certificate verify result: unable to get local issuer certificate (20), continuing anyway.
|
||||
* using HTTP/2
|
||||
* [HTTP/2] [1] OPENED stream for https://93.43.5.102/limsapi/api/authentication/authenticate
|
||||
* [HTTP/2] [1] [:method: POST]
|
||||
* [HTTP/2] [1] [:scheme: https]
|
||||
* [HTTP/2] [1] [:authority: 93.43.5.102]
|
||||
* [HTTP/2] [1] [:path: /limsapi/api/authentication/authenticate]
|
||||
* [HTTP/2] [1] [content-type: application/json]
|
||||
* [HTTP/2] [1] [accept: application/json]
|
||||
* [HTTP/2] [1] [content-length: 51]
|
||||
> POST /limsapi/api/authentication/authenticate HTTP/2
|
||||
Host: 93.43.5.102
|
||||
Content-Type: application/json
|
||||
Accept: application/json
|
||||
Content-Length: 51
|
||||
|
||||
< HTTP/2 200
|
||||
< cache-control: max-age=0
|
||||
< content-type: application/json; charset=utf-8
|
||||
< server: Microsoft-IIS/10.0
|
||||
< strict-transport-security: max-age=2592000
|
||||
< x-powered-by: ASP.NET
|
||||
< x-content-type-options: nosniff
|
||||
< date: Fri, 29 Aug 2025 14:28:29 GMT
|
||||
<
|
||||
* Connection #0 to host 93.43.5.102 left intact
|
||||
@@ -0,0 +1,35 @@
|
||||
* Trying 93.43.5.102:443...
|
||||
* Connected to 93.43.5.102 (93.43.5.102) port 443
|
||||
* ALPN: curl offers h2,http/1.1
|
||||
* SSL connection using TLSv1.2 / ECDHE-RSA-AES256-GCM-SHA384
|
||||
* ALPN: server accepted h2
|
||||
* Server certificate:
|
||||
* subject: C=FR; ST=Île-de-France; O=Bureau Veritas; CN=bvcpsitaly-elims.it
|
||||
* start date: Feb 17 00:00:00 2025 GMT
|
||||
* expire date: Feb 17 23:59:59 2026 GMT
|
||||
* issuer: C=US; O=Corporation Service Company; CN=Corporation Service Company RSA OV SSL CA
|
||||
* SSL certificate verify result: unable to get local issuer certificate (20), continuing anyway.
|
||||
* using HTTP/2
|
||||
* [HTTP/2] [1] OPENED stream for https://93.43.5.102/limsapi/api/odata/CustomField(1083)?$expand=CustomFieldsValues
|
||||
* [HTTP/2] [1] [:method: GET]
|
||||
* [HTTP/2] [1] [:scheme: https]
|
||||
* [HTTP/2] [1] [:authority: 93.43.5.102]
|
||||
* [HTTP/2] [1] [:path: /limsapi/api/odata/CustomField(1083)?$expand=CustomFieldsValues]
|
||||
* [HTTP/2] [1] [authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJodHRwOi8vc2NoZW1hcy54bWxzb2FwLm9yZy93cy8yMDA1LzA1L2lkZW50aXR5L2NsYWltcy9uYW1laWRlbnRpZmllciI6IjQ5MiIsIlhhZlNlY3VyaXR5QXV0aFBhc3NlZCI6IlhhZlNlY3VyaXR5QXV0aFBhc3NlZCIsImh0dHA6Ly9zY2hlbWFzLnhtbHNvYXAub3JnL3dzLzIwMDUvMDUvaWRlbnRpdHkvY2xhaW1zL25hbWUiOiJXZWJBcGlVc2VyIiwiWGFmU2VjdXJpdHkiOiJYYWZTZWN1cml0eSIsIlhhZkxvZ29uUGFyYW1zIjoicTFZS0xVNHQ4a3ZNVFZXeVVncFBUWElzeUFRSktPa29CU1FXRjVmbkY2VUF4Y3RUa3hJTE1rdUI0Z2FHU3JVQSIsImV4cCI6MTc1NjQ4NDkwOSwiaXNzIjoiTXkiLCJhdWQiOiJodHRwOi8vbG9jYWxob3N0OjQyMDAifQ.VPLdAAvg-D2ReaPr7erRrgX70RQsySvuBXN284HFQ74]
|
||||
* [HTTP/2] [1] [accept: application/json]
|
||||
> GET /limsapi/api/odata/CustomField(1083)?$expand=CustomFieldsValues HTTP/2
|
||||
Host: 93.43.5.102
|
||||
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJodHRwOi8vc2NoZW1hcy54bWxzb2FwLm9yZy93cy8yMDA1LzA1L2lkZW50aXR5L2NsYWltcy9uYW1laWRlbnRpZmllciI6IjQ5MiIsIlhhZlNlY3VyaXR5QXV0aFBhc3NlZCI6IlhhZlNlY3VyaXR5QXV0aFBhc3NlZCIsImh0dHA6Ly9zY2hlbWFzLnhtbHNvYXAub3JnL3dzLzIwMDUvMDUvaWRlbnRpdHkvY2xhaW1zL25hbWUiOiJXZWJBcGlVc2VyIiwiWGFmU2VjdXJpdHkiOiJYYWZTZWN1cml0eSIsIlhhZkxvZ29uUGFyYW1zIjoicTFZS0xVNHQ4a3ZNVFZXeVVncFBUWElzeUFRSktPa29CU1FXRjVmbkY2VUF4Y3RUa3hJTE1rdUI0Z2FHU3JVQSIsImV4cCI6MTc1NjQ4NDkwOSwiaXNzIjoiTXkiLCJhdWQiOiJodHRwOi8vbG9jYWxob3N0OjQyMDAifQ.VPLdAAvg-D2ReaPr7erRrgX70RQsySvuBXN284HFQ74
|
||||
Accept: application/json
|
||||
|
||||
< HTTP/2 200
|
||||
< cache-control: max-age=0
|
||||
< content-type: application/json; odata.metadata=minimal; odata.streaming=true; charset=utf-8
|
||||
< server: Microsoft-IIS/10.0
|
||||
< strict-transport-security: max-age=2592000
|
||||
< odata-version: 4.0
|
||||
< x-powered-by: ASP.NET
|
||||
< x-content-type-options: nosniff
|
||||
< date: Fri, 29 Aug 2025 14:28:33 GMT
|
||||
<
|
||||
* Connection #0 to host 93.43.5.102 left intact
|
||||
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
// Enable errors for debugging
|
||||
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__ . '/delete_record_debug.log');
|
||||
|
||||
// Log iniziale
|
||||
error_log("Inizio cancellazione record alle " . date('Y-m-d H:i:s'));
|
||||
|
||||
// Includi il file di configurazione del database
|
||||
include('include/headscript.php');
|
||||
|
||||
// Ricevi l'ID dalla richiesta POST
|
||||
$input = json_decode(file_get_contents('php://input'), true);
|
||||
$iddatadb = isset($input['id']) ? intval($input['id']) : 0;
|
||||
|
||||
if ($iddatadb <= 0) {
|
||||
http_response_code(400);
|
||||
echo json_encode(['success' => false, 'message' => 'ID non valido']);
|
||||
exit;
|
||||
}
|
||||
|
||||
// Connessione al database
|
||||
try {
|
||||
$db = DBHandlerSelect::getInstance();
|
||||
$pdo = $db->getConnection();
|
||||
} catch (Exception $e) {
|
||||
http_response_code(500);
|
||||
echo json_encode(['success' => false, 'message' => 'Errore di connessione al database: ' . $e->getMessage()]);
|
||||
error_log("Errore di connessione al database: " . $e->getMessage());
|
||||
exit;
|
||||
}
|
||||
|
||||
// Inizia una transazione
|
||||
$pdo->beginTransaction();
|
||||
|
||||
try {
|
||||
// Elimina i dettagli associati dal tavolo import_data_details
|
||||
$stmt = $pdo->prepare("DELETE FROM import_data_details WHERE id = ?");
|
||||
$stmt->execute([$iddatadb]);
|
||||
|
||||
// Elimina il record principale dal tavolo datadb
|
||||
$stmt = $pdo->prepare("DELETE FROM datadb WHERE iddatadb = ?");
|
||||
$stmt->execute([$iddatadb]);
|
||||
|
||||
// Verifica se il record è stato eliminato
|
||||
if ($stmt->rowCount() > 0) {
|
||||
$pdo->commit();
|
||||
echo json_encode(['success' => true, 'message' => 'Record eliminato con successo']);
|
||||
error_log("Record con iddatadb=$iddatadb eliminato con successo");
|
||||
} else {
|
||||
$pdo->rollBack();
|
||||
http_response_code(404);
|
||||
echo json_encode(['success' => false, 'message' => 'Record non trovato']);
|
||||
error_log("Record con iddatadb=$iddatadb non trovato");
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
$pdo->rollBack();
|
||||
http_response_code(500);
|
||||
echo json_encode(['success' => false, 'message' => 'Errore durante la cancellazione: ' . $e->getMessage()]);
|
||||
error_log("Errore durante la cancellazione del record con iddatadb=$iddatadb: " . $e->getMessage());
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
@@ -383,9 +383,14 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
|
||||
border: none;
|
||||
border-radius: 5px;
|
||||
cursor: pointer;
|
||||
width: 50px;
|
||||
width: 35px;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.flash-success {
|
||||
background-color: #d4edda !important;
|
||||
transition: background-color 0.3s ease;
|
||||
}
|
||||
</style>
|
||||
<title>Edit Imported Data - <?= htmlspecialchars($titlewebsite, ENT_QUOTES, 'UTF-8'); ?></title>
|
||||
</head>
|
||||
@@ -428,7 +433,7 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
|
||||
$inputClass = $mainFieldMapping['is_manual'] ? 'manual-input' : 'auto-input';
|
||||
if ($mainFieldMapping['is_required']) $inputClass .= ' required-input';
|
||||
if ($mainFieldMapping['data_type'] === 'SceltaMultipla') {
|
||||
echo "<select class='custom-field dropdown-select $inputClass' data-column='main_field' data-field-id='{$mainFieldMapping['field_id']}' " . ($mainFieldMapping['is_required'] ? 'required' : '') . ">";
|
||||
echo "<select class='custom-field dropdown-select $inputClass' data-column='main_field' data-field-id='{$mainFieldMapping['field_id']}' data-selected-value='" . htmlspecialchars($fieldValue) . "' " . ($mainFieldMapping['is_required'] ? 'required' : '') . ">";
|
||||
echo "<option value=''>Seleziona...</option>";
|
||||
echo "</select>";
|
||||
echo "<button type='button' class='propagate-btn' data-column='main_field'><i class='fas fa-arrow-down'></i></button>";
|
||||
@@ -455,7 +460,7 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
|
||||
if ($mapping['is_required']) $inputClass .= ' required-input';
|
||||
if ($mapping['data_type'] === 'SceltaMultipla') {
|
||||
echo "<div class='grid-cell' style='flex: 0 0 150px;'>";
|
||||
echo "<select class='custom-field dropdown-select $inputClass' data-column='auto_$autoIndex' data-field-id='{$mapping['field_id']}' " . ($mapping['is_required'] ? 'required' : '') . ">";
|
||||
echo "<select class='custom-field dropdown-select $inputClass' data-column='auto_$autoIndex' data-field-id='{$mapping['field_id']}' data-selected-value='" . htmlspecialchars($fieldValue) . "' " . ($mapping['is_required'] ? 'required' : '') . ">";
|
||||
echo "<option value=''>Seleziona...</option>";
|
||||
echo "</select>";
|
||||
echo "<button type='button' class='propagate-btn' data-column='auto_$autoIndex'><i class='fas fa-arrow-down'></i></button>";
|
||||
@@ -478,7 +483,7 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
|
||||
if ($mapping['is_required']) $inputClass .= ' required-input';
|
||||
echo "<div class='grid-cell' style='flex: 0 0 150px;'>";
|
||||
if ($mapping['data_type'] === 'SceltaMultipla') {
|
||||
echo "<select class='custom-field dropdown-select $inputClass' data-column='manual_$manualIndex' data-field-id='{$mapping['field_id']}' " . ($mapping['is_required'] ? 'required' : '') . ">";
|
||||
echo "<select class='custom-field dropdown-select $inputClass' data-column='manual_$manualIndex' data-field-id='{$mapping['field_id']}' data-selected-value='" . htmlspecialchars($fieldValue) . "' " . ($mapping['is_required'] ? 'required' : '') . ">";
|
||||
echo "<option value=''>Seleziona...</option>";
|
||||
echo "</select>";
|
||||
} elseif ($mapping['data_type'] === 'DATE') {
|
||||
@@ -542,6 +547,7 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
|
||||
<?php foreach ($importedData as $index => $row): ?>
|
||||
<div class="grid-row" data-id="<?= $row['iddatadb'] ?>">
|
||||
<div class="grid-cell button-cell" style="flex: 0 0 210px; position: relative;">
|
||||
<button type="button" class="export-lims-btn action-btn" data-row="<?= $index ?>" data-iddatadb="<?= $row['iddatadb'] ?>" title="Export to LIMS" style="background: #eb0b0bff; color: white; border: none; border-radius: 5px; cursor: pointer;"><i class="fas fa-upload"></i></button>
|
||||
<button type="button" class="save-btn action-btn" data-row="<?= $index ?>" title="Save" style="background: #28a745; color: white; border: none; border-radius: 5px; cursor: pointer;"><i class="fas fa-save"></i></button>
|
||||
<button type="button" class="photos-btn action-btn" data-row="<?= $index ?>" data-iddatadb="<?= $row['iddatadb'] ?>" title="Photos" style="background: #007bff; color: white; border: none; border-radius: 5px; cursor: pointer;"><i class="fas fa-camera"></i></button>
|
||||
<button type="button" class="parts-btn action-btn" data-row="<?= $index ?>" data-iddatadb="<?= $row['iddatadb'] ?>" title="Parts" style="background: #ffc107; color: white; border: none; border-radius: 5px; cursor: pointer;"><i class="fas fa-puzzle-piece"></i></button>
|
||||
@@ -560,7 +566,7 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
|
||||
?>
|
||||
<div class="grid-cell editable-cell <?= $requiredClass ?>" data-col="main_field" data-row="<?= $index ?>" data-index="1" style="flex: 0 0 150px;">
|
||||
<?php if ($mainFieldMapping['data_type'] === 'SceltaMultipla'): ?>
|
||||
<select name="rows[<?= $index ?>][details][<?= $mainFieldMapping['id'] ?>][field_value]" class="cell-input dropdown-select <?= $inputClass ?>" data-mapping-id="<?= $mainFieldMapping['id'] ?>" data-field-id="<?= $mainFieldMapping['field_id'] ?>" <?= $mainFieldMapping['is_required'] ? 'required' : '' ?>>
|
||||
<select name="rows[<?= $index ?>][details][<?= $mainFieldMapping['id'] ?>][field_value]" class="cell-input dropdown-select <?= $inputClass ?>" data-mapping-id="<?= $mainFieldMapping['id'] ?>" data-field-id="<?= $mainFieldMapping['field_id'] ?>" data-selected-value="<?= htmlspecialchars($fieldValue) ?>" <?= $mainFieldMapping['is_required'] ? 'required' : '' ?>>
|
||||
<option value="">Seleziona...</option>
|
||||
</select>
|
||||
<?php elseif ($mainFieldMapping['data_type'] === 'DATE'): ?>
|
||||
@@ -592,7 +598,7 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
|
||||
if ($mapping['is_required']) $inputClass .= ' required-input';
|
||||
echo "<div class='grid-cell editable-cell $requiredClass' data-col='auto_$autoIndex' data-row='$index' data-index='$cellIndex' style='flex: 0 0 150px;'>";
|
||||
if ($mapping['data_type'] === 'SceltaMultipla') {
|
||||
echo "<select name='rows[$index][details][{$mapping['id']}][field_value]' class='cell-input dropdown-select $inputClass' data-mapping-id='{$mapping['id']}' data-field-id='{$mapping['field_id']}' " . ($mapping['is_required'] ? 'required' : '') . ">";
|
||||
echo "<select name='rows[$index][details][{$mapping['id']}][field_value]' class='cell-input dropdown-select $inputClass' data-mapping-id='{$mapping['id']}' data-field-id='{$mapping['field_id']}' data-selected-value='" . htmlspecialchars($fieldValue) . "' " . ($mapping['is_required'] ? 'required' : '') . ">";
|
||||
echo "<option value=''>Seleziona...</option>";
|
||||
echo "</select>";
|
||||
} elseif ($mapping['data_type'] === 'DATE') {
|
||||
@@ -621,7 +627,7 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
|
||||
if ($mapping['is_required']) $inputClass .= ' required-input';
|
||||
echo "<div class='grid-cell editable-cell $requiredClass' data-col='manual_$manualIndex' data-row='$index' data-index='$cellIndex' style='flex: 0 0 150px;'>";
|
||||
if ($mapping['data_type'] === 'SceltaMultipla') {
|
||||
echo "<select name='rows[$index][details][{$mapping['id']}][field_value]' class='cell-input dropdown-select $inputClass' data-mapping-id='{$mapping['id']}' data-field-id='{$mapping['field_id']}' " . ($mapping['is_required'] ? 'required' : '') . ">";
|
||||
echo "<select name='rows[$index][details][{$mapping['id']}][field_value]' class='cell-input dropdown-select $inputClass' data-mapping-id='{$mapping['id']}' data-field-id='{$mapping['field_id']}' data-selected-value='" . htmlspecialchars($fieldValue) . "' " . ($mapping['is_required'] ? 'required' : '') . ">";
|
||||
echo "<option value=''>Seleziona...</option>";
|
||||
echo "</select>";
|
||||
} elseif ($mapping['data_type'] === 'DATE') {
|
||||
@@ -718,35 +724,6 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
|
||||
});
|
||||
</script>
|
||||
|
||||
<script>
|
||||
document.addEventListener("DOMContentLoaded", function() {
|
||||
const inputs = document.querySelectorAll('.cell-input');
|
||||
inputs.forEach(input => {
|
||||
input.addEventListener('focus', function() {
|
||||
this.closest('.grid-cell').classList.add('expanded');
|
||||
});
|
||||
input.addEventListener('blur', function() {
|
||||
this.closest('.grid-cell').classList.remove('expanded');
|
||||
});
|
||||
});
|
||||
|
||||
const saveButtons = document.querySelectorAll('.save-btn');
|
||||
saveButtons.forEach(button => {
|
||||
btn.addEventListener('click', function() {
|
||||
hasChanges = false;
|
||||
unsavedDiv.style.display = "none";
|
||||
});
|
||||
});
|
||||
|
||||
window.addEventListener("beforeunload", function(e) {
|
||||
if (hasChanges) {
|
||||
e.preventDefault();
|
||||
e.returnValue = "";
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
<script>
|
||||
document.addEventListener("DOMContentLoaded", function() {
|
||||
const inputs = document.querySelectorAll('.cell-input');
|
||||
@@ -817,9 +794,11 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
|
||||
if (cells.length > targetTopIndex) {
|
||||
const targetInput = cells[targetTopIndex].querySelector('input, select');
|
||||
if (targetInput) {
|
||||
if (targetInput.type === 'date') targetInput.value = value;
|
||||
else if (targetInput.tagName === 'SELECT') targetInput.value = value;
|
||||
else targetInput.value = value;
|
||||
targetInput.value = value;
|
||||
if (targetInput.tagName === 'SELECT') {
|
||||
const event = new Event('change');
|
||||
targetInput.dispatchEvent(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -899,6 +878,9 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
|
||||
|
||||
dropdowns.forEach(dropdown => {
|
||||
const fieldId = dropdown.getAttribute('data-field-id');
|
||||
const selectedValue = dropdown.getAttribute('data-selected-value') || '';
|
||||
const currentValue = dropdown.value; // Preserva il valore corrente
|
||||
|
||||
if (!fieldId || !dropdownData[fieldId]) {
|
||||
dropdown.innerHTML = '<option value="">Errore nel caricamento</option>';
|
||||
return;
|
||||
@@ -909,17 +891,64 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
|
||||
const option = document.createElement('option');
|
||||
option.value = value.IdCustomFieldsValue;
|
||||
option.textContent = value.Valore;
|
||||
if (dropdown.value === option.value) option.selected = true;
|
||||
// Usa il valore corrente se disponibile, altrimenti usa data-selected-value
|
||||
if (currentValue && currentValue === String(value.IdCustomFieldsValue)) {
|
||||
option.selected = true;
|
||||
} else if (!currentValue && selectedValue === String(value.IdCustomFieldsValue)) {
|
||||
option.selected = true;
|
||||
}
|
||||
dropdown.appendChild(option);
|
||||
});
|
||||
|
||||
if ((currentValue || selectedValue) && dropdown.value !== (currentValue || selectedValue)) {
|
||||
dropdown.value = '';
|
||||
console.warn(`Valore ${currentValue || selectedValue} non trovato per fieldId ${fieldId}`);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Chiama populateDropdowns solo al caricamento iniziale
|
||||
populateDropdowns();
|
||||
|
||||
document.querySelectorAll('.save-btn').forEach(btn => {
|
||||
btn.addEventListener('click', function() {
|
||||
setTimeout(populateDropdowns, 100);
|
||||
const rowIndex = this.getAttribute('data-row');
|
||||
const row = this.closest('.grid-row');
|
||||
const iddatadb = row.getAttribute('data-id');
|
||||
const formData = new FormData();
|
||||
|
||||
const inputs = row.querySelectorAll(`input[name^="rows[${rowIndex}]"], select[name^="rows[${rowIndex}]"]`);
|
||||
inputs.forEach(input => {
|
||||
const name = input.name.replace(`rows[${rowIndex}]`, '').replace(/\[|\]/g, '');
|
||||
formData.append(name, input.value);
|
||||
// Aggiorna data-selected-value per i dropdown
|
||||
if (input.tagName === 'SELECT' && input.classList.contains('dropdown-select')) {
|
||||
input.setAttribute('data-selected-value', input.value);
|
||||
}
|
||||
});
|
||||
formData.append('iddatadb', iddatadb);
|
||||
formData.append('mapping', JSON.stringify(<?= json_encode($allMappings) ?>));
|
||||
|
||||
fetch('save_edited_row.php', {
|
||||
method: 'POST',
|
||||
body: formData
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
if (data.success) {
|
||||
const cells = row.querySelectorAll('.grid-cell');
|
||||
cells.forEach(cell => {
|
||||
cell.classList.remove('flash-success');
|
||||
void cell.offsetWidth;
|
||||
cell.classList.add('flash-success');
|
||||
});
|
||||
setTimeout(() => cells.forEach(cell => cell.classList.remove('flash-success')), 500);
|
||||
alert('Salvataggio avvenuto con successo!');
|
||||
} else {
|
||||
alert('Errore durante il salvataggio: ' + data.message);
|
||||
}
|
||||
})
|
||||
.catch(error => alert('Errore durante il salvataggio: ' + error.message));
|
||||
});
|
||||
});
|
||||
|
||||
@@ -944,6 +973,7 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
|
||||
if (targetInput) {
|
||||
targetInput.value = value;
|
||||
if (targetInput.tagName === 'SELECT') {
|
||||
targetInput.setAttribute('data-selected-value', value); // Aggiorna anche qui
|
||||
const event = new Event('change');
|
||||
targetInput.dispatchEvent(event);
|
||||
}
|
||||
|
||||
@@ -126,7 +126,11 @@ error_log("Loaded template: " . print_r($template, true));
|
||||
<div class="page-wrapper">
|
||||
<div class="page-content">
|
||||
<?php include('top_stat_widget.php'); ?>
|
||||
|
||||
<div class="mb-3 text">
|
||||
<a href="historical_trf.php?id=<?= $id ?>&status=i" class="btn btn-warning me-2">Imported (i)</a>
|
||||
<a href="historical_trf.php?id=<?= $id ?>&status=P" class="btn btn-primary me-2">In Progress (P)</a>
|
||||
<a href="historical_trf.php?id=<?= $id ?>&status=l" class="btn btn-success">To LIMS (l)</a>
|
||||
</div>
|
||||
<div class="card radius-10">
|
||||
<div class="card-header">
|
||||
<div class="d-flex align-items-center">
|
||||
@@ -136,6 +140,7 @@ error_log("Loaded template: " . print_r($template, true));
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card-body">
|
||||
<!-- Form per caricare il file -->
|
||||
<form id="uploadForm" enctype="multipart/form-data" class="mb-4">
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
<li> <a href="import_dashboard.php"><i class='bx bx-radio-circle'></i>XLS Import</a>
|
||||
</li>
|
||||
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
<li>
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
header('Content-Type: application/json');
|
||||
|
||||
include('include/headscript.php');
|
||||
|
||||
// Parametri dalla richiesta AJAX
|
||||
$template_id = intval($_GET['template_id'] ?? 0);
|
||||
$status = $_GET['status'] ?? 'i';
|
||||
$offset = intval($_GET['offset'] ?? 0);
|
||||
$limit = intval($_GET['limit'] ?? 20);
|
||||
|
||||
if (!$template_id || !in_array($status, ['i', 'P', 'l'])) {
|
||||
error_log("Errore in load_more_rows.php: Parametri non validi - template_id: $template_id, status: $status");
|
||||
echo json_encode(['success' => false, 'message' => 'Parametri non validi']);
|
||||
exit;
|
||||
}
|
||||
|
||||
// Connessione al database
|
||||
$db = DBHandlerSelect::getInstance();
|
||||
$pdo = $db->getConnection();
|
||||
|
||||
// Recupera i dati
|
||||
try {
|
||||
$stmt = $pdo->prepare("
|
||||
SELECT d.*, CONCAT(u.first_name, ' ', u.last_name) AS user_name
|
||||
FROM datadb d
|
||||
LEFT JOIN auth_users u ON d.user_id = u.id
|
||||
WHERE d.templateid = ? AND d.status = ?
|
||||
LIMIT ? OFFSET ?
|
||||
");
|
||||
$stmt->execute([$template_id, $status, $limit, $offset]);
|
||||
$importedData = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
// Recupera i dettagli manuali
|
||||
$insertedIds = array_column($importedData, 'iddatadb');
|
||||
$manualDetails = [];
|
||||
if (!empty($insertedIds)) {
|
||||
$placeholders = implode(',', array_fill(0, count($insertedIds), '?'));
|
||||
$stmt = $pdo->prepare("
|
||||
SELECT d.id AS detail_id, d.id AS datadb_id, d.mapping_id, d.field_value, m.field_label, m.data_type, m.is_required, m.manual_default
|
||||
FROM import_data_details d
|
||||
JOIN template_mapping m ON d.mapping_id = m.id
|
||||
WHERE d.id IN ($placeholders)
|
||||
");
|
||||
$stmt->execute($insertedIds);
|
||||
$manualDetails = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
}
|
||||
|
||||
// Prepara i dati per il JSON
|
||||
$rows = [];
|
||||
foreach ($importedData as $row) {
|
||||
$rowData = [
|
||||
'iddatadb' => $row['iddatadb'] ?? '',
|
||||
'importreferencecode' => $row['importreferencecode'] ?? '',
|
||||
'filename_import' => $row['filename_import'] ?? '',
|
||||
'status' => $row['status'] ?? '',
|
||||
'importdate' => $row['importdate'] ?? '',
|
||||
'details' => array_filter($manualDetails, fn($d) => $d['datadb_id'] == $row['iddatadb'])
|
||||
];
|
||||
$rows[] = $rowData;
|
||||
}
|
||||
|
||||
error_log("load_more_rows.php: Caricate " . count($rows) . " righe per template_id=$template_id, status=$status, offset=$offset");
|
||||
echo json_encode(['success' => true, 'rows' => $rows]);
|
||||
} catch (Exception $e) {
|
||||
error_log("Errore in load_more_rows.php: " . $e->getMessage());
|
||||
echo json_encode(['success' => false, 'message' => 'Errore nel caricamento: ' . $e->getMessage()]);
|
||||
}
|
||||
exit;
|
||||
@@ -1,4 +1,3 @@
|
||||
<!-- Modal -->
|
||||
<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-content">
|
||||
@@ -13,24 +12,24 @@
|
||||
<ul id="partsList" class="list-group"></ul>
|
||||
<table class="table table-striped table-sm mt-3" id="partsTable">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Num. Parte</th>
|
||||
<th>Descrizione Parte</th>
|
||||
<th>Azioni</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Num. Parte</th>
|
||||
<th>Descrizione Parte</th>
|
||||
<th>Azioni</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="partsTableBody">
|
||||
<tr data-part-id="new">
|
||||
<td><input type="number" class="form-control form-control-sm part-number" value="1" style="width: 80px;"></td>
|
||||
<td><input type="text" class="form-control form-control-sm part-description" placeholder="Inserisci descrizione" style="width: 100%;"></td>
|
||||
<td>
|
||||
<button type="button" class="btn btn-success btn-sm add-row" style="padding: 0.1rem 0.3rem; font-size: 0.8rem;"><i class="fas fa-plus fa-xs"></i></button>
|
||||
<button type="button" class="btn btn-primary btn-sm add-mix-row" style="padding: 0.1rem 0.3rem; font-size: 0.8rem;">M</button>
|
||||
<button type="button" class="btn btn-danger btn-sm remove-row" style="padding: 0.1rem 0.3rem; font-size: 0.8rem; display: none;"><i class="fas fa-trash fa-xs"></i></button>
|
||||
<span class="save-status text-success" style="display: none; margin-left: 5px;"><i class="fas fa-check fa-xs"></i></span>
|
||||
<span class="save-loading text-warning" style="display: none; margin-left: 5px;"><i class="fas fa-spinner fa-spin fa-xs"></i></span>
|
||||
</td>
|
||||
</tr>
|
||||
<tr data-part-id="new">
|
||||
<td><input type="number" class="form-control form-control-sm part-number" value="1" style="width: 80px;"></td>
|
||||
<td><input type="text" class="form-control form-control-sm part-description" placeholder="Inserisci descrizione" style="width: 100%;"></td>
|
||||
<td>
|
||||
<button type="button" class="btn btn-success btn-sm add-row" style="padding: 0.1rem 0.3rem; font-size: 0.8rem;"><i class="fas fa-plus fa-xs"></i></button>
|
||||
<button type="button" class="btn btn-primary btn-sm add-mix-row" style="padding: 0.1rem 0.3rem; font-size: 0.8rem;">M</button>
|
||||
<button type="button" class="btn btn-danger btn-sm remove-row" style="padding: 0.1rem 0.3rem; font-size: 0.8rem; display: none;"><i class="fas fa-trash fa-xs"></i></button>
|
||||
<span class="save-status text-success" style="display: none; margin-left: 5px;"><i class="fas fa-check fa-xs"></i></span>
|
||||
<span class="save-loading text-warning" style="display: none; margin-left: 5px;"><i class="fas fa-spinner fa-spin fa-xs"></i></span>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
@@ -50,6 +49,7 @@
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-primary btn-sm" id="addDescriptionsBtn" style="padding: 0.1rem 0.5rem; font-size: 0.8rem;">Aggiungi Lista Descrizioni</button>
|
||||
<button type="button" class="btn btn-warning btn-sm" id="removeBackgroundBtn" style="padding: 0.1rem 0.5rem; font-size: 0.8rem;">Rimuovi Sfondo</button>
|
||||
<button type="button" class="btn btn-danger btn-sm" id="removeAnnotationsBtn" style="padding: 0.1rem 0.5rem; font-size: 0.8rem;">Rimuovi Annotazioni</button>
|
||||
<button type="button" class="btn btn-success btn-sm" id="savePhotoBtn" style="padding: 0.1rem 0.5rem; font-size: 0.8rem;">Salva Foto con Nome</button>
|
||||
<button type="button" class="btn btn-secondary btn-sm" data-bs-dismiss="modal" style="padding: 0.1rem 0.5rem; font-size: 0.8rem;">Chiudi</button>
|
||||
@@ -146,23 +146,31 @@
|
||||
font-size: 0.8rem;
|
||||
}
|
||||
|
||||
/* ნორმალური Save ღილაკი */
|
||||
/* Normale Save button */
|
||||
#savePhotoBtn {
|
||||
transition: all 0.3s ease-in-out;
|
||||
}
|
||||
|
||||
/* დაუმახსოვრებელი ცვლილებები */
|
||||
/* Modifiche non salvate */
|
||||
#savePhotoBtn.unsaved {
|
||||
background-color: #dc3545 !important; /* წითელი */
|
||||
background-color: #dc3545 !important;
|
||||
border-color: #dc3545 !important;
|
||||
color: white !important;
|
||||
animation: pulse 1.2s infinite;
|
||||
}
|
||||
|
||||
/* ლამაზი პულსაცია */
|
||||
/* Animazione di pulsazione */
|
||||
@keyframes pulse {
|
||||
0% { box-shadow: 0 0 0 0 rgba(220, 53, 69, 0.7); }
|
||||
70% { box-shadow: 0 0 10px 15px rgba(220, 53, 69, 0); }
|
||||
100% { box-shadow: 0 0 0 0 rgba(220, 53, 69, 0); }
|
||||
0% {
|
||||
box-shadow: 0 0 0 0 rgba(220, 53, 69, 0.7);
|
||||
}
|
||||
|
||||
70% {
|
||||
box-shadow: 0 0 10px 15px rgba(220, 53, 69, 0);
|
||||
}
|
||||
|
||||
100% {
|
||||
box-shadow: 0 0 0 0 rgba(220, 53, 69, 0);
|
||||
}
|
||||
}
|
||||
</style>
|
||||
</style>
|
||||
+271
-218
@@ -2,7 +2,12 @@ $(document).ready(function () {
|
||||
console.log("parts.js caricato correttamente");
|
||||
|
||||
// ===================
|
||||
// GLOBAL STATE (NEW)
|
||||
// CONFIGURAZIONE API Remove.bg
|
||||
// ===================
|
||||
const REMOVE_BG_API_KEY = "E85XGT5heTBUtWsf9zMLM7cg"; // Sostituisci con la tua chiave API
|
||||
|
||||
// ===================
|
||||
// GLOBAL STATE
|
||||
// ===================
|
||||
let photoData = {
|
||||
naturalWidth: 0,
|
||||
@@ -12,29 +17,36 @@ $(document).ready(function () {
|
||||
scale: 1,
|
||||
};
|
||||
|
||||
// markers keyed by photo src => [{ partNumber, x, y } using NATURAL coords]
|
||||
let photoMarkers = {};
|
||||
|
||||
// selection & descriptions
|
||||
let selectedPartNumber = null;
|
||||
let descriptionPosition = {x: 10, y: 10}; // NATURAL coords
|
||||
let descriptionPosition = { x: 10, y: 10 };
|
||||
let hasDescriptions = false;
|
||||
|
||||
// Verifica inizializzazione del pulsante
|
||||
console.log(
|
||||
"Verifica pulsante #removeBackgroundBtn:",
|
||||
$("#removeBackgroundBtn").length,
|
||||
);
|
||||
|
||||
// ===================
|
||||
// POPUP HANDLING
|
||||
// ===================
|
||||
const partsButtons = document.querySelectorAll(".parts-btn");
|
||||
const partsModal = document.getElementById("partsModal");
|
||||
const closeBtn = document.querySelector("#partsModal .close-btn");
|
||||
const overlay = document.querySelector(".overlay");
|
||||
|
||||
partsButtons.forEach((button) => {
|
||||
button.addEventListener("click", function () {
|
||||
console.log("Pulsante Parts cliccato");
|
||||
const iddatadb = $(this).data("iddatadb");
|
||||
const rowIndex = $(this).data("row");
|
||||
const importRef = $("table tbody tr").eq(rowIndex).find("td").eq(1).text();
|
||||
const description = $("table tbody tr").eq(rowIndex).find("td").eq(2).text() || "Sconosciuto";
|
||||
const importRef = $("table tbody tr")
|
||||
.eq(rowIndex)
|
||||
.find("td")
|
||||
.eq(1)
|
||||
.text();
|
||||
const description =
|
||||
$("table tbody tr").eq(rowIndex).find("td").eq(2).text() ||
|
||||
"Sconosciuto";
|
||||
|
||||
$("#trfHeader").text(`${iddatadb} - ${importRef} - ${description}`);
|
||||
$("#partsModal").data("iddatadb", iddatadb);
|
||||
@@ -45,66 +57,62 @@ $(document).ready(function () {
|
||||
if (partsModal) {
|
||||
const modal = new bootstrap.Modal(partsModal);
|
||||
modal.show();
|
||||
console.log("Modale aperto");
|
||||
} else {
|
||||
console.error("Modal Parts non trovato");
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
if (closeBtn) {
|
||||
closeBtn.addEventListener("click", function () {
|
||||
partsModal.style.display = "none";
|
||||
overlay.style.display = "none";
|
||||
document.body.style.pointerEvents = "auto";
|
||||
});
|
||||
}
|
||||
|
||||
if (partsModal) {
|
||||
window.addEventListener("click", function (event) {
|
||||
if (event.target === partsModal) {
|
||||
partsModal.style.display = "none";
|
||||
overlay.style.display = "none";
|
||||
document.body.style.pointerEvents = "auto";
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// ===================
|
||||
// PHOTO LOADERS
|
||||
// ===================
|
||||
function loadPhoto(iddatadb) {
|
||||
console.log("Caricamento foto per iddatadb:", iddatadb);
|
||||
$.ajax({
|
||||
url: "load_photo.php",
|
||||
method: "GET",
|
||||
data: {iddatadb: iddatadb},
|
||||
data: { iddatadb: iddatadb },
|
||||
success: function (response) {
|
||||
console.log("Risposta load_photo.php:", response);
|
||||
if (response.success) {
|
||||
if (response.photos && response.photos.length > 1) {
|
||||
showPhotoSelector(response.photos);
|
||||
} else if (response.photos && response.photos.length === 1) {
|
||||
} else if (
|
||||
response.photos &&
|
||||
response.photos.length === 1
|
||||
) {
|
||||
loadSinglePhoto(response.photos[0]);
|
||||
} else {
|
||||
$("#samplePhoto").attr("src", "");
|
||||
alert("Nessuna foto trovata per questo TRF.");
|
||||
console.log("Nessuna foto trovata");
|
||||
}
|
||||
} else {
|
||||
alert(response.message || "Errore nel caricamento della foto.");
|
||||
alert(
|
||||
response.message ||
|
||||
"Errore nel caricamento della foto.",
|
||||
);
|
||||
console.error("Errore load_photo.php:", response.message);
|
||||
}
|
||||
},
|
||||
error: function (xhr, status, error) {
|
||||
alert("Errore nel caricamento della foto: " + error);
|
||||
console.error("Errore AJAX load_photo.php:", error, xhr.status);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
function showPhotoSelector(photos) {
|
||||
console.log("Mostra selettore foto:", photos);
|
||||
const selectorContainer = $("#photoSelectorContainer");
|
||||
selectorContainer.empty();
|
||||
|
||||
const selector = $('<select id="photoSelector"></select>');
|
||||
photos.forEach((photo, index) => {
|
||||
const option = $('<option></option>').val(photo).text(`Photo ${index + 1}`);
|
||||
// display option with photo name if available
|
||||
const option = $("<option></option>")
|
||||
.val(photo)
|
||||
.text(`Photo ${index + 1}`);
|
||||
if (photo.includes("/")) {
|
||||
const photoName = photo.split("/").pop();
|
||||
option.text(`Photo ${index + 1} - ${photoName}`);
|
||||
@@ -127,49 +135,67 @@ $(document).ready(function () {
|
||||
}
|
||||
|
||||
function loadSinglePhoto(photoPath) {
|
||||
console.log("Caricamento singola foto:", photoPath);
|
||||
const img = $("#samplePhoto");
|
||||
img.off("load"); // avoid stacking multiple handlers
|
||||
img.off("load");
|
||||
img.attr("src", photoPath);
|
||||
|
||||
img.on("load", function () {
|
||||
console.log(
|
||||
"Immagine caricata, dimensioni naturali:",
|
||||
img[0].naturalWidth,
|
||||
img[0].naturalHeight,
|
||||
);
|
||||
const canvas = document.getElementById("photoCanvas");
|
||||
const ctx = canvas.getContext("2d");
|
||||
|
||||
// Real image size
|
||||
const naturalWidth = img[0].naturalWidth;
|
||||
const naturalHeight = img[0].naturalHeight;
|
||||
|
||||
// Compute scale to FIT inside its parent without distorting aspect ratio
|
||||
const parent = $(canvas).parent();
|
||||
const maxW = parent.width();
|
||||
const maxH = parent.height();
|
||||
const scale = Math.min(maxW / naturalWidth, maxH / naturalHeight);
|
||||
|
||||
// Display size on screen
|
||||
const displayWidth = Math.max(1, Math.round(naturalWidth * scale));
|
||||
const displayHeight = Math.max(1, Math.round(naturalHeight * scale));
|
||||
const displayHeight = Math.max(
|
||||
1,
|
||||
Math.round(naturalHeight * scale),
|
||||
);
|
||||
|
||||
// Save globally
|
||||
photoData = {naturalWidth, naturalHeight, displayWidth, displayHeight, scale};
|
||||
photoData = {
|
||||
naturalWidth,
|
||||
naturalHeight,
|
||||
displayWidth,
|
||||
displayHeight,
|
||||
scale,
|
||||
};
|
||||
|
||||
// Canvas in REAL size (so saving uses natural coords 1:1)
|
||||
canvas.width = naturalWidth;
|
||||
canvas.height = naturalHeight;
|
||||
|
||||
// Visual size on screen
|
||||
canvas.style.width = `${displayWidth}px`;
|
||||
canvas.style.height = `${displayHeight}px`;
|
||||
|
||||
// Also size/align the overlay containers to match the canvas
|
||||
$("#markerContainer").css({width: `${displayWidth}px`, height: `${displayHeight}px`});
|
||||
$("#descriptionList").css({maxWidth: `${Math.max(200, Math.round(displayWidth * 0.35))}px`});
|
||||
$("#markerContainer").css({
|
||||
width: `${displayWidth}px`,
|
||||
height: `${displayHeight}px`,
|
||||
});
|
||||
$("#descriptionList").css({
|
||||
maxWidth: `${Math.max(200, Math.round(displayWidth * 0.35))}px`,
|
||||
});
|
||||
|
||||
// Draw fresh image at full resolution
|
||||
ctx.clearRect(0, 0, naturalWidth, naturalHeight);
|
||||
ctx.drawImage(img.get(0), 0, 0, naturalWidth, naturalHeight);
|
||||
|
||||
updateMarkers();
|
||||
if (hasDescriptions) drawDescriptions(descriptionPosition.x, descriptionPosition.y);
|
||||
if (hasDescriptions)
|
||||
drawDescriptions(descriptionPosition.x, descriptionPosition.y);
|
||||
});
|
||||
|
||||
img.on("error", function () {
|
||||
console.error("Errore caricamento immagine:", photoPath);
|
||||
alert("Errore nel caricamento dell'immagine.");
|
||||
});
|
||||
}
|
||||
|
||||
@@ -198,16 +224,19 @@ $(document).ready(function () {
|
||||
const rowCount = $("#partsTableBody tr").length;
|
||||
$("#partsTableBody tr").each(function () {
|
||||
const $removeBtn = $(this).find(".remove-row");
|
||||
if (rowCount > 1) $removeBtn.show(); else $removeBtn.hide();
|
||||
if (rowCount > 1) $removeBtn.show();
|
||||
else $removeBtn.hide();
|
||||
});
|
||||
}
|
||||
|
||||
$(document).on("click", ".add-row", function (e) {
|
||||
e.preventDefault();
|
||||
const maxPartNumber = Math.max(
|
||||
...$("#partsTableBody tr").map(function () {
|
||||
return parseInt($(this).find(".part-number").val()) || 0;
|
||||
}).get(),
|
||||
...$("#partsTableBody tr")
|
||||
.map(function () {
|
||||
return parseInt($(this).find(".part-number").val()) || 0;
|
||||
})
|
||||
.get(),
|
||||
);
|
||||
addNewRow(maxPartNumber + 1);
|
||||
updatePartsList();
|
||||
@@ -216,9 +245,11 @@ $(document).ready(function () {
|
||||
$(document).on("click", ".add-mix-row", function (e) {
|
||||
e.preventDefault();
|
||||
const maxPartNumber = Math.max(
|
||||
...$("#partsTableBody tr").map(function () {
|
||||
return parseInt($(this).find(".part-number").val()) || 0;
|
||||
}).get(),
|
||||
...$("#partsTableBody tr")
|
||||
.map(function () {
|
||||
return parseInt($(this).find(".part-number").val()) || 0;
|
||||
})
|
||||
.get(),
|
||||
);
|
||||
addNewRow(maxPartNumber + 1, true);
|
||||
updatePartsList();
|
||||
@@ -233,7 +264,7 @@ $(document).ready(function () {
|
||||
$.ajax({
|
||||
url: "delete_part.php",
|
||||
method: "POST",
|
||||
data: JSON.stringify({part_id: partId}),
|
||||
data: JSON.stringify({ part_id: partId }),
|
||||
contentType: "application/json",
|
||||
success: function (response) {
|
||||
if (response.success) {
|
||||
@@ -246,7 +277,14 @@ $(document).ready(function () {
|
||||
}
|
||||
},
|
||||
error: function (xhr, status, error) {
|
||||
alert("Errore nell'eliminazione: " + error + ". Stato: " + xhr.status + " - " + xhr.responseText);
|
||||
alert(
|
||||
"Errore nell'eliminazione: " +
|
||||
error +
|
||||
". Stato: " +
|
||||
xhr.status +
|
||||
" - " +
|
||||
xhr.responseText,
|
||||
);
|
||||
},
|
||||
});
|
||||
} else {
|
||||
@@ -266,7 +304,6 @@ $(document).ready(function () {
|
||||
const iddatadb = $("#partsModal").data("iddatadb");
|
||||
const isMix = partDescription.startsWith("Mix") ? "Y" : "N";
|
||||
|
||||
// არსებული part-id row-დან (თუ უკვე არსებობს)
|
||||
const partId = $row.data("part-id") || null;
|
||||
|
||||
if (partDescription && iddatadb) {
|
||||
@@ -280,7 +317,7 @@ $(document).ready(function () {
|
||||
iddatadb: iddatadb,
|
||||
parts: [
|
||||
{
|
||||
id: partId, // გავგზავნე part-ის ID (თუ არის)
|
||||
id: partId,
|
||||
part_number: partNumber,
|
||||
part_description: partDescription,
|
||||
mix: isMix,
|
||||
@@ -293,7 +330,6 @@ $(document).ready(function () {
|
||||
$saveLoading.hide();
|
||||
$saveStatus.show();
|
||||
updatePartsList();
|
||||
// თუ ახალია, backend-მა მოგვცა ახალი ID
|
||||
if (response.part_id) {
|
||||
$row.attr("data-part-id", response.part_id);
|
||||
$row.data("part-id", response.part_id);
|
||||
@@ -313,11 +349,13 @@ $(document).ready(function () {
|
||||
});
|
||||
|
||||
function loadExistingParts(iddatadb) {
|
||||
console.log("Caricamento parti esistenti per iddatadb:", iddatadb);
|
||||
$.ajax({
|
||||
url: "load_parts.php",
|
||||
method: "GET",
|
||||
data: {iddatadb: iddatadb},
|
||||
data: { iddatadb: iddatadb },
|
||||
success: function (response) {
|
||||
console.log("Risposta load_parts.php:", response);
|
||||
if (response.success) {
|
||||
$("#partsTableBody").empty();
|
||||
if (response.parts.length > 0) {
|
||||
@@ -342,12 +380,17 @@ $(document).ready(function () {
|
||||
updateRowButtons();
|
||||
updatePartsList();
|
||||
} else {
|
||||
alert("Errore nel caricamento delle parti: " + response.message);
|
||||
alert(
|
||||
"Errore nel caricamento delle parti: " +
|
||||
response.message,
|
||||
);
|
||||
console.error("Errore load_parts.php:", response.message);
|
||||
addNewRow(1);
|
||||
}
|
||||
},
|
||||
error: function (xhr, status, error) {
|
||||
alert("Errore nel caricamento delle parti: " + error);
|
||||
console.error("Errore AJAX load_parts.php:", error, xhr.status);
|
||||
addNewRow(1);
|
||||
},
|
||||
});
|
||||
@@ -358,7 +401,11 @@ $(document).ready(function () {
|
||||
$("#partsTableBody tr").each(function () {
|
||||
const partNumber = $(this).find(".part-number").val();
|
||||
const partDescription = $(this).find(".part-description").val();
|
||||
if (partNumber && partDescription && !partDescription.startsWith("Mix")) {
|
||||
if (
|
||||
partNumber &&
|
||||
partDescription &&
|
||||
!partDescription.startsWith("Mix")
|
||||
) {
|
||||
const listItem = `
|
||||
<li class="list-group-item" data-part-number="${partNumber}">
|
||||
${partNumber} - ${partDescription}
|
||||
@@ -372,9 +419,14 @@ $(document).ready(function () {
|
||||
$(document).on("click", ".add-to-mix-btn", function () {
|
||||
const $listItem = $(this).closest("li");
|
||||
const partDescription = $listItem.text().split(" - ")[1].trim();
|
||||
const $mixRow = $("#partsTableBody tr").filter(function () {
|
||||
return $(this).find(".part-description").val().startsWith("Mix");
|
||||
}).last();
|
||||
const $mixRow = $("#partsTableBody tr")
|
||||
.filter(function () {
|
||||
return $(this)
|
||||
.find(".part-description")
|
||||
.val()
|
||||
.startsWith("Mix");
|
||||
})
|
||||
.last();
|
||||
|
||||
if ($mixRow.length === 0) {
|
||||
alert("Crea prima una riga Mix usando il pulsante 'M'.");
|
||||
@@ -416,22 +468,29 @@ $(document).ready(function () {
|
||||
const clickX = e.clientX - rect.left;
|
||||
const clickY = e.clientY - rect.top;
|
||||
|
||||
const x = clickX / photoData.scale; // convert to NATURAL coords
|
||||
const x = clickX / photoData.scale;
|
||||
const y = clickY / photoData.scale;
|
||||
|
||||
const currentPhoto = $("#samplePhoto").attr("src");
|
||||
if (!photoMarkers[currentPhoto]) photoMarkers[currentPhoto] = [];
|
||||
|
||||
const existingMarker = photoMarkers[currentPhoto].find(m => m.partNumber == selectedPartNumber);
|
||||
const existingMarker = photoMarkers[currentPhoto].find(
|
||||
(m) => m.partNumber == selectedPartNumber,
|
||||
);
|
||||
if (existingMarker) {
|
||||
existingMarker.x = x;
|
||||
existingMarker.y = y;
|
||||
} else {
|
||||
photoMarkers[currentPhoto].push({partNumber: selectedPartNumber, x, y});
|
||||
photoMarkers[currentPhoto].push({
|
||||
partNumber: selectedPartNumber,
|
||||
x,
|
||||
y,
|
||||
});
|
||||
}
|
||||
|
||||
updateMarkers();
|
||||
if (hasDescriptions) drawDescriptions(descriptionPosition.x, descriptionPosition.y);
|
||||
if (hasDescriptions)
|
||||
drawDescriptions(descriptionPosition.x, descriptionPosition.y);
|
||||
|
||||
selectedPartNumber = null;
|
||||
$("#partsList li").removeClass("active");
|
||||
@@ -441,8 +500,10 @@ $(document).ready(function () {
|
||||
const markerContainer = $("#markerContainer");
|
||||
markerContainer.empty();
|
||||
|
||||
// keep overlay sized to canvas display
|
||||
markerContainer.css({width: `${photoData.displayWidth}px`, height: `${photoData.displayHeight}px`});
|
||||
markerContainer.css({
|
||||
width: `${photoData.displayWidth}px`,
|
||||
height: `${photoData.displayHeight}px`,
|
||||
});
|
||||
|
||||
const currentPhoto = $("#samplePhoto").attr("src");
|
||||
const markers = photoMarkers[currentPhoto] || [];
|
||||
@@ -451,7 +512,9 @@ $(document).ready(function () {
|
||||
const scaledX = marker.x * photoData.scale;
|
||||
const scaledY = marker.y * photoData.scale;
|
||||
|
||||
const $marker = $(`<div class="draggable-marker">${marker.partNumber}</div>`).css({
|
||||
const $marker = $(
|
||||
`<div class="draggable-marker">${marker.partNumber}</div>`,
|
||||
).css({
|
||||
left: scaledX - 8 + "px",
|
||||
top: scaledY - 8 + "px",
|
||||
});
|
||||
@@ -488,13 +551,12 @@ $(document).ready(function () {
|
||||
currentX = Math.max(0, Math.min(currentX, maxX));
|
||||
currentY = Math.max(0, Math.min(currentY, maxY));
|
||||
|
||||
$element.css({left: currentX + "px", top: currentY + "px"});
|
||||
$element.css({ left: currentX + "px", top: currentY + "px" });
|
||||
|
||||
if (item && item.partNumber) {
|
||||
item.x = (currentX + 8) / photoData.scale;
|
||||
item.y = (currentY + 8) / photoData.scale;
|
||||
} else {
|
||||
// draggable description panel
|
||||
descriptionPosition.x = (currentX + 5) / photoData.scale;
|
||||
descriptionPosition.y = (currentY + 5) / photoData.scale;
|
||||
}
|
||||
@@ -513,7 +575,11 @@ $(document).ready(function () {
|
||||
$("#partsTableBody tr").each(function () {
|
||||
const partNumber = $(this).find(".part-number").val();
|
||||
const partDescription = $(this).find(".part-description").val();
|
||||
if (partNumber && partDescription && !partDescription.startsWith("Mix")) {
|
||||
if (
|
||||
partNumber &&
|
||||
partDescription &&
|
||||
!partDescription.startsWith("Mix")
|
||||
) {
|
||||
partsList.push(`${partNumber} ${partDescription}`);
|
||||
}
|
||||
});
|
||||
@@ -525,7 +591,9 @@ $(document).ready(function () {
|
||||
top: y * photoData.scale + "px",
|
||||
left: x * photoData.scale + "px",
|
||||
});
|
||||
partsList.forEach((part) => descriptionList.append(`<div>${part}</div>`));
|
||||
partsList.forEach((part) =>
|
||||
descriptionList.append(`<div>${part}</div>`),
|
||||
);
|
||||
|
||||
updateMarkers();
|
||||
}
|
||||
@@ -540,7 +608,6 @@ $(document).ready(function () {
|
||||
const canvas = document.getElementById("photoCanvas");
|
||||
const ctx = canvas.getContext("2d");
|
||||
|
||||
// reset canvas to current image (keeps proportions)
|
||||
canvas.width = photoData.naturalWidth;
|
||||
canvas.height = photoData.naturalHeight;
|
||||
canvas.style.width = `${photoData.displayWidth}px`;
|
||||
@@ -554,43 +621,156 @@ $(document).ready(function () {
|
||||
}
|
||||
|
||||
$("#addDescriptionsBtn").on("click", function () {
|
||||
console.log("Aggiungi descrizioni cliccato");
|
||||
hasDescriptions = true;
|
||||
descriptionPosition = {x: 10, y: 10};
|
||||
descriptionPosition = { x: 10, y: 10 };
|
||||
drawDescriptions(descriptionPosition.x, descriptionPosition.y);
|
||||
makeDraggable($("#descriptionList"));
|
||||
});
|
||||
|
||||
$("#removeAnnotationsBtn").on("click", function () {
|
||||
console.log("Rimuovi annotazioni cliccato");
|
||||
clearCanvasMarkers();
|
||||
});
|
||||
|
||||
// ===================
|
||||
// REMOVE BACKGROUND (Remove.bg)
|
||||
// ===================
|
||||
$("#removeBackgroundBtn").on("click", function () {
|
||||
console.log("Pulsante Rimuovi Sfondo cliccato");
|
||||
|
||||
if (
|
||||
!REMOVE_BG_API_KEY ||
|
||||
REMOVE_BG_API_KEY === "INSERISCI_LA_TUA_CHIAVE_API"
|
||||
) {
|
||||
alert(
|
||||
"Chiave API di Remove.bg non configurata. Inserisci una chiave valida.",
|
||||
);
|
||||
console.error("Chiave API non valida");
|
||||
return;
|
||||
}
|
||||
|
||||
const currentPhoto = $("#samplePhoto")[0];
|
||||
if (!currentPhoto.src) {
|
||||
alert("Nessuna foto selezionata.");
|
||||
console.error("Nessuna immagine in #samplePhoto");
|
||||
return;
|
||||
}
|
||||
|
||||
console.log("Immagine corrente:", currentPhoto.src);
|
||||
|
||||
// Salva marker e descrizioni
|
||||
const currentPhotoKey = currentPhoto.src;
|
||||
const markers = photoMarkers[currentPhotoKey] || [];
|
||||
const descPos = { ...descriptionPosition };
|
||||
const hasDesc = hasDescriptions;
|
||||
|
||||
// Mostra spinner
|
||||
$("#removeBackgroundBtn")
|
||||
.html('<i class="fas fa-spinner fa-spin"></i> Elaborazione...')
|
||||
.prop("disabled", true);
|
||||
|
||||
// Controlla se l'immagine è un URL pubblico o un dataURL
|
||||
const formData = new FormData();
|
||||
if (currentPhoto.src.startsWith("data:")) {
|
||||
// Converti dataURL in blob
|
||||
console.log("Immagine è un dataURL, conversione in blob...");
|
||||
fetch(currentPhoto.src)
|
||||
.then((res) => res.blob())
|
||||
.then((blob) => {
|
||||
formData.append("image_file", blob, "image.png");
|
||||
formData.append("size", "auto");
|
||||
sendRemoveBgRequest(formData, markers, descPos, hasDesc);
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error("Errore conversione dataURL in blob:", err);
|
||||
alert("Errore nella conversione dell'immagine.");
|
||||
$("#removeBackgroundBtn")
|
||||
.html("Rimuovi Sfondo")
|
||||
.prop("disabled", false);
|
||||
});
|
||||
} else {
|
||||
// Usa URL pubblico
|
||||
console.log("Immagine è un URL, invio diretto...");
|
||||
formData.append("image_url", currentPhoto.src);
|
||||
formData.append("size", "auto");
|
||||
sendRemoveBgRequest(formData, markers, descPos, hasDesc);
|
||||
}
|
||||
});
|
||||
|
||||
function sendRemoveBgRequest(formData, markers, descPos, hasDesc) {
|
||||
console.log("Invio richiesta a Remove.bg...");
|
||||
$.ajax({
|
||||
url: "https://api.remove.bg/v1.0/removebg",
|
||||
method: "POST",
|
||||
headers: {
|
||||
"X-Api-Key": REMOVE_BG_API_KEY,
|
||||
},
|
||||
data: formData,
|
||||
processData: false,
|
||||
contentType: false,
|
||||
success: function (response) {
|
||||
console.log("Risposta Remove.bg ricevuta:", response);
|
||||
// Ripristina il pulsante
|
||||
$("#removeBackgroundBtn")
|
||||
.html("Rimuovi Sfondo")
|
||||
.prop("disabled", false);
|
||||
|
||||
// Imposta l'immagine senza sfondo
|
||||
const dataURL =
|
||||
"data:image/png;base64," + response.data.result_b64;
|
||||
$("#samplePhoto").attr("src", dataURL);
|
||||
|
||||
// Ripristina marker e descrizioni
|
||||
photoMarkers[dataURL] = markers;
|
||||
descriptionPosition = descPos;
|
||||
hasDescriptions = hasDesc;
|
||||
|
||||
loadSinglePhoto(dataURL);
|
||||
markUnsaved();
|
||||
},
|
||||
error: function (xhr) {
|
||||
console.error(
|
||||
"Errore API Remove.bg:",
|
||||
xhr.status,
|
||||
xhr.responseText,
|
||||
);
|
||||
alert(
|
||||
"Errore nella rimozione dello sfondo: " +
|
||||
(xhr.responseJSON?.errors?.[0]?.title ||
|
||||
xhr.statusText),
|
||||
);
|
||||
$("#removeBackgroundBtn")
|
||||
.html("Rimuovi Sfondo")
|
||||
.prop("disabled", false);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
let unsavedChanges = false;
|
||||
|
||||
// --- helper functions ---
|
||||
// --- helper functions ---
|
||||
function markUnsaved() {
|
||||
if (!unsavedChanges) {
|
||||
unsavedChanges = true;
|
||||
$("#savePhotoBtn").addClass("unsaved").text("⚠️ Salva Modifiche");
|
||||
console.log("Modifiche non salvate segnate");
|
||||
}
|
||||
}
|
||||
|
||||
function clearUnsaved() {
|
||||
unsavedChanges = false;
|
||||
$("#savePhotoBtn").removeClass("unsaved").text("Salva Foto con Nome");
|
||||
console.log("Modifiche salvate, stato ripristinato");
|
||||
}
|
||||
|
||||
// --- event listeners ---
|
||||
// როცა ვცვლით input-ს ცხრილში
|
||||
// --- event listeners ---
|
||||
$(document).on("input change", "#partsTableBody input", markUnsaved);
|
||||
|
||||
// როცა ვამატებთ/ვშლით რიგს
|
||||
$(document).on("click", ".add-row, .add-mix-row, .remove-row", markUnsaved);
|
||||
|
||||
// თუ გაქვს draggable marker ან description list
|
||||
$(document).on("markerChanged descriptionChanged", markUnsaved);
|
||||
|
||||
// --- modal close protection ---
|
||||
$('#partsModal').on('hide.bs.modal', function (e) {
|
||||
// --- modal close protection ---
|
||||
$("#partsModal").on("hide.bs.modal", function (e) {
|
||||
if (unsavedChanges) {
|
||||
if (!confirm("Hai modifiche non salvate. Vuoi davvero uscire?")) {
|
||||
e.preventDefault();
|
||||
@@ -598,147 +778,20 @@ $(document).ready(function () {
|
||||
}
|
||||
});
|
||||
|
||||
// --- SAVE BUTTON ---
|
||||
// --- SAVE BUTTON (disabilitato per ora) ---
|
||||
$("#savePhotoBtn").on("click", function () {
|
||||
const canvas = document.getElementById("photoCanvas");
|
||||
const ctx = canvas.getContext("2d");
|
||||
const img = $("#samplePhoto");
|
||||
|
||||
// Ensure canvas is real size
|
||||
const naturalWidth = img.get(0).naturalWidth;
|
||||
const naturalHeight = img.get(0).naturalHeight;
|
||||
canvas.width = naturalWidth;
|
||||
canvas.height = naturalHeight;
|
||||
|
||||
// Redraw base image
|
||||
ctx.drawImage(img.get(0), 0, 0, naturalWidth, naturalHeight);
|
||||
|
||||
// Descriptions box
|
||||
const partsList = [];
|
||||
$("#partsTableBody tr").each(function () {
|
||||
const partNumber = $(this).find(".part-number").val();
|
||||
const partDescription = $(this).find(".part-description").val();
|
||||
if (partNumber && partDescription && !partDescription.startsWith("Mix")) {
|
||||
partsList.push(`${partNumber} ${partDescription}`);
|
||||
}
|
||||
});
|
||||
|
||||
if (hasDescriptions && partsList.length > 0) {
|
||||
const fontSize = Math.round(naturalWidth * 0.02);
|
||||
ctx.font = fontSize + "px Arial";
|
||||
const textHeight = fontSize + 8;
|
||||
const boxWidth = Math.round(naturalWidth * 0.28);
|
||||
const boxHeight = partsList.length * textHeight + 25;
|
||||
|
||||
const x = descriptionPosition.x;
|
||||
const y = descriptionPosition.y;
|
||||
|
||||
// ჩრდილი
|
||||
ctx.save();
|
||||
ctx.shadowColor = "rgba(0,0,0,0.3)";
|
||||
ctx.shadowBlur = 8;
|
||||
ctx.shadowOffsetX = 3;
|
||||
ctx.shadowOffsetY = 3;
|
||||
|
||||
// ლამაზი ბექგრაუნდი
|
||||
ctx.fillStyle = "rgba(255, 255, 255, 0.9)";
|
||||
ctx.beginPath();
|
||||
ctx.roundRect(x, y, boxWidth, boxHeight, 12);
|
||||
ctx.fill();
|
||||
|
||||
ctx.restore();
|
||||
|
||||
// ტექსტი
|
||||
ctx.fillStyle = "#111111";
|
||||
partsList.forEach((part, index) => {
|
||||
const domWidth = $("#samplePhoto").width();
|
||||
const domHeight = $("#samplePhoto").height();
|
||||
|
||||
// NATURAL ზომა (ფაილის რეალური ზომა)
|
||||
const naturalWidth = photoData.naturalWidth;
|
||||
const naturalHeight = photoData.naturalHeight;
|
||||
|
||||
// მასშტაბები
|
||||
const scaleX = naturalWidth / domWidth;
|
||||
const scaleY = naturalHeight / domHeight;
|
||||
|
||||
// გადაყვანილი კოორდინატები
|
||||
const x = descriptionPosition.x * scaleX;
|
||||
const y = descriptionPosition.y * scaleY;
|
||||
|
||||
ctx.fillText(part, x + 15, y + 35 + index * textHeight);
|
||||
});
|
||||
}
|
||||
|
||||
// Markers
|
||||
const currentPhoto = $("#samplePhoto").attr("src");
|
||||
const markers = photoMarkers[currentPhoto] || [];
|
||||
markers.forEach((marker) => {
|
||||
const x = marker.x; // already NATURAL coords
|
||||
const y = marker.y;
|
||||
const radius = Math.max(5, Math.round(naturalWidth * 0.025));
|
||||
const fontSize = Math.max(8, Math.round(radius * 0.9));
|
||||
|
||||
ctx.beginPath();
|
||||
ctx.arc(x, y, radius, 0, 2 * Math.PI);
|
||||
ctx.fillStyle = "rgba(255,0,0,0.85)";
|
||||
ctx.fill();
|
||||
|
||||
ctx.lineWidth = 3;
|
||||
ctx.strokeStyle = "#ffffff";
|
||||
ctx.stroke();
|
||||
|
||||
ctx.fillStyle = "#ffffff";
|
||||
ctx.font = `bold ${fontSize}px Arial`;
|
||||
ctx.textAlign = "center";
|
||||
ctx.textBaseline = "middle";
|
||||
ctx.fillText(marker.partNumber || "", x, y);
|
||||
});
|
||||
|
||||
const dataURL = canvas.toDataURL("image/png");
|
||||
const timestamp = new Date().toISOString().replace(/[:.]/g, "-");
|
||||
const iddatadb = $("#partsModal").data("iddatadb");
|
||||
const defaultName = `photo_${iddatadb}_${timestamp}.png`;
|
||||
|
||||
const newName = prompt("Inserisci il nome del file (senza estensione):", defaultName.split(".png")[0]);
|
||||
|
||||
if (newName) {
|
||||
const finalName = newName + "_" + timestamp + ".png";
|
||||
$.ajax({
|
||||
url: "save_annotated_photo.php",
|
||||
method: "POST",
|
||||
data: {
|
||||
dataURL: dataURL,
|
||||
filename: finalName,
|
||||
iddatadb: iddatadb
|
||||
},
|
||||
success: function (response) {
|
||||
if (response.success) {
|
||||
alert("Foto salvata con successo: " + response.file_path);
|
||||
$("#samplePhoto").attr("src", response.file_path);
|
||||
loadPhoto(iddatadb);
|
||||
clearCanvasMarkers();
|
||||
|
||||
clearUnsaved(); // ✅ reset unsaved status
|
||||
} else {
|
||||
alert("Errore: " + response.message);
|
||||
}
|
||||
},
|
||||
error: function (xhr, status, error) {
|
||||
alert("Errore Ajax: " + error);
|
||||
},
|
||||
});
|
||||
}
|
||||
alert("Funzionalità di salvataggio non implementata per ora.");
|
||||
console.log("Pulsante Salva Foto cliccato");
|
||||
});
|
||||
|
||||
// ===================
|
||||
// DEBUG HOVER LOGS
|
||||
// ===================
|
||||
$(document).on("mouseenter", "tr", function () {
|
||||
// console.log("Mouse entrato su riga");
|
||||
console.log("Mouse entrato su riga");
|
||||
});
|
||||
|
||||
$(document).on("mouseleave", "tr", function () {
|
||||
// console.log("Mouse uscito da riga");
|
||||
console.log("Mouse uscito da riga");
|
||||
});
|
||||
});
|
||||
|
||||
+109
-23
@@ -28,6 +28,7 @@ document.addEventListener("DOMContentLoaded", function () {
|
||||
const webcamVideo = document.getElementById("webcamVideo");
|
||||
const captureBtn = document.getElementById("captureBtn");
|
||||
const closeWebcamBtn = document.getElementById("closeWebcamBtn");
|
||||
const webcamSelect = document.getElementById("webcamSelect");
|
||||
let stream = null;
|
||||
|
||||
if (!navigator.mediaDevices || !navigator.mediaDevices.getUserMedia) {
|
||||
@@ -41,25 +42,116 @@ document.addEventListener("DOMContentLoaded", function () {
|
||||
!webcamArea ||
|
||||
!webcamVideo ||
|
||||
!captureBtn ||
|
||||
!closeWebcamBtn
|
||||
!closeWebcamBtn ||
|
||||
!webcamSelect
|
||||
) {
|
||||
console.error("Elementi webcam mancanti");
|
||||
console.error("Elementi webcam mancanti", {
|
||||
openWebcamBtn,
|
||||
webcamArea,
|
||||
webcamVideo,
|
||||
captureBtn,
|
||||
closeWebcamBtn,
|
||||
webcamSelect,
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
// Apri la webcam
|
||||
openWebcamBtn.addEventListener("click", async () => {
|
||||
// Funzione per avviare la webcam con un deviceId specifico
|
||||
async function startWebcam(deviceId = null) {
|
||||
try {
|
||||
stream = await navigator.mediaDevices.getUserMedia({
|
||||
video: true,
|
||||
});
|
||||
// Ferma il flusso video esistente, se presente
|
||||
if (stream) {
|
||||
stream.getTracks().forEach((track) => track.stop());
|
||||
stream = null;
|
||||
webcamVideo.srcObject = null;
|
||||
}
|
||||
|
||||
// Configura i vincoli per getUserMedia
|
||||
const constraints = {
|
||||
video: deviceId ? { deviceId: { exact: deviceId } } : true,
|
||||
};
|
||||
|
||||
// Avvia il flusso video
|
||||
stream = await navigator.mediaDevices.getUserMedia(constraints);
|
||||
webcamVideo.srcObject = stream;
|
||||
webcamArea.style.display = "block";
|
||||
openWebcamBtn.style.display = "none";
|
||||
dropArea.style.display = "none";
|
||||
} catch (error) {
|
||||
console.error("Errore nell'accesso alla webcam:", error);
|
||||
alert("Errore nell'accesso alla webcam: " + error.message);
|
||||
webcamArea.style.display = "none";
|
||||
openWebcamBtn.style.display = "block";
|
||||
dropArea.style.display = "block";
|
||||
}
|
||||
}
|
||||
|
||||
// Funzione per popolare il dropdown delle webcam
|
||||
async function populateWebcamSelect() {
|
||||
try {
|
||||
// Richiedi i permessi per accedere ai dispositivi
|
||||
await navigator.mediaDevices.getUserMedia({ video: true });
|
||||
const devices = await navigator.mediaDevices.enumerateDevices();
|
||||
const videoDevices = devices.filter(
|
||||
(device) => device.kind === "videoinput",
|
||||
);
|
||||
|
||||
// Svuota il dropdown
|
||||
webcamSelect.innerHTML =
|
||||
'<option value="">Select a webcam</option>';
|
||||
|
||||
// Popola il dropdown con le webcam disponibili
|
||||
videoDevices.forEach((device) => {
|
||||
const option = document.createElement("option");
|
||||
option.value = device.deviceId;
|
||||
option.text =
|
||||
device.label || `Webcam ${webcamSelect.options.length}`;
|
||||
webcamSelect.appendChild(option);
|
||||
});
|
||||
|
||||
// Mostra il dropdown solo se ci sono più webcam
|
||||
webcamSelect.style.display =
|
||||
videoDevices.length > 1 ? "block" : "none";
|
||||
|
||||
// Avvia la webcam predefinita se ce n'è almeno una
|
||||
if (videoDevices.length > 0) {
|
||||
await startWebcam(videoDevices[0].deviceId);
|
||||
} else {
|
||||
alert("Nessuna webcam rilevata.");
|
||||
webcamArea.style.display = "none";
|
||||
openWebcamBtn.style.display = "block";
|
||||
dropArea.style.display = "block";
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Errore nel recupero dei dispositivi:", error);
|
||||
alert("Errore nel recupero dei dispositivi: " + error.message);
|
||||
webcamSelect.style.display = "none";
|
||||
}
|
||||
}
|
||||
|
||||
// Apri la webcam e popola il dropdown
|
||||
openWebcamBtn.addEventListener("click", async () => {
|
||||
await populateWebcamSelect();
|
||||
});
|
||||
|
||||
// Gestisci il cambio della webcam selezionata
|
||||
webcamSelect.addEventListener("change", async (e) => {
|
||||
const deviceId = e.target.value;
|
||||
if (deviceId) {
|
||||
await startWebcam(deviceId);
|
||||
}
|
||||
});
|
||||
|
||||
// Chiudi la webcam
|
||||
closeWebcamBtn.addEventListener("click", () => {
|
||||
if (stream) {
|
||||
stream.getTracks().forEach((track) => track.stop());
|
||||
stream = null;
|
||||
webcamVideo.srcObject = null;
|
||||
}
|
||||
webcamArea.style.display = "none";
|
||||
openWebcamBtn.style.display = "block";
|
||||
dropArea.style.display = "block";
|
||||
});
|
||||
|
||||
// Cattura la foto
|
||||
@@ -71,7 +163,6 @@ document.addEventListener("DOMContentLoaded", function () {
|
||||
.getContext("2d")
|
||||
.drawImage(webcamVideo, 0, 0, canvas.width, canvas.height);
|
||||
|
||||
// Converti l'immagine in un file
|
||||
canvas.toBlob(async (blob) => {
|
||||
const file = new File(
|
||||
[blob],
|
||||
@@ -84,24 +175,16 @@ document.addEventListener("DOMContentLoaded", function () {
|
||||
loader.style.display = "flex";
|
||||
}
|
||||
await handleFiles([file], iddatadb);
|
||||
closeWebcam();
|
||||
}, "image/jpeg");
|
||||
});
|
||||
|
||||
// Chiudi la webcam
|
||||
closeWebcamBtn.addEventListener("click", () => {
|
||||
closeWebcam();
|
||||
});
|
||||
|
||||
function closeWebcam() {
|
||||
if (stream) {
|
||||
stream.getTracks().forEach((track) => track.stop());
|
||||
webcamVideo.srcObject = null;
|
||||
if (stream) {
|
||||
stream.getTracks().forEach((track) => track.stop());
|
||||
stream = null;
|
||||
webcamVideo.srcObject = null;
|
||||
}
|
||||
webcamArea.style.display = "none";
|
||||
openWebcamBtn.style.display = "block";
|
||||
dropArea.style.display = "block";
|
||||
}
|
||||
}
|
||||
}, "image/jpeg");
|
||||
});
|
||||
}
|
||||
|
||||
// Funzione per attaccare gli event listener al contenuto del popup
|
||||
@@ -198,6 +281,9 @@ document.addEventListener("DOMContentLoaded", function () {
|
||||
});
|
||||
const result = await response.json();
|
||||
if (result.success) {
|
||||
console.log(
|
||||
"Foto eliminata con successo, ricarico popup",
|
||||
);
|
||||
loadPopupContent(iddatadb);
|
||||
} else {
|
||||
alert(
|
||||
|
||||
@@ -116,16 +116,19 @@ $result->saveToFile($qrCodeFile);
|
||||
<input type="file" id="photoInput" multiple accept="image/*" style="display: none;">
|
||||
</div>
|
||||
<!-- Area per la webcam -->
|
||||
<!-- Area per la webcam -->
|
||||
<div id="webcamArea" style="display: none; text-align: center; margin-bottom: 20px;">
|
||||
<p>Webcam Preview</p>
|
||||
<select id="webcamSelect" style="margin-bottom: 10px; padding: 5px;">
|
||||
<option value="">Select a webcam</option>
|
||||
</select>
|
||||
<video id="webcamVideo" autoplay playsinline style="max-width: 100%; max-height: 300px;"></video>
|
||||
<div style="margin-top: 10px;">
|
||||
<button id="captureBtn" style="padding: 10px 20px; background: #28a745; color: white; border: none; cursor: pointer;">Capture Photo</button>
|
||||
<button id="closeWebcamBtn" style="padding: 10px 20px; background: #dc3545; color: white; border: none; cursor: pointer;">Close Webcam</button>
|
||||
</div>
|
||||
</div>
|
||||
<button id="openWebcamBtn" style="padding: 10px 20px; background: #007bff; color: white; border: none; cursor: pointer; margin-bottom: 20px;">Take Photo with Webcam</button>
|
||||
<!-- Elenco delle foto -->
|
||||
<button id="openWebcamBtn" style="padding: 10px 20px; background: #007bff; color: white; border: none; cursor: pointer; margin-bottom: 20px;">Take Photo with Webcam</button> <!-- Elenco delle foto -->
|
||||
<div id="photosList">
|
||||
<?php if (empty($photos)): ?>
|
||||
<p>No Photos present.</p>
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
header('Content-Type: application/json');
|
||||
|
||||
$photo_path = $_POST['photo_path'] ?? '';
|
||||
$iddatadb = $_POST['iddatadb'] ?? '';
|
||||
|
||||
if (empty($photo_path) || empty($iddatadb)) {
|
||||
echo json_encode(['success' => false, 'message' => 'Parametri mancanti']);
|
||||
exit;
|
||||
}
|
||||
|
||||
// Verifica che il file esista
|
||||
$full_path = realpath($photo_path);
|
||||
if (!$full_path || !file_exists($full_path)) {
|
||||
echo json_encode(['success' => false, 'message' => 'File non trovato']);
|
||||
exit;
|
||||
}
|
||||
|
||||
// Configurazione Remove.bg API
|
||||
$api_key = 'YOUR_API_KEY'; // Inserisci la tua chiave API di Remove.bg
|
||||
$api_url = 'https://api.remove.bg/v1.0/removebg';
|
||||
|
||||
// Preparazione della richiesta
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, $api_url);
|
||||
curl_setopt($ch, CURLOPT_POST, true);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, [
|
||||
'image_file' => new CURLFile($full_path),
|
||||
'size' => 'auto',
|
||||
]);
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, [
|
||||
'X-Api-Key: ' . $api_key
|
||||
]);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
|
||||
// Esecuzione della richiesta
|
||||
$response = curl_exec($ch);
|
||||
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
curl_close($ch);
|
||||
|
||||
if ($http_code !== 200) {
|
||||
echo json_encode(['success' => false, 'message' => 'Errore API Remove.bg']);
|
||||
exit;
|
||||
}
|
||||
|
||||
// Salva l'immagine senza sfondo
|
||||
$timestamp = date('YmdHis');
|
||||
$new_filename = "no_bg_photo_{$iddatadb}_{$timestamp}.png";
|
||||
$new_filepath = "uploads/{$new_filename}"; // Assumi una directory Uploads/
|
||||
file_put_contents($new_filepath, $response);
|
||||
|
||||
// Aggiorna il database o il sistema di file con il nuovo percorso
|
||||
// Qui potresti aggiungere logica per aggiornare il database con il nuovo percorso
|
||||
|
||||
echo json_encode(['success' => true, 'new_photo_path' => $new_filepath]);
|
||||
Reference in New Issue
Block a user