Files
zibo-dashboard/public/userarea/scadenzario/include/my_deadlines_widget.php
T
2026-05-14 16:10:10 +03:00

107 lines
4.7 KiB
PHP

<?php
/**
* Renders two status banners for the current user:
* - red -> overdue deadlines (scaduta)
* - orange -> approaching deadlines (in scadenza)
* Scope: deadlines assigned directly to the user OR to their department.
*/
$_empStmt = $pdo->prepare("SELECT id, department FROM employees WHERE auth_user_id = ? LIMIT 1");
$_empStmt->execute([(int)$iduserlogin]);
$_emp = $_empStmt->fetch(PDO::FETCH_ASSOC) ?: null;
$_overdue = 0;
$_approaching = 0;
if ($_emp) {
$_empId = (int)$_emp['id'];
$_deptRaw = (string)($_emp['department'] ?? '');
$_dept = trim($_deptRaw);
$_sql = "
SELECT
SUM(CASE WHEN d.due_date < CURDATE() THEN 1 ELSE 0 END) AS overdue_cnt,
SUM(CASE WHEN d.due_date >= CURDATE()
AND d.due_date <= DATE_ADD(CURDATE(), INTERVAL d.notification_days DAY)
THEN 1 ELSE 0 END) AS approaching_cnt
FROM scad_deadlines d
WHERE d.status <> 'completed'
AND (
d.id IN (SELECT deadline_id FROM scad_deadline_employee WHERE employee_id = ?)
OR (? <> '' AND FIND_IN_SET(?, REPLACE(d.departments, ', ', ',')) > 0)
)
";
$_st = $pdo->prepare($_sql);
$_st->execute([$_empId, $_dept, $_dept]);
$_row = $_st->fetch(PDO::FETCH_ASSOC) ?: [];
$_overdue = (int)($_row['overdue_cnt'] ?? 0);
$_approaching = (int)($_row['approaching_cnt'] ?? 0);
}
if (!$_emp || ($_overdue === 0 && $_approaching === 0)) {
return;
}
?>
<style>
.my-deadlines-widgets {
display: flex; flex-wrap: wrap; gap: 0.75rem;
margin-bottom: 1rem; width: 100%;
}
.my-deadlines-widgets:empty { display: none; }
/* When two widget containers are nested inside an outer .my-deadlines-widgets
(e.g. on the production dashboard), let their children flow into the outer flex. */
.my-deadlines-widgets .my-deadlines-widgets {
display: contents;
}
.my-deadlines-widgets .mdw {
flex: 1 1 0; min-width: 0;
display: flex; align-items: center; gap: 0.75rem;
padding: 0.8rem 0.9rem; border-radius: 0.6rem;
text-decoration: none; color: #fff;
box-shadow: 0 2px 6px rgba(0,0,0,0.08);
transition: transform 0.15s, box-shadow 0.15s;
}
.my-deadlines-widgets .mdw:hover { transform: translateY(-1px); box-shadow: 0 4px 12px rgba(0,0,0,0.15); color: #fff; }
.my-deadlines-widgets .mdw-red { background: linear-gradient(135deg, #dc3545 0%, #b02a37 100%); }
.my-deadlines-widgets .mdw-orange { background: linear-gradient(135deg, #e8930c 0%, #c77a00 100%); }
.my-deadlines-widgets .mdw-gray { background: linear-gradient(135deg, #6b7280 0%, #4b5563 100%); }
.my-deadlines-widgets .mdw-icon {
width: 38px; height: 38px; border-radius: 50%;
display: flex; align-items: center; justify-content: center;
background: rgba(255,255,255,0.22); font-size: 1.05rem; flex-shrink: 0;
}
.my-deadlines-widgets .mdw-body { flex: 1; line-height: 1.2; min-width: 0; }
.my-deadlines-widgets .mdw-count { font-size: 1.5rem; font-weight: 700; }
.my-deadlines-widgets .mdw-label { font-size: 0.78rem; opacity: 0.95;
overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.my-deadlines-widgets .mdw-arrow { opacity: 0.7; font-size: 0.85rem; flex-shrink: 0; }
@media (max-width: 991.98px) {
.my-deadlines-widgets .mdw { flex: 1 1 calc(50% - 0.375rem); }
}
@media (max-width: 575.98px) {
.my-deadlines-widgets .mdw { flex: 1 1 100%; }
}
</style>
<div class="my-deadlines-widgets">
<?php if ($_overdue > 0): ?>
<a class="mdw mdw-red" href="scadenzario/index.php?filter_my=1&filter_status=scaduta">
<span class="mdw-icon"><i class="fa-solid fa-triangle-exclamation"></i></span>
<span class="mdw-body">
<span class="mdw-count"><?= $_overdue ?></span>
<span class="mdw-label d-block">Scadenz<?= $_overdue === 1 ? 'a' : 'e' ?> scadut<?= $_overdue === 1 ? 'a' : 'e' ?> — <?= $_dept !== '' ? htmlspecialchars($_dept, ENT_QUOTES, 'UTF-8') : 'personali' ?></span>
</span>
<span class="mdw-arrow"><i class="fa-solid fa-arrow-right"></i></span>
</a>
<?php endif; ?>
<?php if ($_approaching > 0): ?>
<a class="mdw mdw-orange" href="scadenzario/index.php?filter_my=1&filter_status=in-scadenza">
<span class="mdw-icon"><i class="fa-solid fa-clock"></i></span>
<span class="mdw-body">
<span class="mdw-count"><?= $_approaching ?></span>
<span class="mdw-label d-block">In scadenza a breve — <?= $_dept !== '' ? htmlspecialchars($_dept, ENT_QUOTES, 'UTF-8') : 'personali' ?></span>
</span>
<span class="mdw-arrow"><i class="fa-solid fa-arrow-right"></i></span>
</a>
<?php endif; ?>
</div>