yogiboook_new/public/userarea/school_dashboard.php

1008 lines
57 KiB
PHP

<?php
// Forza la visualizzazione degli errori
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();
// Verifica che iduserlogin sia definito
if (!isset($iduserlogin)) {
die("Errore: ID utente non definito.");
}
// Recupera i dati della scuola in base all'utente loggato
$stmt = $pdo->prepare("
SELECT id, name, website, email, phone, description, address_street, address_city, address_postal_code, address_province, address_country, logo, status
FROM schools
WHERE owner_id = ?
");
$stmt->execute([$iduserlogin]);
$school = $stmt->fetch();
if (!$school) {
die("Errore: Nessuna scuola trovata per l'utente loggato.");
}
$school_id = $school['id'];
$school_name = $school['name'];
// Recupera tutte le categorie disponibili
$stmt = $pdo->prepare("SELECT id, name FROM class_categories WHERE status = 'active' ORDER BY name");
$stmt->execute();
$categories = $stmt->fetchAll();
// Recupera tutti gli insegnanti della scuola
$stmt = $pdo->prepare("SELECT id, first_name, last_name FROM teachers WHERE user_id = ? AND status = 'active' ORDER BY first_name, last_name");
$stmt->execute([$iduserlogin]);
$teachers = $stmt->fetchAll();
// Funzione per ridimensionare l'immagine
function resizeImage($source_path, $dest_path, $max_width = 800)
{
list($width, $height, $type) = getimagesize($source_path);
if ($width <= $max_width) {
copy($source_path, $dest_path);
return;
}
$new_width = $max_width;
$new_height = (int)(($height * $new_width) / $width);
switch ($type) {
case IMAGETYPE_JPEG:
$source = imagecreatefromjpeg($source_path);
break;
case IMAGETYPE_PNG:
$source = imagecreatefrompng($source_path);
break;
case IMAGETYPE_GIF:
$source = imagecreatefromgif($source_path);
break;
default:
throw new Exception("Formato immagine non supportato.");
}
$dest = imagecreatetruecolor($new_width, $new_height);
if ($type == IMAGETYPE_PNG) {
imagealphablending($dest, false);
imagesavealpha($dest, true);
}
imagecopyresampled($dest, $source, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
switch ($type) {
case IMAGETYPE_JPEG:
imagejpeg($dest, $dest_path, 90);
break;
case IMAGETYPE_PNG:
imagepng($dest, $dest_path);
break;
case IMAGETYPE_GIF:
imagegif($dest, $dest_path);
break;
}
imagedestroy($source);
imagedestroy($dest);
}
// Gestione delle azioni (aggiunta, modifica, cancellazione)
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
if (isset($_POST['action'])) {
$action = $_POST['action'];
// Aggiunta di una nuova classe
if ($action === 'add') {
$class_category_id = $_POST['class_category_id'] ?? 0;
$name = $_POST['name'] ?? '';
$description = $_POST['description'] ?? null;
$requirements = $_POST['requirements'] ?? null;
$level = in_array($_POST['level'], ['beginner', 'intermediate', 'advanced']) ? $_POST['level'] : 'beginner';
$typical_duration = $_POST['typical_duration'] ? (int)$_POST['typical_duration'] : null;
$max_capacity = $_POST['max_capacity'] ? (int)$_POST['max_capacity'] : 0; // Nuovo campo
$days_of_week = $_POST['days_of_week'] ?? '';
$start_time = $_POST['start_time'] ?? '';
$status = $_POST['status'] === 'active' ? 'active' : 'inactive';
// Rimossi period_start e period_end dai controlli
if (empty($name) || $class_category_id <= 0 || empty($days_of_week) || empty($start_time)) {
$error = "I campi obbligatori non sono stati compilati.";
} else {
$photo = null;
if (isset($_FILES['photo']) && $_FILES['photo']['error'] === UPLOAD_ERR_OK) {
$file = $_FILES['photo'];
$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 = "photoclass/{$school_id}-{$timestamp}-{$original_name}";
$temp_path = $file['tmp_name'];
try {
resizeImage($temp_path, $new_filename);
$photo = $new_filename;
} catch (Exception $e) {
$error = "Errore durante il ridimensionamento della foto: " . $e->getMessage();
}
} else {
$error = "Estensione del file non consentita. Usa JPG, JPEG, PNG o GIF.";
}
}
if (!isset($error)) {
$stmt = $pdo->prepare("
INSERT INTO class_types (school_id, class_category_id, name, description, photo, requirements, level, typical_duration, max_capacity, days_of_week, start_time, status)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
");
$success = $stmt->execute([
$school_id,
$class_category_id,
$name,
$description,
$photo,
$requirements,
$level,
$typical_duration,
$max_capacity, // Nuovo campo
$days_of_week,
$start_time,
$status
]);
if ($success) {
$success_message = "Classe aggiunta con successo!";
} else {
$error = "Errore durante l'aggiunta della classe.";
}
}
}
}
// Modifica di una classe esistente
if ($action === 'edit') {
$id = $_POST['id'] ?? 0;
$class_category_id = $_POST['class_category_id'] ?? 0;
$name = $_POST['name'] ?? '';
$description = $_POST['description'] ?? null;
$requirements = $_POST['requirements'] ?? null;
$level = in_array($_POST['level'], ['beginner', 'intermediate', 'advanced']) ? $_POST['level'] : 'beginner';
$typical_duration = $_POST['typical_duration'] ? (int)$_POST['typical_duration'] : null;
$max_capacity = $_POST['max_capacity'] ? (int)$_POST['max_capacity'] : 0; // Nuovo campo
$days_of_week = $_POST['days_of_week'] ?? '';
$start_time = $_POST['start_time'] ?? '';
$status = $_POST['status'] === 'active' ? 'active' : 'inactive';
// Rimossi period_start e period_end dai controlli
if (empty($name) || $class_category_id <= 0 || empty($days_of_week) || empty($start_time)) {
$error = "I campi obbligatori non sono stati compilati.";
} else {
// Recupera la classe esistente per ottenere il percorso della foto attuale
$stmt = $pdo->prepare("SELECT photo FROM class_types WHERE id = ? AND school_id = ?");
$stmt->execute([$id, $school_id]);
$class = $stmt->fetch();
if (!$class) {
$error = "Classe non trovata.";
} else {
$photo = $class['photo'];
if (isset($_FILES['photo']) && $_FILES['photo']['error'] === UPLOAD_ERR_OK) {
$file = $_FILES['photo'];
$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 = "photoclass/{$school_id}-{$timestamp}-{$original_name}";
$temp_path = $file['tmp_name'];
try {
resizeImage($temp_path, $new_filename);
$photo = $new_filename;
if ($class['photo'] && file_exists($class['photo'])) {
unlink($class['photo']);
}
} catch (Exception $e) {
$error = "Errore durante il ridimensionamento della foto: " . $e->getMessage();
}
} else {
$error = "Estensione del file non consentita. Usa JPG, JPEG, PNG o GIF.";
}
}
if (!isset($error)) {
$stmt = $pdo->prepare("
UPDATE class_types
SET class_category_id = ?, name = ?, description = ?, photo = ?, requirements = ?, level = ?,
typical_duration = ?, max_capacity = ?, days_of_week = ?, start_time = ?, status = ?
WHERE id = ? AND school_id = ?
");
$success = $stmt->execute([
$class_category_id,
$name,
$description,
$photo,
$requirements,
$level,
$typical_duration,
$max_capacity, // Nuovo campo
$days_of_week,
$start_time,
$status,
$id,
$school_id
]);
if ($success) {
$success_message = "Classe aggiornata con successo!";
} else {
$error = "Errore durante l'aggiornamento della classe.";
}
}
}
}
}
// Cancellazione di una classe
if ($action === 'delete') {
$id = $_POST['id'] ?? 0;
$stmt = $pdo->prepare("SELECT photo FROM class_types WHERE id = ? AND school_id = ?");
$stmt->execute([$id, $school_id]);
$class = $stmt->fetch();
if ($class) {
if ($class['photo'] && file_exists($class['photo'])) {
unlink($class['photo']);
}
$stmt = $pdo->prepare("DELETE FROM class_types WHERE id = ? AND school_id = ?");
$success = $stmt->execute([$id, $school_id]);
if ($success) {
$success_message = "Classe eliminata con successo!";
} else {
$error = "Errore durante l'eliminazione della classe.";
}
} else {
$error = "Classe non trovata.";
}
}
// Assegnazione di un insegnante
if ($action === 'assign_teacher') {
$class_id = $_POST['class_id'] ?? 0;
$teacher_id = !empty($_POST['teacher_id']) ? (int)$_POST['teacher_id'] : null;
// Verifica che la classe appartenga alla scuola
$stmt = $pdo->prepare("SELECT id FROM class_types WHERE id = ? AND school_id = ?");
$stmt->execute([$class_id, $school_id]);
if (!$stmt->fetch()) {
$error = "Classe non trovata.";
} else {
// Se teacher_id è null, rimuoviamo l'assegnazione; altrimenti, assegniamo l'insegnante
$stmt = $pdo->prepare("UPDATE class_types SET teacher_id = ? WHERE id = ?");
$success = $stmt->execute([$teacher_id, $class_id]);
if ($success) {
$success_message = "Insegnante assegnato con successo!";
} else {
$error = "Errore durante l'assegnazione dell'insegnante.";
}
}
}
// Propagazione delle sessioni
if ($action === 'propagate_sessions') {
$class_id = $_POST['class_id'] ?? 0;
$start_date = $_POST['start_date'] ?? '';
$end_date = $_POST['end_date'] ?? '';
// Validazione delle date
if (empty($start_date) || empty($end_date)) {
$error = "Le date di inizio e fine sono obbligatorie.";
} elseif (strtotime($end_date) < strtotime($start_date)) {
$error = "La data di fine non può essere precedente alla data di inizio.";
} else {
// Verifica che la classe appartenga alla scuola
$stmt = $pdo->prepare("
SELECT days_of_week, start_time, typical_duration, teacher_id
FROM class_types
WHERE id = ? AND school_id = ?
");
$stmt->execute([$class_id, $school_id]);
$class = $stmt->fetch();
if (!$class) {
$error = "Classe non trovata.";
} else {
// Recupera i giorni di chiusura della scuola
$stmt = $pdo->prepare("
SELECT start_date, end_date
FROM day_off
WHERE school_id = ? AND (
(start_date BETWEEN ? AND ?) OR
(end_date BETWEEN ? AND ?) OR
(start_date <= ? AND end_date >= ?)
)
");
$stmt->execute([
$school_id,
$start_date,
$end_date,
$start_date,
$end_date,
$start_date,
$end_date
]);
$days_off = $stmt->fetchAll();
// Crea un array di giorni di chiusura
$off_dates = [];
foreach ($days_off as $day_off) {
$current = new DateTime($day_off['start_date']);
$end = new DateTime($day_off['end_date']);
while ($current <= $end) {
$off_dates[] = $current->format('Y-m-d');
$current->modify('+1 day');
}
}
// Converti i giorni della settimana in un array
$days_of_week = array_map('trim', explode(',', $class['days_of_week']));
$days_map = [
'Lun' => 'Monday',
'Mar' => 'Tuesday',
'Mer' => 'Wednesday',
'Gio' => 'Thursday',
'Ven' => 'Friday',
'Sab' => 'Saturday',
'Dom' => 'Sunday'
];
// Converti i giorni in formato inglese per il confronto
$days_of_week_english = [];
foreach ($days_of_week as $day) {
if (isset($days_map[$day])) {
$days_of_week_english[] = $days_map[$day];
}
}
// Calcola l'orario di fine
$start_time = new DateTime($class['start_time']);
$end_time = clone $start_time;
if ($class['typical_duration']) {
$end_time->modify("+{$class['typical_duration']} minutes");
} else {
$end_time->modify("+60 minutes"); // Default: 1 ora se la durata non è specificata
}
// Genera un propagation_id univoco
$propagation_id = uniqid('prop_', true);
// Genera le sessioni
$current_date = new DateTime($start_date);
$end_date_dt = new DateTime($end_date);
$end_date_dt->setTime(23, 59, 59); // Include l'ultimo giorno
$stmt = $pdo->prepare("
INSERT INTO class_sessions (class_type_id, session_date, start_time, end_time, teacher_id, status, propagation_id)
VALUES (?, ?, ?, ?, ?, 'scheduled', ?)
");
$sessions_created = 0;
while ($current_date <= $end_date_dt) {
$day_of_week = $current_date->format('l'); // Giorno della settimana in inglese (es. Monday)
$current_date_str = $current_date->format('Y-m-d');
// Verifica se il giorno è un giorno di chiusura e se è nei giorni della settimana della classe
if (!in_array($current_date_str, $off_dates) && in_array($day_of_week, $days_of_week_english)) {
$session_date = $current_date->format('Y-m-d');
$start_time_str = $start_time->format('H:i:s');
$end_time_str = $end_time->format('H:i:s');
try {
$stmt->execute([
$class_id,
$session_date,
$start_time_str,
$end_time_str,
$class['teacher_id'],
$propagation_id
]);
$sessions_created++;
} catch (PDOException $e) {
// Ignora errori di chiave unica (sessioni già esistenti)
if ($e->getCode() != 23000) {
$error = "Errore durante la propagazione delle sessioni: " . $e->getMessage();
break;
}
}
}
$current_date->modify('+1 day');
}
if (!isset($error)) {
$success_message = "Propagate $sessions_created sessioni con successo! (ID Propagazione: $propagation_id)";
}
}
}
}
// Rimozione di una propagazione
if ($action === 'remove_propagation') {
$propagation_id = $_POST['propagation_id'] ?? '';
$class_id = $_POST['class_id'] ?? 0;
if (empty($propagation_id) || $class_id <= 0) {
$error = "ID di propagazione o classe non validi.";
} else {
// Verifica che la classe appartenga alla scuola
$stmt = $pdo->prepare("SELECT id FROM class_types WHERE id = ? AND school_id = ?");
$stmt->execute([$class_id, $school_id]);
if (!$stmt->fetch()) {
$error = "Classe non trovata.";
} else {
// Elimina tutte le sessioni associate a questa propagazione
$stmt = $pdo->prepare("
DELETE FROM class_sessions
WHERE propagation_id = ? AND class_type_id = ?
");
$stmt->execute([$propagation_id, $class_id]);
$deleted_rows = $stmt->rowCount();
$success_message = "Propagazione rimossa con successo! ($deleted_rows sessioni eliminate)";
}
}
}
// Reindirizza per evitare il doppio invio del form
header("Location: school_dashboard.php");
exit;
}
}
// Recupera tutte le classi della scuola con il nome dell'insegnante
$stmt = $pdo->prepare("
SELECT ct.*, cc.name AS category_name, t.first_name AS teacher_first_name, t.last_name AS teacher_last_name
FROM class_types ct
LEFT JOIN class_categories cc ON ct.class_category_id = cc.id
LEFT JOIN teachers t ON ct.teacher_id = t.id
WHERE ct.school_id = ?
ORDER BY ct.created_at DESC
");
$stmt->execute([$school_id]);
$classes = $stmt->fetchAll();
?>
<!doctype html>
<html lang="en">
<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" />
<?php include('cssinclude.php'); ?>
<?php include('siteinfo.php'); ?>
</head>
<body>
<div class="wrapper">
<?php include('include/navbar.php'); ?>
<?php include('include/topbar.php'); ?>
<div class="page-wrapper">
<div class="page-content">
<!-- Sezione Informazioni Scuola -->
<div class="card radius-10 mb-4">
<div class="card-body">
<div class="d-flex align-items-center">
<div class="me-4">
<img src="<?php echo $school['logo'] ? htmlspecialchars($school['logo']) : 'assets/images/default-school-logo.png'; ?>"
alt="Logo Scuola" class="rounded-circle" style="width: 100px; height: 100px; object-fit: cover;">
</div>
<div class="flex-grow-1">
<h5 class="mb-1"><?php echo htmlspecialchars($school['name']); ?></h5>
<p class="mb-1">
<strong>Indirizzo:</strong>
<?php
$address_parts = array_filter([
$school['address_street'],
$school['address_city'],
$school['address_postal_code'],
$school['address_province'],
$school['address_country']
]);
echo htmlspecialchars(implode(', ', $address_parts)) ?: 'Non specificato';
?>
</p>
<p class="mb-1"><strong>Email:</strong> <?php echo htmlspecialchars($school['email'] ?: 'Non specificato'); ?></p>
<p class="mb-1"><strong>Telefono:</strong> <?php echo htmlspecialchars($school['phone'] ?: 'Non specificato'); ?></p>
<p class="mb-1"><strong>Sito Web:</strong>
<?php if ($school['website']): ?>
<a href="<?php echo htmlspecialchars($school['website']); ?>" target="_blank"><?php echo htmlspecialchars($school['website']); ?></a>
<?php else: ?>
Non specificato
<?php endif; ?>
</p>
<p class="mb-0"><strong>Descrizione:</strong> <?php echo htmlspecialchars($school['description'] ?: 'Non specificata'); ?></p>
</div>
<div>
<a href="school_profile.php" class="btn btn-primary">Modifica Profilo</a>
</div>
</div>
</div>
</div>
<!-- Sezione Pulsantiera -->
<div class="row mb-4">
<div class="col-12">
<div class="d-flex flex-wrap justify-content-center gap-3">
<!-- Pulsante Situazione Clienti -->
<a href="#" class="btn btn-primary d-flex align-items-center px-4 py-3 shadow-sm rounded" style="min-width: 200px;">
<i class="bx bx-user me-2" style="font-size: 24px;"></i>
<span class="fs-5">Situazione Clienti</span>
</a>
<!-- Pulsante Ordini -->
<a href="#" class="btn btn-success d-flex align-items-center px-4 py-3 shadow-sm rounded" style="min-width: 200px;">
<i class="bx bx-cart me-2" style="font-size: 24px;"></i>
<span class="fs-5">Ordini</span>
</a>
<!-- Pulsante Finanze -->
<a href="#" class="btn btn-warning d-flex align-items-center px-4 py-3 shadow-sm rounded" style="min-width: 200px;">
<i class="bx bx-dollar me-2" style="font-size: 24px;"></i>
<span class="fs-5">Finanze</span>
</a>
<!-- Pulsante Abbonamenti -->
<a href="#" class="btn btn-info d-flex align-items-center px-4 py-3 shadow-sm rounded" style="min-width: 200px;">
<i class="bx bx-calendar me-2" style="font-size: 24px;"></i>
<span class="fs-5">Abbonamenti</span>
</a>
<!-- Pulsante Day Off -->
<a href="day_off.php" class="btn btn-danger d-flex align-items-center px-4 py-3 shadow-sm rounded" style="min-width: 200px;">
<i class="bx bx-calendar-x me-2" style="font-size: 24px;"></i>
<span class="fs-5">Giorni di Chiusura</span>
</a>
<!-- Pulsante Impostazioni -->
<a href="#" class="btn btn-dark d-flex align-items-center px-4 py-3 shadow-sm rounded" style="min-width: 200px;">
<i class="bx bx-cog me-2" style="font-size: 24px;"></i>
<span class="fs-5">Impostazioni</span>
</a>
</div>
</div>
</div>
<!-- Sezione Classi -->
<div class="card radius-10">
<div class="card-header">
<div class="d-flex align-items-center">
<div>
<h6 class="mb-0">Classi della scuola</h6>
</div>
<div class="ms-auto">
<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#addClassModal">
Aggiungi Classe
</button>
</div>
</div>
</div>
<div class="card-body">
<?php if (isset($success_message)): ?>
<div class="alert alert-success" role="alert">
<?php echo $success_message; ?>
</div>
<?php endif; ?>
<?php if (isset($error)): ?>
<div class="alert alert-danger" role="alert">
<?php echo $error; ?>
</div>
<?php endif; ?>
<div class="table-responsive">
<table id="classesTable" class="table table-striped table-bordered">
<thead>
<tr>
<th>Categoria</th>
<th>Nome</th>
<th>Descrizione</th>
<th>Foto</th>
<th>Livello</th>
<th>Durata (min)</th>
<th>Posti Massimi</th> <!-- Nuova colonna -->
<th>Giorni</th>
<th>Orario</th>
<!-- Rimossi Inizio e Fine -->
<th>Stato</th>
<th>Insegnante</th>
<th>Azioni</th>
</tr>
</thead>
<tbody>
<?php foreach ($classes as $class): ?>
<tr>
<td><?php echo htmlspecialchars($class['category_name']); ?></td>
<td><?php echo htmlspecialchars($class['name']); ?></td>
<td><?php echo htmlspecialchars($class['description'] ?? ''); ?></td>
<td>
<?php if ($class['photo']): ?>
<img src="<?php echo htmlspecialchars($class['photo']); ?>" alt="Foto Classe" style="max-width: 50px; max-height: 50px;">
<?php else: ?>
Nessuna foto
<?php endif; ?>
</td>
<td><?php echo htmlspecialchars($class['level']); ?></td>
<td><?php echo htmlspecialchars($class['typical_duration'] ?? ''); ?></td>
<td><?php echo htmlspecialchars($class['max_capacity']); ?></td> <!-- Nuova colonna -->
<td><?php echo htmlspecialchars($class['days_of_week']); ?></td>
<td><?php echo htmlspecialchars($class['start_time']); ?></td>
<!-- Rimossi period_start e period_end -->
<td>
<span class="badge <?php echo $class['status'] === 'active' ? 'bg-success' : 'bg-danger'; ?>">
<?php echo $class['status'] === 'active' ? 'Attivo' : 'Inattivo'; ?>
</span>
</td>
<td>
<?php if ($class['teacher_id']): ?>
<button type="button" class="btn btn-sm btn-info" data-bs-toggle="modal" data-bs-target="#assignTeacherModal"
onclick='fillAssignTeacherModal(<?php echo json_encode([
"class_id" => $class['id'],
"teacher_id" => $class['teacher_id']
]); ?>)'>
<?php echo htmlspecialchars($class['teacher_first_name'] . ' ' . $class['teacher_last_name']); ?>
</button>
<?php else: ?>
<button type="button" class="btn btn-sm btn-secondary" data-bs-toggle="modal" data-bs-target="#assignTeacherModal"
onclick='fillAssignTeacherModal(<?php echo json_encode([
"class_id" => $class['id'],
"teacher_id" => null
]); ?>)'>
Non assegnata
</button>
<?php endif; ?>
</td>
<td>
<button type="button" class="btn btn-sm btn-warning" data-bs-toggle="modal" data-bs-target="#editClassModal"
onclick='fillEditModal(<?php echo json_encode([
"id" => $class['id'],
"class_category_id" => $class['class_category_id'],
"name" => htmlspecialchars($class['name'], ENT_QUOTES),
"description" => htmlspecialchars($class['description'] ?? '', ENT_QUOTES),
"requirements" => htmlspecialchars($class['requirements'] ?? '', ENT_QUOTES),
"level" => $class['level'],
"typical_duration" => $class['typical_duration'] ?? '',
"max_capacity" => $class['max_capacity'],
"days_of_week" => htmlspecialchars($class['days_of_week'], ENT_QUOTES),
"start_time" => $class['start_time'],
"status" => $class['status']
]); ?>)'
data-bs-toggle="tooltip" data-bs-placement="top" title="Modifica">
<i class="bx bx-edit"></i>
</button>
<form action="" method="POST" style="display:inline;" onsubmit="return confirm('Sei sicuro di voler eliminare questa classe?');">
<input type="hidden" name="action" value="delete">
<input type="hidden" name="id" value="<?php echo $class['id']; ?>">
<button type="submit" class="btn btn-sm btn-danger" data-bs-toggle="tooltip" data-bs-placement="top" title="Elimina">
<i class="bx bx-trash"></i>
</button>
</form>
<button type="button" class="btn btn-sm btn-success" data-bs-toggle="modal" data-bs-target="#propagateClassModal"
onclick='fillPropagateModal(<?php echo json_encode([
"class_id" => $class['id']
]); ?>)'
data-bs-toggle="tooltip" data-bs-placement="top" title="Propaga">
<i class="bx bx-broadcast"></i> Propaga
</button>
<button type="button" class="btn btn-sm btn-danger" data-bs-toggle="modal" data-bs-target="#removePropagationModal"
onclick='fillRemovePropagationModal(<?php echo json_encode([
"class_id" => $class['id']
]); ?>)'
data-bs-toggle="tooltip" data-bs-placement="top" title="Rimuovi Propagazione">
<i class="bx bx-undo"></i>
</button>
<a href="class_sessions.php?class_id=<?php echo $class['id']; ?>" class="btn btn-sm btn-primary" data-bs-toggle="tooltip" data-bs-placement="top" title="Lezioni">
<i class="bx bx-calendar-event"></i>
</a>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
</div>
</div>
<!-- Spazio per future sezioni -->
<!-- Puoi aggiungere altre sezioni qui sotto, come statistiche, eventi, ecc. -->
</div>
</div>
<!-- Modale per aggiungere una classe -->
<div class="modal fade" id="addClassModal" tabindex="-1" aria-labelledby="addClassModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="addClassModalLabel">Aggiungi Classe</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<form action="" method="POST" enctype="multipart/form-data">
<div class="modal-body">
<input type="hidden" name="action" value="add">
<div class="row">
<div class="col-md-6 mb-3">
<label for="add_class_category_id" class="form-label">Categoria</label>
<select class="form-control" id="add_class_category_id" name="class_category_id" required>
<option value="">Seleziona una categoria</option>
<?php foreach ($categories as $category): ?>
<option value="<?php echo $category['id']; ?>"><?php echo htmlspecialchars($category['name']); ?></option>
<?php endforeach; ?>
</select>
</div>
<div class="col-md-6 mb-3">
<label for="add_name" class="form-label">Nome</label>
<input type="text" class="form-control" id="add_name" name="name" required>
</div>
</div>
<div class="mb-3">
<label for="add_description" class="form-label">Descrizione</label>
<textarea class="form-control" id="add_description" name="description" rows="3"></textarea>
</div>
<div class="mb-3">
<label for="add_photo" class="form-label">Foto</label>
<input type="file" class="form-control" id="add_photo" name="photo" accept="image/*">
</div>
<div class="mb-3">
<label for="add_requirements" class="form-label">Requisiti</label>
<textarea class="form-control" id="add_requirements" name="requirements" rows="2"></textarea>
</div>
<div class="row">
<div class="col-md-4 mb-3">
<label for="add_level" class="form-label">Livello</label>
<select class="form-control" id="add_level" name="level" required>
<option value="beginner">Beginner</option>
<option value="intermediate">Intermediate</option>
<option value="advanced">Advanced</option>
</select>
</div>
<div class="col-md-4 mb-3">
<label for="add_typical_duration" class="form-label">Durata Tipica (min)</label>
<input type="number" class="form-control" id="add_typical_duration" name="typical_duration">
</div>
<div class="col-md-4 mb-3">
<label for="add_max_capacity" class="form-label">Posti Massimi</label>
<input type="number" class="form-control" id="add_max_capacity" name="max_capacity" min="0" required>
</div>
</div>
<div class="mb-3">
<label for="add_days_of_week" class="form-label">Giorni della Settimana</label>
<input type="text" class="form-control" id="add_days_of_week" name="days_of_week" placeholder="Es. Lun, Mer, Ven" required>
</div>
<div class="row">
<div class="col-md-12 mb-3">
<label for="add_start_time" class="form-label">Orario di Inizio</label>
<input type="time" class="form-control" id="add_start_time" name="start_time" required>
</div>
<!-- Rimossi period_start e period_end -->
</div>
<div class="mb-3">
<label for="add_status" class="form-label">Stato</label>
<div class="form-check form-switch">
<input class="form-check-input" type="checkbox" id="add_status" name="status" value="active" checked>
<label class="form-check-label" for="add_status">Attivo</label>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Chiudi</button>
<button type="submit" class="btn btn-primary">Aggiungi</button>
</div>
</form>
</div>
</div>
</div>
<!-- Modale per modificare una classe -->
<div class="modal fade" id="editClassModal" tabindex="-1" aria-labelledby="editClassModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="editClassModalLabel">Modifica Classe</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<form action="" method="POST" enctype="multipart/form-data">
<div class="modal-body">
<input type="hidden" name="action" value="edit">
<input type="hidden" name="id" id="edit_id">
<div class="row">
<div class="col-md-6 mb-3">
<label for="edit_class_category_id" class="form-label">Categoria</label>
<select class="form-control" id="edit_class_category_id" name="class_category_id" required>
<option value="">Seleziona una categoria</option>
<?php foreach ($categories as $category): ?>
<option value="<?php echo $category['id']; ?>"><?php echo htmlspecialchars($category['name']); ?></option>
<?php endforeach; ?>
</select>
</div>
<div class="col-md-6 mb-3">
<label for="edit_name" class="form-label">Nome</label>
<input type="text" class="form-control" id="edit_name" name="name" required>
</div>
</div>
<div class="mb-3">
<label for="edit_description" class="form-label">Descrizione</label>
<textarea class="form-control" id="edit_description" name="description" rows="3"></textarea>
</div>
<div class="mb-3">
<label for="edit_photo" class="form-label">Foto</label>
<input type="file" class="form-control" id="edit_photo" name="photo" accept="image/*">
</div>
<div class="mb-3">
<label for="edit_requirements" class="form-label">Requisiti</label>
<textarea class="form-control" id="edit_requirements" name="requirements" rows="2"></textarea>
</div>
<div class="row">
<div class="col-md-4 mb-3">
<label for="edit_level" class="form-label">Livello</label>
<select class="form-control" id="edit_level" name="level" required>
<option value="beginner">Beginner</option>
<option value="intermediate">Intermediate</option>
<option value="advanced">Advanced</option>
</select>
</div>
<div class="col-md-4 mb-3">
<label for="edit_typical_duration" class="form-label">Durata Tipica (min)</label>
<input type="number" class="form-control" id="edit_typical_duration" name="typical_duration">
</div>
<div class="col-md-4 mb-3">
<label for="edit_max_capacity" class="form-label">Posti Massimi</label>
<input type="number" class="form-control" id="edit_max_capacity" name="max_capacity" min="0" required>
</div>
</div>
<div class="mb-3">
<label for="edit_days_of_week" class="form-label">Giorni della Settimana</label>
<input type="text" class="form-control" id="edit_days_of_week" name="days_of_week" required>
</div>
<div class="row">
<div class="col-md-12 mb-3">
<label for="edit_start_time" class="form-label">Orario di Inizio</label>
<input type="time" class="form-control" id="edit_start_time" name="start_time" required>
</div>
<!-- Rimossi period_start e period_end -->
</div>
<div class="mb-3">
<label for="edit_status" class="form-label">Stato</label>
<div class="form-check form-switch">
<input class="form-check-input" type="checkbox" id="edit_status" name="status" value="active">
<label class="form-check-label" for="edit_status">Attivo</label>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Chiudi</button>
<button type="submit" class="btn btn-primary">Salva Modifiche</button>
</div>
</form>
</div>
</div>
</div>
<!-- Modale per assegnare un insegnante -->
<div class="modal fade" id="assignTeacherModal" tabindex="-1" aria-labelledby="assignTeacherModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="assignTeacherModalLabel">Assegna Insegnante</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<form action="" method="POST">
<div class="modal-body">
<input type="hidden" name="action" value="assign_teacher">
<input type="hidden" name="class_id" id="assign_class_id">
<div class="mb-3">
<label for="assign_teacher_id" class="form-label">Seleziona Insegnante</label>
<select class="form-control" id="assign_teacher_id" name="teacher_id">
<option value="">Nessun insegnante (Non assegnata)</option>
<?php foreach ($teachers as $teacher): ?>
<option value="<?php echo $teacher['id']; ?>">
<?php echo htmlspecialchars($teacher['first_name'] . ' ' . $teacher['last_name']); ?>
</option>
<?php endforeach; ?>
</select>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Chiudi</button>
<button type="submit" class="btn btn-primary">Assegna</button>
</div>
</form>
</div>
</div>
</div>
<!-- Modale per propagare le sessioni -->
<div class="modal fade" id="propagateClassModal" tabindex="-1" aria-labelledby="propagateClassModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="propagateClassModalLabel">Propaga Sessioni</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<form action="" method="POST">
<div class="modal-body">
<input type="hidden" name="action" value="propagate_sessions">
<input type="hidden" name="class_id" id="propagate_class_id">
<div class="mb-3">
<label for="propagate_start_date" class="form-label">Data Inizio</label>
<input type="date" class="form-control" id="propagate_start_date" name="start_date" required>
</div>
<div class="mb-3">
<label for="propagate_end_date" class="form-label">Data Fine</label>
<input type="date" class="form-control" id="propagate_end_date" name="end_date" required>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Chiudi</button>
<button type="submit" class="btn btn-success">Propaga</button>
</div>
</form>
</div>
</div>
</div>
<!-- Modale per rimuovere una propagazione -->
<div class="modal fade" id="removePropagationModal" tabindex="-1" aria-labelledby="removePropagationModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="removePropagationModalLabel">Rimuovi Propagazione</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<form action="" method="POST">
<div class="modal-body">
<input type="hidden" name="action" value="remove_propagation">
<input type="hidden" name="class_id" id="remove_propagation_class_id">
<div class="mb-3">
<label for="remove_propagation_id" class="form-label">ID Propagazione</label>
<input type="text" class="form-control" id="remove_propagation_id" name="propagation_id" required>
<small class="form-text text-muted">Inserisci l'ID della propagazione da rimuovere (lo trovi nel messaggio di successo dopo la propagazione).</small>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Chiudi</button>
<button type="submit" class="btn btn-danger">Rimuovi</button>
</div>
</form>
</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 inizializzare DataTables e gestire i modali -->
<script>
$(document).ready(function() {
$('#classesTable').DataTable({
"language": {
"url": "//cdn.datatables.net/plug-ins/1.10.25/i18n/Italian.json"
}
});
});
function fillEditModal(data) {
document.getElementById('edit_id').value = data.id;
document.getElementById('edit_class_category_id').value = data.class_category_id;
document.getElementById('edit_name').value = data.name;
document.getElementById('edit_description').value = data.description;
document.getElementById('edit_requirements').value = data.requirements;
document.getElementById('edit_level').value = data.level;
document.getElementById('edit_typical_duration').value = data.typical_duration;
document.getElementById('edit_max_capacity').value = data.max_capacity; // Nuovo campo
document.getElementById('edit_days_of_week').value = data.days_of_week;
document.getElementById('edit_start_time').value = data.start_time;
document.getElementById('edit_status').checked = (data.status === 'active');
}
function fillAssignTeacherModal(data) {
document.getElementById('assign_class_id').value = data.class_id;
document.getElementById('assign_teacher_id').value = data.teacher_id || '';
}
function fillPropagateModal(data) {
document.getElementById('propagate_class_id').value = data.class_id;
}
</script>
</body>
</html>