-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstdMidsem_marks.php
More file actions
238 lines (225 loc) · 7.46 KB
/
stdMidsem_marks.php
File metadata and controls
238 lines (225 loc) · 7.46 KB
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
<?php
// Include database connection
include "connecting.php";
// Start session
session_start();
// Check if user is logged in
if (!isset($_SESSION['username'])) {
die("User not logged in. Please log in to access this page.");
}
// Fetch session data
$username = $_SESSION['username'];
// Sanitize and validate session data
if (empty($username) || !preg_match('/^[a-zA-Z0-9_]+$/', $username)) {
die("Invalid username.");
}
// Fetch user details for the sidebar
$sql_user = "SELECT students.first_name, students.last_name, students.enrollment_no, students.student_id
FROM students
WHERE students.enrollment_no = ?";
$stmt_user = $conn->prepare($sql_user);
if (!$stmt_user) {
die("SQL Error: " . $conn->error);
}
$stmt_user->bind_param('s', $username);
$stmt_user->execute();
$result_user = $stmt_user->get_result();
$user = $result_user->fetch_assoc();
if (!$user) {
die("User not found.");
}
// Fetch student_id using user_id for marks
try {
$query_student = "SELECT student_id FROM studentusers WHERE user_id = ?";
$stmt_student = $conn->prepare($query_student);
if (!$stmt_student) {
throw new Exception("Failed to prepare student query: " . $conn->error);
}
$stmt_student->bind_param("i", $_SESSION['user_id']);
$stmt_student->execute();
$result_student = $stmt_student->get_result();
if ($result_student->num_rows > 0) {
$row_student = $result_student->fetch_assoc();
$student_id = $row_student['student_id'];
// Fetch marks for the student
$query_marks = "
SELECT
mm.marks_obtained,
mm.outof_marks,
c.course_name,
p.first_name AS professor_first_name,
p.last_name AS professor_last_name,
mm.upload_date
FROM midsem_marks mm
JOIN courses c ON mm.course_id = c.course_id
JOIN professors p ON mm.professor_id = p.professor_id
WHERE mm.student_id = ?";
$stmt_marks = $conn->prepare($query_marks);
if (!$stmt_marks) {
throw new Exception("Failed to prepare marks query: " . $conn->error);
}
$stmt_marks->bind_param("i", $student_id);
$stmt_marks->execute();
$result_marks = $stmt_marks->get_result();
} else {
throw new Exception("Invalid user or student not found.");
}
} catch (Exception $e) {
die("Error: " . $e->getMessage());
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Midsem Marks</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
/* background-color: #f9f9f9; */
background-color:rgb(176, 170, 212);
}
.container {
display: flex;
height: 100vh;
}
.sidebar {
width: 300px;
background-color: #fff;
padding: 20px;
box-shadow: 2px 0 5px rgba(0, 0, 0, 0.1);
}
.profile {
text-align: center;
margin-bottom: 20px;
}
.profile img {
width: 100px;
height: 100px;
border-radius: 50%;
background-color: #ccc;
}
.profile h3 {
margin: 10px 0 5px;
font-size: 18px;
}
.profile p {
font-size: 14px;
color: #555;
}
.stats .stat {
margin: 10px 0;
background-color: #f4f4f4;
padding: 10px;
border-radius: 5px;
text-align: center;
font-weight: bold;
}
.sidebar button {
width: 100%;
padding: 10px;
background-color: #6c5ce7;
color: white;
border: none;
border-radius: 5px;
cursor: pointer;
margin-bottom: 10px;
}
.sidebar button:hover {
background-color: #4834d4;
}
.addOn {
text-decoration: none;
color: white;
}
.main-content {
flex: 1;
padding: 20px;
}
h1 {
text-align: center;
color: #333;
}
table {
width: 100%;
border-collapse: collapse;
margin-top: 20px;
background-color: #f9f9f9;
}
table, th, td {
border: 1px solid #ddd;
}
th, td {
padding: 10px;
text-align: left;
}
th {
background-color: #4CAF50;
color: white;
}
p {
text-align: center;
color: red;
}
</style>
</head>
<body>
<div class="container">
<!-- Sidebar -->
<div class="sidebar">
<div class="profile">
<img src="<?php echo htmlspecialchars($user['profile_picture'] ?? 'profile.jpg'); ?>" alt="Profile Picture">
<h3><?php echo htmlspecialchars($user['first_name']) . ' ' . htmlspecialchars($user['last_name']); ?></h3>
<p>Enrollment ID: <?php echo htmlspecialchars($user['enrollment_no']); ?></p>
</div>
<div class="stats">
<div class="stat">Total Present: <?php echo $total_present ?? 0; ?></div>
<div class="stat">Total Percentage: <?php echo number_format($total_percentage ?? 0, 2); ?>%</div>
</div>
<button><a class="addOn" href="dashboard_std.php">Sem Attendance</a></button>
<button>Mid-Semester Marks</button>
<button>Notes</button>
<button>Quiz</button>
<button onclick="window.location.href='logout.php';">Log Out</button>
</div>
<!-- Main Content -->
<div class="main-content">
<h1>Your Midsem Marks</h1>
<?php if (isset($result_marks) && $result_marks->num_rows > 0): ?>
<table>
<thead>
<tr>
<th>Course Name</th>
<th>Marks Obtained</th>
<th>Out of Marks</th>
<th>Professor</th>
<th>Upload Date</th>
</tr>
</thead>
<tbody>
<?php while ($row = $result_marks->fetch_assoc()): ?>
<tr>
<td><?= htmlspecialchars($row['course_name']) ?></td>
<td><?= htmlspecialchars($row['marks_obtained']) ?></td>
<td><?= htmlspecialchars($row['outof_marks']) ?></td>
<td><?= htmlspecialchars($row['professor_first_name'] . " " . $row['professor_last_name']) ?></td>
<td><?= htmlspecialchars($row['upload_date']) ?></td>
</tr>
<?php endwhile; ?>
</tbody>
</table>
<?php else: ?>
<p>No marks have been uploaded yet.</p>
<?php endif; ?>
<?php
// Close the statements and connection
if (isset($stmt_student)) $stmt_student->close();
if (isset($stmt_marks)) $stmt_marks->close();
$conn->close();
?>
</div>
</div>
</body>
</html>