Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 6a652af086 | |||
| 1303cff9fd | |||
| 6b2bd0964b | |||
| 0d2cf13524 | |||
| f6ef9c39d2 |
@@ -31,6 +31,6 @@ Content-Length: 51
|
|||||||
< strict-transport-security: max-age=2592000
|
< strict-transport-security: max-age=2592000
|
||||||
< x-powered-by: ASP.NET
|
< x-powered-by: ASP.NET
|
||||||
< x-content-type-options: nosniff
|
< x-content-type-options: nosniff
|
||||||
< date: Thu, 21 Aug 2025 10:23:44 GMT
|
< date: Fri, 29 Aug 2025 14:28:29 GMT
|
||||||
<
|
<
|
||||||
* Connection #0 to host 93.43.5.102 left intact
|
* Connection #0 to host 93.43.5.102 left intact
|
||||||
|
|||||||
@@ -15,11 +15,11 @@
|
|||||||
* [HTTP/2] [1] [:scheme: https]
|
* [HTTP/2] [1] [:scheme: https]
|
||||||
* [HTTP/2] [1] [:authority: 93.43.5.102]
|
* [HTTP/2] [1] [:authority: 93.43.5.102]
|
||||||
* [HTTP/2] [1] [:path: /limsapi/api/odata/CustomField(1083)?$expand=CustomFieldsValues]
|
* [HTTP/2] [1] [:path: /limsapi/api/odata/CustomField(1083)?$expand=CustomFieldsValues]
|
||||||
* [HTTP/2] [1] [authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJodHRwOi8vc2NoZW1hcy54bWxzb2FwLm9yZy93cy8yMDA1LzA1L2lkZW50aXR5L2NsYWltcy9uYW1laWRlbnRpZmllciI6IjQ5MiIsIlhhZlNlY3VyaXR5QXV0aFBhc3NlZCI6IlhhZlNlY3VyaXR5QXV0aFBhc3NlZCIsImh0dHA6Ly9zY2hlbWFzLnhtbHNvYXAub3JnL3dzLzIwMDUvMDUvaWRlbnRpdHkvY2xhaW1zL25hbWUiOiJXZWJBcGlVc2VyIiwiWGFmU2VjdXJpdHkiOiJYYWZTZWN1cml0eSIsIlhhZkxvZ29uUGFyYW1zIjoicTFZS0xVNHQ4a3ZNVFZXeVVncFBUWElzeUFRSktPa29CU1FXRjVmbkY2VUF4Y3RUa3hJTE1rdUI0Z2FHU3JVQSIsImV4cCI6MTc1NTc3OTAyNSwiaXNzIjoiTXkiLCJhdWQiOiJodHRwOi8vbG9jYWxob3N0OjQyMDAifQ.bBV1z1uaxZeUuw-2YS2gLGaxTCQJAHTieM82KVJb5nw]
|
* [HTTP/2] [1] [authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJodHRwOi8vc2NoZW1hcy54bWxzb2FwLm9yZy93cy8yMDA1LzA1L2lkZW50aXR5L2NsYWltcy9uYW1laWRlbnRpZmllciI6IjQ5MiIsIlhhZlNlY3VyaXR5QXV0aFBhc3NlZCI6IlhhZlNlY3VyaXR5QXV0aFBhc3NlZCIsImh0dHA6Ly9zY2hlbWFzLnhtbHNvYXAub3JnL3dzLzIwMDUvMDUvaWRlbnRpdHkvY2xhaW1zL25hbWUiOiJXZWJBcGlVc2VyIiwiWGFmU2VjdXJpdHkiOiJYYWZTZWN1cml0eSIsIlhhZkxvZ29uUGFyYW1zIjoicTFZS0xVNHQ4a3ZNVFZXeVVncFBUWElzeUFRSktPa29CU1FXRjVmbkY2VUF4Y3RUa3hJTE1rdUI0Z2FHU3JVQSIsImV4cCI6MTc1NjQ4NDkwOSwiaXNzIjoiTXkiLCJhdWQiOiJodHRwOi8vbG9jYWxob3N0OjQyMDAifQ.VPLdAAvg-D2ReaPr7erRrgX70RQsySvuBXN284HFQ74]
|
||||||
* [HTTP/2] [1] [accept: application/json]
|
* [HTTP/2] [1] [accept: application/json]
|
||||||
> GET /limsapi/api/odata/CustomField(1083)?$expand=CustomFieldsValues HTTP/2
|
> GET /limsapi/api/odata/CustomField(1083)?$expand=CustomFieldsValues HTTP/2
|
||||||
Host: 93.43.5.102
|
Host: 93.43.5.102
|
||||||
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJodHRwOi8vc2NoZW1hcy54bWxzb2FwLm9yZy93cy8yMDA1LzA1L2lkZW50aXR5L2NsYWltcy9uYW1laWRlbnRpZmllciI6IjQ5MiIsIlhhZlNlY3VyaXR5QXV0aFBhc3NlZCI6IlhhZlNlY3VyaXR5QXV0aFBhc3NlZCIsImh0dHA6Ly9zY2hlbWFzLnhtbHNvYXAub3JnL3dzLzIwMDUvMDUvaWRlbnRpdHkvY2xhaW1zL25hbWUiOiJXZWJBcGlVc2VyIiwiWGFmU2VjdXJpdHkiOiJYYWZTZWN1cml0eSIsIlhhZkxvZ29uUGFyYW1zIjoicTFZS0xVNHQ4a3ZNVFZXeVVncFBUWElzeUFRSktPa29CU1FXRjVmbkY2VUF4Y3RUa3hJTE1rdUI0Z2FHU3JVQSIsImV4cCI6MTc1NTc3OTAyNSwiaXNzIjoiTXkiLCJhdWQiOiJodHRwOi8vbG9jYWxob3N0OjQyMDAifQ.bBV1z1uaxZeUuw-2YS2gLGaxTCQJAHTieM82KVJb5nw
|
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJodHRwOi8vc2NoZW1hcy54bWxzb2FwLm9yZy93cy8yMDA1LzA1L2lkZW50aXR5L2NsYWltcy9uYW1laWRlbnRpZmllciI6IjQ5MiIsIlhhZlNlY3VyaXR5QXV0aFBhc3NlZCI6IlhhZlNlY3VyaXR5QXV0aFBhc3NlZCIsImh0dHA6Ly9zY2hlbWFzLnhtbHNvYXAub3JnL3dzLzIwMDUvMDUvaWRlbnRpdHkvY2xhaW1zL25hbWUiOiJXZWJBcGlVc2VyIiwiWGFmU2VjdXJpdHkiOiJYYWZTZWN1cml0eSIsIlhhZkxvZ29uUGFyYW1zIjoicTFZS0xVNHQ4a3ZNVFZXeVVncFBUWElzeUFRSktPa29CU1FXRjVmbkY2VUF4Y3RUa3hJTE1rdUI0Z2FHU3JVQSIsImV4cCI6MTc1NjQ4NDkwOSwiaXNzIjoiTXkiLCJhdWQiOiJodHRwOi8vbG9jYWxob3N0OjQyMDAifQ.VPLdAAvg-D2ReaPr7erRrgX70RQsySvuBXN284HFQ74
|
||||||
Accept: application/json
|
Accept: application/json
|
||||||
|
|
||||||
< HTTP/2 200
|
< HTTP/2 200
|
||||||
@@ -30,6 +30,6 @@ Accept: application/json
|
|||||||
< odata-version: 4.0
|
< odata-version: 4.0
|
||||||
< x-powered-by: ASP.NET
|
< x-powered-by: ASP.NET
|
||||||
< x-content-type-options: nosniff
|
< x-content-type-options: nosniff
|
||||||
< date: Thu, 21 Aug 2025 10:23:44 GMT
|
< date: Fri, 29 Aug 2025 14:28:33 GMT
|
||||||
<
|
<
|
||||||
* Connection #0 to host 93.43.5.102 left intact
|
* Connection #0 to host 93.43.5.102 left intact
|
||||||
|
|||||||
+294
-148
@@ -499,6 +499,22 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
|
|||||||
.proceed-btn {
|
.proceed-btn {
|
||||||
margin-top: 20px;
|
margin-top: 20px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.grid-cell.button-cell,
|
||||||
|
.grid-header.button-header {
|
||||||
|
min-width: 210px !important;
|
||||||
|
flex: 0 0 210px !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.action-btn {
|
||||||
|
padding: 6px 8px;
|
||||||
|
margin-right: 5px;
|
||||||
|
border: none;
|
||||||
|
border-radius: 5px;
|
||||||
|
cursor: pointer;
|
||||||
|
width: 50px;
|
||||||
|
box-sizing: border-box;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
<title>Dati Storici - <?= htmlspecialchars($titlewebsite, ENT_QUOTES, 'UTF-8'); ?></title>
|
<title>Dati Storici - <?= htmlspecialchars($titlewebsite, ENT_QUOTES, 'UTF-8'); ?></title>
|
||||||
</head>
|
</head>
|
||||||
@@ -610,142 +626,190 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
|
|||||||
</div>
|
</div>
|
||||||
<div id="noResults" class="text-danger" style="display:none;">Nessun risultato trovato</div>
|
<div id="noResults" class="text-danger" style="display:none;">Nessun risultato trovato</div>
|
||||||
<div class="scrollbar-container"></div>
|
<div class="scrollbar-container"></div>
|
||||||
|
|
||||||
<form id="editForm">
|
<form id="editForm">
|
||||||
<div class="grid-container">
|
<div class="grid-container">
|
||||||
<?php $fixedColumns = ['filename_import', 'status', 'importdate']; ?>
|
<div class="grid-top">
|
||||||
<?php if ($status === 'i'): ?>
|
<div class="grid-cell actions-cell" style="flex: 0 0 200px;"></div>
|
||||||
<div class="grid-top">
|
<?php
|
||||||
<div class="grid-cell" style="flex: 0 0 100px;"></div>
|
// Campo con main_field = 1
|
||||||
<div class="grid-cell" style="flex: 0 0 100px;"></div>
|
if ($mainFieldMapping) {
|
||||||
<div class="grid-cell" style="flex: 0 0 100px;"></div>
|
$inputClass = $mainFieldMapping['is_manual'] ? 'manual-input' : 'auto-input';
|
||||||
<div class="grid-cell" style="flex: 0 0 150px;"></div>
|
if ($mainFieldMapping['is_required']) $inputClass .= ' required-input';
|
||||||
<?php
|
$index = $mainFieldMapping['is_manual'] ? "manual_0" : "auto_0";
|
||||||
foreach ($fixedColumns as $col) {
|
echo "<div class='grid-cell' style='flex: 0 0 150px;'>";
|
||||||
echo "<div class='grid-cell' style='flex: 0 0 150px;'></div>";
|
if ($mainFieldMapping['data_type'] === 'SceltaMultipla') {
|
||||||
}
|
$fieldValue = $mainFieldMapping['manual_default'] ?? '';
|
||||||
$autoIndex = 0;
|
echo "<select class='custom-field dropdown-select $inputClass' data-column='$index' data-field-id='{$mainFieldMapping['field_id']}' data-selected-value='" . htmlspecialchars($fieldValue) . "' " . ($mainFieldMapping['is_required'] ? 'required' : '') . ($is_readonly ? ' readonly' : '') . ">";
|
||||||
foreach ($allMappings as $mapping) {
|
echo "<option value=''>Seleziona...</option>";
|
||||||
if (!$mapping['is_manual']) {
|
echo "</select>";
|
||||||
$inputClass = 'auto-input';
|
echo "<button type='button' class='propagate-btn' data-column='$index' " . ($is_readonly ? 'disabled' : '') . "><i class='fas fa-arrow-down'></i></button>";
|
||||||
if ($mapping['is_required']) $inputClass .= ' required-input';
|
} else {
|
||||||
if ($mapping['data_type'] === 'SceltaMultipla') {
|
$fieldValue = $mainFieldMapping['manual_default'] ?? '';
|
||||||
echo "<div class='grid-cell' style='flex: 0 0 150px;'>";
|
if ($mainFieldMapping['data_type'] === 'DATE' && $mainFieldMapping['manual_default'] === 'today') {
|
||||||
echo "<select class='custom-field dropdown-select $inputClass' data-column='auto_$autoIndex' data-field-id='{$mapping['field_id']}' " . ($mapping['is_required'] ? 'required' : '') . ($is_readonly ? ' readonly' : '') . ">";
|
$fieldValue = date('Y-m-d');
|
||||||
echo "<option value=''>Seleziona...</option>";
|
|
||||||
echo "</select>";
|
|
||||||
echo "<button type='button' class='propagate-btn' data-column='auto_$autoIndex' " . ($is_readonly ? 'disabled' : '') . "><i class='fas fa-arrow-down'></i></button>";
|
|
||||||
echo "</div>";
|
|
||||||
} else {
|
|
||||||
echo "<div class='grid-cell' style='flex: 0 0 150px;'></div>";
|
|
||||||
}
|
|
||||||
$autoIndex++;
|
|
||||||
}
|
}
|
||||||
|
if ($mainFieldMapping['data_type'] === 'DATE') {
|
||||||
|
echo "<input type='date' class='custom-field $inputClass' data-column='$index' value='" . htmlspecialchars($fieldValue) . "' " . ($mainFieldMapping['is_required'] ? 'required' : '') . ($is_readonly ? ' readonly' : '') . ">";
|
||||||
|
} elseif ($mainFieldMapping['data_type'] === 'INT') {
|
||||||
|
echo "<input type='number' class='custom-field $inputClass' data-column='$index' value='" . htmlspecialchars($fieldValue) . "' " . ($mainFieldMapping['is_required'] ? 'required' : '') . ($is_readonly ? ' readonly' : '') . ">";
|
||||||
|
} else {
|
||||||
|
echo "<input type='text' class='custom-field $inputClass' data-column='$index' value='" . htmlspecialchars($fieldValue) . "' " . ($mainFieldMapping['is_required'] ? 'required' : '') . ($is_readonly ? ' readonly' : '') . ">";
|
||||||
|
}
|
||||||
|
echo "<button type='button' class='propagate-btn' data-column='$index' " . ($is_readonly ? 'disabled' : '') . "><i class='fas fa-arrow-down'></i></button>";
|
||||||
}
|
}
|
||||||
$manualIndex = 0;
|
echo "</div>";
|
||||||
foreach ($allMappings as $mapping) {
|
} else {
|
||||||
if ($mapping['is_manual']) {
|
echo "<div class='grid-cell' style='flex: 0 0 150px;'></div>";
|
||||||
|
}
|
||||||
|
// Campi automatici (escluso main_field)
|
||||||
|
$autoIndex = ($mainFieldMapping && !$mainFieldMapping['is_manual']) ? 1 : 0;
|
||||||
|
foreach ($allMappings as $mapping) {
|
||||||
|
if (!$mapping['is_manual'] && $mapping['main_field'] != 1) {
|
||||||
|
$inputClass = 'auto-input';
|
||||||
|
if ($mapping['is_required']) $inputClass .= ' required-input';
|
||||||
|
echo "<div class='grid-cell' style='flex: 0 0 150px;'>";
|
||||||
|
if ($mapping['data_type'] === 'SceltaMultipla') {
|
||||||
$fieldValue = $mapping['manual_default'] ?? '';
|
$fieldValue = $mapping['manual_default'] ?? '';
|
||||||
if ($mapping['data_type'] === 'DATE' && $mapping['manual_default'] === 'today') {
|
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' : '') . ($is_readonly ? ' readonly' : '') . ">";
|
||||||
$fieldValue = date('Y-m-d');
|
echo "<option value=''>Seleziona...</option>";
|
||||||
}
|
echo "</select>";
|
||||||
$inputClass = 'manual-input';
|
echo "<button type='button' class='propagate-btn' data-column='auto_$autoIndex' " . ($is_readonly ? 'disabled' : '') . "><i class='fas fa-arrow-down'></i></button>";
|
||||||
if ($mapping['is_required']) $inputClass .= ' required-input';
|
} else {
|
||||||
echo "<div class='grid-cell' style='flex: 0 0 150px;'>";
|
echo "<div style='height: 34px;'></div>";
|
||||||
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' : '') . ($is_readonly ? ' readonly' : '') . ">";
|
|
||||||
echo "<option value=''>Seleziona...</option>";
|
|
||||||
echo "</select>";
|
|
||||||
echo "<button type='button' class='propagate-btn' data-column='manual_$manualIndex' " . ($is_readonly ? 'disabled' : '') . "><i class='fas fa-arrow-down'></i></button>";
|
|
||||||
} elseif ($mapping['data_type'] === 'DATE') {
|
|
||||||
echo "<input type='date' class='custom-field $inputClass' data-column='manual_$manualIndex' value='" . htmlspecialchars($fieldValue) . "' " . ($mapping['is_required'] ? 'required' : '') . ($is_readonly ? ' readonly' : '') . ">";
|
|
||||||
} elseif ($mapping['data_type'] === 'INT') {
|
|
||||||
echo "<input type='number' class='custom-field $inputClass' data-column='manual_$manualIndex' value='" . htmlspecialchars($fieldValue) . "' " . ($mapping['is_required'] ? 'required' : '') . ($is_readonly ? ' readonly' : '') . ">";
|
|
||||||
} else {
|
|
||||||
echo "<input type='text' class='custom-field $inputClass' data-column='manual_$manualIndex' value='" . htmlspecialchars($fieldValue) . "' " . ($mapping['is_required'] ? 'required' : '') . ($is_readonly ? ' readonly' : '') . ">";
|
|
||||||
}
|
|
||||||
echo "<button type='button' class='propagate-btn' data-column='manual_$manualIndex' " . ($is_readonly ? 'disabled' : '') . "><i class='fas fa-arrow-down'></i></button>";
|
|
||||||
echo "</div>";
|
|
||||||
$manualIndex++;
|
|
||||||
}
|
}
|
||||||
|
echo "</div>";
|
||||||
|
$autoIndex++;
|
||||||
}
|
}
|
||||||
echo "<div class='grid-cell' style='flex: 0 0 200px;'></div>";
|
}
|
||||||
echo "<div class='grid-cell' style='flex: 0 0 250px;'></div>";
|
// Campi manuali (escluso main_field)
|
||||||
?>
|
$manualIndex = ($mainFieldMapping && $mainFieldMapping['is_manual']) ? 1 : 0;
|
||||||
</div>
|
foreach ($allMappings as $mapping) {
|
||||||
<?php endif; ?>
|
if ($mapping['is_manual'] && $mapping['main_field'] != 1) {
|
||||||
|
$fieldValue = $mapping['manual_default'] ?? '';
|
||||||
|
if ($mapping['data_type'] === 'DATE' && $mapping['manual_default'] === 'today') {
|
||||||
|
$fieldValue = date('Y-m-d');
|
||||||
|
}
|
||||||
|
$inputClass = 'manual-input';
|
||||||
|
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']}' data-selected-value='" . htmlspecialchars($fieldValue) . "' " . ($mapping['is_required'] ? 'required' : '') . ($is_readonly ? ' readonly' : '') . ">";
|
||||||
|
echo "<option value=''>Seleziona...</option>";
|
||||||
|
echo "</select>";
|
||||||
|
echo "<button type='button' class='propagate-btn' data-column='manual_$manualIndex' " . ($is_readonly ? 'disabled' : '') . "><i class='fas fa-arrow-down'></i></button>";
|
||||||
|
} elseif ($mapping['data_type'] === 'DATE') {
|
||||||
|
echo "<input type='date' class='custom-field $inputClass' data-column='manual_$manualIndex' value='" . htmlspecialchars($fieldValue) . "' " . ($mapping['is_required'] ? 'required' : '') . ($is_readonly ? ' readonly' : '') . ">";
|
||||||
|
echo "<button type='button' class='propagate-btn' data-column='manual_$manualIndex' " . ($is_readonly ? 'disabled' : '') . "><i class='fas fa-arrow-down'></i></button>";
|
||||||
|
} elseif ($mapping['data_type'] === 'INT') {
|
||||||
|
echo "<input type='number' class='custom-field $inputClass' data-column='manual_$manualIndex' value='" . htmlspecialchars($fieldValue) . "' " . ($mapping['is_required'] ? 'required' : '') . ($is_readonly ? ' readonly' : '') . ">";
|
||||||
|
echo "<button type='button' class='propagate-btn' data-column='manual_$manualIndex' " . ($is_readonly ? 'disabled' : '') . "><i class='fas fa-arrow-down'></i></button>";
|
||||||
|
} else {
|
||||||
|
echo "<input type='text' class='custom-field $inputClass' data-column='manual_$manualIndex' value='" . htmlspecialchars($fieldValue) . "' " . ($mapping['is_required'] ? 'required' : '') . ($is_readonly ? ' readonly' : '') . ">";
|
||||||
|
echo "<button type='button' class='propagate-btn' data-column='manual_$manualIndex' " . ($is_readonly ? 'disabled' : '') . "><i class='fas fa-arrow-down'></i></button>";
|
||||||
|
}
|
||||||
|
echo "</div>";
|
||||||
|
$manualIndex++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Colonne status, Import Reference Code, filename_import
|
||||||
|
$fixedColumnsReduced = ['status'];
|
||||||
|
foreach ($fixedColumnsReduced as $col) {
|
||||||
|
echo "<div class='grid-cell' style='flex: 0 0 150px;'></div>";
|
||||||
|
}
|
||||||
|
echo "<div class='grid-cell' style='flex: 0 0 150px;'></div>"; // Import Reference Code
|
||||||
|
echo "<div class='grid-cell' style='flex: 0 0 150px;'></div>"; // filename_import
|
||||||
|
// AWB Number e Tracking Info
|
||||||
|
echo "<div class='grid-cell' style='flex: 0 0 200px;'></div>";
|
||||||
|
echo "<div class='grid-cell' style='flex: 0 0 250px;'></div>";
|
||||||
|
?>
|
||||||
|
</div>
|
||||||
<div class="grid-row">
|
<div class="grid-row">
|
||||||
<div class="grid-header" style="flex: 0 0 100px;">Save</div>
|
<div class="grid-header actions-cell" style="flex: 0 0 200px; position: relative;">Azioni<div class="resizer"></div>
|
||||||
<div class="grid-header" style="flex: 0 0 100px;">Photos</div>
|
|
||||||
<div class="grid-header" style="flex: 0 0 100px;">Parts</div>
|
|
||||||
<div class="grid-header" data-index="3" style="flex: 0 0 150px; position: relative;">Import Reference Code<div class="resizer"></div>
|
|
||||||
</div>
|
</div>
|
||||||
<?php
|
<?php
|
||||||
$headerIndex = 4;
|
// Header per il campo main_field = 1
|
||||||
foreach ($fixedColumns as $col) {
|
$headerIndex = 1;
|
||||||
|
if ($mainFieldMapping) {
|
||||||
|
echo "<div class='grid-header' data-index='$headerIndex' style='flex: 0 0 150px; position: relative;'>" . htmlspecialchars($mainFieldMapping['field_label']) . "<div class='resizer'></div></div>";
|
||||||
|
$headerIndex++;
|
||||||
|
}
|
||||||
|
// Header per campi automatici (escluso main_field)
|
||||||
|
foreach ($allMappings as $mapping) {
|
||||||
|
if (!$mapping['is_manual'] && $mapping['main_field'] != 1) {
|
||||||
|
echo "<div class='grid-header' data-index='$headerIndex' style='flex: 0 0 150px; position: relative;'>" . htmlspecialchars($mapping['field_label']) . "<div class='resizer'></div></div>";
|
||||||
|
$headerIndex++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Header per campi manuali (escluso main_field)
|
||||||
|
foreach ($allMappings as $mapping) {
|
||||||
|
if ($mapping['is_manual'] && $mapping['main_field'] != 1) {
|
||||||
|
echo "<div class='grid-header' data-index='$headerIndex' style='flex: 0 0 150px; position: relative;'>" . htmlspecialchars($mapping['field_label']) . "<div class='resizer'></div></div>";
|
||||||
|
$headerIndex++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Header per status, Import Reference Code, filename_import
|
||||||
|
foreach ($fixedColumnsReduced as $col) {
|
||||||
$displayName = $slugMapping[$col] ?? $col;
|
$displayName = $slugMapping[$col] ?? $col;
|
||||||
echo "<div class='grid-header' data-index='$headerIndex' style='flex: 0 0 150px; position: relative;'>$displayName<div class='resizer'></div></div>";
|
echo "<div class='grid-header' data-index='$headerIndex' style='flex: 0 0 150px; position: relative;'>$displayName<div class='resizer'></div></div>";
|
||||||
$headerIndex++;
|
$headerIndex++;
|
||||||
}
|
}
|
||||||
foreach ($allMappings as $mapping) {
|
echo "<div class='grid-header' data-index='$headerIndex' style='flex: 0 0 150px; position: relative;'>Import Reference Code<div class='resizer'></div></div>";
|
||||||
if (!$mapping['is_manual']) {
|
$headerIndex++;
|
||||||
echo "<div class='grid-header' data-index='$headerIndex' style='flex: 0 0 150px; position: relative;'>" . htmlspecialchars($mapping['field_label']) . "<div class='resizer'></div></div>";
|
echo "<div class='grid-header' data-index='$headerIndex' style='flex: 0 0 150px; position: relative;'>File<div class='resizer'></div></div>";
|
||||||
$headerIndex++;
|
$headerIndex++;
|
||||||
}
|
// Header per AWB Number e Tracking Info
|
||||||
}
|
|
||||||
foreach ($allMappings as $mapping) {
|
|
||||||
if ($mapping['is_manual']) {
|
|
||||||
echo "<div class='grid-header' data-index='$headerIndex' style='flex: 0 0 150px; position: relative;'>" . htmlspecialchars($mapping['field_label']) . "<div class='resizer'></div></div>";
|
|
||||||
$headerIndex++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
echo "<div class='grid-header' data-index='$headerIndex' style='flex: 0 0 200px; position: relative;'>AWB Number<div class='resizer'></div></div>";
|
echo "<div class='grid-header' data-index='$headerIndex' style='flex: 0 0 200px; position: relative;'>AWB Number<div class='resizer'></div></div>";
|
||||||
echo "<div class='grid-header' data-index='" . ($headerIndex + 1) . "' style='flex: 0 0 250px; position: relative;'>Tracking Info<div class='resizer'></div></div>";
|
$headerIndex++;
|
||||||
|
echo "<div class='grid-header' data-index='$headerIndex' style='flex: 0 0 250px; position: relative;'>Tracking Info<div class='resizer'></div></div>";
|
||||||
?>
|
?>
|
||||||
</div>
|
</div>
|
||||||
<?php foreach ($importedData as $index => $row): ?>
|
<?php foreach ($importedData as $index => $row): ?>
|
||||||
<div class="grid-row" data-id="<?= $row['iddatadb'] ?>">
|
<div class="grid-row" data-id="<?= $row['iddatadb'] ?>">
|
||||||
<div class="grid-cell" style="flex: 0 0 100px; position: relative;">
|
<div class="grid-cell actions-cell" style="flex: 0 0 200px; position: relative;">
|
||||||
<?php if (!$is_readonly): ?>
|
<div style="display: flex; gap: 5px; justify-content: center;">
|
||||||
<button type="button" class="save-btn action-btn" data-row="<?= $index ?>" style="background: #28a745; color: white; border: none; padding: 8px 12px; border-radius: 5px; cursor: pointer; width: 100%; box-sizing: border-box;"><i class="fas fa-save"></i></button>
|
<?php if (!$is_readonly): ?>
|
||||||
<?php else: ?>
|
<button type="button" class="save-btn action-btn" data-row="<?= $index ?>" style="background: #28a745; color: white; border: none; padding: 8px 12px; border-radius: 5px; cursor: pointer; flex: 1;"><i class="fas fa-save"></i></button>
|
||||||
<button type="button" class="save-btn action-btn" data-row="<?= $index ?>" style="background: #ccc; color: white; border: none; padding: 8px 12px; border-radius: 5px; cursor: not-allowed; width: 100%; box-sizing: border-box;" disabled><i class="fas fa-save"></i></button>
|
<button type="button" class="photos-btn action-btn" data-row="<?= $index ?>" data-iddatadb="<?= $row['iddatadb'] ?>" style="background: #007bff; color: white; border: none; padding: 8px 12px; border-radius: 5px; cursor: pointer; flex: 1;"><i class="fas fa-camera"></i></button>
|
||||||
<?php endif; ?>
|
<button type="button" class="parts-btn action-btn" data-row="<?= $index ?>" data-iddatadb="<?= $row['iddatadb'] ?>" style="background: #ffc107; color: white; border: none; padding: 8px 12px; border-radius: 5px; cursor: pointer; flex: 1;"><i class="fas fa-puzzle-piece"></i></button>
|
||||||
</div>
|
<?php else: ?>
|
||||||
<div class="grid-cell" style="flex: 0 0 100px; position: relative;">
|
<button type="button" class="save-btn action-btn" data-row="<?= $index ?>" style="background: #ccc; color: white; border: none; padding: 8px 12px; border-radius: 5px; cursor: not-allowed; flex: 1;" disabled><i class="fas fa-save"></i></button>
|
||||||
<button type="button" class="photos-btn action-btn" data-row="<?= $index ?>" data-iddatadb="<?= $row['iddatadb'] ?>" style="background: #007bff; color: white; border: none; padding: 8px 12px; border-radius: 5px; cursor: pointer; width: 100%; box-sizing: border-box;"><i class="fas fa-camera"></i></button>
|
<button type="button" class="photos-btn action-btn" data-row="<?= $index ?>" data-iddatadb="<?= $row['iddatadb'] ?>" style="background: #ccc; color: white; border: none; padding: 8px 12px; border-radius: 5px; cursor: not-allowed; flex: 1;" disabled><i class="fas fa-camera"></i></button>
|
||||||
</div>
|
<button type="button" class="parts-btn action-btn" data-row="<?= $index ?>" data-iddatadb="<?= $row['iddatadb'] ?>" style="background: #ccc; color: white; border: none; padding: 8px 12px; border-radius: 5px; cursor: not-allowed; flex: 1;" disabled><i class="fas fa-puzzle-piece"></i></button>
|
||||||
<div class="grid-cell" style="flex: 0 0 100px; position: relative;">
|
<?php endif; ?>
|
||||||
<button type="button" class="parts-btn action-btn" data-row="<?= $index ?>" data-iddatadb="<?= $row['iddatadb'] ?>" style="background: #ffc107; color: white; border: none; padding: 8px 12px; border-radius: 5px; cursor: pointer; width: 100%; box-sizing: border-box;"><i class="fas fa-puzzle-piece"></i></button>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<?php
|
<?php
|
||||||
$cellIndex = 3;
|
$cellIndex = 1;
|
||||||
echo "<div class='grid-cell' data-col='importreferencecode' data-row='$index' data-index='$cellIndex' style='flex: 0 0 150px;'>";
|
$rowDetails = array_filter($manualDetails, fn($d) => $d['datadb_id'] == $row['iddatadb']);
|
||||||
echo "<span>" . htmlspecialchars($row['importreferencecode']) . "</span>";
|
// Campo con main_field = 1
|
||||||
echo "<input type='hidden' name='rows[$index][importreferencecode]' value='" . htmlspecialchars($row['importreferencecode']) . "'>";
|
if ($mainFieldMapping) {
|
||||||
echo "</div>";
|
$detail = array_filter($rowDetails, fn($d) => $d['mapping_id'] == $mainFieldMapping['id']);
|
||||||
$cellIndex++;
|
$detail = reset($detail) ?: ['field_value' => $mainFieldMapping['manual_default']];
|
||||||
foreach ($fixedColumns as $col) {
|
$fieldValue = $detail['field_value'] ?? $mainFieldMapping['manual_default'] ?? '';
|
||||||
$value = $row[$col] ?? '';
|
$requiredClass = ($mainFieldMapping['is_required'] && (is_null($fieldValue) || $fieldValue === '')) ? 'missing-required' : '';
|
||||||
echo "<div class='grid-cell editable-cell' data-col='$col' data-row='$index' data-index='$cellIndex' style='flex: 0 0 150px;'>";
|
$inputClass = $mainFieldMapping['is_manual'] ? 'manual-input' : 'auto-input';
|
||||||
if ($col === 'importdate') {
|
if ($mainFieldMapping['is_required']) $inputClass .= ' required-input';
|
||||||
echo "<span>" . htmlspecialchars($value) . "</span>";
|
$indexField = $mainFieldMapping['is_manual'] ? "manual_0" : "auto_0";
|
||||||
echo "<input type='hidden' name='rows[$index][$col]' value='" . htmlspecialchars($value) . "'>";
|
echo "<div class='grid-cell editable-cell $requiredClass' data-col='$indexField' data-row='$index' data-index='$cellIndex' style='flex: 0 0 150px;'>";
|
||||||
} elseif ($col === 'filename_import') {
|
if ($mainFieldMapping['data_type'] === 'SceltaMultipla') {
|
||||||
echo "<a href='imported_trf/" . htmlspecialchars($value) . "' target='_blank'>File</a>";
|
echo "<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' : '') . ($is_readonly ? ' readonly' : '') . ">";
|
||||||
echo "<input type='hidden' name='rows[$index][$col]' value='" . htmlspecialchars($value) . "'>";
|
echo "<option value=''>Seleziona...</option>";
|
||||||
} elseif ($col === 'status') {
|
echo "</select>";
|
||||||
$badgeClass = $value === 'i' ? 'status-i' : ($value === 'P' ? 'status-P' : 'status-l');
|
} elseif ($mainFieldMapping['data_type'] === 'DATE') {
|
||||||
$badgeText = $value === 'i' ? 'Imported' : ($value === 'P' ? 'Progress' : 'LIMS');
|
echo "<input type='date' name='rows[$index][details][{$mainFieldMapping['id']}][field_value]' value='" . htmlspecialchars($fieldValue) . "' class='cell-input $inputClass' " . ($mainFieldMapping['is_required'] ? 'required' : '') . ($is_readonly ? ' readonly' : '') . ">";
|
||||||
echo "<span class='status-badge $badgeClass'>" . htmlspecialchars($badgeText) . "</span>";
|
} elseif ($mainFieldMapping['data_type'] === 'INT') {
|
||||||
echo "<input type='hidden' name='rows[$index][$col]' value='" . htmlspecialchars($value ?? 'i') . "'>";
|
echo "<input type='number' name='rows[$index][details][{$mainFieldMapping['id']}][field_value]' value='" . htmlspecialchars($fieldValue) . "' class='cell-input $inputClass' " . ($mainFieldMapping['is_required'] ? 'required' : '') . ($is_readonly ? ' readonly' : '') . ">";
|
||||||
|
} else {
|
||||||
|
echo "<input type='text' name='rows[$index][details][{$mainFieldMapping['id']}][field_value]' value='" . htmlspecialchars($fieldValue) . "' class='cell-input $inputClass' " . ($mainFieldMapping['is_required'] ? 'required' : '') . ($is_readonly ? ' readonly' : '') . ">";
|
||||||
}
|
}
|
||||||
echo "</div>";
|
echo "</div>";
|
||||||
$cellIndex++;
|
$cellIndex++;
|
||||||
}
|
}
|
||||||
$rowDetails = array_filter($manualDetails, fn($d) => $d['datadb_id'] == $row['iddatadb']);
|
// Campi automatici (escluso main_field)
|
||||||
$autoIndex = 0;
|
$autoIndex = ($mainFieldMapping && !$mainFieldMapping['is_manual']) ? 1 : 0;
|
||||||
foreach ($allMappings as $mapping) {
|
foreach ($allMappings as $mapping) {
|
||||||
if (!$mapping['is_manual']) {
|
if (!$mapping['is_manual'] && $mapping['main_field'] != 1) {
|
||||||
$detail = array_filter($rowDetails, fn($d) => $d['mapping_id'] == $mapping['id']);
|
$detail = array_filter($rowDetails, fn($d) => $d['mapping_id'] == $mapping['id']);
|
||||||
$detail = reset($detail) ?: ['field_value' => $mapping['manual_default']];
|
$detail = reset($detail) ?: ['field_value' => $mapping['manual_default']];
|
||||||
$fieldValue = $detail['field_value'] ?? $mapping['manual_default'] ?? '';
|
$fieldValue = $detail['field_value'] ?? $mapping['manual_default'] ?? '';
|
||||||
@@ -754,7 +818,7 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
|
|||||||
if ($mapping['is_required']) $inputClass .= ' required-input';
|
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;'>";
|
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') {
|
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' : '') . ($is_readonly ? ' readonly' : '') . ">";
|
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' : '') . ($is_readonly ? ' readonly' : '') . ">";
|
||||||
echo "<option value=''>Seleziona...</option>";
|
echo "<option value=''>Seleziona...</option>";
|
||||||
echo "</select>";
|
echo "</select>";
|
||||||
} elseif ($mapping['data_type'] === 'DATE') {
|
} elseif ($mapping['data_type'] === 'DATE') {
|
||||||
@@ -769,9 +833,10 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
|
|||||||
$autoIndex++;
|
$autoIndex++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$manualIndex = 0;
|
// Campi manuali (escluso main_field)
|
||||||
|
$manualIndex = ($mainFieldMapping && $mainFieldMapping['is_manual']) ? 1 : 0;
|
||||||
foreach ($allMappings as $mapping) {
|
foreach ($allMappings as $mapping) {
|
||||||
if ($mapping['is_manual']) {
|
if ($mapping['is_manual'] && $mapping['main_field'] != 1) {
|
||||||
$detail = array_filter($rowDetails, fn($d) => $d['mapping_id'] == $mapping['id']);
|
$detail = array_filter($rowDetails, fn($d) => $d['mapping_id'] == $mapping['id']);
|
||||||
$detail = reset($detail) ?: ['field_value' => $mapping['manual_default']];
|
$detail = reset($detail) ?: ['field_value' => $mapping['manual_default']];
|
||||||
$fieldValue = $detail['field_value'] ?? $mapping['manual_default'] ?? '';
|
$fieldValue = $detail['field_value'] ?? $mapping['manual_default'] ?? '';
|
||||||
@@ -783,7 +848,7 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
|
|||||||
if ($mapping['is_required']) $inputClass .= ' required-input';
|
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;'>";
|
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') {
|
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' : '') . ($is_readonly ? ' readonly' : '') . ">";
|
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' : '') . ($is_readonly ? ' readonly' : '') . ">";
|
||||||
echo "<option value=''>Seleziona...</option>";
|
echo "<option value=''>Seleziona...</option>";
|
||||||
echo "</select>";
|
echo "</select>";
|
||||||
} elseif ($mapping['data_type'] === 'DATE') {
|
} elseif ($mapping['data_type'] === 'DATE') {
|
||||||
@@ -798,6 +863,32 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
|
|||||||
$manualIndex++;
|
$manualIndex++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Colonna status
|
||||||
|
$fixedColumnsReduced = ['status'];
|
||||||
|
foreach ($fixedColumnsReduced as $col) {
|
||||||
|
$value = $row[$col] ?? '';
|
||||||
|
echo "<div class='grid-cell editable-cell' data-col='$col' data-row='$index' data-index='$cellIndex' style='flex: 0 0 150px;'>";
|
||||||
|
if ($col === 'status') {
|
||||||
|
$badgeClass = $value === 'i' ? 'status-i' : ($value === 'P' ? 'status-P' : 'status-l');
|
||||||
|
$badgeText = $value === 'i' ? 'Imported' : ($value === 'P' ? 'Progress' : 'LIMS');
|
||||||
|
echo "<span class='status-badge $badgeClass'>" . htmlspecialchars($badgeText) . "</span>";
|
||||||
|
echo "<input type='hidden' name='rows[$index][$col]' value='" . htmlspecialchars($value ?? 'i') . "'>";
|
||||||
|
}
|
||||||
|
echo "</div>";
|
||||||
|
$cellIndex++;
|
||||||
|
}
|
||||||
|
// Colonne Import Reference Code e filename_import
|
||||||
|
echo "<div class='grid-cell' data-col='importreferencecode' data-row='$index' data-index='$cellIndex' style='flex: 0 0 150px;'>";
|
||||||
|
echo "<span>" . htmlspecialchars($row['importreferencecode']) . "</span>";
|
||||||
|
echo "<input type='hidden' name='rows[$index][importreferencecode]' value='" . htmlspecialchars($row['importreferencecode']) . "'>";
|
||||||
|
echo "</div>";
|
||||||
|
$cellIndex++;
|
||||||
|
echo "<div class='grid-cell' data-col='filename_import' data-row='$index' data-index='$cellIndex' style='flex: 0 0 150px;'>";
|
||||||
|
echo "<a href='imported_trf/" . htmlspecialchars($row['filename_import']) . "' target='_blank'>File</a>";
|
||||||
|
echo "<input type='hidden' name='rows[$index][filename_import]' value='" . htmlspecialchars($row['filename_import']) . "'>";
|
||||||
|
echo "</div>";
|
||||||
|
$cellIndex++;
|
||||||
|
// Colonne AWB Number e Tracking Info
|
||||||
?>
|
?>
|
||||||
<div class="grid-cell" style="flex: 0 0 200px;">
|
<div class="grid-cell" style="flex: 0 0 200px;">
|
||||||
<select name="rows[<?= $index ?>][carrier]" class="carrier-select" <?= $is_readonly ? 'disabled' : '' ?>>
|
<select name="rows[<?= $index ?>][carrier]" class="carrier-select" <?= $is_readonly ? 'disabled' : '' ?>>
|
||||||
@@ -833,6 +924,7 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
|
|||||||
</ul>
|
</ul>
|
||||||
</nav>
|
</nav>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
<?php
|
<?php
|
||||||
if (file_exists('modal_parts.php')) {
|
if (file_exists('modal_parts.php')) {
|
||||||
include 'modal_parts.php';
|
include 'modal_parts.php';
|
||||||
@@ -890,7 +982,7 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
|
|||||||
const cells = row.querySelectorAll('td');
|
const cells = row.querySelectorAll('td');
|
||||||
let match = false;
|
let match = false;
|
||||||
cells.forEach((cell, index) => {
|
cells.forEach((cell, index) => {
|
||||||
if (index >= 1 && index <= 3) {
|
if (index >= 1 && index <= 4) { // Cerca in ID, main_field, importreferencecode, filename
|
||||||
const text = cell.textContent.toLowerCase();
|
const text = cell.textContent.toLowerCase();
|
||||||
if (text.includes(filter)) {
|
if (text.includes(filter)) {
|
||||||
match = true;
|
match = true;
|
||||||
@@ -934,6 +1026,18 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Gestione eliminazione multipla
|
||||||
|
const bulkActionForm = document.getElementById('bulkActionForm');
|
||||||
|
bulkActionForm.addEventListener('submit', function(e) {
|
||||||
|
const selectedCheckboxes = document.querySelectorAll('input[name="selected_ids[]"]:checked');
|
||||||
|
if (selectedCheckboxes.length === 0) {
|
||||||
|
e.preventDefault();
|
||||||
|
alert('Seleziona almeno un record da eliminare.');
|
||||||
|
} else if (!confirm('Sicuro di voler eliminare i record selezionati?')) {
|
||||||
|
e.preventDefault();
|
||||||
|
}
|
||||||
|
});
|
||||||
<?php else: ?>
|
<?php else: ?>
|
||||||
// Gestione input e celle espandibili
|
// Gestione input e celle espandibili
|
||||||
const inputs = document.querySelectorAll('.cell-input');
|
const inputs = document.querySelectorAll('.cell-input');
|
||||||
@@ -961,8 +1065,13 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
|
|||||||
inputs.forEach(input => {
|
inputs.forEach(input => {
|
||||||
const name = input.name.replace(`rows[${rowIndex}]`, '').replace(/\[|\]/g, '');
|
const name = input.name.replace(`rows[${rowIndex}]`, '').replace(/\[|\]/g, '');
|
||||||
formData.append(name, input.value);
|
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('iddatadb', iddatadb);
|
||||||
|
formData.append('mapping', JSON.stringify(<?= json_encode($allMappings) ?>));
|
||||||
fetch('save_edited_row.php', {
|
fetch('save_edited_row.php', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: formData
|
body: formData
|
||||||
@@ -977,6 +1086,7 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
|
|||||||
cell.classList.add('flash-success');
|
cell.classList.add('flash-success');
|
||||||
});
|
});
|
||||||
setTimeout(() => cells.forEach(cell => cell.classList.remove('flash-success')), 500);
|
setTimeout(() => cells.forEach(cell => cell.classList.remove('flash-success')), 500);
|
||||||
|
alert('Salvataggio avvenuto con successo!');
|
||||||
} else {
|
} else {
|
||||||
alert('Errore durante il salvataggio: ' + data.message);
|
alert('Errore durante il salvataggio: ' + data.message);
|
||||||
}
|
}
|
||||||
@@ -990,12 +1100,12 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
|
|||||||
propagateButtons.forEach(button => {
|
propagateButtons.forEach(button => {
|
||||||
button.addEventListener('click', function() {
|
button.addEventListener('click', function() {
|
||||||
if (this.hasAttribute('disabled')) return;
|
if (this.hasAttribute('disabled')) return;
|
||||||
const columnIndex = this.getAttribute('data-column').replace('manual_', '');
|
const column = this.getAttribute('data-column');
|
||||||
const input = this.previousElementSibling;
|
const input = this.previousElementSibling;
|
||||||
const value = input.value;
|
const value = input.value;
|
||||||
const gridTopCells = document.querySelector('.grid-top').querySelectorAll('.grid-cell');
|
const gridTopCells = document.querySelector('.grid-top').querySelectorAll('.grid-cell');
|
||||||
const targetTopIndex = Array.from(gridTopCells).findIndex(cell =>
|
const targetTopIndex = Array.from(gridTopCells).findIndex(cell =>
|
||||||
cell.querySelector('.propagate-btn') === button
|
cell.querySelector('.propagate-btn[data-column="' + column + '"]')
|
||||||
);
|
);
|
||||||
if (targetTopIndex !== -1) {
|
if (targetTopIndex !== -1) {
|
||||||
const rows = document.querySelectorAll('.grid-row');
|
const rows = document.querySelectorAll('.grid-row');
|
||||||
@@ -1004,9 +1114,12 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
|
|||||||
if (cells.length > targetTopIndex) {
|
if (cells.length > targetTopIndex) {
|
||||||
const targetInput = cells[targetTopIndex].querySelector('input, select');
|
const targetInput = cells[targetTopIndex].querySelector('input, select');
|
||||||
if (targetInput && !targetInput.hasAttribute('readonly')) {
|
if (targetInput && !targetInput.hasAttribute('readonly')) {
|
||||||
if (targetInput.type === 'date') targetInput.value = value;
|
targetInput.value = value;
|
||||||
else if (targetInput.tagName === 'SELECT') targetInput.value = value;
|
if (targetInput.tagName === 'SELECT') {
|
||||||
else targetInput.value = value;
|
targetInput.setAttribute('data-selected-value', value);
|
||||||
|
const event = new Event('change');
|
||||||
|
targetInput.dispatchEvent(event);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -1123,47 +1236,80 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
|
|||||||
async function populateDropdowns() {
|
async function populateDropdowns() {
|
||||||
if (<?= json_encode($is_readonly) ?>) return;
|
if (<?= json_encode($is_readonly) ?>) return;
|
||||||
const dropdowns = document.querySelectorAll('.dropdown-select');
|
const dropdowns = document.querySelectorAll('.dropdown-select');
|
||||||
if (dropdowns.length === 0) return;
|
console.log('Dropdown trovati:', dropdowns.length);
|
||||||
const uniqueFieldIds = [...new Set(Array.from(dropdowns).map(d => d.getAttribute('data-field-id')))].filter(fieldId => fieldId);
|
if (dropdowns.length === 0) {
|
||||||
for (const fieldId of uniqueFieldIds) {
|
console.warn('Nessun dropdown trovato con classe .dropdown-select');
|
||||||
if (!dropdownData[fieldId]) {
|
return;
|
||||||
try {
|
|
||||||
const response = await fetch(`get_customfield_values.php?field_id=${fieldId}`);
|
|
||||||
const data = await response.json();
|
|
||||||
if (data.error) {
|
|
||||||
console.error('Errore per field_id', fieldId, ':', data.error);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
dropdownData[fieldId] = data.CustomFieldsValues || [];
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Errore nel fetch per field_id', fieldId, ':', error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
dropdowns.forEach(dropdown => {
|
|
||||||
const fieldId = dropdown.getAttribute('data-field-id');
|
const uniqueFieldIds = [...new Set(Array.from(dropdowns).map(d => d.getAttribute('data-field-id')))].filter(fieldId => fieldId);
|
||||||
if (!fieldId || !dropdownData[fieldId]) {
|
console.log('Field IDs unici:', uniqueFieldIds);
|
||||||
dropdown.innerHTML = '<option value="">Errore nel caricamento</option>';
|
const missingFieldIds = uniqueFieldIds.filter(fieldId => !dropdownData[fieldId]);
|
||||||
|
|
||||||
|
if (missingFieldIds.length > 0) {
|
||||||
|
try {
|
||||||
|
const response = await fetch(`get_customfield_values.php?field_ids=${missingFieldIds.join(',')}`);
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error(`Errore HTTP: ${response.status} ${response.statusText}`);
|
||||||
|
}
|
||||||
|
const data = await response.json();
|
||||||
|
console.log('Risposta da get_customfield_values.php:', data);
|
||||||
|
|
||||||
|
if (data.error) {
|
||||||
|
console.error('Errore dal server:', data.error);
|
||||||
|
dropdowns.forEach(dropdown => {
|
||||||
|
dropdown.innerHTML = '<option value="">Errore server</option>';
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const fieldId of Object.keys(data)) {
|
||||||
|
dropdownData[fieldId] = data[fieldId] || [];
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Errore nel fetch dei valori dei dropdown:', error);
|
||||||
|
dropdowns.forEach(dropdown => {
|
||||||
|
dropdown.innerHTML = '<option value="">Errore caricamento</option>';
|
||||||
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dropdowns.forEach(dropdown => {
|
||||||
|
const fieldId = dropdown.getAttribute('data-field-id');
|
||||||
|
const mappingId = dropdown.getAttribute('data-mapping-id');
|
||||||
|
const selectedValue = dropdown.getAttribute('data-selected-value') || '';
|
||||||
|
const currentValue = dropdown.value || '';
|
||||||
|
console.log(`Popolamento dropdown field_id=${fieldId}, mapping_id=${mappingId}, valore corrente=${currentValue}, valore selezionato=${selectedValue}`);
|
||||||
|
|
||||||
|
if (!fieldId || !dropdownData[fieldId]) {
|
||||||
|
dropdown.innerHTML = '<option value="">Nessun dato</option>';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Preserva il valore corrente o usa quello salvato
|
||||||
dropdown.innerHTML = '<option value="">Seleziona...</option>';
|
dropdown.innerHTML = '<option value="">Seleziona...</option>';
|
||||||
dropdownData[fieldId].forEach(value => {
|
dropdownData[fieldId].forEach(value => {
|
||||||
const option = document.createElement('option');
|
const option = document.createElement('option');
|
||||||
option.value = value.IdCustomFieldsValue;
|
option.value = value.IdCustomFieldsValue;
|
||||||
option.textContent = value.Valore;
|
option.textContent = value.Valore;
|
||||||
if (dropdown.value === option.value) option.selected = true;
|
// Dai priorità a data-selected-value per il caricamento iniziale
|
||||||
|
if (selectedValue === String(value.IdCustomFieldsValue)) {
|
||||||
|
option.selected = true;
|
||||||
|
} else if (currentValue === String(value.IdCustomFieldsValue)) {
|
||||||
|
option.selected = true;
|
||||||
|
}
|
||||||
dropdown.appendChild(option);
|
dropdown.appendChild(option);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Verifica se il valore selezionato esiste tra le opzioni
|
||||||
|
if ((selectedValue || currentValue) && dropdown.value !== (selectedValue || currentValue)) {
|
||||||
|
dropdown.value = '';
|
||||||
|
console.warn(`Valore ${selectedValue || currentValue} non trovato per fieldId ${fieldId}`);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
populateDropdowns();
|
populateDropdowns();
|
||||||
saveButtons.forEach(btn => {
|
|
||||||
btn.addEventListener('click', function() {
|
|
||||||
if (!this.hasAttribute('disabled')) {
|
|
||||||
setTimeout(populateDropdowns, 100);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
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: none;
|
||||||
border-radius: 5px;
|
border-radius: 5px;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
width: 50px;
|
width: 35px;
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.flash-success {
|
||||||
|
background-color: #d4edda !important;
|
||||||
|
transition: background-color 0.3s ease;
|
||||||
|
}
|
||||||
</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>
|
||||||
@@ -428,7 +433,7 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
|
|||||||
$inputClass = $mainFieldMapping['is_manual'] ? 'manual-input' : 'auto-input';
|
$inputClass = $mainFieldMapping['is_manual'] ? 'manual-input' : 'auto-input';
|
||||||
if ($mainFieldMapping['is_required']) $inputClass .= ' required-input';
|
if ($mainFieldMapping['is_required']) $inputClass .= ' required-input';
|
||||||
if ($mainFieldMapping['data_type'] === 'SceltaMultipla') {
|
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 "<option value=''>Seleziona...</option>";
|
||||||
echo "</select>";
|
echo "</select>";
|
||||||
echo "<button type='button' class='propagate-btn' data-column='main_field'><i class='fas fa-arrow-down'></i></button>";
|
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['is_required']) $inputClass .= ' required-input';
|
||||||
if ($mapping['data_type'] === 'SceltaMultipla') {
|
if ($mapping['data_type'] === 'SceltaMultipla') {
|
||||||
echo "<div class='grid-cell' style='flex: 0 0 150px;'>";
|
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 "<option value=''>Seleziona...</option>";
|
||||||
echo "</select>";
|
echo "</select>";
|
||||||
echo "<button type='button' class='propagate-btn' data-column='auto_$autoIndex'><i class='fas fa-arrow-down'></i></button>";
|
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';
|
if ($mapping['is_required']) $inputClass .= ' required-input';
|
||||||
echo "<div class='grid-cell' style='flex: 0 0 150px;'>";
|
echo "<div class='grid-cell' style='flex: 0 0 150px;'>";
|
||||||
if ($mapping['data_type'] === 'SceltaMultipla') {
|
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 "<option value=''>Seleziona...</option>";
|
||||||
echo "</select>";
|
echo "</select>";
|
||||||
} elseif ($mapping['data_type'] === 'DATE') {
|
} elseif ($mapping['data_type'] === 'DATE') {
|
||||||
@@ -542,6 +547,7 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
|
|||||||
<?php foreach ($importedData as $index => $row): ?>
|
<?php foreach ($importedData as $index => $row): ?>
|
||||||
<div class="grid-row" data-id="<?= $row['iddatadb'] ?>">
|
<div class="grid-row" data-id="<?= $row['iddatadb'] ?>">
|
||||||
<div class="grid-cell button-cell" style="flex: 0 0 210px; position: relative;">
|
<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="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="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>
|
<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;">
|
<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'): ?>
|
<?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>
|
<option value="">Seleziona...</option>
|
||||||
</select>
|
</select>
|
||||||
<?php elseif ($mainFieldMapping['data_type'] === 'DATE'): ?>
|
<?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';
|
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;'>";
|
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') {
|
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 "<option value=''>Seleziona...</option>";
|
||||||
echo "</select>";
|
echo "</select>";
|
||||||
} elseif ($mapping['data_type'] === 'DATE') {
|
} elseif ($mapping['data_type'] === 'DATE') {
|
||||||
@@ -621,7 +627,7 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
|
|||||||
if ($mapping['is_required']) $inputClass .= ' required-input';
|
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;'>";
|
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') {
|
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 "<option value=''>Seleziona...</option>";
|
||||||
echo "</select>";
|
echo "</select>";
|
||||||
} elseif ($mapping['data_type'] === 'DATE') {
|
} elseif ($mapping['data_type'] === 'DATE') {
|
||||||
@@ -718,35 +724,6 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
|
|||||||
});
|
});
|
||||||
</script>
|
</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>
|
<script>
|
||||||
document.addEventListener("DOMContentLoaded", function() {
|
document.addEventListener("DOMContentLoaded", function() {
|
||||||
const inputs = document.querySelectorAll('.cell-input');
|
const inputs = document.querySelectorAll('.cell-input');
|
||||||
@@ -817,9 +794,11 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
|
|||||||
if (cells.length > targetTopIndex) {
|
if (cells.length > targetTopIndex) {
|
||||||
const targetInput = cells[targetTopIndex].querySelector('input, select');
|
const targetInput = cells[targetTopIndex].querySelector('input, select');
|
||||||
if (targetInput) {
|
if (targetInput) {
|
||||||
if (targetInput.type === 'date') targetInput.value = value;
|
targetInput.value = value;
|
||||||
else if (targetInput.tagName === 'SELECT') targetInput.value = value;
|
if (targetInput.tagName === 'SELECT') {
|
||||||
else targetInput.value = value;
|
const event = new Event('change');
|
||||||
|
targetInput.dispatchEvent(event);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -899,6 +878,9 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
|
|||||||
|
|
||||||
dropdowns.forEach(dropdown => {
|
dropdowns.forEach(dropdown => {
|
||||||
const fieldId = dropdown.getAttribute('data-field-id');
|
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]) {
|
if (!fieldId || !dropdownData[fieldId]) {
|
||||||
dropdown.innerHTML = '<option value="">Errore nel caricamento</option>';
|
dropdown.innerHTML = '<option value="">Errore nel caricamento</option>';
|
||||||
return;
|
return;
|
||||||
@@ -909,17 +891,64 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
|
|||||||
const option = document.createElement('option');
|
const option = document.createElement('option');
|
||||||
option.value = value.IdCustomFieldsValue;
|
option.value = value.IdCustomFieldsValue;
|
||||||
option.textContent = value.Valore;
|
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);
|
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();
|
populateDropdowns();
|
||||||
|
|
||||||
document.querySelectorAll('.save-btn').forEach(btn => {
|
document.querySelectorAll('.save-btn').forEach(btn => {
|
||||||
btn.addEventListener('click', function() {
|
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) {
|
if (targetInput) {
|
||||||
targetInput.value = value;
|
targetInput.value = value;
|
||||||
if (targetInput.tagName === 'SELECT') {
|
if (targetInput.tagName === 'SELECT') {
|
||||||
|
targetInput.setAttribute('data-selected-value', value); // Aggiorna anche qui
|
||||||
const event = new Event('change');
|
const event = new Event('change');
|
||||||
targetInput.dispatchEvent(event);
|
targetInput.dispatchEvent(event);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
<!-- Modal -->
|
|
||||||
<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">
|
||||||
@@ -13,24 +12,24 @@
|
|||||||
<ul id="partsList" class="list-group"></ul>
|
<ul id="partsList" class="list-group"></ul>
|
||||||
<table class="table table-striped table-sm mt-3" id="partsTable">
|
<table class="table table-striped table-sm mt-3" id="partsTable">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th>Num. Parte</th>
|
<th>Num. Parte</th>
|
||||||
<th>Descrizione Parte</th>
|
<th>Descrizione Parte</th>
|
||||||
<th>Azioni</th>
|
<th>Azioni</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody id="partsTableBody">
|
<tbody id="partsTableBody">
|
||||||
<tr data-part-id="new">
|
<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="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><input type="text" class="form-control form-control-sm part-description" placeholder="Inserisci descrizione" style="width: 100%;"></td>
|
||||||
<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-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-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>
|
<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-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>
|
<span class="save-loading text-warning" style="display: none; margin-left: 5px;"><i class="fas fa-spinner fa-spin fa-xs"></i></span>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
@@ -50,6 +49,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="modal-footer">
|
<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-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-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-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>
|
<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;
|
font-size: 0.8rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ნორმალური Save ღილაკი */
|
/* Normale Save button */
|
||||||
#savePhotoBtn {
|
#savePhotoBtn {
|
||||||
transition: all 0.3s ease-in-out;
|
transition: all 0.3s ease-in-out;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* დაუმახსოვრებელი ცვლილებები */
|
/* Modifiche non salvate */
|
||||||
#savePhotoBtn.unsaved {
|
#savePhotoBtn.unsaved {
|
||||||
background-color: #dc3545 !important; /* წითელი */
|
background-color: #dc3545 !important;
|
||||||
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 di pulsazione */
|
||||||
@keyframes pulse {
|
@keyframes pulse {
|
||||||
0% { box-shadow: 0 0 0 0 rgba(220, 53, 69, 0.7); }
|
0% {
|
||||||
70% { box-shadow: 0 0 10px 15px rgba(220, 53, 69, 0); }
|
box-shadow: 0 0 0 0 rgba(220, 53, 69, 0.7);
|
||||||
100% { box-shadow: 0 0 0 0 rgba(220, 53, 69, 0); }
|
}
|
||||||
|
|
||||||
|
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");
|
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 = {
|
let photoData = {
|
||||||
naturalWidth: 0,
|
naturalWidth: 0,
|
||||||
@@ -12,29 +17,36 @@ $(document).ready(function () {
|
|||||||
scale: 1,
|
scale: 1,
|
||||||
};
|
};
|
||||||
|
|
||||||
// markers keyed by photo src => [{ partNumber, x, y } using NATURAL coords]
|
|
||||||
let photoMarkers = {};
|
let photoMarkers = {};
|
||||||
|
|
||||||
// selection & descriptions
|
|
||||||
let selectedPartNumber = null;
|
let selectedPartNumber = null;
|
||||||
let descriptionPosition = {x: 10, y: 10}; // NATURAL coords
|
let descriptionPosition = { x: 10, y: 10 };
|
||||||
let hasDescriptions = false;
|
let hasDescriptions = false;
|
||||||
|
|
||||||
|
// Verifica inizializzazione del pulsante
|
||||||
|
console.log(
|
||||||
|
"Verifica pulsante #removeBackgroundBtn:",
|
||||||
|
$("#removeBackgroundBtn").length,
|
||||||
|
);
|
||||||
|
|
||||||
// ===================
|
// ===================
|
||||||
// POPUP HANDLING
|
// POPUP HANDLING
|
||||||
// ===================
|
// ===================
|
||||||
const partsButtons = document.querySelectorAll(".parts-btn");
|
const partsButtons = document.querySelectorAll(".parts-btn");
|
||||||
const partsModal = document.getElementById("partsModal");
|
const partsModal = document.getElementById("partsModal");
|
||||||
const closeBtn = document.querySelector("#partsModal .close-btn");
|
|
||||||
const overlay = document.querySelector(".overlay");
|
|
||||||
|
|
||||||
partsButtons.forEach((button) => {
|
partsButtons.forEach((button) => {
|
||||||
button.addEventListener("click", function () {
|
button.addEventListener("click", function () {
|
||||||
console.log("Pulsante Parts cliccato");
|
console.log("Pulsante Parts cliccato");
|
||||||
const iddatadb = $(this).data("iddatadb");
|
const iddatadb = $(this).data("iddatadb");
|
||||||
const rowIndex = $(this).data("row");
|
const rowIndex = $(this).data("row");
|
||||||
const importRef = $("table tbody tr").eq(rowIndex).find("td").eq(1).text();
|
const importRef = $("table tbody tr")
|
||||||
const description = $("table tbody tr").eq(rowIndex).find("td").eq(2).text() || "Sconosciuto";
|
.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}`);
|
$("#trfHeader").text(`${iddatadb} - ${importRef} - ${description}`);
|
||||||
$("#partsModal").data("iddatadb", iddatadb);
|
$("#partsModal").data("iddatadb", iddatadb);
|
||||||
@@ -45,66 +57,62 @@ $(document).ready(function () {
|
|||||||
if (partsModal) {
|
if (partsModal) {
|
||||||
const modal = new bootstrap.Modal(partsModal);
|
const modal = new bootstrap.Modal(partsModal);
|
||||||
modal.show();
|
modal.show();
|
||||||
|
console.log("Modale aperto");
|
||||||
} else {
|
} else {
|
||||||
console.error("Modal Parts non trovato");
|
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
|
// PHOTO LOADERS
|
||||||
// ===================
|
// ===================
|
||||||
function loadPhoto(iddatadb) {
|
function loadPhoto(iddatadb) {
|
||||||
|
console.log("Caricamento foto per iddatadb:", iddatadb);
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: "load_photo.php",
|
url: "load_photo.php",
|
||||||
method: "GET",
|
method: "GET",
|
||||||
data: {iddatadb: iddatadb},
|
data: { iddatadb: iddatadb },
|
||||||
success: function (response) {
|
success: function (response) {
|
||||||
|
console.log("Risposta load_photo.php:", response);
|
||||||
if (response.success) {
|
if (response.success) {
|
||||||
if (response.photos && response.photos.length > 1) {
|
if (response.photos && response.photos.length > 1) {
|
||||||
showPhotoSelector(response.photos);
|
showPhotoSelector(response.photos);
|
||||||
} else if (response.photos && response.photos.length === 1) {
|
} else if (
|
||||||
|
response.photos &&
|
||||||
|
response.photos.length === 1
|
||||||
|
) {
|
||||||
loadSinglePhoto(response.photos[0]);
|
loadSinglePhoto(response.photos[0]);
|
||||||
} else {
|
} else {
|
||||||
$("#samplePhoto").attr("src", "");
|
$("#samplePhoto").attr("src", "");
|
||||||
alert("Nessuna foto trovata per questo TRF.");
|
alert("Nessuna foto trovata per questo TRF.");
|
||||||
|
console.log("Nessuna foto trovata");
|
||||||
}
|
}
|
||||||
} else {
|
} 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) {
|
error: function (xhr, status, error) {
|
||||||
alert("Errore nel caricamento della foto: " + error);
|
alert("Errore nel caricamento della foto: " + error);
|
||||||
|
console.error("Errore AJAX load_photo.php:", error, xhr.status);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function showPhotoSelector(photos) {
|
function showPhotoSelector(photos) {
|
||||||
|
console.log("Mostra selettore foto:", photos);
|
||||||
const selectorContainer = $("#photoSelectorContainer");
|
const selectorContainer = $("#photoSelectorContainer");
|
||||||
selectorContainer.empty();
|
selectorContainer.empty();
|
||||||
|
|
||||||
const selector = $('<select id="photoSelector"></select>');
|
const selector = $('<select id="photoSelector"></select>');
|
||||||
photos.forEach((photo, index) => {
|
photos.forEach((photo, index) => {
|
||||||
const option = $('<option></option>').val(photo).text(`Photo ${index + 1}`);
|
const option = $("<option></option>")
|
||||||
// display option with photo name if available
|
.val(photo)
|
||||||
|
.text(`Photo ${index + 1}`);
|
||||||
if (photo.includes("/")) {
|
if (photo.includes("/")) {
|
||||||
const photoName = photo.split("/").pop();
|
const photoName = photo.split("/").pop();
|
||||||
option.text(`Photo ${index + 1} - ${photoName}`);
|
option.text(`Photo ${index + 1} - ${photoName}`);
|
||||||
@@ -127,49 +135,67 @@ $(document).ready(function () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function loadSinglePhoto(photoPath) {
|
function loadSinglePhoto(photoPath) {
|
||||||
|
console.log("Caricamento singola foto:", photoPath);
|
||||||
const img = $("#samplePhoto");
|
const img = $("#samplePhoto");
|
||||||
img.off("load"); // avoid stacking multiple handlers
|
img.off("load");
|
||||||
img.attr("src", photoPath);
|
img.attr("src", photoPath);
|
||||||
|
|
||||||
img.on("load", function () {
|
img.on("load", function () {
|
||||||
|
console.log(
|
||||||
|
"Immagine caricata, dimensioni naturali:",
|
||||||
|
img[0].naturalWidth,
|
||||||
|
img[0].naturalHeight,
|
||||||
|
);
|
||||||
const canvas = document.getElementById("photoCanvas");
|
const canvas = document.getElementById("photoCanvas");
|
||||||
const ctx = canvas.getContext("2d");
|
const ctx = canvas.getContext("2d");
|
||||||
|
|
||||||
// Real image size
|
|
||||||
const naturalWidth = img[0].naturalWidth;
|
const naturalWidth = img[0].naturalWidth;
|
||||||
const naturalHeight = img[0].naturalHeight;
|
const naturalHeight = img[0].naturalHeight;
|
||||||
|
|
||||||
// Compute scale to FIT inside its parent without distorting aspect ratio
|
|
||||||
const parent = $(canvas).parent();
|
const parent = $(canvas).parent();
|
||||||
const maxW = parent.width();
|
const maxW = parent.width();
|
||||||
const maxH = parent.height();
|
const maxH = parent.height();
|
||||||
const scale = Math.min(maxW / naturalWidth, maxH / naturalHeight);
|
const scale = Math.min(maxW / naturalWidth, maxH / naturalHeight);
|
||||||
|
|
||||||
// Display size on screen
|
|
||||||
const displayWidth = Math.max(1, Math.round(naturalWidth * scale));
|
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 = {
|
||||||
photoData = {naturalWidth, naturalHeight, displayWidth, displayHeight, scale};
|
naturalWidth,
|
||||||
|
naturalHeight,
|
||||||
|
displayWidth,
|
||||||
|
displayHeight,
|
||||||
|
scale,
|
||||||
|
};
|
||||||
|
|
||||||
// Canvas in REAL size (so saving uses natural coords 1:1)
|
|
||||||
canvas.width = naturalWidth;
|
canvas.width = naturalWidth;
|
||||||
canvas.height = naturalHeight;
|
canvas.height = naturalHeight;
|
||||||
|
|
||||||
// Visual size on screen
|
|
||||||
canvas.style.width = `${displayWidth}px`;
|
canvas.style.width = `${displayWidth}px`;
|
||||||
canvas.style.height = `${displayHeight}px`;
|
canvas.style.height = `${displayHeight}px`;
|
||||||
|
|
||||||
// Also size/align the overlay containers to match the canvas
|
$("#markerContainer").css({
|
||||||
$("#markerContainer").css({width: `${displayWidth}px`, height: `${displayHeight}px`});
|
width: `${displayWidth}px`,
|
||||||
$("#descriptionList").css({maxWidth: `${Math.max(200, Math.round(displayWidth * 0.35))}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.clearRect(0, 0, naturalWidth, naturalHeight);
|
||||||
ctx.drawImage(img.get(0), 0, 0, naturalWidth, naturalHeight);
|
ctx.drawImage(img.get(0), 0, 0, naturalWidth, naturalHeight);
|
||||||
|
|
||||||
updateMarkers();
|
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;
|
const rowCount = $("#partsTableBody tr").length;
|
||||||
$("#partsTableBody tr").each(function () {
|
$("#partsTableBody tr").each(function () {
|
||||||
const $removeBtn = $(this).find(".remove-row");
|
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) {
|
$(document).on("click", ".add-row", function (e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
const maxPartNumber = Math.max(
|
const maxPartNumber = Math.max(
|
||||||
...$("#partsTableBody tr").map(function () {
|
...$("#partsTableBody tr")
|
||||||
return parseInt($(this).find(".part-number").val()) || 0;
|
.map(function () {
|
||||||
}).get(),
|
return parseInt($(this).find(".part-number").val()) || 0;
|
||||||
|
})
|
||||||
|
.get(),
|
||||||
);
|
);
|
||||||
addNewRow(maxPartNumber + 1);
|
addNewRow(maxPartNumber + 1);
|
||||||
updatePartsList();
|
updatePartsList();
|
||||||
@@ -216,9 +245,11 @@ $(document).ready(function () {
|
|||||||
$(document).on("click", ".add-mix-row", function (e) {
|
$(document).on("click", ".add-mix-row", function (e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
const maxPartNumber = Math.max(
|
const maxPartNumber = Math.max(
|
||||||
...$("#partsTableBody tr").map(function () {
|
...$("#partsTableBody tr")
|
||||||
return parseInt($(this).find(".part-number").val()) || 0;
|
.map(function () {
|
||||||
}).get(),
|
return parseInt($(this).find(".part-number").val()) || 0;
|
||||||
|
})
|
||||||
|
.get(),
|
||||||
);
|
);
|
||||||
addNewRow(maxPartNumber + 1, true);
|
addNewRow(maxPartNumber + 1, true);
|
||||||
updatePartsList();
|
updatePartsList();
|
||||||
@@ -233,7 +264,7 @@ $(document).ready(function () {
|
|||||||
$.ajax({
|
$.ajax({
|
||||||
url: "delete_part.php",
|
url: "delete_part.php",
|
||||||
method: "POST",
|
method: "POST",
|
||||||
data: JSON.stringify({part_id: partId}),
|
data: JSON.stringify({ part_id: partId }),
|
||||||
contentType: "application/json",
|
contentType: "application/json",
|
||||||
success: function (response) {
|
success: function (response) {
|
||||||
if (response.success) {
|
if (response.success) {
|
||||||
@@ -246,7 +277,14 @@ $(document).ready(function () {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
error: function (xhr, status, error) {
|
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 {
|
} else {
|
||||||
@@ -266,7 +304,6 @@ $(document).ready(function () {
|
|||||||
const iddatadb = $("#partsModal").data("iddatadb");
|
const iddatadb = $("#partsModal").data("iddatadb");
|
||||||
const isMix = partDescription.startsWith("Mix") ? "Y" : "N";
|
const isMix = partDescription.startsWith("Mix") ? "Y" : "N";
|
||||||
|
|
||||||
// არსებული part-id row-დან (თუ უკვე არსებობს)
|
|
||||||
const partId = $row.data("part-id") || null;
|
const partId = $row.data("part-id") || null;
|
||||||
|
|
||||||
if (partDescription && iddatadb) {
|
if (partDescription && iddatadb) {
|
||||||
@@ -280,7 +317,7 @@ $(document).ready(function () {
|
|||||||
iddatadb: iddatadb,
|
iddatadb: iddatadb,
|
||||||
parts: [
|
parts: [
|
||||||
{
|
{
|
||||||
id: partId, // გავგზავნე part-ის ID (თუ არის)
|
id: partId,
|
||||||
part_number: partNumber,
|
part_number: partNumber,
|
||||||
part_description: partDescription,
|
part_description: partDescription,
|
||||||
mix: isMix,
|
mix: isMix,
|
||||||
@@ -293,7 +330,6 @@ $(document).ready(function () {
|
|||||||
$saveLoading.hide();
|
$saveLoading.hide();
|
||||||
$saveStatus.show();
|
$saveStatus.show();
|
||||||
updatePartsList();
|
updatePartsList();
|
||||||
// თუ ახალია, backend-მა მოგვცა ახალი ID
|
|
||||||
if (response.part_id) {
|
if (response.part_id) {
|
||||||
$row.attr("data-part-id", response.part_id);
|
$row.attr("data-part-id", response.part_id);
|
||||||
$row.data("part-id", response.part_id);
|
$row.data("part-id", response.part_id);
|
||||||
@@ -313,11 +349,13 @@ $(document).ready(function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
function loadExistingParts(iddatadb) {
|
function loadExistingParts(iddatadb) {
|
||||||
|
console.log("Caricamento parti esistenti per iddatadb:", iddatadb);
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: "load_parts.php",
|
url: "load_parts.php",
|
||||||
method: "GET",
|
method: "GET",
|
||||||
data: {iddatadb: iddatadb},
|
data: { iddatadb: iddatadb },
|
||||||
success: function (response) {
|
success: function (response) {
|
||||||
|
console.log("Risposta load_parts.php:", response);
|
||||||
if (response.success) {
|
if (response.success) {
|
||||||
$("#partsTableBody").empty();
|
$("#partsTableBody").empty();
|
||||||
if (response.parts.length > 0) {
|
if (response.parts.length > 0) {
|
||||||
@@ -342,12 +380,17 @@ $(document).ready(function () {
|
|||||||
updateRowButtons();
|
updateRowButtons();
|
||||||
updatePartsList();
|
updatePartsList();
|
||||||
} else {
|
} 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);
|
addNewRow(1);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
error: function (xhr, status, error) {
|
error: function (xhr, status, error) {
|
||||||
alert("Errore nel caricamento delle parti: " + error);
|
alert("Errore nel caricamento delle parti: " + error);
|
||||||
|
console.error("Errore AJAX load_parts.php:", error, xhr.status);
|
||||||
addNewRow(1);
|
addNewRow(1);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
@@ -358,7 +401,11 @@ $(document).ready(function () {
|
|||||||
$("#partsTableBody tr").each(function () {
|
$("#partsTableBody tr").each(function () {
|
||||||
const partNumber = $(this).find(".part-number").val();
|
const partNumber = $(this).find(".part-number").val();
|
||||||
const partDescription = $(this).find(".part-description").val();
|
const partDescription = $(this).find(".part-description").val();
|
||||||
if (partNumber && partDescription && !partDescription.startsWith("Mix")) {
|
if (
|
||||||
|
partNumber &&
|
||||||
|
partDescription &&
|
||||||
|
!partDescription.startsWith("Mix")
|
||||||
|
) {
|
||||||
const listItem = `
|
const listItem = `
|
||||||
<li class="list-group-item" data-part-number="${partNumber}">
|
<li class="list-group-item" data-part-number="${partNumber}">
|
||||||
${partNumber} - ${partDescription}
|
${partNumber} - ${partDescription}
|
||||||
@@ -372,9 +419,14 @@ $(document).ready(function () {
|
|||||||
$(document).on("click", ".add-to-mix-btn", function () {
|
$(document).on("click", ".add-to-mix-btn", function () {
|
||||||
const $listItem = $(this).closest("li");
|
const $listItem = $(this).closest("li");
|
||||||
const partDescription = $listItem.text().split(" - ")[1].trim();
|
const partDescription = $listItem.text().split(" - ")[1].trim();
|
||||||
const $mixRow = $("#partsTableBody tr").filter(function () {
|
const $mixRow = $("#partsTableBody tr")
|
||||||
return $(this).find(".part-description").val().startsWith("Mix");
|
.filter(function () {
|
||||||
}).last();
|
return $(this)
|
||||||
|
.find(".part-description")
|
||||||
|
.val()
|
||||||
|
.startsWith("Mix");
|
||||||
|
})
|
||||||
|
.last();
|
||||||
|
|
||||||
if ($mixRow.length === 0) {
|
if ($mixRow.length === 0) {
|
||||||
alert("Crea prima una riga Mix usando il pulsante 'M'.");
|
alert("Crea prima una riga Mix usando il pulsante 'M'.");
|
||||||
@@ -416,22 +468,29 @@ $(document).ready(function () {
|
|||||||
const clickX = e.clientX - rect.left;
|
const clickX = e.clientX - rect.left;
|
||||||
const clickY = e.clientY - rect.top;
|
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 y = clickY / photoData.scale;
|
||||||
|
|
||||||
const currentPhoto = $("#samplePhoto").attr("src");
|
const currentPhoto = $("#samplePhoto").attr("src");
|
||||||
if (!photoMarkers[currentPhoto]) photoMarkers[currentPhoto] = [];
|
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) {
|
if (existingMarker) {
|
||||||
existingMarker.x = x;
|
existingMarker.x = x;
|
||||||
existingMarker.y = y;
|
existingMarker.y = y;
|
||||||
} else {
|
} else {
|
||||||
photoMarkers[currentPhoto].push({partNumber: selectedPartNumber, x, y});
|
photoMarkers[currentPhoto].push({
|
||||||
|
partNumber: selectedPartNumber,
|
||||||
|
x,
|
||||||
|
y,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
updateMarkers();
|
updateMarkers();
|
||||||
if (hasDescriptions) drawDescriptions(descriptionPosition.x, descriptionPosition.y);
|
if (hasDescriptions)
|
||||||
|
drawDescriptions(descriptionPosition.x, descriptionPosition.y);
|
||||||
|
|
||||||
selectedPartNumber = null;
|
selectedPartNumber = null;
|
||||||
$("#partsList li").removeClass("active");
|
$("#partsList li").removeClass("active");
|
||||||
@@ -441,8 +500,10 @@ $(document).ready(function () {
|
|||||||
const markerContainer = $("#markerContainer");
|
const markerContainer = $("#markerContainer");
|
||||||
markerContainer.empty();
|
markerContainer.empty();
|
||||||
|
|
||||||
// keep overlay sized to canvas display
|
markerContainer.css({
|
||||||
markerContainer.css({width: `${photoData.displayWidth}px`, height: `${photoData.displayHeight}px`});
|
width: `${photoData.displayWidth}px`,
|
||||||
|
height: `${photoData.displayHeight}px`,
|
||||||
|
});
|
||||||
|
|
||||||
const currentPhoto = $("#samplePhoto").attr("src");
|
const currentPhoto = $("#samplePhoto").attr("src");
|
||||||
const markers = photoMarkers[currentPhoto] || [];
|
const markers = photoMarkers[currentPhoto] || [];
|
||||||
@@ -451,7 +512,9 @@ $(document).ready(function () {
|
|||||||
const scaledX = marker.x * photoData.scale;
|
const scaledX = marker.x * photoData.scale;
|
||||||
const scaledY = marker.y * 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",
|
left: scaledX - 8 + "px",
|
||||||
top: scaledY - 8 + "px",
|
top: scaledY - 8 + "px",
|
||||||
});
|
});
|
||||||
@@ -488,13 +551,12 @@ $(document).ready(function () {
|
|||||||
currentX = Math.max(0, Math.min(currentX, maxX));
|
currentX = Math.max(0, Math.min(currentX, maxX));
|
||||||
currentY = Math.max(0, Math.min(currentY, maxY));
|
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) {
|
if (item && item.partNumber) {
|
||||||
item.x = (currentX + 8) / photoData.scale;
|
item.x = (currentX + 8) / photoData.scale;
|
||||||
item.y = (currentY + 8) / photoData.scale;
|
item.y = (currentY + 8) / photoData.scale;
|
||||||
} else {
|
} else {
|
||||||
// draggable description panel
|
|
||||||
descriptionPosition.x = (currentX + 5) / photoData.scale;
|
descriptionPosition.x = (currentX + 5) / photoData.scale;
|
||||||
descriptionPosition.y = (currentY + 5) / photoData.scale;
|
descriptionPosition.y = (currentY + 5) / photoData.scale;
|
||||||
}
|
}
|
||||||
@@ -513,7 +575,11 @@ $(document).ready(function () {
|
|||||||
$("#partsTableBody tr").each(function () {
|
$("#partsTableBody tr").each(function () {
|
||||||
const partNumber = $(this).find(".part-number").val();
|
const partNumber = $(this).find(".part-number").val();
|
||||||
const partDescription = $(this).find(".part-description").val();
|
const partDescription = $(this).find(".part-description").val();
|
||||||
if (partNumber && partDescription && !partDescription.startsWith("Mix")) {
|
if (
|
||||||
|
partNumber &&
|
||||||
|
partDescription &&
|
||||||
|
!partDescription.startsWith("Mix")
|
||||||
|
) {
|
||||||
partsList.push(`${partNumber} ${partDescription}`);
|
partsList.push(`${partNumber} ${partDescription}`);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -525,7 +591,9 @@ $(document).ready(function () {
|
|||||||
top: y * photoData.scale + "px",
|
top: y * photoData.scale + "px",
|
||||||
left: x * 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();
|
updateMarkers();
|
||||||
}
|
}
|
||||||
@@ -540,7 +608,6 @@ $(document).ready(function () {
|
|||||||
const canvas = document.getElementById("photoCanvas");
|
const canvas = document.getElementById("photoCanvas");
|
||||||
const ctx = canvas.getContext("2d");
|
const ctx = canvas.getContext("2d");
|
||||||
|
|
||||||
// reset canvas to current image (keeps proportions)
|
|
||||||
canvas.width = photoData.naturalWidth;
|
canvas.width = photoData.naturalWidth;
|
||||||
canvas.height = photoData.naturalHeight;
|
canvas.height = photoData.naturalHeight;
|
||||||
canvas.style.width = `${photoData.displayWidth}px`;
|
canvas.style.width = `${photoData.displayWidth}px`;
|
||||||
@@ -554,43 +621,156 @@ $(document).ready(function () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$("#addDescriptionsBtn").on("click", function () {
|
$("#addDescriptionsBtn").on("click", function () {
|
||||||
|
console.log("Aggiungi descrizioni cliccato");
|
||||||
hasDescriptions = true;
|
hasDescriptions = true;
|
||||||
descriptionPosition = {x: 10, y: 10};
|
descriptionPosition = { x: 10, y: 10 };
|
||||||
drawDescriptions(descriptionPosition.x, descriptionPosition.y);
|
drawDescriptions(descriptionPosition.x, descriptionPosition.y);
|
||||||
makeDraggable($("#descriptionList"));
|
makeDraggable($("#descriptionList"));
|
||||||
});
|
});
|
||||||
|
|
||||||
$("#removeAnnotationsBtn").on("click", function () {
|
$("#removeAnnotationsBtn").on("click", function () {
|
||||||
|
console.log("Rimuovi annotazioni cliccato");
|
||||||
clearCanvasMarkers();
|
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;
|
let unsavedChanges = false;
|
||||||
|
|
||||||
// --- helper functions ---
|
// --- helper functions ---
|
||||||
function markUnsaved() {
|
function markUnsaved() {
|
||||||
if (!unsavedChanges) {
|
if (!unsavedChanges) {
|
||||||
unsavedChanges = true;
|
unsavedChanges = true;
|
||||||
$("#savePhotoBtn").addClass("unsaved").text("⚠️ Salva Modifiche");
|
$("#savePhotoBtn").addClass("unsaved").text("⚠️ Salva Modifiche");
|
||||||
|
console.log("Modifiche non salvate segnate");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function clearUnsaved() {
|
function clearUnsaved() {
|
||||||
unsavedChanges = false;
|
unsavedChanges = false;
|
||||||
$("#savePhotoBtn").removeClass("unsaved").text("Salva Foto con Nome");
|
$("#savePhotoBtn").removeClass("unsaved").text("Salva Foto con Nome");
|
||||||
|
console.log("Modifiche salvate, stato ripristinato");
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- event listeners ---
|
// --- event listeners ---
|
||||||
// როცა ვცვლით input-ს ცხრილში
|
|
||||||
$(document).on("input change", "#partsTableBody input", markUnsaved);
|
$(document).on("input change", "#partsTableBody input", markUnsaved);
|
||||||
|
|
||||||
// როცა ვამატებთ/ვშლით რიგს
|
|
||||||
$(document).on("click", ".add-row, .add-mix-row, .remove-row", markUnsaved);
|
$(document).on("click", ".add-row, .add-mix-row, .remove-row", markUnsaved);
|
||||||
|
|
||||||
// თუ გაქვს draggable marker ან description list
|
|
||||||
$(document).on("markerChanged descriptionChanged", markUnsaved);
|
$(document).on("markerChanged descriptionChanged", markUnsaved);
|
||||||
|
|
||||||
// --- modal close protection ---
|
// --- modal close protection ---
|
||||||
$('#partsModal').on('hide.bs.modal', function (e) {
|
$("#partsModal").on("hide.bs.modal", function (e) {
|
||||||
if (unsavedChanges) {
|
if (unsavedChanges) {
|
||||||
if (!confirm("Hai modifiche non salvate. Vuoi davvero uscire?")) {
|
if (!confirm("Hai modifiche non salvate. Vuoi davvero uscire?")) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
@@ -598,147 +778,20 @@ $(document).ready(function () {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// --- SAVE BUTTON ---
|
// --- SAVE BUTTON (disabilitato per ora) ---
|
||||||
$("#savePhotoBtn").on("click", function () {
|
$("#savePhotoBtn").on("click", function () {
|
||||||
const canvas = document.getElementById("photoCanvas");
|
alert("Funzionalità di salvataggio non implementata per ora.");
|
||||||
const ctx = canvas.getContext("2d");
|
console.log("Pulsante Salva Foto cliccato");
|
||||||
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);
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// ===================
|
// ===================
|
||||||
// DEBUG HOVER LOGS
|
// DEBUG HOVER LOGS
|
||||||
// ===================
|
// ===================
|
||||||
$(document).on("mouseenter", "tr", function () {
|
$(document).on("mouseenter", "tr", function () {
|
||||||
// console.log("Mouse entrato su riga");
|
console.log("Mouse entrato su riga");
|
||||||
});
|
});
|
||||||
|
|
||||||
$(document).on("mouseleave", "tr", function () {
|
$(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 webcamVideo = document.getElementById("webcamVideo");
|
||||||
const captureBtn = document.getElementById("captureBtn");
|
const captureBtn = document.getElementById("captureBtn");
|
||||||
const closeWebcamBtn = document.getElementById("closeWebcamBtn");
|
const closeWebcamBtn = document.getElementById("closeWebcamBtn");
|
||||||
|
const webcamSelect = document.getElementById("webcamSelect");
|
||||||
let stream = null;
|
let stream = null;
|
||||||
|
|
||||||
if (!navigator.mediaDevices || !navigator.mediaDevices.getUserMedia) {
|
if (!navigator.mediaDevices || !navigator.mediaDevices.getUserMedia) {
|
||||||
@@ -41,25 +42,116 @@ document.addEventListener("DOMContentLoaded", function () {
|
|||||||
!webcamArea ||
|
!webcamArea ||
|
||||||
!webcamVideo ||
|
!webcamVideo ||
|
||||||
!captureBtn ||
|
!captureBtn ||
|
||||||
!closeWebcamBtn
|
!closeWebcamBtn ||
|
||||||
|
!webcamSelect
|
||||||
) {
|
) {
|
||||||
console.error("Elementi webcam mancanti");
|
console.error("Elementi webcam mancanti", {
|
||||||
|
openWebcamBtn,
|
||||||
|
webcamArea,
|
||||||
|
webcamVideo,
|
||||||
|
captureBtn,
|
||||||
|
closeWebcamBtn,
|
||||||
|
webcamSelect,
|
||||||
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Apri la webcam
|
// Funzione per avviare la webcam con un deviceId specifico
|
||||||
openWebcamBtn.addEventListener("click", async () => {
|
async function startWebcam(deviceId = null) {
|
||||||
try {
|
try {
|
||||||
stream = await navigator.mediaDevices.getUserMedia({
|
// Ferma il flusso video esistente, se presente
|
||||||
video: true,
|
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;
|
webcamVideo.srcObject = stream;
|
||||||
webcamArea.style.display = "block";
|
webcamArea.style.display = "block";
|
||||||
openWebcamBtn.style.display = "none";
|
openWebcamBtn.style.display = "none";
|
||||||
dropArea.style.display = "none";
|
dropArea.style.display = "none";
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
console.error("Errore nell'accesso alla webcam:", error);
|
||||||
alert("Errore nell'accesso alla webcam: " + error.message);
|
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
|
// Cattura la foto
|
||||||
@@ -71,7 +163,6 @@ document.addEventListener("DOMContentLoaded", function () {
|
|||||||
.getContext("2d")
|
.getContext("2d")
|
||||||
.drawImage(webcamVideo, 0, 0, canvas.width, canvas.height);
|
.drawImage(webcamVideo, 0, 0, canvas.width, canvas.height);
|
||||||
|
|
||||||
// Converti l'immagine in un file
|
|
||||||
canvas.toBlob(async (blob) => {
|
canvas.toBlob(async (blob) => {
|
||||||
const file = new File(
|
const file = new File(
|
||||||
[blob],
|
[blob],
|
||||||
@@ -84,24 +175,16 @@ document.addEventListener("DOMContentLoaded", function () {
|
|||||||
loader.style.display = "flex";
|
loader.style.display = "flex";
|
||||||
}
|
}
|
||||||
await handleFiles([file], iddatadb);
|
await handleFiles([file], iddatadb);
|
||||||
closeWebcam();
|
if (stream) {
|
||||||
}, "image/jpeg");
|
stream.getTracks().forEach((track) => track.stop());
|
||||||
});
|
stream = null;
|
||||||
|
webcamVideo.srcObject = null;
|
||||||
// Chiudi la webcam
|
}
|
||||||
closeWebcamBtn.addEventListener("click", () => {
|
|
||||||
closeWebcam();
|
|
||||||
});
|
|
||||||
|
|
||||||
function closeWebcam() {
|
|
||||||
if (stream) {
|
|
||||||
stream.getTracks().forEach((track) => track.stop());
|
|
||||||
webcamVideo.srcObject = null;
|
|
||||||
webcamArea.style.display = "none";
|
webcamArea.style.display = "none";
|
||||||
openWebcamBtn.style.display = "block";
|
openWebcamBtn.style.display = "block";
|
||||||
dropArea.style.display = "block";
|
dropArea.style.display = "block";
|
||||||
}
|
}, "image/jpeg");
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Funzione per attaccare gli event listener al contenuto del popup
|
// Funzione per attaccare gli event listener al contenuto del popup
|
||||||
@@ -198,6 +281,9 @@ document.addEventListener("DOMContentLoaded", function () {
|
|||||||
});
|
});
|
||||||
const result = await response.json();
|
const result = await response.json();
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
|
console.log(
|
||||||
|
"Foto eliminata con successo, ricarico popup",
|
||||||
|
);
|
||||||
loadPopupContent(iddatadb);
|
loadPopupContent(iddatadb);
|
||||||
} else {
|
} else {
|
||||||
alert(
|
alert(
|
||||||
|
|||||||
@@ -116,16 +116,19 @@ $result->saveToFile($qrCodeFile);
|
|||||||
<input type="file" id="photoInput" multiple accept="image/*" style="display: none;">
|
<input type="file" id="photoInput" multiple accept="image/*" style="display: none;">
|
||||||
</div>
|
</div>
|
||||||
<!-- Area per la webcam -->
|
<!-- Area per la webcam -->
|
||||||
|
<!-- Area per la webcam -->
|
||||||
<div id="webcamArea" style="display: none; text-align: center; margin-bottom: 20px;">
|
<div id="webcamArea" style="display: none; text-align: center; margin-bottom: 20px;">
|
||||||
<p>Webcam Preview</p>
|
<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>
|
<video id="webcamVideo" autoplay playsinline style="max-width: 100%; max-height: 300px;"></video>
|
||||||
<div style="margin-top: 10px;">
|
<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="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>
|
<button id="closeWebcamBtn" style="padding: 10px 20px; background: #dc3545; color: white; border: none; cursor: pointer;">Close Webcam</button>
|
||||||
</div>
|
</div>
|
||||||
</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>
|
<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 -->
|
||||||
<!-- Elenco delle foto -->
|
|
||||||
<div id="photosList">
|
<div id="photosList">
|
||||||
<?php if (empty($photos)): ?>
|
<?php if (empty($photos)): ?>
|
||||||
<p>No Photos present.</p>
|
<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