Subject CRUD

This commit is contained in:
2026-04-18 15:26:04 +03:00
parent d2e5cc8b2b
commit 0550ffe923
11 changed files with 557 additions and 36 deletions
@@ -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'],
@@ -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'],
];
}
@@ -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
]);