This commit is contained in:
2026-01-21 10:29:37 +01:00
parent dda63d9711
commit 7f7dff32d9
17 changed files with 1885 additions and 521 deletions
+352 -331
View File
@@ -1,41 +1,37 @@
<?php
// Forza la visualizzazione degli errori
// school_profile.php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
include('include/headscript.php');
// Connessione al database
$dbHandler = DBHandlerSelect::getInstance();
$pdo = $dbHandler->getConnection();
// ID dell'utente loggato (assumiamo sia definito)
if (!isset($iduserlogin)) {
die("Errore: ID utente non definito.");
}
// Recupera i dati della scuola associata all'utente
// Recupera scuola dell'utente loggato
$stmt = $pdo->prepare("
SELECT s.*, u.first_name, u.last_name, u.email
FROM auth_users u
LEFT JOIN schools s ON s.owner_id = u.id
FROM schools s
RIGHT JOIN auth_users u ON s.owner_id = u.id
WHERE u.id = ?
");
$stmt->execute([$iduserlogin]);
$school = $stmt->fetch();
$school = $stmt->fetch(PDO::FETCH_ASSOC);
if (!$school) {
die("Errore: Utente non trovato.");
}
$is_new = empty($school['id']);
// Determina se è una nuova scuola
$is_new = !isset($school['id']);
if ($is_new) {
$school = [
'id' => null,
'owner_id' => $iduserlogin,
'name' => '',
'slug' => '',
'website' => '',
'email' => '',
'phone' => '',
@@ -44,176 +40,139 @@ if ($is_new) {
'address_city' => '',
'address_postal_code' => '',
'address_province' => '',
'address_country' => '',
'latitude' => '',
'longitude' => '',
'address_country' => 'Italia',
'latitude' => null,
'longitude' => null,
'owner_name' => '',
'vat_number' => '',
'logo' => '',
'status' => 'active',
'created_at' => '',
'updated_at' => '',
'slug' => '',
'first_name' => $school['first_name'],
'last_name' => $school['last_name'],
'email' => $school['email']
'first_name' => '',
'last_name' => '',
'email' => ''
];
}
// Funzione per generare uno slug valido
// Generatore slug
function generateSlug($string)
{
$slug = strtolower($string); // Converti in minuscolo
$slug = preg_replace('/[^a-z0-9-]+/', '-', $slug); // Sostituisci caratteri non validi con trattini
$slug = preg_replace('/-+/', '-', $slug); // Rimuovi trattini multipli
$slug = trim($slug, '-'); // Rimuovi trattini all'inizio e alla fine
$slug = iconv('UTF-8', 'ASCII//TRANSLIT', $string);
$slug = preg_replace('/[^a-z0-9 -]/i', '', $slug);
$slug = trim($slug);
$slug = preg_replace('/ +/', '-', $slug);
$slug = strtolower($slug);
return $slug;
}
// Gestione del form
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$name = $_POST['name'] ?? '';
$website = $_POST['website'] ?? null;
$email = $_POST['email'] ?? '';
$phone = $_POST['phone'] ?? null;
$description = $_POST['description'] ?? null;
$address_street = $_POST['address_street'] ?? '';
$address_city = $_POST['address_city'] ?? '';
$address_postal_code = $_POST['address_postal_code'] ?? '';
$address_province = $_POST['address_province'] ?? null;
$address_country = $_POST['address_country'] ?? '';
$latitude = $_POST['latitude'] ? floatval($_POST['latitude']) : null;
$longitude = $_POST['longitude'] ? floatval($_POST['longitude']) : null;
$owner_name = $_POST['owner_name'] ?? '';
$vat_number = $_POST['vat_number'] ?? '';
$status = in_array($_POST['status'], ['active', 'inactive', 'suspended']) ? $_POST['status'] : 'active';
$slug = isset($_POST['slug']) ? generateSlug($_POST['slug']) : '';
// POST - Salvataggio
$success_message = $error = null;
// Validazione dello slug
if (empty($slug)) {
$error = "Errore: Lo slug non può essere vuoto.";
} else {
// Controlla se lo slug è univoco
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$name = trim($_POST['name'] ?? '');
$slug = generateSlug(trim($_POST['slug'] ?? $name));
$website = trim($_POST['website'] ?? '');
$email = trim($_POST['email'] ?? '');
$phone = trim($_POST['phone'] ?? '');
$description = trim($_POST['description'] ?? '');
$address_street = trim($_POST['address_street'] ?? '');
$address_city = trim($_POST['address_city'] ?? '');
$address_postal_code = trim($_POST['address_postal_code'] ?? '');
$address_province = trim($_POST['address_province'] ?? '');
$address_country = trim($_POST['address_country'] ?? 'Italia');
$latitude = !empty($_POST['latitude']) ? floatval($_POST['latitude']) : null;
$longitude = !empty($_POST['longitude']) ? floatval($_POST['longitude']) : null;
$owner_name = trim($_POST['owner_name'] ?? '');
$vat_number = trim($_POST['vat_number'] ?? '');
$status = in_array($_POST['status'] ?? 'active', ['active', 'inactive', 'suspended']) ? $_POST['status'] : 'active';
// Validazioni
if (empty($name)) $error = "Il nome della scuola è obbligatorio.";
elseif (empty($slug)) $error = "Lo slug non può essere vuoto.";
else {
$stmt = $pdo->prepare("SELECT COUNT(*) FROM schools WHERE slug = ? AND id != ?");
$stmt->execute([$slug, $school['id'] ?? 0]);
$slug_exists = $stmt->fetchColumn();
if ($slug_exists) {
$error = "Errore: Lo slug '$slug' è già in uso. Scegli un altro slug.";
if ($stmt->fetchColumn() > 0) {
$error = "Lo slug '$slug' è già in uso.";
}
}
// Gestione del caricamento del logo
$logo = $school['logo'];
if (isset($_FILES['logo']) && $_FILES['logo']['error'] === UPLOAD_ERR_OK) {
$file = $_FILES['logo'];
$timestamp = time();
$original_name = basename($file['name']);
$extension = strtolower(pathinfo($original_name, PATHINFO_EXTENSION));
$allowed_extensions = ['jpg', 'jpeg', 'png', 'gif'];
if (in_array($extension, $allowed_extensions)) {
$new_filename = "photoschool/{$iduserlogin}-{$timestamp}-{$original_name}";
if (move_uploaded_file($file['tmp_name'], $new_filename)) {
$logo = $new_filename;
if ($school['logo'] && file_exists($school['logo']) && !$is_new) {
unlink($school['logo']);
}
// Logo
$logo = $school['logo'] ?? '';
if (!empty($_FILES['logo']['name']) && $_FILES['logo']['error'] === UPLOAD_ERR_OK) {
$ext = strtolower(pathinfo($_FILES['logo']['name'], PATHINFO_EXTENSION));
if (in_array($ext, ['jpg', 'jpeg', 'png', 'gif'])) {
$new_name = "photoschool/{$iduserlogin}-" . time() . "-logo.$ext";
if (move_uploaded_file($_FILES['logo']['tmp_name'], $new_name)) {
if ($logo && file_exists($logo) && !$is_new) @unlink($logo);
$logo = $new_name;
} else {
$error = "Errore durante il caricamento del logo.";
$error = "Errore caricamento logo.";
}
} else {
$error = "Estensione del file non consentita. Usa JPG, JPEG, PNG o GIF.";
$error = "Solo JPG, PNG, GIF ammessi.";
}
}
// Se non ci sono errori, procedi con il salvataggio
if (!isset($error)) {
// Aggiorna auth_users (opzionale, se vuoi aggiornare first_name e last_name)
$stmt = $pdo->prepare("UPDATE auth_users SET first_name = ?, last_name = ? WHERE id = ?");
$stmt->execute([$school['first_name'], $school['last_name'], $iduserlogin]);
$params = [
$name,
$slug,
$website ?: null,
$email,
$phone ?: null,
$description,
$address_street,
$address_city,
$address_postal_code,
$address_province,
$address_country,
$latitude,
$longitude,
$owner_name,
$vat_number,
$logo,
$status
];
if ($is_new) {
$stmt = $pdo->prepare("
INSERT INTO schools (owner_id, name, website, email, phone, description, address_street, address_city, address_postal_code, address_province, address_country, latitude, longitude, owner_name, vat_number, logo, status, slug)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
INSERT INTO schools (
owner_id, name, slug, website, email, phone, description,
address_street, address_city, address_postal_code, address_province, address_country,
latitude, longitude, owner_name, vat_number, logo, status
) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)
");
$success = $stmt->execute([
$iduserlogin,
$name,
$website,
$email,
$phone,
$description,
$address_street,
$address_city,
$address_postal_code,
$address_province,
$address_country,
$latitude,
$longitude,
$owner_name,
$vat_number,
$logo,
$status,
$slug
]);
array_unshift($params, $iduserlogin);
$success = $stmt->execute($params);
if ($success) {
$success_message = "Scuola creata con successo!";
$stmt = $pdo->prepare("
SELECT s.*, u.first_name, u.last_name, u.email
FROM auth_users u
LEFT JOIN schools s ON s.owner_id = u.id
WHERE u.id = ?
");
$stmt = $pdo->prepare("SELECT * FROM schools WHERE owner_id = ? ORDER BY id DESC LIMIT 1");
$stmt->execute([$iduserlogin]);
$school = $stmt->fetch();
$school = $stmt->fetch(PDO::FETCH_ASSOC);
$is_new = false;
} else {
$error = "Errore durante la creazione della scuola.";
$error = "Errore creazione scuola.";
}
} else {
$params[] = $school['id'];
$stmt = $pdo->prepare("
UPDATE schools
SET name = ?, website = ?, email = ?, phone = ?, description = ?, address_street = ?, address_city = ?,
address_postal_code = ?, address_province = ?, address_country = ?, latitude = ?, longitude = ?,
owner_name = ?, vat_number = ?, logo = ?, status = ?, slug = ?
WHERE owner_id = ?
UPDATE schools SET
name=?, slug=?, website=?, email=?, phone=?, description=?,
address_street=?, address_city=?, address_postal_code=?, address_province=?,
address_country=?, latitude=?, longitude=?, owner_name=?, vat_number=?,
logo=?, status=?
WHERE id=?
");
$success = $stmt->execute([
$name,
$website,
$email,
$phone,
$description,
$address_street,
$address_city,
$address_postal_code,
$address_province,
$address_country,
$latitude,
$longitude,
$owner_name,
$vat_number,
$logo,
$status,
$slug,
$iduserlogin
]);
$success = $stmt->execute($params);
if ($success) {
$success_message = "Dati aggiornati con successo!";
$stmt = $pdo->prepare("
SELECT s.*, u.first_name, u.last_name, u.email
FROM auth_users u
LEFT JOIN schools s ON s.owner_id = u.id
WHERE u.id = ?
");
$stmt->execute([$iduserlogin]);
$school = $stmt->fetch();
$success_message = "Profilo aggiornato con successo!";
$stmt = $pdo->prepare("SELECT * FROM schools WHERE id = ?");
$stmt->execute([$school['id']]);
$school = $stmt->fetch(PDO::FETCH_ASSOC);
} else {
$error = "Errore durante l'aggiornamento dei dati.";
$error = "Errore aggiornamento.";
}
}
}
@@ -226,23 +185,54 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" href="assets/images/favicon-32x32.png" type="image/png" />
<title><?php echo $is_new ? 'Crea' : 'Modifica'; ?> Profilo Scuola</title>
<?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="" />
<!-- Quill.js CDN -->
<link href="https://cdn.jsdelivr.net/npm/quill@2.0.2/dist/quill.snow.css" rel="stylesheet" />
<style>
#map {
height: 350px;
height: 380px;
border-radius: 10px;
margin-top: 15px;
box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
margin-top: 12px;
box-shadow: 0 4px 15px rgba(0, 0, 0, 0.08);
}
.geocode-btn {
margin-top: 10px;
/* Editor Quill */
.ql-container {
min-height: 260px;
font-size: 15px;
border: 1px solid #ced4da;
border-radius: 0.375rem;
}
.ql-editor {
min-height: 260px;
}
.form-label {
font-weight: 500;
}
.ql-toolbar {
border-radius: 0.375rem 0.375rem 0 0;
border-color: #ced4da;
}
/* Logo rettangolare, non arrotondato */
.school-logo {
max-width: 100%;
height: auto;
max-height: 220px;
object-fit: contain;
border: 1px solid #dee2e6;
border-radius: 8px;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.08);
background: #fff;
padding: 10px;
display: block;
margin: 0 auto 1rem;
}
</style>
</head>
@@ -255,169 +245,172 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
<div class="page-wrapper">
<div class="page-content">
<div class="card radius-10">
<div class="card-header">
<h6 class="mb-0"><?php echo $is_new ? 'Crea Profilo Scuola' : 'Profilo Scuola'; ?></h6>
<div class="card-header bg-gradient-primary text-white">
<h5 class="mb-0"><?php echo $is_new ? 'Crea il tuo profilo scuola' : 'Gestisci profilo scuola'; ?></h5>
</div>
<div class="card-body">
<?php if (isset($success_message)): ?>
<div class="alert alert-success"><?php echo $success_message; ?></div>
<?php endif; ?>
<?php if (isset($error)): ?>
<div class="alert alert-danger"><?php echo $error; ?></div>
<?php if ($success_message): ?>
<div class="alert alert-success alert-dismissible fade show">
<?php echo htmlspecialchars($success_message); ?>
<button type="button" class="btn-close" data-bs-dismiss="alert"></button>
</div>
<?php endif; ?>
<form method="POST" enctype="multipart/form-data">
<div class="row">
<!-- Colonna sinistra: logo -->
<div class="col-md-4 text-center">
<?php if ($error): ?>
<div class="alert alert-danger alert-dismissible fade show">
<?php echo htmlspecialchars($error); ?>
<button type="button" class="btn-close" data-bs-dismiss="alert"></button>
</div>
<?php endif; ?>
<form method="POST" enctype="multipart/form-data" id="schoolForm">
<div class="row g-4">
<!-- Colonna sinistra: solo logo -->
<div class="col-lg-4 text-center">
<img src="<?php echo $school['logo'] ? htmlspecialchars($school['logo']) : 'photoschool/default-school.png'; ?>"
alt="Logo Scuola" class="school-logo mb-3">
<div class="mb-3">
<img src="<?php echo $school['logo'] ? htmlspecialchars($school['logo']) : 'photoschool/ndphoto.png'; ?>"
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/*">
<label class="form-label">Cambia Logo (opzionale)</label>
<input type="file" class="form-control" name="logo" accept="image/jpeg,image/png,image/gif">
<small class="text-muted d-block mt-1">Max 2MB JPG, PNG, GIF</small>
</div>
</div>
<!-- Colonna destra: tutti i campi -->
<div class="col-md-8">
<!-- Colonna destra: tutti i campi inclusa descrizione con Quill -->
<div class="col-lg-8">
<div class="row g-3">
<div class="col-md-6">
<label class="form-label">Nome Scuola <span class="text-danger">*</span></label>
<input type="text" class="form-control" name="name" required
value="<?php echo htmlspecialchars($school['name'] ?? ''); ?>">
</div>
<!-- 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>
</div>
<div class="col-md-6">
<label class="form-label">Slug (URL personalizzato) <span class="text-danger">*</span></label>
<div class="input-group">
<span class="input-group-text">yogiboook.com/</span>
<input type="text" class="form-control" name="slug" id="slug" required
value="<?php echo htmlspecialchars($school['slug'] ?? ''); ?>">
</div>
</div>
<div class="mb-3">
<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="col-md-6">
<label class="form-label">Sito web</label>
<input type="url" class="form-control" name="website"
value="<?php echo htmlspecialchars($school['website'] ?? ''); ?>">
</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'] ?? ''); ?>">
</div>
<div class="col-md-6">
<label class="form-label">Email scuola <span class="text-danger">*</span></label>
<input type="email" class="form-control" name="email" required
value="<?php echo htmlspecialchars($school['email'] ?? ''); ?>">
</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>
</div>
<div class="col-md-6">
<label class="form-label">Telefono</label>
<input type="tel" class="form-control" name="phone"
value="<?php echo htmlspecialchars($school['phone'] ?? ''); ?>">
</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'] ?? ''); ?>">
</div>
<!-- Editor Quill qui, nella colonna destra -->
<div class="col-12">
<label class="form-label">Descrizione scuola</label>
<div id="quill-editor"></div>
<input type="hidden" name="description" id="description-hidden">
</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>
<div class="col-12">
<hr class="my-4">
<h6 class="mb-3">Indirizzo sede</h6>
</div>
<!-- ==================== INIZIO INDIRIZZO + MAPPA ==================== -->
<div class="mb-3">
<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="col-12">
<label class="form-label">Via e numero civico</label>
<input type="text" class="form-control" 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"
<div class="col-md-4">
<label class="form-label">Città</label>
<input type="text" class="form-control" 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"
<div class="col-md-4">
<label class="form-label">CAP</label>
<input type="text" class="form-control" 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"
<div class="col-md-4">
<label class="form-label">Provincia</label>
<input type="text" class="form-control" 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"
<div class="col-md-6">
<label class="form-label">Nazione</label>
<input type="text" class="form-control" name="address_country"
value="<?php echo htmlspecialchars($school['address_country'] ?? 'Italia'); ?>">
</div>
</div>
<!-- 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>
<div class="col-md-6 mt-4 pt-2">
<button type="button" class="btn btn-outline-primary w-100" id="geocodeBtn">
<i class="bx bx-map-pin me-1"></i> Trova coordinate sulla mappa
</button>
</div>
<!-- Mappa -->
<div id="map"></div>
<div class="col-12">
<div id="map"></div>
</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="text" class="form-control" id="latitude" name="latitude"
<label class="form-label">Latitudine</label>
<input type="text" class="form-control" name="latitude" id="latitude"
value="<?php echo htmlspecialchars($school['latitude'] ?? ''); ?>" readonly>
</div>
<div class="col-md-6">
<label for="longitude" class="form-label">Longitudine</label>
<input type="text" class="form-control" id="longitude" name="longitude"
<label class="form-label">Longitudine</label>
<input type="text" class="form-control" name="longitude" id="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'] ?? ''); ?>">
</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'] ?? ''); ?>">
</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>
</select>
</div>
<?php if (!$is_new): ?>
<div class="mb-3">
<label class="form-label">Creato il</label>
<input type="text" class="form-control" value="<?php echo htmlspecialchars($school['created_at'] ?? ''); ?>" readonly>
<div class="col-12">
<hr class="my-4">
<h6 class="mb-3">Dati amministrativi</h6>
</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>
</div>
<?php endif; ?>
<button type="submit" class="btn btn-primary btn-lg">
<?php echo $is_new ? 'Crea Profilo' : 'Salva Modifiche'; ?>
</button>
<div class="col-md-6">
<label class="form-label">Nome proprietario / legale</label>
<input type="text" class="form-control" name="owner_name"
value="<?php echo htmlspecialchars($school['owner_name'] ?? ''); ?>">
</div>
<div class="col-md-6">
<label class="form-label">Partita IVA</label>
<input type="text" class="form-control" name="vat_number"
value="<?php echo htmlspecialchars($school['vat_number'] ?? ''); ?>">
</div>
<div class="col-md-6">
<label class="form-label">Stato</label>
<select class="form-select" name="status">
<option value="active" <?php echo ($school['status'] ?? '') === 'active' ? 'selected' : ''; ?>>Attiva</option>
<option value="inactive" <?php echo ($school['status'] ?? '') === 'inactive' ? 'selected' : ''; ?>>Inattiva</option>
<option value="suspended" <?php echo ($school['status'] ?? '') === 'suspended' ? 'selected' : ''; ?>>Sospesa</option>
</select>
</div>
<div class="col-12 mt-5">
<button type="submit" class="btn btn-primary btn-lg px-5">
<i class="bx bx-save me-2"></i>
<?php echo $is_new ? 'Crea Scuola' : 'Salva Modifiche'; ?>
</button>
</div>
</div>
</div>
</div>
</form>
@@ -426,54 +419,97 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
</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'); ?>
<!-- Leaflet JS -->
<script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js"
integrity="sha256-o9N1j3Z3B9n0nN2V3H7N7X8z0z1k6p3c1F0L5g0B6p8=" crossorigin=""></script>
<!-- Quill.js -->
<script src="https://cdn.jsdelivr.net/npm/quill@2.0.2/dist/quill.js"></script>
<!-- Leaflet -->
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css" />
<script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js"></script>
<script>
// ====================== QUILL EDITOR - colori testo e sfondo visibili ======================
const quill = new Quill('#quill-editor', {
theme: 'snow',
modules: {
toolbar: [
['bold', 'italic', 'underline', 'strike'],
['blockquote', 'code-block'],
[{
'header': [1, 2, 3, false]
}],
[{
'color': [
'#000000', '#434343', '#666666', '#999999', '#b7b7b7', '#cccccc', '#d9d9d9', '#ffffff',
'#ff0000', '#ff9900', '#ffff00', '#00ff00', '#00ffff', '#0000ff', '#9900ff', '#ff00ff',
'#ffcccc', '#ffe6cc', '#ffffcc', '#ccffcc', '#ccffff', '#ccccff', '#e6ccff', '#ffccff'
]
}, {
'background': [
'#000000', '#434343', '#666666', '#999999', '#b7b7b7', '#cccccc', '#d9d9d9', '#ffffff',
'#ff0000', '#ff9900', '#ffff00', '#00ff00', '#00ffff', '#0000ff', '#9900ff', '#ff00ff',
'#ffcccc', '#ffe6cc', '#ffffcc', '#ccffcc', '#ccffff', '#ccccff', '#e6ccff', '#ffccff'
]
}],
[{
'list': 'ordered'
}, {
'list': 'bullet'
}],
[{
'align': []
}],
['link', 'clean']
]
}
});
// Carica contenuto iniziale (HTML)
quill.root.innerHTML = `<?php echo addslashes($school['description'] ?? ''); ?>`;
// Salva HTML prima del submit
document.getElementById('schoolForm').addEventListener('submit', function(e) {
document.getElementById('description-hidden').value = quill.root.innerHTML;
});
// ====================== MAPPA (invariata, funziona già) ======================
let map, marker;
// Inizializza la mappa
function initMap(lat = 41.9028, lng = 12.4964, zoom = 5) {
function initMap(lat = 45.4642, lng = 9.1900, zoom = 12) {
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'
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a>'
}).addTo(map);
marker = L.marker([lat, lng], {
draggable: true
}).addTo(map);
marker.on('dragend', function() {
const pos = marker.getLatLng();
marker.on('dragend', function(e) {
const pos = e.target.getLatLng();
document.getElementById('latitude').value = pos.lat.toFixed(8);
document.getElementById('longitude').value = pos.lng.toFixed(8);
});
}
// Aggiorna mappa e campi
function updateMap(lat, lng) {
if (!map) initMap(lat, lng, 16);
else {
map.setView([lat, lng], 16);
marker.setLatLng([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]);
}
// 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';
document.getElementById('geocodeBtn')?.addEventListener('click', function() {
const street = document.querySelector('[name="address_street"]').value.trim();
const city = document.querySelector('[name="address_city"]').value.trim();
const cap = document.querySelector('[name="address_postal_code"]').value.trim();
const country = document.querySelector('[name="address_country"]').value.trim() || 'Italia';
if (!street || !city) {
alert('Inserisci almeno Via e Città');
@@ -486,52 +522,37 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
fetch(url)
.then(r => r.json())
.then(data => {
if (data && data.length > 0) {
const r = data[0];
updateMap(parseFloat(r.lat), parseFloat(r.lon));
if (data?.length > 0) {
const loc = data[0];
updateMap(parseFloat(loc.lat), parseFloat(loc.lon));
} else {
alert('Indirizzo non trovato. Controlla i dati.');
alert('Indirizzo non trovato.');
}
})
.catch(() => alert('Errore di rete. Riprova.'));
.catch(() => alert('Errore durante la ricerca.'));
});
// Al caricamento della pagina
// Init mappa
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);
const lat = parseFloat(document.getElementById('latitude').value);
const lng = parseFloat(document.getElementById('longitude').value);
if (!isNaN(lat) && !isNaN(lng)) {
initMap(lat, lng, 16);
} else {
initMap(); // Italia centrata
initMap();
}
});
/* Slug automatico (il tuo codice originale invariato) */
const nameInput = document.getElementById('name');
const slugInput = document.getElementById('slug');
let isUserTypingSlug = false;
// Slug automatico
const nameField = document.querySelector('[name="name"]');
const slugField = document.querySelector('[name="slug"]');
let slugTouched = 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);
}
nameField?.addEventListener('input', function() {
if (!slugTouched) slugField.value = generateSlug(this.value);
});
slugInput?.addEventListener('input', function(e) {
isUserTypingSlug = true;
this.value = generateSlug(this.value);
});
slugInput?.addEventListener('blur', () => isUserTypingSlug = false);
slugField?.addEventListener('input', () => slugTouched = true);
</script>
</body>