added upload doc
This commit is contained in:
@@ -0,0 +1,230 @@
|
||||
<?php include('include/headscript.php'); ?>
|
||||
<?php
|
||||
// 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 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();
|
||||
|
||||
// Recupera i documenti dalla tabella 'documents' raggruppati per sezione
|
||||
$queryDocuments = $conn->query("SELECT * FROM documents ORDER BY section");
|
||||
|
||||
$documents = [];
|
||||
while ($row = $queryDocuments->fetch_assoc()) {
|
||||
$documents[$row['section']][] = $row;
|
||||
}
|
||||
|
||||
// Recupera i documenti già caricati per questa casa
|
||||
$queryLoadedDocuments = $conn->prepare("SELECT * FROM doc_storage WHERE idhome = ?");
|
||||
$queryLoadedDocuments->bind_param('i', $idhome);
|
||||
$queryLoadedDocuments->execute();
|
||||
$resultLoadedDocuments = $queryLoadedDocuments->get_result();
|
||||
|
||||
$loadedDocuments = [];
|
||||
while ($row = $resultLoadedDocuments->fetch_assoc()) {
|
||||
$loadedDocuments[$row['document_id']][] = $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" />
|
||||
|
||||
<!-- 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" />
|
||||
|
||||
<style>
|
||||
.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;
|
||||
}
|
||||
</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'); ?>
|
||||
|
||||
<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>
|
||||
|
||||
<!-- Sezioni per documenti -->
|
||||
<?php foreach ($documents as $section => $sectionDocuments) { ?>
|
||||
<div class="section-separator"></div>
|
||||
<h5 class="section-title"><?php echo htmlspecialchars($section); ?></h5>
|
||||
<?php foreach ($sectionDocuments as $document) { ?>
|
||||
<div class="row">
|
||||
<div class="col-lg-12">
|
||||
<div class="card card-body mb-4">
|
||||
<!-- Titolo del documento -->
|
||||
<p class="document-title">
|
||||
<?php echo htmlspecialchars($document['document_name']); ?>
|
||||
<?php if ($document['is_required']) echo "<strong>(Obbligatorio)</strong>"; ?>
|
||||
<?php if ($document['max_documents'] > 0) echo " - Max: " . $document['max_documents']; ?>
|
||||
</p>
|
||||
|
||||
<!-- Area Drag & Drop per il caricamento -->
|
||||
<div class="dropzone mb-3" id="dropzone-<?php echo $document['document_id']; ?>">
|
||||
<div class="dz-message">
|
||||
<i class="fas fa-cloud-upload-alt"></i><br>
|
||||
Trascina qui i documenti o clicca per caricare
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Tabella dei documenti già caricati -->
|
||||
<h6 class="mt-4">Documenti già caricati:</h6>
|
||||
<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>
|
||||
<!-- Qui verranno inseriti i documenti caricati per quel documento -->
|
||||
<?php if (isset($loadedDocuments[$document['document_id']])) { ?>
|
||||
<?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><button class="btn btn-danger btn-sm">Elimina</button></td>
|
||||
</tr>
|
||||
<?php } ?>
|
||||
<?php } ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php } ?>
|
||||
<?php } ?>
|
||||
</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>
|
||||
// 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 del caricamento
|
||||
paramName: "file", // Il nome del campo per il file
|
||||
maxFiles: <?php echo $document['max_documents']; ?>, // Imposta il numero massimo di file
|
||||
addRemoveLinks: true,
|
||||
init: function() {
|
||||
this.on("success", function(file, response) {
|
||||
let tableId = "#table-<?php echo $document['document_id']; ?> tbody";
|
||||
// Aggiorna la tabella dei documenti caricati
|
||||
let row = `<tr>
|
||||
<td><a href="homedocuments/${response.fileName}" target="_blank">${response.fileName}</a></td>
|
||||
<td>${response.uploadDate}</td>
|
||||
<td><button class="btn btn-danger btn-sm">Elimina</button></td>
|
||||
</tr>`;
|
||||
$(tableId).append(row);
|
||||
});
|
||||
},
|
||||
sending: function(file, xhr, formData) {
|
||||
formData.append("idhome", "<?php echo $idhome; ?>");
|
||||
formData.append("document_id", "<?php echo $document['document_id']; ?>");
|
||||
}
|
||||
});
|
||||
<?php } ?>
|
||||
<?php } ?>
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
Reference in New Issue
Block a user