added tags to document

This commit is contained in:
2025-06-06 17:14:16 +02:00
parent 3e9262d6bf
commit 799a5506ef
5 changed files with 90 additions and 63 deletions
+29 -15
View File
@@ -106,7 +106,6 @@ while ($row = $queryTags->fetch_assoc()) {
</thead>
<tbody>
<?php foreach ($documents as $document) {
// Prepara la query per recuperare i tag associati
$tagStmt = $conn->prepare("SELECT t.tag_id, t.tag_name FROM tags t
JOIN document_tags dt ON t.tag_id = dt.tag_id
WHERE dt.document_id = ?");
@@ -114,10 +113,18 @@ while ($row = $queryTags->fetch_assoc()) {
$tagStmt->execute();
$tagResult = $tagStmt->get_result();
$documentTags = [];
while ($tagRow = $tagResult->fetch_assoc()) {
$documentTags[] = $tagRow['tag_name'];
$documentTagIds = [];
if ($tagResult) {
while ($tagRow = $tagResult->fetch_assoc()) {
$documentTags[] = $tagRow['tag_name'];
$documentTagIds[] = (int)$tagRow['tag_id'];
}
}
$tagStmt->close();
// Debug: Stampa il valore di data-tags
$tagsJson = json_encode($documentTagIds);
echo "<!-- data-tags value for document_id {$document['document_id']}: $tagsJson -->\n";
?>
<tr>
<td><?php echo $document['document_id']; ?></td>
@@ -139,7 +146,7 @@ while ($row = $queryTags->fetch_assoc()) {
data-max-documents="<?php echo htmlspecialchars($document['max_documents']); ?>"
data-is-required="<?php echo $document['is_required']; ?>"
data-notes="<?php echo htmlspecialchars($document['notes']); ?>"
data-tags="<?php echo htmlspecialchars(json_encode(array_column($documentTags, 'tag_id'))); ?>">
data-tags="<?php echo json_encode($documentTagIds); ?>">
<i class="mdi mdi-pencil"></i>
</button>
@@ -340,7 +347,7 @@ while ($row = $queryTags->fetch_assoc()) {
var maxDocuments = button.data('max-documents');
var isRequired = button.data('is-required');
var notes = button.data('notes');
var tags = button.data('tags') ? JSON.parse(button.data('tags')) : [];
var tags = button.data('tags') || [];
console.log("Dati ricevuti dal pulsante:", {
documentId,
@@ -380,17 +387,24 @@ while ($row = $queryTags->fetch_assoc()) {
$.ajax({
url: 'delete-document.php',
type: 'POST',
data: {
document_id: documentId
},
data: { document_id: documentId },
dataType: 'json',
success: function(response) {
Swal.fire(
'Eliminato!',
'Il documento è stato eliminato con successo.',
'success'
).then(() => {
location.reload();
});
if (response.success) {
Swal.fire(
'Eliminato!',
'Il documento è stato eliminato con successo.',
'success'
).then(() => {
location.reload();
});
} else {
Swal.fire(
'Errore!',
response.message || 'Si è verificato un errore durante l\'eliminazione.',
'error'
);
}
},
error: function() {
Swal.fire(