diff --git a/public/userarea/scadenzario/ajax/complete_deadline.php b/public/userarea/scadenzario/ajax/complete_deadline.php
index 31dd90e..6592c08 100644
--- a/public/userarea/scadenzario/ajax/complete_deadline.php
+++ b/public/userarea/scadenzario/ajax/complete_deadline.php
@@ -57,12 +57,12 @@ try {
$ins = $pdo->prepare("
INSERT INTO scad_deadlines
- (category, topic, law_regulation, recurrence_type, due_date, check_date,
+ (subject_id, topic, law_regulation, recurrence_type, due_date, check_date,
document_date, notification_days, storage_location, notes, created_by, departments)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
");
$ins->execute([
- $deadline['category'], $deadline['topic'], $deadline['law_regulation'],
+ $deadline['subject_id'], $deadline['topic'], $deadline['law_regulation'],
$deadline['recurrence_type'], $dueDate->format('Y-m-d'),
$checkDate ? $checkDate->format('Y-m-d') : null,
$deadline['document_date'],
diff --git a/public/userarea/scadenzario/ajax/get_calendar_events.php b/public/userarea/scadenzario/ajax/get_calendar_events.php
index faaceaa..4185593 100644
--- a/public/userarea/scadenzario/ajax/get_calendar_events.php
+++ b/public/userarea/scadenzario/ajax/get_calendar_events.php
@@ -13,8 +13,10 @@ try {
$filterDept = $_GET['department'] ?? '';
$filterEmployee = $_GET['employee'] ?? '';
- $sql = "SELECT DISTINCT d.id, d.topic, d.category, d.due_date, d.status, d.notification_days, d.departments
+ $sql = "SELECT DISTINCT d.id, d.topic, d.due_date, d.status, d.notification_days, d.departments,
+ s.name AS subject_name, s.color AS subject_color
FROM scad_deadlines d
+ LEFT JOIN scad_subjects s ON s.id = d.subject_id
LEFT JOIN scad_deadline_employee de ON de.deadline_id = d.id
LEFT JOIN employees e ON e.id = de.employee_id";
@@ -73,14 +75,14 @@ try {
else { $color = '#5a8fd8'; }
$title = $d['topic'];
- if ($d['category']) $title = $d['category'] . ': ' . $title;
+ if (!empty($d['subject_name'])) $title = $d['subject_name'] . ': ' . $title;
$events[] = [
'id' => $d['id'],
'title' => $title,
'start' => $d['due_date'],
'backgroundColor' => $color,
- 'borderColor' => $color,
+ 'borderColor' => !empty($d['subject_color']) ? $d['subject_color'] : $color,
'url' => 'scadenzario/detail.php?id=' . $d['id'],
];
}
diff --git a/public/userarea/scadenzario/ajax/save_deadline.php b/public/userarea/scadenzario/ajax/save_deadline.php
index ce47ac3..58a999a 100644
--- a/public/userarea/scadenzario/ajax/save_deadline.php
+++ b/public/userarea/scadenzario/ajax/save_deadline.php
@@ -8,7 +8,7 @@ try {
$pdo = $db->getConnection();
$id = isset($_POST['id']) && is_numeric($_POST['id']) ? (int)$_POST['id'] : null;
- $category = trim($_POST['category'] ?? '') ?: null;
+ $subject_id = isset($_POST['subject_id']) && is_numeric($_POST['subject_id']) && (int)$_POST['subject_id'] > 0 ? (int)$_POST['subject_id'] : null;
$topic = trim($_POST['topic'] ?? '');
$law_regulation = trim($_POST['law_regulation'] ?? '') ?: null;
$recurrence_type = $_POST['recurrence_type'] ?? 'once';
@@ -52,13 +52,13 @@ try {
if ($id) {
$stmt = $pdo->prepare("
UPDATE scad_deadlines SET
- category = ?, topic = ?, law_regulation = ?, recurrence_type = ?,
+ subject_id = ?, topic = ?, law_regulation = ?, recurrence_type = ?,
due_date = ?, check_date = ?, document_date = ?, notification_days = ?,
storage_location = ?, notes = ?, departments = ?
WHERE id = ?
");
$stmt->execute([
- $category, $topic, $law_regulation, $recurrence_type,
+ $subject_id, $topic, $law_regulation, $recurrence_type,
$due_date, $check_date, $document_date, $notification_days,
$storage_location, $notes, $departmentsStr, $id
]);
@@ -75,12 +75,12 @@ try {
// INSERT
$stmt = $pdo->prepare("
INSERT INTO scad_deadlines
- (category, topic, law_regulation, recurrence_type, due_date, check_date,
+ (subject_id, topic, law_regulation, recurrence_type, due_date, check_date,
document_date, notification_days, storage_location, notes, created_by, departments)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
");
$stmt->execute([
- $category, $topic, $law_regulation, $recurrence_type,
+ $subject_id, $topic, $law_regulation, $recurrence_type,
$due_date, $check_date, $document_date, $notification_days,
$storage_location, $notes, $currentUserId, $departmentsStr
]);
diff --git a/public/userarea/scadenzario/cron/send_notifications.php b/public/userarea/scadenzario/cron/send_notifications.php
index dca2536..a8930b7 100644
--- a/public/userarea/scadenzario/cron/send_notifications.php
+++ b/public/userarea/scadenzario/cron/send_notifications.php
@@ -31,8 +31,9 @@ $errors = 0;
// Get active deadlines that are approaching or overdue
$stmt = $pdo->query("
- SELECT d.id, d.topic, d.category, d.due_date, d.notification_days
+ SELECT d.id, d.topic, s.name AS subject_name, d.due_date, d.notification_days
FROM scad_deadlines d
+ LEFT JOIN scad_subjects s ON s.id = d.subject_id
WHERE d.status = 'active'
AND d.due_date <= DATE_ADD(CURDATE(), INTERVAL d.notification_days DAY)
");
@@ -143,7 +144,7 @@ foreach ($deadlines as $dl) {
$mail->addAddress($emp['email'], trim($emp['first_name'] . ' ' . $emp['last_name']));
$detailUrl = $appUrl . '/userarea/scadenzario/detail.php?id=' . $dl['id'];
- $topicText = ($dl['category'] ? $dl['category'] . ' — ' : '') . $dl['topic'];
+ $topicText = (!empty($dl['subject_name']) ? $dl['subject_name'] . ' — ' : '') . $dl['topic'];
if ($isOverdue) {
$mail->Subject = '⚠️ Scadenza superata: ' . $dl['topic'];
diff --git a/public/userarea/scadenzario/detail.php b/public/userarea/scadenzario/detail.php
index 01c5fb2..9d9a95b 100644
--- a/public/userarea/scadenzario/detail.php
+++ b/public/userarea/scadenzario/detail.php
@@ -9,7 +9,12 @@ if (!isset($_GET['id']) || !is_numeric($_GET['id'])) {
$error = 'ID non valido.';
} else {
$id = (int)$_GET['id'];
- $stmt = $pdo->prepare("SELECT * FROM scad_deadlines WHERE id = ?");
+ $stmt = $pdo->prepare("
+ SELECT d.*, s.name AS subject_name, s.color AS subject_color
+ FROM scad_deadlines d
+ LEFT JOIN scad_subjects s ON s.id = d.subject_id
+ WHERE d.id = ?
+ ");
$stmt->execute([$id]);
$deadline = $stmt->fetch(PDO::FETCH_ASSOC);
@@ -263,9 +268,13 @@ if (!isset($_GET['id']) || !is_numeric($_GET['id'])) {
-
+
Argomento
-
= htmlspecialchars($deadline['category'], ENT_QUOTES, 'UTF-8') ?>
+
+
+ = htmlspecialchars($deadline['subject_name'], ENT_QUOTES, 'UTF-8') ?>
+
+
Dettaglio
diff --git a/public/userarea/scadenzario/index.php b/public/userarea/scadenzario/index.php
index 2d468ce..aa2a259 100644
--- a/public/userarea/scadenzario/index.php
+++ b/public/userarea/scadenzario/index.php
@@ -3,24 +3,46 @@
$db = DBHandlerSelect::getInstance();
$pdo = $db->getConnection();
-$stmt = $pdo->query("
+// Optional filter: show only deadlines of a given subject (used by "Storico" link from subjects CRUD)
+$filterSubjectId = isset($_GET['subject_id']) && is_numeric($_GET['subject_id']) ? (int)$_GET['subject_id'] : null;
+$filterSubjectName = null;
+if ($filterSubjectId) {
+ $s = $pdo->prepare("SELECT name FROM scad_subjects WHERE id = ?");
+ $s->execute([$filterSubjectId]);
+ $filterSubjectName = $s->fetchColumn() ?: null;
+ if (!$filterSubjectName) { $filterSubjectId = null; }
+}
+
+$sql = "
SELECT d.*,
+ s.name AS subject_name,
+ s.color AS subject_color,
GROUP_CONCAT(DISTINCT CONCAT(e.first_name, ' ', e.last_name) ORDER BY e.first_name SEPARATOR ', ') as responsabili,
GROUP_CONCAT(DISTINCT e.department ORDER BY e.department SEPARATOR ', ') as reparti_persone,
d.departments as reparti_assegnati,
(SELECT COUNT(*) FROM scad_deadline_attachments att WHERE att.deadline_id = d.id) as attachment_count
FROM scad_deadlines d
+ LEFT JOIN scad_subjects s ON s.id = d.subject_id
LEFT JOIN scad_deadline_employee de ON de.deadline_id = d.id
LEFT JOIN employees e ON e.id = de.employee_id
- GROUP BY d.id
- ORDER BY (d.status = 'completed') ASC, d.due_date ASC
-");
+";
+$params = [];
+if ($filterSubjectId) {
+ $sql .= " WHERE d.subject_id = ?";
+ $params[] = $filterSubjectId;
+}
+$sql .= " GROUP BY d.id ORDER BY (d.status = 'completed') ASC, d.due_date ASC";
+
+$stmt = $pdo->prepare($sql);
+$stmt->execute($params);
$deadlines = $stmt->fetchAll(PDO::FETCH_ASSOC);
$employees = $pdo->query("SELECT id, first_name, last_name, department FROM employees WHERE status = 'active' ORDER BY first_name")->fetchAll(PDO::FETCH_ASSOC);
$departments = $pdo->query("SELECT DISTINCT department FROM employees WHERE department IS NOT NULL AND department != '' ORDER BY department")->fetchAll(PDO::FETCH_COLUMN);
+$subjects = $pdo->query("SELECT id, name, color FROM scad_subjects ORDER BY name")->fetchAll(PDO::FETCH_ASSOC);
+
$today = date('Y-m-d');
?>
@@ -137,6 +159,32 @@ $today = date('Y-m-d');
#deadlinesTable tbody tr.row-completed { opacity: 0.6; }
#deadlinesTable tbody tr:hover { filter: brightness(0.97); }
+ /* Subject color stripe */
+ #deadlinesTable tbody tr[data-subject-color] td:first-child {
+ border-left: 4px solid var(--subject-color, transparent);
+ }
+ .subject-chip {
+ display: inline-block;
+ padding: 0.15rem 0.55rem;
+ border-radius: 1rem;
+ font-size: 0.72rem;
+ font-weight: 600;
+ color: #fff;
+ letter-spacing: 0.02em;
+ white-space: nowrap;
+ }
+ .deadline-card[data-subject-color] {
+ border-left: 4px solid var(--subject-color, var(--scad-card-border));
+ }
+
+ /* Filter banner (subject history mode) */
+ .subject-filter-banner {
+ display: flex; align-items: center; justify-content: space-between;
+ gap: 0.75rem; padding: 0.75rem 1rem;
+ background: var(--scad-card-bg); border: 1px solid var(--scad-card-border);
+ border-radius: 0.5rem; margin-bottom: 1rem; font-size: 0.9rem;
+ }
+
/* Filter bar */
.filter-bar .form-select {
border-radius: 0.5rem;
@@ -244,19 +292,46 @@ $today = date('Y-m-d');
+
+
+
+
+ Storico per argomento:
+ = htmlspecialchars($filterSubjectName, ENT_QUOTES, 'UTF-8') ?>
+ (tutte le scadenze — aperte e chiuse)
+
+
+ Rimuovi filtro
+
+
+
+
+
+
+