fixed quotations
This commit is contained in:
parent
960832efb1
commit
78495880ca
@ -25,15 +25,21 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['
|
||||
$description = '';
|
||||
$customer = '';
|
||||
|
||||
$stmt = $pdo->prepare("INSERT INTO quotations (description, customer, iduser) VALUES (?, ?, ?)");
|
||||
$stmt->execute([$description, $customer, $user_id]);
|
||||
$newId = $pdo->lastInsertId();
|
||||
|
||||
// Log creazione
|
||||
error_log("Creata nuova quotation ID: $newId");
|
||||
|
||||
// Reindirizza alla modifica della nuova quotation
|
||||
header("Location: quotations.php?edit_id=" . $newId . "&status=success&message=" . urlencode("Quotation creata con successo"));
|
||||
try {
|
||||
$stmt = $pdo->prepare("INSERT INTO quotations (description, customer, iduser) VALUES (?, ?, ?)");
|
||||
$success = $stmt->execute([$description, $customer, $user_id]);
|
||||
if ($success) {
|
||||
$newId = $pdo->lastInsertId();
|
||||
error_log("Creata nuova quotation ID: $newId");
|
||||
header("Location: quotations.php?edit_id=" . $newId . "&status=success&message=" . urlencode("Quotation creata con successo"));
|
||||
} else {
|
||||
error_log("Errore: Impossibile creare la quotation, nessun ID generato.");
|
||||
header("Location: quotations.php?status=error&message=" . urlencode("Errore durante la creazione della quotation"));
|
||||
}
|
||||
} catch (PDOException $e) {
|
||||
error_log("Errore PDO durante la creazione della quotation: " . $e->getMessage());
|
||||
header("Location: quotations.php?status=error&message=" . urlencode("Errore database: " . $e->getMessage()));
|
||||
}
|
||||
exit;
|
||||
}
|
||||
|
||||
@ -43,14 +49,15 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['
|
||||
$description = $_POST['description'] ?? '';
|
||||
$customer = $_POST['customer'] ?? '';
|
||||
|
||||
$stmt = $pdo->prepare("UPDATE quotations SET description = ?, customer = ? WHERE id = ? AND iduser = ?");
|
||||
$stmt->execute([$description, $customer, $id, $user_id]);
|
||||
|
||||
// Log modifica
|
||||
error_log("Modificata quotation ID: $id");
|
||||
|
||||
// Reindirizza alla lista delle quotations
|
||||
header("Location: quotations.php?status=success&message=" . urlencode("Quotation modificata con successo"));
|
||||
try {
|
||||
$stmt = $pdo->prepare("UPDATE quotations SET description = ?, customer = ? WHERE id = ? AND iduser = ?");
|
||||
$stmt->execute([$description, $customer, $id, $user_id]);
|
||||
error_log("Modificata quotation ID: $id");
|
||||
header("Location: quotations.php?status=success&message=" . urlencode("Quotation modificata con successo"));
|
||||
} catch (PDOException $e) {
|
||||
error_log("Errore PDO durante la modifica della quotation: " . $e->getMessage());
|
||||
header("Location: quotations.php?status=error&message=" . urlencode("Errore database: " . $e->getMessage()));
|
||||
}
|
||||
exit;
|
||||
}
|
||||
|
||||
@ -58,28 +65,43 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['action'] === 'delete' && isset($_POST['id'])) {
|
||||
$id = intval($_POST['id']);
|
||||
|
||||
$stmt = $pdo->prepare("DELETE FROM quotations WHERE id = ? AND iduser = ?");
|
||||
$stmt->execute([$id, $user_id]);
|
||||
|
||||
// Log cancellazione
|
||||
error_log("Cancellata quotation ID: $id");
|
||||
|
||||
header("Location: quotations.php?status=success&message=" . urlencode("Quotation cancellata con successo"));
|
||||
try {
|
||||
$stmt = $pdo->prepare("DELETE FROM quotations WHERE id = ? AND iduser = ?");
|
||||
$stmt->execute([$id, $user_id]);
|
||||
error_log("Cancellata quotation ID: $id");
|
||||
header("Location: quotations.php?status=success&message=" . urlencode("Quotation cancellata con successo"));
|
||||
} catch (PDOException $e) {
|
||||
error_log("Errore PDO durante la cancellazione della quotation: " . $e->getMessage());
|
||||
header("Location: quotations.php?status=error&message=" . urlencode("Errore database: " . $e->getMessage()));
|
||||
}
|
||||
exit;
|
||||
}
|
||||
|
||||
// Recupera tutte le quotations per l'utente
|
||||
$stmt = $pdo->prepare("SELECT * FROM quotations WHERE iduser = ? ORDER BY creation_date DESC");
|
||||
$stmt->execute([$user_id]);
|
||||
$quotations = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
try {
|
||||
$stmt = $pdo->prepare("SELECT * FROM quotations WHERE iduser = ? ORDER BY creation_date DESC");
|
||||
$stmt->execute([$user_id]);
|
||||
$quotations = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
} catch (PDOException $e) {
|
||||
error_log("Errore PDO durante il recupero delle quotations: " . $e->getMessage());
|
||||
$quotations = [];
|
||||
}
|
||||
|
||||
// Verifica se è richiesta la modifica di una quotation
|
||||
$editQuotation = null;
|
||||
if (isset($_GET['edit_id'])) {
|
||||
$editId = intval($_GET['edit_id']);
|
||||
$stmt = $pdo->prepare("SELECT * FROM quotations WHERE id = ? AND iduser = ?");
|
||||
$stmt->execute([$editId, $user_id]);
|
||||
$editQuotation = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
try {
|
||||
$stmt = $pdo->prepare("SELECT * FROM quotations WHERE id = ? AND iduser = ?");
|
||||
$stmt->execute([$editId, $user_id]);
|
||||
$editQuotation = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
if (!$editQuotation) {
|
||||
error_log("Nessuna quotation trovata per id: $editId");
|
||||
}
|
||||
} catch (PDOException $e) {
|
||||
error_log("Errore PDO durante il recupero della quotation per modifica: " . $e->getMessage());
|
||||
$editQuotation = null;
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
@ -95,7 +117,6 @@ if (isset($_GET['edit_id'])) {
|
||||
<link rel="stylesheet" href="https://cdn.datatables.net/1.13.4/css/jquery.dataTables.min.css">
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/fabric.js/5.3.1/fabric.min.js"></script>
|
||||
<style>
|
||||
/* Stili simili alla pagina fornita, adattati */
|
||||
.cell-changed {
|
||||
background-color: #fff3b0 !important;
|
||||
transition: background-color 0.3s ease;
|
||||
@ -212,6 +233,36 @@ if (isset($_GET['edit_id'])) {
|
||||
color: #000;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.modal.fade {
|
||||
z-index: 1060 !important;
|
||||
}
|
||||
|
||||
.modal-backdrop {
|
||||
z-index: 1055 !important;
|
||||
}
|
||||
|
||||
.overlay.toggle-icon {
|
||||
z-index: 1000 !important;
|
||||
}
|
||||
|
||||
.alert {
|
||||
margin-bottom: 15px;
|
||||
padding: 10px;
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
.alert-success {
|
||||
background-color: #d4edda;
|
||||
color: #155724;
|
||||
border: 1px solid #c3e6cb;
|
||||
}
|
||||
|
||||
.alert-danger {
|
||||
background-color: #f8d7da;
|
||||
color: #721c24;
|
||||
border: 1px solid #f5c6cb;
|
||||
}
|
||||
</style>
|
||||
<title>Gestione Quotations - <?= htmlspecialchars($titlewebsite, ENT_QUOTES, 'UTF-8'); ?></title>
|
||||
</head>
|
||||
@ -231,6 +282,11 @@ if (isset($_GET['edit_id'])) {
|
||||
</div>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<?php if (isset($_GET['status']) && isset($_GET['message'])): ?>
|
||||
<div class="alert alert-<?= $_GET['status'] === 'success' ? 'success' : 'danger' ?>">
|
||||
<?= htmlspecialchars(urldecode($_GET['message'])) ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<?php if ($editQuotation): ?>
|
||||
<!-- Modifica Quotation -->
|
||||
<h6 class="mb-3">Modifica Quotation ID: <?= $editQuotation['id'] ?></h6>
|
||||
@ -250,8 +306,8 @@ if (isset($_GET['edit_id'])) {
|
||||
</form>
|
||||
<div class="quotation-actions">
|
||||
<h6 class="mb-3">Azioni</h6>
|
||||
<button type="button" class="photos-btn action-btn" data-row="<?= $index ?>" data-idquotations="<?= $editQuotation['id'] ?>" style="background: #007bff; color: white; border: none; padding: 8px 12px; border-radius: 5px; cursor: pointer; flex: 1;"><i class="fas fa-camera"></i></button>
|
||||
<button class="parts-btn" data-iddatadb="" data-idquotations="456" data-row="0">Parti</button>
|
||||
<button type="button" class="photos-btn action-btn" data-row="0" data-idquotations="<?= $editQuotation['id'] ?>" style="background: #007bff; color: white; border: none; padding: 8px 12px; border-radius: 5px; cursor: pointer; flex: 1;"><i class="fas fa-camera"></i></button>
|
||||
<button type="button" class="parts-btn action-btn" data-iddatadb="" data-idquotations="<?= $editQuotation['id'] ?>" data-row="0">Parti</button>
|
||||
</div>
|
||||
<?php else: ?>
|
||||
<!-- Lista Quotations -->
|
||||
@ -270,7 +326,7 @@ if (isset($_GET['edit_id'])) {
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach ($quotations as $row): ?>
|
||||
<?php foreach ($quotations as $index => $row): ?>
|
||||
<tr data-id="<?= $row['id'] ?>">
|
||||
<td><?= htmlspecialchars($row['id']) ?></td>
|
||||
<td><?= htmlspecialchars($row['creation_date']) ?></td>
|
||||
@ -280,12 +336,11 @@ if (isset($_GET['edit_id'])) {
|
||||
<td>
|
||||
<input type="text" name="customer" class="cell-input manual-input form-control" value="<?= htmlspecialchars($row['customer']) ?>">
|
||||
</td>
|
||||
<!-- In quotations.php, nella tabella delle quotations -->
|
||||
<td>
|
||||
<button type="button" class="save-btn action-btn edit-btn" data-id="<?= $row['id'] ?>" title="Salva Modifiche"><i class="fas fa-save"></i></button>
|
||||
<button type="button" class="delete-btn action-btn" data-id="<?= $row['id'] ?>" title="Cancella" data-bs-toggle="modal" data-bs-target="#deleteModal"><i class="fas fa-trash"></i></button>
|
||||
<button type="button" class="photos-btn action-btn" data-entity-type="quotation" data-idquotations="<?= $row['id'] ?>" title="Photos"><i class="fas fa-camera"></i></button>
|
||||
<button type="button" class="parts-btn action-btn" data-entity-type="quotation" data-idquotations="<?= $row['id'] ?>" title="Parts"><i class="fas fa-puzzle-piece"></i></button>
|
||||
<button type="button" class="photos-btn action-btn" data-entity-type="quotation" data-idquotations="<?= $row['id'] ?>" data-row="<?= $index ?>" title="Photos"><i class="fas fa-camera"></i></button>
|
||||
<button type="button" class="parts-btn action-btn" data-entity-type="quotation" data-idquotations="<?= $row['id'] ?>" data-row="<?= $index ?>" title="Parts"><i class="fas fa-puzzle-piece"></i></button>
|
||||
<a href="quotations.php?edit_id=<?= $row['id'] ?>" class="btn btn-secondary action-btn" title="Modifica Dettagliata"><i class="fas fa-edit"></i></a>
|
||||
</td>
|
||||
</tr>
|
||||
@ -348,26 +403,75 @@ if (isset($_GET['edit_id'])) {
|
||||
<?php include('photos_functions.php'); ?>
|
||||
<?php include('jsinclude.php'); ?>
|
||||
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
|
||||
<script src="https://cdn.datatables.net/1.13.4/js/jquery.dataTables.min.js"></script>
|
||||
<script src="photos.js"></script>
|
||||
<script src="parts.js"></script>
|
||||
<script>
|
||||
document.addEventListener("DOMContentLoaded", function() {
|
||||
// Mostra messaggi di stato se presenti
|
||||
const urlParams = new URLSearchParams(window.location.search);
|
||||
const status = urlParams.get('status');
|
||||
const message = urlParams.get('message');
|
||||
if (status && message) {
|
||||
const alertDiv = document.createElement('div');
|
||||
alertDiv.className = `alert alert-${status === 'success' ? 'success' : 'danger'} temp-alert`;
|
||||
alertDiv.textContent = decodeURIComponent(message);
|
||||
document.querySelector('.card-body').prepend(alertDiv);
|
||||
setTimeout(() => {
|
||||
alertDiv.remove();
|
||||
}, 5000);
|
||||
}
|
||||
|
||||
// Inizializza DataTables se non siamo in modalità modifica
|
||||
if (!document.querySelector('#editForm')) {
|
||||
$('#quotationsTable').DataTable({
|
||||
"paging": true,
|
||||
"searching": true,
|
||||
"ordering": true,
|
||||
"info": true,
|
||||
"autoWidth": false,
|
||||
"responsive": true
|
||||
paging: true,
|
||||
searching: true,
|
||||
ordering: true,
|
||||
info: true,
|
||||
autoWidth: false,
|
||||
responsive: true
|
||||
});
|
||||
}
|
||||
|
||||
// Quando il modale di creazione si apre, nascondi l'overlay
|
||||
$('#createModal').on('show.bs.modal', function() {
|
||||
$('.overlay.toggle-icon').css('display', 'none');
|
||||
});
|
||||
|
||||
// Quando il modale si chiude, ripristina l'overlay
|
||||
$('#createModal').on('hide.bs.modal', function() {
|
||||
$('.overlay.toggle-icon').css('display', '');
|
||||
});
|
||||
|
||||
// Gestione conferma creazione nel modal
|
||||
document.getElementById('confirmCreate').addEventListener('click', function() {
|
||||
document.getElementById('createModalForm').submit();
|
||||
const createModal = bootstrap.Modal.getInstance(document.getElementById('createModal'));
|
||||
createModal.hide();
|
||||
const form = document.getElementById('createModalForm');
|
||||
const formData = new FormData(form);
|
||||
|
||||
fetch('quotations.php', {
|
||||
method: 'POST',
|
||||
body: formData
|
||||
}).then(response => {
|
||||
if (!response.ok) {
|
||||
throw new Error('Errore HTTP: ' + response.status);
|
||||
}
|
||||
return response.text();
|
||||
}).then(() => {
|
||||
window.location.href = 'quotations.php?status=success&message=' + encodeURIComponent('Quotation creata con successo');
|
||||
}).catch(error => {
|
||||
console.error('Errore durante la creazione della quotation:', error);
|
||||
const alertDiv = document.createElement('div');
|
||||
alertDiv.className = 'alert alert-danger temp-alert';
|
||||
alertDiv.textContent = 'Errore durante la creazione della quotation: ' + error.message;
|
||||
document.querySelector('.card-body').prepend(alertDiv);
|
||||
setTimeout(() => {
|
||||
alertDiv.remove();
|
||||
}, 5000);
|
||||
});
|
||||
});
|
||||
|
||||
// Gestione modifica inline e save nella lista
|
||||
@ -395,6 +499,9 @@ if (isset($_GET['edit_id'])) {
|
||||
} else {
|
||||
alert('Errore durante la modifica.');
|
||||
}
|
||||
}).catch(error => {
|
||||
console.error('Errore durante la modifica della quotation:', error);
|
||||
alert('Errore durante la modifica: ' + error.message);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user