fixed section share
This commit is contained in:
parent
cfd38f3a52
commit
5d64b2ed06
598
public/userportal/documents-home-shared.php
Normal file
598
public/userportal/documents-home-shared.php
Normal file
@ -0,0 +1,598 @@
|
||||
<?php include('include/headscript.php');
|
||||
ini_set('display_errors', 1);
|
||||
ini_set('display_startup_errors', 1);
|
||||
error_reporting(E_ALL);
|
||||
|
||||
// Connessione al database
|
||||
$conn = new mysqli($servername, $username, $password, $database);
|
||||
// Recupera l'id utente loggato
|
||||
$iduserlogin = $_SESSION['iduserlogin'];
|
||||
|
||||
// Recupera l'id della casa dall'URL
|
||||
$idhome = isset($_GET['idhome']) ? intval($_GET['idhome']) : 0;
|
||||
|
||||
// Recupera lo sharing_type e le sezioni condivise per questa casa
|
||||
$querySharing = $conn->prepare("
|
||||
SELECT sharing_type, shared_sections
|
||||
FROM home_sharing
|
||||
WHERE idhome = ? AND idshareduser = ? AND status = 'accepted'
|
||||
");
|
||||
$querySharing->bind_param('ii', $idhome, $iduserlogin);
|
||||
$querySharing->execute();
|
||||
$resultSharing = $querySharing->get_result();
|
||||
$sharingData = $resultSharing->fetch_assoc();
|
||||
|
||||
// Se non ci sono dati, mostra errore o gestisci diversamente
|
||||
if (!$sharingData) {
|
||||
die("Accesso negato o condivisione non trovata.");
|
||||
}
|
||||
|
||||
// Ottieni i dati di condivisione
|
||||
$sharingType = $sharingData['sharing_type'];
|
||||
$sharedSections = json_decode($sharingData['shared_sections'], true); // Decodifica il JSON
|
||||
?>
|
||||
<?php
|
||||
|
||||
|
||||
|
||||
// Recupera i dettagli della casa
|
||||
$queryHome = $conn->prepare("SELECT * FROM home WHERE idhome = ? AND iduser = ?");
|
||||
$queryHome->bind_param('ii', $idhome, $iduserlogin);
|
||||
$queryHome->execute();
|
||||
$resultHome = $queryHome->get_result();
|
||||
$homeData = $resultHome->fetch_assoc();
|
||||
|
||||
if (!isset($_GET['docpage'])) {
|
||||
$docpage = "legal"; // Slug predefinito
|
||||
} else {
|
||||
$docpage = $_GET['docpage']; // Slug passato via GET
|
||||
}
|
||||
|
||||
// Recupera il `page_id` corrispondente allo slug
|
||||
$queryPageId = $conn->prepare("SELECT idpages FROM pages WHERE slug = ?");
|
||||
$queryPageId->bind_param('s', $docpage);
|
||||
$queryPageId->execute();
|
||||
$resultPageId = $queryPageId->get_result();
|
||||
$pageData = $resultPageId->fetch_assoc();
|
||||
|
||||
if ($pageData) {
|
||||
$page_id = $pageData['idpages']; // Page ID trovato
|
||||
} else {
|
||||
die("Errore: Pagina non valida."); // Slug non trovato
|
||||
}
|
||||
|
||||
// Recupera i documenti associati al `page_id`, con le sezioni
|
||||
$queryDocuments = $conn->prepare("
|
||||
SELECT d.*, s.idsections, s.section_name AS section_name
|
||||
FROM documents d
|
||||
LEFT JOIN sections s ON d.idsections = s.idsections
|
||||
WHERE d.page_id = ?
|
||||
ORDER BY s.section_name, d.document_name
|
||||
");
|
||||
$queryDocuments->bind_param('i', $page_id);
|
||||
$queryDocuments->execute();
|
||||
$resultDocuments = $queryDocuments->get_result();
|
||||
|
||||
$documents = [];
|
||||
while ($row = $resultDocuments->fetch_assoc()) {
|
||||
$documents[$row['section_name']][] = $row;
|
||||
}
|
||||
|
||||
// Recupera i documenti già caricati per questa casa
|
||||
$queryLoadedDocuments = $conn->prepare("
|
||||
SELECT ds.*, hs.sharing_type
|
||||
FROM doc_storage ds
|
||||
LEFT JOIN home_sharing hs ON hs.idhome = ds.idhome
|
||||
WHERE ds.idhome = ? AND hs.idshareduser = ? AND hs.status = 'accepted'
|
||||
");
|
||||
$queryLoadedDocuments->bind_param('ii', $idhome, $iduserlogin);
|
||||
$queryLoadedDocuments->execute();
|
||||
$resultLoadedDocuments = $queryLoadedDocuments->get_result();
|
||||
|
||||
$loadedDocuments = [];
|
||||
while ($row = $resultLoadedDocuments->fetch_assoc()) {
|
||||
$loadedDocuments[$row['document_id']][] = $row;
|
||||
}
|
||||
|
||||
// Recupera le pagine disponibili nella tabella 'documents'
|
||||
$queryPages = $conn->query("SELECT * FROM pages ORDER BY namepages");
|
||||
$pages = [];
|
||||
while ($row = $queryPages->fetch_assoc()) {
|
||||
$pages[] = $row;
|
||||
}
|
||||
?>
|
||||
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html lang="it">
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimal-ui">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<title>Documenti della Casa</title>
|
||||
|
||||
<!-- Bootstrap 4 CSS -->
|
||||
<link href="assets/css/bootstrap.min.css" rel="stylesheet" type="text/css">
|
||||
<link href="https://cdn.datatables.net/1.11.5/css/dataTables.bootstrap4.min.css" rel="stylesheet" />
|
||||
<link href="https://cdnjs.cloudflare.com/ajax/libs/dripicons/2.0.0/webfont.min.css" rel="stylesheet">
|
||||
<!-- Font Awesome -->
|
||||
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css" rel="stylesheet" />
|
||||
|
||||
<!-- Custom CSS -->
|
||||
<link href="assets/css/style.css" rel="stylesheet" type="text/css">
|
||||
|
||||
<!-- Dropzone CSS -->
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/dropzone/5.9.2/dropzone.min.css" />
|
||||
<script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.11.7/dist/umd/popper.min.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha3/dist/js/bootstrap.min.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
|
||||
|
||||
<style>
|
||||
/* Personalizza la riga della sezione */
|
||||
.section-header {
|
||||
background-color: #f8f9fa;
|
||||
/* Sfondo chiaro */
|
||||
border: 1px solid #007bff;
|
||||
/* Bordo blu */
|
||||
color: #007bff;
|
||||
/* Testo blu */
|
||||
font-size: 1.2rem;
|
||||
/* Dimensione del font */
|
||||
font-weight: bold;
|
||||
/* Grassetto */
|
||||
padding: 15px 20px;
|
||||
/* Padding */
|
||||
text-align: left;
|
||||
/* Allinea il testo a sinistra */
|
||||
width: 100%;
|
||||
/* A tutta larghezza */
|
||||
}
|
||||
|
||||
.section-header:hover {
|
||||
background-color: #007bff;
|
||||
/* Sfondo blu al passaggio del mouse */
|
||||
color: #fff;
|
||||
/* Testo bianco al passaggio del mouse */
|
||||
}
|
||||
|
||||
.accordion-button {
|
||||
border-radius: 0 !important;
|
||||
/* Rimuove gli angoli arrotondati */
|
||||
box-shadow: none !important;
|
||||
/* Rimuove l'ombra */
|
||||
}
|
||||
|
||||
/* Icona accanto al titolo */
|
||||
.section-header i {
|
||||
font-size: 1.5rem;
|
||||
/* Dimensione dell'icona */
|
||||
margin-right: 10px;
|
||||
/* Spaziatura a destra dell'icona */
|
||||
}
|
||||
|
||||
.section-title {
|
||||
font-size: 1.25rem;
|
||||
font-weight: bold;
|
||||
color: #333;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.document-title {
|
||||
font-size: 1.1rem;
|
||||
font-weight: 500;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.dropzone {
|
||||
background-color: #f0f8ff;
|
||||
border: 2px dashed #007bff;
|
||||
padding: 20px;
|
||||
border-radius: 10px;
|
||||
text-align: center;
|
||||
transition: background-color 0.3s ease;
|
||||
}
|
||||
|
||||
.dropzone:hover {
|
||||
background-color: #e6f5ff;
|
||||
}
|
||||
|
||||
.dropzone .dz-message {
|
||||
font-size: 1.1rem;
|
||||
font-weight: 500;
|
||||
color: #007bff;
|
||||
}
|
||||
|
||||
.dropzone .dz-message i {
|
||||
font-size: 3rem;
|
||||
margin-bottom: 10px;
|
||||
color: #007bff;
|
||||
}
|
||||
|
||||
.document-list-table th,
|
||||
.document-list-table td {
|
||||
text-align: center;
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
.section-separator {
|
||||
border-top: 2px solid #ddd;
|
||||
margin: 40px 0;
|
||||
}
|
||||
|
||||
.btn {
|
||||
margin-right: 5px;
|
||||
}
|
||||
|
||||
.btn.active {
|
||||
background-color: #007bff;
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
/* Stile per l'intestazione della sezione */
|
||||
.accordion-button {
|
||||
background-color: #322999;
|
||||
color: white;
|
||||
font-size: 1.2rem;
|
||||
font-weight: bold;
|
||||
text-align: left;
|
||||
border: 1px solid #007bff;
|
||||
}
|
||||
|
||||
.accordion-button:hover {
|
||||
background-color: #007bff;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.accordion-button i {
|
||||
font-size: 1.5rem;
|
||||
color: #fff562;
|
||||
}
|
||||
|
||||
.accordion-body {
|
||||
padding: 20px;
|
||||
background-color: #f9f9f9;
|
||||
border: 1px solid #ddd;
|
||||
}
|
||||
|
||||
.card-body {
|
||||
margin-bottom: 20px;
|
||||
padding: 15px;
|
||||
background-color: #ffffff;
|
||||
border: 1px solid #ddd;
|
||||
border-radius: 5px;
|
||||
}
|
||||
|
||||
.toggle-dropzone {
|
||||
transition: all 0.3s ease;
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
|
||||
.dropzone-container {
|
||||
padding: 10px;
|
||||
background-color: #f9f9f9;
|
||||
border: 1px dashed #007bff;
|
||||
border-radius: 8px;
|
||||
display: none;
|
||||
/* Nasconde inizialmente l'area */
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body class="fixed-left">
|
||||
<div id="wrapper">
|
||||
<?php include('include/navigationbar.php'); ?>
|
||||
<div class="content-page">
|
||||
<div class="content">
|
||||
<?php include('include/topbar.php'); ?>
|
||||
<br>
|
||||
<div class="page-content-wrapper">
|
||||
<div class="container-fluid">
|
||||
<!-- Dettagli della Casa -->
|
||||
<div class="row">
|
||||
<div class="col-sm-12">
|
||||
<h4 class="page-title">Documenti per la Casa: <?php echo htmlspecialchars($homeData['name']); ?></h4>
|
||||
<p><strong>Indirizzo:</strong> <?php echo htmlspecialchars($homeData['address']) . ', ' . htmlspecialchars($homeData['city']) . ' ' . htmlspecialchars($homeData['zip']); ?></p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row mb-4">
|
||||
<div class="col-12 text-center">
|
||||
<div class="btn-group" role="group" aria-label="Pagine">
|
||||
<?php foreach ($pages as $page) { ?>
|
||||
<button
|
||||
class="btn btn-outline-primary filter-btn <?php echo $docpage === $page['slug'] ? 'active' : ''; ?>"
|
||||
onclick="window.location.href='?docpage=<?php echo htmlspecialchars($page['slug']); ?>&idhome=<?php echo htmlspecialchars($idhome); ?>';">
|
||||
<?php echo ucfirst(htmlspecialchars($page['namepages'])); ?>
|
||||
</button>
|
||||
<?php } ?>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Sezioni per documenti -->
|
||||
<div class="accordion" id="documentSections">
|
||||
<?php
|
||||
// Decodifica le sezioni condivise
|
||||
$sharedSections = json_decode($sharingData['shared_sections'], true); // Decodifica il JSON in un array
|
||||
|
||||
foreach ($documents as $sectionName => $sectionDocuments) {
|
||||
// Ottieni l'id della sezione dalla prima riga di documenti (dato che `idsections` è comune ai documenti di una sezione)
|
||||
$sectionId = $sectionDocuments[0]['idsections'] ?? null;
|
||||
|
||||
// Verifica se la sezione corrente è condivisa
|
||||
if (!in_array($sectionId, $sharedSections)) {
|
||||
continue; // Salta questa sezione
|
||||
}
|
||||
?>
|
||||
<div class="accordion-item">
|
||||
<!-- Header della sezione -->
|
||||
<h2 class="accordion-header" id="heading-<?php echo md5($sectionId); ?>">
|
||||
<button class="accordion-button collapsed section-header full-width" type="button" data-bs-toggle="collapse" data-bs-target="#collapse-<?php echo md5($sectionId); ?>" aria-expanded="false" aria-controls="collapse-<?php echo md5($sectionId); ?>">
|
||||
<i class="fas fa-door-open"></i> <?php echo htmlspecialchars($sectionName); ?>
|
||||
</button>
|
||||
</h2>
|
||||
<!-- Corpo della sezione -->
|
||||
<div id="collapse-<?php echo md5($sectionId); ?>" class="accordion-collapse collapse" aria-labelledby="heading-<?php echo md5($sectionId); ?>" data-bs-parent="#documentSections">
|
||||
<div class="accordion-body">
|
||||
<?php foreach ($sectionDocuments as $document) { ?>
|
||||
<div class="card card-body mb-4">
|
||||
<!-- Titolo del documento -->
|
||||
<div class="document-header d-flex justify-content-between align-items-center p-3 mb-3" style="background-color: #e8f5e9; border-radius: 8px; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);">
|
||||
<div>
|
||||
<span class="document-title fw-bold"><?php echo htmlspecialchars($document['document_name']); ?></span>
|
||||
<?php if ($document['is_required']) { ?>
|
||||
<span class="badge bg-danger ms-2" style="font-size: 1rem; padding: 0.5em 0.8em;">Obbligatorio</span>
|
||||
<?php } ?>
|
||||
<?php if ($document['max_documents'] > 0) { ?>
|
||||
<span class="badge bg-info ms-2" style="font-size: 1rem; padding: 0.5em 0.8em;">Max: <?php echo $document['max_documents']; ?></span>
|
||||
<?php } ?>
|
||||
</div>
|
||||
|
||||
<?php if (in_array($sharingType, ['add-documents', 'full-control'])) { ?>
|
||||
<button class="btn btn-sm btn-outline-primary toggle-dropzone" data-target="#dropzone-<?php echo $document['document_id']; ?>">
|
||||
<i class="fas fa-plus"></i>
|
||||
</button>
|
||||
<?php } ?>
|
||||
</div>
|
||||
|
||||
<!-- Area Drag & Drop per il caricamento -->
|
||||
<div class="dropzone-container collapse" id="dropzone-<?php echo $document['document_id']; ?>">
|
||||
<div class="dropzone mb-3">
|
||||
<div class="dz-message">
|
||||
<i class="fas fa-cloud-upload-alt"></i><br>
|
||||
Trascina qui i documenti o clicca per caricare
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Tabella dei documenti già caricati -->
|
||||
<h6 class="mt-4">Documenti già caricati:</h6>
|
||||
<?php if (isset($loadedDocuments[$document['document_id']]) && count($loadedDocuments[$document['document_id']]) > 0) { ?>
|
||||
<table class="table table-bordered document-list-table" id="table-<?php echo $document['document_id']; ?>">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Nome Documento</th>
|
||||
<th>Data Caricamento</th>
|
||||
<th>Azioni</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach ($loadedDocuments[$document['document_id']] as $loadedDoc) { ?>
|
||||
<tr>
|
||||
<td><a href="homedocuments/<?php echo $loadedDoc['filename']; ?>" target="_blank"><?php echo htmlspecialchars($loadedDoc['filename']); ?></a></td>
|
||||
<td><?php echo htmlspecialchars($loadedDoc['created_at']); ?></td>
|
||||
<td>
|
||||
<?php if ($sharingType === 'full-control') { ?>
|
||||
<button class="btn btn-danger btn-sm delete-document" data-id="<?php echo $loadedDoc['id']; ?>" data-file="<?php echo $loadedDoc['filename']; ?>">
|
||||
<i class="fas fa-trash"></i>
|
||||
</button>
|
||||
<?php } ?>
|
||||
</td>
|
||||
</tr>
|
||||
<?php } ?>
|
||||
</tbody>
|
||||
</table>
|
||||
<?php } else { ?>
|
||||
<p class="text-muted">Nessun documento caricato</p>
|
||||
<?php } ?>
|
||||
</div>
|
||||
<?php } ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php } ?>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
</div><!-- container -->
|
||||
</div><!-- Page content Wrapper -->
|
||||
</div><!-- content -->
|
||||
<?php include('include/footer.php'); ?>
|
||||
</div><!-- End Right content here -->
|
||||
</div><!-- END wrapper -->
|
||||
|
||||
<!-- jQuery -->
|
||||
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
|
||||
<script src="https://cdn.datatables.net/1.11.5/js/jquery.dataTables.min.js"></script>
|
||||
<script src="https://cdn.datatables.net/1.11.5/js/dataTables.bootstrap4.min.js"></script>
|
||||
|
||||
<!-- Plugin Dropzone -->
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/dropzone/5.9.2/dropzone.min.js"></script>
|
||||
|
||||
<script>
|
||||
// Disabilita l'auto-discover di Dropzone
|
||||
Dropzone.autoDiscover = false;
|
||||
|
||||
// Inizializza Dropzone per ciascun documento
|
||||
<?php foreach ($documents as $section => $sectionDocuments) { ?>
|
||||
<?php foreach ($sectionDocuments as $document) { ?>
|
||||
new Dropzone("#dropzone-<?php echo $document['document_id']; ?>", {
|
||||
url: "upload-document.php", // URL per il caricamento
|
||||
paramName: "file", // Nome del campo per il file
|
||||
maxFiles: <?php echo $document['max_documents']; ?>, // Numero massimo di file
|
||||
maxFilesize: 5, // Dimensione massima del file in MB
|
||||
addRemoveLinks: true, // Permette di rimuovere i file
|
||||
acceptedFiles: "image/*,application/pdf", // Tipi di file accettati
|
||||
dictDefaultMessage: "Trascina qui i file o clicca per caricarli",
|
||||
dictRemoveFile: "Rimuovi",
|
||||
previewTemplate: `
|
||||
<div class="dz-preview dz-file-preview">
|
||||
<div class="dz-image"><img data-dz-thumbnail /></div>
|
||||
<div class="dz-details">
|
||||
<div class="dz-filename"><span data-dz-name></span></div>
|
||||
<div class="dz-size"><span data-dz-size></span></div>
|
||||
</div>
|
||||
<div class="dz-progress">
|
||||
<span class="dz-upload" data-dz-uploadprogress></span>
|
||||
</div>
|
||||
<div class="dz-error-message"><span data-dz-errormessage></span></div>
|
||||
<div class="dz-success-mark">
|
||||
<i class="fas fa-check-circle"></i>
|
||||
</div>
|
||||
<div class="dz-error-mark">
|
||||
<i class="fas fa-times-circle"></i>
|
||||
</div>
|
||||
</div>
|
||||
`,
|
||||
init: function() {
|
||||
this.on("success", function(file, response) {
|
||||
try {
|
||||
let parsedResponse = typeof response === "string" ? JSON.parse(response) : response;
|
||||
|
||||
if (parsedResponse.success) {
|
||||
// Aggiungi il file alla tabella
|
||||
let tableId = "#table-<?php echo $document['document_id']; ?> tbody";
|
||||
let row = `
|
||||
<tr>
|
||||
<td><a href="homedocuments/${parsedResponse.fileName}" target="_blank">${parsedResponse.fileName}</a></td>
|
||||
<td>${parsedResponse.uploadDate}</td>
|
||||
<td><button class="btn btn-danger btn-sm delete-document" data-id="${parsedResponse.documentId}" data-file="${parsedResponse.fileName}">Elimina</button></td>
|
||||
</tr>`;
|
||||
$(tableId).append(row);
|
||||
} else {
|
||||
Swal.fire({
|
||||
icon: "error",
|
||||
title: "Errore",
|
||||
text: parsedResponse.message || "Errore nel caricamento",
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Errore nel parsing della risposta:", error);
|
||||
Swal.fire({
|
||||
icon: "error",
|
||||
title: "Errore",
|
||||
text: "Risposta dal server non valida.",
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
this.on("error", function(file, errorMessage) {
|
||||
Swal.fire({
|
||||
icon: "error",
|
||||
title: "Errore",
|
||||
text: errorMessage || "Si è verificato un problema.",
|
||||
});
|
||||
this.removeFile(file); // Rimuovi il file in caso di errore
|
||||
});
|
||||
},
|
||||
sending: function(file, xhr, formData) {
|
||||
formData.append("idhome", "<?php echo $idhome; ?>");
|
||||
formData.append("document_id", "<?php echo $document['document_id']; ?>");
|
||||
}
|
||||
});
|
||||
<?php } ?>
|
||||
<?php } ?>
|
||||
</script>
|
||||
|
||||
<script>
|
||||
$(document).on("click", ".delete-document", function() {
|
||||
const documentId = $(this).data("id");
|
||||
const fileName = $(this).data("file");
|
||||
const $row = $(this).closest("tr");
|
||||
|
||||
Swal.fire({
|
||||
title: "Sei sicuro?",
|
||||
text: "Questa azione eliminerà il documento in modo permanente.",
|
||||
icon: "warning",
|
||||
showCancelButton: true,
|
||||
confirmButtonColor: "#d33",
|
||||
cancelButtonColor: "#3085d6",
|
||||
confirmButtonText: "Sì, elimina",
|
||||
cancelButtonText: "Annulla",
|
||||
}).then((result) => {
|
||||
if (result.isConfirmed) {
|
||||
$.ajax({
|
||||
url: "delete-document.php",
|
||||
type: "POST",
|
||||
data: {
|
||||
document_id: documentId,
|
||||
file_name: fileName,
|
||||
},
|
||||
success: function(response) {
|
||||
try {
|
||||
const parsedResponse = typeof response === "string" ? JSON.parse(response) : response;
|
||||
|
||||
if (parsedResponse.success) {
|
||||
$row.remove(); // Rimuovi la riga dalla tabella
|
||||
Swal.fire({
|
||||
icon: "success",
|
||||
title: "Eliminato",
|
||||
text: "Documento eliminato con successo.",
|
||||
timer: 1500,
|
||||
showConfirmButton: false,
|
||||
});
|
||||
} else {
|
||||
Swal.fire({
|
||||
icon: "error",
|
||||
title: "Errore",
|
||||
text: parsedResponse.message || "Impossibile eliminare il documento.",
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Errore durante l'eliminazione:", error);
|
||||
Swal.fire({
|
||||
icon: "error",
|
||||
title: "Errore",
|
||||
text: "Risposta dal server non valida.",
|
||||
});
|
||||
}
|
||||
},
|
||||
error: function() {
|
||||
Swal.fire({
|
||||
icon: "error",
|
||||
title: "Errore",
|
||||
text: "Si è verificato un problema con la richiesta.",
|
||||
});
|
||||
},
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
<script>
|
||||
// Gestione del toggle dell'area Dropzone
|
||||
document.querySelectorAll('.toggle-dropzone').forEach(button => {
|
||||
button.addEventListener('click', function() {
|
||||
const target = document.querySelector(this.dataset.target);
|
||||
const icon = this.querySelector('i');
|
||||
|
||||
if (target.classList.contains('show')) {
|
||||
target.classList.remove('show');
|
||||
target.style.display = 'none';
|
||||
icon.classList.remove('fa-minus');
|
||||
icon.classList.add('fa-plus');
|
||||
} else {
|
||||
target.classList.add('show');
|
||||
target.style.display = 'block';
|
||||
icon.classList.remove('fa-plus');
|
||||
icon.classList.add('fa-minus');
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
@ -20,7 +20,7 @@
|
||||
<a href="../" class="" data-toggle="tooltip" data-placement="top" title="Profile"><i class="dripicons-user text-purple"></i></a>
|
||||
</li>
|
||||
<li class="list-inline-item">
|
||||
<a href="#" class="" data-toggle="tooltip" data-placement="top" title="Settings"><i class="dripicons-gear text-dark"></i></a>
|
||||
<a href="../" class="" data-toggle="tooltip" data-placement="top" title="Settings"><i class="dripicons-gear text-dark"></i></a>
|
||||
</li>
|
||||
<li class="list-inline-item">
|
||||
<a href="../logout" class="" data-toggle="tooltip" data-placement="top" title="Log out"><i class="dripicons-power text-danger"></i></a>
|
||||
@ -53,7 +53,7 @@
|
||||
|
||||
</li>
|
||||
<li class="">
|
||||
<a href="person-list.php" class="waves-effect"><i class="dripicons-blog"></i><span> Immobili Condivisi </span></a>
|
||||
<a href="shared-homes.php" class="waves-effect"><i class="dripicons-blog"></i><span> Immobili Condivisi </span></a>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
@ -29,7 +29,7 @@ $conn->close();
|
||||
|
||||
<ul class="list-inline float-right mb-0">
|
||||
<!-- language-->
|
||||
<li class="list-inline-item dropdown notification-list hide-phone">
|
||||
<!-- <li class="list-inline-item dropdown notification-list hide-phone">
|
||||
<a class="nav-link dropdown-toggle arrow-none waves-effect text-white" data-toggle="dropdown" href="#" role="button"
|
||||
aria-haspopup="false" aria-expanded="false">
|
||||
English <img src="assets/images/flags/us_flag.jpg" class="ml-2" height="16" alt="" />
|
||||
@ -37,7 +37,7 @@ $conn->close();
|
||||
<div class="dropdown-menu dropdown-menu-right language-switch">
|
||||
|
||||
</div>
|
||||
</li>
|
||||
</li> -->
|
||||
|
||||
|
||||
|
||||
@ -52,8 +52,8 @@ $conn->close();
|
||||
<div class="dropdown-item noti-title">
|
||||
<h5>Welcome</h5>
|
||||
</div>
|
||||
<a class="dropdown-item" href="../"><i class="mdi mdi-account-circle m-r-5 text-muted"></i> Profile</a>
|
||||
<a class="dropdown-item" href="#"><i class="mdi mdi-settings m-r-5 text-muted"></i> Settings</a>
|
||||
<a class="dropdown-item" href="../"><i class="mdi mdi-account-circle m-r-5 text-muted"></i> Profilo Utente</a>
|
||||
|
||||
|
||||
<div class="dropdown-divider"></div>
|
||||
<a class="dropdown-item" href="#"><i class="mdi mdi-logout m-r-5 text-muted"></i> Logout</a>
|
||||
|
||||
@ -230,7 +230,7 @@ $totalDocuments = $resultDocuments->fetch_assoc()['total_documents'];
|
||||
</a>
|
||||
</div>
|
||||
<div class="col-lg-4 col-md-6 mb-4">
|
||||
<a href="condivisioni.php" class="btn btn-info d-flex flex-column justify-content-center align-items-center py-5 shadow rounded-lg">
|
||||
<a href="shared-homes.php" class="btn btn-info d-flex flex-column justify-content-center align-items-center py-5 shadow rounded-lg">
|
||||
<i class="mdi mdi-share-outline" style="font-size: 3rem;"></i>
|
||||
<span class="mt-2 fw-bold" style="font-size: 1.25rem;">Immobili Condivisi</span>
|
||||
</a>
|
||||
|
||||
152
public/userportal/shared-homes.php
Normal file
152
public/userportal/shared-homes.php
Normal file
@ -0,0 +1,152 @@
|
||||
<?php include('include/headscript.php'); ?>
|
||||
<?php
|
||||
// Connessione al database
|
||||
$conn = new mysqli($servername, $username, $password, $database);
|
||||
|
||||
// Recupera l'id utente loggato e la sua email
|
||||
$iduserlogin = $_SESSION['iduserlogin'];
|
||||
$emailuser = $_SESSION['emailuser'];
|
||||
|
||||
// Query per ottenere gli immobili condivisi con l'utente loggato
|
||||
$sql = "
|
||||
SELECT
|
||||
hs.idhome,
|
||||
h.name,
|
||||
h.address,
|
||||
h.zip,
|
||||
h.city,
|
||||
h.country,
|
||||
hs.sharing_type,
|
||||
hs.expiration_date,
|
||||
au.first_name,
|
||||
au.last_name
|
||||
FROM home_sharing hs
|
||||
LEFT JOIN home h ON hs.idhome = h.idhome
|
||||
LEFT JOIN auth_users au ON hs.iduser = au.id
|
||||
WHERE
|
||||
(hs.idshareduser = ? OR hs.shared_email = ?)
|
||||
AND hs.status = 'accepted'
|
||||
";
|
||||
$stmt = $conn->prepare($sql);
|
||||
$stmt->bind_param('is', $iduserlogin, $emailuser);
|
||||
$stmt->execute();
|
||||
$result = $stmt->get_result();
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="it">
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimal-ui">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<title>Immobili Condivisi</title>
|
||||
|
||||
<!-- Bootstrap 4 CSS -->
|
||||
<link href="assets/css/bootstrap.min.css" rel="stylesheet" type="text/css">
|
||||
<link href="https://cdn.datatables.net/1.11.5/css/dataTables.bootstrap4.min.css" rel="stylesheet" />
|
||||
<link href="https://cdnjs.cloudflare.com/ajax/libs/dripicons/2.0.0/webfont.min.css" rel="stylesheet">
|
||||
|
||||
<!-- Font Awesome -->
|
||||
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css" rel="stylesheet" />
|
||||
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
|
||||
|
||||
<!-- Custom CSS -->
|
||||
<link href="assets/css/style.css" rel="stylesheet" type="text/css">
|
||||
</head>
|
||||
|
||||
<body class="fixed-left">
|
||||
<div id="wrapper">
|
||||
<?php include('include/navigationbar.php'); ?>
|
||||
<div class="content-page">
|
||||
<div class="content">
|
||||
<?php include('include/topbar.php'); ?>
|
||||
|
||||
<div class="page-content-wrapper">
|
||||
<div class="container-fluid">
|
||||
<div class="row">
|
||||
<div class="col-sm-12">
|
||||
<div class="page-title-box">
|
||||
<div class="btn-group float-right">
|
||||
<ol class="breadcrumb hide-phone p-0 m-0">
|
||||
<li class="breadcrumb-item"><a href="#">CasaDoc</a></li>
|
||||
<li class="breadcrumb-item active">Immobili Condivisi</li>
|
||||
</ol>
|
||||
</div>
|
||||
<h4 class="page-title">Immobili Condivisi</h4>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-xl-12">
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<div class="table-responsive">
|
||||
<table id="sharedHomesTable" class="table table-bordered table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Nome</th>
|
||||
<th>Indirizzo</th>
|
||||
<th>CAP</th>
|
||||
<th>Città</th>
|
||||
<th>Nazione</th>
|
||||
<th>Condiviso da</th>
|
||||
<th>Tipo Condivisione</th>
|
||||
<th>Data Scadenza</th>
|
||||
<th>Azioni</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php while ($row = $result->fetch_assoc()) { ?>
|
||||
<tr>
|
||||
<td><?php echo htmlspecialchars($row['name']); ?></td>
|
||||
<td><?php echo htmlspecialchars($row['address']); ?></td>
|
||||
<td><?php echo htmlspecialchars($row['zip']); ?></td>
|
||||
<td><?php echo htmlspecialchars($row['city']); ?></td>
|
||||
<td><?php echo htmlspecialchars($row['country']); ?></td>
|
||||
<td><?php echo htmlspecialchars($row['first_name'] . ' ' . $row['last_name']); ?></td>
|
||||
<td><?php echo htmlspecialchars(ucfirst($row['sharing_type'])); ?></td>
|
||||
<td>
|
||||
<?php echo $row['expiration_date'] ? htmlspecialchars($row['expiration_date']) : 'Nessuna'; ?>
|
||||
</td>
|
||||
<td>
|
||||
<!-- Pulsante per visualizzare i dettagli -->
|
||||
<a href="documents-home-shared.php?idhome=<?php echo $row['idhome']; ?>" class="btn btn-primary btn-sm" title="Documenti">
|
||||
<i class="fas fa-folder-open"></i>
|
||||
</a>
|
||||
</td>
|
||||
</tr>
|
||||
<?php } ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div><!-- end table-responsive -->
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div><!-- container -->
|
||||
</div><!-- Page content Wrapper -->
|
||||
</div><!-- content -->
|
||||
<?php include('include/footer.php'); ?>
|
||||
</div><!-- End Right content here -->
|
||||
</div><!-- END wrapper -->
|
||||
|
||||
<!-- jQuery -->
|
||||
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
|
||||
<script src="https://cdn.datatables.net/1.11.5/js/jquery.dataTables.min.js"></script>
|
||||
<script src="https://cdn.datatables.net/1.11.5/js/dataTables.bootstrap4.min.js"></script>
|
||||
|
||||
<script>
|
||||
$(document).ready(function() {
|
||||
// Inizializza DataTables
|
||||
$('#sharedHomesTable').DataTable({
|
||||
order: [
|
||||
[0, 'asc']
|
||||
] // Ordina per nome
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
||||
Loading…
x
Reference in New Issue
Block a user