push notification setting and update pages with PDO
This commit is contained in:
+189
-452
@@ -1,90 +1,71 @@
|
||||
<?php
|
||||
// Abilita visualizzazione errori PHP (solo per debug)
|
||||
ini_set('display_errors', 1);
|
||||
ini_set('display_startup_errors', 1);
|
||||
error_reporting(E_ALL);
|
||||
|
||||
require_once('include/headscript.php');
|
||||
|
||||
// Inizializza log
|
||||
$logFile = 'dashboard_log.txt';
|
||||
$logMessage = "Esecuzione dashboard: " . date('Y-m-d H:i:s') . "\n";
|
||||
/**
|
||||
* Connessione unica PDO (singleton). $iduserlogin arriva dalla sessione
|
||||
* autenticata via headscript.php. Lo forziamo comunque a intero.
|
||||
*/
|
||||
$pdo = DBHandlerSelect::getInstance()->getConnection();
|
||||
$iduserlogin = (int) $iduserlogin;
|
||||
|
||||
// Verifica se è stato inviato un modulo
|
||||
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
||||
if (isset($_FILES["fileToUpload"]) && $_FILES["fileToUpload"]["error"] === UPLOAD_ERR_OK) {
|
||||
$conn = new mysqli($servername, $username, $password, $dbname);
|
||||
if ($conn->connect_error) {
|
||||
$logMessage .= "Connessione al database fallita: " . $conn->connect_error . "\n";
|
||||
file_put_contents($logFile, $logMessage, FILE_APPEND);
|
||||
die("Connessione al database fallita: " . $conn->connect_error);
|
||||
/* -------------------------------------------------------------------------
|
||||
* Helper per output sicuro in HTML (anti-XSS)
|
||||
* ---------------------------------------------------------------------- */
|
||||
function e($value): string
|
||||
{
|
||||
return htmlspecialchars((string) $value, ENT_QUOTES, 'UTF-8');
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------
|
||||
* 1) Ordini dell'utente
|
||||
* ---------------------------------------------------------------------- */
|
||||
$sqlOrders = "SELECT o.idorderbook, o.order_id, o.idservice, o.order_date_created,
|
||||
o.quantityclass, o.first_lesson_date, o.expireon,
|
||||
o.maxreschedule, o.reprogrammed,
|
||||
s.servicename, s.day, s.time
|
||||
FROM orderbook o
|
||||
LEFT JOIN service s ON o.idservice = s.idservice
|
||||
WHERE o.iduser = :iduser
|
||||
ORDER BY o.order_date_created DESC";
|
||||
|
||||
$stmtOrders = $pdo->prepare($sqlOrders);
|
||||
$stmtOrders->execute([':iduser' => $iduserlogin]);
|
||||
$orders = $stmtOrders->fetchAll();
|
||||
|
||||
/* -------------------------------------------------------------------------
|
||||
* 2) Tutte le lezioni degli ordini in UNA sola query (niente N+1)
|
||||
* Poi le raggruppiamo per idorder in PHP.
|
||||
* ---------------------------------------------------------------------- */
|
||||
$lessonsByOrder = [];
|
||||
$orderIds = array_filter(array_map(fn($o) => (int) $o['idorderbook'], $orders));
|
||||
|
||||
if (!empty($orderIds)) {
|
||||
$placeholders = implode(',', array_fill(0, count($orderIds), '?'));
|
||||
$sqlLessons = "SELECT bc.idbookingclass, bc.bookingstart, bc.status, bc.lostlesson,
|
||||
bc.expirylesson, bc.idservice, bc.is_reprogrammed,
|
||||
bc.idorder, s.servicename
|
||||
FROM bookingclass bc
|
||||
LEFT JOIN service s ON bc.idservice = s.idservice
|
||||
WHERE bc.idorder IN ($placeholders)";
|
||||
$stmtLessons = $pdo->prepare($sqlLessons);
|
||||
$stmtLessons->execute(array_values($orderIds));
|
||||
|
||||
foreach ($stmtLessons->fetchAll() as $lesson) {
|
||||
// Normalizziamo la data in formato ISO 8601 (come faceva date('c', ...))
|
||||
if (!empty($lesson['bookingstart'])) {
|
||||
$lesson['bookingstart'] = date('c', strtotime($lesson['bookingstart']));
|
||||
}
|
||||
$iduserlogin = filter_var($_POST["iduserlogin"], FILTER_VALIDATE_INT);
|
||||
$logMessage .= "ID utente ricevuto dal form: $iduserlogin\n";
|
||||
$conn->close();
|
||||
} else {
|
||||
$logMessage .= "Errore caricamento file o iduserlogin non valido\n";
|
||||
file_put_contents($logFile, $logMessage, FILE_APPEND);
|
||||
$lessonsByOrder[(int) $lesson['idorder']][] = $lesson;
|
||||
}
|
||||
}
|
||||
|
||||
// Connessione al database
|
||||
$conn = new mysqli($servername, $username, $password, $dbname);
|
||||
if ($conn->connect_error) {
|
||||
$logMessage .= "Connessione al database fallita: " . $conn->connect_error . "\n";
|
||||
file_put_contents($logFile, $logMessage, FILE_APPEND);
|
||||
die("Connessione al database fallita: " . $conn->connect_error);
|
||||
// Attacchiamo a ogni ordine il suo array di lezioni
|
||||
foreach ($orders as &$order) {
|
||||
$oid = (int) $order['idorderbook'];
|
||||
$order['lessons'] = $lessonsByOrder[$oid] ?? [];
|
||||
}
|
||||
|
||||
$logMessage .= "Database connesso: $dbname\n";
|
||||
|
||||
// Query per selezionare i dati filtrati per iduser, inclusi maxreschedule e reprogrammed
|
||||
$iduserlogin = $iduserlogin; // Sostituisci con $iduserlogin in produzione
|
||||
$query = "SELECT o.idorderbook, o.order_id, o.idservice, o.order_date_created, o.quantityclass, o.first_lesson_date, o.expireon, o.maxreschedule, o.reprogrammed, s.servicename, s.day, s.time
|
||||
FROM orderbook o
|
||||
LEFT JOIN service s ON o.idservice = s.idservice
|
||||
WHERE o.iduser = ?";
|
||||
$stmt = $conn->prepare($query);
|
||||
$stmt->bind_param("i", $iduserlogin);
|
||||
$stmt->execute();
|
||||
$result = $stmt->get_result();
|
||||
|
||||
$documents = array();
|
||||
while ($row = $result->fetch_assoc()) {
|
||||
// Get lesson details for each order
|
||||
$idorderbook = $row['idorderbook'];
|
||||
$logMessage .= "Elaborazione ordine: idorderbook = $idorderbook, order_id = {$row['order_id']}\n";
|
||||
|
||||
$lesson_query = "SELECT bc.idbookingclass, bc.bookingstart, bc.status, bc.lostlesson, bc.expirylesson, bc.idservice, bc.is_reprogrammed, s.servicename
|
||||
FROM bookingclass bc
|
||||
LEFT JOIN service s ON bc.idservice = s.idservice
|
||||
WHERE bc.idorder = ?";
|
||||
$lesson_stmt = $conn->prepare($lesson_query);
|
||||
$lesson_stmt->bind_param("i", $idorderbook);
|
||||
$lesson_stmt->execute();
|
||||
$lesson_result = $lesson_stmt->get_result();
|
||||
|
||||
$lessons = array();
|
||||
$logMessage .= "Query lezioni per idorderbook $idorderbook: $lesson_query\n";
|
||||
if ($lesson_result) {
|
||||
$logMessage .= "Numero di lezioni trovate per idorderbook $idorderbook: " . $lesson_result->num_rows . "\n";
|
||||
while ($lesson_row = $lesson_result->fetch_assoc()) {
|
||||
$lesson_row['bookingstart'] = date('c', strtotime($lesson_row['bookingstart']));
|
||||
$lessons[] = $lesson_row;
|
||||
$logMessage .= "Lezione aggiunta: " . json_encode($lesson_row) . "\n";
|
||||
}
|
||||
} else {
|
||||
$logMessage .= "Errore nella query per idorderbook $idorderbook: " . $conn->error . "\n";
|
||||
}
|
||||
$row['lessons'] = $lessons;
|
||||
$documents[] = $row;
|
||||
$logMessage .= "Lezioni per idorderbook $idorderbook: " . count($lessons) . "\n";
|
||||
$lesson_stmt->close();
|
||||
}
|
||||
$stmt->close();
|
||||
file_put_contents($logFile, $logMessage, FILE_APPEND);
|
||||
unset($order);
|
||||
?>
|
||||
|
||||
<!doctype html>
|
||||
<html lang="it">
|
||||
|
||||
@@ -109,47 +90,39 @@ file_put_contents($logFile, $logMessage, FILE_APPEND);
|
||||
dateFormat: "yy-mm-dd"
|
||||
});
|
||||
|
||||
// Handle order click for popup
|
||||
$('.order-row').click(function() {
|
||||
var lessons = $(this).data('lessons');
|
||||
console.log('Lezioni ricevute:', lessons);
|
||||
var total = $(this).data('total');
|
||||
var orderId = $(this).data('order-id');
|
||||
var isExpired = $(this).data('is-expired') === true; // Converti in booleano
|
||||
var expireOn = $(this).data('expireon');
|
||||
// ---- Funzione unica per costruire e mostrare il popup dettagli ordine ----
|
||||
function showOrderDetails(data) {
|
||||
var lessons = data.lessons || [];
|
||||
var total = data.total;
|
||||
var orderId = data.orderId;
|
||||
var isExpired = data.isExpired === true;
|
||||
var expireOn = data.expireOn;
|
||||
|
||||
// Calcolo delle date
|
||||
var now = new Date();
|
||||
|
||||
// Calcolo dei conteggi
|
||||
var completed = lessons.filter(l => {
|
||||
var completed = lessons.filter(function(l) {
|
||||
var lessonDate = new Date(l.bookingstart);
|
||||
return (l.status === 'completed') ||
|
||||
(l.status === 'booked' && lessonDate < now && l.lostlesson !== 'Y' && l.expirylesson !== 'Y');
|
||||
}).length;
|
||||
var lost = lessons.filter(l => l.lostlesson === 'Y').length;
|
||||
var expired = lessons.filter(l => l.expirylesson === 'Y').length;
|
||||
var booked = lessons.filter(l => {
|
||||
var lost = lessons.filter(function(l) {
|
||||
return l.lostlesson === 'Y';
|
||||
}).length;
|
||||
var expired = lessons.filter(function(l) {
|
||||
return l.expirylesson === 'Y';
|
||||
}).length;
|
||||
var booked = lessons.filter(function(l) {
|
||||
var lessonDate = new Date(l.bookingstart);
|
||||
return (l.status === 'booked' && lessonDate >= now && l.lostlesson !== 'Y' && l.expirylesson !== 'Y');
|
||||
}).length;
|
||||
var toSchedule = total - (booked + completed + lost + expired);
|
||||
|
||||
// Se l'ordine è scaduto, sposta le lezioni "Da Programmare" in "Scadute"
|
||||
// Se l'ordine è scaduto, le "Da Programmare" diventano "Scadute"
|
||||
if (isExpired) {
|
||||
expired += toSchedule;
|
||||
toSchedule = 0;
|
||||
}
|
||||
|
||||
console.log({
|
||||
booked: booked,
|
||||
completed: completed,
|
||||
lost: lost,
|
||||
expired: expired,
|
||||
toSchedule: toSchedule,
|
||||
total: total
|
||||
});
|
||||
|
||||
var expireOnFormatted = expireOn ? new Date(expireOn).toLocaleDateString('it-IT', {
|
||||
day: '2-digit',
|
||||
month: '2-digit',
|
||||
@@ -157,58 +130,58 @@ file_put_contents($logFile, $logMessage, FILE_APPEND);
|
||||
}) : 'Non specificata';
|
||||
|
||||
var htmlContent = `
|
||||
<h4 style="margin-bottom: 20px; color: #333; font-weight: 600;">
|
||||
Dettagli Ordine #${orderId}
|
||||
<span class="badge ${isExpired ? 'bg-danger' : 'bg-primary'}" style="margin-left: 10px; color: white;">
|
||||
${isExpired ? 'Scaduto' : 'Attivo'}
|
||||
</span>
|
||||
</h4>
|
||||
<div style="display: flex; justify-content: space-around; margin-bottom: 30px; gap: 10px;">
|
||||
<div class="stat-box" style="background-color: #d1e7dd; border: 1px solid #a3cfbb;" title="Numero di lezioni acquistate per questo ordine">
|
||||
<h5 style="margin: 0; color: #0f5132; font-size: 14px;">Totale</h5>
|
||||
<p style="font-size: 24px; font-weight: bold; margin: 5px 0; color: #0f5132;">${total}</p>
|
||||
</div>
|
||||
<div class="stat-box" style="background-color: #d4edda; border: 1px solid #b1d4b6;" title="Lezioni già praticate">
|
||||
<h5 style="margin: 0; color: #155724; font-size: 14px;">Praticate</h5>
|
||||
<p style="font-size: 24px; font-weight: bold; margin: 5px 0; color: #155724;">${completed}</p>
|
||||
</div>
|
||||
<div class="stat-box" style="background-color: #f8d7da; border: 1px solid #f1aeb5;" title="Lezioni non praticate e non riprogrammate in tempo">
|
||||
<h5 style="margin: 0; color: #721c24; font-size: 14px;">Perse</h5>
|
||||
<p style="font-size: 24px; font-weight: bold; margin: 5px 0; color: #721c24;">${lost}</p>
|
||||
</div>
|
||||
<div class="stat-box" style="background-color: #fff3cd; border: 1px solid #ffecb5;" title="Lezioni non riprogrammate entro la data di scadenza dell'ordine">
|
||||
<h5 style="margin: 0; color: #856404; font-size: 14px;">Scadute</h5>
|
||||
<p style="font-size: 24px; font-weight: bold; margin: 5px 0; color: #856404;">${expired}</p>
|
||||
</div>
|
||||
<div class="stat-box" style="background-color: #e2d3f5; border: 1px solid #c3b2d6;" title="Lezioni da programmare entro la data di scadenza del tuo ordine (${expireOnFormatted})">
|
||||
<h5 style="margin: 0; color: #4c2c92; font-size: 14px;">Da Programmare</h5>
|
||||
<p style="font-size: 24px; font-weight: bold; margin: 5px 0; color: #4c2c92;">${toSchedule}</p>
|
||||
</div>
|
||||
</div>
|
||||
<div style="background-color: #f8f9fa; padding: 15px; border-radius: 8px;">
|
||||
<p style="margin: 0 0 15px 0; color: #333; font-size: 14px; font-weight: 500;">
|
||||
Il tuo ordine scadrà il ${expireOnFormatted}
|
||||
</p>
|
||||
<table class="lesson-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Data e Ora</th>
|
||||
<th>Lezione</th>
|
||||
<th>Stato</th>
|
||||
<th>Riprogrammata</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
`;
|
||||
<h4 style="margin-bottom: 20px; color: #333; font-weight: 600;">
|
||||
Dettagli Ordine #${orderId}
|
||||
<span class="badge ${isExpired ? 'bg-danger' : 'bg-primary'}" style="margin-left: 10px; color: white;">
|
||||
${isExpired ? 'Scaduto' : 'Attivo'}
|
||||
</span>
|
||||
</h4>
|
||||
<div style="display: flex; justify-content: space-around; margin-bottom: 30px; gap: 10px;">
|
||||
<div class="stat-box" style="background-color: #d1e7dd; border: 1px solid #a3cfbb;" title="Numero di lezioni acquistate per questo ordine">
|
||||
<h5 style="margin: 0; color: #0f5132; font-size: 14px;">Totale</h5>
|
||||
<p style="font-size: 24px; font-weight: bold; margin: 5px 0; color: #0f5132;">${total}</p>
|
||||
</div>
|
||||
<div class="stat-box" style="background-color: #d4edda; border: 1px solid #b1d4b6;" title="Lezioni già praticate">
|
||||
<h5 style="margin: 0; color: #155724; font-size: 14px;">Praticate</h5>
|
||||
<p style="font-size: 24px; font-weight: bold; margin: 5px 0; color: #155724;">${completed}</p>
|
||||
</div>
|
||||
<div class="stat-box" style="background-color: #f8d7da; border: 1px solid #f1aeb5;" title="Lezioni non praticate e non riprogrammate in tempo">
|
||||
<h5 style="margin: 0; color: #721c24; font-size: 14px;">Perse</h5>
|
||||
<p style="font-size: 24px; font-weight: bold; margin: 5px 0; color: #721c24;">${lost}</p>
|
||||
</div>
|
||||
<div class="stat-box" style="background-color: #fff3cd; border: 1px solid #ffecb5;" title="Lezioni non riprogrammate entro la data di scadenza dell'ordine">
|
||||
<h5 style="margin: 0; color: #856404; font-size: 14px;">Scadute</h5>
|
||||
<p style="font-size: 24px; font-weight: bold; margin: 5px 0; color: #856404;">${expired}</p>
|
||||
</div>
|
||||
<div class="stat-box" style="background-color: #e2d3f5; border: 1px solid #c3b2d6;" title="Lezioni da programmare entro la data di scadenza del tuo ordine (${expireOnFormatted})">
|
||||
<h5 style="margin: 0; color: #4c2c92; font-size: 14px;">Da Programmare</h5>
|
||||
<p style="font-size: 24px; font-weight: bold; margin: 5px 0; color: #4c2c92;">${toSchedule}</p>
|
||||
</div>
|
||||
</div>
|
||||
<div style="background-color: #f8f9fa; padding: 15px; border-radius: 8px;">
|
||||
<p style="margin: 0 0 15px 0; color: #333; font-size: 14px; font-weight: 500;">
|
||||
Il tuo ordine scadrà il ${expireOnFormatted}
|
||||
</p>
|
||||
<table class="lesson-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Data e Ora</th>
|
||||
<th>Lezione</th>
|
||||
<th>Stato</th>
|
||||
<th>Riprogrammata</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
`;
|
||||
|
||||
if (lessons.length === 0) {
|
||||
htmlContent += `
|
||||
<tr>
|
||||
<td colspan="4" style="text-align: center; padding: 10px; color: #666; font-size: 13px;">
|
||||
Nessuna lezione trovata per questo ordine.
|
||||
</td>
|
||||
</tr>
|
||||
`;
|
||||
<tr>
|
||||
<td colspan="4" style="text-align: center; padding: 10px; color: #666; font-size: 13px;">
|
||||
Nessuna lezione trovata per questo ordine.
|
||||
</td>
|
||||
</tr>
|
||||
`;
|
||||
} else {
|
||||
lessons.forEach(function(lesson, index) {
|
||||
var lessonDate = new Date(lesson.bookingstart);
|
||||
@@ -239,29 +212,25 @@ file_put_contents($logFile, $logMessage, FILE_APPEND);
|
||||
var isReprogrammedText = lesson.is_reprogrammed === 'Y' ? 'Sì' : 'No';
|
||||
|
||||
htmlContent += `
|
||||
<tr class="${index % 2 === 0 ? 'even-row' : 'odd-row'}">
|
||||
<td style="padding: 8px; font-size: 13px;">${lessonDate.toLocaleString('it-IT', {
|
||||
day: '2-digit',
|
||||
month: '2-digit',
|
||||
year: 'numeric',
|
||||
hour: '2-digit',
|
||||
minute: '2-digit'
|
||||
})}</td>
|
||||
<td style="padding: 8px; font-size: 13px;">${lesson.servicename}</td>
|
||||
<td style="padding: 8px;">
|
||||
<span class="badge ${badgeClass}" style="color: ${badgeTextColor}; padding: 6px 10px; font-size: 12px; font-weight: 500;">${statusText}</span>
|
||||
</td>
|
||||
<td style="padding: 8px; font-size: 13px;">${isReprogrammedText}</td>
|
||||
</tr>
|
||||
`;
|
||||
<tr class="${index % 2 === 0 ? 'even-row' : 'odd-row'}">
|
||||
<td style="padding: 8px; font-size: 13px;">${lessonDate.toLocaleString('it-IT', {
|
||||
day: '2-digit', month: '2-digit', year: 'numeric', hour: '2-digit', minute: '2-digit'
|
||||
})}</td>
|
||||
<td style="padding: 8px; font-size: 13px;">${lesson.servicename ?? ''}</td>
|
||||
<td style="padding: 8px;">
|
||||
<span class="badge ${badgeClass}" style="color: ${badgeTextColor}; padding: 6px 10px; font-size: 12px; font-weight: 500;">${statusText}</span>
|
||||
</td>
|
||||
<td style="padding: 8px; font-size: 13px;">${isReprogrammedText}</td>
|
||||
</tr>
|
||||
`;
|
||||
});
|
||||
}
|
||||
|
||||
htmlContent += `
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
`;
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
`;
|
||||
|
||||
Swal.fire({
|
||||
title: '',
|
||||
@@ -272,276 +241,49 @@ file_put_contents($logFile, $logMessage, FILE_APPEND);
|
||||
popup: 'custom-modal'
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Estrae i dati dalla riga e chiama la funzione unica
|
||||
function detailsFromRow(row) {
|
||||
showOrderDetails({
|
||||
lessons: row.data('lessons'),
|
||||
total: row.data('total'),
|
||||
orderId: row.data('order-id'),
|
||||
isExpired: row.data('is-expired') === true,
|
||||
expireOn: row.data('expireon')
|
||||
});
|
||||
}
|
||||
|
||||
// Click sulla riga
|
||||
$('.order-row').click(function() {
|
||||
detailsFromRow($(this));
|
||||
});
|
||||
|
||||
// Handle details button click
|
||||
// Click sul bottone "Dettagli" (senza propagare alla riga)
|
||||
$('.details-btn').click(function(e) {
|
||||
e.stopPropagation();
|
||||
var row = $(this).closest('tr');
|
||||
var lessons = row.data('lessons');
|
||||
var total = row.data('total');
|
||||
var orderId = row.data('order-id');
|
||||
var isExpired = row.data('is-expired') === true;
|
||||
var expireOn = row.data('expireon');
|
||||
|
||||
var now = new Date();
|
||||
|
||||
var completed = lessons.filter(l => {
|
||||
var lessonDate = new Date(l.bookingstart);
|
||||
return (l.status === 'completed') ||
|
||||
(l.status === 'booked' && lessonDate < now && l.lostlesson !== 'Y' && l.expirylesson !== 'Y');
|
||||
}).length;
|
||||
var lost = lessons.filter(l => l.lostlesson === 'Y').length;
|
||||
var expired = lessons.filter(l => l.expirylesson === 'Y').length;
|
||||
var booked = lessons.filter(l => {
|
||||
var lessonDate = new Date(l.bookingstart);
|
||||
return (l.status === 'booked' && lessonDate >= now && l.lostlesson !== 'Y' && l.expirylesson !== 'Y');
|
||||
}).length;
|
||||
var toSchedule = total - (booked + completed + lost + expired);
|
||||
|
||||
// Se l'ordine è scaduto, sposta le lezioni "Da Programmare" in "Scadute"
|
||||
if (isExpired) {
|
||||
expired += toSchedule;
|
||||
toSchedule = 0;
|
||||
}
|
||||
|
||||
var expireOnFormatted = expireOn ? new Date(expireOn).toLocaleDateString('it-IT', {
|
||||
day: '2-digit',
|
||||
month: '2-digit',
|
||||
year: 'numeric'
|
||||
}) : 'Non specificata';
|
||||
|
||||
var htmlContent = `
|
||||
<h4 style="margin-bottom: 20px; color: #333; font-weight: 600;">
|
||||
Dettagli Ordine #${orderId}
|
||||
<span class="badge ${isExpired ? 'bg-danger' : 'bg-primary'}" style="margin-left: 10px; color: white;">
|
||||
${isExpired ? 'Scaduto' : 'Attivo'}
|
||||
</span>
|
||||
</h4>
|
||||
<div style="display: flex; justify-content: space-around; margin-bottom: 30px; gap: 10px;">
|
||||
<div class="stat-box" style="background-color: #d1e7dd; border: 1px solid #a3cfbb;" title="Numero di lezioni acquistate per questo ordine">
|
||||
<h5 style="margin: 0; color: #0f5132; font-size: 14px;">Totale</h5>
|
||||
<p style="font-size: 24px; font-weight: bold; margin: 5px 0; color: #0f5132;">${total}</p>
|
||||
</div>
|
||||
<div class="stat-box" style="background-color: #d4edda; border: 1px solid #b1d4b6;" title="Lezioni già praticate">
|
||||
<h5 style="margin: 0; color: #155724; font-size: 14px;">Praticate</h5>
|
||||
<p style="font-size: 24px; font-weight: bold; margin: 5px 0; color: #155724;">${completed}</p>
|
||||
</div>
|
||||
<div class="stat-box" style="background-color: #f8d7da; border: 1px solid #f1aeb5;" title="Lezioni non praticate e non riprogrammate in tempo">
|
||||
<h5 style="margin: 0; color: #721c24; font-size: 14px;">Perse</h5>
|
||||
<p style="font-size: 24px; font-weight: bold; margin: 5px 0; color: #721c24;">${lost}</p>
|
||||
</div>
|
||||
<div class="stat-box" style="background-color: #fff3cd; border: 1px solid #ffecb5;" title="Lezioni non riprogrammate entro la data di scadenza dell'ordine">
|
||||
<h5 style="margin: 0; color: #856404; font-size: 14px;">Scadute</h5>
|
||||
<p style="font-size: 24px; font-weight: bold; margin: 5px 0; color: #856404;">${expired}</p>
|
||||
</div>
|
||||
<div class="stat-box" style="background-color: #e2d3f5; border: 1px solid #c3b2d6;" title="Lezioni da programmare entro la data di scadenza del tuo ordine (${expireOnFormatted})">
|
||||
<h5 style="margin: 0; color: #4c2c92; font-size: 14px;">Da Programmare</h5>
|
||||
<p style="font-size: 24px; font-weight: bold; margin: 5px 0; color: #4c2c92;">${toSchedule}</p>
|
||||
</div>
|
||||
</div>
|
||||
<div style="background-color: #f8f9fa; padding: 15px; border-radius: 8px;">
|
||||
<table class="lesson-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Data e Ora</th>
|
||||
<th>Lezione</th>
|
||||
<th>Stato</th>
|
||||
<th>Riprogrammata</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
`;
|
||||
|
||||
if (lessons.length === 0) {
|
||||
htmlContent += `
|
||||
<tr>
|
||||
<td colspan="4" style="text-align: center; padding: 10px; color: #666; font-size: 13px;">
|
||||
Nessuna lezione trovata per questo ordine.
|
||||
</td>
|
||||
</tr>
|
||||
`;
|
||||
} else {
|
||||
lessons.forEach(function(lesson, index) {
|
||||
var lessonDate = new Date(lesson.bookingstart);
|
||||
var statusText = lesson.status;
|
||||
var badgeClass = 'bg-primary';
|
||||
var badgeTextColor = '#fff';
|
||||
if (lesson.status === 'completed') {
|
||||
badgeClass = 'bg-success';
|
||||
badgeTextColor = '#fff';
|
||||
statusText = 'Completata';
|
||||
} else if (lesson.lostlesson === 'Y') {
|
||||
badgeClass = 'bg-danger';
|
||||
badgeTextColor = '#fff';
|
||||
statusText = 'Persa';
|
||||
} else if (lesson.expirylesson === 'Y') {
|
||||
badgeClass = 'bg-warning';
|
||||
badgeTextColor = '#000';
|
||||
statusText = 'Scaduta';
|
||||
} else if (lesson.status === 'booked') {
|
||||
if (lessonDate < now && lesson.lostlesson !== 'Y' && lesson.expirylesson !== 'Y') {
|
||||
statusText = 'Completata';
|
||||
badgeClass = 'bg-success';
|
||||
badgeTextColor = '#fff';
|
||||
} else {
|
||||
statusText = 'Programmata';
|
||||
}
|
||||
}
|
||||
var isReprogrammedText = lesson.is_reprogrammed === 'Y' ? 'Sì' : 'No';
|
||||
|
||||
htmlContent += `
|
||||
<tr class="${index % 2 === 0 ? 'even-row' : 'odd-row'}">
|
||||
<td style="padding: 8px; font-size: 13px;">${lessonDate.toLocaleString('it-IT', {
|
||||
day: '2-digit',
|
||||
month: '2-digit',
|
||||
year: 'numeric',
|
||||
hour: '2-digit',
|
||||
minute: '2-digit'
|
||||
})}</td>
|
||||
<td style="padding: 8px; font-size: 13px;">${lesson.servicename}</td>
|
||||
<td style="padding: 8px;">
|
||||
<span class="badge ${badgeClass}" style="color: ${badgeTextColor}; padding: 6px 10px; font-size: 12px; font-weight: 500;">${statusText}</span>
|
||||
</td>
|
||||
<td style="padding: 8px; font-size: 13px;">${isReprogrammedText}</td>
|
||||
</tr>
|
||||
`;
|
||||
});
|
||||
}
|
||||
|
||||
htmlContent += `
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
`;
|
||||
|
||||
Swal.fire({
|
||||
title: '',
|
||||
html: htmlContent,
|
||||
confirmButtonText: 'Chiudi',
|
||||
width: '1000px',
|
||||
customClass: {
|
||||
popup: 'custom-modal'
|
||||
}
|
||||
});
|
||||
detailsFromRow($(this).closest('tr'));
|
||||
});
|
||||
|
||||
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}`;
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
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>
|
||||
<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: #ff4d4f;
|
||||
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: #e6f3ff;
|
||||
}
|
||||
|
||||
.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;
|
||||
}
|
||||
}
|
||||
|
||||
.order-row {
|
||||
cursor: pointer;
|
||||
}
|
||||
@@ -667,7 +409,7 @@ file_put_contents($logFile, $logMessage, FILE_APPEND);
|
||||
<div class="col-xl-12">
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<h5>Benvenuta/o <?php echo $firstname; ?></h5>
|
||||
<h5>Benvenuta/o <?php echo e($firstname); ?></h5>
|
||||
<p>Di seguito puoi visualizzare i tuoi ordini</p>
|
||||
<div class="table-responsive">
|
||||
<table class="table table-striped mb-0">
|
||||
@@ -686,33 +428,32 @@ file_put_contents($logFile, $logMessage, FILE_APPEND);
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach ($documents as $document) {
|
||||
<?php foreach ($orders as $document) {
|
||||
$is_expired = strtotime($document['expireon']) < time();
|
||||
$logMessage .= "Order ID: {$document['idorderbook']}, Lessons count: " . count($document['lessons']) . "\n";
|
||||
?>
|
||||
<tr class="order-row"
|
||||
data-lessons='<?php echo json_encode($document['lessons']); ?>'
|
||||
data-total='<?php echo $document['quantityclass']; ?>'
|
||||
data-order-id='<?php echo $document['idorderbook']; ?>'
|
||||
data-lessons='<?php echo e(json_encode($document['lessons'])); ?>'
|
||||
data-total='<?php echo e($document['quantityclass']); ?>'
|
||||
data-order-id='<?php echo e($document['idorderbook']); ?>'
|
||||
data-is-expired='<?php echo $is_expired ? 'true' : 'false'; ?>'
|
||||
data-expireon='<?php echo $document['expireon']; ?>'>
|
||||
<td><?php echo $document['idorderbook']; ?></td>
|
||||
<td><?php echo date('d-m-Y', strtotime($document['order_date_created'])); ?></td>
|
||||
<td><?php echo $document['servicename']; ?></td>
|
||||
<td><?php echo $document['day'] . ' ' . $document['time']; ?></td>
|
||||
<td><?php echo $document['quantityclass']; ?></td>
|
||||
<td><?php echo $document['first_lesson_date'] ? date('d-m-Y', strtotime($document['first_lesson_date'])) : '-'; ?></td>
|
||||
data-expireon='<?php echo e($document['expireon']); ?>'>
|
||||
<td><?php echo e($document['idorderbook']); ?></td>
|
||||
<td><?php echo e(date('d-m-Y', strtotime($document['order_date_created']))); ?></td>
|
||||
<td><?php echo e($document['servicename']); ?></td>
|
||||
<td><?php echo e($document['day'] . ' ' . $document['time']); ?></td>
|
||||
<td><?php echo e($document['quantityclass']); ?></td>
|
||||
<td><?php echo e($document['first_lesson_date'] ? date('d-m-Y', strtotime($document['first_lesson_date'])) : '-'); ?></td>
|
||||
<td style="<?php echo $is_expired ? 'color: #dc3545;' : ''; ?>">
|
||||
<?php echo date('d-m-Y', strtotime($document['expireon'])); ?>
|
||||
<?php echo e(date('d-m-Y', strtotime($document['expireon']))); ?>
|
||||
</td>
|
||||
<td>
|
||||
<span style="display: inline-block; padding: 4px 8px; font-size: 11px; font-weight: 500; color: #fff; background-color: #17a2b8; border-radius: 4px;">
|
||||
<?php echo $document['maxreschedule']; ?>
|
||||
<?php echo e($document['maxreschedule']); ?>
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<span style="display: inline-block; padding: 4px 8px; font-size: 11px; font-weight: 500; color: #fff; background-color: <?php echo ($document['reprogrammed'] >= $document['maxreschedule']) ? '#dc3545' : '#28a745'; ?>; border-radius: 4px;">
|
||||
<?php echo $document['reprogrammed']; ?>
|
||||
<?php echo e($document['reprogrammed']); ?>
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
@@ -741,8 +482,4 @@ file_put_contents($logFile, $logMessage, FILE_APPEND);
|
||||
<script src="assets/js/app.js"></script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
<?php
|
||||
file_put_contents($logFile, $logMessage, FILE_APPEND);
|
||||
$conn->close();
|
||||
?>
|
||||
</html>
|
||||
Reference in New Issue
Block a user