diff --git a/db/migrations/20260719125322_change_variazioni_to_flag.php b/db/migrations/20260719125322_change_variazioni_to_flag.php new file mode 100644 index 0000000..71cf7eb --- /dev/null +++ b/db/migrations/20260719125322_change_variazioni_to_flag.php @@ -0,0 +1,21 @@ +execute("ALTER TABLE `scad_deadlines` + CHANGE `variazioni` `variazioni` TINYINT(1) NOT NULL DEFAULT 0 + COMMENT 'Flag: in caso di variazioni'"); + } + + public function down(): void + { + $this->execute("ALTER TABLE `scad_deadlines` + CHANGE `variazioni` `variazioni` TEXT NULL DEFAULT NULL"); + } +} diff --git a/db/migrations/20260719130240_set_attiva_alert_default_on.php b/db/migrations/20260719130240_set_attiva_alert_default_on.php new file mode 100644 index 0000000..27305c4 --- /dev/null +++ b/db/migrations/20260719130240_set_attiva_alert_default_on.php @@ -0,0 +1,31 @@ +execute("ALTER TABLE `scad_deadlines` + CHANGE `attiva_alert` `attiva_alert` TINYINT(1) NOT NULL DEFAULT 1"); + } + + public function down(): void + { + $this->execute("ALTER TABLE `scad_deadlines` + CHANGE `attiva_alert` `attiva_alert` TINYINT(1) NOT NULL DEFAULT 0"); + } +} diff --git a/db/migrations/20260719130458_enable_attiva_alert_on_existing.php b/db/migrations/20260719130458_enable_attiva_alert_on_existing.php new file mode 100644 index 0000000..d4e3860 --- /dev/null +++ b/db/migrations/20260719130458_enable_attiva_alert_on_existing.php @@ -0,0 +1,22 @@ +execute("UPDATE `scad_deadlines` + SET `attiva_alert` = 1 + WHERE `status` = 'active'"); + } + + public function down(): void + { + $this->execute("UPDATE `scad_deadlines` + SET `attiva_alert` = 0 + WHERE `status` = 'active'"); + } +} diff --git a/public/userarea/scadenzario/ajax/complete_deadline.php b/public/userarea/scadenzario/ajax/complete_deadline.php index a192fd5..f71d9ac 100644 --- a/public/userarea/scadenzario/ajax/complete_deadline.php +++ b/public/userarea/scadenzario/ajax/complete_deadline.php @@ -50,17 +50,38 @@ try { $documentDate = $deadline['document_date'] ? new DateTime($deadline['document_date']) : null; switch ($deadline['recurrence_type']) { - case 'monthly': $interval = new DateInterval('P1M'); break; - case 'quarterly': $interval = new DateInterval('P3M'); break; - case 'semiannual': $interval = new DateInterval('P6M'); break; - case 'annual': $interval = new DateInterval('P1Y'); break; - case 'biennial': $interval = new DateInterval('P2Y'); break; - case 'triennial': $interval = new DateInterval('P3Y'); break; - case 'quadriennial': $interval = new DateInterval('P4Y'); break; - case 'quinquennial': $interval = new DateInterval('P5Y'); break; - case 'decennial': $interval = new DateInterval('P10Y'); break; - case 'quindecennial': $interval = new DateInterval('P15Y'); break; - default: $interval = null; + case 'monthly': + $interval = new DateInterval('P1M'); + break; + case 'quarterly': + $interval = new DateInterval('P3M'); + break; + case 'semiannual': + $interval = new DateInterval('P6M'); + break; + case 'annual': + $interval = new DateInterval('P1Y'); + break; + case 'biennial': + $interval = new DateInterval('P2Y'); + break; + case 'triennial': + $interval = new DateInterval('P3Y'); + break; + case 'quadriennial': + $interval = new DateInterval('P4Y'); + break; + case 'quinquennial': + $interval = new DateInterval('P5Y'); + break; + case 'decennial': + $interval = new DateInterval('P10Y'); + break; + case 'quindecennial': + $interval = new DateInterval('P15Y'); + break; + default: + $interval = null; } if ($interval) { @@ -70,17 +91,27 @@ try { $ins = $pdo->prepare(" INSERT INTO scad_deadlines - (subject_id, function_id, topic, law_regulation, recurrence_type, due_date, check_date, - document_date, notification_days, storage_location, notes, created_by, departments) - VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) + (subject_id, function_id, notify_function, topic, law_regulation, recurrence_type, due_date, check_date, + document_date, notification_days, storage_location, notes, variazioni, attiva_alert, created_by, departments) + VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) "); $ins->execute([ - $deadline['subject_id'], $deadline['function_id'], $deadline['topic'], $deadline['law_regulation'], - $deadline['recurrence_type'], $dueDate->format('Y-m-d'), + $deadline['subject_id'], + $deadline['function_id'], + $deadline['notify_function'], + $deadline['topic'], + $deadline['law_regulation'], + $deadline['recurrence_type'], + $dueDate->format('Y-m-d'), $checkDate ? $checkDate->format('Y-m-d') : null, $documentDate ? $documentDate->format('Y-m-d') : null, - $deadline['notification_days'], $deadline['storage_location'], - $deadline['notes'], $deadline['created_by'], $deadline['departments'] + $deadline['notification_days'], + $deadline['storage_location'], + $deadline['notes'], + $deadline['variazioni'], + $deadline['attiva_alert'], + $deadline['created_by'], + $deadline['departments'] ]); $newId = $pdo->lastInsertId(); @@ -137,7 +168,6 @@ try { } echo json_encode(['success' => true, 'message' => $msg, 'new_id' => $newId]); - } catch (Exception $e) { if (isset($pdo) && $pdo->inTransaction()) { $pdo->rollBack(); diff --git a/public/userarea/scadenzario/ajax/save_deadline.php b/public/userarea/scadenzario/ajax/save_deadline.php index 4495e36..a01cbdf 100644 --- a/public/userarea/scadenzario/ajax/save_deadline.php +++ b/public/userarea/scadenzario/ajax/save_deadline.php @@ -20,7 +20,8 @@ try { $notification_days = isset($_POST['notification_days']) && is_numeric($_POST['notification_days']) ? (int)$_POST['notification_days'] : 7; $storage_location = trim($_POST['storage_location'] ?? '') ?: null; $notes = trim($_POST['notes'] ?? '') ?: null; - $variazioni = trim($_POST['variazioni'] ?? '') ?: null; + $variazioni = !empty($_POST['variazioni']) ? 1 : 0; + $attiva_alert = !empty($_POST['attiva_alert']) ? 1 : 0; $employee_ids = $_POST['employee_ids'] ?? []; $department_names = $_POST['department_names'] ?? []; @@ -57,7 +58,7 @@ try { UPDATE scad_deadlines SET subject_id = ?, function_id = ?, notify_function = ?, topic = ?, law_regulation = ?, recurrence_type = ?, due_date = ?, check_date = ?, document_date = ?, notification_days = ?, - storage_location = ?, notes = ?, variazioni = ?, departments = ? + storage_location = ?, notes = ?, variazioni = ?, attiva_alert = ?, departments = ? WHERE id = ? "); $stmt->execute([ @@ -74,6 +75,7 @@ try { $storage_location, $notes, $variazioni, + $attiva_alert, $departmentsStr, $id ]); @@ -91,8 +93,8 @@ try { $stmt = $pdo->prepare(" INSERT INTO scad_deadlines (subject_id, function_id, notify_function, topic, law_regulation, recurrence_type, due_date, check_date, - document_date, notification_days, storage_location, notes, variazioni, created_by, departments) - VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) + document_date, notification_days, storage_location, notes, variazioni, attiva_alert, created_by, departments) + VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) "); $stmt->execute([ $subject_id, @@ -108,6 +110,7 @@ try { $storage_location, $notes, $variazioni, + $attiva_alert, $currentUserId, $departmentsStr ]); diff --git a/public/userarea/scadenzario/cron/send_notifications.php b/public/userarea/scadenzario/cron/send_notifications.php index 06ea757..d3f7b38 100644 --- a/public/userarea/scadenzario/cron/send_notifications.php +++ b/public/userarea/scadenzario/cron/send_notifications.php @@ -57,12 +57,13 @@ $stmt = $pdo->query(" LEFT JOIN scad_subjects s ON s.id = d.subject_id LEFT JOIN scad_functions f ON f.id = d.function_id WHERE d.status = 'active' + AND d.attiva_alert = 1 AND d.due_date <= DATE_ADD(CURDATE(), INTERVAL d.notification_days DAY) "); $deadlines = $stmt->fetchAll(PDO::FETCH_ASSOC); if (empty($deadlines)) { - echo date('Y-m-d H:i:s') . " — Nessuna scadenza da notificare.\n"; + echo date('Y-m-d H:i:s') . " — Nessuna scadenza da notificare (alert attivo).\n"; exit(0); } diff --git a/public/userarea/scadenzario/detail.php b/public/userarea/scadenzario/detail.php index c365288..b819a5d 100644 --- a/public/userarea/scadenzario/detail.php +++ b/public/userarea/scadenzario/detail.php @@ -646,6 +646,24 @@ if (!isset($_GET['id']) || !is_numeric($_GET['id'])) {
Note
+ +
Alert
+
+ + Attivo + + Non attivo + +
+ +
In caso di variazioni
+
+ + Sì + + No + +
diff --git a/public/userarea/scadenzario/include/deadline_modal.php b/public/userarea/scadenzario/include/deadline_modal.php index 2ddb12c..e8c0b69 100644 --- a/public/userarea/scadenzario/include/deadline_modal.php +++ b/public/userarea/scadenzario/include/deadline_modal.php @@ -147,8 +147,20 @@
- - +
+ + +
+
+
+
+ + +
diff --git a/public/userarea/scadenzario/include/deadline_modal_js.php b/public/userarea/scadenzario/include/deadline_modal_js.php index bb6ee65..8122992 100644 --- a/public/userarea/scadenzario/include/deadline_modal_js.php +++ b/public/userarea/scadenzario/include/deadline_modal_js.php @@ -135,6 +135,8 @@ $('#dlEmployees').val(null).trigger('change'); $('#dlFunction').val('').trigger('change'); $('#notify_function').prop('checked', false); + $('#dlVariazioni').prop('checked', false); + $('#dlAttivaAlert').prop('checked', false); renderAttachments([]); modal.show(); }; @@ -164,7 +166,8 @@ document.getElementById('dlNotifDays').value = d.notification_days || 7; document.getElementById('dlStorage').value = d.storage_location || ''; document.getElementById('dlNotes').value = d.notes || ''; - document.getElementById('dlVariazioni').value = d.variazioni || ''; + $('#dlVariazioni').prop('checked', Number(d.variazioni) === 1); + $('#dlAttivaAlert').prop('checked', Number(d.attiva_alert) === 1); document.getElementById('dlFiles').value = ''; document.getElementById('modalTitle').textContent = 'Modifica Scadenza'; $('#dlDepartments').val(d.department_names || []).trigger('change'); diff --git a/public/userarea/scadenzario/index.php b/public/userarea/scadenzario/index.php index 9ea5d73..92ea6ea 100644 --- a/public/userarea/scadenzario/index.php +++ b/public/userarea/scadenzario/index.php @@ -941,6 +941,12 @@ function getContrastTextColor($hexColor) 0): ?> + + Alert + + + Variazioni + @@ -1010,6 +1016,12 @@ function getContrastTextColor($hexColor) + + + + + + 0): ?>