fixed products

This commit is contained in:
2025-12-06 20:11:54 +01:00
parent 279bdd615e
commit 8c5b9a0d85
4 changed files with 641 additions and 290 deletions
+194 -63
View File
@@ -221,7 +221,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
?>
<!doctype html>
<html lang="en">
<html lang="it">
<head>
<meta charset="utf-8">
@@ -229,12 +229,29 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
<link rel="icon" href="assets/images/favicon-32x32.png" type="image/png" />
<?php include('cssinclude.php'); ?>
<?php include('siteinfo.php'); ?>
<!-- Leaflet CSS -->
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css"
integrity="sha256-sA+Zcx6cNpCzIvJczQqny0Sg0r7GDL2wMpN4k1kJ0fPQ=" crossorigin="" />
<style>
#map {
height: 350px;
border-radius: 10px;
margin-top: 15px;
box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
}
.geocode-btn {
margin-top: 10px;
}
</style>
</head>
<body>
<div class="wrapper">
<?php include('include/navbar.php'); ?>
<?php include('include/topbar.php'); ?>
<div class="page-wrapper">
<div class="page-content">
<div class="card radius-10">
@@ -242,115 +259,165 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
<h6 class="mb-0"><?php echo $is_new ? 'Crea Profilo Scuola' : 'Profilo Scuola'; ?></h6>
</div>
<div class="card-body">
<?php if (isset($success_message)): ?>
<div class="alert alert-success" role="alert">
<?php echo $success_message; ?>
</div>
<div class="alert alert-success"><?php echo $success_message; ?></div>
<?php endif; ?>
<?php if (isset($error)): ?>
<div class="alert alert-danger" role="alert">
<?php echo $error; ?>
</div>
<div class="alert alert-danger"><?php echo $error; ?></div>
<?php endif; ?>
<form method="POST" enctype="multipart/form-data">
<div class="row">
<!-- Colonna sinistra: logo -->
<div class="col-md-4 text-center">
<div class="mb-3">
<img src="<?php echo $school['logo'] ? htmlspecialchars($school['logo']) : 'photoschool/ndphoto.png'; ?>"
alt="Logo Scuola" class="img-fluid rounded-circle" style="width: 150px; height: 150px; object-fit: cover;">
alt="Logo" class="img-fluid rounded-circle"
style="width:150px;height:150px;object-fit:cover;">
</div>
<div class="mb-3">
<label for="logo" class="form-label">Carica nuovo logo</label>
<input type="file" class="form-control" id="logo" name="logo" accept="image/*">
</div>
</div>
<!-- Colonna destra: tutti i campi -->
<div class="col-md-8">
<!-- Nome, slug, ecc... (tutto invariato fino all'indirizzo) -->
<div class="mb-3">
<label for="name" class="form-label">Nome Scuola</label>
<input type="text" class="form-control" id="name" name="name" value="<?php echo htmlspecialchars($school['name'] ?? ''); ?>" required>
<input type="text" class="form-control" id="name" name="name"
value="<?php echo htmlspecialchars($school['name'] ?? ''); ?>" required>
</div>
<div class="mb-3">
<label for="slug" class="form-label">Slug (URL personalizzato, es. yogiboook.com/slug)</label>
<input type="text" class="form-control" id="slug" name="slug" value="<?php echo htmlspecialchars($school['slug'] ?? ''); ?>" required>
<small class="form-text text-muted">Usa solo lettere minuscole, numeri e trattini (es. yoga-milano).</small>
<label for="slug" class="form-label">Slug (URL personalizzato)</label>
<input type="text" class="form-control" id="slug" name="slug"
value="<?php echo htmlspecialchars($school['slug'] ?? ''); ?>" required>
<small class="text-muted">es. yoga-milano</small>
</div>
<div class="mb-3">
<label for="website" class="form-label">Sito Web</label>
<input type="url" class="form-control" id="website" name="website" value="<?php echo htmlspecialchars($school['website'] ?? ''); ?>">
<input type="url" class="form-control" id="website" name="website"
value="<?php echo htmlspecialchars($school['website'] ?? ''); ?>">
</div>
<div class="mb-3">
<label for="email" class="form-label">Email Scuola</label>
<input type="email" class="form-control" id="email" name="email" value="<?php echo htmlspecialchars($school['email'] ?? ''); ?>" required>
<input type="email" class="form-control" id="email" name="email"
value="<?php echo htmlspecialchars($school['email'] ?? ''); ?>" required>
</div>
<div class="mb-3">
<label for="phone" class="form-label">Telefono</label>
<input type="text" class="form-control" id="phone" name="phone" value="<?php echo htmlspecialchars($school['phone'] ?? ''); ?>">
<input type="text" class="form-control" id="phone" name="phone"
value="<?php echo htmlspecialchars($school['phone'] ?? ''); ?>">
</div>
<div class="mb-3">
<label for="description" class="form-label">Descrizione</label>
<textarea class="form-control" id="description" name="description" rows="3"><?php echo htmlspecialchars($school['description'] ?? ''); ?></textarea>
</div>
<!-- ==================== INIZIO INDIRIZZO + MAPPA ==================== -->
<div class="mb-3">
<label for="address_street" class="form-label">Via</label>
<input type="text" class="form-control" id="address_street" name="address_street" value="<?php echo htmlspecialchars($school['address_street'] ?? ''); ?>">
<label for="address_street" class="form-label">Via / Numero civico</label>
<input type="text" class="form-control" id="address_street" name="address_street"
value="<?php echo htmlspecialchars($school['address_street'] ?? ''); ?>">
</div>
<div class="row">
<div class="col-md-6 mb-3">
<label for="address_city" class="form-label">Città</label>
<input type="text" class="form-control" id="address_city" name="address_city" value="<?php echo htmlspecialchars($school['address_city'] ?? ''); ?>">
<input type="text" class="form-control" id="address_city" name="address_city"
value="<?php echo htmlspecialchars($school['address_city'] ?? ''); ?>">
</div>
<div class="col-md-6 mb-3">
<label for="address_postal_code" class="form-label">CAP</label>
<input type="text" class="form-control" id="address_postal_code" name="address_postal_code" value="<?php echo htmlspecialchars($school['address_postal_code'] ?? ''); ?>">
<input type="text" class="form-control" id="address_postal_code" name="address_postal_code"
value="<?php echo htmlspecialchars($school['address_postal_code'] ?? ''); ?>">
</div>
</div>
<div class="row">
<div class="col-md-6 mb-3">
<label for="address_province" class="form-label">Provincia</label>
<input type="text" class="form-control" id="address_province" name="address_province" value="<?php echo htmlspecialchars($school['address_province'] ?? ''); ?>">
<input type="text" class="form-control" id="address_province" name="address_province"
value="<?php echo htmlspecialchars($school['address_province'] ?? ''); ?>">
</div>
<div class="col-md-6 mb-3">
<label for="address_country" class="form-label">Nazione</label>
<input type="text" class="form-control" id="address_country" name="address_country" value="<?php echo htmlspecialchars($school['address_country'] ?? ''); ?>">
<input type="text" class="form-control" id="address_country" name="address_country"
value="<?php echo htmlspecialchars($school['address_country'] ?? 'Italia'); ?>">
</div>
</div>
<div class="row">
<div class="col-md-6 mb-3">
<!-- Pulsante geocoding -->
<div class="mb-3">
<button type="button" class="btn btn-outline-primary geocode-btn" id="geocode-btn">
Cerca sulla mappa
</button>
<small class="text-muted d-block">Compila via + città + CAP clicca qui</small>
</div>
<!-- Mappa -->
<div id="map"></div>
<!-- Latitudine e Longitudine (readonly ma modificabili manualmente se serve) -->
<div class="row mt-3">
<div class="col-md-6">
<label for="latitude" class="form-label">Latitudine</label>
<input type="number" step="any" class="form-control" id="latitude" name="latitude" value="<?php echo htmlspecialchars($school['latitude'] ?? ''); ?>">
<input type="text" class="form-control" id="latitude" name="latitude"
value="<?php echo htmlspecialchars($school['latitude'] ?? ''); ?>" readonly>
</div>
<div class="col-md-6 mb-3">
<div class="col-md-6">
<label for="longitude" class="form-label">Longitudine</label>
<input type="number" step="any" class="form-control" id="longitude" name="longitude" value="<?php echo htmlspecialchars($school['longitude'] ?? ''); ?>">
<input type="text" class="form-control" id="longitude" name="longitude"
value="<?php echo htmlspecialchars($school['longitude'] ?? ''); ?>" readonly>
</div>
</div>
<!-- ==================== FINE INDIRIZZO + MAPPA ==================== -->
<hr class="my-4">
<div class="mb-3">
<label for="owner_name" class="form-label">Nome Proprietario</label>
<input type="text" class="form-control" id="owner_name" name="owner_name" value="<?php echo htmlspecialchars($school['owner_name'] ?? ''); ?>">
<input type="text" class="form-control" id="owner_name" name="owner_name"
value="<?php echo htmlspecialchars($school['owner_name'] ?? ''); ?>">
</div>
<div class="mb-3">
<label for="vat_number" class="form-label">Partita IVA</label>
<input type="text" class="form-control" id="vat_number" name="vat_number" value="<?php echo htmlspecialchars($school['vat_number'] ?? ''); ?>">
<input type="text" class="form-control" id="vat_number" name="vat_number"
value="<?php echo htmlspecialchars($school['vat_number'] ?? ''); ?>">
</div>
<div class="mb-3">
<label for="status" class="form-label">Stato</label>
<select class="form-control" id="status" name="status">
<option value="active" <?php echo $school['status'] === 'active' ? 'selected' : ''; ?>>Attivo</option>
<option value="inactive" <?php echo $school['status'] === 'inactive' ? 'selected' : ''; ?>>Inattivo</option>
<option value="suspended" <?php echo $school['status'] === 'suspended' ? 'selected' : ''; ?>>Sospeso</option>
<option value="active" <?php echo ($school['status'] ?? '') === 'active' ? 'selected' : ''; ?>>Attivo</option>
<option value="inactive" <?php echo ($school['status'] ?? '') === 'inactive' ? 'selected' : ''; ?>>Inattivo</option>
<option value="suspended" <?php echo ($school['status'] ?? '') === 'suspended' ? 'selected' : ''; ?>>Sospeso</option>
</select>
</div>
<?php if (!$is_new): ?>
<div class="mb-3">
<label class="form-label">Data Creazione</label>
<input type="text" class="form-control" value="<?php echo htmlspecialchars($school['created_at']); ?>" readonly>
<label class="form-label">Creato il</label>
<input type="text" class="form-control" value="<?php echo htmlspecialchars($school['created_at'] ?? ''); ?>" readonly>
</div>
<div class="mb-3">
<label class="form-label">Ultimo Aggiornamento</label>
<input type="text" class="form-control" value="<?php echo htmlspecialchars($school['updated_at']); ?>" readonly>
<label class="form-label">Ultimo aggiornamento</label>
<input type="text" class="form-control" value="<?php echo htmlspecialchars($school['updated_at'] ?? ''); ?>" readonly>
</div>
<?php endif; ?>
<button type="submit" class="btn btn-primary"><?php echo $is_new ? 'Crea Profilo' : 'Salva Modifiche'; ?></button>
<button type="submit" class="btn btn-primary btn-lg">
<?php echo $is_new ? 'Crea Profilo' : 'Salva Modifiche'; ?>
</button>
</div>
</div>
</form>
@@ -358,49 +425,113 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
</div>
</div>
</div>
<div class="overlay toggle-icon"></div>
<a href="javaScript:;" class="back-to-top"><i class='bx bxs-up-arrow-alt'></i></a>
<?php include('include/footer.php'); ?>
</div>
<?php include('jsinclude.php'); ?>
<!-- Script per validazione e suggerimento dello slug -->
<!-- Leaflet JS -->
<script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js"
integrity="sha256-o9N1j3Z3B9n0nN2V3H7N7X8z0z1k6p3c1F0L5g0B6p8=" crossorigin=""></script>
<script>
// Funzione per generare uno slug valido
function generateSlug(string) {
return string
.toLowerCase() // Converti in minuscolo
.replace(/[^a-z0-9-]+/g, '-') // Sostituisci caratteri non validi con trattini
.replace(/-+/g, '-') // Rimuovi trattini multipli
.replace(/^-|-$/g, ''); // Rimuovi trattini all'inizio e alla fine
let map, marker;
// Inizializza la mappa
function initMap(lat = 41.9028, lng = 12.4964, zoom = 5) {
if (map) map.remove();
map = L.map('map').setView([lat, lng], zoom);
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '&copy; OpenStreetMap contributors'
}).addTo(map);
marker = L.marker([lat, lng], {
draggable: true
}).addTo(map);
marker.on('dragend', function() {
const pos = marker.getLatLng();
document.getElementById('latitude').value = pos.lat.toFixed(8);
document.getElementById('longitude').value = pos.lng.toFixed(8);
});
}
// Riferimenti ai campi
const nameInput = document.getElementById('name');
const slugInput = document.getElementById('slug');
let isUserTypingSlug = false; // Flag per tracciare se l'utente sta modificando lo slug manualmente
// Aggiorna mappa e campi
function updateMap(lat, lng) {
document.getElementById('latitude').value = lat.toFixed(8);
document.getElementById('longitude').value = lng.toFixed(8);
map.setView([lat, lng], 16);
if (marker) marker.setLatLng([lat, lng]);
}
// Suggerimento dello slug basato sul nome
nameInput.addEventListener('input', function(e) {
if (!isUserTypingSlug) { // Aggiorna lo slug solo se l'utente non lo sta modificando manualmente
const name = e.target.value;
const generatedSlug = generateSlug(name);
slugInput.value = generatedSlug;
// Geocoding con Nominatim
document.getElementById('geocode-btn').addEventListener('click', function() {
const street = document.getElementById('address_street').value.trim();
const city = document.getElementById('address_city').value.trim();
const cap = document.getElementById('address_postal_code').value.trim();
const country = document.getElementById('address_country').value.trim() || 'Italia';
if (!street || !city) {
alert('Inserisci almeno Via e Città');
return;
}
const query = `${street}, ${city}${cap ? ' ' + cap : ''}, ${country}`;
const url = `https://nominatim.openstreetmap.org/search?format=json&q=${encodeURIComponent(query)}&limit=1`;
fetch(url)
.then(r => r.json())
.then(data => {
if (data && data.length > 0) {
const r = data[0];
updateMap(parseFloat(r.lat), parseFloat(r.lon));
} else {
alert('Indirizzo non trovato. Controlla i dati.');
}
})
.catch(() => alert('Errore di rete. Riprova.'));
});
// Al caricamento della pagina
document.addEventListener('DOMContentLoaded', function() {
const lat = document.getElementById('latitude').value;
const lng = document.getElementById('longitude').value;
if (lat && lng) {
initMap(parseFloat(lat), parseFloat(lng), 16);
} else {
initMap(); // Italia centrata
}
});
// Validazione dello slug in tempo reale
slugInput.addEventListener('input', function(e) {
isUserTypingSlug = true; // L'utente sta modificando lo slug manualmente
let value = e.target.value;
value = generateSlug(value); // Applica le regole di validazione
e.target.value = value; // Aggiorna il campo con il valore validato
/* Slug automatico (il tuo codice originale invariato) */
const nameInput = document.getElementById('name');
const slugInput = document.getElementById('slug');
let isUserTypingSlug = false;
function generateSlug(str) {
return str.toLowerCase()
.replace(/[^a-z0-9-]+/g, '-')
.replace(/-+/g, '-')
.replace(/^-|-$/g, '');
}
nameInput?.addEventListener('input', function() {
if (!isUserTypingSlug) {
slugInput.value = generateSlug(this.value);
}
});
// Ripristina il flag quando l'utente smette di modificare lo slug
slugInput.addEventListener('blur', function() {
isUserTypingSlug = false; // L'utente ha finito di modificare lo slug
slugInput?.addEventListener('input', function(e) {
isUserTypingSlug = true;
this.value = generateSlug(this.value);
});
slugInput?.addEventListener('blur', () => isUserTypingSlug = false);
</script>
</body>