trainings changed details
This commit is contained in:
+400
-85
@@ -23,7 +23,7 @@ $fEmployeeId = isset($_GET['employee_id']) && $_GET['employee_id'] !== '' ?
|
||||
$fTopicId = isset($_GET['topic_id']) && $_GET['topic_id'] !== '' ? (int)$_GET['topic_id'] : 0;
|
||||
$fStatus = isset($_GET['status']) ? trim($_GET['status']) : '';
|
||||
$fType = isset($_GET['type']) ? trim($_GET['type']) : '';
|
||||
$fDepartmentId = isset($_GET['department_id'])&& $_GET['department_id']!== '' ? (int)$_GET['department_id']: 0;
|
||||
$fDepartmentId = isset($_GET['department_id']) && $_GET['department_id'] !== '' ? (int)$_GET['department_id'] : 0;
|
||||
|
||||
/* ==========================================
|
||||
LOAD DATA
|
||||
@@ -39,13 +39,22 @@ $where[] = "NOT EXISTS (
|
||||
AND (et2.completed_date > et.completed_date
|
||||
OR (et2.completed_date = et.completed_date AND et2.id > et.id))
|
||||
)";
|
||||
if ($fEmployeeId > 0) { $where[] = 'et.employee_id = :eid'; $params['eid'] = $fEmployeeId; }
|
||||
if ($fTopicId > 0) { $where[] = 'et.training_topic_id = :tid'; $params['tid'] = $fTopicId; }
|
||||
if ($fEmployeeId > 0) {
|
||||
$where[] = 'et.employee_id = :eid';
|
||||
$params['eid'] = $fEmployeeId;
|
||||
}
|
||||
if ($fTopicId > 0) {
|
||||
$where[] = 'et.training_topic_id = :tid';
|
||||
$params['tid'] = $fTopicId;
|
||||
}
|
||||
if ($fType !== '' && in_array($fType, ['initial', 'refresher'], true)) {
|
||||
$where[] = 'et.training_type = :ty';
|
||||
$params['ty'] = $fType;
|
||||
}
|
||||
if ($fDepartmentId > 0) { $where[] = 'e.department_id = :did'; $params['did'] = $fDepartmentId; }
|
||||
if ($fDepartmentId > 0) {
|
||||
$where[] = 'e.department_id = :did';
|
||||
$params['did'] = $fDepartmentId;
|
||||
}
|
||||
$whereSql = $where ? ('WHERE ' . implode(' AND ', $where)) : '';
|
||||
|
||||
$stmt = $pdo->prepare("
|
||||
@@ -66,7 +75,8 @@ $stmt->execute($params);
|
||||
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
/* Filter by computed status */
|
||||
function trainingStatus(?string $nextDue, ?int $reminderDays, ?int $topicDefaultRem): array {
|
||||
function trainingStatus(?string $nextDue, ?int $reminderDays, ?int $topicDefaultRem): array
|
||||
{
|
||||
if (!$nextDue) {
|
||||
return ['code' => 'compliant', 'label' => 'Conforme', 'class' => 'success'];
|
||||
}
|
||||
@@ -83,9 +93,11 @@ function trainingStatus(?string $nextDue, ?int $reminderDays, ?int $topicDefault
|
||||
$filtered = [];
|
||||
$counters = ['compliant' => 0, 'due_soon' => 0, 'expired' => 0, 'not_present' => 0, 'all' => 0];
|
||||
foreach ($rows as $r) {
|
||||
$s = trainingStatus($r['next_due_date'] ?: null,
|
||||
$s = trainingStatus(
|
||||
$r['next_due_date'] ?: null,
|
||||
$r['reminder_days'] !== null ? (int)$r['reminder_days'] : null,
|
||||
$r['topic_default_rem'] !== null ? (int)$r['topic_default_rem'] : null);
|
||||
$r['topic_default_rem'] !== null ? (int)$r['topic_default_rem'] : null
|
||||
);
|
||||
$r['_status'] = $s;
|
||||
$counters['all']++;
|
||||
$counters[$s['code']] = ($counters[$s['code']] ?? 0) + 1;
|
||||
@@ -101,9 +113,18 @@ foreach ($rows as $r) {
|
||||
if ($fType === '' || $fType === 'initial') {
|
||||
$missingWhere = [];
|
||||
$missingParams = [];
|
||||
if ($fEmployeeId > 0) { $missingWhere[] = 'e.id = :eid'; $missingParams['eid'] = $fEmployeeId; }
|
||||
if ($fTopicId > 0) { $missingWhere[] = 'tt.id = :tid'; $missingParams['tid'] = $fTopicId; }
|
||||
if ($fDepartmentId > 0) { $missingWhere[] = 'e.department_id = :did'; $missingParams['did'] = $fDepartmentId; }
|
||||
if ($fEmployeeId > 0) {
|
||||
$missingWhere[] = 'e.id = :eid';
|
||||
$missingParams['eid'] = $fEmployeeId;
|
||||
}
|
||||
if ($fTopicId > 0) {
|
||||
$missingWhere[] = 'tt.id = :tid';
|
||||
$missingParams['tid'] = $fTopicId;
|
||||
}
|
||||
if ($fDepartmentId > 0) {
|
||||
$missingWhere[] = 'e.department_id = :did';
|
||||
$missingParams['did'] = $fDepartmentId;
|
||||
}
|
||||
$missingWhereSql = $missingWhere ? ('AND ' . implode(' AND ', $missingWhere)) : '';
|
||||
|
||||
$missingStmt = $pdo->prepare("
|
||||
@@ -163,7 +184,8 @@ $departments = $pdo->query("
|
||||
SELECT id, name, color FROM departments WHERE is_active = 1 ORDER BY sort_order, name
|
||||
")->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
function fmtDate(?string $d): string {
|
||||
function fmtDate(?string $d): string
|
||||
{
|
||||
if (!$d || $d === '0000-00-00') return '—';
|
||||
$ts = strtotime($d);
|
||||
return $ts ? date('d/m/Y', $ts) : '—';
|
||||
@@ -186,53 +208,266 @@ function fmtDate(?string $d): string {
|
||||
<script src="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/js/select2.min.js"></script>
|
||||
|
||||
<style>
|
||||
body { font-size: 1.05rem; background: #f8fafc; }
|
||||
.card { border-radius: 16px; box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08); }
|
||||
.back-dashboard {
|
||||
background-color: #cfe3ff !important; color: #1f2d3d !important;
|
||||
border: 1px solid #bcd4f4 !important; border-radius: 10px;
|
||||
font-weight: 600; padding: 10px 18px;
|
||||
body {
|
||||
font-size: 1.05rem;
|
||||
background: #f8fafc;
|
||||
}
|
||||
.stat-row { display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px; margin-bottom: 20px; }
|
||||
@media (max-width: 991.98px) { .stat-row { grid-template-columns: repeat(3, 1fr); } }
|
||||
@media (max-width: 575.98px) { .stat-row { grid-template-columns: repeat(2, 1fr); } }
|
||||
.stat-card {
|
||||
border-radius: 14px; padding: 14px 16px; text-align: center;
|
||||
background: #fff; box-shadow: 0 2px 6px rgba(0,0,0,.05);
|
||||
cursor: pointer; transition: transform .15s;
|
||||
}
|
||||
.stat-card:hover { transform: translateY(-2px); }
|
||||
.stat-card.active { outline: 3px solid #0d6efd; }
|
||||
.stat-card .stat-num { font-size: 1.8rem; font-weight: 700; line-height: 1; }
|
||||
.stat-card .stat-label { font-size: 0.85rem; color: #64748b; margin-top: 4px; }
|
||||
.stat-card.all .stat-num { color: #1f2937; }
|
||||
.stat-card.compliant .stat-num { color: #16a34a; }
|
||||
.stat-card.due_soon .stat-num { color: #d97706; }
|
||||
.stat-card.expired .stat-num { color: #dc2626; }
|
||||
.stat-card.not_present .stat-num { color: #6b7280; }
|
||||
|
||||
.pill { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 0.85rem; font-weight: 600; }
|
||||
.pill-success { background: #d1fae5; color: #065f46; }
|
||||
.pill-warning { background: #fef3c7; color: #92400e; }
|
||||
.pill-danger { background: #fee2e2; color: #991b1b; }
|
||||
.pill-secondary { background: #e5e7eb; color: #374151; }
|
||||
.pill-role { background: #fff; color: #334155; border: 1px solid #cbd5e1; }
|
||||
.pill-dept-inline { padding: 2px 8px; }
|
||||
.card {
|
||||
border-radius: 16px;
|
||||
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
|
||||
}
|
||||
|
||||
.back-dashboard {
|
||||
background-color: #cfe3ff !important;
|
||||
color: #1f2d3d !important;
|
||||
border: 1px solid #bcd4f4 !important;
|
||||
border-radius: 10px;
|
||||
font-weight: 600;
|
||||
padding: 10px 18px;
|
||||
}
|
||||
|
||||
.training-header-actions {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.btn-training-action {
|
||||
border-radius: 10px;
|
||||
font-weight: 500;
|
||||
padding: 10px 16px;
|
||||
box-shadow: 0 3px 8px rgba(0, 0, 0, 0.1);
|
||||
transition: all 0.2s ease-in-out;
|
||||
color: #fff !important;
|
||||
}
|
||||
|
||||
.btn-training-action:hover {
|
||||
transform: translateY(-2px);
|
||||
color: #fff !important;
|
||||
}
|
||||
|
||||
.btn-training-topics {
|
||||
background-color: #0d6efd !important;
|
||||
border: 1px solid #0b5ed7 !important;
|
||||
}
|
||||
|
||||
.btn-training-topics:hover {
|
||||
background-color: #0b5ed7 !important;
|
||||
}
|
||||
|
||||
.btn-training-calendar {
|
||||
background-color: #2563eb !important;
|
||||
border: 1px solid #1d4ed8 !important;
|
||||
}
|
||||
|
||||
.btn-training-calendar:hover {
|
||||
background-color: #1d4ed8 !important;
|
||||
}
|
||||
|
||||
@media (max-width: 767.98px) {
|
||||
.training-header-actions {
|
||||
width: 100%;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.training-header-actions .btn,
|
||||
.training-header-actions a {
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
|
||||
.stat-row {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(5, 1fr);
|
||||
gap: 12px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
@media (max-width: 991.98px) {
|
||||
.stat-row {
|
||||
grid-template-columns: repeat(3, 1fr);
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 575.98px) {
|
||||
.stat-row {
|
||||
grid-template-columns: repeat(2, 1fr);
|
||||
}
|
||||
}
|
||||
|
||||
.stat-card {
|
||||
border-radius: 14px;
|
||||
padding: 14px 16px;
|
||||
text-align: center;
|
||||
background: #fff;
|
||||
box-shadow: 0 2px 6px rgba(0, 0, 0, .05);
|
||||
cursor: pointer;
|
||||
transition: transform .15s, box-shadow .15s, border-color .15s;
|
||||
border: 1px solid transparent;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.stat-card:hover {
|
||||
transform: translateY(-2px);
|
||||
box-shadow: 0 6px 14px rgba(0, 0, 0, .10);
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.stat-card.active {
|
||||
outline: 3px solid #0d6efd;
|
||||
outline-offset: 2px;
|
||||
}
|
||||
|
||||
.stat-card .stat-num {
|
||||
font-size: 1.8rem;
|
||||
font-weight: 800;
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
.stat-card .stat-label {
|
||||
font-size: 0.85rem;
|
||||
margin-top: 4px;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
/* Totale */
|
||||
.stat-card.all {
|
||||
background: #f8fafc;
|
||||
border-color: #cbd5e1;
|
||||
}
|
||||
|
||||
.stat-card.all .stat-num,
|
||||
.stat-card.all .stat-label {
|
||||
color: #1f2937;
|
||||
}
|
||||
|
||||
/* Conforme - verde */
|
||||
.stat-card.compliant {
|
||||
background: #dcfce7;
|
||||
border-color: #86efac;
|
||||
}
|
||||
|
||||
.stat-card.compliant .stat-num,
|
||||
.stat-card.compliant .stat-label {
|
||||
color: #166534;
|
||||
}
|
||||
|
||||
/* Da aggiornare - arancio */
|
||||
.stat-card.due_soon {
|
||||
background: #ffedd5;
|
||||
border-color: #fdba74;
|
||||
}
|
||||
|
||||
.stat-card.due_soon .stat-num,
|
||||
.stat-card.due_soon .stat-label {
|
||||
color: #9a3412;
|
||||
}
|
||||
|
||||
/* Scaduti - rosso */
|
||||
.stat-card.expired {
|
||||
background: #fee2e2;
|
||||
border-color: #fca5a5;
|
||||
}
|
||||
|
||||
.stat-card.expired .stat-num,
|
||||
.stat-card.expired .stat-label {
|
||||
color: #991b1b;
|
||||
}
|
||||
|
||||
/* Non presenti - rosso diverso / bordeaux */
|
||||
.stat-card.not_present {
|
||||
background: #fce7f3;
|
||||
border-color: #f9a8d4;
|
||||
}
|
||||
|
||||
.stat-card.not_present .stat-num,
|
||||
.stat-card.not_present .stat-label {
|
||||
color: #9d174d;
|
||||
}
|
||||
|
||||
.pill {
|
||||
display: inline-block;
|
||||
padding: 3px 10px;
|
||||
border-radius: 999px;
|
||||
font-size: 0.85rem;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.pill-success {
|
||||
background: #d1fae5;
|
||||
color: #065f46;
|
||||
}
|
||||
|
||||
.pill-warning {
|
||||
background: #fef3c7;
|
||||
color: #92400e;
|
||||
}
|
||||
|
||||
.pill-danger {
|
||||
background: #fee2e2;
|
||||
color: #991b1b;
|
||||
}
|
||||
|
||||
.pill-secondary {
|
||||
background: #e5e7eb;
|
||||
color: #374151;
|
||||
}
|
||||
|
||||
.pill-role {
|
||||
background: #fff;
|
||||
color: #334155;
|
||||
border: 1px solid #cbd5e1;
|
||||
}
|
||||
|
||||
.pill-dept-inline {
|
||||
padding: 2px 8px;
|
||||
}
|
||||
|
||||
.tr-card {
|
||||
border: 1px solid #e2e8f0; border-radius: 14px;
|
||||
padding: 14px 16px; margin-bottom: 12px;
|
||||
border: 1px solid #e2e8f0;
|
||||
border-radius: 14px;
|
||||
padding: 14px 16px;
|
||||
margin-bottom: 12px;
|
||||
background: #fff;
|
||||
box-shadow: 0 2px 6px rgba(0, 0, 0, 0.04);
|
||||
}
|
||||
.tr-card .name a { color: #1f2937; font-weight: 600; text-decoration: none; }
|
||||
.tr-card .topic { color: #475569; }
|
||||
.tr-card .meta { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 0.85rem; color: #64748b; margin-top: 8px; }
|
||||
.tr-card .meta b { color: #1f2937; font-weight: 600; }
|
||||
|
||||
.tr-card .name a {
|
||||
color: #1f2937;
|
||||
font-weight: 600;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.tr-card .topic {
|
||||
color: #475569;
|
||||
}
|
||||
|
||||
.tr-card .meta {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 6px 14px;
|
||||
font-size: 0.85rem;
|
||||
color: #64748b;
|
||||
margin-top: 8px;
|
||||
}
|
||||
|
||||
.tr-card .meta b {
|
||||
color: #1f2937;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
@media (max-width: 767.98px) {
|
||||
.card-header { flex-direction: column; align-items: flex-start !important; gap: .5rem; }
|
||||
.back-dashboard { width: 100%; }
|
||||
.card-header {
|
||||
flex-direction: column;
|
||||
align-items: flex-start !important;
|
||||
gap: .5rem;
|
||||
}
|
||||
|
||||
.back-dashboard {
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
@@ -246,11 +481,25 @@ function fmtDate(?string $d): string {
|
||||
<div class="page-content">
|
||||
<div class="card p-3">
|
||||
<div class="card-header d-flex justify-content-between align-items-center flex-wrap gap-2">
|
||||
<h5 class="mb-0">📚 Storico Formazione</h5>
|
||||
<div class="d-flex gap-2 flex-wrap">
|
||||
<h5 class="mb-0">📚 Gestione Formazione</h5>
|
||||
|
||||
<div class="training-header-actions">
|
||||
<button type="button" class="btn btn-primary" id="btnBulkTraining">
|
||||
➕ Aggiungi sessione
|
||||
</button>
|
||||
|
||||
<?php if (userCan('hr.training_topics.view')): ?>
|
||||
<a href="training_topics.php" class="btn btn-training-action btn-training-topics">
|
||||
📘 Corsi Formazione
|
||||
</a>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if (userCan('hr.trainings.view')): ?>
|
||||
<a href="training_calendar.php" class="btn btn-training-action btn-training-calendar">
|
||||
📅 Calendario Formazione
|
||||
</a>
|
||||
<?php endif; ?>
|
||||
|
||||
<button type="button" class="btn back-dashboard" onclick="location.href='production_dashboard.php'">
|
||||
↩️ Torna alla Dashboard
|
||||
</button>
|
||||
@@ -323,7 +572,7 @@ function fmtDate(?string $d): string {
|
||||
<label class="form-label small fw-semibold">Tipo</label>
|
||||
<select name="type" class="form-select form-select-sm" onchange="this.form.submit()">
|
||||
<option value="">— Tutti —</option>
|
||||
<option value="initial" <?= $fType === 'initial' ? 'selected' : '' ?>>Iniziale</option>
|
||||
<option value="initial" <?= $fType === 'initial' ? 'selected' : '' ?>>Iniziale</option>
|
||||
<option value="refresher" <?= $fType === 'refresher' ? 'selected' : '' ?>>Aggiornamento</option>
|
||||
</select>
|
||||
</div>
|
||||
@@ -387,7 +636,7 @@ function fmtDate(?string $d): string {
|
||||
<span class="pill pill-dept-inline" style="background:<?= htmlspecialchars($r['department_color'] ?? '#e5e7eb', ENT_QUOTES) ?>20; color:<?= htmlspecialchars($r['department_color'] ?? '#374151', ENT_QUOTES) ?>;">
|
||||
<?= htmlspecialchars($r['department_name']) ?>
|
||||
</span>
|
||||
<?php else: ?>—<?php endif; ?>
|
||||
<?php else: ?>—<?php endif; ?>
|
||||
</td>
|
||||
<td><?= htmlspecialchars($r['topic_name']) ?></td>
|
||||
<td><span class="pill pill-role"><?= $typeLbl ?></span></td>
|
||||
@@ -396,11 +645,11 @@ function fmtDate(?string $d): string {
|
||||
<td><span class="pill pill-<?= $r['_status']['class'] ?>"><?= $r['_status']['label'] ?></span></td>
|
||||
<td>
|
||||
<?php if ($days === null): ?>—
|
||||
<?php elseif ($days < 0): ?>
|
||||
<span class="text-danger fw-semibold"><?= $days ?></span>
|
||||
<?php else: ?>
|
||||
+<?= $days ?>
|
||||
<?php endif; ?>
|
||||
<?php elseif ($days < 0): ?>
|
||||
<span class="text-danger fw-semibold"><?= $days ?></span>
|
||||
<?php else: ?>
|
||||
+<?= $days ?>
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
@@ -514,7 +763,9 @@ function fmtDate(?string $d): string {
|
||||
<textarea id="bulkDescription" class="form-control" rows="2"></textarea>
|
||||
</div>
|
||||
|
||||
<div class="col-12"><hr class="my-1"></div>
|
||||
<div class="col-12">
|
||||
<hr class="my-1">
|
||||
</div>
|
||||
|
||||
<div class="col-12">
|
||||
<label class="form-label fw-semibold">Dipendenti <span class="text-danger">*</span></label>
|
||||
@@ -600,7 +851,9 @@ function fmtDate(?string $d): string {
|
||||
});
|
||||
|
||||
document.getElementById('bulkSelectAll').addEventListener('click', function() {
|
||||
var all = $emp.find('option').map(function() { return this.value; }).get();
|
||||
var all = $emp.find('option').map(function() {
|
||||
return this.value;
|
||||
}).get();
|
||||
$emp.val(all).trigger('change');
|
||||
});
|
||||
document.getElementById('bulkClear').addEventListener('click', function() {
|
||||
@@ -613,9 +866,18 @@ function fmtDate(?string $d): string {
|
||||
var completed = document.getElementById('bulkCompletedDate').value;
|
||||
var emps = $emp.val() || [];
|
||||
|
||||
if (!topicId) { Swal.fire('Attenzione', 'Selezionare un corso.', 'warning'); return; }
|
||||
if (!completed) { Swal.fire('Attenzione', 'Indicare la data di completamento.', 'warning'); return; }
|
||||
if (emps.length === 0) { Swal.fire('Attenzione', 'Selezionare almeno un dipendente.', 'warning'); return; }
|
||||
if (!topicId) {
|
||||
Swal.fire('Attenzione', 'Selezionare un corso.', 'warning');
|
||||
return;
|
||||
}
|
||||
if (!completed) {
|
||||
Swal.fire('Attenzione', 'Indicare la data di completamento.', 'warning');
|
||||
return;
|
||||
}
|
||||
if (emps.length === 0) {
|
||||
Swal.fire('Attenzione', 'Selezionare almeno un dipendente.', 'warning');
|
||||
return;
|
||||
}
|
||||
|
||||
var btn = document.getElementById('bulkSaveBtn');
|
||||
btn.disabled = true;
|
||||
@@ -630,22 +892,39 @@ function fmtDate(?string $d): string {
|
||||
fd.append('description', document.getElementById('bulkDescription').value);
|
||||
fd.append('update_frequency_months', document.getElementById('bulkFreq').value);
|
||||
fd.append('reminder_days', document.getElementById('bulkRem').value);
|
||||
emps.forEach(function(id) { fd.append('employee_ids[]', id); });
|
||||
emps.forEach(function(id) {
|
||||
fd.append('employee_ids[]', id);
|
||||
});
|
||||
|
||||
fetch('ajax/trainings/save_bulk_training.php', { method: 'POST', body: fd })
|
||||
.then(function(r) { return r.json(); })
|
||||
fetch('ajax/trainings/save_bulk_training.php', {
|
||||
method: 'POST',
|
||||
body: fd
|
||||
})
|
||||
.then(function(r) {
|
||||
return r.json();
|
||||
})
|
||||
.then(function(data) {
|
||||
if (data.success) {
|
||||
bulkModal.hide();
|
||||
Swal.fire({ icon: 'success', title: 'Fatto', text: data.message, timer: 1800, showConfirmButton: false })
|
||||
.then(function() { location.reload(); });
|
||||
Swal.fire({
|
||||
icon: 'success',
|
||||
title: 'Fatto',
|
||||
text: data.message,
|
||||
timer: 1800,
|
||||
showConfirmButton: false
|
||||
})
|
||||
.then(function() {
|
||||
location.reload();
|
||||
});
|
||||
} else {
|
||||
btn.disabled = false; btn.innerHTML = orig;
|
||||
btn.disabled = false;
|
||||
btn.innerHTML = orig;
|
||||
Swal.fire('Errore', data.message || 'Errore.', 'error');
|
||||
}
|
||||
})
|
||||
.catch(function() {
|
||||
btn.disabled = false; btn.innerHTML = orig;
|
||||
btn.disabled = false;
|
||||
btn.innerHTML = orig;
|
||||
Swal.fire('Errore', 'Errore di connessione.', 'error');
|
||||
});
|
||||
});
|
||||
@@ -682,14 +961,22 @@ function fmtDate(?string $d): string {
|
||||
|
||||
function checkedIds() {
|
||||
return Array.prototype.slice.call(document.querySelectorAll('.row-check:checked'))
|
||||
.map(function(c) { return c.value; });
|
||||
.map(function(c) {
|
||||
return c.value;
|
||||
});
|
||||
}
|
||||
|
||||
function refreshBulkBar() {
|
||||
var ids = checkedIds();
|
||||
var bar = document.getElementById('bulkBar');
|
||||
document.getElementById('bulkSelCount').textContent = ids.length;
|
||||
if (ids.length > 0) { bar.classList.remove('d-none'); bar.classList.add('d-flex'); }
|
||||
else { bar.classList.add('d-none'); bar.classList.remove('d-flex'); }
|
||||
if (ids.length > 0) {
|
||||
bar.classList.remove('d-none');
|
||||
bar.classList.add('d-flex');
|
||||
} else {
|
||||
bar.classList.add('d-none');
|
||||
bar.classList.remove('d-flex');
|
||||
}
|
||||
var all = document.querySelectorAll('.row-check');
|
||||
if (checkAll) checkAll.checked = (all.length > 0 && ids.length === all.length);
|
||||
}
|
||||
@@ -698,11 +985,15 @@ function fmtDate(?string $d): string {
|
||||
if (e.target && e.target.classList && e.target.classList.contains('row-check')) refreshBulkBar();
|
||||
});
|
||||
if (checkAll) checkAll.addEventListener('change', function() {
|
||||
document.querySelectorAll('.row-check').forEach(function(c) { c.checked = checkAll.checked; });
|
||||
document.querySelectorAll('.row-check').forEach(function(c) {
|
||||
c.checked = checkAll.checked;
|
||||
});
|
||||
refreshBulkBar();
|
||||
});
|
||||
document.getElementById('btnBulkDeselect').addEventListener('click', function() {
|
||||
document.querySelectorAll('.row-check').forEach(function(c) { c.checked = false; });
|
||||
document.querySelectorAll('.row-check').forEach(function(c) {
|
||||
c.checked = false;
|
||||
});
|
||||
if (checkAll) checkAll.checked = false;
|
||||
refreshBulkBar();
|
||||
});
|
||||
@@ -718,8 +1009,14 @@ function fmtDate(?string $d): string {
|
||||
e.preventDefault();
|
||||
var ids = checkedIds();
|
||||
var date = document.getElementById('renewDate').value;
|
||||
if (ids.length === 0) { renewModal.hide(); return; }
|
||||
if (!date) { Swal.fire('Attenzione', 'Indicare la data.', 'warning'); return; }
|
||||
if (ids.length === 0) {
|
||||
renewModal.hide();
|
||||
return;
|
||||
}
|
||||
if (!date) {
|
||||
Swal.fire('Attenzione', 'Indicare la data.', 'warning');
|
||||
return;
|
||||
}
|
||||
|
||||
var btn = document.getElementById('renewSaveBtn');
|
||||
btn.disabled = true;
|
||||
@@ -728,26 +1025,44 @@ function fmtDate(?string $d): string {
|
||||
|
||||
var fd = new FormData();
|
||||
fd.append('completed_date', date);
|
||||
ids.forEach(function(id) { fd.append('training_ids[]', id); });
|
||||
ids.forEach(function(id) {
|
||||
fd.append('training_ids[]', id);
|
||||
});
|
||||
|
||||
fetch('ajax/trainings/bulk_update_deadline.php', { method: 'POST', body: fd })
|
||||
.then(function(r) { return r.json(); })
|
||||
fetch('ajax/trainings/bulk_update_deadline.php', {
|
||||
method: 'POST',
|
||||
body: fd
|
||||
})
|
||||
.then(function(r) {
|
||||
return r.json();
|
||||
})
|
||||
.then(function(data) {
|
||||
if (data.success) {
|
||||
renewModal.hide();
|
||||
Swal.fire({ icon: 'success', title: 'Fatto', text: data.message, timer: 1800, showConfirmButton: false })
|
||||
.then(function() { location.reload(); });
|
||||
Swal.fire({
|
||||
icon: 'success',
|
||||
title: 'Fatto',
|
||||
text: data.message,
|
||||
timer: 1800,
|
||||
showConfirmButton: false
|
||||
})
|
||||
.then(function() {
|
||||
location.reload();
|
||||
});
|
||||
} else {
|
||||
btn.disabled = false; btn.innerHTML = orig;
|
||||
btn.disabled = false;
|
||||
btn.innerHTML = orig;
|
||||
Swal.fire('Errore', data.message || 'Errore.', 'error');
|
||||
}
|
||||
})
|
||||
.catch(function() {
|
||||
btn.disabled = false; btn.innerHTML = orig;
|
||||
btn.disabled = false;
|
||||
btn.innerHTML = orig;
|
||||
Swal.fire('Errore', 'Errore di connessione.', 'error');
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
</html>
|
||||
Reference in New Issue
Block a user