regenrates pages
This commit is contained in:
+383
-311
@@ -1,195 +1,222 @@
|
||||
<?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());
|
||||
require_once('include/headscript.php');
|
||||
|
||||
/**
|
||||
* Gestione ordini in stato "pending": elenco, propagazione (con calcolo
|
||||
* scadenza), cancellazione e inserimento manuale di un nuovo ordine.
|
||||
* orderbook contiene già first_name, last_name, cod, ecc.
|
||||
*/
|
||||
$pdo = DBHandlerSelect::getInstance()->getConnection();
|
||||
|
||||
function e($value): string
|
||||
{
|
||||
return htmlspecialchars((string) $value, ENT_QUOTES, 'UTF-8');
|
||||
}
|
||||
// Query SQL per ottenere le informazioni desiderate
|
||||
$sql = "SELECT * from orderbook WHERE orderbook.status ='pending'";
|
||||
$result = mysqli_query($conn, $sql);
|
||||
// Verifica se la query ha restituito risultati
|
||||
if (!$result) {
|
||||
die("Errore nella query: " . mysqli_error($conn));
|
||||
|
||||
function initials(string $first, string $last): string
|
||||
{
|
||||
$ini = strtoupper(mb_substr(trim($first), 0, 1) . mb_substr(trim($last), 0, 1));
|
||||
return $ini !== '' ? $ini : '?';
|
||||
}
|
||||
|
||||
function avatarColor(string $seed): string
|
||||
{
|
||||
$palette = ['#1ebf73', '#2980b9', '#8e44ad', '#e67e22', '#16a085', '#c0392b', '#2c3e50', '#d35400'];
|
||||
return $palette[abs(crc32($seed)) % count($palette)];
|
||||
}
|
||||
|
||||
// Ordini pending
|
||||
$orders = $pdo->query("SELECT * FROM orderbook WHERE status = 'pending' ORDER BY order_date_created DESC")->fetchAll();
|
||||
|
||||
// Servizi per il dropdown del nuovo ordine
|
||||
$services = $pdo->query("SELECT idservice, servicename, day, time FROM service ORDER BY servicename")->fetchAll();
|
||||
?>
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<html lang="it">
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<title>YogiBook - Prenotazioni YogaSoul</title>
|
||||
<title>YogiBook - Ordini in attesa</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta content="YogiBook - Prenotazione facile YogaSOul" name="description" />
|
||||
<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://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
|
||||
<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() {
|
||||
$("#example-date-input, #first-lesson-date").datepicker({
|
||||
dateFormat: "yy-mm-dd",
|
||||
minDate: 0
|
||||
});
|
||||
});
|
||||
</script>
|
||||
<script>
|
||||
$(document).ready(function() {
|
||||
console.log("Script loaded and running!");
|
||||
$(".surname").on("input", function() {
|
||||
var searchTerm = $(this).val();
|
||||
var currentForm = $(this).closest('form');
|
||||
if (searchTerm.length >= 2) {
|
||||
$.ajax({
|
||||
url: "search_users.php",
|
||||
method: "POST",
|
||||
data: {
|
||||
searchTerm: searchTerm
|
||||
},
|
||||
dataType: "json",
|
||||
success: function(data) {
|
||||
var results = data.results;
|
||||
currentForm.next('.search-results').empty();
|
||||
if (results.length > 0) {
|
||||
currentForm.next('.search-results').append("<p>Seleziona un utente:</p>");
|
||||
for (var i = 0; i < results.length; i++) {
|
||||
var user = results[i];
|
||||
currentForm.next('.search-results').append(
|
||||
'<div class="user-result" data-email="' + user.email + '" data-userid="' + user.userid + '" data-firstname="' + user.first_name + '" data-lastname="' + user.last_name + '">' +
|
||||
'Email: ' + user.email + ' | Nome: ' + user.first_name + ' | Cognome: ' + user.last_name +
|
||||
'</div>'
|
||||
);
|
||||
}
|
||||
currentForm.next('.search-results').on('click', '.user-result', function() {
|
||||
var selectedEmail = $(this).data("email");
|
||||
var selectedUserId = $(this).data("userid");
|
||||
var selectedFirstName = $(this).data("firstname");
|
||||
var selectedLastName = $(this).data("lastname");
|
||||
console.log("Email:", selectedEmail);
|
||||
console.log("User ID:", selectedUserId);
|
||||
console.log("First Name:", selectedFirstName);
|
||||
console.log("Last Name:", selectedLastName);
|
||||
currentForm.find(".email").val(selectedEmail);
|
||||
currentForm.find(".userid").val(selectedUserId);
|
||||
currentForm.find(".name").val(selectedFirstName);
|
||||
currentForm.find(".surname").val(selectedLastName);
|
||||
$("#userid").val(selectedUserId);
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
currentForm.next('.search-results').empty();
|
||||
}
|
||||
});
|
||||
});
|
||||
</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;
|
||||
.admin-card {
|
||||
border: none;
|
||||
padding: 8px 12px;
|
||||
border-radius: 4px;
|
||||
border-radius: 14px;
|
||||
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.06);
|
||||
}
|
||||
|
||||
.admin-card .card-body {
|
||||
padding: 26px 30px;
|
||||
}
|
||||
|
||||
.section-title {
|
||||
font-size: 15px;
|
||||
font-weight: 700;
|
||||
letter-spacing: 0.04em;
|
||||
text-transform: uppercase;
|
||||
color: #6b7280;
|
||||
margin-bottom: 4px;
|
||||
}
|
||||
|
||||
.section-lead {
|
||||
color: #9ca3af;
|
||||
font-size: 14px;
|
||||
margin-bottom: 22px;
|
||||
}
|
||||
|
||||
.order-table thead th {
|
||||
font-size: 12px;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.03em;
|
||||
color: #6b7280;
|
||||
border-bottom: 2px solid #eef0f3;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.order-table td {
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
.user-cell {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.avatar {
|
||||
width: 36px;
|
||||
height: 36px;
|
||||
border-radius: 50%;
|
||||
color: #fff;
|
||||
font-weight: 700;
|
||||
font-size: 13px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.user-name {
|
||||
font-weight: 600;
|
||||
color: #1f2937;
|
||||
}
|
||||
|
||||
.qty-pill {
|
||||
display: inline-block;
|
||||
background: #eef6f1;
|
||||
color: #1a7f52;
|
||||
font-weight: 700;
|
||||
font-size: 13px;
|
||||
padding: 2px 10px;
|
||||
border-radius: 20px;
|
||||
}
|
||||
|
||||
.btn-propagate,
|
||||
.btn-cancel {
|
||||
border: none;
|
||||
border-radius: 8px;
|
||||
padding: 7px 14px;
|
||||
font-size: 13px;
|
||||
font-weight: 600;
|
||||
color: #fff;
|
||||
cursor: pointer;
|
||||
transition: background-color 0.2s;
|
||||
transition: filter 0.15s;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.custom-action-button:hover {
|
||||
background-color: #e0e0e0;
|
||||
.btn-propagate {
|
||||
background: #27ae60;
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.custom-card {
|
||||
flex-direction: column;
|
||||
}
|
||||
.btn-cancel {
|
||||
background: #e74c3c;
|
||||
}
|
||||
|
||||
.custom-date-box,
|
||||
.custom-event-details {
|
||||
width: 100%;
|
||||
border-radius: 0;
|
||||
}
|
||||
.btn-propagate:hover,
|
||||
.btn-cancel:hover {
|
||||
filter: brightness(0.93);
|
||||
}
|
||||
|
||||
.custom-event-time {
|
||||
font-size: 24px;
|
||||
}
|
||||
.form-label {
|
||||
font-weight: 600;
|
||||
font-size: 14px;
|
||||
color: #374151;
|
||||
}
|
||||
|
||||
.form-control,
|
||||
.form-select {
|
||||
border-radius: 8px;
|
||||
border: 1px solid #e2e4e9;
|
||||
padding: 10px 12px;
|
||||
}
|
||||
|
||||
.form-control:focus,
|
||||
.form-select:focus {
|
||||
border-color: #1ebf73;
|
||||
box-shadow: 0 0 0 3px rgba(30, 191, 115, 0.12);
|
||||
}
|
||||
|
||||
.btn-save {
|
||||
border-radius: 8px;
|
||||
padding: 10px 26px;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.search-results {
|
||||
border: 1px solid #e2e4e9;
|
||||
border-radius: 8px;
|
||||
margin-top: 6px;
|
||||
max-height: 220px;
|
||||
overflow-y: auto;
|
||||
display: none;
|
||||
background: #fff;
|
||||
}
|
||||
|
||||
.search-results.show {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.user-result {
|
||||
padding: 10px 12px;
|
||||
cursor: pointer;
|
||||
font-size: 13px;
|
||||
border-bottom: 1px solid #f0f2f5;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.user-result:last-child {
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
.user-result:hover {
|
||||
background: #eef6f1;
|
||||
}
|
||||
|
||||
.empty-state {
|
||||
text-align: center;
|
||||
padding: 40px 10px;
|
||||
color: #9ca3af;
|
||||
}
|
||||
|
||||
.empty-state i {
|
||||
font-size: 34px;
|
||||
margin-bottom: 10px;
|
||||
display: block;
|
||||
color: #d5d9e0;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
@@ -204,26 +231,11 @@ if (!$result) {
|
||||
<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>
|
||||
<h4 class="page-title mb-0">Ordini in attesa</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>
|
||||
@@ -239,44 +251,70 @@ if (!$result) {
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<div class="main-content">
|
||||
<div class="page-content">
|
||||
<div class="container-fluid">
|
||||
|
||||
<!-- Elenco ordini pending -->
|
||||
<div class="row">
|
||||
<div class="col-xl-12">
|
||||
<div class="card">
|
||||
<div class="col-12">
|
||||
<div class="card admin-card mb-4">
|
||||
<div class="card-body">
|
||||
<h5>Benvenuta/o <?php echo $firstname; ?> </h5>
|
||||
<p>Ordini Pending</p>
|
||||
<div class="section-title">Ordini in attesa</div>
|
||||
<p class="section-lead">Ciao <?php echo e($firstname); ?>, questi ordini sono in stato pending: propagali o cancellali.</p>
|
||||
|
||||
<div class="table-responsive">
|
||||
<table class="table table-striped mb-0">
|
||||
<table class="table order-table align-middle">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>ID Ordine</th>
|
||||
<th>Data</th>
|
||||
<th>Utente</th>
|
||||
<th>Iduser</th>
|
||||
<th>Class</th>
|
||||
<th>Classe</th>
|
||||
<th>Quantità</th>
|
||||
<th>Propaga</th>
|
||||
<th>Cancella</th>
|
||||
<th class="text-end">Azioni</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php
|
||||
while ($row = mysqli_fetch_assoc($result)) {
|
||||
echo "<tr>";
|
||||
echo "<td>" . $row['order_id'] . "</td>";
|
||||
echo "<td>" . $row['order_date_created'] . "</td>";
|
||||
echo "<td>" . $row['first_name'] . " " . $row['last_name'] . "</td>";
|
||||
echo "<td>" . $row['iduser'] . "</td>";
|
||||
echo "<td>" . $row['cod'] . "</td>";
|
||||
echo "<td>" . $row['quantityclass'] . "</td>";
|
||||
echo "<td><button type='button' class='btn btn-success waves-effect btn-label waves-light propagate-btn' data-idorder='" . $row['idorderbook'] . "'><i class='bx bx-check-double label-icon'></i> Propaga</button></td>";
|
||||
echo "<td>" . "<a href='cancelsingleorder.php?idorder=" . $row['idorderbook'] . "'><button type='button' class='btn btn-danger waves-effect waves-light'><i class='bx bx-block font-size-16 align-middle me-2'></i> Cancella</button></a>" . "</td>";
|
||||
echo "</tr>";
|
||||
}
|
||||
?>
|
||||
<?php if (empty($orders)) : ?>
|
||||
<tr>
|
||||
<td colspan="6">
|
||||
<div class="empty-state">
|
||||
<i class="fas fa-receipt"></i>
|
||||
Nessun ordine in attesa al momento.
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
<?php else : ?>
|
||||
<?php foreach ($orders as $o) :
|
||||
$fullName = trim($o['first_name'] . ' ' . $o['last_name']);
|
||||
$idorder = (int) $o['idorderbook'];
|
||||
?>
|
||||
<tr>
|
||||
<td><strong><?php echo e($o['order_id']); ?></strong></td>
|
||||
<td><?php echo e($o['order_date_created'] ? date('d-m-Y', strtotime($o['order_date_created'])) : '-'); ?></td>
|
||||
<td>
|
||||
<div class="user-cell">
|
||||
<div class="avatar" style="background: <?php echo avatarColor($fullName); ?>;">
|
||||
<?php echo e(initials($o['first_name'] ?? '', $o['last_name'] ?? '')); ?>
|
||||
</div>
|
||||
<span class="user-name"><?php echo e($fullName); ?></span>
|
||||
</div>
|
||||
</td>
|
||||
<td><?php echo e($o['cod']); ?></td>
|
||||
<td><span class="qty-pill"><?php echo e($o['quantityclass']); ?></span></td>
|
||||
<td class="text-end">
|
||||
<button type="button" class="btn-propagate propagate-btn" data-idorder="<?php echo $idorder; ?>">
|
||||
<i class="bx bx-check-double"></i> Propaga
|
||||
</button>
|
||||
<a href="cancelsingleorder.php?idorder=<?php echo $idorder; ?>">
|
||||
<button type="button" class="btn-cancel"><i class="bx bx-block"></i> Cancella</button>
|
||||
</a>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
<?php endif; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
@@ -284,152 +322,186 @@ if (!$result) {
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Nuovo ordine -->
|
||||
<div class="row">
|
||||
<div class="col-xl-12">
|
||||
<div class="card">
|
||||
<div class="col-12">
|
||||
<div class="card admin-card">
|
||||
<div class="card-body">
|
||||
<h5>Inserisci nuovo Ordine</h5>
|
||||
<form action="inserisci_ordine.php" method="post">
|
||||
<div class="section-title">Inserisci nuovo ordine</div>
|
||||
<p class="section-lead">Cerca un utente esistente digitando il cognome, oppure inserisci i dati manualmente.</p>
|
||||
|
||||
<form action="inserisci_ordine.php" method="post" id="new-order-form">
|
||||
<div class="row">
|
||||
<div class="col-md-6 mb-3">
|
||||
<label for="formrow-firstname-input" class="form-label">Enter First Name</label>
|
||||
<input type="text" class="form-control name" placeholder="First Name" id="formrow-firstname-input" name="formrow-firstname-input">
|
||||
<label class="form-label">Nome</label>
|
||||
<input type="text" class="form-control name" placeholder="Nome" name="formrow-firstname-input">
|
||||
</div>
|
||||
<div class="col-md-6 mb-3">
|
||||
<label for="surname-input" class="form-label">Cognome</label>
|
||||
<input list="users-suggestions" type="text" class="form-control surname" placeholder="Last Name" id="surname-input" name="surname-input">
|
||||
<label class="form-label">Cognome</label>
|
||||
<input type="text" class="form-control surname" placeholder="Cognome" name="surname-input" autocomplete="off">
|
||||
<div class="search-results"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-md-6">
|
||||
<div class="mb-3">
|
||||
<label for="formrow-email-input" class="form-label">Enter Email</label>
|
||||
<input type="email" class="form-control email" placeholder="Email" id="formrow-email-input" name="formrow-email-input">
|
||||
</div>
|
||||
<div class="col-md-6 mb-3">
|
||||
<label class="form-label">Email</label>
|
||||
<input type="email" class="form-control email" placeholder="Email" name="formrow-email-input">
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<div class="mb-3">
|
||||
<label for="example-date-input" class="form-label">Data Ordine</label>
|
||||
<input class="form-control" type="date" value="" id="example-date-input" name="example-date-input">
|
||||
</div>
|
||||
<div class="col-md-6 mb-3">
|
||||
<label class="form-label">Data ordine</label>
|
||||
<input class="form-control" type="date" name="example-date-input">
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-md-6">
|
||||
<div class="mb-3">
|
||||
<label for="first-lesson-date" class="form-label">Data Prima Lezione</label>
|
||||
<input class="form-control" type="date" value="" id="first-lesson-date" name="first-lesson-date">
|
||||
</div>
|
||||
<div class="col-md-4 mb-3">
|
||||
<label class="form-label">Data prima lezione</label>
|
||||
<input class="form-control" type="date" name="first-lesson-date">
|
||||
</div>
|
||||
<div class="col-lg-4">
|
||||
<div class="mb-3">
|
||||
<label for="ticket" class="form-label">N. Ticket</label>
|
||||
<input type="text" class="form-control" placeholder="Ticket" id="ticket" name="ticket">
|
||||
<input type="text" name="userid" id="userid" value="" />
|
||||
</div>
|
||||
<div class="col-md-4 mb-3">
|
||||
<label class="form-label">N. Ticket</label>
|
||||
<input type="text" class="form-control" placeholder="Ticket" name="ticket">
|
||||
</div>
|
||||
<div class="col-lg-4">
|
||||
<div class="mb-3">
|
||||
<label for="formrow-inputState" class="form-label">Classe</label>
|
||||
<select id="formrow-inputState" name="formrow-inputState" class="form-select">
|
||||
<?php
|
||||
$conn = new mysqli($servername, $username, $password, $dbname);
|
||||
if ($conn->connect_error) {
|
||||
die("Connection failed: " . $conn->connect_error);
|
||||
}
|
||||
$sql = "SELECT idservice, servicename, day, time FROM service ORDER BY servicename";
|
||||
$result = $conn->query($sql);
|
||||
echo '<option selected="">Choose...</option>';
|
||||
if ($result->num_rows > 0) {
|
||||
while ($row = $result->fetch_assoc()) {
|
||||
$label = $row['servicename'] . ' - ' . $row['day'] . ' - ' . $row['time'];
|
||||
$value = $row['idservice'];
|
||||
echo "<option value='$value'>$label</option>";
|
||||
}
|
||||
} else {
|
||||
echo '<option>No services available</option>';
|
||||
}
|
||||
$conn->close();
|
||||
?>
|
||||
</select>
|
||||
<input type="hidden" name="cod" id="hiddenCod">
|
||||
</div>
|
||||
<script>
|
||||
const selectElem = document.getElementById('formrow-inputState');
|
||||
const hiddenElem = document.getElementById('hiddenCod');
|
||||
selectElem.addEventListener('change', function() {
|
||||
hiddenElem.value = selectElem.options[selectElem.selectedIndex].text;
|
||||
});
|
||||
</script>
|
||||
<div class="col-md-4 mb-3">
|
||||
<label class="form-label">Classe</label>
|
||||
<select id="service-select" name="formrow-inputState" class="form-select">
|
||||
<option value="">Scegli...</option>
|
||||
<?php foreach ($services as $svc) :
|
||||
$label = trim($svc['servicename'] . ' - ' . $svc['day'] . ' - ' . $svc['time'], ' -');
|
||||
?>
|
||||
<option value="<?php echo (int) $svc['idservice']; ?>"><?php echo e($label); ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
<input type="hidden" name="cod" id="hiddenCod">
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<button type="submit" class="btn btn-primary w-md">Submit</button>
|
||||
</div>
|
||||
|
||||
<input type="hidden" class="userid" name="userid" id="userid">
|
||||
<button type="submit" class="btn btn-primary btn-save">Inserisci ordine</button>
|
||||
</form>
|
||||
<div class="search-results"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<?php include('include/footer.php'); ?>
|
||||
</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>
|
||||
<script>
|
||||
$(document).ready(function() {
|
||||
$('.propagate-btn').on('click', function() {
|
||||
var idorder = $(this).data('idorder');
|
||||
</div>
|
||||
|
||||
// Chiama AJAX per calcolare la scadenza
|
||||
<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>
|
||||
|
||||
<script>
|
||||
// Salva il testo della classe scelta nel campo hidden 'cod'
|
||||
const selectElem = document.getElementById('service-select');
|
||||
const hiddenElem = document.getElementById('hiddenCod');
|
||||
selectElem.addEventListener('change', function() {
|
||||
hiddenElem.value = selectElem.options[selectElem.selectedIndex].text;
|
||||
});
|
||||
|
||||
$(document).ready(function() {
|
||||
// Ricerca utenti per cognome (e nome)
|
||||
let searchTimeout;
|
||||
$('.surname, .name').on('input', function() {
|
||||
clearTimeout(searchTimeout);
|
||||
var form = $(this).closest('form');
|
||||
var results = form.find('.search-results');
|
||||
var firstName = form.find('.name').val().trim();
|
||||
var lastName = form.find('.surname').val().trim();
|
||||
|
||||
if (firstName.length < 2 && lastName.length < 2) {
|
||||
results.removeClass('show').empty();
|
||||
return;
|
||||
}
|
||||
|
||||
searchTimeout = setTimeout(function() {
|
||||
$.ajax({
|
||||
url: 'calculate_expiry.php',
|
||||
method: 'GET',
|
||||
url: 'search_users.php',
|
||||
method: 'POST',
|
||||
data: {
|
||||
idorder: idorder
|
||||
firstName: firstName,
|
||||
lastName: lastName,
|
||||
searchTerm: lastName
|
||||
},
|
||||
dataType: 'json',
|
||||
cache: false,
|
||||
success: function(data) {
|
||||
if (data.error) {
|
||||
Swal.fire('Errore', data.error, 'error');
|
||||
return;
|
||||
results.empty();
|
||||
if (data.results && data.results.length > 0) {
|
||||
data.results.forEach(function(u) {
|
||||
var uid = u.userid || u.id;
|
||||
var ini = ((u.first_name || '').charAt(0) + (u.last_name || '').charAt(0)).toUpperCase();
|
||||
results.append(
|
||||
'<div class="user-result" data-email="' + u.email + '" data-userid="' + uid +
|
||||
'" data-firstname="' + u.first_name + '" data-lastname="' + u.last_name + '">' +
|
||||
'<span class="avatar" style="width:32px;height:32px;font-size:12px;background:#2980b9;">' + ini + '</span>' +
|
||||
'<span><strong>' + u.first_name + ' ' + u.last_name + '</strong><br>' +
|
||||
'<small style="color:#6b7280;">' + u.email + '</small></span></div>'
|
||||
);
|
||||
});
|
||||
results.addClass('show');
|
||||
results.find('.user-result').on('click', function() {
|
||||
form.find('.email').val($(this).data('email'));
|
||||
form.find('.userid').val($(this).data('userid'));
|
||||
form.find('.name').val($(this).data('firstname'));
|
||||
form.find('.surname').val($(this).data('lastname'));
|
||||
results.removeClass('show').empty();
|
||||
});
|
||||
} else {
|
||||
results.append('<div class="user-result" style="color:#9ca3af;">Nessun utente trovato.</div>').addClass('show');
|
||||
}
|
||||
|
||||
var calculatedExpiry = data.expiry_date;
|
||||
|
||||
// Mostra modal di conferma
|
||||
Swal.fire({
|
||||
title: 'Conferma Scadenza',
|
||||
html: `
|
||||
<p>Data di scadenza calcolata: <strong>${calculatedExpiry}</strong></p>
|
||||
<label for="expiry-date">Modifica scadenza (se necessario):</label>
|
||||
<input type="date" id="expiry-date" class="swal2-input" value="${calculatedExpiry}">
|
||||
`,
|
||||
showCancelButton: true,
|
||||
confirmButtonText: 'Conferma e Propaga',
|
||||
cancelButtonText: 'Annulla',
|
||||
preConfirm: () => {
|
||||
return document.getElementById('expiry-date').value;
|
||||
}
|
||||
}).then((result) => {
|
||||
if (result.isConfirmed) {
|
||||
var expiryDate = result.value || calculatedExpiry; // Usa modificata o originale
|
||||
window.location.href = `propagatesingleorder.php?idorder=${idorder}&expiry_date=${expiryDate}`;
|
||||
}
|
||||
});
|
||||
},
|
||||
error: function() {
|
||||
Swal.fire('Errore', 'Impossibile calcolare la scadenza', 'error');
|
||||
results.html('<div class="user-result" style="color:#c0392b;">Errore durante la ricerca.</div>').addClass('show');
|
||||
}
|
||||
});
|
||||
}, 300);
|
||||
});
|
||||
|
||||
// Propagazione ordine con calcolo scadenza
|
||||
$('.propagate-btn').on('click', function() {
|
||||
var idorder = $(this).data('idorder');
|
||||
$.ajax({
|
||||
url: 'calculate_expiry.php',
|
||||
method: 'GET',
|
||||
data: {
|
||||
idorder: idorder
|
||||
},
|
||||
dataType: 'json',
|
||||
success: function(data) {
|
||||
if (data.error) {
|
||||
Swal.fire('Errore', data.error, 'error');
|
||||
return;
|
||||
}
|
||||
var calculatedExpiry = data.expiry_date;
|
||||
Swal.fire({
|
||||
title: 'Conferma Scadenza',
|
||||
html: '<p>Data di scadenza calcolata: <strong>' + calculatedExpiry + '</strong></p>' +
|
||||
'<label for="expiry-date">Modifica scadenza (se necessario):</label>' +
|
||||
'<input type="date" id="expiry-date" class="swal2-input" value="' + calculatedExpiry + '">',
|
||||
showCancelButton: true,
|
||||
confirmButtonText: 'Conferma e Propaga',
|
||||
cancelButtonText: 'Annulla',
|
||||
preConfirm: () => document.getElementById('expiry-date').value
|
||||
}).then((result) => {
|
||||
if (result.isConfirmed) {
|
||||
var expiryDate = result.value || calculatedExpiry;
|
||||
window.location.href = 'propagatesingleorder.php?idorder=' + idorder + '&expiry_date=' + expiryDate;
|
||||
}
|
||||
});
|
||||
},
|
||||
error: function() {
|
||||
Swal.fire('Errore', 'Impossibile calcolare la scadenza', 'error');
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
Reference in New Issue
Block a user