update icon manage home
This commit is contained in:
parent
9399e5b54a
commit
b5e9901b8e
@ -4,7 +4,8 @@ include('include/headscript.php');
|
|||||||
$conn = new mysqli($servername, $username, $password, $database);
|
$conn = new mysqli($servername, $username, $password, $database);
|
||||||
$iduserlogin = $_SESSION['iduserlogin'];
|
$iduserlogin = $_SESSION['iduserlogin'];
|
||||||
$idhome = isset($_GET['idhome']) ? intval($_GET['idhome']) : 0;
|
$idhome = isset($_GET['idhome']) ? intval($_GET['idhome']) : 0;
|
||||||
$docpage = isset($_GET['slug']) ? $_GET['slug'] : 'legal';
|
$docpage = isset($_GET['slug']) ? $_GET['slug'] : 'legal'; // Slug principale per la pagina
|
||||||
|
$subSlug = isset($_GET['subSlug']) ? $_GET['subSlug'] : null; // Slug aggiuntivo opzionale
|
||||||
$showOnlyRequired = isset($_GET['showOnlyRequired']) && $_GET['showOnlyRequired'] === 'true';
|
$showOnlyRequired = isset($_GET['showOnlyRequired']) && $_GET['showOnlyRequired'] === 'true';
|
||||||
$sectionId = isset($_GET['sectionId']) ? $_GET['sectionId'] : null;
|
$sectionId = isset($_GET['sectionId']) ? $_GET['sectionId'] : null;
|
||||||
|
|
||||||
@ -32,26 +33,35 @@ if (!$pageData) {
|
|||||||
|
|
||||||
$page_id = $pageData['idpages'];
|
$page_id = $pageData['idpages'];
|
||||||
|
|
||||||
|
// Costruisci la query per i documenti
|
||||||
$sql = "
|
$sql = "
|
||||||
SELECT d.*, s.section_name AS section_name
|
SELECT d.*, s.section_name AS section_name
|
||||||
FROM documents d
|
FROM documents d
|
||||||
LEFT JOIN sections s ON d.idsections = s.idsections
|
LEFT JOIN sections s ON d.idsections = s.idsections
|
||||||
WHERE d.page_id = ?
|
WHERE d.page_id = ?
|
||||||
";
|
";
|
||||||
|
$params = [$page_id];
|
||||||
|
|
||||||
if ($showOnlyRequired) {
|
if ($showOnlyRequired) {
|
||||||
$sql .= " AND d.is_required = 1";
|
$sql .= " AND d.is_required = 1";
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($sectionId) {
|
if ($sectionId) {
|
||||||
$sql .= " AND md5(s.section_name) = ?";
|
$sql .= " AND md5(s.section_name) = ?";
|
||||||
|
$params[] = $sectionId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Aggiungi filtro per subSlug (assumendo che i documenti abbiano un campo slug o un riferimento)
|
||||||
|
if ($subSlug) {
|
||||||
|
$sql .= " AND d.slug = ?"; // Assumo che 'documents' abbia un campo 'slug' per il filtraggio
|
||||||
|
$params[] = $subSlug;
|
||||||
|
}
|
||||||
|
|
||||||
$sql .= " ORDER BY s.section_name, d.document_name";
|
$sql .= " ORDER BY s.section_name, d.document_name";
|
||||||
|
|
||||||
$queryDocuments = $conn->prepare($sql);
|
$queryDocuments = $conn->prepare($sql);
|
||||||
if ($sectionId) {
|
$types = str_repeat('s', count($params) - 1) . 'i'; // 's' per stringhe, 'i' per page_id
|
||||||
$queryDocuments->bind_param('is', $page_id, $sectionId);
|
$queryDocuments->bind_param($types, ...$params);
|
||||||
} else {
|
|
||||||
$queryDocuments->bind_param('i', $page_id);
|
|
||||||
}
|
|
||||||
$queryDocuments->execute();
|
$queryDocuments->execute();
|
||||||
$resultDocuments = $queryDocuments->get_result();
|
$resultDocuments = $queryDocuments->get_result();
|
||||||
|
|
||||||
|
|||||||
@ -107,7 +107,6 @@ $mainphoto = !empty($homeData['mainphoto']) ? 'mainphoto/' . $homeData['mainphot
|
|||||||
margin: 0;
|
margin: 0;
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
color: #ffffff;
|
color: #ffffff;
|
||||||
/* Nome dell'immobile in bianco */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.header-banner-overlay .property-info p {
|
.header-banner-overlay .property-info p {
|
||||||
@ -180,10 +179,10 @@ $mainphoto = !empty($homeData['mainphoto']) ? 'mainphoto/' . $homeData['mainphot
|
|||||||
<!-- Tab Navigation -->
|
<!-- Tab Navigation -->
|
||||||
<ul class="nav nav-tabs" id="propertyTabs" role="tablist">
|
<ul class="nav nav-tabs" id="propertyTabs" role="tablist">
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<a class="nav-link active" id="details-tab" data-toggle="tab" href="#details" role="tab" aria-controls="details" aria-selected="true">Dettagli</a>
|
<a class="nav-link" id="details-tab" data-toggle="tab" href="#details" role="tab" aria-controls="details" aria-selected="false">Dettagli</a>
|
||||||
</li>
|
</li>
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<a class="nav-link" id="documents-tab" data-toggle="tab" href="#documents" role="tab" aria-controls="documents" aria-selected="false">Documenti</a>
|
<a class="nav-link active" id="documents-tab" data-toggle="tab" href="#documents" role="tab" aria-controls="documents" aria-selected="true">Documenti</a>
|
||||||
</li>
|
</li>
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<a class="nav-link" id="owners-tab" data-toggle="tab" href="#owners" role="tab" aria-controls="owners" aria-selected="false">Proprietari</a>
|
<a class="nav-link" id="owners-tab" data-toggle="tab" href="#owners" role="tab" aria-controls="owners" aria-selected="false">Proprietari</a>
|
||||||
@ -193,11 +192,11 @@ $mainphoto = !empty($homeData['mainphoto']) ? 'mainphoto/' . $homeData['mainphot
|
|||||||
<!-- Tab Content -->
|
<!-- Tab Content -->
|
||||||
<div class="tab-content" id="propertyTabsContent">
|
<div class="tab-content" id="propertyTabsContent">
|
||||||
<!-- Tab Dettagli -->
|
<!-- Tab Dettagli -->
|
||||||
<div class="tab-pane fade show active" id="details" role="tabpanel" aria-labelledby="details-tab">
|
<div class="tab-pane fade" id="details" role="tabpanel" aria-labelledby="details-tab">
|
||||||
<?php include('tabs/dettagli.php'); ?>
|
<?php include('tabs/dettagli.php'); ?>
|
||||||
</div>
|
</div>
|
||||||
<!-- Tab Documenti -->
|
<!-- Tab Documenti -->
|
||||||
<div class="tab-pane fade" id="documents" role="tabpanel" aria-labelledby="documents-tab">
|
<div class="tab-pane fade show active" id="documents" role="tabpanel" aria-labelledby="documents-tab">
|
||||||
<?php include('tabs/documenti.php'); ?>
|
<?php include('tabs/documenti.php'); ?>
|
||||||
</div>
|
</div>
|
||||||
<!-- Tab Proprietari -->
|
<!-- Tab Proprietari -->
|
||||||
|
|||||||
@ -2,67 +2,89 @@
|
|||||||
global $idhome, $isNew, $homeData, $namedb, $addressdb, $countrydb, $citydb, $zipdb, $commentdb, $latitudedb, $longitudedb, $fulladdressdb,
|
global $idhome, $isNew, $homeData, $namedb, $addressdb, $countrydb, $citydb, $zipdb, $commentdb, $latitudedb, $longitudedb, $fulladdressdb,
|
||||||
$cadastral_municipalitydb, $cadastral_sectiondb, $cadastral_sheetdb, $cadastral_particledb, $cadastral_subdb, $cadastral_categorydb,
|
$cadastral_municipalitydb, $cadastral_sectiondb, $cadastral_sheetdb, $cadastral_particledb, $cadastral_subdb, $cadastral_categorydb,
|
||||||
$cadastral_classdb, $cadastral_surfacedb, $cadastral_renditadb;
|
$cadastral_classdb, $cadastral_surfacedb, $cadastral_renditadb;
|
||||||
|
|
||||||
require_once dirname(__DIR__) . '/class/db-functions.php';
|
require_once dirname(__DIR__) . '/class/db-functions.php';
|
||||||
$dbHandler = DBHandlerSelect::getInstance();
|
$dbHandler = DBHandlerSelect::getInstance();
|
||||||
$pdo = $dbHandler->getConnection();
|
$pdo = $dbHandler->getConnection();
|
||||||
|
|
||||||
|
// Recupera i dati della casa dal database
|
||||||
|
$stmt = $pdo->prepare("SELECT * FROM home WHERE idhome = ?");
|
||||||
|
$stmt->execute([$idhome]);
|
||||||
|
$homeData = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||||
|
|
||||||
|
if (!$homeData) {
|
||||||
|
die("Errore: Casa non trovata.");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Popola le variabili globali con i dati recuperati
|
||||||
|
$namedb = $homeData['name'] ?? '';
|
||||||
|
$addressdb = $homeData['address'] ?? '';
|
||||||
|
$countrydb = $homeData['country'] ?? '';
|
||||||
|
$citydb = $homeData['city'] ?? '';
|
||||||
|
$zipdb = $homeData['zip'] ?? '';
|
||||||
|
$commentdb = $homeData['comment'] ?? '';
|
||||||
|
$latitudedb = $homeData['latitude'] ?? '';
|
||||||
|
$longitudedb = $homeData['longitude'] ?? '';
|
||||||
|
$fulladdressdb = $homeData['fulladdress'] ?? '';
|
||||||
|
$cadastral_municipalitydb = $homeData['cadastral_municipality'] ?? '';
|
||||||
|
$cadastral_sectiondb = $homeData['cadastral_section'] ?? '';
|
||||||
|
$cadastral_sheetdb = $homeData['cadastral_sheet'] ?? '';
|
||||||
|
$cadastral_particledb = $homeData['cadastral_particle'] ?? '';
|
||||||
|
$cadastral_subdb = $homeData['cadastral_sub'] ?? '';
|
||||||
|
$cadastral_categorydb = $homeData['cadastral_category'] ?? '';
|
||||||
|
$cadastral_classdb = $homeData['cadastral_class'] ?? '';
|
||||||
|
$cadastral_surfacedb = $homeData['cadastral_surface'] ?? '';
|
||||||
|
$cadastral_renditadb = $homeData['cadastral_rendita'] ?? '';
|
||||||
?>
|
?>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
/* Stile per l'overlay dello spinner */
|
/* Stile per il lucchetto */
|
||||||
.loading-overlay {
|
.lock-btn {
|
||||||
position: fixed;
|
font-size: 1.5rem;
|
||||||
top: 0;
|
padding: 0.5rem 1rem;
|
||||||
left: 0;
|
transition: all 0.3s ease;
|
||||||
width: 100%;
|
|
||||||
height: 100%;
|
|
||||||
background: rgba(0, 0, 0, 0.5);
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
justify-content: center;
|
|
||||||
align-items: center;
|
|
||||||
z-index: 9999;
|
|
||||||
display: none;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.loading-overlay .spinner-custom {
|
.lock-btn.locked {
|
||||||
width: 4rem;
|
color: #dc3545;
|
||||||
height: 4rem;
|
|
||||||
border: 4px solid #fff;
|
|
||||||
border-top: 4px solid #007bff;
|
|
||||||
border-radius: 50%;
|
|
||||||
animation: spin 1s linear infinite;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.loading-overlay .spinner-text {
|
.lock-btn.unlocked {
|
||||||
color: #fff;
|
color: #28a745;
|
||||||
font-size: 1.2rem;
|
|
||||||
margin-top: 1rem;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@keyframes spin {
|
/* Flash verde per l'input */
|
||||||
|
.input-flash {
|
||||||
|
animation: flashGreen 0.5s ease-in-out;
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes flashGreen {
|
||||||
0% {
|
0% {
|
||||||
transform: rotate(0deg);
|
background-color: #d4edda;
|
||||||
|
}
|
||||||
|
|
||||||
|
50% {
|
||||||
|
background-color: #d4edda;
|
||||||
}
|
}
|
||||||
|
|
||||||
100% {
|
100% {
|
||||||
transform: rotate(360deg);
|
background-color: transparent;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Stile per il messaggio di salvataggio */
|
||||||
|
.save-flash {
|
||||||
|
animation: flashGreen 1s ease-in-out;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<div class="card card-body">
|
<div class="card card-body">
|
||||||
<!-- Overlay dello spinner -->
|
|
||||||
<div id="loading-overlay" class="loading-overlay">
|
|
||||||
<div class="spinner-custom"></div>
|
|
||||||
<div class="spinner-text">Salvataggio Dati...</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<h4 class="card-title font-20 mt-0"><?php echo $isNew ? "Aggiungi una nuova casa" : "Modifica la tua casa"; ?></h4>
|
<h4 class="card-title font-20 mt-0"><?php echo $isNew ? "Aggiungi una nuova casa" : "Modifica la tua casa"; ?></h4>
|
||||||
|
|
||||||
<!-- Tasto Salva in cima -->
|
<!-- Lucchetto -->
|
||||||
<div class="d-flex justify-content-between align-items-center mb-3">
|
<div class="d-flex justify-content-between align-items-center mb-3">
|
||||||
<button type="button" id="save-form-btn" class="btn btn-primary">
|
<button type="button" id="lock-btn" class="btn lock-btn locked" data-locked="true">
|
||||||
<i class="fas fa-save"></i> Salva Modifiche
|
<i class="fas fa-lock"></i>
|
||||||
</button>
|
</button>
|
||||||
<div id="save-message" class="alert d-none" role="alert"></div>
|
<div id="save-message" class="alert d-none" role="alert"></div>
|
||||||
</div>
|
</div>
|
||||||
@ -74,18 +96,18 @@ $pdo = $dbHandler->getConnection();
|
|||||||
<h4 class="mt-4">Dati Principali</h4>
|
<h4 class="mt-4">Dati Principali</h4>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label>Nome</label>
|
<label>Nome</label>
|
||||||
<input type="text" value="<?php echo htmlspecialchars($namedb); ?>" id="name" name="name" class="form-control" required>
|
<input type="text" value="<?php echo htmlspecialchars($namedb); ?>" id="name" name="name" class="form-control" required readonly>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label>Nota</label>
|
<label>Nota</label>
|
||||||
<textarea id="comment" name="comment" rows="4" class="form-control"><?php echo htmlspecialchars($commentdb); ?></textarea>
|
<textarea id="comment" name="comment" rows="4" class="form-control" readonly><?php echo htmlspecialchars($commentdb); ?></textarea>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<h4 class="mt-4">Indirizzo</h4>
|
<h4 class="mt-4">Indirizzo</h4>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label>Indirizzo Completo</label>
|
<label>Indirizzo Completo</label>
|
||||||
<input type="text" value="<?php echo htmlspecialchars($fulladdressdb); ?>" id="fulladdress" name="fulladdress" class="form-control">
|
<input type="text" value="<?php echo htmlspecialchars($fulladdressdb); ?>" id="fulladdress" name="fulladdress" class="form-control" readonly>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Sezione Mappa e Foto -->
|
<!-- Sezione Mappa e Foto -->
|
||||||
@ -98,7 +120,7 @@ $pdo = $dbHandler->getConnection();
|
|||||||
<h5>Foto dell'immobile</h5>
|
<h5>Foto dell'immobile</h5>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="photo">Carica Foto</label>
|
<label for="photo">Carica Foto</label>
|
||||||
<input type="file" id="photo" name="photo" class="form-control" accept="image/*">
|
<input type="file" id="photo" name="photo" class="form-control" accept="image/*" readonly disabled>
|
||||||
<small class="text-muted">Carica un'unica foto, verrà sovrascritta se ne scegli un'altra.</small>
|
<small class="text-muted">Carica un'unica foto, verrà sovrascritta se ne scegli un'altra.</small>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
@ -115,27 +137,27 @@ $pdo = $dbHandler->getConnection();
|
|||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-6 form-group">
|
<div class="col-md-6 form-group">
|
||||||
<label>Comune Catastale</label>
|
<label>Comune Catastale</label>
|
||||||
<input type="text" id="cadastral_municipality" name="cadastral_municipality" value="<?php echo htmlspecialchars($cadastral_municipalitydb); ?>" class="form-control">
|
<input type="text" id="cadastral_municipality" name="cadastral_municipality" value="<?php echo htmlspecialchars($cadastral_municipalitydb); ?>" class="form-control" readonly>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-md-6 form-group">
|
<div class="col-md-6 form-group">
|
||||||
<label>Sezione Catastale</label>
|
<label>Sezione Catastale</label>
|
||||||
<input type="text" id="cadastral_section" name="cadastral_section" value="<?php echo htmlspecialchars($cadastral_sectiondb); ?>" class="form-control">
|
<input type="text" id="cadastral_section" name="cadastral_section" value="<?php echo htmlspecialchars($cadastral_sectiondb); ?>" class="form-control" readonly>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-6 form-group">
|
<div class="col-md-6 form-group">
|
||||||
<label>Foglio Catastale</label>
|
<label>Foglio Catastale</label>
|
||||||
<input type="text" id="cadastral_sheet" name="cadastral_sheet" value="<?php echo htmlspecialchars($cadastral_sheetdb); ?>" class="form-control">
|
<input type="text" id="cadastral_sheet" name="cadastral_sheet" value="<?php echo htmlspecialchars($cadastral_sheetdb); ?>" class="form-control" readonly>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-md-6 form-group">
|
<div class="col-md-6 form-group">
|
||||||
<label>Particella Catastale</label>
|
<label>Particella Catastale</label>
|
||||||
<input type="text" id="cadastral_particle" name="cadastral_particle" value="<?php echo htmlspecialchars($cadastral_particledb); ?>" class="form-control">
|
<input type="text" id="cadastral_particle" name="cadastral_particle" value="<?php echo htmlspecialchars($cadastral_particledb); ?>" class="form-control" readonly>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-6 form-group">
|
<div class="col-md-6 form-group">
|
||||||
<label>Subalterno Catastale</label>
|
<label>Subalterno Catastale</label>
|
||||||
<input type="text" id="cadastral_sub" name="cadastral_sub" value="<?php echo htmlspecialchars($cadastral_subdb); ?>" class="form-control">
|
<input type="text" id="cadastral_sub" name="cadastral_sub" value="<?php echo htmlspecialchars($cadastral_subdb); ?>" class="form-control" readonly>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -143,21 +165,21 @@ $pdo = $dbHandler->getConnection();
|
|||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-6 form-group">
|
<div class="col-md-6 form-group">
|
||||||
<label>Categoria Catastale</label>
|
<label>Categoria Catastale</label>
|
||||||
<input type="text" id="cadastral_category" name="cadastral_category" value="<?php echo htmlspecialchars($cadastral_categorydb); ?>" class="form-control">
|
<input type="text" id="cadastral_category" name="cadastral_category" value="<?php echo htmlspecialchars($cadastral_categorydb); ?>" class="form-control" readonly>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-md-6 form-group">
|
<div class="col-md-6 form-group">
|
||||||
<label>Classe Catastale</label>
|
<label>Classe Catastale</label>
|
||||||
<input type="text" id="cadastral_class" name="cadastral_class" value="<?php echo htmlspecialchars($cadastral_classdb); ?>" class="form-control">
|
<input type="text" id="cadastral_class" name="cadastral_class" value="<?php echo htmlspecialchars($cadastral_classdb); ?>" class="form-control" readonly>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-6 form-group">
|
<div class="col-md-6 form-group">
|
||||||
<label>Superficie Catastale (m²)</label>
|
<label>Superficie Catastale (m²)</label>
|
||||||
<input type="number" step="0.01" id="cadastral_surface" name="cadastral_surface" value="<?php echo htmlspecialchars($cadastral_surfacedb); ?>" class="form-control">
|
<input type="number" step="0.01" id="cadastral_surface" name="cadastral_surface" value="<?php echo htmlspecialchars($cadastral_surfacedb); ?>" class="form-control" readonly>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-md-6 form-group">
|
<div class="col-md-6 form-group">
|
||||||
<label>Rendita Catastale (€)</label>
|
<label>Rendita Catastale (€)</label>
|
||||||
<input type="text" id="cadastral_rendita" name="cadastral_rendita" value="<?php echo htmlspecialchars($cadastral_renditadb); ?>" class="form-control">
|
<input type="text" id="cadastral_rendita" name="cadastral_rendita" value="<?php echo htmlspecialchars($cadastral_renditadb); ?>" class="form-control" readonly>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -176,7 +198,10 @@ $pdo = $dbHandler->getConnection();
|
|||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-6 form-group">
|
<div class="col-md-6 form-group">
|
||||||
<label>Nazione</label>
|
<label>Nazione</label>
|
||||||
<input type="text" id="country" name="country" value="<?php echo htmlspecialchars($countrydb); ?>" class="form-control" readonly>
|
<select id="country" name="country" class="form-control">
|
||||||
|
<option value="<?php echo htmlspecialchars($countrydb); ?>" selected><?php echo htmlspecialchars($countrydb); ?></option>
|
||||||
|
<!-- Aggiungi altre opzioni se necessario -->
|
||||||
|
</select>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
@ -195,12 +220,15 @@ $pdo = $dbHandler->getConnection();
|
|||||||
<script>
|
<script>
|
||||||
// Gestione caricamento foto
|
// Gestione caricamento foto
|
||||||
document.getElementById('photo').addEventListener('change', function(event) {
|
document.getElementById('photo').addEventListener('change', function(event) {
|
||||||
|
if (document.getElementById('lock-btn').dataset.locked === 'true') {
|
||||||
|
alert('Devi sbloccare la modifica prima di caricare una foto.');
|
||||||
|
this.value = '';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
let file = event.target.files[0];
|
let file = event.target.files[0];
|
||||||
if (!file) return;
|
if (!file) return;
|
||||||
|
|
||||||
const loadingOverlay = document.getElementById('loading-overlay');
|
|
||||||
loadingOverlay.style.display = 'flex';
|
|
||||||
|
|
||||||
let formData = new FormData();
|
let formData = new FormData();
|
||||||
formData.append("photo", file);
|
formData.append("photo", file);
|
||||||
formData.append("idhome", <?php echo $idhome; ?>);
|
formData.append("idhome", <?php echo $idhome; ?>);
|
||||||
@ -209,11 +237,12 @@ $pdo = $dbHandler->getConnection();
|
|||||||
xhr.open("POST", "save-home.php", true);
|
xhr.open("POST", "save-home.php", true);
|
||||||
xhr.onreadystatechange = function() {
|
xhr.onreadystatechange = function() {
|
||||||
if (xhr.readyState === XMLHttpRequest.DONE) {
|
if (xhr.readyState === XMLHttpRequest.DONE) {
|
||||||
loadingOverlay.style.display = 'none';
|
|
||||||
let response = JSON.parse(xhr.responseText);
|
let response = JSON.parse(xhr.responseText);
|
||||||
if (response.success) {
|
if (response.success) {
|
||||||
document.getElementById('photo-preview').src = "mainphoto/" + response.filename;
|
document.getElementById('photo-preview').src = "mainphoto/" + response.filename;
|
||||||
showSaveMessage("Foto caricata con successo!", "success");
|
showSaveMessage("Foto caricata con successo!", "success");
|
||||||
|
document.getElementById('photo').value = '';
|
||||||
|
document.getElementById('photo').classList.add('input-flash');
|
||||||
} else {
|
} else {
|
||||||
showSaveMessage("Errore nel caricamento della foto: " + response.message, "danger");
|
showSaveMessage("Errore nel caricamento della foto: " + response.message, "danger");
|
||||||
}
|
}
|
||||||
@ -225,64 +254,117 @@ $pdo = $dbHandler->getConnection();
|
|||||||
// Funzione per mostrare il messaggio di salvataggio
|
// Funzione per mostrare il messaggio di salvataggio
|
||||||
function showSaveMessage(message, type) {
|
function showSaveMessage(message, type) {
|
||||||
const saveMessage = document.getElementById('save-message');
|
const saveMessage = document.getElementById('save-message');
|
||||||
saveMessage.className = `alert alert-${type} d-block`;
|
saveMessage.className = `alert alert-${type} d-block save-flash`;
|
||||||
saveMessage.textContent = message;
|
saveMessage.textContent = message;
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
saveMessage.className = 'alert d-none';
|
saveMessage.className = 'alert d-none';
|
||||||
}, 3000);
|
}, 3000);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Gestione tasto Salva con spinner
|
// Gestione lucchetto e modalità modifica
|
||||||
document.getElementById('save-form-btn').addEventListener('click', function() {
|
document.getElementById('lock-btn').addEventListener('click', function() {
|
||||||
const loadingOverlay = document.getElementById('loading-overlay');
|
const isLocked = this.dataset.locked === 'true';
|
||||||
loadingOverlay.style.display = 'flex';
|
|
||||||
this.disabled = true;
|
|
||||||
|
|
||||||
const form = document.getElementById('home-form');
|
if (isLocked) {
|
||||||
const fields = [
|
Swal.fire({
|
||||||
'name', 'comment', 'fulladdress',
|
title: 'Conferma',
|
||||||
'cadastral_municipality', 'cadastral_section', 'cadastral_sheet', 'cadastral_particle', 'cadastral_sub',
|
text: 'Vuoi procedere alla modifica dei dati?',
|
||||||
'cadastral_category', 'cadastral_class', 'cadastral_surface', 'cadastral_rendita',
|
icon: 'warning',
|
||||||
'latitude', 'longitude', 'zip', 'city', 'country', 'address'
|
showCancelButton: true,
|
||||||
];
|
confirmButtonColor: '#28a745',
|
||||||
|
cancelButtonColor: '#d33',
|
||||||
|
confirmButtonText: 'Sì, modifica',
|
||||||
|
cancelButtonText: 'Annulla'
|
||||||
|
}).then((result) => {
|
||||||
|
if (result.isConfirmed) {
|
||||||
|
this.classList.remove('locked');
|
||||||
|
this.classList.add('unlocked');
|
||||||
|
this.innerHTML = '<i class="fas fa-lock-open"></i>';
|
||||||
|
this.dataset.locked = 'false';
|
||||||
|
|
||||||
// Raccogli i dati del form
|
// Rendi i campi editabili
|
||||||
let params = `idhome=${encodeURIComponent(<?php echo $idhome; ?>)}`;
|
document.querySelectorAll('input:not(#country), textarea').forEach(element => {
|
||||||
fields.forEach(field => {
|
element.removeAttribute('readonly');
|
||||||
const value = document.getElementById(field)?.value || '';
|
element.removeAttribute('disabled');
|
||||||
params += `&${field}=${encodeURIComponent(value)}`;
|
});
|
||||||
});
|
|
||||||
|
|
||||||
// Invia i dati tramite AJAX
|
|
||||||
const xhr = new XMLHttpRequest();
|
|
||||||
xhr.open("POST", "save-home.php", true);
|
|
||||||
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
|
|
||||||
|
|
||||||
xhr.onreadystatechange = function() {
|
|
||||||
if (xhr.readyState === XMLHttpRequest.DONE) {
|
|
||||||
loadingOverlay.style.display = 'none';
|
|
||||||
document.getElementById('save-form-btn').disabled = false;
|
|
||||||
|
|
||||||
if (xhr.status === 200) {
|
|
||||||
let response;
|
|
||||||
try {
|
|
||||||
response = JSON.parse(xhr.responseText);
|
|
||||||
} catch (e) {
|
|
||||||
showSaveMessage("Errore: Risposta non valida dal server.", "danger");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (response.success) {
|
|
||||||
showSaveMessage("Modifiche salvate con successo!", "success");
|
|
||||||
} else {
|
|
||||||
showSaveMessage("Errore durante il salvataggio: " + response.message, "danger");
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
showSaveMessage("Errore di connessione: " + xhr.statusText, "danger");
|
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
};
|
} else {
|
||||||
|
Swal.fire({
|
||||||
|
title: 'Conferma',
|
||||||
|
text: 'Vuoi bloccare le modifiche e salvare i dati?',
|
||||||
|
icon: 'warning',
|
||||||
|
showCancelButton: true,
|
||||||
|
confirmButtonColor: '#dc3545',
|
||||||
|
cancelButtonColor: '#3085d6',
|
||||||
|
confirmButtonText: 'Sì, blocca',
|
||||||
|
cancelButtonText: 'Annulla'
|
||||||
|
}).then((result) => {
|
||||||
|
if (result.isConfirmed) {
|
||||||
|
this.classList.remove('unlocked');
|
||||||
|
this.classList.add('locked');
|
||||||
|
this.innerHTML = '<i class="fas fa-lock"></i>';
|
||||||
|
this.dataset.locked = 'true';
|
||||||
|
|
||||||
xhr.send(params);
|
// Rendi i campi read-only
|
||||||
|
document.querySelectorAll('input:not(#country), textarea').forEach(element => {
|
||||||
|
element.setAttribute('readonly', true);
|
||||||
|
if (element.type === 'file') element.setAttribute('disabled', true);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Salvataggio automatico al cambio di un campo
|
||||||
|
const fields = [
|
||||||
|
'name', 'comment', 'fulladdress',
|
||||||
|
'cadastral_municipality', 'cadastral_section', 'cadastral_sheet', 'cadastral_particle', 'cadastral_sub',
|
||||||
|
'cadastral_category', 'cadastral_class', 'cadastral_surface', 'cadastral_rendita',
|
||||||
|
'latitude', 'longitude', 'zip', 'city', 'country'
|
||||||
|
];
|
||||||
|
|
||||||
|
fields.forEach(field => {
|
||||||
|
const element = document.getElementById(field);
|
||||||
|
if (element) {
|
||||||
|
element.addEventListener('change', function() {
|
||||||
|
if (field !== 'country' && document.getElementById('lock-btn').dataset.locked === 'true') return;
|
||||||
|
|
||||||
|
let params = `idhome=${encodeURIComponent(<?php echo $idhome; ?>)}`;
|
||||||
|
fields.forEach(f => {
|
||||||
|
const value = document.getElementById(f)?.value || '';
|
||||||
|
params += `&${f}=${encodeURIComponent(value)}`;
|
||||||
|
});
|
||||||
|
|
||||||
|
const xhr = new XMLHttpRequest();
|
||||||
|
xhr.open("POST", "save-home.php", true);
|
||||||
|
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
|
||||||
|
|
||||||
|
xhr.onreadystatechange = function() {
|
||||||
|
if (xhr.readyState === XMLHttpRequest.DONE) {
|
||||||
|
if (xhr.status === 200) {
|
||||||
|
let response;
|
||||||
|
try {
|
||||||
|
response = JSON.parse(xhr.responseText);
|
||||||
|
} catch (e) {
|
||||||
|
showSaveMessage("Errore: Risposta non valida dal server.", "danger");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (response.success) {
|
||||||
|
showSaveMessage("Modifiche salvate con successo!", "success");
|
||||||
|
element.classList.add('input-flash');
|
||||||
|
} else {
|
||||||
|
showSaveMessage("Errore durante il salvataggio: " + response.message, "danger");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
showSaveMessage("Errore di connessione: " + xhr.statusText, "danger");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
xhr.send(params);
|
||||||
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Gestione mappa
|
// Gestione mappa
|
||||||
@ -313,9 +395,12 @@ $pdo = $dbHandler->getConnection();
|
|||||||
});
|
});
|
||||||
|
|
||||||
google.maps.event.addListener(marker, 'dragend', function() {
|
google.maps.event.addListener(marker, 'dragend', function() {
|
||||||
|
if (document.getElementById('lock-btn').dataset.locked === 'true') return;
|
||||||
|
|
||||||
const position = marker.getPosition();
|
const position = marker.getPosition();
|
||||||
document.getElementById('latitude').value = position.lat();
|
document.getElementById('latitude').value = position.lat();
|
||||||
document.getElementById('longitude').value = position.lng();
|
document.getElementById('longitude').value = position.lng();
|
||||||
|
document.getElementById('latitude').dispatchEvent(new Event('change'));
|
||||||
});
|
});
|
||||||
|
|
||||||
autocomplete = new google.maps.places.Autocomplete(document.getElementById('fulladdress'), {
|
autocomplete = new google.maps.places.Autocomplete(document.getElementById('fulladdress'), {
|
||||||
@ -325,6 +410,8 @@ $pdo = $dbHandler->getConnection();
|
|||||||
}
|
}
|
||||||
|
|
||||||
function fillInAddress() {
|
function fillInAddress() {
|
||||||
|
if (document.getElementById('lock-btn').dataset.locked === 'true') return;
|
||||||
|
|
||||||
const place = autocomplete.getPlace();
|
const place = autocomplete.getPlace();
|
||||||
if (!place.geometry) {
|
if (!place.geometry) {
|
||||||
console.error("Errore: Il luogo selezionato non contiene informazioni di geolocalizzazione.");
|
console.error("Errore: Il luogo selezionato non contiene informazioni di geolocalizzazione.");
|
||||||
@ -333,12 +420,8 @@ $pdo = $dbHandler->getConnection();
|
|||||||
|
|
||||||
const location = place.geometry.location;
|
const location = place.geometry.location;
|
||||||
|
|
||||||
if (document.getElementById('latitude')) {
|
document.getElementById('latitude').value = location.lat();
|
||||||
document.getElementById('latitude').value = location.lat();
|
document.getElementById('longitude').value = location.lng();
|
||||||
}
|
|
||||||
if (document.getElementById('longitude')) {
|
|
||||||
document.getElementById('longitude').value = location.lng();
|
|
||||||
}
|
|
||||||
|
|
||||||
const addressComponents = place.address_components;
|
const addressComponents = place.address_components;
|
||||||
let zip = "",
|
let zip = "",
|
||||||
@ -356,20 +439,16 @@ $pdo = $dbHandler->getConnection();
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (document.getElementById('zip')) {
|
document.getElementById('zip').value = zip;
|
||||||
document.getElementById('zip').value = zip;
|
document.getElementById('city').value = city;
|
||||||
}
|
document.getElementById('country').value = country;
|
||||||
if (document.getElementById('city')) {
|
document.getElementById('fulladdress').value = address.trim();
|
||||||
document.getElementById('city').value = city;
|
|
||||||
}
|
|
||||||
if (document.getElementById('country')) {
|
|
||||||
document.getElementById('country').value = country;
|
|
||||||
}
|
|
||||||
if (document.getElementById('address')) {
|
|
||||||
document.getElementById('address').value = address.trim();
|
|
||||||
}
|
|
||||||
|
|
||||||
map.setCenter(location);
|
map.setCenter(location);
|
||||||
marker.setPosition(location);
|
marker.setPosition(location);
|
||||||
|
document.getElementById('fulladdress').dispatchEvent(new Event('change'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Inizializza la mappa quando il DOM è pronto
|
||||||
|
document.addEventListener('DOMContentLoaded', initAutocomplete);
|
||||||
</script>
|
</script>
|
||||||
@ -22,6 +22,10 @@ while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
|
|||||||
|
|
||||||
// Imposta lo slug predefinito
|
// Imposta lo slug predefinito
|
||||||
$docpage = isset($_GET['docpage']) ? $_GET['docpage'] : 'legal';
|
$docpage = isset($_GET['docpage']) ? $_GET['docpage'] : 'legal';
|
||||||
|
|
||||||
|
// Recupera tutti i tag disponibili
|
||||||
|
$stmt = $pdo->query("SELECT tag_id, tag_name FROM tags ORDER BY tag_name");
|
||||||
|
$allTags = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||||
?>
|
?>
|
||||||
|
|
||||||
<!-- Contenuto del tab Documenti -->
|
<!-- Contenuto del tab Documenti -->
|
||||||
@ -64,9 +68,9 @@ $docpage = isset($_GET['docpage']) ? $_GET['docpage'] : 'legal';
|
|||||||
$name = ucfirst(htmlspecialchars($page['namepages']));
|
$name = ucfirst(htmlspecialchars($page['namepages']));
|
||||||
$iconClass = getCategoryIcon($index);
|
$iconClass = getCategoryIcon($index);
|
||||||
echo "<div class='category-icon' data-slug='{$slug}' data-index='{$index}'>
|
echo "<div class='category-icon' data-slug='{$slug}' data-index='{$index}'>
|
||||||
<i class='{$iconClass}'></i>
|
<i class='{$iconClass}'></i>
|
||||||
<div class='category-name'>{$name}</div>
|
<div class='category-name'>{$name}</div>
|
||||||
</div>";
|
</div>";
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
</div>
|
</div>
|
||||||
@ -78,12 +82,33 @@ $docpage = isset($_GET['docpage']) ? $_GET['docpage'] : 'legal';
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<!-- Campo di ricerca e checkbox -->
|
<!-- Campo di ricerca per nome/sezione, tag e checkbox -->
|
||||||
<div class="col-12">
|
<div class="col-12">
|
||||||
<div class="position-relative mt-3">
|
<div class="row">
|
||||||
<label for="documentSearch" class="form-label mb-1 fw-bold">Cerca:</label>
|
<!-- Campo di ricerca per nome/sezione -->
|
||||||
<input type="text" id="documentSearch" class="form-control w-100" placeholder="Sezione o documento..." autocomplete="off">
|
<div class="col-md-6 position-relative mt-3">
|
||||||
<div id="searchResults" class="list-group dropdown-menu show w-100" style="position: absolute; max-height: 200px; overflow-y: auto; z-index: 1000; display: none;"></div>
|
<label for="documentSearch" class="form-label mb-1 fw-bold">Cerca per nome o sezione:</label>
|
||||||
|
<input type="text" id="documentSearch" class="form-control w-100" placeholder="Sezione o documento..." autocomplete="off">
|
||||||
|
<div id="searchResults" class="list-group dropdown-menu show w-100" style="position: absolute; max-height: 200px; overflow-y: auto; z-index: 1000; display: none;"></div>
|
||||||
|
</div>
|
||||||
|
<!-- Dropdown per i tag -->
|
||||||
|
<div class="col-md-6 position-relative mt-3">
|
||||||
|
<label class="form-label mb-1 fw-bold">Filtra per tag:</label>
|
||||||
|
<div class="dropdown">
|
||||||
|
<button class="btn btn-outline-secondary dropdown-toggle w-100" type="button" id="tagDropdown" data-bs-toggle="dropdown" aria-expanded="false">
|
||||||
|
Seleziona tag...
|
||||||
|
</button>
|
||||||
|
<div class="dropdown-menu w-100" aria-labelledby="tagDropdown">
|
||||||
|
<?php foreach ($allTags as $tag): ?>
|
||||||
|
<a class="dropdown-item tag-option" href="#" data-tag-id="<?php echo $tag['tag_id']; ?>" data-tag-name="<?php echo htmlspecialchars($tag['tag_name']); ?>">
|
||||||
|
<?php echo htmlspecialchars($tag['tag_name']); ?>
|
||||||
|
</a>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<!-- Contenitore per i badge selezionati -->
|
||||||
|
<div id="selectedTags" class="d-flex flex-wrap gap-2 mt-2"></div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<!-- Checkbox -->
|
<!-- Checkbox -->
|
||||||
<div class="form-check form-switch mt-2">
|
<div class="form-check form-switch mt-2">
|
||||||
@ -239,14 +264,42 @@ $docpage = isset($_GET['docpage']) ? $_GET['docpage'] : 'legal';
|
|||||||
background-color: #f1f3f5;
|
background-color: #f1f3f5;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Stile per il dropdown dei tag */
|
||||||
|
.dropdown-menu {
|
||||||
|
max-height: 200px;
|
||||||
|
overflow-y: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tag-option:hover {
|
||||||
|
background-color: #f1f3f5;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Stile per i badge selezionati */
|
||||||
|
#selectedTags .tag-badge {
|
||||||
|
background-color: #e6f0fa;
|
||||||
|
/* Colore chiaro per i badge selezionati */
|
||||||
|
color: #2c3e50;
|
||||||
|
font-size: 0.9rem;
|
||||||
|
padding: 0.4em 0.8em;
|
||||||
|
border-radius: 10px;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
margin-bottom: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#selectedTags .tag-badge .remove-tag {
|
||||||
|
font-size: 0.7rem;
|
||||||
|
margin-left: 5px;
|
||||||
|
cursor: pointer;
|
||||||
|
color: #dc3545;
|
||||||
|
}
|
||||||
|
|
||||||
/* Stile per il titolo del documento */
|
/* Stile per il titolo del documento */
|
||||||
.document-title {
|
.document-title {
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
/* Grassetto per maggiore risalto */
|
|
||||||
font-size: 1.1rem;
|
font-size: 1.1rem;
|
||||||
/* Aumenta leggermente la dimensione */
|
|
||||||
color: #2c3e50;
|
color: #2c3e50;
|
||||||
/* Colore scuro per contrasto */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Stile per il preloader */
|
/* Stile per il preloader */
|
||||||
@ -307,7 +360,11 @@ $docpage = isset($_GET['docpage']) ? $_GET['docpage'] : 'legal';
|
|||||||
|
|
||||||
.document-title {
|
.document-title {
|
||||||
font-size: 1rem;
|
font-size: 1rem;
|
||||||
/* Riduci leggermente su mobile */
|
}
|
||||||
|
|
||||||
|
.tag-badge {
|
||||||
|
font-size: 0.8rem;
|
||||||
|
padding: 0.3em 0.6em;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
@ -317,9 +374,9 @@ $docpage = isset($_GET['docpage']) ? $_GET['docpage'] : 'legal';
|
|||||||
let idhome = <?php echo $idhome; ?>;
|
let idhome = <?php echo $idhome; ?>;
|
||||||
let currentCategory = '<?php echo $docpage; ?>';
|
let currentCategory = '<?php echo $docpage; ?>';
|
||||||
let currentSection = null;
|
let currentSection = null;
|
||||||
|
let selectedTags = []; // Array per tenere traccia dei tag selezionati
|
||||||
|
|
||||||
// Caricamento iniziale: non carichiamo documenti finché non selezioniamo una sezione
|
// Caricamento iniziale: non carichiamo documenti finché non selezioniamo una categoria o cerchiamo
|
||||||
// loadDocuments(currentCategory); // Rimuoviamo questa chiamata
|
|
||||||
|
|
||||||
// Gestione del clic sulle icone delle categorie
|
// Gestione del clic sulle icone delle categorie
|
||||||
$('.category-icon').on('click', function() {
|
$('.category-icon').on('click', function() {
|
||||||
@ -331,29 +388,29 @@ $docpage = isset($_GET['docpage']) ? $_GET['docpage'] : 'legal';
|
|||||||
$('.category-icon').removeClass('active');
|
$('.category-icon').removeClass('active');
|
||||||
$(this).addClass('active');
|
$(this).addClass('active');
|
||||||
$('.section-icons-container').hide().empty();
|
$('.section-icons-container').hide().empty();
|
||||||
$('#documentSections').empty(); // Svuota i documenti quando selezioni una categoria
|
$('#documentSections').empty();
|
||||||
$('.preloader').show(); // Mostra il preloader
|
$('.preloader').show();
|
||||||
loadSections(slug);
|
loadSections(slug);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Gestione del clic sulle icone delle sezioni
|
// Gestione del clic sulle icone delle sezioni
|
||||||
$(document).on('click', '.section-icon', function() {
|
$(document).on('click', '.section-icon', function() {
|
||||||
const sectionId = $(this).data('section-id');
|
const sectionId = $(this).data('section-id');
|
||||||
const sectionName = $(this).find('.section-name').text(); // Recupera il nome della sezione
|
const sectionName = $(this).find('.section-name').text();
|
||||||
if (currentSection === sectionId) return;
|
if (currentSection === sectionId) return;
|
||||||
|
|
||||||
currentSection = sectionId;
|
currentSection = sectionId;
|
||||||
$('.section-icon').removeClass('active');
|
$('.section-icon').removeClass('active');
|
||||||
$(this).addClass('active');
|
$(this).addClass('active');
|
||||||
$('.document-preloader').show(); // Mostra il preloader per i documenti
|
$('.document-preloader').show();
|
||||||
loadDocuments(currentCategory, sectionId, sectionName); // Carica i documenti della sezione
|
loadDocuments(currentCategory, sectionId, sectionName);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Gestione del checkbox "Solo obbligatori"
|
// Gestione del checkbox "Solo obbligatori"
|
||||||
$("#showOnlyRequired").on('change', function() {
|
$("#showOnlyRequired").on('change', function() {
|
||||||
if (currentSection) { // Carica solo se una sezione è selezionata
|
if (currentSection) {
|
||||||
const sectionName = $('.section-icon.active .section-name').text();
|
const sectionName = $('.section-icon.active .section-name').text();
|
||||||
$('.document-preloader').show(); // Mostra il preloader
|
$('.document-preloader').show();
|
||||||
loadDocuments(currentCategory, currentSection, sectionName);
|
loadDocuments(currentCategory, currentSection, sectionName);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -369,7 +426,7 @@ $docpage = isset($_GET['docpage']) ? $_GET['docpage'] : 'legal';
|
|||||||
},
|
},
|
||||||
dataType: 'json',
|
dataType: 'json',
|
||||||
success: function(response) {
|
success: function(response) {
|
||||||
$('.preloader').hide(); // Nascondi il preloader
|
$('.preloader').hide();
|
||||||
if (response.error) {
|
if (response.error) {
|
||||||
console.error(response.error);
|
console.error(response.error);
|
||||||
return;
|
return;
|
||||||
@ -385,7 +442,7 @@ $docpage = isset($_GET['docpage']) ? $_GET['docpage'] : 'legal';
|
|||||||
$('.section-icons-container').html(html).slideDown();
|
$('.section-icons-container').html(html).slideDown();
|
||||||
},
|
},
|
||||||
error: function(xhr, status, error) {
|
error: function(xhr, status, error) {
|
||||||
$('.preloader').hide(); // Nascondi il preloader in caso di errore
|
$('.preloader').hide();
|
||||||
console.error('Errore nel caricamento delle sezioni:', error);
|
console.error('Errore nel caricamento delle sezioni:', error);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -395,23 +452,28 @@ $docpage = isset($_GET['docpage']) ? $_GET['docpage'] : 'legal';
|
|||||||
let allDocuments = [];
|
let allDocuments = [];
|
||||||
<?php
|
<?php
|
||||||
$stmt = $pdo->query("
|
$stmt = $pdo->query("
|
||||||
SELECT d.document_id, d.document_name, p.slug, s.section_name
|
SELECT d.document_id, d.document_name, p.slug, s.section_name, GROUP_CONCAT(t.tag_name) AS tags
|
||||||
FROM documents d
|
FROM documents d
|
||||||
LEFT JOIN sections s ON d.idsections = s.idsections
|
LEFT JOIN sections s ON d.idsections = s.idsections
|
||||||
LEFT JOIN pages p ON d.page_id = p.idpages
|
LEFT JOIN pages p ON d.page_id = p.idpages
|
||||||
|
LEFT JOIN document_tags dt ON d.document_id = dt.document_id
|
||||||
|
LEFT JOIN tags t ON dt.tag_id = t.tag_id
|
||||||
|
GROUP BY d.document_id, d.document_name, p.slug, s.section_name
|
||||||
ORDER BY s.section_name, d.document_name
|
ORDER BY s.section_name, d.document_name
|
||||||
");
|
");
|
||||||
while ($doc = $stmt->fetch(PDO::FETCH_ASSOC)) {
|
while ($doc = $stmt->fetch(PDO::FETCH_ASSOC)) {
|
||||||
|
$tags = $doc['tags'] ? addslashes(htmlspecialchars($doc['tags'])) : '';
|
||||||
echo "allDocuments.push({
|
echo "allDocuments.push({
|
||||||
id: '{$doc['document_id']}',
|
id: '{$doc['document_id']}',
|
||||||
name: '" . addslashes(htmlspecialchars($doc['document_name'])) . "',
|
name: '" . addslashes(htmlspecialchars($doc['document_name'])) . "',
|
||||||
section: '" . addslashes(htmlspecialchars($doc['section_name'])) . "',
|
section: '" . addslashes(htmlspecialchars($doc['section_name'])) . "',
|
||||||
slug: '" . addslashes(htmlspecialchars($doc['slug'])) . "'
|
slug: '" . addslashes(htmlspecialchars($doc['slug'])) . "',
|
||||||
|
tags: '{$tags}'
|
||||||
});\n";
|
});\n";
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
|
||||||
// Gestione della ricerca dinamica
|
// Gestione della ricerca dinamica per nome/sezione
|
||||||
$('#documentSearch').on('input', function() {
|
$('#documentSearch').on('input', function() {
|
||||||
const searchTerm = $(this).val().toLowerCase().trim();
|
const searchTerm = $(this).val().toLowerCase().trim();
|
||||||
$('#searchResults').empty().hide();
|
$('#searchResults').empty().hide();
|
||||||
@ -428,8 +490,8 @@ $docpage = isset($_GET['docpage']) ? $_GET['docpage'] : 'legal';
|
|||||||
if (results.length > 0) {
|
if (results.length > 0) {
|
||||||
let html = '';
|
let html = '';
|
||||||
results.forEach(result => {
|
results.forEach(result => {
|
||||||
html += `<a href="#" class="list-group-item list-group-item-action" data-slug="${result.slug}" data-section="${md5(result.section)}">
|
html += `<a href="#" class="list-group-item list-group-item-action" data-slug="${result.slug}" data-section="${md5(result.section)}" data-name="${result.name}">
|
||||||
${result.name} (Sezione: ${result.section})
|
${result.name} (Sezione: ${result.section}${result.tags ? ', Tag: ' + result.tags : ''})
|
||||||
</a>`;
|
</a>`;
|
||||||
});
|
});
|
||||||
$('#searchResults').html(html).show();
|
$('#searchResults').html(html).show();
|
||||||
@ -438,33 +500,69 @@ $docpage = isset($_GET['docpage']) ? $_GET['docpage'] : 'legal';
|
|||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
const slug = $(this).data('slug');
|
const slug = $(this).data('slug');
|
||||||
const sectionId = $(this).data('section');
|
const sectionId = $(this).data('section');
|
||||||
|
const documentName = $(this).data('name');
|
||||||
|
|
||||||
currentCategory = slug;
|
currentCategory = slug;
|
||||||
currentSection = sectionId;
|
currentSection = sectionId;
|
||||||
$('.category-icon').removeClass('active');
|
$('.category-icon').removeClass('active');
|
||||||
$('.category-icon[data-slug="' + slug + '"]').addClass('active');
|
$('.category-icon[data-slug="' + slug + '"]').addClass('active');
|
||||||
$('.section-icons-container').hide().empty();
|
$('.section-icons-container').hide().empty();
|
||||||
$('.preloader').show(); // Mostra il preloader durante la ricerca
|
$('#documentSections').empty();
|
||||||
loadSections(slug);
|
$('.document-preloader').show();
|
||||||
|
|
||||||
|
// Carica direttamente i documenti senza passare per le sezioni
|
||||||
|
loadDocuments(slug, sectionId, null, documentName);
|
||||||
|
|
||||||
$('#documentSearch').val('');
|
$('#documentSearch').val('');
|
||||||
$('#searchResults').hide();
|
$('#searchResults').hide();
|
||||||
|
|
||||||
// Trova il nome della sezione e carica i documenti
|
|
||||||
setTimeout(() => {
|
|
||||||
const sectionElement = $(`.section-icon[data-section-id="${sectionId}"]`);
|
|
||||||
if (sectionElement.length) {
|
|
||||||
$('.section-icon').removeClass('active');
|
|
||||||
sectionElement.addClass('active');
|
|
||||||
const sectionName = sectionElement.find('.section-name').text();
|
|
||||||
$('.document-preloader').show(); // Mostra il preloader
|
|
||||||
loadDocuments(slug, sectionId, sectionName);
|
|
||||||
}
|
|
||||||
}, 500);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Gestione del dropdown dei tag
|
||||||
|
$('.tag-option').on('click', function(e) {
|
||||||
|
e.preventDefault();
|
||||||
|
const tagId = $(this).data('tag-id');
|
||||||
|
const tagName = $(this).data('tag-name');
|
||||||
|
|
||||||
|
if (!selectedTags.some(t => t.id === tagId)) {
|
||||||
|
selectedTags.push({
|
||||||
|
id: tagId,
|
||||||
|
name: tagName
|
||||||
|
});
|
||||||
|
updateSelectedTags();
|
||||||
|
if (currentSection) {
|
||||||
|
const sectionName = $('.section-icon.active .section-name').text();
|
||||||
|
$('.document-preloader').show();
|
||||||
|
loadDocuments(currentCategory, currentSection, sectionName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Funzione per aggiornare i badge dei tag selezionati
|
||||||
|
function updateSelectedTags() {
|
||||||
|
$('#selectedTags').empty();
|
||||||
|
selectedTags.forEach(tag => {
|
||||||
|
$('#selectedTags').append(`
|
||||||
|
<span class="tag-badge">
|
||||||
|
${tag.name}
|
||||||
|
<span class="remove-tag" data-tag-id="${tag.id}">×</span>
|
||||||
|
</span>
|
||||||
|
`);
|
||||||
|
});
|
||||||
|
$('.remove-tag').on('click', function(e) {
|
||||||
|
e.preventDefault();
|
||||||
|
const tagId = $(this).data('tag-id');
|
||||||
|
selectedTags = selectedTags.filter(t => t.id !== tagId);
|
||||||
|
updateSelectedTags();
|
||||||
|
if (currentSection) {
|
||||||
|
const sectionName = $('.section-icon.active .section-name').text();
|
||||||
|
$('.document-preloader').show();
|
||||||
|
loadDocuments(currentCategory, currentSection, sectionName);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// Chiudi i risultati della ricerca se clicchi fuori
|
// Chiudi i risultati della ricerca se clicchi fuori
|
||||||
$(document).on('click', function(e) {
|
$(document).on('click', function(e) {
|
||||||
if (!$(e.target).closest('.input-group, #searchResults').length) {
|
if (!$(e.target).closest('.input-group, #searchResults').length) {
|
||||||
@ -472,8 +570,9 @@ $docpage = isset($_GET['docpage']) ? $_GET['docpage'] : 'legal';
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
function loadDocuments(slug, targetSectionId = null, sectionName = null) {
|
function loadDocuments(slug, targetSectionId = null, sectionName = null, searchName = null) {
|
||||||
const showOnlyRequired = $("#showOnlyRequired").is(":checked");
|
const showOnlyRequired = $("#showOnlyRequired").is(":checked");
|
||||||
|
const tagIds = selectedTags.map(t => t.id);
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: 'get-documents.php',
|
url: 'get-documents.php',
|
||||||
@ -482,11 +581,13 @@ $docpage = isset($_GET['docpage']) ? $_GET['docpage'] : 'legal';
|
|||||||
slug: slug,
|
slug: slug,
|
||||||
idhome: idhome,
|
idhome: idhome,
|
||||||
showOnlyRequired: showOnlyRequired,
|
showOnlyRequired: showOnlyRequired,
|
||||||
sectionId: targetSectionId ? targetSectionId : null
|
sectionId: targetSectionId ? targetSectionId : null,
|
||||||
|
tags: tagIds.length > 0 ? tagIds.join(',') : null,
|
||||||
|
searchName: searchName ? searchName : null
|
||||||
},
|
},
|
||||||
dataType: 'json',
|
dataType: 'json',
|
||||||
success: function(response) {
|
success: function(response) {
|
||||||
$('.document-preloader').hide(); // Nascondi il preloader
|
$('.document-preloader').hide();
|
||||||
if (response.error) {
|
if (response.error) {
|
||||||
Swal.fire({
|
Swal.fire({
|
||||||
icon: 'error',
|
icon: 'error',
|
||||||
@ -515,7 +616,6 @@ $docpage = isset($_GET['docpage']) ? $_GET['docpage'] : 'legal';
|
|||||||
}
|
}
|
||||||
sectionCount++;
|
sectionCount++;
|
||||||
|
|
||||||
// Usa il nome della sezione passato come parametro
|
|
||||||
const displaySectionName = sectionName || sectionKey;
|
const displaySectionName = sectionName || sectionKey;
|
||||||
|
|
||||||
html += `
|
html += `
|
||||||
@ -540,6 +640,7 @@ $docpage = isset($_GET['docpage']) ? $_GET['docpage'] : 'legal';
|
|||||||
<span class="document-title fw-bold">${document.document_name || 'Documento senza nome'}</span>
|
<span class="document-title fw-bold">${document.document_name || 'Documento senza nome'}</span>
|
||||||
${document.is_required ? '<span class="badge bg-danger ms-2" style="font-size: 1rem; padding: 0.5em 0.8em;">Obbligatorio</span>' : ''}
|
${document.is_required ? '<span class="badge bg-danger ms-2" style="font-size: 1rem; padding: 0.5em 0.8em;">Obbligatorio</span>' : ''}
|
||||||
${document.max_documents > 0 ? `<span class="badge bg-info ms-2" style="font-size: 1rem; padding: 0.5em 0.8em;">Max: ${document.max_documents}</span>` : ''}
|
${document.max_documents > 0 ? `<span class="badge bg-info ms-2" style="font-size: 1rem; padding: 0.5em 0.8em;">Max: ${document.max_documents}</span>` : ''}
|
||||||
|
${document.tags ? `<span class="badge bg-secondary ms-2" style="font-size: 1rem; padding: 0.5em 0.8em;">Tag: ${document.tags}</span>` : ''}
|
||||||
</div>
|
</div>
|
||||||
<button class="btn btn-sm btn-outline-primary toggle-dropzone" data-target="#dropzone-${document.document_id}">
|
<button class="btn btn-sm btn-outline-primary toggle-dropzone" data-target="#dropzone-${document.document_id}">
|
||||||
<i class="fas fa-plus"></i>
|
<i class="fas fa-plus"></i>
|
||||||
@ -602,9 +703,9 @@ $docpage = isset($_GET['docpage']) ? $_GET['docpage'] : 'legal';
|
|||||||
collapseElement.collapse('show');
|
collapseElement.collapse('show');
|
||||||
$('html, body').animate({
|
$('html, body').animate({
|
||||||
scrollTop: collapseElement.offset().top - 100
|
scrollTop: collapseElement.offset().top - 100
|
||||||
}, 500);
|
}, 100);
|
||||||
}
|
}
|
||||||
}, 1000);
|
}, 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Rinizializza Dropzone per ogni documento
|
// Rinizializza Dropzone per ogni documento
|
||||||
@ -877,7 +978,7 @@ $docpage = isset($_GET['docpage']) ? $_GET['docpage'] : 'legal';
|
|||||||
};
|
};
|
||||||
},
|
},
|
||||||
error: function(xhr, status, error) {
|
error: function(xhr, status, error) {
|
||||||
$('.document-preloader').hide(); // Nascondi il preloader in caso di errore
|
$('.document-preloader').hide();
|
||||||
Swal.fire({
|
Swal.fire({
|
||||||
icon: 'error',
|
icon: 'error',
|
||||||
title: 'Errore',
|
title: 'Errore',
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user