fixed multiple things

This commit is contained in:
2025-10-15 20:59:49 +02:00
parent 754c5f93f0
commit aff67bc496
26 changed files with 3504 additions and 1246 deletions
+47 -45
View File
@@ -8,6 +8,8 @@ $conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connessione fallita: " . $conn->connect_error);
}
// Gestione del messaggio GET
if (isset($_GET['message'])) {
$message = $_GET['message'];
} else {
@@ -31,20 +33,6 @@ if (isset($_POST['submit'])) {
$stmt->close();
}
// Gestione dell'aggiornamento della data di scadenza
if (isset($_POST['update_expiry'])) {
$order_id = $_POST['order_id'];
$new_expiry = $_POST['new_expiry'];
$stmt = $conn->prepare("UPDATE orderbook SET expireon = ? WHERE order_id = ?");
$stmt->bind_param("si", $new_expiry, $order_id);
if ($stmt->execute()) {
$message = 'success';
} else {
$message = 'error';
}
$stmt->close();
}
// Gestione del filtro per gli ordini
$filter = isset($_GET['filter']) ? $_GET['filter'] : 'all';
$today = date("Y-m-d");
@@ -56,11 +44,11 @@ if ($filter == 'active') {
}
// Query SQL per recuperare tutti gli ordini con join su service
$query = "SELECT o.order_id, o.first_name, o.last_name, s.servicename, o.expireon, o.status, o.nticket
$query = "SELECT o.idorderbook, o.first_name, o.last_name, s.servicename, o.expireon, o.status, o.nticket
FROM orderbook o
LEFT JOIN service s ON o.idservice = s.idservice
$whereClause
ORDER BY o.order_id DESC";
ORDER BY o.idorderbook DESC";
$result = $conn->query($query);
$orders = [];
if ($result->num_rows > 0) {
@@ -113,6 +101,7 @@ if ($result_dayoff->num_rows > 0) {
minDate: 0,
onSelect: function(dateText) {
let orderId = $(this).data('order-id');
console.log("Datepicker selezionato - idorderbook: " + orderId + ", newExpiry: " + dateText);
confirmUpdate(orderId, dateText);
}
});
@@ -122,12 +111,21 @@ if ($result_dayoff->num_rows > 0) {
$(document).on('click', '.expiry-date', function() {
let orderId = $(this).data('order-id');
let currentDate = $(this).text().trim();
console.log("Clic su expiry-date - idorderbook: " + orderId + ", currentDate: " + currentDate);
if (!orderId) {
Swal.fire('Errore!', 'ID ordine non valido.', 'error');
return;
}
$(this).html(`<input type="text" class="form-control expiryDateInput" data-order-id="${orderId}" value="${currentDate}" />`);
$(this).find('.expiryDateInput').focus();
});
// Funzione per confermare l'aggiornamento della scadenza
function confirmUpdate(orderId, newExpiry) {
let originalCell = $(`td.expiry-date[data-order-id="${orderId}"]`);
let originalDate = originalCell.text().trim();
console.log("Invio AJAX - idorderbook: " + orderId + ", new_expiry: " + newExpiry);
Swal.fire({
title: "Sei sicuro?",
text: "La data di scadenza verrà modificata!",
@@ -139,35 +137,42 @@ if ($result_dayoff->num_rows > 0) {
cancelButtonText: "Annulla"
}).then((result) => {
if (result.isConfirmed) {
let form = $('<form>', {
'method': 'POST',
'action': ''
}).append(
$('<input>', {
'type': 'hidden',
'name': 'order_id',
'value': orderId
}),
$('<input>', {
'type': 'hidden',
'name': 'new_expiry',
'value': newExpiry
}),
$('<input>', {
'type': 'hidden',
'name': 'update_expiry',
'value': '1'
})
);
$('body').append(form);
form.submit();
$.ajax({
url: 'update_expiry.php',
type: 'POST',
data: {
order_id: orderId,
new_expiry: newExpiry,
update_expiry: 1
},
dataType: 'json',
success: function(response) {
console.log("Risposta AJAX:", response);
if (response.status === 'success') {
Swal.fire('Successo!', response.message, 'success');
originalCell.text(newExpiry);
} else {
Swal.fire('Errore!', response.message, 'error');
originalCell.text(originalDate);
}
},
error: function(xhr, status, error) {
console.error('Errore AJAX:', {
status: status,
error: error,
responseText: xhr.responseText
});
Swal.fire('Errore!', 'Errore durante la richiesta al server: ' + error, 'error');
originalCell.text(originalDate);
}
});
} else {
location.reload();
originalCell.text(originalDate);
}
});
}
// Funzione per confermare la cancellazione (mantenuta dal template originale)
// Funzione per confermare la cancellazione
function confirmDelete(id, deletePageUrl) {
Swal.fire({
title: "Sei sicuro?",
@@ -343,9 +348,6 @@ if ($result_dayoff->num_rows > 0) {
<div class="main-content">
<div class="page-content">
<div class="container-fluid">
<div class="row">
<div class="col-xl-12">
<div class="card">
@@ -379,12 +381,12 @@ if ($result_dayoff->num_rows > 0) {
?>
<tr>
<td><span class="<?php echo $badgeClass; ?>"><?php echo $badgeText; ?></span></td>
<td><?php echo $order["order_id"]; ?></td>
<td><?php echo $order["idorderbook"]; ?></td>
<td><?php echo $order["first_name"]; ?></td>
<td><?php echo $order["last_name"]; ?></td>
<td><?php echo $order["servicename"]; ?></td>
<td><?php echo $order["nticket"]; ?></td>
<td class="expiry-date" data-order-id="<?php echo $order['order_id']; ?>"><?php echo $order["expireon"]; ?></td>
<td class="expiry-date" data-order-id="<?php echo $order['idorderbook']; ?>"><?php echo $order["expireon"]; ?></td>
<td><?php echo $order["status"]; ?></td>
</tr>
<?php } ?>