yogibook_aury_new/public/bookingpanel.php

589 lines
25 KiB
PHP

<?php require_once('include/headscript.php'); ?>
<?php
// optionquery
$optionquery = new WA_MySQLi_RS("optionquery", $bkngstm, 0);
$optionquery->setQuery("SELECT * FROM option");
$optionquery->execute();
?>
<?php
// array service possible
$conn = new mysqli($servername, $username, $password, $dbname);
// Verifica della connessione
if ($conn->connect_error) {
die("Connessione al database fallita: " . $conn->connect_error);
}
// Prendi il valore di idservieordered dalla variabile GET o POST
if (isset($_GET['id'])) {
$idpreviousbooking = $_GET['id'];
}
if (isset($_POST['idorder'])) {
$idorder = $_POST['idorder'];
}
if (isset($_GET['idserviceordered'])) {
$idserviceordered = $_GET['idserviceordered'];
}
if (isset($_POST['idserviceordered'])) {
$idserviceordered = $_POST['idserviceordered'];
}
// Recupera la data di scadenza dell'ordine
$expiryQuery = "SELECT expireon FROM orderbook WHERE order_id = ?";
$stmt = $conn->prepare($expiryQuery);
$stmt->bind_param("i", $idpreviousbooking);
$stmt->execute();
$expiryResult = $stmt->get_result();
$expiryDate = null;
if ($expiryResult->num_rows > 0) {
$row = $expiryResult->fetch_assoc();
$expiryDate = new DateTime($row['expireon']);
}
$stmt->close();
// Query sulla tabella associateclass
$sql = "SELECT idassociateservice FROM associateclass WHERE idmainservice = ?";
$stmt = $conn->prepare($sql);
$stmt->bind_param("i", $idserviceordered);
$stmt->execute();
$result = $stmt->get_result();
$idassociateservices = array();
array_push($idassociateservices, $idserviceordered);
if ($result->num_rows > 0) {
while ($row = $result->fetch_assoc()) {
$idassociateservices[] = $row['idassociateservice'];
}
}
$stmt->close();
$conn->close();
?>
<?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");
}
$currentMonthEnd = date("Y-m-t", strtotime($currentMonthStart));
// Aggiungi filtro per la data di scadenza se definita, includendo la data di scadenza
$expiryCondition = '';
if ($expiryDate) {
$expiryCondition = "AND (serviceschedule.dateschedule <= '{$expiryDate->format('Y-m-d 23:59:59')}' OR serviceschedule.dateschedule = '{$expiryDate->format('Y-m-d')}')";
}
$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)
$expiryCondition
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
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connessione al database fallita: " . $conn->connect_error);
}
$iduser = 1; // Sostituisci con l'ID utente desiderato
$currentDateTime = date("Y-m-d H:i:s");
$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'];
}
$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" 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">
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@10"></script>
<style>
.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: lightblue;
}
.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;
}
}
.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;
}
.pastel-color {
border: 1px solid #D1C4CC;
padding: 0px;
text-align: center;
border-radius: 10px;
margin-right: 20px;
font-size: 18px;
}
.pastel-color.blue {
background-color: #D4E1F1;
}
.pastel-color.green {
background-color: #FFD8B5;
}
.pastel-color.pink {
background-color: #C3E6CB;
}
.pastel-color.purple {
background-color: #F4CCCC;
}
@media (max-width: 768px) {
.pastel-color {
margin-right: 0;
margin-bottom: 20px;
}
}
.booking-details {
margin-top: 10px;
border-top: 1px solid #ccc;
padding-top: 10px;
}
.booking-table {
width: 100%;
border-collapse: collapse;
margin-top: 10px;
}
.booking-table td {
padding: 5px;
border-bottom: 1px solid #ccc;
}
.delete-button {
background-color: #ff6347;
color: #fff;
border: none;
padding: 5px 10px;
cursor: pointer;
}
.delete-button:hover {
background-color: #d64937;
}
</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) {
window.location.href = `deleteclass.php?id=${id}`;
}
});
}
</script>
<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">Riprogramma la tua lezione</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
$toprogram = $totalTickets - $passedRecords - $futureRecords;
?>
</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>Riprogrammazione Lezione</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>';
}
?>
<button type="button" class="btn btn-success 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> Acquista Pacchetto Lezioni</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="container-fluid">
<?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))); ?>&idserviceordered=<?php echo $idserviceordered; ?>&id=<?php echo $idpreviousbooking; ?>" 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))); ?>&idserviceordered=<?php echo $idserviceordered; ?>&id=<?php echo $idpreviousbooking; ?>" 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 o oltre la data di scadenza</p>";
} else {
while (!$bookedclass->atEnd()) {
$wa_startindex = $bookedclass->Index;
$dateschedule = $bookedclass->getColumnVal("dateschedule");
$dateObj = new DateTime($dateschedule);
$dayInItalian = $dateObj->format("d");
$monthInItalian = $italianMonths[$dateObj->format("F")];
$newDateFormat = $dateObj->format("d-m-Y H:i");
$currentTime = new DateTime();
$classTime = new DateTime($dateschedule);
$timeDifference = $classTime->diff($currentTime);
$hoursDifference = $timeDifference->h + $timeDifference->days * 24;
$timetocancel = $optionquery->getColumnVal("maxbeforetimecancell");
$canBeDeleted = ($hoursDifference >= $timetocancel);
$mysqli = new mysqli($servername, $username, $password, $dbname);
$eventId = $bookedclass->getColumnVal("idserviceschedule");
$bookingQuery = "SELECT iduser FROM bookingclass WHERE bookingclass.idserviceschedule = ? AND bookingclass.status='booked'";
$stmt = $mysqli->prepare($bookingQuery);
$stmt->bind_param("i", $eventId);
$stmt->execute();
$bookingResult = $stmt->get_result();
$countPersons = $bookingResult->num_rows;
$stmt->close();
$cardservice = $bookedclass->getColumnVal("idservice");
if (in_array($cardservice, $idassociateservices)) {
$maxcapacity = $bookedclass->getColumnVal("maxcapacity");
$freeplace = $maxcapacity - $countPersons;
$conn = new mysqli($servername, $username, $password, $dbname);
$idcheckservice = $bookedclass->getColumnVal("idserviceschedule");
$iduser = $iduserlog;
$query = "SELECT * FROM bookingclass WHERE idserviceschedule = ? AND iduser = ?";
$stmt = $conn->prepare($query);
$stmt->bind_param("ii", $idcheckservice, $iduser);
$stmt->execute();
$resultcheck = $stmt->get_result();
$alreadybooked = $resultcheck->num_rows > 0 ? 'Y' : 'N';
$stmt->close();
$conn->close();
?>
<div class="custom-card" onclick="toggleCard(this)">
<?php if ($alreadybooked == 'Y') { ?>
<div class="custom-date-box" style="background-color:#FF6609">
<?php } elseif ($freeplace > 0) { ?>
<div class="custom-date-box" style="background-color:#1ebf73">
<?php } else { ?>
<div class="custom-date-box" style="background-color:#9C9C9C">
<?php } ?>
<div class="custom-day"><?php echo $dayInItalian; ?></div>
<div class="custom-month"><?php echo $monthInItalian; ?></div>
</div>
<?php if ($alreadybooked == 'Y') { ?>
<div class="custom-event-details" style="background-color:#FFAC7A">
<?php } elseif ($freeplace > 0) { ?>
<div class="custom-event-details" style="background-color:<?php echo ($bookedclass->getColumnVal("colorclass")); ?>">
<?php } else { ?>
<div class="custom-event-details" style="background-color:#CDCDCD">
<?php } ?>
<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>
<?php $idnewbooking = $bookedclass->getColumnVal("idserviceschedule"); ?>
<?php $idservicenew = $bookedclass->getColumnVal("idservice"); ?>
<div class="booking-details">
<?php if ($alreadybooked == 'Y') { ?>
<button class="booking-button"><i class="fa fa-check"></i> Sei già prenotata/o</button>
<?php } elseif ($freeplace > 0) { ?>
<a href="rebookandgo.php?idpreviousbooking=<?php echo $idpreviousbooking; ?>&idservicenew=<?php echo $idservicenew; ?>&idnewbooking=<?php echo $idnewbooking; ?>&iduser=<?php echo $iduserlogin; ?>"><button class="booking-button"><i class="fas fa-arrow-circle-right"></i> Riprogramma Classe</button></a>
<?php } else { ?>
<button class="booking-button"><i class="fa fa-stop"></i> Classe Piena</button>
<?php } ?>
</div>
</div>
</div>
<?php
}
$bookedclass->moveNext();
}
}
$bookedclass->moveFirst();
unset($wa_startindex);
unset($wa_repeatcount);
?>
<div class="month-navigation">
<a href="?prev_month=<?php echo date('Y-m', strtotime('-1 month', strtotime($currentMonthStart))); ?>&idserviceordered=<?php echo $idserviceordered; ?>&id=<?php echo $idpreviousbooking; ?>" 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))); ?>&idserviceordered=<?php echo $idserviceordered; ?>&id=<?php echo $idpreviousbooking; ?>" class="arrow-link">
<i class="fas fa-chevron-right fa-2x"></i>
</a>
</div>
</div>
</div>
<script>
function toggleCard(card) {
card.classList.toggle("expanded");
}
</script>
<?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>
</body>
</html>