Files
zibo-dashboard/public/userarea/scadenzario/include/my_deadlines_widget.php
T
RMubarakzyanov 7cbd74111d Merge branch 'main' into feature/user_profile
# Conflicts:
#	public/userarea/include/topbar.php
#	public/userarea/scadenzario/include/my_deadlines_widget.php
2026-05-21 22:44:42 +03:00

135 lines
4.3 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;
gap: 0.75rem;
margin-bottom: 1rem;
flex-wrap: wrap;
}
.my-deadlines-widgets .mdw {
flex: 1 1 260px;
display: flex;
align-items: center;
gap: 0.9rem;
padding: 0.85rem 1rem;
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-icon {
width: 42px;
height: 42px;
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
background: rgba(255, 255, 255, 0.22);
font-size: 1.2rem;
flex-shrink: 0;
}
.my-deadlines-widgets .mdw-body {
flex: 1;
line-height: 1.2;
}
.my-deadlines-widgets .mdw-count {
font-size: 1.6rem;
font-weight: 700;
}
.my-deadlines-widgets .mdw-label {
font-size: 0.8rem;
opacity: 0.95;
}
.my-deadlines-widgets .mdw-arrow {
opacity: 0.7;
font-size: 0.9rem;
}
</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">Task<?= $_overdue === 1 ? '' : 's' ?> scadut<?= $_overdue === 1 ? 'o' : 'i' ?> — <?= $_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>