loopkup, foglio di lavoro

This commit is contained in:
2026-02-03 16:04:45 +01:00
parent 31f22b4d92
commit 22e5b90fe4
6 changed files with 2505 additions and 30 deletions
+33 -30
View File
@@ -7,7 +7,7 @@ include('include/headscript.php');
$db = DBHandlerSelect::getInstance();
$pdo = $db->getConnection();
// AJAX salvataggio singolo (ora gestisce anche testo libero)
// AJAX salvataggio singolo
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['ajax']) && $_POST['ajax'] == '1') {
header('Content-Type: application/json');
@@ -20,8 +20,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['ajax']) && $_POST['aj
$pdo->prepare("DELETE FROM employee_skills WHERE employee_id = ? AND skill_id = ?")
->execute([$employee_id, $skill_id]);
// Salva solo se c'è valore (non vuoto)
if ($level !== '') {
if ($level !== '' && $level !== '–') {
$pdo->prepare("INSERT INTO employee_skills (employee_id, skill_id, level) VALUES (?, ?, ?)")
->execute([$employee_id, $skill_id, $level]);
}
@@ -47,7 +46,7 @@ $employees = $pdo->query("
$skills = $pdo->query("
SELECT
s.id,
s.name AS nome_completo,
s.name,
COALESCE(s.abbreviato, SUBSTRING(s.name, 1, 12)) AS acronimo,
pl.line_number,
pl.name AS linea
@@ -154,10 +153,9 @@ while ($r = $stmt->fetch(PDO::FETCH_ASSOC)) {
.table input[type="text"] {
background: #fffacd;
/* giallo chiaro per distinguere il campo testo */
}
/* COLORI LIVELLI (solo per select) */
/* COLORI LIVELLI */
.level-Q {
background: #d4edda;
color: #155724;
@@ -195,6 +193,14 @@ while ($r = $stmt->fetch(PDO::FETCH_ASSOC)) {
color: #6c757d;
}
/* Cella vuota / trattino */
td:empty,
td select option[value="–"]:checked~select,
td input[value=""] {
background: #f8f9fa !important;
color: #6c757d;
}
.table-responsive {
overflow-x: auto;
}
@@ -229,7 +235,7 @@ while ($r = $stmt->fetch(PDO::FETCH_ASSOC)) {
<tr>
<?php foreach ($skills as $s): ?>
<th class="skill-col skill-header"
title="<?= htmlspecialchars($s['nome_completo']) ?>">
title="<?= htmlspecialchars($s['name']) ?>">
<?= htmlspecialchars($s['acronimo']) ?>
</th>
<?php endforeach; ?>
@@ -240,29 +246,33 @@ while ($r = $stmt->fetch(PDO::FETCH_ASSOC)) {
<tr>
<td class="fixed-name"><?= htmlspecialchars($emp['nome']) ?></td>
<?php foreach ($skills as $s):
$val = $livelli[$emp['id']][$s['id']] ?? '';
$cls = str_replace(['.', ' '], '-', $val);
// Default: trattino se non c'è valore
$val = $livelli[$emp['id']][$s['id']] ?? '–';
// Classe solo se valore reale (non trattino)
$cls = ($val !== '–' && $val !== '') ? str_replace(['.', ' '], '-', $val) : '';
?>
<td>
<?php if ($s['id'] == 29): ?>
<!-- Campo testo libero per id=29 -->
<!-- Campo testo: mostra vuoto se trattino -->
<input type="text"
class="form-control"
value="<?= htmlspecialchars($val) ?>"
value="<?= $val === '–' ? '' : htmlspecialchars($val) ?>"
onblur="salvaTesto(<?= $emp['id'] ?>, <?= $s['id'] ?>, this.value)">
<?php else: ?>
<!-- Tendina normale per tutte le altre -->
<select class="form-select level-<?= $cls ?>"
<!-- Tendina: include opzione "–" -->
<select class="form-select <?= $cls ? 'level-' . $cls : '' ?>"
onchange="salva(<?= $emp['id'] ?>, <?= $s['id'] ?>, this.value, this)">
<?php if (strpos($s['nome_completo'], 'TURNO NOTTURNO') !== false): ?>
<?php if (strpos($s['name'], 'TURNO NOTTURNO') !== false): ?>
<option value="si" <?= $val === 'si' ? 'selected' : '' ?>>si</option>
<option value="no" <?= $val === 'no' ? 'selected' : '' ?>>no</option>
<option value="–" <?= $val === '–' ? 'selected' : '' ?>>–</option>
<?php else: ?>
<option value="DF" <?= $val === 'DF' ? 'selected' : '' ?>>DF</option>
<option value="C" <?= $val === 'C' ? 'selected' : '' ?>>C</option>
<option value="CQ" <?= $val === 'CQ' ? 'selected' : '' ?>>CQ</option>
<option value="Q" <?= $val === 'Q' ? 'selected' : '' ?>>Q</option>
<option value="NON RICH." <?= $val === 'NON RICH.' ? 'selected' : '' ?>>–</option>
<option value="NON RICH." <?= $val === 'NON RICH.' ? 'selected' : '' ?>>NON RICH.</option>
<option value="–" <?= $val === '–' ? 'selected' : '' ?>>–</option>
<?php endif; ?>
</select>
<?php endif; ?>
@@ -282,7 +292,7 @@ while ($r = $stmt->fetch(PDO::FETCH_ASSOC)) {
</div>
<script>
// Salvataggio per tendina (onchange)
// Salvataggio per tendina
function salva(empId, skillId, val, selectElement) {
fetch('', {
method: 'POST',
@@ -301,21 +311,14 @@ while ($r = $stmt->fetch(PDO::FETCH_ASSOC)) {
showConfirmButton: false
});
// Aggiorna colore SOLO se selectElement è valido
if (selectElement && selectElement.tagName === 'SELECT') {
// Rimuovi tutte le classi level-*
selectElement.classList.forEach(c => {
if (c.startsWith('level-')) selectElement.classList.remove(c);
});
// Aggiungi la nuova classe level-*
const newCls = 'level-' + val.replace(/[\.\s]/g, '-');
selectElement.classList.add(newCls);
// (sicurezza) assicurati che resti form-select
selectElement.className = selectElement.className.replace(/\blevel-[^\s]+\b/g, '').trim();
if (val && val !== '–') {
const newCls = 'level-' + val.replace(/[\.\s]/g, '-');
selectElement.classList.add(newCls);
}
selectElement.classList.add('form-select');
}
} else {
Swal.fire({
icon: 'error',
@@ -328,13 +331,13 @@ while ($r = $stmt->fetch(PDO::FETCH_ASSOC)) {
console.error('Fetch error:', err);
Swal.fire({
icon: 'error',
title: 'Errore rete o parsing',
title: 'Errore rete',
text: err.message || 'Controlla console'
});
});
}
// Salvataggio per campo testo (onblur)
// Salvataggio per testo
function salvaTesto(empId, skillId, val) {
val = val.trim();
fetch('', {