yogibook_aury_new/public/adminpanel-bck090525.php
2025-09-01 15:06:58 +02:00

884 lines
28 KiB
PHP

<?php require_once('include/headscript.php'); ?>
<?php // require_once('Connections/bkngstm.php'); ?>
<?php // require_once('webassist/mysqli/rsobj.php'); ?>
<?php // require_once('webassist/mysqli/queryobj.php'); ?>
<?php // optionquery
$optionquery = new WA_MySQLi_RS("optionquery",$bkngstm,0);
$optionquery->setQuery("SELECT * FROM option");
$optionquery->execute();
?>
<?php
$bookedclass = new WA_MySQLi_RS("bookedclass", $bkngstm, 0);
// Verifica se è stata specificata una richiesta per cambiare il mese
if (isset($_GET['prev_month'])) {
$currentMonthStart = $_GET['prev_month'] . '-01';
} elseif (isset($_GET['next_month'])) {
$currentMonthStart = $_GET['next_month'] . '-01';
} else {
$currentMonthStart = date("Y-m-01");
}
$currentDate = date("Y-m-d");
// Modifica: Se la data odierna è dopo l'inizio del mese corrente, imposta la data odierna come inizio
//if ($currentDate > $currentMonthStart) {
// $currentMonthStart = $currentDate;
//}
$currentMonthEnd = date("Y-m-t", strtotime($currentMonthStart));
$bookedclass->setQuery("SELECT * FROM serviceschedule
LEFT JOIN service ON serviceschedule.idservice = service.idservice
WHERE serviceschedule.dateschedule BETWEEN '$currentMonthStart' AND DATE_ADD('$currentMonthEnd', INTERVAL 1 DAY) ORDER BY serviceschedule.dateschedule");
$bookedclass->execute();
?>
<?php
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connessione fallita: " . $conn->connect_error);
}
// ID dell'utente per il quale vuoi filtrare gli ordini
$userid = 1;
// Query per ottenere la somma dei ticket per ogni ordine dell'utente
$query = "SELECT iduser, idorderbook, SUM(nticket) as total_tickets
FROM orderbook
WHERE iduser = $userid
GROUP BY iduser";
$result = $conn->query($query);
if (!$result) {
die("Query fallita: " . $conn->error);
}
if ($result->num_rows > 0) {
while ($row = $result->fetch_assoc()) {
$idOrdine = $row["idorderbook"];
$totalTickets = $row["total_tickets"];
}
} else {
$totalTickets = 0; // Imposta a zero se non ci sono righe nella query
}
$conn->close();
?>
<?php //check tickets
// Connessione al database
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connessione al database fallita: " . $conn->connect_error);
}
// ID dell'utente per il quale si desidera eseguire la query
$iduser = 1; // Sostituisci con l'ID utente desiderato
// Data e ora attuali
$currentDateTime = date("Y-m-d H:i:s");
// Query per contare i record con data e ora passate e future
$query = "SELECT COUNT(*) AS total,
SUM(CASE WHEN serviceschedule.dateschedule <= '$currentDateTime' THEN 1 ELSE 0 END) AS passed,
SUM(CASE WHEN serviceschedule.dateschedule > '$currentDateTime' THEN 1 ELSE 0 END) AS future
FROM bookingclass
LEFT JOIN serviceschedule ON bookingclass.idserviceschedule = serviceschedule.idserviceschedule
WHERE bookingclass.iduser = $iduser";
$result = $conn->query($query);
if ($result) {
$row = $result->fetch_assoc();
$totalRecords = $row['total'];
$passedRecords = $row['passed'];
$futureRecords = $row['future'];
}
// Chiusura della connessione
$conn->close();
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>YogiBook - Prenotazioni YogaSoul</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" />
<!-- App favicon -->
<link rel="shortcut icon" href="assets/images/favicon.ico">
<!-- Bootstrap Css -->
<link href="assets/css/bootstrap.min.css" id="bootstrap-style" rel="stylesheet" type="text/css" />
<!-- Icons Css -->
<link href="assets/css/icons.min.css" rel="stylesheet" type="text/css" />
<!-- App Css-->
<link href="assets/css/app.min.css" id="app-style" rel="stylesheet" type="text/css" />
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css">
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@10"></script>
<script>
// Function to handle the click event on the "Rimuovi" button
function handleRemoveClick(idbookingclass) {
// Display SweetAlert confirmation
Swal.fire({
title: 'Sei sicuro?',
text: 'Questa azione rimuoverà la persona dalla classe. Vuoi procedere?',
icon: 'warning',
showCancelButton: true,
confirmButtonText: 'Sì, rimuovi!',
cancelButtonText: 'Annulla',
}).then((result) => {
if (result.isConfirmed) {
// If user confirms, redirect to the removebooking.php page
window.location.href = `removebooking.php?idbookingclass=${idbookingclass}`;
}
});
}
</script>
<script>
$(document).ready(function() {
$(".lost-button").click(function() {
var idbookingclass = $(this).data("idbookingclass");
// Mostra un SweetAlert di conferma
Swal.fire({
title: 'Sei sicuro?',
text: 'Vuoi davvero contrassegnare questa lezione come persa?',
icon: 'warning',
showCancelButton: true,
confirmButtonText: 'Sì, contrassegna come persa',
cancelButtonText: 'Annulla'
}).then((result) => {
if (result.isConfirmed) {
// Se l'utente conferma, esegui l'aggiornamento
$.ajax({
url: "aggiorna_campo_lost.php",
method: "POST",
data: { idbookingclass: idbookingclass },
success: function(response) {
// Dopo aver contrassegnato con successo la lezione come persa, reindirizza all'adminpanel
window.location.href = 'adminpanel.php?success=1';
},
error: function() {
Swal.fire('Errore durante l\'aggiornamento', '', 'error');
}
});
}
});
});
});
</script>
<style>
.lost-button {
background-color: orange; /* Imposta il colore arancione */
color: white; /* Imposta il testo in bianco o altro colore a tua scelta */
border: none;
padding: 6px 12px;
border-radius: 4px;
cursor: pointer;
transition: background-color 0.2s;
}
.lost-button:hover {
background-color: darkorange; /* Cambia il colore al passaggio del mouse se lo desideri */
}
.email-search-results {
position: absolute; /* O posizionamento relativo a seconda delle esigenze */
top: 100%; /* Posizionamento rispetto all'elemento padre */
left: 0;
right: 0;
background-color: white; /* Colore di sfondo */
border: 1px solid #ccc; /* Bordo */
max-height: 200px; /* Altezza massima */
overflow-y: auto; /* Scorrimento verticale se i risultati superano l'altezza massima */
z-index: 1000; /* Per sovrapporre altri elementi */
display: none; /* Inizialmente nascosto */
}
.custom-card {
margin: 10px auto;
display: flex;
width: 90%;
max-width: 700px;
background-color: white;
box-shadow: 0px 2px 4px rgba(0, 0, 0, 0.1);
border-radius: 8px;
overflow: hidden;
cursor: pointer;
transition: transform 0.2s;
}
.custom-card:hover {
transform: translateY(-5px);
}
.custom-date-box {
flex: 1;
background-color: red;
color: white;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
padding: 0;
font-size: 60px;
font-weight: bold;
border-top-left-radius: 8px;
border-bottom-left-radius: 8px;
}
.custom-day {
line-height: 1;
}
.custom-month {
font-size: 28px;
}
.custom-event-details {
flex: 2;
display: flex;
flex-direction: column;
padding: 10px 20px;
background-color: #AEEAF5;
}
.custom-heading {
margin-top: 0;
font-size: 24px;
}
.custom-paragraph {
margin-bottom: 5px;
}
.custom-actions {
display: none;
flex-direction: row;
justify-content: space-between;
margin-top: 10px;
}
.custom-card.expanded .custom-actions {
display: flex;
}
.custom-action-button {
background-color: #f0f0f0;
border: none;
padding: 8px 12px;
border-radius: 4px;
cursor: pointer;
transition: background-color 0.2s;
}
.custom-action-button:hover {
background-color: #e0e0e0;
}
@media (max-width: 768px) {
.custom-card {
flex-direction: column;
}
.custom-date-box, .custom-event-details {
width: 100%;
border-radius: 0;
}
.custom-event-time {
font-size: 24px;
}
}
</style>
<style>
.month-navigation {
display: flex;
justify-content: center;
align-items: center;
margin-bottom: 20px;
}
.month-nav-button {
background: none;
border: none;
font-size: 24px;
cursor: pointer;
}
.current-month {
font-size: 24px;
margin: 0 20px;
}
</style>
<script>
function confirmDelete(id, deletePageUrl) {
Swal.fire({
title: "Sei sicuro?",
text: "Questa prenotazione verrà cancellata definitivamente! Ricordati poi di riprogrammare la tua lezione!",
icon: "warning",
showCancelButton: true,
confirmButtonColor: "#d33",
cancelButtonColor: "#3085d6",
confirmButtonText: "Sì, cancella!",
cancelButtonText: "Annulla"
}).then((result) => {
if (result.isConfirmed) {
// Reindirizza direttamente alla pagina di cancellazione con l'ID come parametro.
window.location.href = `deleteclass.php?id=${id}`;
}
});
}
</script>
<style>
.pastel-color {
border: 1px solid #D1C4CC;
padding: 0px;
text-align: center;
border-radius: 10px;
margin-right: 20px; /* Spazio tra i box */
font-size: 18px;
}
.pastel-color.blue {
background-color: #D4E1F1; /* Azzurro pastello */
}
.pastel-color.green {
background-color: #FFD8B5; /* Verde pastello */
}
.pastel-color.pink {
background-color: #C3E6CB; /* Rosa pastello */
}
.pastel-color.purple {
background-color: #F4CCCC; /* Viola pastello */
}
}
@media (max-width: 768px) {
.pastel-color {
margin-right: 0; /* Rimuovi lo spazio tra i box */
margin-bottom: 20px; /* Spazio tra i box */
}
}
</style>
<style>
.booking-details {
margin-top: 10px;
border-top: 1px solid #ccc;
padding-top: 10px;
}
.booking-table {
width: 100%;
border-collapse: collapse;
margin-top: 5px;
border-bottom: 1px solid #ccc;
border: 1px solid #333; /* Aggiunto il bordo grigio scuro */
}
.booking-row td {
padding: 2px;
border-bottom: 1px solid #ccc;
}
.delete-cell {
text-align: left; /* Allinea il contenuto a sinistra */
vertical-align: top; /* Allinea il contenuto in alto */
}
.delete-button {
display: block; /* Per occupare l'intera larghezza del cell */
padding: 6px 12px;
border: none;
background-color: #e74c3c;
color: white;
border-radius: 4px;
cursor: pointer;
font-size: 14px;
}
.delete-button:hover {
background-color: #d64937;
}
</style>
<body>
<!-- <body data-layout="horizontal"> -->
<!-- Begin page -->
<div id="layout-wrapper">
<!-- Top Bar -->
<header id="page-topbar" class="isvertical-topbar">
<div class="navbar-header">
<div class="d-flex">
<!-- LOGO -->
<?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>
<!-- start page title -->
<div class="page-title-box align-self-center d-none d-md-block">
<h4 class="page-title mb-0">Prenotazione Classi</h4>
</div>
<!-- end page title -->
</div>
<div class="d-flex">
<?php include('include/languageselection.php'); ?>
<div class="dropdown d-inline-block">
<button type="button" class="btn header-item noti-icon"
data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<i class="bx bx-search icon-sm align-middle"></i>
</button>
<div class="dropdown-menu dropdown-menu-lg dropdown-menu-end p-0">
<form class="p-2">
<div class="search-box">
<div class="position-relative">
<input type="text" class="form-control rounded bg-light border-0" placeholder="Search...">
<i class="bx bx-search search-icon"></i>
</div>
</div>
</form>
</div>
</div>
<?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>
<!-- ============================================================== -->
<!-- Start right Content here -->
<!-- ============================================================== -->
<div class="main-content">
<div class="page-content">
<div class="container-fluid">
<?php
$toprogram = $totalTickets - $passedRecords - $futureRecords;
?>
<!-- container-fluid -->
</div>
<div class="container-fluid">
<div class="row">
<div class="col-xl-12">
<div class="card">
<div class="card-body">
<div class="">
<div class="row mb-2">
<div class="col-xl-3 col-md-12">
<div class="pb-3 pb-xl-0">
<form class="email-search">
<div class="position-relative">
<h3>Classi</h3>
</div>
</form>
</div>
</div>
<div class="col-xl-9 col-md-12">
<div class="text-sm-end">
<?php if ($toprogram > 0) {
echo '<button type="button" class="btn btn-info btn-rounded waves-effect waves-light mb-2 me-2" data-bs-toggle="modal" data-bs-target=".create-task"><i class="mdi mdi-plus me-1"></i> Programma Lezioni</button>';
}
?>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- container-fluid -->
<?php
if(isset($_GET['success']) && $_GET['success'] == 1) { ?>
<div class="alert alert-danger success-message" role="alert">
Lezione segnata come persa con successo
</div>
<?php
}
?>
<div class="container-fluid">
<!-- starts cards -->
<!-- Aggiungi le frecce per la navigazione tra i mesi -->
<?php
$italianMonths = [
"January" => "Gennaio",
"February" => "Febbraio",
"March" => "Marzo",
"April" => "Aprile",
"May" => "Maggio",
"June" => "Giugno",
"July" => "Luglio",
"August" => "Agosto",
"September" => "Settembre",
"October" => "Ottobre",
"November" => "Novembre",
"December" => "Dicembre"
];
?>
<div class="month-navigation">
<a href="?prev_month=<?php echo date('Y-m', strtotime('-1 month', strtotime($currentMonthStart))); ?>" class="arrow-link">
<i class="fas fa-chevron-left fa-2x"></i>
</a>
<h2><?php echo $italianMonths[date("F", strtotime($currentMonthStart))] . ' ' . date("Y", strtotime($currentMonthStart)); ?></h2>
<a href="?next_month=<?php echo date('Y-m', strtotime('+1 month', strtotime($currentMonthStart))); ?>" class="arrow-link">
<i class="fas fa-chevron-right fa-2x"></i>
</a>
</div>
<?php
$wa_startindex = 0;
if ($bookedclass->TotalRows == 0) {
echo "<p>Classi non presenti per questo mese</p>";
} else {
while (!$bookedclass->atEnd()) {
$wa_startindex = $bookedclass->Index;
?>
<?php
// Data dalla variabile $bookedclass->getColumnVal("dateschedule")
$dateschedule = $bookedclass->getColumnVal("dateschedule");
// Converti la data in un oggetto DateTime
$dateObj = new DateTime($dateschedule);
// Estrai il giorno e il mese in italiano
$dayInItalian = $dateObj->format("d");
$monthInItalian = $dateObj->format("F");
// Mappa dei nomi dei mesi in italiano
$italianMonths = [
"January" => "Gennaio",
"February" => "Febbraio",
"March" => "Marzo",
"April" => "Aprile",
"May" => "Maggio",
"June" => "Giugno",
"July" => "Luglio",
"August" => "Agosto",
"September" => "Settembre",
"October" => "Ottobre",
"November" => "Novembre",
"December" => "Dicembre"
];
// Sostituisci il nome del mese con la versione italiana
$monthInItalian = $italianMonths[$monthInItalian];
?>
<?php
// Data dalla variabile $bookedclass->getColumnVal("dateschedule")
$dateschedule = $bookedclass->getColumnVal("dateschedule");
// Converti la data in un oggetto DateTime
$dateObj = new DateTime($dateschedule);
// Formatta la data nel nuovo formato desiderato
$newDateFormat = $dateObj->format("d-m-Y H:i");
// Calculate the time difference in hours
$currentTime = new DateTime();
$classTime = new DateTime($dateschedule);
$timeDifference = $classTime->diff($currentTime);
$hoursDifference = $timeDifference->h + $timeDifference->days * 24;
// Check if the time difference is less than 6 hours
$timetocancel=$optionquery->getColumnVal("maxbeforetimecancell");
$canBeDeleted = ($hoursDifference >= $timetocancel);
?>
<?php $mysqli = new mysqli($servername, $username, $password, $dbname);
// Esegui una nuova query per ottenere le persone prenotate per l'evento corrente
$eventId = $bookedclass->getColumnVal("idserviceschedule");
$bookingQuery = "SELECT * FROM bookingclass LEFT JOIN auth_users ON bookingclass.iduser=auth_users.id
WHERE bookingclass.idserviceschedule = $eventId AND bookingclass.status='booked'";
$bookingResult = $mysqli->query($bookingQuery);
// Calcola il numero di persone prenotate
$countPersons = $bookingResult->num_rows;
?>
<div class="custom-card" onclick="toggleCard(this)">
<div class="custom-date-box" style="background-color:#3BDD79">
<div class="custom-day"><?php echo $dayInItalian; ?></div>
<div class="custom-month"><?php echo $monthInItalian; ?></div>
</div>
<div class="custom-event-details" style="background-color:<?php echo($bookedclass->getColumnVal("colorclass")); ?>">
<h2 class="custom-heading"><?php echo($bookedclass->getColumnVal("servicename")); ?> -<?php echo $countPersons; ?>/<?php echo($bookedclass->getColumnVal("maxcapacity")); ?></h2>
<p class="custom-paragraph">Quando: <?php echo $newDateFormat; ?></p>
<p class="custom-paragraph">Luogo: via Valassina 62/B Seregno - Sala Contesto Yoga</p>
<div class="custom">
<button class="custom-action-button" onclick="toggleCustomContent(this, 'bookings')"><i class="fas fa-list-plus"></i> Vedi prenotazioni</button>
</div>
<div class="custom-actions">
<table class="booking-table">
<?php while ($booking = $bookingResult->fetch_assoc()) : ?>
<tr class="booking-row">
<?php $idbookedclass = $booking['idbookingclass']; ?>
<td><?php echo $booking['first_name']; ?> <?php echo $booking['last_name']; ?></td>
<td class="delete-cell">
<button class="delete-button" onclick="handleRemoveClick(<?php echo $idbookedclass; ?>)">
<i class="fa fa-trash"></i> Rimuovi
</button>
</td>
<td class="lost-cell">
<button class="lost-button" data-idbookingclass="<?php echo $idbookedclass; ?>">
<i class="fas fa-wind"></i> Persa
</button>
</td>
</tr>
<?php endwhile; ?>
</table>
<form action="inserisci_record.php" method="post">
<label for="name">Nome:</label>
<input type="text" class="name" name="name"><br><br>
<label for="surname">Cognome:</label>
<input type="text" class="surname" name="surname"><br><br>
<label for="email">Email:</label>
<input type="text" class="email" name="email"><br><br>
<input type="hidden" class="userid" name="userid">
<input type="hidden" id="idserviceschedule" name="idserviceschedule" value="<?php echo $bookedclass->getColumnVal("idserviceschedule"); ?>">
<input type="hidden" id="status" name="status" value="booked">
<input type="hidden" id="idorder" name="idorder" value="0">
<input type="hidden" id="idservice" name="idservice" value="<?php echo $bookedclass->getColumnVal("idservice"); ?>">
<input type="hidden" id="bookingstart" name="bookingstart" value="<?php echo $dateschedule; ?>">
<button type="submit">Inserisci</button>
</form>
<div class="search-results"></div>
</div>
<script>
$(document).ready(function() {
$(".surname").on("input", function() {
var searchTerm = $(this).val();
var currentForm = $(this).closest('form'); // Riferimento alla form corrente
if (searchTerm.length >= 2) {
$.ajax({
url: "searchemail.php",
method: "POST",
data: { searchTerm: searchTerm },
dataType: "json",
success: function(data) {
var results = data.results;
currentForm.next('.search-results').empty();
if (results.length > 0) {
currentForm.next('.search-results').append("<p>Seleziona un utente:</p>");
for (var i = 0; i < results.length; i++) {
var user = results[i];
currentForm.next('.search-results').append(
'<div class="user-result" data-email="' + user.email + '" data-userid="' + user.id + '" data-firstname="' + user.first_name + '" data-lastname="' + user.last_name + '">' +
'Email: ' + user.email + ' | Nome: ' + user.first_name + ' | Cognome: ' + user.last_name +
'</div>'
);
}
$(".user-result").click(function() {
var selectedEmail = $(this).data("email");
var selectedUserId = $(this).data("userid");
var selectedFirstName = $(this).data("firstname");
var selectedLastName = $(this).data("lastname");
currentForm.find(".email").val(selectedEmail);
currentForm.find(".userid").val(selectedUserId); // Cambiato ".serid" in ".userid" poiché sembra un errore nel tuo codice
currentForm.find(".name").val(selectedFirstName);
currentForm.find(".surname").val(selectedLastName);
});
}
}
});
} else {
currentForm.next('.search-results').empty();
}
});
});
</script>
</div>
</div>
<script>
function toggleCard(card) {
card.classList.toggle("expanded");
}
function toggleCustomContent(button, content) {
const card = button.closest('.custom-card');
const bookings = card.querySelector('.custom-actions');
const addForm = card.querySelector('.add-booking-form');
if (content === 'bookings') {
bookings.style.display = 'block';
addForm.style.display = 'none';
} else if (content === 'addForm') {
addForm.style.display = 'block';
bookings.style.display = 'none';
}
}
</script>
<?php
$bookedclass->moveNext();
}
}
$bookedclass->moveFirst(); // Ritorna all'inizio del recordset
unset($wa_startindex);
unset($wa_repeatcount);
?>
<!-- Aggiungi altre card qui con le stesse classi -->
<script>
function toggleCard(card) {
card.classList.toggle("expanded");
}
</script>
</div>
</div>
<!-- End Page-content -->
<?php include('include/footer.php'); ?>
</div>
<!-- end main content-->
</div>
<!-- END layout-wrapper -->
<!-- JAVASCRIPT -->
<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>
</body>
</html>