forked from Reema-murthy/Course-Registration-Prj
-
Notifications
You must be signed in to change notification settings - Fork 0
/
student_dashboard.php
131 lines (114 loc) · 4.72 KB
/
student_dashboard.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Bootstrap demo</title>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">
</head>
<body>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz" crossorigin="anonymous"></script>
<?php
// Include database connection
include_once 'db.php';
// Start the session
session_start();
if (isset($_GET['logout'])) {
session_destroy();
// Redirect back to "index.php" after logging out
header("location: /index.php");
exit();
}
echo ' <nav class="navbar navbar-expand-lg navbar-dark bg-dark" style="height:5rem !important;">
<div class="container-fluid">
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="student_dashboard.php">My Courses</a>
</li>
<li class="nav-item">
<a class="nav-link active" href="register.php" aria-current="page">Register</a>
</li>
</ul>
</div>
<div>
<a class="nav-link active" aria-current="page" href="show_detailsstud.php" style="color:#fff !important; padding-right:15px;">Profile</a>
</div>
<div>
<a class="nav-link" href="?logout=true" style="color:#fff !important;">Logout</a>
</div>
</div>
</nav>';
//Check if the user is logged in, if not redirect to login page
if (!isset($_SESSION['loggedin']) || $_SESSION['loggedin'] !== true || $_SESSION['role'] !== '3') {
header("Location: index.php");
exit;
}
// Access the user ID from the session
$user_id = $_SESSION['user_id'];
//To select courses that the student has registered for that are currently active or yet to commence
$sql = "SELECT * FROM Registration R
JOIN Course C on R.Course_ID = C.Course_ID
JOIN Student S on S.Student_ID = R.Student_ID
WHERE S.Login_ID = $user_id and C.Course_End_Date >=CURDATE()";
$result = $conn->query($sql);
// Check if there are results
if ($result->num_rows > 0) {
echo ' <div class="container mt-5">
<div class="card-container mt-5">';
while ($row = $result->fetch_assoc()) {
//Displays the courses as separate cards
echo ' <div class="card" style="width: 25rem;">
<img class="card-img-top" src="pic.jpg" alt="Card image cap">
<div class="card-body">
<p class="card-text">Course Title: ' . $row["Course_Name"] . ' <br>
Faculty : ' . $row["Faculty_ID"] . ' <br>
L-T-P : ' . $row["LTP"] . ' <br>
Credits : ' . $row["Credits"] . ' <br>
Course Duration : ' . $row["Course_Start_Date"] . ' to ' . $row["Course_End_Date"] . '</p>
<a href="#" class="btn btn-primary drop-btn" data-reg-id="' . $row["Reg_ID"] . '">Drop Course</a>
</div>
</div>';
}
echo ' </div>
</div> ';
} else {
echo '<div class="container mt-5">
<h7>No Courses Available</h7>
</div>';
}
// Close the database connection
$conn->close();
?>
</body>
<script>
document.querySelectorAll('.drop-btn').forEach(button => {
button.addEventListener('click', function() {
const regId = this.getAttribute('data-reg-id');
// Send AJAX request to register the course
const xhr = new XMLHttpRequest();
xhr.open('POST', 'drop_course.php');
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xhr.onload = function() {
if (xhr.status === 200) {
location.reload();
} else {
console.error('Error in dropping course:', xhr.statusText);
}
};
xhr.send(`reg_id=${regId}`);
});
});
</script>
</html>
<style>
.card-container {
display: flex;
flex-direction: row;
flex-wrap: wrap;
gap: 50px 40px;
}
</style>