escape($conn, $_POST['name']), 'date' => $_POST['date'], 'time_in' => $_POST['time_in'], 'time_out' => $_POST['time_out'], 'description' => escape($conn, $_POST['description']), 'location' => escape($conn, $_POST['location']), 'required_students' => $_POST['required_students'], 'course_id' => $_POST['course_id'] ? intval($_POST['course_id']) : null, 'department_id' => $_POST['department_id'] ? intval($_POST['department_id']) : null, 'created_by' => $_SESSION['user_id'] ]; // Validate time if (strtotime($activity_data['time_out']) <= strtotime($activity_data['time_in'])) { $message = 'Time Out must be later than Time In!'; $message_type = 'danger'; } else { $sql = "INSERT INTO activities ( name, date, time_in, time_out, description, location, required_students, course_id, department_id, created_by, created_at, updated_at, status ) VALUES ( '{$activity_data['name']}', '{$activity_data['date']}', '{$activity_data['time_in']}', '{$activity_data['time_out']}', '{$activity_data['description']}', '{$activity_data['location']}', '{$activity_data['required_students']}', " . ($activity_data['course_id'] ? $activity_data['course_id'] : 'NULL') . ", " . ($activity_data['department_id'] ? $activity_data['department_id'] : 'NULL') . ", {$activity_data['created_by']}, NOW(), NOW(), 1 )"; if (query($conn, $sql)) { $_SESSION['message'] = 'Activity added successfully!'; $_SESSION['message_type'] = 'success'; header('Location: manage_activities.php'); exit(); } else { $message = 'Error adding activity: ' . mysqli_error($conn); $message_type = 'danger'; } } } } // Get dropdown data $courses = []; $departments = []; // Courses $result = query($conn, "SELECT * FROM courses WHERE status = 1 ORDER BY code"); while ($row = mysqli_fetch_assoc($result)) { $courses[] = $row; } // Departments $result = query($conn, "SELECT * FROM departments WHERE status = 1 ORDER BY code"); while ($row = mysqli_fetch_assoc($result)) { $departments[] = $row; } include '../includes/header.php'; ?>

Add New Activity

Schedule a new activity, event, or class.

Back to Activities
Activity Details
Cancel
function toggleParticipantSelection() { const participantType = document.getElementById("participantType").value; const courseSelection = document.getElementById("courseSelection"); const departmentSelection = document.getElementById("departmentSelection"); if (participantType === "specific_course") { courseSelection.style.display = "block"; departmentSelection.style.display = "none"; document.getElementById("courseSelect").required = true; document.getElementById("departmentSelect").required = false; } else if (participantType === "specific_department") { courseSelection.style.display = "none"; departmentSelection.style.display = "block"; document.getElementById("courseSelect").required = false; document.getElementById("departmentSelect").required = true; } else { courseSelection.style.display = "none"; departmentSelection.style.display = "none"; document.getElementById("courseSelect").required = false; document.getElementById("departmentSelect").required = false; } } // Set minimum date for activity date (today or later) document.addEventListener("DOMContentLoaded", function() { const today = new Date().toISOString().split("T")[0]; document.querySelector("input[name=\'date\']").min = today; // Initialize participant selection toggleParticipantSelection(); // Time validation document.getElementById("addActivityForm").addEventListener("submit", function(e) { const timeIn = document.querySelector("input[name=\'time_in\']").value; const timeOut = document.querySelector("input[name=\'time_out\']").value; if (timeIn && timeOut && timeOut <= timeIn) { e.preventDefault(); alert("Time Out must be later than Time In!"); return false; } }); }); '; include '../includes/footer.php'; ?>