first commit
This commit is contained in:
@@ -0,0 +1,804 @@
|
||||
<?php require_once('include/headscript.php'); ?>
|
||||
|
||||
<?php
|
||||
$conn = mysqli_connect($servername, $username, $password, $dbname);
|
||||
|
||||
// Verifica la connessione
|
||||
if (!$conn) {
|
||||
die("Connessione al database fallita: " . mysqli_connect_error());
|
||||
}
|
||||
|
||||
// Ottieni la data/ora attuale del server per il confronto
|
||||
$serverCurrentDateTime = date('Y-m-d H:i:s');
|
||||
|
||||
// Query SQL per ottenere le informazioni desiderate
|
||||
$sql = "
|
||||
SELECT
|
||||
auth_users.id AS id_utente,
|
||||
auth_users.first_name AS nome_utente,
|
||||
auth_users.last_name AS cognome_utente,
|
||||
auth_users.email AS email_utente, -- Aggiungiamo l'email dell'utente
|
||||
COALESCE(lezioni_acquistate, 0) AS lezioni_acquistate,
|
||||
COUNT(CASE WHEN bookingclass.bookingstart <= CURDATE() AND bookingclass.lostlesson = 'N' THEN 1 END) AS lezioni_praticate,
|
||||
COUNT(CASE WHEN bookingclass.bookingstart > CURDATE() THEN 1 END) AS lezioni_programmate,
|
||||
COUNT(CASE WHEN bookingclass.lostlesson = 'Y' THEN 1 END) AS lezioni_perse,
|
||||
COALESCE(lezioni_acquistate, 0) - COUNT(CASE WHEN bookingclass.bookingstart > CURDATE() THEN 1 END) - COUNT(CASE WHEN bookingclass.bookingstart <= CURDATE() AND bookingclass.lostlesson = 'N' THEN 1 END) - COUNT(CASE WHEN bookingclass.lostlesson = 'Y' THEN 1 END) AS lezioni_da_programmare
|
||||
FROM
|
||||
auth_users
|
||||
LEFT JOIN
|
||||
(
|
||||
SELECT
|
||||
iduser,
|
||||
SUM(quantityclass) AS lezioni_acquistate
|
||||
FROM
|
||||
orderbook
|
||||
GROUP BY
|
||||
iduser
|
||||
) AS orderbook_lessons ON auth_users.id = orderbook_lessons.iduser
|
||||
LEFT JOIN
|
||||
bookingclass ON auth_users.id = bookingclass.iduser
|
||||
GROUP BY
|
||||
auth_users.id, auth_users.last_name
|
||||
ORDER BY auth_users.last_name
|
||||
";
|
||||
|
||||
$result = mysqli_query($conn, $sql);
|
||||
|
||||
// Verifica se la query ha restituito risultati
|
||||
if (!$result) {
|
||||
die("Errore nella query: " . mysqli_error($conn));
|
||||
}
|
||||
?>
|
||||
|
||||
<!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" />
|
||||
<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>
|
||||
<link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.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>
|
||||
$(function() {
|
||||
$("#expiryDate").datepicker({
|
||||
dateFormat: "yy-mm-dd",
|
||||
minDate: 0,
|
||||
});
|
||||
});
|
||||
</script>
|
||||
<script>
|
||||
$(function() {
|
||||
$("#dayoff").datepicker({ dateFormat: "yy-mm-dd" });
|
||||
});
|
||||
</script>
|
||||
<!-- DataTables CSS -->
|
||||
<link rel="stylesheet" href="https://cdn.datatables.net/1.13.6/css/jquery.dataTables.min.css">
|
||||
<!-- DataTables JS -->
|
||||
<script src="https://cdn.datatables.net/1.13.6/js/jquery.dataTables.min.js"></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;
|
||||
}
|
||||
}
|
||||
|
||||
/* Styling for the modal table */
|
||||
.lost-lesson {
|
||||
background-color: #ffcc80 !important; /* Orange for lost lessons */
|
||||
}
|
||||
|
||||
.past-lesson {
|
||||
background-color: #c6d9f0 !important; /* Lighter grayish-blue for past lessons */
|
||||
}
|
||||
|
||||
.past-lesson-reprogrammed {
|
||||
background-color: #a9bcd8 !important; /* Slightly different gray for past reprogrammed lessons */
|
||||
}
|
||||
|
||||
.future-lesson {
|
||||
background-color: #b3ffb3 !important; /* Softer pastel green for future lessons */
|
||||
}
|
||||
|
||||
.future-lesson-reprogrammed {
|
||||
background-color: #a3e6a3 !important; /* Slightly different green for future reprogrammed lessons */
|
||||
}
|
||||
|
||||
.status-reprogrammed {
|
||||
background-color: #fffacd !important; /* Light yellow for "Riprogrammata" status cell */
|
||||
}
|
||||
|
||||
.btn-warning {
|
||||
background-color: #ff8c00 !important;
|
||||
border-color: #ff8c00 !important;
|
||||
color: white !important;
|
||||
}
|
||||
|
||||
.btn-warning:hover {
|
||||
background-color: #e07b00 !important;
|
||||
border-color: #e07b00 !important;
|
||||
}
|
||||
|
||||
/* Custom modal width */
|
||||
.modal-xl-custom {
|
||||
max-width: 1200px; /* Wider modal */
|
||||
}
|
||||
|
||||
/* Stile per il pulsante email */
|
||||
.btn-email {
|
||||
background-color: #6c757d !important;
|
||||
border-color: #6c757d !important;
|
||||
color: white !important;
|
||||
}
|
||||
|
||||
.btn-email:hover {
|
||||
background-color: #5a6268 !important;
|
||||
border-color: #5a6268 !important;
|
||||
}
|
||||
|
||||
/* Stile per il pulsante "Invia Email a Tutti" */
|
||||
.btn-email-all {
|
||||
background-color: #007bff !important;
|
||||
border-color: #007bff !important;
|
||||
color: white !important;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.btn-email-all:hover {
|
||||
background-color: #0056b3 !important;
|
||||
border-color: #0056b3 !important;
|
||||
}
|
||||
|
||||
/* Stile per l'editor email */
|
||||
#emailBody {
|
||||
width: 100%;
|
||||
height: 200px;
|
||||
resize: vertical;
|
||||
}
|
||||
</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>
|
||||
</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">Prenotazione Classi</h4>
|
||||
</div>
|
||||
</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>
|
||||
|
||||
<div class="main-content">
|
||||
<div class="page-content">
|
||||
<div class="container-fluid">
|
||||
<div class="row">
|
||||
<div class="col-xl-12">
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<h5>Benvenuta/o <?php echo $firstname; ?> </h5>
|
||||
<p>Certificati</p>
|
||||
<!-- Pulsante "Invia Email a Tutti" -->
|
||||
<button class="btn btn-email-all" id="sendEmailToAll">Invia Email a Tutti</button>
|
||||
<div class="table-responsive">
|
||||
<table id="userStatsTable" class="table table-striped mb-0">
|
||||
|
||||
<thead>
|
||||
<tr>
|
||||
<th>ID Utente</th>
|
||||
<th>Nome Utente</th>
|
||||
<th>Cognome Utente</th>
|
||||
<th>Lezioni Acquistate</th>
|
||||
<th>Lezioni Praticate</th>
|
||||
<th>Lezioni Programmate</th>
|
||||
<th>Lezioni Perse</th>
|
||||
<th>Lezioni da Programmare</th>
|
||||
<th>Azione Email</th> <!-- Nuova colonna -->
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php
|
||||
while ($row = mysqli_fetch_assoc($result)) {
|
||||
echo "<tr>";
|
||||
echo "<td>" . $row['id_utente'] . "</td>";
|
||||
echo "<td><a href='#' class='user-link' data-id='" . $row['id_utente'] . "' data-nome='" . $row['nome_utente'] . " " . $row['cognome_utente'] . "' data-bs-toggle='modal' data-bs-target='#classModal'>" . $row['nome_utente'] . "</a></td>";
|
||||
echo "<td>" . $row['cognome_utente'] . "</td>";
|
||||
echo "<td>" . $row['lezioni_acquistate'] . "</td>";
|
||||
echo "<td>" . $row['lezioni_praticate'] . "</td>";
|
||||
echo "<td>" . $row['lezioni_programmate'] . "</td>";
|
||||
echo "<td>" . $row['lezioni_perse'] . "</td>";
|
||||
echo "<td>" . $row['lezioni_da_programmare'] . "</td>";
|
||||
// Nuova colonna "Azione Email" con il pulsante
|
||||
echo "<td>";
|
||||
echo "<button class='btn btn-sm btn-email send-email' data-id='" . $row['id_utente'] . "' data-nome='" . $row['nome_utente'] . "' data-email='" . $row['email_utente'] . "'><i class='fas fa-envelope'></i></button>";
|
||||
echo "</td>";
|
||||
echo "</tr>";
|
||||
}
|
||||
?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php include('include/footer.php'); ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Modal for Class Details -->
|
||||
<div class="modal fade" id="classModal" tabindex="-1" aria-labelledby="classModalLabel" aria-hidden="true">
|
||||
<div class="modal-dialog modal-xl modal-xl-custom">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title" id="classModalLabel">Dettagli Classi per <span id="userName"></span></h5>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<div class="table-responsive">
|
||||
<table class="table table-bordered" id="classDetailsTable">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Data Lezione</th>
|
||||
<th>Nome Lezione (Giorno e Ora)</th>
|
||||
<th>Stato</th>
|
||||
<th>Data Precedente (Se Riprogrammata)</th>
|
||||
<th>ID Ordine</th>
|
||||
<th>Data Ordine</th>
|
||||
<th>Azione</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="classDetailsBody"></tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Chiudi</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Modal per l'Editor Email -->
|
||||
<div class="modal fade" id="emailModal" tabindex="-1" aria-labelledby="emailModalLabel" aria-hidden="true">
|
||||
<div class="modal-dialog modal-lg">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title" id="emailModalLabel">Invia Email</h5>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<form id="emailForm">
|
||||
<div class="mb-3">
|
||||
<label for="emailSubject" class="form-label">Oggetto</label>
|
||||
<input type="text" class="form-control" id="emailSubject" placeholder="Oggetto dell'email" required>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="emailBody" class="form-label">Messaggio</label>
|
||||
<textarea class="form-control" id="emailBody" required></textarea>
|
||||
</div>
|
||||
<input type="hidden" id="emailRecipients" name="recipients">
|
||||
</form>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Chiudi</button>
|
||||
<button type="button" class="btn btn-primary" id="sendEmailBtn">Invia Email</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 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>
|
||||
|
||||
<!-- Aggiorna il link a SweetAlert2 -->
|
||||
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
|
||||
|
||||
<!-- JavaScript -->
|
||||
<script>
|
||||
$('#userStatsTable').DataTable({
|
||||
paging: false, // ❌ disattiva paginazione
|
||||
searching: true,
|
||||
ordering: true,
|
||||
language: {
|
||||
url: "//cdn.datatables.net/plug-ins/1.13.6/i18n/it-IT.json"
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
$(document).ready(function() {
|
||||
// Function to format date as "DD - Month - YYYY HH:mm:ss"
|
||||
function formatDate(dateStr) {
|
||||
if (!dateStr || dateStr === '-') {
|
||||
return '-';
|
||||
}
|
||||
|
||||
const months = [
|
||||
'January', 'February', 'March', 'April', 'May', 'June',
|
||||
'July', 'August', 'September', 'October', 'November', 'December'
|
||||
];
|
||||
|
||||
const dateTimeParts = dateStr.split(' ');
|
||||
const dateParts = dateTimeParts[0].split('-');
|
||||
const timePart = dateTimeParts[1];
|
||||
|
||||
const year = dateParts[0];
|
||||
const month = months[parseInt(dateParts[1], 10) - 1];
|
||||
const day = dateParts[2].padStart(2, '0');
|
||||
|
||||
return `${day} - ${month} - ${year} ${timePart}`;
|
||||
}
|
||||
|
||||
// Function to refresh the table
|
||||
function refreshTable(id_utente, nome_utente) {
|
||||
$.ajax({
|
||||
url: 'fetch_class_details.php',
|
||||
method: 'POST',
|
||||
data: { id_utente: id_utente },
|
||||
dataType: 'json',
|
||||
success: function(data) {
|
||||
console.log('Refresh Success Response:', data);
|
||||
var tbody = $('#classDetailsBody');
|
||||
tbody.empty();
|
||||
|
||||
// Ensure data is an array
|
||||
if (!Array.isArray(data)) {
|
||||
data = [data];
|
||||
}
|
||||
|
||||
if (data.error) {
|
||||
tbody.append('<tr><td colspan="7" class="text-center">Errore: ' + data.error + '</td></tr>');
|
||||
return;
|
||||
}
|
||||
|
||||
if (data.length === 0) {
|
||||
tbody.append('<tr><td colspan="7" class="text-center">Nessuna classe trovata per questo utente.</td></tr>');
|
||||
return;
|
||||
}
|
||||
|
||||
var currentDate = new Date('<?php echo $serverCurrentDateTime; ?>');
|
||||
|
||||
$.each(data, function(index, row) {
|
||||
var bookingDate = new Date(row.bookingstart);
|
||||
var isPast = bookingDate < currentDate;
|
||||
var rowClass = '';
|
||||
var statusText = '';
|
||||
var isReprogrammed = row.prevbookingstart !== null;
|
||||
|
||||
if (row.lostlesson === 'Y') {
|
||||
rowClass = 'lost-lesson';
|
||||
statusText = 'Persa';
|
||||
} else {
|
||||
if (isReprogrammed) {
|
||||
statusText = 'Riprogrammata';
|
||||
rowClass = isPast ? 'past-lesson-reprogrammed' : 'future-lesson-reprogrammed';
|
||||
} else if (isPast) {
|
||||
statusText = 'Praticata';
|
||||
rowClass = 'past-lesson';
|
||||
} else {
|
||||
statusText = 'Programmata';
|
||||
rowClass = 'future-lesson';
|
||||
}
|
||||
}
|
||||
|
||||
var lessonInfo = row.servicename + ' (' + row.day + ' ' + row.time + ')';
|
||||
|
||||
var formattedBookingStart = formatDate(row.bookingstart);
|
||||
var formattedPrevBookingStart = formatDate(row.prevbookingstart);
|
||||
|
||||
var tr = $('<tr>').addClass(rowClass);
|
||||
tr.append('<td>' + formattedBookingStart + '</td>');
|
||||
tr.append('<td>' + lessonInfo + '</td>');
|
||||
var statusTd = $('<td>').text(statusText);
|
||||
if (isReprogrammed) {
|
||||
statusTd.addClass('status-reprogrammed');
|
||||
}
|
||||
tr.append(statusTd);
|
||||
tr.append('<td>' + formattedPrevBookingStart + '</td>');
|
||||
tr.append('<td>' + (row.idorder || '-') + '</td>');
|
||||
tr.append('<td>' + (row.order_date_created || '-') + '</td>');
|
||||
|
||||
var actionTd = $('<td>');
|
||||
if (row.lostlesson !== 'Y') {
|
||||
var pButton = $('<button>')
|
||||
.addClass('btn btn-sm btn-warning mark-lost')
|
||||
.text('P')
|
||||
.data('id', row.idbookingclass);
|
||||
actionTd.append(pButton);
|
||||
} else {
|
||||
actionTd.text('-');
|
||||
}
|
||||
tr.append(actionTd);
|
||||
|
||||
tbody.append(tr);
|
||||
});
|
||||
},
|
||||
error: function(xhr, status, error) {
|
||||
console.log('Refresh AJAX Error:', xhr, status, error);
|
||||
console.log('Refresh Response Text:', xhr.responseText);
|
||||
$('#classDetailsBody').html('<tr><td colspan="7" class="text-center">Errore nel caricamento dei dati: ' + error + '</td></tr>');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
$('.user-link').on('click', function() {
|
||||
var id_utente = $(this).data('id');
|
||||
var nome_utente = $(this).data('nome');
|
||||
|
||||
$('#classModal').data('current-id', id_utente);
|
||||
$('#userName').text(nome_utente);
|
||||
|
||||
refreshTable(id_utente, nome_utente);
|
||||
});
|
||||
|
||||
$(document).on('click', '.mark-lost', function() {
|
||||
var id = $(this).data('id');
|
||||
var id_utente = $('#classModal').data('current-id');
|
||||
var nome_utente = $('#userName').text();
|
||||
|
||||
Swal.fire({
|
||||
title: "Sei sicuro?",
|
||||
text: "Questa lezione verrà segnata come persa!",
|
||||
icon: "warning",
|
||||
showCancelButton: true,
|
||||
confirmButtonColor: "#d33",
|
||||
cancelButtonColor: "#3085d6",
|
||||
confirmButtonText: "Sì, segna come persa!",
|
||||
cancelButtonText: "Annulla",
|
||||
focusConfirm: true,
|
||||
didOpen: () => {
|
||||
document.body.removeAttribute('aria-hidden');
|
||||
}
|
||||
}).then((result) => {
|
||||
if (result.isConfirmed) {
|
||||
$.ajax({
|
||||
url: 'mark_lost.php',
|
||||
method: 'POST',
|
||||
data: { id: id },
|
||||
dataType: 'json',
|
||||
timeout: 10000,
|
||||
success: function(response) {
|
||||
console.log('Mark Lost Success Response:', response);
|
||||
if (response && response.success) {
|
||||
Swal.fire({
|
||||
title: "Successo",
|
||||
text: "Lezione segnata come persa.",
|
||||
icon: "success",
|
||||
focusConfirm: true,
|
||||
didOpen: () => {
|
||||
document.body.removeAttribute('aria-hidden');
|
||||
}
|
||||
});
|
||||
refreshTable(id_utente, nome_utente);
|
||||
} else {
|
||||
Swal.fire({
|
||||
title: "Errore",
|
||||
text: "Impossibile segnare la lezione come persa: " + (response.message || "Errore sconosciuto"),
|
||||
icon: "error",
|
||||
focusConfirm: true,
|
||||
didOpen: () => {
|
||||
document.body.removeAttribute('aria-hidden');
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
error: function(xhr, status, error) {
|
||||
console.log('Mark Lost AJAX Error:', xhr, status, error);
|
||||
console.log('Mark Lost Raw Response:', xhr.responseText || 'No response received');
|
||||
let errorMessage = "Errore durante l'aggiornamento: " + (error || "Errore sconosciuto");
|
||||
if (status === "timeout") {
|
||||
errorMessage = "Errore durante l'aggiornamento: La richiesta ha impiegato troppo tempo. Controlla la connessione o riprova.";
|
||||
} else if (error === "net::ERR_HTTP2_PROTOCOL_ERROR") {
|
||||
errorMessage = "Errore durante l'aggiornamento: Problema di comunicazione con il server (HTTP/2 Protocol Error). Controlla la configurazione del server o riprova.";
|
||||
}
|
||||
Swal.fire({
|
||||
title: "Errore",
|
||||
text: errorMessage + " (Raw Response: " + (xhr.responseText || "undefined") + ")",
|
||||
icon: "error",
|
||||
focusConfirm: true,
|
||||
didOpen: () => {
|
||||
document.body.removeAttribute('aria-hidden');
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Gestione invio email individuale
|
||||
$('.send-email').on('click', function() {
|
||||
var id_utente = $(this).data('id');
|
||||
var nome_utente = $(this).data('nome');
|
||||
var email_utente = $(this).data('email');
|
||||
|
||||
// Imposta il titolo del modal
|
||||
$('#emailModalLabel').text('Invia Email a ' + nome_utente);
|
||||
|
||||
// Precompila il corpo dell'email con "Ciao [Nome]"
|
||||
$('#emailBody').val('Ciao ' + nome_utente.split(' ')[0] + ',\n\n');
|
||||
|
||||
// Imposta il destinatario (solo questo utente), includendo il nome
|
||||
$('#emailRecipients').val(JSON.stringify([{id: id_utente, email: email_utente, nome: nome_utente}]));
|
||||
|
||||
// Mostra il modal
|
||||
$('#emailModal').modal('show');
|
||||
});
|
||||
|
||||
// Gestione invio email a tutti
|
||||
$('#sendEmailToAll').on('click', function() {
|
||||
// Raccogli tutti gli utenti idonei (ID 4, 10, 3)
|
||||
var recipients = [];
|
||||
$('.send-email').each(function() {
|
||||
var id_utente = $(this).data('id');
|
||||
var email_utente = $(this).data('email');
|
||||
var nome_utente = $(this).data('nome');
|
||||
// Limita agli utenti con ID 4, 10, 3
|
||||
if ([4, 10, 3].includes(id_utente)) {
|
||||
recipients.push({id: id_utente, email: email_utente, nome: nome_utente});
|
||||
}
|
||||
});
|
||||
|
||||
if (recipients.length === 0) {
|
||||
Swal.fire({
|
||||
title: "Attenzione",
|
||||
text: "Nessun utente idoneo trovato per l'invio dell'email.",
|
||||
icon: "warning",
|
||||
focusConfirm: true,
|
||||
didOpen: () => {
|
||||
document.body.removeAttribute('aria-hidden');
|
||||
}
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
// Imposta il titolo del modal
|
||||
$('#emailModalLabel').text('Invia Email a Tutti');
|
||||
|
||||
// Precompila il corpo dell'email con "Ciao a tutti"
|
||||
$('#emailBody').val('Ciao a tutti,\n\n');
|
||||
|
||||
// Imposta i destinatari
|
||||
$('#emailRecipients').val(JSON.stringify(recipients));
|
||||
|
||||
// Mostra il modal
|
||||
$('#emailModal').modal('show');
|
||||
});
|
||||
|
||||
// Gestione invio email
|
||||
$('#sendEmailBtn').on('click', function() {
|
||||
var subject = $('#emailSubject').val();
|
||||
var body = $('#emailBody').val();
|
||||
var recipients = JSON.parse($('#emailRecipients').val());
|
||||
|
||||
if (!subject || !body) {
|
||||
Swal.fire({
|
||||
title: "Errore",
|
||||
text: "Per favore, compila sia l'oggetto che il messaggio.",
|
||||
icon: "error",
|
||||
focusConfirm: true,
|
||||
didOpen: () => {
|
||||
document.body.removeAttribute('aria-hidden');
|
||||
}
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
// Invia l'email tramite AJAX
|
||||
$.ajax({
|
||||
url: '/public/send_email.php', // Usa il percorso relativo corretto
|
||||
method: 'POST',
|
||||
data: {
|
||||
subject: subject,
|
||||
body: body,
|
||||
recipients: JSON.stringify(recipients)
|
||||
},
|
||||
dataType: 'json',
|
||||
success: function(response) {
|
||||
if (response.success) {
|
||||
Swal.fire({
|
||||
title: "Successo",
|
||||
text: response.message,
|
||||
icon: "success",
|
||||
focusConfirm: true,
|
||||
didOpen: () => {
|
||||
document.body.removeAttribute('aria-hidden');
|
||||
}
|
||||
});
|
||||
$('#emailModal').modal('hide');
|
||||
} else {
|
||||
Swal.fire({
|
||||
title: "Errore",
|
||||
text: response.message,
|
||||
icon: "error",
|
||||
focusConfirm: true,
|
||||
didOpen: () => {
|
||||
document.body.removeAttribute('aria-hidden');
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
error: function(xhr, status, error) {
|
||||
console.log('Send Email AJAX Error:', xhr, status, error);
|
||||
Swal.fire({
|
||||
title: "Errore",
|
||||
text: "Errore durante l'invio dell'email: " + error,
|
||||
icon: "error",
|
||||
focusConfirm: true,
|
||||
didOpen: () => {
|
||||
document.body.removeAttribute('aria-hidden');
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user