468 lines
25 KiB
PHP
468 lines
25 KiB
PHP
<?php
|
|
require_once('include/headscript.php');
|
|
|
|
/**
|
|
* Connessione unica PDO (singleton).
|
|
*/
|
|
$pdo = DBHandlerSelect::getInstance()->getConnection();
|
|
|
|
function e($value): string
|
|
{
|
|
return htmlspecialchars((string) $value, ENT_QUOTES, 'UTF-8');
|
|
}
|
|
|
|
$message = $_GET['message'] ?? 'N';
|
|
$insertFeedback = null;
|
|
|
|
/* -------------------------------------------------------------------------
|
|
* Inserimento nuova classe (POST) con prepared statement
|
|
* ---------------------------------------------------------------------- */
|
|
if (isset($_POST['classinsert']) && $_POST['classinsert'] === 'Y') {
|
|
$servicename = trim($_POST['servicename'] ?? '');
|
|
$wpcatalog = $_POST['wpcatalognumber'] ?? '';
|
|
$day = trim($_POST['classdayday'] ?? '');
|
|
$time = trim($_POST['classtime'] ?? '');
|
|
$category = $_POST['servicecategory'] ?? '';
|
|
$maxcapacity = $_POST['maxcapacity'] ?? '';
|
|
$colorclass = trim($_POST['colorclass'] ?? '');
|
|
$classduration = $_POST['classduration'] ?? '';
|
|
|
|
if ($servicename === '') {
|
|
$insertFeedback = ['type' => 'error', 'text' => 'La descrizione della classe è obbligatoria.'];
|
|
} else {
|
|
$sql = "INSERT INTO service
|
|
(servicename, wpcatalognumber, day, time, category, maxcapacity, colorclass, classduration)
|
|
VALUES
|
|
(:servicename, :wpcatalog, :day, :time, :category, :maxcapacity, :colorclass, :classduration)";
|
|
$stmt = $pdo->prepare($sql);
|
|
$ok = $stmt->execute([
|
|
':servicename' => $servicename,
|
|
':wpcatalog' => $wpcatalog !== '' ? (int) $wpcatalog : null,
|
|
':day' => $day,
|
|
':time' => $time,
|
|
':category' => $category !== '' ? (int) $category : null,
|
|
':maxcapacity' => $maxcapacity !== '' ? (int) $maxcapacity : null,
|
|
':colorclass' => $colorclass,
|
|
':classduration' => $classduration !== '' ? (float) $classduration : null,
|
|
]);
|
|
|
|
if ($ok) {
|
|
// Redirect per evitare re-invio del form al refresh (pattern PRG)
|
|
header('Location: ' . $_SERVER['PHP_SELF'] . '?message=inserted');
|
|
exit;
|
|
}
|
|
$insertFeedback = ['type' => 'error', 'text' => 'Errore durante l\'inserimento della classe. Riprova.'];
|
|
}
|
|
}
|
|
|
|
/* -------------------------------------------------------------------------
|
|
* Categorie per il dropdown
|
|
* ---------------------------------------------------------------------- */
|
|
$categories = $pdo->query("SELECT idservicecategory, namecategory FROM servicecategory ORDER BY namecategory")->fetchAll();
|
|
|
|
/* -------------------------------------------------------------------------
|
|
* Elenco classi esistenti
|
|
* ---------------------------------------------------------------------- */
|
|
$services = $pdo->query(
|
|
"SELECT service.*, servicecategory.namecategory
|
|
FROM service
|
|
LEFT JOIN servicecategory ON service.category = servicecategory.idservicecategory
|
|
ORDER BY service.servicename"
|
|
)->fetchAll();
|
|
?>
|
|
<!doctype html>
|
|
<html lang="it">
|
|
|
|
<head>
|
|
<meta charset="utf-8" />
|
|
<title>YogiBook - Inserimento e Propagazione Classi</title>
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<meta content="YogiBook - Prenotazione facile YogaSoul" name="description" />
|
|
<meta content="Advanced Creative Solutions" name="author" />
|
|
<link rel="shortcut icon" href="assets/images/favicon.ico">
|
|
|
|
<link href="assets/css/bootstrap.min.css" id="bootstrap-style" rel="stylesheet" type="text/css" />
|
|
<link href="assets/css/icons.min.css" rel="stylesheet" type="text/css" />
|
|
<link href="assets/css/app.min.css" id="app-style" rel="stylesheet" type="text/css" />
|
|
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css">
|
|
<link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
|
|
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/spectrum/1.8.1/spectrum.min.css">
|
|
|
|
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
|
|
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
|
|
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/spectrum/1.8.1/spectrum.min.js"></script>
|
|
|
|
<style>
|
|
.admin-card {
|
|
border: none;
|
|
border-radius: 14px;
|
|
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.06);
|
|
}
|
|
|
|
.admin-card .card-body {
|
|
padding: 26px 30px;
|
|
}
|
|
|
|
.section-title {
|
|
font-size: 15px;
|
|
font-weight: 700;
|
|
letter-spacing: 0.04em;
|
|
text-transform: uppercase;
|
|
color: #6b7280;
|
|
margin-bottom: 4px;
|
|
}
|
|
|
|
.section-lead {
|
|
color: #9ca3af;
|
|
font-size: 14px;
|
|
margin-bottom: 22px;
|
|
}
|
|
|
|
.form-label {
|
|
font-weight: 600;
|
|
font-size: 14px;
|
|
color: #374151;
|
|
}
|
|
|
|
.form-control,
|
|
.form-select {
|
|
border-radius: 8px;
|
|
border: 1px solid #e2e4e9;
|
|
padding: 10px 12px;
|
|
}
|
|
|
|
.form-control:focus,
|
|
.form-select:focus {
|
|
border-color: #1ebf73;
|
|
box-shadow: 0 0 0 3px rgba(30, 191, 115, 0.12);
|
|
}
|
|
|
|
.btn-save {
|
|
border-radius: 8px;
|
|
padding: 10px 26px;
|
|
font-weight: 600;
|
|
}
|
|
|
|
.class-table thead th {
|
|
font-size: 12px;
|
|
text-transform: uppercase;
|
|
letter-spacing: 0.03em;
|
|
color: #6b7280;
|
|
border-bottom: 2px solid #eef0f3;
|
|
}
|
|
|
|
.class-table td {
|
|
vertical-align: middle;
|
|
}
|
|
|
|
.color-dot {
|
|
display: inline-block;
|
|
width: 14px;
|
|
height: 14px;
|
|
border-radius: 50%;
|
|
border: 1px solid rgba(0, 0, 0, 0.1);
|
|
vertical-align: middle;
|
|
margin-right: 6px;
|
|
}
|
|
|
|
.expanded-row {
|
|
display: none;
|
|
}
|
|
|
|
.expanded-row.expanded {
|
|
display: table-row;
|
|
}
|
|
|
|
.expanded-content {
|
|
background: #f8fbf9;
|
|
border-radius: 10px;
|
|
padding: 18px 20px;
|
|
margin: 8px 0;
|
|
}
|
|
|
|
.action-btns .btn {
|
|
margin: 2px;
|
|
}
|
|
</style>
|
|
</head>
|
|
|
|
<body>
|
|
<div id="layout-wrapper">
|
|
<header id="page-topbar" class="isvertical-topbar">
|
|
<div class="navbar-header">
|
|
<div class="d-flex">
|
|
<?php include('include/logoarea.php'); ?>
|
|
<button type="button" class="btn btn-sm px-3 font-size-24 header-item waves-effect vertical-menu-btn">
|
|
<i class="bx bx-menu align-middle"></i>
|
|
</button>
|
|
<div class="page-title-box align-self-center d-none d-md-block">
|
|
<h4 class="page-title mb-0">Inserimento e Propagazione Classi</h4>
|
|
</div>
|
|
</div>
|
|
<div class="d-flex">
|
|
<?php include('include/languageselection.php'); ?>
|
|
<?php include('include/profiletopbar.php'); ?>
|
|
</div>
|
|
</div>
|
|
</header>
|
|
<?php include('include/sidebar.php'); ?>
|
|
<header class="ishorizontal-topbar">
|
|
<div class="navbar-header">
|
|
<div class="d-flex"></div>
|
|
</div>
|
|
<div class="topnav">
|
|
<div class="container-fluid">
|
|
<nav class="navbar navbar-light navbar-expand-lg topnav-menu"></nav>
|
|
</div>
|
|
</div>
|
|
</header>
|
|
|
|
<div class="main-content">
|
|
<div class="page-content">
|
|
<div class="container-fluid">
|
|
|
|
<?php if ($message === 'inserted') : ?>
|
|
<div class="alert alert-success" role="alert">Classe inserita con successo.</div>
|
|
<?php endif; ?>
|
|
<?php if ($message === 'success') : ?>
|
|
<div class="alert alert-success" role="alert">Propagazione avvenuta con successo.</div>
|
|
<?php endif; ?>
|
|
<?php if ($insertFeedback) : ?>
|
|
<div class="alert alert-<?php echo $insertFeedback['type'] === 'success' ? 'success' : 'danger'; ?>" role="alert">
|
|
<?php echo e($insertFeedback['text']); ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<!-- Form inserimento classe -->
|
|
<div class="row">
|
|
<div class="col-12">
|
|
<div class="card admin-card mb-4">
|
|
<div class="card-body">
|
|
<div class="section-title">Nuova classe</div>
|
|
<p class="section-lead">Inserisci i dettagli della classe da aggiungere al catalogo.</p>
|
|
|
|
<form method="post" name="insertclass" id="insertclass">
|
|
<input type="hidden" name="classinsert" value="Y">
|
|
|
|
<div class="mb-3">
|
|
<label for="servicename" class="form-label">Descrizione classe</label>
|
|
<input type="text" class="form-control" placeholder="Es. Hatha Yoga" id="servicename" name="servicename" required>
|
|
</div>
|
|
|
|
<div class="row">
|
|
<div class="col-md-6">
|
|
<div class="mb-3">
|
|
<label for="wpcatalognumber" class="form-label">WP catalog number</label>
|
|
<input type="text" class="form-control" placeholder="WP Number" id="wpcatalognumber" name="wpcatalognumber">
|
|
</div>
|
|
</div>
|
|
<div class="col-md-6">
|
|
<div class="mb-3">
|
|
<label for="classdayday" class="form-label">Giorno</label>
|
|
<select class="form-select" id="classdayday" name="classdayday">
|
|
<option value="">Seleziona</option>
|
|
<option value="Monday">Lunedì</option>
|
|
<option value="Tuesday">Martedì</option>
|
|
<option value="Wednesday">Mercoledì</option>
|
|
<option value="Thursday">Giovedì</option>
|
|
<option value="Friday">Venerdì</option>
|
|
<option value="Saturday">Sabato</option>
|
|
<option value="Sunday">Domenica</option>
|
|
</select>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="row">
|
|
<div class="col-lg-4">
|
|
<div class="mb-3">
|
|
<label for="classtime" class="form-label">Ora</label>
|
|
<input type="text" class="form-control" placeholder="Es. 18:30" id="classtime" name="classtime">
|
|
</div>
|
|
</div>
|
|
<div class="col-lg-4">
|
|
<div class="mb-3">
|
|
<label for="classduration" class="form-label">Durata (ore)</label>
|
|
<input type="text" class="form-control" placeholder="Es. 1.5" id="classduration" name="classduration">
|
|
</div>
|
|
</div>
|
|
<div class="col-lg-4">
|
|
<div class="mb-3">
|
|
<label for="servicecategory" class="form-label">Categoria</label>
|
|
<select name="servicecategory" id="servicecategory" class="form-select">
|
|
<option value="">Seleziona</option>
|
|
<?php foreach ($categories as $cat) : ?>
|
|
<option value="<?php echo e($cat['idservicecategory']); ?>">
|
|
<?php echo e($cat['namecategory']); ?>
|
|
</option>
|
|
<?php endforeach; ?>
|
|
</select>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="row">
|
|
<div class="col-lg-4">
|
|
<div class="mb-3">
|
|
<label for="maxcapacity" class="form-label">Capacità massima</label>
|
|
<input type="text" class="form-control" placeholder="Es. 12" id="maxcapacity" name="maxcapacity">
|
|
</div>
|
|
</div>
|
|
<div class="col-lg-4">
|
|
<div class="mb-3">
|
|
<label for="colorclass" class="form-label">Colore classe</label>
|
|
<input type="text" class="form-control" id="colorclass" name="colorclass" value="#1ebf73">
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<button type="submit" class="btn btn-primary btn-save">Inserisci classe</button>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Elenco classi -->
|
|
<div class="row">
|
|
<div class="col-12">
|
|
<div class="card admin-card">
|
|
<div class="card-body">
|
|
<div class="section-title">Classi esistenti</div>
|
|
<p class="section-lead">Propaga una classe sul calendario, associala o modificane i dettagli.</p>
|
|
|
|
<div class="table-responsive">
|
|
<table class="table class-table align-middle mb-0">
|
|
<thead>
|
|
<tr>
|
|
<th>Classe</th>
|
|
<th>Giorno</th>
|
|
<th>Orario</th>
|
|
<th>Durata</th>
|
|
<th>Categoria</th>
|
|
<th class="text-end">Azioni</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php if (empty($services)) : ?>
|
|
<tr>
|
|
<td colspan="6" class="text-center text-muted py-4">Nessuna classe presente.</td>
|
|
</tr>
|
|
<?php else : ?>
|
|
<?php foreach ($services as $svc) : ?>
|
|
<tr>
|
|
<td>
|
|
<span class="color-dot" style="background-color: <?php echo e($svc['colorclass'] ?: '#ccc'); ?>;"></span>
|
|
<span class="font-size-14"><?php echo e($svc['servicename']); ?></span>
|
|
</td>
|
|
<td><?php echo e($svc['day']); ?></td>
|
|
<td><?php echo e($svc['time']); ?></td>
|
|
<td>
|
|
<i class="mdi mdi-clock-time-nine-outline align-middle font-size-16 me-1"></i>
|
|
<?php echo e($svc['classduration']); ?>
|
|
</td>
|
|
<td><?php echo e($svc['namecategory']); ?></td>
|
|
<td class="text-end action-btns">
|
|
<button type="button" class="btn btn-primary btn-sm toggle-form">Propaga</button>
|
|
<a href="associate-services.php?id=<?php echo (int) $svc['idservice']; ?>">
|
|
<button type="button" class="btn btn-info btn-sm">Associa</button>
|
|
</a>
|
|
<a href="updateservice.php?idservice=<?php echo (int) $svc['idservice']; ?>">
|
|
<button type="button" class="btn btn-warning btn-sm">
|
|
<i class="mdi mdi-lead-pencil font-size-16 align-middle"></i>
|
|
</button>
|
|
</a>
|
|
<a href="cancelservice.php?idservice=<?php echo (int) $svc['idservice']; ?>">
|
|
<button type="button" class="btn btn-danger btn-sm">
|
|
<i class="bx bx-block font-size-16 align-middle"></i>
|
|
</button>
|
|
</a>
|
|
</td>
|
|
</tr>
|
|
<tr class="expanded-row">
|
|
<td colspan="6">
|
|
<div class="expanded-content">
|
|
<form class="calendar-form" method="post" action="nextdateclass.php">
|
|
<div class="row">
|
|
<div class="col-md-6">
|
|
<div class="mb-3">
|
|
<label class="form-label">Data inizio</label>
|
|
<input type="text" class="datepicker form-control" name="propagatestartdate" required>
|
|
</div>
|
|
</div>
|
|
<div class="col-md-6">
|
|
<div class="mb-3">
|
|
<label class="form-label">Data fine</label>
|
|
<input type="text" class="datepicker form-control" name="propagateenddate" required>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<input type="hidden" name="idservice" value="<?php echo (int) $svc['idservice']; ?>">
|
|
<input type="hidden" name="timeclass" value="<?php echo e($svc['time']); ?>">
|
|
<input type="hidden" name="dayclass" value="<?php echo e($svc['day']); ?>">
|
|
<input type="hidden" name="durationtime" value="<?php echo e($svc['classduration']); ?>">
|
|
<button type="submit" class="btn btn-primary btn-save">Propaga sul calendario</button>
|
|
</form>
|
|
</div>
|
|
</td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
<?php endif; ?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
</div>
|
|
<?php include('include/footer.php'); ?>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<script src="assets/libs/bootstrap/js/bootstrap.bundle.min.js"></script>
|
|
<script src="assets/libs/metismenujs/metismenujs.min.js"></script>
|
|
<script src="assets/libs/simplebar/simplebar.min.js"></script>
|
|
<script src="assets/libs/eva-icons/eva.min.js"></script>
|
|
<script src="assets/js/app.js"></script>
|
|
|
|
<script>
|
|
$(document).ready(function() {
|
|
// Datepicker sui campi di propagazione
|
|
$(".datepicker").datepicker({
|
|
dateFormat: "yy-mm-dd"
|
|
});
|
|
|
|
// Color picker spectrum collegato al VERO campo colorclass (ora viene salvato)
|
|
$('#colorclass').spectrum({
|
|
preferredFormat: 'hex',
|
|
showInput: true,
|
|
showPalette: true,
|
|
palette: [
|
|
["#FF0000", "#00FF00", "#0000FF"],
|
|
["#1ebf73", "#f39c12", "#8e44ad"]
|
|
],
|
|
change: function(color) {
|
|
$('#colorclass').val(color.toHexString());
|
|
}
|
|
});
|
|
});
|
|
|
|
// Espansione riga propagazione
|
|
document.addEventListener("DOMContentLoaded", function() {
|
|
document.querySelectorAll(".toggle-form").forEach(function(button) {
|
|
button.addEventListener("click", function() {
|
|
var row = this.closest("tr");
|
|
var expandedRow = row.nextElementSibling;
|
|
if (expandedRow && expandedRow.classList.contains("expanded-row")) {
|
|
expandedRow.classList.toggle("expanded");
|
|
}
|
|
});
|
|
});
|
|
});
|
|
</script>
|
|
</body>
|
|
|
|
</html>
|