-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsubmit_experiment.php
More file actions
307 lines (280 loc) · 12.6 KB
/
Copy pathsubmit_experiment.php
File metadata and controls
307 lines (280 loc) · 12.6 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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
<?php
session_start();
require_once 'db.php';
// Check if user is logged in and is a student
if (!isset($_SESSION['user']) || $_SESSION['user']['role'] !== 'student') {
header('Location: login.php');
exit();
}
// Handle form submission
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$experiment_name = $_POST['experiment_name'] ?? '';
$steps = $_POST['steps'] ?? '';
$user_id = $_SESSION['user']['id'];
// Handle video upload
$video_path = '';
if (isset($_FILES['video']) && $_FILES['video']['error'] === UPLOAD_ERR_OK) {
$upload_dir = 'uploads/videos/';
if (!is_dir($upload_dir)) {
mkdir($upload_dir, 0755, true);
}
$file_extension = pathinfo($_FILES['video']['name'], PATHINFO_EXTENSION);
$file_name = uniqid('experiment_') . '.' . $file_extension;
$target_path = $upload_dir . $file_name;
if (move_uploaded_file($_FILES['video']['tmp_name'], $target_path)) {
$video_path = $target_path;
} else {
$error = 'Failed to upload video file.';
}
}
if (empty($error)) {
// Get experiment ID or create if doesn't exist
$stmt = $conn->prepare("SELECT id FROM experiments WHERE name = ?");
$stmt->bind_param("s", $experiment_name);
$stmt->execute();
$result = $stmt->get_result();
if ($result->num_rows > 0) {
$experiment = $result->fetch_assoc();
$experiment_id = $experiment['id'];
} else {
// Insert new experiment
$stmt = $conn->prepare("INSERT INTO experiments (name, difficulty) VALUES (?, 'medium')");
$stmt->bind_param("s", $experiment_name);
$stmt->execute();
$experiment_id = $conn->insert_id;
}
// Insert submission - try with video_path first, fallback without if column doesn't exist
$stmt = $conn->prepare("INSERT INTO submissions (user_id, experiment_id, experiment_name, video_path, steps, status) VALUES (?, ?, ?, ?, ?, 'pending')");
if ($stmt) {
$stmt->bind_param("iisss", $user_id, $experiment_id, $experiment_name, $video_path, $steps);
} else {
// Fallback for old table structure without video_path
$stmt = $conn->prepare("INSERT INTO submissions (user_id, experiment_id, experiment_name, steps, status) VALUES (?, ?, ?, ?, 'pending')");
if (!$stmt) {
$error = 'Database error: Could not prepare statement.';
} else {
$stmt->bind_param("iiss", $user_id, $experiment_id, $experiment_name, $steps);
}
}
if ($stmt->execute()) {
$success = 'Experiment submitted successfully!';
} else {
$error = 'Failed to submit experiment.';
}
}
}
// Get user's previous submissions
$user_id = $_SESSION['user']['id'];
$submissions = [];
$stmt = $conn->prepare("
SELECT s.*, e.name as experiment_name_db
FROM submissions s
LEFT JOIN experiments e ON s.experiment_id = e.id
WHERE s.user_id = ?
ORDER BY s.created_at DESC
");
$stmt->bind_param("i", $user_id);
$stmt->execute();
$result = $stmt->get_result();
while ($row = $result->fetch_assoc()) {
$submissions[] = $row;
}
?>
<!DOCTYPE html>
<html lang="en" data-theme="light">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Submit Experiment - Virtual Chemistry Lab</title>
<link rel="stylesheet" href="style.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap" rel="stylesheet">
</head>
<body>
<!-- Navigation Bar -->
<nav class="navbar">
<div class="nav-container">
<div class="nav-brand">
<div class="logo-icon">
<i class="fas fa-atom"></i>
</div>
<span class="logo-text">ChemLab 3D</span>
</div>
<div class="nav-menu">
<div class="nav-links">
<a href="student_index.php" class="nav-link">
<i class="fas fa-home"></i>
<span>Home</span>
</a>
<a href="student_index.php#lab" class="nav-link">
<i class="fas fa-flask"></i>
<span>3D Lab</span>
</a>
<a href="student_index.php#experiments" class="nav-link">
<i class="fas fa-vial"></i>
<span>Experiments</span>
</a>
<a href="student_index.php#submissions" class="nav-link">
<i class="fas fa-file-alt"></i>
<span>My Reports</span>
</a>
</div>
<div class="nav-user">
<div class="user-profile">
<div class="user-avatar">
<i class="fas fa-user-graduate"></i>
</div>
<div class="user-info">
<span class="username"><?= htmlspecialchars($_SESSION['user']['username']) ?></span>
<span class="user-role">Student</span>
</div>
<div class="user-actions">
<a href="logout.php" class="btn-logout">
<i class="fas fa-sign-out-alt"></i>
</a>
</div>
</div>
</div>
<button class="theme-toggle">
<i class="fas fa-moon"></i>
</button>
</div>
<button class="nav-toggle">
<i class="fas fa-bars"></i>
</button>
</div>
</nav>
<!-- Main Content -->
<main>
<!-- Hero Section -->
<section class="hero">
<div class="hero-background">
<div class="particle"></div>
<div class="particle"></div>
<div class="particle"></div>
</div>
<div class="hero-content">
<div class="hero-text">
<h1 class="hero-title">
<span class="gradient-text">Submit Experiment</span>
<br>
<span class="subtitle">Share Your Work</span>
</h1>
<p class="hero-description">
Upload your recorded experiment video and detailed steps for professor review.
Make sure your video clearly shows the procedure and results.
</p>
</div>
</div>
</section>
<!-- Submission Form -->
<section class="submission-section">
<div class="container">
<div class="submission-form-container">
<h2>Submit Your Experiment</h2>
<?php if (isset($success)): ?>
<div class="alert alert-success">
<i class="fas fa-check-circle"></i>
<?= $success ?>
</div>
<?php endif; ?>
<?php if (isset($error)): ?>
<div class="alert alert-error">
<i class="fas fa-exclamation-circle"></i>
<?= $error ?>
</div>
<?php endif; ?>
<form action="submit_expeiment.php" method="POST" enctype="multipart/form-data" class="experiment-form">
<div class="form-group">
<label for="experiment_name">
<i class="fas fa-flask"></i>
Experiment Name
</label>
<input type="text" id="experiment_name" name="experiment_name" required
placeholder="e.g., Color Change Experiment, Gas Production, etc.">
</div>
<div id="recordStatus" class="record-status">Click to start recording your experiment</div>
</div>
<div class="form-group">
<label for="video">
<i class="fas fa-video"></i>
Experiment Video (MP4)
</label>
<input type="file" id="video" name="video" accept="video/mp4" required>
<small class="form-hint">Upload your recorded experiment video (MP4 format, max 100MB) or use the recording feature above</small>
</div>
<div class="form-group">
<label for="steps">
<i class="fas fa-list-ol"></i>
Experiment Steps & Observations
</label>
<textarea id="steps" name="steps" rows="8" required
placeholder="Describe the steps you followed, observations made, and any results obtained..."></textarea>
</div>
<div class="form-actions">
<button type="button" class="btn-secondary" onclick="window.location.href='student_index.php'">
<i class="fas fa-arrow-left"></i>
Back to Lab
</button>
<button type="submit" class="btn-primary">
<i class="fas fa-paper-plane"></i>
Submit Experiment
</button>
</div>
</form>
</div>
<!-- Previous Submissions -->
<?php if (!empty($submissions)): ?>
<div class="previous-submissions">
<h3>Your Previous Submissions</h3>
<div class="submissions-list">
<?php foreach ($submissions as $submission): ?>
<div class="submission-item">
<div class="submission-info">
<h4><?= htmlspecialchars($submission['experiment_name']) ?></h4>
<p><i class="fas fa-calendar"></i> Submitted: <?= date('M d, Y', strtotime($submission['created_at'])) ?></p>
<p><i class="fas fa-clock"></i> Status:
<span class="status <?= $submission['status'] ?>">
<?= ucfirst($submission['status']) ?>
<?php if ($submission['grade']): ?>
(<?= $submission['grade'] ?>%)
<?php endif; ?>
</span>
</p>
</div>
<?php if ($submission['video_path']): ?>
<div class="submission-actions">
<button class="btn-view" onclick="viewSubmission(<?= $submission['id'] ?>)">
<i class="fas fa-play"></i>
View Video
</button>
</div>
<?php endif; ?>
</div>
<?php endforeach; ?>
</div>
</div>
<?php endif; ?>
</div>
</section>
</main>
<!-- Footer -->
<footer class="footer">
<div class="container">
<div class="footer-content">
<div class="footer-section">
<div class="footer-logo">
<i class="fas fa-atom"></i>
<span>ChemLab 3D</span>
</div>
<p class="footer-description">
Submit your chemistry experiments for professor review and feedback.
</p>
</div>
</div>
</div>
</footer>
<!-- Scripts -->
<script src="script.js"></script>
</body>
</html>