casadoc/public/userportal/homes-list.php
2025-01-25 21:37:42 +01:00

281 lines
14 KiB
PHP

<?php include('include/headscript.php'); ?>
<?php
// Connessione al database
$conn = new mysqli($servername, $username, $password, $database);
// Recupera l'id utente loggato
$iduserlogin = $_SESSION['iduserlogin'];
// Query per ottenere le case dell'utente
$sql = "
SELECT
h.idhome,
h.name,
h.address,
h.zip,
h.city,
h.country,
COUNT(ho.owner_id) AS owner_count,
GROUP_CONCAT(
CASE
WHEN po.owner_type = 'individual'
THEN CONCAT(po.first_name, ' ', po.last_name)
ELSE po.company_name
END
SEPARATOR '\n'
) AS owner_names
FROM
home h
LEFT JOIN
home_owners ho ON h.idhome = ho.home_id
LEFT JOIN
property_owners po ON ho.owner_id = po.owner_id
WHERE
h.iduser = ?
GROUP BY
h.idhome
";
$stmt = $conn->prepare($sql);
$stmt->bind_param('i', $iduserlogin);
$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>Elenco delle tue case</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">Elenco Case</li>
</ol>
</div>
<h4 class="page-title">Elenco delle tue case</h4>
</div>
</div>
</div>
<div class="row mb-3">
<div class="col-sm-12">
<div class="float-right">
<!-- Pulsante per aggiungere una nuova casa -->
<a href="manage-home.php" class="btn btn-success">
<i class="fas fa-plus"></i> Aggiungi Casa/Terreno
</a>
</div>
</div>
</div>
<div class="row">
<div class="col-xl-12">
<div class="card">
<div class="card-body">
<div class="table-responsive">
<table id="homeTable" class="table table-bordered table-striped">
<thead>
<tr>
<th>Nome</th>
<th>Indirizzo</th>
<th>Città</th>
<th>Nazione</th>
<th>Nomi Proprietari</th>
<th>Proprietari</th>
<th>Action</th>
</tr>
<tr>
<!-- Campi di input per i filtri -->
<th><input type="text" placeholder="Cerca Nome" class="form-control form-control-sm"></th>
<th><input type="text" placeholder="Cerca Indirizzo" class="form-control form-control-sm"></th>
<th><input type="text" placeholder="Cerca Città" class="form-control form-control-sm"></th>
<th><input type="text" placeholder="Cerca Nazione" class="form-control form-control-sm"></th>
<th><input type="text" placeholder="Cerca Proprietari" class="form-control form-control-sm"></th>
<th></th>
<th></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']); ?> - <?php echo htmlspecialchars($row['city']); ?></td>
<td><?php echo htmlspecialchars($row['country']); ?></td>
<td><?php echo nl2br(htmlspecialchars($row['owner_names'])); ?></td>
<td>
<?php if ($row['owner_count'] == 0) { ?>
<a href="assign-owners.php?idhome=<?php echo $row['idhome']; ?>" class="btn btn-danger btn-sm">
<i class="fas fa-user-times"></i> Assegna Proprietario
</a>
<?php } else { ?>
<a href="assign-owners.php?idhome=<?php echo $row['idhome']; ?>" class="btn btn-success btn-sm">
<i class="fas fa-user-check"></i> <?php echo htmlspecialchars($row['owner_count']); ?> Proprietari
</a>
<?php } ?>
</td>
<td class="text-nowrap">
<div class="d-flex justify-content-start align-items-center gap-2">
<!-- Pulsante per modificare i dettagli della casa -->
<a href="manage-home.php?idhome=<?php echo $row['idhome']; ?>" class="btn btn-info btn-sm me-2" title="Dettagli">
<i class="fas fa-info-circle"></i>
</a>
<!-- Pulsante per i documenti della casa -->
<a href="documents-home.php?idhome=<?php echo $row['idhome']; ?>" class="btn btn-primary btn-sm me-2" title="Documenti">
<i class="fas fa-folder-open"></i>
</a>
<!-- Pulsante per condividere la casa -->
<a href="share-home.php?idhome=<?php echo $row['idhome']; ?>" class="btn btn-warning btn-sm me-2" title="Condividi">
<i class="fas fa-share-alt"></i>
</a>
<!-- Pulsante per passaggio proprietà -->
<button class="btn btn-secondary btn-sm me-2 transfer-property-btn" data-id="<?php echo $row['idhome']; ?>" title="Passaggio Proprietà">
<i class="fas fa-exchange-alt"></i>
</button>
<!-- Pulsante per eliminare la casa -->
<button class="btn btn-danger btn-sm delete-home-btn" data-id="<?php echo $row['idhome']; ?>" title="Elimina">
<i class="fas fa-trash-alt"></i>
</button>
</div>
</td>
</tr>
<?php } ?>
</tbody>
</table>
</div><!-- end table-responsive -->
</div>
</div>
</div>
</div>
<div class="mb-3">
<button onclick="history.back()" class="btn btn-dark">
<i class="fas fa-arrow-left"></i> Torna indietro
</button>
</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 con filtri di colonna
var table = $('#homeTable').DataTable();
// Aggiungi ricerca personalizzata in ogni colonna
$('#homeTable thead tr:eq(1) th').each(function(i) {
$('input', this).on('keyup change', function() {
if (table.column(i).search() !== this.value) {
table.column(i).search(this.value).draw();
}
});
});
});
</script>
<script>
$(document).ready(function() {
// Inizializza DataTables con filtri di colonna
var table = $('#homeTable').DataTable();
// Aggiungi ricerca personalizzata in ogni colonna
$('#homeTable thead tr:eq(1) th').each(function(i) {
$('input', this).on('keyup change', function() {
if (table.column(i).search() !== this.value) {
table.column(i).search(this.value).draw();
}
});
});
// Gestisci l'eliminazione con SweetAlert
$('.delete-home-btn').on('click', function() {
var idhome = $(this).data('id'); // Ottieni l'id della casa
Swal.fire({
title: 'Sei sicuro?',
text: "Questa azione eliminerà la casa e non può essere annullata.",
icon: 'warning',
showCancelButton: true,
confirmButtonColor: '#d33',
cancelButtonColor: '#3085d6',
confirmButtonText: 'Sì, elimina',
cancelButtonText: 'Annulla'
}).then((result) => {
if (result.isConfirmed) {
// Reindirizza al file di eliminazione
window.location.href = "delete-home.php?idhome=" + idhome;
}
});
});
});
</script>
<script>
$(document).ready(function() {
<?php if (isset($_GET['status']) && $_GET['status'] == 'success') { ?>
Swal.fire({
icon: 'success',
title: 'Eliminazione completata!',
text: 'La casa è stata eliminata con successo.'
});
<?php } elseif (isset($_GET['status']) && $_GET['status'] == 'error') { ?>
Swal.fire({
icon: 'error',
title: 'Errore!',
text: 'Si è verificato un errore durante l\'eliminazione della casa.'
});
<?php } ?>
});
</script>
</body>
</html>