From 2512e7a7ab96bcd6e08b5cd3ba3a3c2d8bb96dc9 Mon Sep 17 00:00:00 2001 From: solocla Date: Thu, 24 Sep 2026 11:20:05 +0200 Subject: [PATCH] added modify to orders --- public/ordersummary.php | 791 ++++++++++++++++++++--------------- public/php_errors.log | 1 + public/update_reschedule.php | 65 +++ 3 files changed, 511 insertions(+), 346 deletions(-) create mode 100644 public/update_reschedule.php diff --git a/public/ordersummary.php b/public/ordersummary.php index bfa4886..5ec547c 100644 --- a/public/ordersummary.php +++ b/public/ordersummary.php @@ -1,314 +1,143 @@ - getConnection(); -// Verifica della connessione -if ($conn->connect_error) { - die("Connessione fallita: " . $conn->connect_error); -} - -// Gestione del messaggio GET -if (isset($_GET['message'])) { - $message = $_GET['message']; -} else { - $message = 'n'; -} - -// ID dell'insegnante (per il form DayOff) -$idTeacher = 1; - -// Gestione dell'inserimento del DayOff -if (isset($_POST['submit'])) { - $dayoffdate = $_POST['dayoff']; - $insertQuery = "INSERT INTO dayoff (idteacher, dayoffdate) VALUES (?, ?)"; - $stmt = $conn->prepare($insertQuery); - $stmt->bind_param("is", $idTeacher, $dayoffdate); - if ($stmt->execute()) { - $message = 'success_dayoff'; - } else { - $message = 'error_dayoff'; - } - $stmt->close(); -} - -// Gestione del filtro per gli ordini -$filter = isset($_GET['filter']) ? $_GET['filter'] : 'all'; -$today = date("Y-m-d"); -$whereClause = ""; -if ($filter == 'active') { - $whereClause = "WHERE expireon > '$today'"; -} elseif ($filter == 'expired') { - $whereClause = "WHERE expireon <= '$today'"; -} - -// Query SQL per recuperare tutti gli ordini con join su service -$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.idorderbook DESC"; -$result = $conn->query($query); -$orders = []; -if ($result->num_rows > 0) { - while ($row = $result->fetch_assoc()) { - $orders[] = $row; +if (!function_exists('e')) { + function e($value): string + { + return htmlspecialchars((string) $value, ENT_QUOTES, 'UTF-8'); } } -// Query SQL per i DayOff -$query_dayoff = "SELECT iddayoff, dayoffdate FROM dayoff WHERE idteacher = '1'"; -$result_dayoff = $conn->query($query_dayoff); -$documents = []; -if ($result_dayoff->num_rows > 0) { - while ($row = $result_dayoff->fetch_assoc()) { - $documents[] = $row; +function reschedBadge($max, $done): string +{ + $done = (int) $done; + if ($max === null || $max === '') { + return '' . $done . ''; } + $max = (int) $max; + $cls = $done >= $max ? 'bg-danger' : ($done > 0 ? 'bg-warning text-dark' : 'bg-success'); + return '' . $done . ' / ' . $max . ''; } + +$message = $_GET['message'] ?? 'n'; + +$filter = $_GET['filter'] ?? 'all'; +if (!in_array($filter, ['all', 'active', 'expired'], true)) { + $filter = 'all'; +} +$q = trim((string) ($_GET['q'] ?? '')); +$today = date('Y-m-d'); + +$where = ''; +$params = []; +if ($filter === 'active') { + $where = 'WHERE o.expireon > :today'; + $params[':today'] = $today; +} elseif ($filter === 'expired') { + $where = 'WHERE o.expireon <= :today'; + $params[':today'] = $today; +} + +$sql = "SELECT o.idorderbook, o.order_id, o.first_name, o.last_name, o.order_billing_email, + s.servicename, o.expireon, o.status, o.nticket, o.maxreschedule, o.reprogrammed + FROM orderbook o + LEFT JOIN service s ON o.idservice = s.idservice + $where + ORDER BY o.idorderbook DESC"; +$stmt = $pdo->prepare($sql); +$stmt->execute($params); +$orders = $stmt->fetchAll(); + +$qParam = $q !== '' ? '&q=' . urlencode($q) : ''; ?> - - + - YogiBook - Prenotazioni YogaSoul + YogiBook - Riepilogo Ordini - + - + - @@ -329,98 +158,118 @@ if ($result_dayoff->num_rows > 0) {
- -
- - - -
- -
-
- +
+ +
+ - -
+
+
+ +
+
+ -
-
-
-
-
-
-
-
Riepilogo Ordini (Amministratore)
-

