trf_certest/public/userarea/templates_dashboard.php
2025-03-08 08:34:00 +01:00

275 lines
10 KiB
PHP

<?php include('include/headscript.php'); ?>
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!--favicon-->
<link rel="icon" href="assets/images/favicon-32x32.png" type="image/png" />
<?php include('cssinclude.php'); ?>
<title>TRF-Project - Template Dashboard</title>
<link rel="stylesheet" href="https://cdn.datatables.net/1.13.6/css/dataTables.bootstrap5.min.css">
<style>
.switch {
position: relative;
display: inline-block;
width: 34px;
height: 20px;
}
.switch input {
opacity: 0;
width: 0;
height: 0;
}
.slider {
position: absolute;
cursor: pointer;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: #ccc;
transition: .4s;
border-radius: 34px;
}
.slider:before {
position: absolute;
content: "";
height: 12px;
width: 12px;
left: 4px;
bottom: 4px;
background-color: white;
transition: .4s;
border-radius: 50%;
}
input:checked+.slider {
background-color: #4CAF50;
}
input:checked+.slider:before {
transform: translateX(14px);
}
</style>
</head>
<body>
<!--wrapper-->
<div class="wrapper">
<!--sidebar wrapper -->
<?php include('include/navbar.php'); ?>
<!--end sidebar wrapper -->
<!--start header -->
<?php include('include/topbar.php'); ?>
<!--end header -->
<!--start page wrapper -->
<div class="page-wrapper">
<div class="page-content">
<?php include('top_stat_widget.php'); ?>
<div class="card radius-10">
<div class="card-header">
<div class="d-flex align-items-center justify-content-between">
<h6 class="mb-0">XLS Templates Dashboard</h6>
<a href="insert_template_xls.php" class="btn btn-success ms-auto">
<i class="fas fa-plus"></i> New Template
</a>
</div>
</div>
<div class="card-body">
<div class="table-responsive">
<table id="xlsTemplatesTable" class="table table-striped table-bordered">
<thead>
<tr>
<th>ID</th>
<th><?= htmlspecialchars($nametemplate, ENT_QUOTES, 'UTF-8'); ?></th>
<th><?= htmlspecialchars($lastmodtemplate, ENT_QUOTES, 'UTF-8'); ?></th>
<th><?= htmlspecialchars($rowheader, ENT_QUOTES, 'UTF-8'); ?></th>
<th><?= htmlspecialchars($columnheader, ENT_QUOTES, 'UTF-8'); ?></th>
<th><?= htmlspecialchars($desctemplate, ENT_QUOTES, 'UTF-8'); ?></th>
<th><?= htmlspecialchars($desttable, ENT_QUOTES, 'UTF-8'); ?></th>
<th><?= htmlspecialchars($action, ENT_QUOTES, 'UTF-8'); ?></th>
</tr>
</thead>
<tbody>
<!-- DataTables riempirà questa sezione automaticamente -->
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
<!--end page wrapper -->
<!--start overlay-->
<div class="overlay toggle-icon"></div>
<!--end overlay-->
<!--Start Back To Top Button-->
<a href="javaScript:;" class="back-to-top"><i class='bx bxs-up-arrow-alt'></i></a>
<!--End Back To Top Button-->
<?php include('include/footer.php'); ?>
</div>
<!--end wrapper-->
<!-- search modal -->
<?php //include('include/searchmodal.php');
?>
<!-- end search modal -->
<!--start switcher-->
<?php //include('include/themeswitcher.php');
?>
<!--end switcher-->
<?php include('jsinclude.php'); ?>
<script src="https://cdn.datatables.net/1.13.6/js/jquery.dataTables.min.js"></script>
<script src="https://cdn.datatables.net/1.13.6/js/dataTables.bootstrap5.min.js"></script>
<script>
$(document).ready(function() {
$('#xlsTemplatesTable').DataTable({
processing: true,
serverSide: false,
ajax: 'load_templates.php',
columns: [{
data: 'name', // Nome del template
title: "Template Name"
},
{
data: 'updated_at', // Ultima modifica, formattata come data leggibile
title: "Last Modified",
render: function(data) {
return new Date(data).toLocaleDateString();
}
},
{
data: 'header_row', // Riga degli header
title: "Header Row"
},
{
data: 'start_column', // Colonna di partenza
title: "Start Column"
},
{
data: 'description', // Descrizione del template
title: "Description",
defaultContent: 'No description'
},
{
data: 'target_table', // Tabella di destinazione
title: "Target Table"
},
{
data: 'status', // Stato con Toggle Switch
title: "Status",
orderable: false,
searchable: false,
render: function(status, type, row) {
let checked = (status === "active") ? "checked" : "";
return `
<label class="switch">
<input type="checkbox" class="toggle-status" data-id="${row.id}" ${checked}>
<span class="slider round"></span>
</label>
`;
}
},
{
data: 'id', // Azioni: Modifica, Mappatura e Eliminazione
orderable: false,
searchable: false,
title: "Actions",
render: function(data) {
return `
<div class="d-flex">
<a href="edit_template_xls.php?id=${data}" class="btn btn-sm btn-primary me-1">
<i class="bx bx-edit-alt"></i>
</a>
<a href="mapping_template_xls.php?id=${data}" class="btn btn-sm btn-success me-1">
<i class="bx bx-link-alt"></i>
</a>
<button class="btn btn-sm btn-danger" onclick="confirmDelete(${data})">
<i class="bx bx-trash"></i>
</button>
</div>
`;
}
}
],
dom: '<"card-header border-bottom p-3"<"d-flex align-items-center"<"card-title mb-0 flex-grow-1"f>>>rt<"card-footer border-top p-3"<"d-flex align-items-center"<"me-auto"l><"d-flex gap-2"ip>>>',
lengthMenu: [10, 25, 50, 100],
language: {
url: "//cdn.datatables.net/plug-ins/1.13.6/i18n/Italian.json",
search: "Cerca:",
lengthMenu: "Mostra _MENU_ elementi",
info: "Visualizzando da _START_ a _END_ di _TOTAL_ elementi",
paginate: {
first: "<?= $langdatatables['paginate_first'] ?>",
last: "<?= $langdatatables['paginate_last'] ?>",
next: "<?= $langdatatables['paginate_next'] ?>",
previous: "<?= $langdatatables['paginate_previous'] ?>"
}
}
});
});
function confirmDelete(id) {
Swal.fire({
title: "Are you sure?",
text: "This action cannot be undone!",
icon: "warning",
showCancelButton: true,
confirmButtonColor: "#d33",
cancelButtonColor: "#3085d6",
confirmButtonText: "Yes, delete it!",
cancelButtonText: "Cancel"
}).then((result) => {
if (result.isConfirmed) {
window.location.href = `delete_template_xls.php?id=${id}`;
}
});
}
$(document).on("change", ".toggle-status", function() {
let templateId = $(this).data("id");
let newStatus = $(this).is(":checked") ? "active" : "inactive";
$.ajax({
url: "update_template_status.php",
type: "POST",
data: {
id: templateId,
status: newStatus
},
success: function(response) {
if (response.success) {
console.log("✅ Status updated successfully.");
} else {
console.error("❌ Error updating status:", response.message);
alert("Error updating status: " + response.message);
}
},
error: function() {
console.error("❌ AJAX error.");
}
});
});
</script>
</body>
</html>