added logs
This commit is contained in:
parent
c533973420
commit
57ab20ed1f
BIN
public/photostrf/qrcodes/qrcode_365.png
Normal file
BIN
public/photostrf/qrcodes/qrcode_365.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 508 B |
0
public/tmp/import_debug.log
Normal file
0
public/tmp/import_debug.log
Normal file
@ -31,6 +31,6 @@ Content-Length: 51
|
||||
< strict-transport-security: max-age=2592000
|
||||
< x-powered-by: ASP.NET
|
||||
< x-content-type-options: nosniff
|
||||
< date: Tue, 08 Jul 2025 10:12:39 GMT
|
||||
< date: Tue, 08 Jul 2025 14:12:35 GMT
|
||||
<
|
||||
* Connection #0 to host 93.43.5.102 left intact
|
||||
|
||||
@ -15,11 +15,11 @@
|
||||
* [HTTP/2] [1] [:scheme: https]
|
||||
* [HTTP/2] [1] [:authority: 93.43.5.102]
|
||||
* [HTTP/2] [1] [:path: /limsapi/api/odata/SchemaCustomField]
|
||||
* [HTTP/2] [1] [authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJodHRwOi8vc2NoZW1hcy54bWxzb2FwLm9yZy93cy8yMDA1LzA1L2lkZW50aXR5L2NsYWltcy9uYW1laWRlbnRpZmllciI6IjQ5MiIsIlhhZlNlY3VyaXR5QXV0aFBhc3NlZCI6IlhhZlNlY3VyaXR5QXV0aFBhc3NlZCIsImh0dHA6Ly9zY2hlbWFzLnhtbHNvYXAub3JnL3dzLzIwMDUvMDUvaWRlbnRpdHkvY2xhaW1zL25hbWUiOiJXZWJBcGlVc2VyIiwiWGFmU2VjdXJpdHkiOiJYYWZTZWN1cml0eSIsIlhhZkxvZ29uUGFyYW1zIjoicTFZS0xVNHQ4a3ZNVFZXeVVncFBUWElzeUFRSktPa29CU1FXRjVmbkY2VUF4Y3RUa3hJTE1rdUI0Z2FHU3JVQSIsImV4cCI6MTc1MTk3Njc1OSwiaXNzIjoiTXkiLCJhdWQiOiJodHRwOi8vbG9jYWxob3N0OjQyMDAifQ.CgecorvqDyNuZYSU8FJSIb5kjPs0TnjXqoNbdMS0IzI]
|
||||
* [HTTP/2] [1] [authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJodHRwOi8vc2NoZW1hcy54bWxzb2FwLm9yZy93cy8yMDA1LzA1L2lkZW50aXR5L2NsYWltcy9uYW1laWRlbnRpZmllciI6IjQ5MiIsIlhhZlNlY3VyaXR5QXV0aFBhc3NlZCI6IlhhZlNlY3VyaXR5QXV0aFBhc3NlZCIsImh0dHA6Ly9zY2hlbWFzLnhtbHNvYXAub3JnL3dzLzIwMDUvMDUvaWRlbnRpdHkvY2xhaW1zL25hbWUiOiJXZWJBcGlVc2VyIiwiWGFmU2VjdXJpdHkiOiJYYWZTZWN1cml0eSIsIlhhZkxvZ29uUGFyYW1zIjoicTFZS0xVNHQ4a3ZNVFZXeVVncFBUWElzeUFRSktPa29CU1FXRjVmbkY2VUF4Y3RUa3hJTE1rdUI0Z2FHU3JVQSIsImV4cCI6MTc1MTk5MTE1NSwiaXNzIjoiTXkiLCJhdWQiOiJodHRwOi8vbG9jYWxob3N0OjQyMDAifQ.uNHyCIqeByDG3reSjXU6Y3QZz7xnug9lAnlg2KPk8x8]
|
||||
* [HTTP/2] [1] [accept: application/json]
|
||||
> GET /limsapi/api/odata/SchemaCustomField HTTP/2
|
||||
Host: 93.43.5.102
|
||||
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJodHRwOi8vc2NoZW1hcy54bWxzb2FwLm9yZy93cy8yMDA1LzA1L2lkZW50aXR5L2NsYWltcy9uYW1laWRlbnRpZmllciI6IjQ5MiIsIlhhZlNlY3VyaXR5QXV0aFBhc3NlZCI6IlhhZlNlY3VyaXR5QXV0aFBhc3NlZCIsImh0dHA6Ly9zY2hlbWFzLnhtbHNvYXAub3JnL3dzLzIwMDUvMDUvaWRlbnRpdHkvY2xhaW1zL25hbWUiOiJXZWJBcGlVc2VyIiwiWGFmU2VjdXJpdHkiOiJYYWZTZWN1cml0eSIsIlhhZkxvZ29uUGFyYW1zIjoicTFZS0xVNHQ4a3ZNVFZXeVVncFBUWElzeUFRSktPa29CU1FXRjVmbkY2VUF4Y3RUa3hJTE1rdUI0Z2FHU3JVQSIsImV4cCI6MTc1MTk3Njc1OSwiaXNzIjoiTXkiLCJhdWQiOiJodHRwOi8vbG9jYWxob3N0OjQyMDAifQ.CgecorvqDyNuZYSU8FJSIb5kjPs0TnjXqoNbdMS0IzI
|
||||
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJodHRwOi8vc2NoZW1hcy54bWxzb2FwLm9yZy93cy8yMDA1LzA1L2lkZW50aXR5L2NsYWltcy9uYW1laWRlbnRpZmllciI6IjQ5MiIsIlhhZlNlY3VyaXR5QXV0aFBhc3NlZCI6IlhhZlNlY3VyaXR5QXV0aFBhc3NlZCIsImh0dHA6Ly9zY2hlbWFzLnhtbHNvYXAub3JnL3dzLzIwMDUvMDUvaWRlbnRpdHkvY2xhaW1zL25hbWUiOiJXZWJBcGlVc2VyIiwiWGFmU2VjdXJpdHkiOiJYYWZTZWN1cml0eSIsIlhhZkxvZ29uUGFyYW1zIjoicTFZS0xVNHQ4a3ZNVFZXeVVncFBUWElzeUFRSktPa29CU1FXRjVmbkY2VUF4Y3RUa3hJTE1rdUI0Z2FHU3JVQSIsImV4cCI6MTc1MTk5MTE1NSwiaXNzIjoiTXkiLCJhdWQiOiJodHRwOi8vbG9jYWxob3N0OjQyMDAifQ.uNHyCIqeByDG3reSjXU6Y3QZz7xnug9lAnlg2KPk8x8
|
||||
Accept: application/json
|
||||
|
||||
< HTTP/2 200
|
||||
@ -30,6 +30,6 @@ Accept: application/json
|
||||
< odata-version: 4.0
|
||||
< x-powered-by: ASP.NET
|
||||
< x-content-type-options: nosniff
|
||||
< date: Tue, 08 Jul 2025 10:12:42 GMT
|
||||
< date: Tue, 08 Jul 2025 14:12:35 GMT
|
||||
<
|
||||
* Connection #0 to host 93.43.5.102 left intact
|
||||
|
||||
File diff suppressed because one or more lines are too long
6
public/userarea/errortest.php
Normal file
6
public/userarea/errortest.php
Normal file
@ -0,0 +1,6 @@
|
||||
<?php
|
||||
ini_set('log_errors', 1);
|
||||
ini_set('error_log', __DIR__ . '/import_debug.log');
|
||||
|
||||
|
||||
error_log("TEST: errore manuale");
|
||||
37
public/userarea/import_debug.log
Normal file
37
public/userarea/import_debug.log
Normal file
File diff suppressed because one or more lines are too long
1072
public/userarea/import_edit2 - bck080725.php
Normal file
1072
public/userarea/import_edit2 - bck080725.php
Normal file
File diff suppressed because it is too large
Load Diff
@ -3,10 +3,9 @@
|
||||
ini_set('display_errors', 1);
|
||||
ini_set('display_startup_errors', 1);
|
||||
error_reporting(E_ALL);
|
||||
|
||||
// Configura il log per Windows
|
||||
ini_set('error_log', 'C:\\xampp\\htdocs\\trf_certest\\tmp\\import_debug.log');
|
||||
ini_set('log_errors', 1);
|
||||
ini_set('error_log', __DIR__ . '/import_debug.log');
|
||||
|
||||
|
||||
// Test iniziale del log
|
||||
error_log("Inizio importazione alle " . date('Y-m-d H:i:s'));
|
||||
@ -39,7 +38,7 @@ $pdo = $db->getConnection();
|
||||
$importReferenceCode = date('YmdHis') . '-' . uniqid();
|
||||
|
||||
// Recupera tutti i mapping dal template (automatici e manuali)
|
||||
$stmt = $pdo->prepare("SELECT id, field_id, field_id AS excel_column, field_id AS mysql_column, data_type, is_required, default_value, is_manual, field_label FROM template_mapping WHERE template_id = ?");
|
||||
$stmt = $pdo->prepare("SELECT id, field_id, field_id AS excel_column, field_id AS mysql_column, data_type, is_required, manual_default, is_manual, field_label FROM template_mapping WHERE template_id = ?");
|
||||
$stmt->execute([$template_id]);
|
||||
$allMappings = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
@ -65,10 +64,10 @@ foreach ($selected_rows as $rowIndex) {
|
||||
$excelColumnIndex = array_search(trim($mapping['excel_column']), array_map('trim', $columns));
|
||||
if ($excelColumnIndex !== false) {
|
||||
$mysqlColumn = $mapping['mysql_column'];
|
||||
$value = $row[$excelColumnIndex] ?? $mapping['default_value'];
|
||||
$value = $row[$excelColumnIndex] ?? $mapping['manual_default'];
|
||||
|
||||
if ($mapping['is_required'] && (is_null($value) || $value === '')) {
|
||||
$value = $mapping['default_value'];
|
||||
$value = $mapping['manual_default'];
|
||||
if (is_null($value)) {
|
||||
header("Location: import_xls.php?id=$template_id&status=error&message=" . urlencode("Valore richiesto mancante per la colonna $mysqlColumn"));
|
||||
exit;
|
||||
@ -77,21 +76,21 @@ foreach ($selected_rows as $rowIndex) {
|
||||
|
||||
switch ($mapping['data_type']) {
|
||||
case 'INT':
|
||||
$value = is_numeric($value) ? (int)$value : ($mapping['default_value'] ?? 0);
|
||||
$value = is_numeric($value) ? (int)$value : ($mapping['manual_default'] ?? 0);
|
||||
break;
|
||||
case 'DATE':
|
||||
$value = !empty($value) ? date('Y-m-d', strtotime($value)) : ($mapping['default_value'] ?? null);
|
||||
if ($mapping['default_value'] === 'today' && is_null($value)) {
|
||||
$value = !empty($value) ? date('Y-m-d', strtotime($value)) : ($mapping['manual_default'] ?? null);
|
||||
if ($mapping['manual_default'] === 'today' && is_null($value)) {
|
||||
$value = date('Y-m-d');
|
||||
}
|
||||
break;
|
||||
case 'CHAR':
|
||||
$value = !empty($value) ? substr($value, 0, 1) : ($mapping['default_value'] ?? '');
|
||||
$value = !empty($value) ? substr($value, 0, 1) : ($mapping['manual_default'] ?? '');
|
||||
break;
|
||||
case 'Testo':
|
||||
case 'VARCHAR':
|
||||
default:
|
||||
$value = !empty($value) ? htmlspecialchars($value) : ($mapping['default_value'] ?? '');
|
||||
$value = !empty($value) ? htmlspecialchars($value) : ($mapping['manual_default'] ?? '');
|
||||
break;
|
||||
}
|
||||
|
||||
@ -137,48 +136,46 @@ foreach ($selected_rows as $rowIndex) {
|
||||
|
||||
// Inserisci tutti i campi (automatici e manuali) in import_data_details
|
||||
foreach ($allMappings as $mapping) {
|
||||
$fieldValue = '';
|
||||
$fieldValue = null;
|
||||
if (!$mapping['is_manual']) { // Campi automatici dall'XLS
|
||||
$excelColumnIndex = array_search(trim($mapping['excel_column']), array_map('trim', $columns));
|
||||
if ($excelColumnIndex !== false) {
|
||||
$fieldValue = $row[$excelColumnIndex] ?? $mapping['default_value'];
|
||||
$excelColumn = trim($mapping['excel_column']);
|
||||
$excelColumnIndex = array_search($excelColumn, array_map('trim', $columns));
|
||||
if ($excelColumnIndex !== false && isset($row[$excelColumnIndex]) && $row[$excelColumnIndex] !== '') {
|
||||
$fieldValue = $row[$excelColumnIndex];
|
||||
error_log("Found Excel column '$excelColumn' at index $excelColumnIndex, value: " . var_export($fieldValue, true));
|
||||
} else {
|
||||
$fieldValue = $mapping['default_value'] ?? '';
|
||||
$fieldValue = $mapping['manual_default'] ?? '';
|
||||
error_log("Excel column '$excelColumn' not found or empty, using default: " . var_export($fieldValue, true));
|
||||
}
|
||||
switch ($mapping['data_type']) {
|
||||
case 'INT':
|
||||
$fieldValue = is_numeric($fieldValue) ? (int)$fieldValue : ($mapping['default_value'] ?? 0);
|
||||
$fieldValue = is_numeric($fieldValue) ? (int)$fieldValue : ($mapping['manual_default'] ?? 0);
|
||||
break;
|
||||
case 'DATE':
|
||||
$fieldValue = !empty($fieldValue) ? date('Y-m-d', strtotime($fieldValue)) : ($mapping['default_value'] ?? '');
|
||||
if ($mapping['default_value'] === 'today' && empty($fieldValue)) {
|
||||
$fieldValue = date('Y-m-d');
|
||||
}
|
||||
$fieldValue = !empty($fieldValue) ? date('Y-m-d', strtotime($fieldValue)) : ($mapping['manual_default'] === 'today' ? date('Y-m-d') : ($mapping['manual_default'] ?? ''));
|
||||
break;
|
||||
case 'CHAR':
|
||||
$fieldValue = !empty($fieldValue) ? substr($fieldValue, 0, 1) : ($mapping['default_value'] ?? '');
|
||||
$fieldValue = !empty($fieldValue) ? substr((string)$fieldValue, 0, 1) : ($mapping['manual_default'] ?? '');
|
||||
break;
|
||||
case 'Testo':
|
||||
case 'VARCHAR':
|
||||
default:
|
||||
$fieldValue = !empty($fieldValue) ? htmlspecialchars($fieldValue) : ($mapping['default_value'] ?? '');
|
||||
$fieldValue = !empty($fieldValue) ? htmlspecialchars((string)$fieldValue) : ($mapping['manual_default'] ?? '');
|
||||
break;
|
||||
}
|
||||
} else { // Campi manuali
|
||||
$fieldValue = $mapping['default_value'] ?? '';
|
||||
if ($mapping['data_type'] === 'DATE' && $mapping['default_value'] === 'today') {
|
||||
$fieldValue = $mapping['manual_default'] ?? '';
|
||||
if ($mapping['data_type'] === 'DATE' && $mapping['manual_default'] === 'today') {
|
||||
$fieldValue = date('Y-m-d');
|
||||
} elseif (!empty($mapping['default_value'])) {
|
||||
$fieldValue = $mapping['default_value']; // Forza l'uso del default_value
|
||||
}
|
||||
}
|
||||
// Log dettagliato prima dell'inserimento
|
||||
error_log("Inserting - Mapping ID: " . $mapping['id'] . ", Field Value: " . var_export($fieldValue, true) . ", Is Manual: " . $mapping['is_manual'] . ", Excel Column: " . ($mapping['excel_column'] ?? 'N/A') . ", Default Value: " . ($mapping['default_value'] ?? 'N/A'));
|
||||
|
||||
if ($mapping['is_required'] && (is_null($fieldValue) || $fieldValue === '')) {
|
||||
error_log("Required field missing for mapping ID: " . $mapping['id'] . ", field: " . $mapping['field_label']);
|
||||
}
|
||||
error_log("Inserting into import_data_details - Mapping ID: " . $mapping['id'] . ", Field Value: " . var_export($fieldValue, true) . ", Is Manual: " . $mapping['is_manual'] . ", Excel Column: " . ($mapping['excel_column'] ?? 'N/A') . ", Manual Default: " . ($mapping['manual_default'] ?? 'N/A'));
|
||||
$stmt = $pdo->prepare("INSERT INTO import_data_details (id, mapping_id, field_value) VALUES (?, ?, ?)");
|
||||
$stmt->execute([$iddatadb, $mapping['id'], $fieldValue]);
|
||||
// Log della query eseguita
|
||||
error_log("Executed Query for ID $iddatadb, Mapping ID: " . $mapping['id'] . ", Field Value: " . $fieldValue);
|
||||
error_log("Inserted into import_data_details for ID $iddatadb, Mapping ID: " . $mapping['id'] . ", Field Value: " . var_export($fieldValue, true));
|
||||
}
|
||||
}
|
||||
|
||||
@ -194,7 +191,7 @@ $importedData = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
// Recupera i dettagli manuali da import_data_details
|
||||
$stmt = $pdo->prepare("
|
||||
SELECT d.id AS detail_id, d.id AS datadb_id, d.mapping_id, d.field_value, m.field_id, m.data_type, m.is_required, m.default_value
|
||||
SELECT d.id AS detail_id, d.id AS datadb_id, d.mapping_id, d.field_value, m.field_id, m.data_type, m.is_required, m.manual_default
|
||||
FROM import_data_details d
|
||||
JOIN template_mapping m ON d.mapping_id = m.id
|
||||
WHERE d.id IN (" . implode(',', array_fill(0, count($insertedIds), '?')) . ")
|
||||
@ -286,7 +283,7 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
|
||||
.grid-cell select {
|
||||
width: 100%;
|
||||
box-sizing: border-box;
|
||||
border: 1px solid #ced4da;
|
||||
border: гордичка 1px solid #ced4da;
|
||||
border-radius: 4px;
|
||||
padding: 5px;
|
||||
font-size: 14px;
|
||||
@ -407,58 +404,6 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.photo-item {
|
||||
transition: background-color 0.3s;
|
||||
}
|
||||
|
||||
.photo-item:hover {
|
||||
background-color: #f8f9fa;
|
||||
}
|
||||
|
||||
#dropArea.highlight {
|
||||
border-color: #28a745;
|
||||
background-color: #e9ecef;
|
||||
}
|
||||
|
||||
.image-modal {
|
||||
display: none;
|
||||
position: fixed;
|
||||
z-index: 1100;
|
||||
left: 0;
|
||||
top: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
overflow: auto;
|
||||
background-color: rgba(0, 0, 0, 0.8);
|
||||
}
|
||||
|
||||
.image-modal-content {
|
||||
margin: auto;
|
||||
display: block;
|
||||
max-width: 90%;
|
||||
max-height: 90vh;
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
}
|
||||
|
||||
.image-modal-close {
|
||||
position: absolute;
|
||||
top: 15px;
|
||||
right: 35px;
|
||||
color: #fff;
|
||||
font-size: 40px;
|
||||
font-weight: bold;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.image-modal-close:hover,
|
||||
.image-modal-close:focus {
|
||||
color: #bbb;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.overlay {
|
||||
display: none;
|
||||
position: fixed;
|
||||
@ -469,6 +414,11 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
|
||||
background: rgba(0, 0, 0, 0.5);
|
||||
z-index: 1049;
|
||||
}
|
||||
|
||||
.grid-cell.missing-required {
|
||||
border: 2px solid red;
|
||||
background-color: #ffe6e6;
|
||||
}
|
||||
</style>
|
||||
<title>Edit Imported Data - <?= htmlspecialchars($titlewebsite, ENT_QUOTES, 'UTF-8'); ?></title>
|
||||
</head>
|
||||
@ -514,8 +464,8 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
|
||||
}
|
||||
// Aggiungi gli input per i campi manuali con propagate-btn
|
||||
foreach ($manualMappings as $manualMapping) {
|
||||
$fieldValue = $manualMapping['default_value'];
|
||||
if ($manualMapping['data_type'] === 'DATE' && $manualMapping['default_value'] === 'today') {
|
||||
$fieldValue = $manualMapping['manual_default'];
|
||||
if ($manualMapping['data_type'] === 'DATE' && $manualMapping['manual_default'] === 'today') {
|
||||
$fieldValue = date('Y-m-d');
|
||||
}
|
||||
$requiredAttr = $manualMapping['is_required'] ? 'required' : '';
|
||||
@ -611,10 +561,11 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
|
||||
$rowDetails = array_filter($manualDetails, fn($d) => $d['datadb_id'] == $row['iddatadb']);
|
||||
foreach ($autoMappings as $mapping) {
|
||||
$detail = array_filter($rowDetails, fn($d) => $d['mapping_id'] == $mapping['id']);
|
||||
$detail = reset($detail) ?: ['field_value' => $mapping['default_value']];
|
||||
$fieldValue = $detail['field_value'] ?? $mapping['default_value'];
|
||||
$detail = reset($detail) ?: ['field_value' => $mapping['manual_default']];
|
||||
$fieldValue = $detail['field_value'] ?? $mapping['manual_default'] ?? '';
|
||||
$requiredClass = ($mapping['is_required'] && (is_null($fieldValue) || $fieldValue === '')) ? 'missing-required' : '';
|
||||
$requiredAttr = $mapping['is_required'] ? 'required' : '';
|
||||
echo "<div class='grid-cell editable-cell' data-col='{$mapping['field_id']}' data-row='$index' data-index='$cellIndex' style='flex: 0 0 150px;'>";
|
||||
echo "<div class='grid-cell editable-cell $requiredClass' data-col='{$mapping['field_id']}' data-row='$index' data-index='$cellIndex' style='flex: 0 0 150px;'>";
|
||||
if ($mapping['data_type'] === 'DATE') {
|
||||
echo "<input type='date' name='rows[$index][details][{$mapping['id']}][field_value]' value='" . htmlspecialchars($fieldValue) . "' class='cell-input' $requiredAttr>";
|
||||
} elseif ($mapping['data_type'] === 'INT') {
|
||||
@ -628,13 +579,14 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
|
||||
// Aggiungi i campi manuali da import_data_details
|
||||
foreach ($manualMappings as $mapping) {
|
||||
$detail = array_filter($rowDetails, fn($d) => $d['mapping_id'] == $mapping['id']);
|
||||
$detail = reset($detail) ?: ['field_value' => $mapping['default_value']];
|
||||
$fieldValue = $detail['field_value'] ?? $mapping['default_value'];
|
||||
if ($mapping['data_type'] === 'DATE' && $mapping['default_value'] === 'today' && empty($fieldValue)) {
|
||||
$detail = reset($detail) ?: ['field_value' => $mapping['manual_default']];
|
||||
$fieldValue = $detail['field_value'] ?? $mapping['manual_default'] ?? '';
|
||||
if ($mapping['data_type'] === 'DATE' && $mapping['manual_default'] === 'today' && empty($fieldValue)) {
|
||||
$fieldValue = date('Y-m-d');
|
||||
}
|
||||
$requiredClass = ($mapping['is_required'] && (is_null($fieldValue) || $fieldValue === '')) ? 'missing-required' : '';
|
||||
$requiredAttr = $mapping['is_required'] ? 'required' : '';
|
||||
echo "<div class='grid-cell editable-cell' data-col='{$mapping['field_id']}' data-row='$index' data-index='$cellIndex' style='flex: 0 0 150px;'>";
|
||||
echo "<div class='grid-cell editable-cell $requiredClass' data-col='{$mapping['field_id']}' data-row='$index' data-index='$cellIndex' style='flex: 0 0 150px;'>";
|
||||
if ($mapping['data_type'] === 'DATE') {
|
||||
echo "<input type='date' name='rows[$index][details][{$mapping['id']}][field_value]' value='" . htmlspecialchars($fieldValue) . "' class='cell-input' $requiredAttr>";
|
||||
} elseif ($mapping['data_type'] === 'INT') {
|
||||
@ -667,14 +619,7 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
|
||||
</div>
|
||||
</form>
|
||||
<?php include 'modal_parts.php'; ?>
|
||||
<div id="photosModal" class="modal">
|
||||
<div class="modal-content">
|
||||
<span class="close-btn">×</span>
|
||||
<div id="popupContent">
|
||||
<p>Loading...</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php include 'photos_functions.php'; ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@ -685,7 +630,9 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
|
||||
</div>
|
||||
<?php include('jsinclude.php'); ?>
|
||||
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
|
||||
<script src="photos.js"></script>
|
||||
<script src="parts.js"></script>
|
||||
<script src="tracking.js"></script>
|
||||
<script>
|
||||
document.addEventListener("DOMContentLoaded", function() {
|
||||
const inputs = document.querySelectorAll('.cell-input');
|
||||
@ -700,372 +647,102 @@ foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
|
||||
|
||||
const saveButtons = document.querySelectorAll('.save-btn');
|
||||
saveButtons.forEach(button => {
|
||||
button.addEventListener('click', function() {
|
||||
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, '');
|
||||
if (name !== 'user_name') {
|
||||
formData.append(name, input.value);
|
||||
}
|
||||
});
|
||||
formData.append('iddatadb', iddatadb);
|
||||
|
||||
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);
|
||||
} else {
|
||||
alert('Errore durante il salvataggio: ' + data.message);
|
||||
}
|
||||
})
|
||||
.catch(error => alert('Errore durante il salvataggio: ' + error.message));
|
||||
});
|
||||
});
|
||||
|
||||
// Propagazione del valore dall'input superiore
|
||||
const propagateButtons = document.querySelectorAll('.propagate-btn');
|
||||
propagateButtons.forEach(button => {
|
||||
button.addEventListener('click', function() {
|
||||
const columnIndex = this.getAttribute('data-column');
|
||||
const input = this.previousElementSibling;
|
||||
const value = input.value;
|
||||
|
||||
const cells = document.querySelectorAll(`.grid-cell[data-index="${columnIndex}"]`);
|
||||
cells.forEach(cell => {
|
||||
const rowInput = cell.querySelector('input, select');
|
||||
if (rowInput) {
|
||||
if (rowInput.type === 'date') {
|
||||
rowInput.value = value;
|
||||
} else if (rowInput.tagName === 'SELECT') {
|
||||
rowInput.value = value;
|
||||
} else {
|
||||
rowInput.value = value;
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
// Ridimensionamento colonne
|
||||
const resizers = document.querySelectorAll('.resizer');
|
||||
let currentResizer = null;
|
||||
let startX = 0;
|
||||
let startWidth = 0;
|
||||
let columnIndex = 0;
|
||||
resizers.forEach(resizer => {
|
||||
resizer.addEventListener('mousedown', function(e) {
|
||||
currentResizer = resizer;
|
||||
const header = resizer.parentElement;
|
||||
columnIndex = header.getAttribute('data-index');
|
||||
startX = e.pageX;
|
||||
startWidth = header.offsetWidth;
|
||||
document.addEventListener('mousemove', resize);
|
||||
document.addEventListener('mouseup', stopResize);
|
||||
});
|
||||
|
||||
function resize(e) {
|
||||
if (currentResizer) {
|
||||
const dx = e.pageX - startX;
|
||||
const newWidth = startWidth + dx;
|
||||
const headers = document.querySelectorAll(`.grid-header[data-index="${columnIndex}"]`);
|
||||
const cells = document.querySelectorAll(`.grid-cell[data-index="${columnIndex}"]`);
|
||||
headers.forEach(header => header.style.flex = `0 0 ${newWidth}px`);
|
||||
cells.forEach(cell => cell.style.flex = `0 0 ${newWidth}px`);
|
||||
}
|
||||
}
|
||||
|
||||
function stopResize() {
|
||||
if (currentResizer) {
|
||||
document.removeEventListener('mousemove', resize);
|
||||
document.removeEventListener('mouseup', stopResize);
|
||||
currentResizer = null;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Gestione del popup per le foto
|
||||
async function loadPopupContent(iddatadb) {
|
||||
const popupContent = document.getElementById('popupContent');
|
||||
try {
|
||||
const response = await fetch(`photos_popup.php?iddatadb=${iddatadb}`);
|
||||
popupContent.innerHTML = await response.text();
|
||||
|
||||
// Dopo aver caricato il contenuto, associa gli event listener
|
||||
attachPhotoEventListeners(iddatadb);
|
||||
} catch (error) {
|
||||
popupContent.innerHTML = `<p>Errore durante il caricamento: ${error.message}</p>`;
|
||||
}
|
||||
}
|
||||
|
||||
function attachPhotoEventListeners(iddatadb) {
|
||||
const dropArea = document.getElementById('dropArea');
|
||||
const photoInput = document.getElementById('photoInput');
|
||||
|
||||
if (!dropArea || !photoInput) {
|
||||
console.error('Elementi dropArea o photoInput non trovati nel DOM');
|
||||
return;
|
||||
}
|
||||
|
||||
console.log('Associando event listener per drag-and-drop'); // Debug
|
||||
|
||||
// Gestione drag-and-drop
|
||||
['dragenter', 'dragover', 'dragleave', 'drop'].forEach(eventName => {
|
||||
dropArea.addEventListener(eventName, preventDefaults, false);
|
||||
});
|
||||
|
||||
function preventDefaults(e) {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
}
|
||||
|
||||
['dragenter', 'dragover'].forEach(eventName => {
|
||||
dropArea.addEventListener(eventName, () => {
|
||||
console.log('Drag enter/over'); // Debug
|
||||
dropArea.classList.add('highlight');
|
||||
}, false);
|
||||
});
|
||||
|
||||
['dragleave', 'drop'].forEach(eventName => {
|
||||
dropArea.addEventListener(eventName, () => {
|
||||
console.log('Drag leave/drop'); // Debug
|
||||
dropArea.classList.remove('highlight');
|
||||
}, false);
|
||||
});
|
||||
|
||||
dropArea.addEventListener('drop', (e) => {
|
||||
console.log('File droppato'); // Debug
|
||||
const files = e.dataTransfer.files;
|
||||
handleFiles(files, iddatadb);
|
||||
}, false);
|
||||
|
||||
dropArea.addEventListener('click', () => {
|
||||
console.log('Click su dropArea'); // Debug
|
||||
photoInput.click();
|
||||
}, false);
|
||||
|
||||
photoInput.addEventListener('change', () => {
|
||||
console.log('File selezionato tramite input'); // Debug
|
||||
handleFiles(photoInput.files, iddatadb);
|
||||
}, false);
|
||||
|
||||
// Gestione della rimozione delle foto
|
||||
const deleteButtons = document.querySelectorAll('.delete-photo-btn');
|
||||
deleteButtons.forEach(button => {
|
||||
button.addEventListener('click', async function() {
|
||||
const photoId = this.getAttribute('data-photo-id');
|
||||
if (confirm('Sei sicuro di voler eliminare questa foto?')) {
|
||||
try {
|
||||
const response = await fetch('delete_photo.php', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
},
|
||||
body: `photo_id=${photoId}`
|
||||
});
|
||||
const result = await response.json();
|
||||
|
||||
if (result.success) {
|
||||
// Ricarica il contenuto del popup
|
||||
loadPopupContent(iddatadb);
|
||||
} else {
|
||||
alert('Errore durante l\'eliminazione: ' + result.message);
|
||||
}
|
||||
} catch (error) {
|
||||
alert('Errore durante l\'eliminazione: ' + error.message);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Gestione del click sulle immagini per ingrandirle
|
||||
document.querySelectorAll('.thumbnail').forEach(img => {
|
||||
img.addEventListener('click', function() {
|
||||
const modal = document.getElementById('imageModal');
|
||||
const enlargedImage = document.getElementById('enlargedImage');
|
||||
enlargedImage.src = this.src;
|
||||
modal.style.display = 'block';
|
||||
});
|
||||
});
|
||||
|
||||
// Gestione della chiusura del modal immagine
|
||||
const imageModal = document.getElementById('imageModal');
|
||||
const imageCloseBtn = document.querySelector('.image-modal-close');
|
||||
if (imageCloseBtn) {
|
||||
imageCloseBtn.addEventListener('click', function() {
|
||||
imageModal.style.display = 'none';
|
||||
});
|
||||
}
|
||||
if (imageModal) {
|
||||
imageModal.addEventListener('click', function(event) {
|
||||
if (event.target === imageModal) {
|
||||
imageModal.style.display = 'none';
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
async function handleFiles(files, iddatadb) {
|
||||
for (const file of files) {
|
||||
if (!file.type.startsWith('image/')) {
|
||||
alert('Per favore, carica solo immagini!');
|
||||
continue;
|
||||
}
|
||||
|
||||
const formData = new FormData();
|
||||
formData.append('photo', file);
|
||||
formData.append('iddatadb', iddatadb);
|
||||
|
||||
try {
|
||||
const response = await fetch('upload_photo.php', {
|
||||
method: 'POST',
|
||||
body: formData
|
||||
});
|
||||
const result = await response.json();
|
||||
|
||||
if (result.success) {
|
||||
// Ricarica il contenuto del popup
|
||||
loadPopupContent(iddatadb);
|
||||
} else {
|
||||
alert('Errore durante il caricamento: ' + result.message);
|
||||
}
|
||||
} catch (error) {
|
||||
alert('Errore durante il caricamento: ' + error.message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Gestione del popup per le foto
|
||||
const photosButtons = document.querySelectorAll('.photos-btn');
|
||||
const photosModal = document.getElementById('photosModal');
|
||||
const closeBtn = document.querySelector('.close-btn');
|
||||
|
||||
photosButtons.forEach(button => {
|
||||
button.addEventListener('click', function() {
|
||||
const iddatadb = this.getAttribute('data-iddatadb');
|
||||
loadPopupContent(iddatadb);
|
||||
photosModal.style.display = 'block';
|
||||
document.querySelector('.overlay').style.display = 'none'; // Nascondi overlay
|
||||
});
|
||||
});
|
||||
|
||||
if (closeBtn) {
|
||||
closeBtn.addEventListener('click', function() {
|
||||
photosModal.style.display = 'none';
|
||||
document.querySelector('.overlay').style.display = 'none'; // Assicurati che l'overlay sia nascosto
|
||||
// Forza la riattivazione della pagina sottostante
|
||||
document.body.style.pointerEvents = 'auto';
|
||||
});
|
||||
}
|
||||
|
||||
if (photosModal) {
|
||||
window.addEventListener('click', function(event) {
|
||||
if (event.target === photosModal) {
|
||||
photosModal.style.display = 'none';
|
||||
document.querySelector('.overlay').style.display = 'none'; // Nascondi overlay
|
||||
document.body.style.pointerEvents = 'auto'; // Riattiva la pagina
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Gestione del popup per le parti
|
||||
const partsButtons = document.querySelectorAll('.parts-btn');
|
||||
const partsModal = document.getElementById('partsModal');
|
||||
|
||||
partsButtons.forEach(button => {
|
||||
button.addEventListener('click', function() {
|
||||
const iddatadb = this.getAttribute('data-iddatadb');
|
||||
// Carica il contenuto del modal Parts (da parts.js o altro)
|
||||
if (partsModal) {
|
||||
partsModal.style.display = 'block';
|
||||
document.querySelector('.overlay').style.display = 'none'; // Nascondi overlay
|
||||
// Assicurati che parts.js gestisca il contenuto specifico
|
||||
} else {
|
||||
console.error('Modal Parts non trovato');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Gestione della chiusura del modal Parts
|
||||
const partsCloseBtn = document.querySelector('#partsModal .close-btn');
|
||||
if (partsCloseBtn) {
|
||||
partsCloseBtn.addEventListener('click', function() {
|
||||
partsModal.style.display = 'none';
|
||||
document.querySelector('.overlay').style.display = 'none'; // Nascondi overlay
|
||||
document.body.style.pointerEvents = 'auto'; // Riattiva la pagina
|
||||
});
|
||||
}
|
||||
|
||||
if (partsModal) {
|
||||
window.addEventListener('click', function(event) {
|
||||
if (event.target === partsModal) {
|
||||
partsModal.style.display = 'none';
|
||||
document.querySelector('.overlay').style.display = 'none'; // Nascondi overlay
|
||||
document.body.style.pointerEvents = 'auto'; // Riattiva la pagina
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Gestione del tracking
|
||||
document.querySelectorAll('.go-btn').forEach(button => {
|
||||
button.addEventListener('click', async function() {
|
||||
const rowIndex = this.getAttribute('data-row');
|
||||
const awbInput = document.querySelector(`input[name="rows[${rowIndex}][awb_number]"]`);
|
||||
const carrierSelect = document.querySelector(`select[name="rows[${rowIndex}][carrier]"]`);
|
||||
const trackingResult = document.querySelector(`.tracking-info[data-row="${rowIndex}"] .tracking-result`);
|
||||
const trackingHidden = document.querySelector(`input[name="rows[${rowIndex}][tracking_info]"]`);
|
||||
const trackingNumber = awbInput.value.trim();
|
||||
const carrierCode = carrierSelect.value;
|
||||
|
||||
if (!trackingNumber) {
|
||||
alert('Inserisci un numero AWB valido!');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
trackingResult.textContent = 'Caricamento...';
|
||||
this.disabled = true;
|
||||
button.addEventListener('click', functionтии) {
|
||||
const rowIndex = this.getAttribute('data-row');
|
||||
const row = this.closest('.grid-row');
|
||||
const iddatadb = row.getAttribute('data-id');
|
||||
const formData = new FormData();
|
||||
formData.append('tracking_number', trackingNumber);
|
||||
formData.append('courier_code', carrierCode);
|
||||
const response = await fetch('fetch_tracking_info.php', {
|
||||
method: 'POST',
|
||||
body: formData
|
||||
});
|
||||
const result = await response.json();
|
||||
|
||||
if (!result.success) throw new Error(result.message);
|
||||
const trackingText = `Date: ${result.deliveryDate}, Signed by: ${result.signedBy}, Courier: ${result.carrierName}`;
|
||||
trackingResult.textContent = trackingText;
|
||||
trackingHidden.value = JSON.stringify({
|
||||
deliveryDate: result.deliveryDate,
|
||||
signedBy: result.signedBy,
|
||||
carrierName: result.carrierName
|
||||
const inputs = row.querySelectorAll(`input[name^="rows[${rowIndex}]"], select[name^="rows[${rowIndex}]"]`);
|
||||
inputs.forEach(input => {
|
||||
const name = input.name.replace(`rows[${rowIndex}]`, '').replace(/\[|\]/g, '');
|
||||
if (name !== 'user_name') {
|
||||
formData.append(name, input.value);
|
||||
}
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Errore:', error);
|
||||
trackingResult.textContent = 'Errore: ' + error.message;
|
||||
trackingHidden.value = '';
|
||||
} finally {
|
||||
this.disabled = false;
|
||||
formData.append('iddatadb', iddatadb);
|
||||
|
||||
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);
|
||||
} else {
|
||||
alert('Errore durante il salvataggio: ' + data.message);
|
||||
}
|
||||
})
|
||||
.catch(error => alert('Errore durante il salvataggio: ' + error.message));
|
||||
});
|
||||
});
|
||||
|
||||
// Propagazione del valore dall'input superiore
|
||||
const propagateButtons = document.querySelectorAll('.propagate-btn'); propagateButtons.forEach(button => {
|
||||
button.addEventListener('click', function() {
|
||||
const columnIndex = this.getAttribute('data-column');
|
||||
const input = this.previousElementSibling;
|
||||
const value = input.value;
|
||||
|
||||
const cells = document.querySelectorAll(`.grid-cell[data-index="${columnIndex}"]`);
|
||||
cells.forEach(cell => {
|
||||
const rowInput = cell.querySelector('input, select');
|
||||
if (rowInput) {
|
||||
if (rowInput.type === 'date') {
|
||||
rowInput.value = value;
|
||||
} else if (rowInput.tagName === 'SELECT') {
|
||||
rowInput.value = value;
|
||||
} else {
|
||||
rowInput.value = value;
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
// Ridimensionamento colonne
|
||||
const resizers = document.querySelectorAll('.resizer');
|
||||
let currentResizer = null;
|
||||
let startX = 0;
|
||||
let startWidth = 0;
|
||||
let columnIndex = 0; resizers.forEach(resizer => {
|
||||
resizer.addEventListener('mousedown', function(e) {
|
||||
currentResizer = resizer;
|
||||
const header = resizer.parentElement;
|
||||
columnIndex = header.getAttribute('data-index');
|
||||
startX = e.pageX;
|
||||
startWidth = header.offsetWidth;
|
||||
document.addEventListener('mousemove', resize);
|
||||
document.addEventListener('mouseup', stopResize);
|
||||
});
|
||||
|
||||
function resize(e) {
|
||||
if (currentResizer) {
|
||||
const dx = e.pageX - startX;
|
||||
const newWidth = startWidth + dx;
|
||||
const headers = document.querySelectorAll(`.grid-header[data-index="${columnIndex}"]`);
|
||||
const cells = document.querySelectorAll(`.grid-cell[data-index="${columnIndex}"]`);
|
||||
headers.forEach(header => header.style.flex = `0 0 ${newWidth}px`);
|
||||
cells.forEach(cell => cell.style.flex = `0 0 ${newWidth}px`);
|
||||
}
|
||||
}
|
||||
|
||||
function stopResize() {
|
||||
if (currentResizer) {
|
||||
document.removeEventListener('mousemove', resize);
|
||||
document.removeEventListener('mouseup', stopResize);
|
||||
currentResizer = null;
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
|
||||
|
||||
Binary file not shown.
@ -66,3 +66,4 @@ https://93.43.5.102/limsapi/api/odata/SchemaCustomField
|
||||
https://93.43.5.102/limsapi/api/odata/SchemaCustomField
|
||||
https://93.43.5.102/limsapi/api/odata/SchemaCustomField
|
||||
https://93.43.5.102/limsapi/api/odata/SchemaCustomField
|
||||
https://93.43.5.102/limsapi/api/odata/SchemaCustomField
|
||||
|
||||
572
public/userarea/parts - Copia.js
Normal file
572
public/userarea/parts - Copia.js
Normal file
@ -0,0 +1,572 @@
|
||||
$(document).ready(function () {
|
||||
console.log("parts.js caricato correttamente");
|
||||
|
||||
$(".parts-btn").on("click", function () {
|
||||
console.log("Pulsante Parts cliccato");
|
||||
const iddatadb = $(this).data("iddatadb");
|
||||
const rowIndex = $(this).data("row");
|
||||
const importRef = $("table tbody tr")
|
||||
.eq(rowIndex)
|
||||
.find("td")
|
||||
.eq(1)
|
||||
.text();
|
||||
const description =
|
||||
$("table tbody tr").eq(rowIndex).find("td").eq(2).text() ||
|
||||
"Sconosciuto";
|
||||
|
||||
$("#trfHeader").text(`${iddatadb} - ${importRef} - ${description}`);
|
||||
$("#partsModal").data("iddatadb", iddatadb);
|
||||
|
||||
loadPhoto(iddatadb);
|
||||
loadExistingParts(iddatadb);
|
||||
|
||||
$("#partsModal").modal("show");
|
||||
});
|
||||
|
||||
function loadPhoto(iddatadb) {
|
||||
$.ajax({
|
||||
url: "load_photo.php",
|
||||
method: "GET",
|
||||
data: { iddatadb: iddatadb },
|
||||
success: function (response) {
|
||||
if (response.success && response.file_path) {
|
||||
const img = $("#samplePhoto");
|
||||
img.attr("src", response.file_path);
|
||||
img.on("load", function () {
|
||||
const container = img.parent();
|
||||
const canvas = document.getElementById("photoCanvas");
|
||||
const containerWidth = container.width();
|
||||
const containerHeight = container.height();
|
||||
const scaleX = containerWidth / img[0].naturalWidth;
|
||||
const scaleY = containerHeight / img[0].naturalHeight;
|
||||
const scale = Math.min(scaleX, scaleY);
|
||||
canvas.width = img[0].naturalWidth * scale;
|
||||
canvas.height = img[0].naturalHeight * scale;
|
||||
canvas.style.width = `${containerWidth}px`;
|
||||
canvas.style.height = `${containerHeight}px`;
|
||||
const ctx = canvas.getContext("2d");
|
||||
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
||||
ctx.drawImage(
|
||||
img.get(0),
|
||||
0,
|
||||
0,
|
||||
canvas.width,
|
||||
canvas.height,
|
||||
);
|
||||
updateMarkers();
|
||||
});
|
||||
} else {
|
||||
$("#samplePhoto").attr("src", "");
|
||||
alert("Nessuna foto trovata per questo TRF.");
|
||||
}
|
||||
},
|
||||
error: function (xhr, status, error) {
|
||||
alert("Errore nel caricamento della foto: " + error);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
function addNewRow(nextPartNumber) {
|
||||
const newRow = `
|
||||
<tr data-part-id="new">
|
||||
<td><input type="number" class="form-control form-control-sm part-number" value="${nextPartNumber || 1}" style="width: 80px;"></td>
|
||||
<td><input type="text" class="form-control form-control-sm part-description" placeholder="Inserisci descrizione" style="width: 100%;"></td>
|
||||
<td>
|
||||
<button type="button" class="btn btn-success btn-sm add-row" style="padding: 0.1rem 0.3rem; font-size: 0.8rem;"><i class="fas fa-plus fa-xs"></i></button>
|
||||
<button type="button" class="btn btn-danger btn-sm remove-row" style="padding: 0.1rem 0.3rem; font-size: 0.8rem; display: none;"><i class="fas fa-trash fa-xs"></i></button>
|
||||
<span class="save-status text-success" style="display: none; margin-left: 5px;"><i class="fas fa-check fa-xs"></i></span>
|
||||
<span class="save-loading text-warning" style="display: none; margin-left: 5px;"><i class="fas fa-spinner fa-spin fa-xs"></i></span>
|
||||
</td>
|
||||
</tr>
|
||||
`;
|
||||
$("#partsTableBody").append(newRow);
|
||||
updateRowButtons();
|
||||
}
|
||||
|
||||
function updateRowButtons() {
|
||||
const rowCount = $("#partsTableBody tr").length;
|
||||
$("#partsTableBody tr").each(function (index) {
|
||||
const $removeBtn = $(this).find(".remove-row");
|
||||
if (rowCount > 1) {
|
||||
$removeBtn.show();
|
||||
} else {
|
||||
$removeBtn.hide();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
$(document).on("click", ".add-row", function (e) {
|
||||
e.preventDefault();
|
||||
console.log("Pulsante Aggiungi riga cliccato");
|
||||
const maxPartNumber = Math.max(
|
||||
...$("#partsTableBody tr")
|
||||
.map(function () {
|
||||
return parseInt($(this).find(".part-number").val()) || 0;
|
||||
})
|
||||
.get(),
|
||||
);
|
||||
addNewRow(maxPartNumber + 1);
|
||||
updatePartsList();
|
||||
});
|
||||
|
||||
$(document).on("click", ".remove-row", function (e) {
|
||||
e.preventDefault();
|
||||
console.log("Pulsante Rimuovi riga cliccato");
|
||||
const $row = $(this).closest("tr");
|
||||
const partId = $row.data("part-id");
|
||||
console.log("ID parte da eliminare:", partId);
|
||||
|
||||
if (partId !== "new" && partId !== undefined && partId !== null) {
|
||||
console.log("Procedo con la cancellazione dal database");
|
||||
$.ajax({
|
||||
url: "delete_part.php",
|
||||
method: "POST",
|
||||
data: JSON.stringify({ part_id: partId }),
|
||||
contentType: "application/json",
|
||||
beforeSend: function () {
|
||||
console.log(
|
||||
"Invio richiesta AJAX a delete_part.php con part_id:",
|
||||
partId,
|
||||
);
|
||||
},
|
||||
success: function (response) {
|
||||
console.log("Risposta da delete_part.php:", response);
|
||||
if (response.success) {
|
||||
$row.remove();
|
||||
updateRowButtons();
|
||||
updatePartsList();
|
||||
clearCanvasMarkers();
|
||||
} else {
|
||||
alert("Errore nell'eliminazione: " + response.message);
|
||||
}
|
||||
},
|
||||
error: function (xhr, status, error) {
|
||||
console.log("Errore AJAX:", status, error);
|
||||
alert(
|
||||
"Errore nell'eliminazione: " +
|
||||
error +
|
||||
". Stato: " +
|
||||
xhr.status +
|
||||
" - " +
|
||||
xhr.responseText,
|
||||
);
|
||||
},
|
||||
});
|
||||
} else {
|
||||
console.log(
|
||||
'Riga non salvata nel database (partId = "new" o non definito), rimuovo solo visivamente',
|
||||
);
|
||||
$row.remove();
|
||||
updateRowButtons();
|
||||
updatePartsList();
|
||||
}
|
||||
});
|
||||
|
||||
$(document).on("blur", ".part-description, .part-number", function () {
|
||||
const $input = $(this);
|
||||
const $row = $input.closest("tr");
|
||||
const partNumber = $row.find(".part-number").val();
|
||||
const partDescription = $row.find(".part-description").val().trim();
|
||||
const $saveStatus = $row.find(".save-status");
|
||||
const $saveLoading = $row.find(".save-loading");
|
||||
const iddatadb = $("#partsModal").data("iddatadb");
|
||||
|
||||
console.log("Evento blur su input:", { partNumber, partDescription });
|
||||
|
||||
if (partDescription && iddatadb) {
|
||||
$saveLoading.show();
|
||||
$saveStatus.hide();
|
||||
|
||||
$.ajax({
|
||||
url: "save_parts.php",
|
||||
method: "POST",
|
||||
data: JSON.stringify({
|
||||
iddatadb: iddatadb,
|
||||
parts: [
|
||||
{
|
||||
part_number: partNumber,
|
||||
part_description: partDescription,
|
||||
},
|
||||
],
|
||||
}),
|
||||
contentType: "application/json",
|
||||
success: function (response) {
|
||||
if (response.success) {
|
||||
if (response.part_id) {
|
||||
$row.data("part-id", response.part_id);
|
||||
console.log(
|
||||
"Aggiornato partId della riga:",
|
||||
response.part_id,
|
||||
);
|
||||
}
|
||||
$saveLoading.hide();
|
||||
$saveStatus.show();
|
||||
updatePartsList();
|
||||
setTimeout(() => $saveStatus.hide(), 2000);
|
||||
} else {
|
||||
alert("Errore nel salvataggio: " + response.message);
|
||||
$saveLoading.hide();
|
||||
}
|
||||
},
|
||||
error: function (xhr, status, error) {
|
||||
alert("Errore nel salvataggio delle parti: " + error);
|
||||
$saveLoading.hide();
|
||||
},
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
function loadExistingParts(iddatadb) {
|
||||
$.ajax({
|
||||
url: "load_parts.php",
|
||||
method: "GET",
|
||||
data: { iddatadb: iddatadb },
|
||||
success: function (response) {
|
||||
if (response.success) {
|
||||
$("#partsTableBody").empty();
|
||||
if (response.parts.length > 0) {
|
||||
response.parts.forEach((part) => {
|
||||
const newRow = `
|
||||
<tr data-part-id="${part.id}">
|
||||
<td><input type="number" class="form-control form-control-sm part-number" value="${part.part_number}" style="width: 80px;"></td>
|
||||
<td><input type="text" class="form-control form-control-sm part-description" value="${part.part_description}" style="width: 100%;"></td>
|
||||
<td>
|
||||
<button type="button" class="btn btn-success btn-sm add-row" style="padding: 0.1rem 0.3rem; font-size: 0.8rem;"><i class="fas fa-plus fa-xs"></i></button>
|
||||
<button type="button" class="btn btn-danger btn-sm remove-row" style="padding: 0.1rem 0.3rem; font-size: 0.8rem;"><i class="fas fa-trash fa-xs"></i></button>
|
||||
<span class="save-status text-success" style="display: none; margin-left: 5px;"><i class="fas fa-check fa-xs"></i></span>
|
||||
<span class="save-loading text-warning" style="display: none; margin-left: 5px;"><i class="fas fa-spinner fa-spin fa-xs"></i></span>
|
||||
</td>
|
||||
</tr>
|
||||
`;
|
||||
$("#partsTableBody").append(newRow);
|
||||
});
|
||||
} else {
|
||||
addNewRow(1);
|
||||
}
|
||||
updateRowButtons();
|
||||
updatePartsList();
|
||||
} else {
|
||||
alert(
|
||||
"Errore nel caricamento delle parti: " +
|
||||
response.message,
|
||||
);
|
||||
addNewRow(1);
|
||||
}
|
||||
},
|
||||
error: function (xhr, status, error) {
|
||||
alert("Errore nel caricamento delle parti: " + error);
|
||||
addNewRow(1);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
function updatePartsList() {
|
||||
$("#partsList").empty();
|
||||
$("#partsTableBody tr").each(function () {
|
||||
const partNumber = $(this).find(".part-number").val();
|
||||
const partDescription = $(this).find(".part-description").val();
|
||||
if (partNumber && partDescription) {
|
||||
const listItem = `<li class="list-group-item" data-part-number="${partNumber}">${partNumber} - ${partDescription}</li>`;
|
||||
$("#partsList").append(listItem);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
let selectedPartNumber = null;
|
||||
let markers = [];
|
||||
let descriptionPosition = { x: 10, y: 10 };
|
||||
let hasDescriptions = false;
|
||||
|
||||
$("#partsList").on("click", "li", function () {
|
||||
selectedPartNumber = $(this).data("part-number");
|
||||
console.log("Part number selezionato:", selectedPartNumber);
|
||||
$(this).addClass("active").siblings().removeClass("active");
|
||||
});
|
||||
|
||||
const canvas = document.getElementById("photoCanvas");
|
||||
const ctx = canvas.getContext("2d");
|
||||
|
||||
$("#markerContainer").on("click", function (e) {
|
||||
console.log("Click sul markerContainer rilevato"); // Debug
|
||||
if (selectedPartNumber !== null) {
|
||||
const img = $("#samplePhoto");
|
||||
const canvas = document.getElementById("photoCanvas");
|
||||
const rect = canvas.getBoundingClientRect();
|
||||
const container = img.parent();
|
||||
const containerWidth = container.width();
|
||||
const containerHeight = container.height();
|
||||
const scaleX = containerWidth / img.get(0).naturalWidth;
|
||||
const scaleY = containerHeight / img.get(0).naturalHeight;
|
||||
const scale = Math.min(scaleX, scaleY);
|
||||
const x = (e.clientX - rect.left) / scale;
|
||||
const y = (e.clientY - rect.top) / scale;
|
||||
|
||||
console.log("Coordinate cliccate (x, y):", x, y); // Debug
|
||||
|
||||
const existingMarker = markers.find(
|
||||
(m) => m.partNumber == selectedPartNumber,
|
||||
);
|
||||
if (existingMarker) {
|
||||
existingMarker.x = x;
|
||||
existingMarker.y = y;
|
||||
} else {
|
||||
markers.push({ partNumber: selectedPartNumber, x, y });
|
||||
}
|
||||
console.log("Markers aggiornati:", markers); // Debug
|
||||
updateMarkers();
|
||||
if (hasDescriptions) {
|
||||
drawDescriptions(descriptionPosition.x, descriptionPosition.y);
|
||||
}
|
||||
selectedPartNumber = null;
|
||||
$("#partsList li").removeClass("active");
|
||||
} else {
|
||||
console.log("Nessun part number selezionato"); // Debug
|
||||
}
|
||||
});
|
||||
function updateMarkers() {
|
||||
const img = $("#samplePhoto");
|
||||
const container = img.parent();
|
||||
const containerWidth = container.width();
|
||||
const containerHeight = container.height();
|
||||
const scaleX = containerWidth / img.get(0).naturalWidth;
|
||||
const scaleY = containerHeight / img.get(0).naturalHeight;
|
||||
const scale = Math.min(scaleX, scaleY);
|
||||
|
||||
const markerContainer = $("#markerContainer");
|
||||
markerContainer.empty();
|
||||
|
||||
markers.forEach((marker) => {
|
||||
const scaledX = marker.x * scale;
|
||||
const scaledY = marker.y * scale;
|
||||
console.log(
|
||||
"Aggiungo marker:",
|
||||
marker.partNumber,
|
||||
"a posizione (scaledX, scaledY):",
|
||||
scaledX,
|
||||
scaledY,
|
||||
); // Debug
|
||||
const $marker = $(
|
||||
`<div class="draggable-marker">${marker.partNumber}</div>`,
|
||||
).css({
|
||||
left: scaledX - 8 + "px",
|
||||
top: scaledY - 8 + "px",
|
||||
});
|
||||
markerContainer.append($marker);
|
||||
makeDraggable($marker, marker, scale);
|
||||
});
|
||||
}
|
||||
|
||||
function makeDraggable($element, item, scale) {
|
||||
let isDragging = false;
|
||||
let currentX = parseFloat($element.css("left")) || 0;
|
||||
let currentY = parseFloat($element.css("top")) || 0;
|
||||
let initialX, initialY;
|
||||
|
||||
$element.on("mousedown", function (e) {
|
||||
e.preventDefault();
|
||||
isDragging = true;
|
||||
initialX = e.clientX - currentX;
|
||||
initialY = e.clientY - currentY;
|
||||
$element.css("z-index", 1001);
|
||||
});
|
||||
|
||||
$(document).on("mousemove", function (e) {
|
||||
if (isDragging) {
|
||||
e.preventDefault();
|
||||
currentX = e.clientX - initialX;
|
||||
currentY = e.clientY - initialY;
|
||||
const container = $("#photoCanvas").parent();
|
||||
const containerWidth = container.width();
|
||||
const containerHeight = container.height();
|
||||
const maxX = containerWidth - $element.width();
|
||||
const maxY = containerHeight - $element.height();
|
||||
|
||||
currentX = Math.max(0, Math.min(currentX, maxX));
|
||||
currentY = Math.max(0, Math.min(currentY, maxY));
|
||||
|
||||
$element.css({
|
||||
left: currentX + "px",
|
||||
top: currentY + "px",
|
||||
});
|
||||
|
||||
if (item.partNumber) {
|
||||
// È un marker
|
||||
item.x = (currentX + 8) / scale;
|
||||
item.y = (currentY + 8) / scale;
|
||||
} else {
|
||||
// È la lista
|
||||
descriptionPosition.x = (currentX + 5) / scale;
|
||||
descriptionPosition.y = (currentY + 5) / scale;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
$(document).on("mouseup", function () {
|
||||
isDragging = false;
|
||||
$element.css("z-index", 1000);
|
||||
});
|
||||
}
|
||||
|
||||
function drawDescriptions(x, y) {
|
||||
const img = $("#samplePhoto");
|
||||
const container = img.parent();
|
||||
const containerWidth = container.width();
|
||||
const containerHeight = container.height();
|
||||
const scaleX = containerWidth / img.get(0).naturalWidth;
|
||||
const scaleY = containerHeight / img.get(0).naturalHeight;
|
||||
const scale = Math.min(scaleX, scaleY);
|
||||
|
||||
const partsList = [];
|
||||
$("#partsTableBody tr").each(function () {
|
||||
const partNumber = $(this).find(".part-number").val();
|
||||
const partDescription = $(this).find(".part-description").val();
|
||||
if (partNumber && partDescription) {
|
||||
partsList.push(`${partNumber} ${partDescription}`);
|
||||
}
|
||||
});
|
||||
|
||||
const descriptionList = $("#descriptionList");
|
||||
descriptionList.empty();
|
||||
descriptionList.css({
|
||||
display: "block",
|
||||
top: y * scale + "px",
|
||||
left: x * scale + "px",
|
||||
width: "200px",
|
||||
});
|
||||
partsList.forEach((part) => {
|
||||
descriptionList.append(`<div>${part}</div>`);
|
||||
});
|
||||
|
||||
updateMarkers();
|
||||
}
|
||||
|
||||
function clearCanvasMarkers() {
|
||||
markers = [];
|
||||
hasDescriptions = false;
|
||||
$("#descriptionList").css("display", "none");
|
||||
$("#markerContainer").empty();
|
||||
const canvas = document.getElementById("photoCanvas");
|
||||
const img = $("#samplePhoto");
|
||||
const ctx = canvas.getContext("2d");
|
||||
const container = img.parent();
|
||||
const containerWidth = container.width();
|
||||
const containerHeight = container.height();
|
||||
const scaleX = containerWidth / img.get(0).naturalWidth;
|
||||
const scaleY = containerHeight / img.get(0).naturalHeight;
|
||||
const scale = Math.min(scaleX, scaleY);
|
||||
|
||||
canvas.width = img.get(0).naturalWidth * scale;
|
||||
canvas.height = img.get(0).naturalHeight * scale;
|
||||
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
||||
ctx.drawImage(img.get(0), 0, 0, canvas.width, canvas.height);
|
||||
}
|
||||
|
||||
$("#addDescriptionsBtn").on("click", function () {
|
||||
hasDescriptions = true;
|
||||
descriptionPosition = { x: 10, y: 10 };
|
||||
drawDescriptions(descriptionPosition.x, descriptionPosition.y);
|
||||
makeDraggable(
|
||||
$("#descriptionList"),
|
||||
descriptionPosition,
|
||||
Math.min(
|
||||
$("#photoCanvas").parent().width() /
|
||||
$("#samplePhoto").get(0).naturalWidth,
|
||||
$("#photoCanvas").parent().height() /
|
||||
$("#samplePhoto").get(0).naturalHeight,
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
$("#removeAnnotationsBtn").on("click", function () {
|
||||
clearCanvasMarkers();
|
||||
});
|
||||
|
||||
$("#savePhotoBtn").on("click", function () {
|
||||
const canvas = document.getElementById("photoCanvas");
|
||||
const img = $("#samplePhoto");
|
||||
const ctx = canvas.getContext("2d");
|
||||
|
||||
canvas.width = img.get(0).naturalWidth;
|
||||
canvas.height = img.get(0).naturalHeight;
|
||||
ctx.drawImage(img.get(0), 0, 0);
|
||||
|
||||
const partsList = [];
|
||||
$("#partsTableBody tr").each(function () {
|
||||
const partNumber = $(this).find(".part-number").val();
|
||||
const partDescription = $(this).find(".part-description").val();
|
||||
if (partNumber && partDescription) {
|
||||
partsList.push(`${partNumber} ${partDescription}`);
|
||||
}
|
||||
});
|
||||
|
||||
if (hasDescriptions) {
|
||||
ctx.fillStyle = "rgba(255, 255, 255, 0.8)";
|
||||
ctx.fillRect(
|
||||
descriptionPosition.x,
|
||||
descriptionPosition.y,
|
||||
200,
|
||||
partsList.length * 12 + 10,
|
||||
);
|
||||
ctx.fillStyle = "#000000";
|
||||
ctx.font = "10px Arial";
|
||||
partsList.forEach((part, index) => {
|
||||
ctx.fillText(
|
||||
part,
|
||||
descriptionPosition.x + 5,
|
||||
descriptionPosition.y + 12 + index * 12,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
markers.forEach((marker) => {
|
||||
ctx.beginPath();
|
||||
ctx.arc(marker.x, marker.y, 8, 0, 2 * Math.PI);
|
||||
ctx.fillStyle = "rgba(255, 0, 0, 0.5)";
|
||||
ctx.fill();
|
||||
ctx.strokeStyle = "#ff0000";
|
||||
ctx.lineWidth = 1;
|
||||
ctx.stroke();
|
||||
ctx.fillStyle = "#ffffff";
|
||||
ctx.font = "bold 8px Arial";
|
||||
ctx.textAlign = "center";
|
||||
ctx.textBaseline = "middle";
|
||||
ctx.fillText(marker.partNumber, marker.x, marker.y);
|
||||
});
|
||||
|
||||
const dataURL = canvas.toDataURL("image/png");
|
||||
const timestamp = new Date().toISOString().replace(/[:.]/g, "-");
|
||||
const defaultName = `photo_${$("#partsModal").data("iddatadb")}_${timestamp}.png`;
|
||||
const newName = prompt(
|
||||
"Inserisci il nome del file (senza estensione):",
|
||||
defaultName.split(".png")[0],
|
||||
);
|
||||
if (newName) {
|
||||
const finalName = newName + "_" + timestamp + ".png";
|
||||
$.ajax({
|
||||
url: "save_annotated_photo.php",
|
||||
method: "POST",
|
||||
data: { dataURL: dataURL, filename: finalName },
|
||||
success: function (response) {
|
||||
if (response.success) {
|
||||
alert(
|
||||
"Foto salvata con successo: " + response.file_path,
|
||||
);
|
||||
} else {
|
||||
alert("Errore nel salvataggio: " + response.message);
|
||||
}
|
||||
},
|
||||
error: function (xhr, status, error) {
|
||||
alert("Errore nel salvataggio della foto: " + error);
|
||||
},
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
$(document).on("mouseenter", "tr", function () {
|
||||
console.log("Mouse entrato su riga");
|
||||
});
|
||||
|
||||
$(document).on("mouseleave", "tr", function () {
|
||||
console.log("Mouse uscito da riga");
|
||||
});
|
||||
});
|
||||
@ -1,28 +1,60 @@
|
||||
$(document).ready(function () {
|
||||
console.log("parts.js caricato correttamente");
|
||||
|
||||
$(".parts-btn").on("click", function () {
|
||||
console.log("Pulsante Parts cliccato");
|
||||
const iddatadb = $(this).data("iddatadb");
|
||||
const rowIndex = $(this).data("row");
|
||||
const importRef = $("table tbody tr")
|
||||
.eq(rowIndex)
|
||||
.find("td")
|
||||
.eq(1)
|
||||
.text();
|
||||
const description =
|
||||
$("table tbody tr").eq(rowIndex).find("td").eq(2).text() ||
|
||||
"Sconosciuto";
|
||||
// Gestione del popup per le parti
|
||||
const partsButtons = document.querySelectorAll(".parts-btn");
|
||||
const partsModal = document.getElementById("partsModal");
|
||||
const closeBtn = document.querySelector("#partsModal .close-btn");
|
||||
const overlay = document.querySelector(".overlay");
|
||||
|
||||
$("#trfHeader").text(`${iddatadb} - ${importRef} - ${description}`);
|
||||
$("#partsModal").data("iddatadb", iddatadb);
|
||||
partsButtons.forEach((button) => {
|
||||
button.addEventListener("click", function () {
|
||||
console.log("Pulsante Parts cliccato");
|
||||
const iddatadb = $(this).data("iddatadb");
|
||||
const rowIndex = $(this).data("row");
|
||||
const importRef = $("table tbody tr")
|
||||
.eq(rowIndex)
|
||||
.find("td")
|
||||
.eq(1)
|
||||
.text();
|
||||
const description =
|
||||
$("table tbody tr").eq(rowIndex).find("td").eq(2).text() ||
|
||||
"Sconosciuto";
|
||||
|
||||
loadPhoto(iddatadb);
|
||||
loadExistingParts(iddatadb);
|
||||
$("#trfHeader").text(`${iddatadb} - ${importRef} - ${description}`);
|
||||
$("#partsModal").data("iddatadb", iddatadb);
|
||||
|
||||
$("#partsModal").modal("show");
|
||||
loadPhoto(iddatadb);
|
||||
loadExistingParts(iddatadb);
|
||||
|
||||
if (partsModal) {
|
||||
partsModal.style.display = "block";
|
||||
overlay.style.display = "none"; // Nascondi overlay
|
||||
} else {
|
||||
console.error("Modal Parts non trovato");
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Gestione della chiusura del modal Parts
|
||||
if (closeBtn) {
|
||||
closeBtn.addEventListener("click", function () {
|
||||
partsModal.style.display = "none";
|
||||
overlay.style.display = "none"; // Nascondi overlay
|
||||
document.body.style.pointerEvents = "auto"; // Riattiva la pagina
|
||||
});
|
||||
}
|
||||
|
||||
if (partsModal) {
|
||||
window.addEventListener("click", function (event) {
|
||||
if (event.target === partsModal) {
|
||||
partsModal.style.display = "none";
|
||||
overlay.style.display = "none"; // Nascondi overlay
|
||||
document.body.style.pointerEvents = "auto"; // Riattiva la pagina
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function loadPhoto(iddatadb) {
|
||||
$.ajax({
|
||||
url: "load_photo.php",
|
||||
@ -287,11 +319,11 @@ $(document).ready(function () {
|
||||
const ctx = canvas.getContext("2d");
|
||||
|
||||
$("#markerContainer").on("click", function (e) {
|
||||
console.log("Click sul markerContainer rilevato"); // Debug
|
||||
console.log("Click sul markerContainer rilevato");
|
||||
if (selectedPartNumber !== null) {
|
||||
const img = $("#samplePhoto");
|
||||
const canvas = document.getElementById("photoCanvas");
|
||||
const rect = canvas.getBoundingClientRect();
|
||||
const rect = canvas.getBoundingRect();
|
||||
const container = img.parent();
|
||||
const containerWidth = container.width();
|
||||
const containerHeight = container.height();
|
||||
@ -301,7 +333,7 @@ $(document).ready(function () {
|
||||
const x = (e.clientX - rect.left) / scale;
|
||||
const y = (e.clientY - rect.top) / scale;
|
||||
|
||||
console.log("Coordinate cliccate (x, y):", x, y); // Debug
|
||||
console.log("Coordinate cliccate (x, y):", x, y);
|
||||
|
||||
const existingMarker = markers.find(
|
||||
(m) => m.partNumber == selectedPartNumber,
|
||||
@ -312,7 +344,7 @@ $(document).ready(function () {
|
||||
} else {
|
||||
markers.push({ partNumber: selectedPartNumber, x, y });
|
||||
}
|
||||
console.log("Markers aggiornati:", markers); // Debug
|
||||
console.log("Markers aggiornati:", markers);
|
||||
updateMarkers();
|
||||
if (hasDescriptions) {
|
||||
drawDescriptions(descriptionPosition.x, descriptionPosition.y);
|
||||
@ -320,9 +352,10 @@ $(document).ready(function () {
|
||||
selectedPartNumber = null;
|
||||
$("#partsList li").removeClass("active");
|
||||
} else {
|
||||
console.log("Nessun part number selezionato"); // Debug
|
||||
console.log("Nessun part number selezionato");
|
||||
}
|
||||
});
|
||||
|
||||
function updateMarkers() {
|
||||
const img = $("#samplePhoto");
|
||||
const container = img.parent();
|
||||
@ -344,7 +377,7 @@ $(document).ready(function () {
|
||||
"a posizione (scaledX, scaledY):",
|
||||
scaledX,
|
||||
scaledY,
|
||||
); // Debug
|
||||
);
|
||||
const $marker = $(
|
||||
`<div class="draggable-marker">${marker.partNumber}</div>`,
|
||||
).css({
|
||||
@ -390,11 +423,9 @@ $(document).ready(function () {
|
||||
});
|
||||
|
||||
if (item.partNumber) {
|
||||
// È un marker
|
||||
item.x = (currentX + 8) / scale;
|
||||
item.y = (currentY + 8) / scale;
|
||||
} else {
|
||||
// È la lista
|
||||
descriptionPosition.x = (currentX + 5) / scale;
|
||||
descriptionPosition.y = (currentY + 5) / scale;
|
||||
}
|
||||
|
||||
5
public/userarea/parts_functions.php
Normal file
5
public/userarea/parts_functions.php
Normal file
@ -0,0 +1,5 @@
|
||||
<?php
|
||||
// Include il modal delle parti (già esistente)
|
||||
include 'modal_parts.php';
|
||||
?>
|
||||
<script src="parts.js"></script>
|
||||
184
public/userarea/photos.js
Normal file
184
public/userarea/photos.js
Normal file
@ -0,0 +1,184 @@
|
||||
document.addEventListener("DOMContentLoaded", function() {
|
||||
// Gestione del popup per le foto
|
||||
async function loadPopupContent(iddatadb) {
|
||||
const popupContent = document.getElementById('popupContent');
|
||||
try {
|
||||
const response = await fetch(`photos_popup.php?iddatadb=${iddatadb}`);
|
||||
popupContent.innerHTML = await response.text();
|
||||
|
||||
// Dopo aver caricato il contenuto, associa gli event listener
|
||||
attachPhotoEventListeners(iddatadb);
|
||||
} catch (error) {
|
||||
popupContent.innerHTML = `<p>Errore durante il caricamento: ${error.message}</p>`;
|
||||
}
|
||||
}
|
||||
|
||||
function attachPhotoEventListeners(iddatadb) {
|
||||
const dropArea = document.getElementById('dropArea');
|
||||
const photoInput = document.getElementById('photoInput');
|
||||
|
||||
if (!dropArea || !photoInput) {
|
||||
console.error('Elementi dropArea o photoInput non trovati nel DOM');
|
||||
return;
|
||||
}
|
||||
|
||||
console.log('Associando event listener per drag-and-drop');
|
||||
|
||||
// Gestione drag-and-drop
|
||||
['dragenter', 'dragover', 'dragleave', 'drop'].forEach(eventName => {
|
||||
dropArea.addEventListener(eventName, preventDefaults, false);
|
||||
});
|
||||
|
||||
function preventDefaults(e) {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
}
|
||||
|
||||
['dragenter', 'dragover'].forEach(eventName => {
|
||||
dropArea.addEventListener(eventName, () => {
|
||||
console.log('Drag enter/over');
|
||||
dropArea.classList.add('highlight');
|
||||
}, false);
|
||||
});
|
||||
|
||||
['dragleave', 'drop'].forEach(eventName => {
|
||||
dropArea.addEventListener(eventName, () => {
|
||||
console.log('Drag leave/drop');
|
||||
dropArea.classList.remove('highlight');
|
||||
}, false);
|
||||
});
|
||||
|
||||
dropArea.addEventListener('drop', (e) => {
|
||||
console.log('File droppato');
|
||||
const files = e.dataTransfer.files;
|
||||
handleFiles(files, iddatadb);
|
||||
}, false);
|
||||
|
||||
dropArea.addEventListener('click', () => {
|
||||
console.log('Click su dropArea');
|
||||
photoInput.click();
|
||||
}, false);
|
||||
|
||||
photoInput.addEventListener('change', () => {
|
||||
console.log('File selezionato tramite input');
|
||||
handleFiles(photoInput.files, iddatadb);
|
||||
}, false);
|
||||
|
||||
// Gestione della rimozione delle foto
|
||||
const deleteButtons = document.querySelectorAll('.delete-photo-btn');
|
||||
deleteButtons.forEach(button => {
|
||||
button.addEventListener('click', async function() {
|
||||
const photoId = this.getAttribute('data-photo-id');
|
||||
if (confirm('Sei sicuro di voler eliminare questa foto?')) {
|
||||
try {
|
||||
const response = await fetch('delete_photo.php', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
},
|
||||
body: `photo_id=${photoId}`
|
||||
});
|
||||
const result = await response.json();
|
||||
|
||||
if (result.success) {
|
||||
// Ricarica il contenuto del popup
|
||||
loadPopupContent(iddatadb);
|
||||
} else {
|
||||
alert('Errore durante l\'eliminazione: ' + result.message);
|
||||
}
|
||||
} catch (error) {
|
||||
alert('Errore durante l\'eliminazione: ' + error.message);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Gestione del click sulle immagini per ingrandirle
|
||||
document.querySelectorAll('.thumbnail').forEach(img => {
|
||||
img.addEventListener('click', function() {
|
||||
const modal = document.getElementById('imageModal');
|
||||
const enlargedImage = document.getElementById('enlargedImage');
|
||||
enlargedImage.src = this.src;
|
||||
modal.style.display = 'block';
|
||||
});
|
||||
});
|
||||
|
||||
// Gestione della chiusura del modal immagine
|
||||
const imageModal = document.getElementById('imageModal');
|
||||
const imageCloseBtn = document.querySelector('.image-modal-close');
|
||||
if (imageCloseBtn) {
|
||||
imageCloseBtn.addEventListener('click', function() {
|
||||
imageModal.style.display = 'none';
|
||||
});
|
||||
}
|
||||
if (imageModal) {
|
||||
imageModal.addEventListener('click', function(event) {
|
||||
if (event.target === imageModal) {
|
||||
imageModal.style.display = 'none';
|
||||
}
|
||||
});
|
||||
_
|
||||
|
||||
async function handleFiles(files, iddatadb) {
|
||||
for (const file of files) {
|
||||
if (!file.type.startsWith('image/')) {
|
||||
alert('Per favore, carica solo immagini!');
|
||||
continue;
|
||||
}
|
||||
|
||||
const formData = new FormData();
|
||||
formData.append('photo', file);
|
||||
formData.append('iddatadb', iddatadb);
|
||||
|
||||
try {
|
||||
const response = await fetch('upload_photo.php', {
|
||||
method: 'POST',
|
||||
body: formData
|
||||
});
|
||||
const result = await response.json();
|
||||
|
||||
if (result.success) {
|
||||
// Ricarica il contenuto del popup
|
||||
loadPopupContent(iddatadb);
|
||||
} else {
|
||||
alert('Errore durante il caricamento: ' + result.message);
|
||||
}
|
||||
} catch (error) {
|
||||
alert('Errore durante il caricamento: ' + error.message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Gestione del popup per le foto
|
||||
const photosButtons = document.querySelectorAll('.photos-btn');
|
||||
const photosModal = document.getElementById('photosModal');
|
||||
const closeBtn = document.querySelector('.close-btn');
|
||||
|
||||
photosButtons.forEach(button => {
|
||||
button.addEventListener('click', function() {
|
||||
const iddatadb = this.getAttribute('data-iddatadb');
|
||||
loadPopupContent(iddatadb);
|
||||
photosModal.style.display = 'block';
|
||||
document.querySelector('.overlay').style.display = 'none'; // Nascondi overlay
|
||||
});
|
||||
});
|
||||
|
||||
if (closeBtn) {
|
||||
closeBtn.addEventListener('click', function() {
|
||||
photosModal.style.display = 'none';
|
||||
document.querySelector('.overlay').style.display = 'none'; // Assicurati che l'overlay sia nascosto
|
||||
// Forza la riattivazione della pagina sottostante
|
||||
document.body.style.pointerEvents = 'auto';
|
||||
});
|
||||
}
|
||||
|
||||
if (photosModal) {
|
||||
window.addEventListener('click', function(event) {
|
||||
if (event.target === photosModal) {
|
||||
photosModal.style.display = 'none';
|
||||
document.querySelector('.overlay').style.display = 'none'; // Nascondi overlay
|
||||
document.body.style.pointerEvents = 'auto'; // Riattiva la pagina
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
68
public/userarea/photos_functions.php
Normal file
68
public/userarea/photos_functions.php
Normal file
@ -0,0 +1,68 @@
|
||||
<?php
|
||||
// HTML per il modal delle foto
|
||||
?>
|
||||
<div id="photosModal" class="modal">
|
||||
<div class="modal-content">
|
||||
<span class="close-btn">×</span>
|
||||
<div id="popupContent">
|
||||
<p>Loading...</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div id="imageModal" class="image-modal">
|
||||
<span class="image-modal-close">×</span>
|
||||
<img class="image-modal-content" id="enlargedImage">
|
||||
</div>
|
||||
<style>
|
||||
.photo-item {
|
||||
transition: background-color 0.3s;
|
||||
}
|
||||
|
||||
.photo-item:hover {
|
||||
background-color: #f8f9fa;
|
||||
}
|
||||
|
||||
#dropArea.highlight {
|
||||
border-color: #28a745;
|
||||
background-color: #e9ecef;
|
||||
}
|
||||
|
||||
.image-modal {
|
||||
display: none;
|
||||
position: fixed;
|
||||
z-index: 1100;
|
||||
left: 0;
|
||||
top: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
overflow: auto;
|
||||
background-color: rgba(0, 0, 0, 0.8);
|
||||
}
|
||||
|
||||
.image-modal-content {
|
||||
margin: auto;
|
||||
display: block;
|
||||
max-width: 90%;
|
||||
max-height: 90vh;
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
}
|
||||
|
||||
.image-modal-close {
|
||||
position: absolute;
|
||||
top: 15px;
|
||||
right: 35px;
|
||||
color: #fff;
|
||||
font-size: 40px;
|
||||
font-weight: bold;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.image-modal-close:hover,
|
||||
.image-modal-close:focus {
|
||||
color: #bbb;
|
||||
text-decoration: none;
|
||||
}
|
||||
</style>
|
||||
@ -52,19 +52,9 @@
|
||||
"Descrizione": "Schema per tutti i Tessuti\r\n"
|
||||
},
|
||||
{
|
||||
"IdSchemaCustomFields": 183,
|
||||
"Nome": "TWINSET",
|
||||
"Descrizione": "Schema da usare per Twinset - come da mail di EP del 20\/05\/2025\r\n\r\n"
|
||||
},
|
||||
{
|
||||
"IdSchemaCustomFields": 186,
|
||||
"Nome": "TWINSET",
|
||||
"Descrizione": "Schema per tutti i campioni di qualsiasi matrice escluso cuoio\/pelle\r\n\r\n"
|
||||
},
|
||||
{
|
||||
"IdSchemaCustomFields": 188,
|
||||
"Nome": "LEMAIRE",
|
||||
"Descrizione": "Schema per tutti i campioni in cuoio\/pelle per i quali non \u00e8 specificato un destinatario.\r\n"
|
||||
"IdSchemaCustomFields": 82,
|
||||
"Nome": "MONCLER Brand",
|
||||
"Descrizione": "Da utilizzare solo per il Brand Diretto\r\nGR 19\/03\/2024"
|
||||
}
|
||||
]
|
||||
}
|
||||
55
public/userarea/tracking.js
Normal file
55
public/userarea/tracking.js
Normal file
@ -0,0 +1,55 @@
|
||||
document.addEventListener("DOMContentLoaded", function () {
|
||||
// Gestione del tracking
|
||||
document.querySelectorAll(".go-btn").forEach((button) => {
|
||||
button.addEventListener("click", async function () {
|
||||
const rowIndex = this.getAttribute("data-row");
|
||||
const awbInput = document.querySelector(
|
||||
`input[name="rows[${rowIndex}][awb_number]"]`,
|
||||
);
|
||||
const carrierSelect = document.querySelector(
|
||||
`select[name="rows[${rowIndex}][carrier]"]`,
|
||||
);
|
||||
const trackingResult = document.querySelector(
|
||||
`.tracking-info[data-row="${rowIndex}"] .tracking-result`,
|
||||
);
|
||||
const trackingHidden = document.querySelector(
|
||||
`input[name="rows[${rowIndex}][tracking_info]"]`,
|
||||
);
|
||||
const trackingNumber = awbInput.value.trim();
|
||||
const carrierCode = carrierSelect.value;
|
||||
|
||||
if (!trackingNumber) {
|
||||
alert("Inserisci un numero AWB valido!");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
trackingResult.textContent = "Caricamento...";
|
||||
this.disabled = true;
|
||||
const formData = new FormData();
|
||||
formData.append("tracking_number", trackingNumber);
|
||||
formData.append("courier_code", carrierCode);
|
||||
const response = await fetch("fetch_tracking_info.php", {
|
||||
method: "POST",
|
||||
body: formData,
|
||||
});
|
||||
const result = await response.json();
|
||||
|
||||
if (!result.success) throw new Error(result.message);
|
||||
const trackingText = `Date: ${result.deliveryDate}, Signed by: ${result.signedBy}, Courier: ${result.carrierName}`;
|
||||
trackingResult.textContent = trackingText;
|
||||
trackingHidden.value = JSON.stringify({
|
||||
deliveryDate: result.deliveryDate,
|
||||
signedBy: result.signedBy,
|
||||
carrierName: result.carrierName,
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("Errore:", error);
|
||||
trackingResult.textContent = "Errore: " + error.message;
|
||||
trackingHidden.value = "";
|
||||
} finally {
|
||||
this.disabled = false;
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
0
public/userarea/tracking_functions.php
Normal file
0
public/userarea/tracking_functions.php
Normal file
0
tmp/import_debug.log
Normal file
0
tmp/import_debug.log
Normal file
Loading…
x
Reference in New Issue
Block a user