Tutti gli ordini registrati

-
- Tutti - Attivi - Scaduti -
-
- - - - - - - - - - - - - - - - $today); - $badgeClass = $isActive ? 'badge bg-success' : 'badge bg-danger'; - $badgeText = $isActive ? 'Attivo' : 'Scaduto'; - ?> +
+
+
+
+
+
+
+
Riepilogo Ordini (Amministratore)
+

Tutti gli ordini registrati

+ +
+ Tutti + Attivi + Scaduti + + +
+ +
+
Clicca su scadenza, max riprogr. o riprogrammate per modificarle.
+ +
+
StatoNumero OrdineNomeCognomeNome ClasseNumero TicketScadenzaStatusAzioni
+ - - - - - - - - - + + + + + + + + + + + - - -
- - StatoN. OrdineNomeCognomeClasseTicketScadenzaMax riprogr.RiprogrammateStatusAzioni
+ + + $today); + $max = $order['maxreschedule']; + $done = (int) $order['reprogrammed']; + $search = implode(' ', [ + $order['first_name'], + $order['last_name'], + $order['order_billing_email'], + $id, + $order['order_id'], + $order['servicename'], + ]); + ?> + + + + + + + + + + + + –' : (int) $max; ?> + + + + + + + + + + + + Nessun ordine trovato. + + + +
+
-
@@ -429,11 +278,261 @@ if ($result_dayoff->num_rows > 0) { - + + + + - + diff --git a/public/php_errors.log b/public/php_errors.log index 24e3684..5c97b12 100644 --- a/public/php_errors.log +++ b/public/php_errors.log @@ -1,3 +1,4 @@ [15-Oct-2025 15:13:11 UTC] Tentativo di aggiornamento AJAX - idorderbook: 1, new_expiry: 2025-10-16 [15-Oct-2025 15:13:19 UTC] Tentativo di aggiornamento AJAX - idorderbook: 1, new_expiry: 2025-10-15 [15-Oct-2025 15:13:58 UTC] Tentativo di aggiornamento AJAX - idorderbook: 1, new_expiry: 2025-10-30 +[24-Sep-2026 09:19:47 UTC] Tentativo di aggiornamento AJAX - idorderbook: 7, new_expiry: 2026-11-02 diff --git a/public/update_reschedule.php b/public/update_reschedule.php new file mode 100644 index 0000000..86c047d --- /dev/null +++ b/public/update_reschedule.php @@ -0,0 +1,65 @@ + 'error', 'message' => 'Metodo non consentito.'], 405); +} + +$allowedFields = ['maxreschedule', 'reprogrammed']; +$field = $_POST['field'] ?? ''; +$orderId = (int) ($_POST['order_id'] ?? 0); +$value = (string) ($_POST['value'] ?? ''); + +if (!in_array($field, $allowedFields, true)) { + jsonOut(['status' => 'error', 'message' => 'Campo non valido.'], 400); +} +if ($orderId <= 0) { + jsonOut(['status' => 'error', 'message' => 'ID ordine non valido.'], 400); +} +if (!preg_match('/^\d{1,3}$/', $value)) { + jsonOut(['status' => 'error', 'message' => 'Inserisci un numero intero da 0 a 999.'], 400); +} + +try { + $pdo = DBHandlerSelect::getInstance()->getConnection(); + + $check = $pdo->prepare("SELECT idorderbook FROM orderbook WHERE idorderbook = :id"); + $check->execute([':id' => $orderId]); + if (!$check->fetch()) { + jsonOut(['status' => 'error', 'message' => 'Ordine non trovato.'], 404); + } + + // $field è da whitelist, quindi sicuro da inserire nella query + $upd = $pdo->prepare("UPDATE orderbook SET `$field` = :v WHERE idorderbook = :id"); + $upd->execute([':v' => (int) $value, ':id' => $orderId]); + + $row = $pdo->prepare("SELECT maxreschedule, reprogrammed FROM orderbook WHERE idorderbook = :id"); + $row->execute([':id' => $orderId]); + $r = $row->fetch(); + + jsonOut([ + 'status' => 'success', + 'message' => 'Valore aggiornato.', + 'maxreschedule' => $r['maxreschedule'] === null ? null : (int) $r['maxreschedule'], + 'reprogrammed' => (int) $r['reprogrammed'], + ]); +} catch (Throwable $e) { + error_log('update_reschedule: ' . $e->getMessage()); + jsonOut(['status' => 'error', 'message' => 'Errore durante il salvataggio.'], 500); +}