-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsignup.php
More file actions
654 lines (573 loc) · 23.1 KB
/
signup.php
File metadata and controls
654 lines (573 loc) · 23.1 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
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
<?php
session_start();
include('db_connect.php');
$message = '';
$messageType = '';
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$fullname = trim($_POST['fullname']);
$username = trim($_POST['username']);
$email = trim($_POST['email']);
$password = $_POST['password'];
$confirm_password = $_POST['confirm_password'];
$role = $_POST['role'];
if ($password !== $confirm_password) {
$message = "Passwords do not match!";
$messageType = "error";
} else {
// Check if email already exists
$email_check_sql = "SELECT email FROM admin WHERE email = ? UNION SELECT email FROM students WHERE email = ? UNION SELECT email FROM faculty WHERE email = ?";
$email_check_stmt = $conn->prepare($email_check_sql);
$email_check_stmt->bind_param("sss", $email, $email, $email);
$email_check_stmt->execute();
$email_result = $email_check_stmt->get_result();
// Check if username already exists (for students and admin only, faculty doesn't have username)
$username_check_sql = "";
if ($role === 'faculty') {
// Faculty doesn't use username, skip check
$username_result = new stdClass();
$username_result->num_rows = 0;
} else {
$username_check_sql = "SELECT username FROM admin WHERE username = ? UNION SELECT username FROM students WHERE username = ?";
$username_check_stmt = $conn->prepare($username_check_sql);
$username_check_stmt->bind_param("ss", $username, $username);
$username_check_stmt->execute();
$username_result = $username_check_stmt->get_result();
}
if ($email_result->num_rows > 0) {
$message = "This email address is already registered. Please use a different email or try logging in.";
$messageType = "error";
$email_check_stmt->close();
$username_check_stmt->close();
} elseif (isset($username_check_stmt) && $username_result->num_rows > 0) {
$message = "This username is already taken. Please choose a different username.";
$messageType = "error";
$email_check_stmt->close();
if (isset($username_check_stmt)) $username_check_stmt->close();
} else {
$email_check_stmt->close();
if (isset($username_check_stmt)) $username_check_stmt->close();
$hashed_password = password_hash($password, PASSWORD_DEFAULT);
if ($role === 'admin') {
$sql = "INSERT INTO admin (fullname, username, email, password) VALUES (?, ?, ?, ?)";
$stmt = $conn->prepare($sql);
$stmt->bind_param("ssss", $fullname, $username, $email, $hashed_password);
} elseif ($role === 'faculty') {
$first_name = trim($_POST['first_name']);
$last_name = trim($_POST['last_name']);
$phone = trim($_POST['phone']);
$department_id = intval($_POST['department_id']);
$bio = trim($_POST['bio'] ?? '');
$hire_date = date('Y-m-d');
$sql = "INSERT INTO faculty (first_name, last_name, email, phone, department_id, hire_date, bio, password) VALUES (?, ?, ?, ?, ?, ?, ?, ?)";
$stmt = $conn->prepare($sql);
$stmt->bind_param("ssssisss", $first_name, $last_name, $email, $phone, $department_id, $hire_date, $bio, $hashed_password);
} else {
$phone = trim($_POST['phone']);
// ---------------- PROFILE UPLOAD LOGIC (Only for Students) ----------------
$profile = "";
if (!empty($_FILES['profile']['name'])) {
$target_dir = "uploads/";
if (!is_dir($target_dir)) {
mkdir($target_dir, 0777, true); // if folder missing, create it
}
$file_name = time() . "_" . basename($_FILES["profile"]["name"]);
$target_file = $target_dir . $file_name;
if (move_uploaded_file($_FILES["profile"]["tmp_name"], $target_file)) {
$profile = $file_name;
} else {
$message = "Error uploading profile picture!";
$messageType = "error";
}
}
// -------------------------------------------------------------------------
// Generate unique student_id
$result = $conn->query("SELECT COUNT(*) as count FROM students");
$count = $result->fetch_assoc()['count'];
$student_id = 'STU-' . date('Y') . '-' . str_pad($count + 1, 4, '0', STR_PAD_LEFT);
// Check if student_id already exists (handle edge case)
$check_stmt = $conn->prepare("SELECT student_id FROM students WHERE student_id = ?");
$check_stmt->bind_param("s", $student_id);
$check_stmt->execute();
$check_result = $check_stmt->get_result();
$attempts = 0;
while ($check_result->num_rows > 0 && $attempts < 10) {
$count++;
$student_id = 'STU-' . date('Y') . '-' . str_pad($count + 1, 4, '0', STR_PAD_LEFT);
$check_stmt->close();
$check_stmt = $conn->prepare("SELECT student_id FROM students WHERE student_id = ?");
$check_stmt->bind_param("s", $student_id);
$check_stmt->execute();
$check_result = $check_stmt->get_result();
$attempts++;
}
$check_stmt->close();
$sql = "INSERT INTO students (student_id, name, username, email, phone, profile, password)
VALUES (?, ?, ?, ?, ?, ?, ?)";
$stmt = $conn->prepare($sql);
$stmt->bind_param("sssssss", $student_id, $fullname, $username, $email, $phone, $profile, $hashed_password);
}
if ($stmt->execute()) {
$message = ucfirst($role) . " registered successfully!";
$messageType = "success";
} else {
// Check for specific database errors
if (strpos($stmt->error, "Duplicate entry") !== false) {
if (strpos($stmt->error, "email") !== false) {
$message = "This email address is already registered. Please use a different email or try logging in.";
} elseif (strpos($stmt->error, "username") !== false) {
$message = "This username is already taken. Please choose a different username.";
} else {
$message = "This account already exists. Please try logging in instead.";
}
} else {
$message = "Registration failed: " . $stmt->error;
}
$messageType = "error";
}
$stmt->close();
}
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Sign Up - Learning Management System</title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700;800&family=Playfair+Display:wght@400;600;700&display=swap" rel="stylesheet">
<style>
:root {
--primary-color: #000000;
--primary-dark: #1a1a1a;
--primary-light: #333333;
--accent-color: #fbbf24;
--accent-light: #fcd34d;
--text-dark: #000000;
--text-light: #4b5563;
--bg-light: #f9fafb;
--bg-white: #ffffff;
--shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
--shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
--shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
--shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1);
}
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Poppins', sans-serif;
background: #ffffff;
min-height: 100vh;
display: flex;
align-items: center;
justify-content: center;
padding: 2rem;
position: relative;
overflow-y: auto;
}
body::before {
content: '';
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: url('https://images.unsplash.com/photo-1523050854058-8df90110c9f1?ixlib=rb-4.0.3&auto=format&fit=crop&w=2070&q=80') center/cover;
opacity: 0.1;
z-index: 0;
}
.container {
position: relative;
z-index: 1;
background: rgba(255, 255, 255, 0.98);
backdrop-filter: blur(20px);
padding: 3rem;
border-radius: 24px;
width: 100%;
max-width: 520px;
box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
animation: fadeInUp 0.6s ease;
}
@keyframes fadeInUp {
from {
opacity: 0;
transform: translateY(30px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
.header {
text-align: center;
margin-bottom: 2rem;
}
.logo {
font-family: 'Playfair Display', serif;
font-size: 2rem;
font-weight: 700;
color: var(--primary-color);
margin-bottom: 0.5rem;
}
h2 {
font-size: 1.75rem;
color: var(--text-dark);
margin-bottom: 0.5rem;
font-weight: 700;
}
.subtitle {
color: var(--text-light);
font-size: 0.95rem;
}
.role-selector {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 0.75rem;
margin-bottom: 1.75rem;
background: var(--bg-light);
padding: 0.5rem;
border-radius: 16px;
}
.role-btn {
padding: 1.25rem 1rem;
background: white;
border: 2px solid transparent;
border-radius: 12px;
text-align: center;
cursor: pointer;
transition: all 0.3s ease;
font-weight: 600;
font-size: 0.95rem;
color: var(--text-dark);
box-shadow: var(--shadow-sm);
}
.role-btn:hover {
transform: translateY(-2px);
box-shadow: var(--shadow-md);
}
.role-btn.active {
background: var(--accent-color);
color: var(--primary-color);
border-color: var(--accent-color);
box-shadow: 0 6px 20px rgba(251, 191, 36, 0.3);
}
.role-btn .emoji {
font-size: 1.5rem;
display: block;
margin-bottom: 0.5rem;
}
.message {
text-align: center;
padding: 1rem;
border-radius: 12px;
margin-bottom: 1.5rem;
font-size: 0.9rem;
font-weight: 500;
animation: slideDown 0.3s ease;
}
@keyframes slideDown {
from {
opacity: 0;
transform: translateY(-10px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
.success {
background: #f0fdf4;
color: #16a34a;
border-left: 4px solid #16a34a;
}
.error {
background: #fef2f2;
color: #dc2626;
border-left: 4px solid #dc2626;
}
.form-group {
margin-bottom: 1.25rem;
}
.form-group label {
font-size: 0.875rem;
margin-bottom: 0.5rem;
display: block;
color: var(--text-dark);
font-weight: 600;
}
form input[type="text"],
form input[type="email"],
form input[type="password"],
form input[type="file"] {
width: 100%;
padding: 1rem 1.25rem;
border: 2px solid #e5e7eb;
border-radius: 12px;
font-size: 0.95rem;
font-family: 'Poppins', sans-serif;
background: white;
transition: all 0.3s ease;
}
form input[type="file"] {
padding: 0.75rem;
cursor: pointer;
}
form input:focus {
outline: none;
border-color: var(--accent-color);
box-shadow: 0 0 0 4px rgba(251, 191, 36, 0.2);
transform: translateY(-2px);
}
form input::placeholder {
color: #9ca3af;
}
form button {
width: 100%;
padding: 1rem;
background: var(--accent-color);
color: var(--primary-color);
border: none;
border-radius: 12px;
font-size: 1rem;
font-weight: 600;
cursor: pointer;
transition: all 0.3s ease;
font-family: 'Poppins', sans-serif;
box-shadow: 0 4px 15px rgba(251, 191, 36, 0.3);
margin-top: 0.5rem;
}
form button:hover {
transform: translateY(-3px);
box-shadow: 0 8px 25px rgba(251, 191, 36, 0.4);
background: var(--accent-light);
}
form button:active {
transform: translateY(-1px);
}
.login-link {
text-align: center;
margin-top: 1.5rem;
padding-top: 1.5rem;
border-top: 1px solid #e5e7eb;
}
.login-link p {
color: var(--text-light);
font-size: 0.9rem;
margin-bottom: 0.5rem;
}
.login-link a {
color: var(--accent-color);
text-decoration: none;
font-weight: 600;
transition: all 0.3s ease;
}
.login-link a:hover {
color: var(--primary-color);
text-decoration: underline;
}
.back-home {
display: inline-flex;
align-items: center;
gap: 0.5rem;
color: var(--text-light);
text-decoration: none;
font-size: 0.875rem;
margin-top: 1rem;
transition: all 0.3s ease;
}
.back-home:hover {
color: var(--accent-color);
transform: translateX(-4px);
}
#studentFields,
#facultyFields {
display: none;
animation: fadeIn 0.3s ease;
}
form select {
width: 100%;
padding: 1rem 1.25rem;
border: 2px solid #e5e7eb;
border-radius: 12px;
font-size: 0.95rem;
font-family: 'Poppins', sans-serif;
background: white;
transition: all 0.3s ease;
}
form select:focus {
outline: none;
border-color: var(--accent-color);
box-shadow: 0 0 0 4px rgba(251, 191, 36, 0.2);
transform: translateY(-2px);
}
form textarea {
width: 100%;
padding: 1rem 1.25rem;
border: 2px solid #e5e7eb;
border-radius: 12px;
font-size: 0.95rem;
font-family: 'Poppins', sans-serif;
background: white;
transition: all 0.3s ease;
resize: vertical;
min-height: 100px;
}
form textarea:focus {
outline: none;
border-color: var(--accent-color);
box-shadow: 0 0 0 4px rgba(251, 191, 36, 0.2);
transform: translateY(-2px);
}
@keyframes fadeIn {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
@media (max-width: 768px) {
.container {
padding: 2rem 1.5rem;
}
h2 {
font-size: 1.5rem;
}
.role-selector {
grid-template-columns: 1fr;
}
}
</style>
<script>
function selectRole(role) {
document.getElementById("role").value = role;
document.getElementById("studentBtn").classList.remove("active");
document.getElementById("adminBtn").classList.remove("active");
document.getElementById("facultyBtn").classList.remove("active");
document.getElementById("studentFields").style.display = "none";
document.getElementById("facultyFields").style.display = "none";
if (role === "student") {
document.getElementById("studentBtn").classList.add("active");
document.getElementById("studentFields").style.display = "block";
document.getElementById("fullnameGroup").style.display = "block";
document.getElementById("usernameGroup").style.display = "block";
document.getElementById("fullname").required = true;
document.getElementById("username").required = true;
} else if (role === "faculty") {
document.getElementById("facultyBtn").classList.add("active");
document.getElementById("facultyFields").style.display = "block";
document.getElementById("fullnameGroup").style.display = "none";
document.getElementById("usernameGroup").style.display = "none";
document.getElementById("fullname").required = false;
document.getElementById("username").required = false;
} else {
document.getElementById("adminBtn").classList.add("active");
document.getElementById("fullnameGroup").style.display = "block";
document.getElementById("usernameGroup").style.display = "block";
document.getElementById("fullname").required = true;
document.getElementById("username").required = true;
}
}
</script>
</head>
<body onload="selectRole('student')">
<div class="container">
<div class="header">
<div class="logo">Learning Management System</div>
<h2>Create Account</h2>
<p class="subtitle">Join us and start your learning journey</p>
</div>
<?php if ($message): ?>
<div class="message <?php echo $messageType; ?>">
<?php echo $message; ?>
</div>
<?php endif; ?>
<div class="role-selector">
<div class="role-btn active" id="studentBtn" onclick="selectRole('student')">
<span class="emoji">🎓</span> Student
</div>
<div class="role-btn" id="facultyBtn" onclick="selectRole('faculty')">
<span class="emoji">👨🏫</span> Faculty
</div>
<div class="role-btn" id="adminBtn" onclick="selectRole('admin')">
<span class="emoji">👨💼</span> Admin
</div>
</div>
<form method="POST" enctype="multipart/form-data">
<input type="hidden" name="role" id="role" value="student">
<div class="form-group" id="fullnameGroup">
<label for="fullname">Full Name</label>
<input type="text" id="fullname" name="fullname" placeholder="Enter your full name" required>
</div>
<div class="form-group" id="usernameGroup">
<label for="username">Username</label>
<input type="text" id="username" name="username" placeholder="Choose a username" required>
</div>
<div class="form-group">
<label for="email">Email Address</label>
<input type="email" id="email" name="email" placeholder="Enter your email address" required>
</div>
<div id="studentFields">
<div class="form-group">
<label for="phone">Phone Number</label>
<input type="text" id="phone" name="phone" placeholder="Enter your phone number">
</div>
<div class="form-group">
<label for="profile">Profile Picture</label>
<input type="file" id="profile" name="profile" accept="image/*">
</div>
</div>
<div id="facultyFields">
<div class="form-group">
<label for="first_name">First Name</label>
<input type="text" id="first_name" name="first_name" placeholder="Enter your first name">
</div>
<div class="form-group">
<label for="last_name">Last Name</label>
<input type="text" id="last_name" name="last_name" placeholder="Enter your last name">
</div>
<div class="form-group">
<label for="faculty_phone">Phone Number</label>
<input type="text" id="faculty_phone" name="phone" placeholder="Enter your phone number">
</div>
<div class="form-group">
<label for="department_id">Department</label>
<select id="department_id" name="department_id" required>
<option value="">Select Department</option>
<?php
$departments = $conn->query("SELECT * FROM departments ORDER BY name");
if ($departments && $departments->num_rows > 0) {
while ($dept = $departments->fetch_assoc()) {
echo '<option value="' . $dept['depart_id'] . '">' . htmlspecialchars($dept['name']) . '</option>';
}
}
?>
</select>
</div>
<div class="form-group">
<label for="bio">Bio (Optional)</label>
<textarea id="bio" name="bio" placeholder="Tell us about yourself"></textarea>
</div>
</div>
<div class="form-group">
<label for="password">Password</label>
<input type="password" id="password" name="password" placeholder="Create a strong password" required>
</div>
<div class="form-group">
<label for="confirm_password">Confirm Password</label>
<input type="password" id="confirm_password" name="confirm_password" placeholder="Re-enter your password" required>
</div>
<button type="submit">Create Account</button>
<div class="login-link">
<p>Already have an account? <a href="login.php">Sign In</a></p>
<a href="index.php" class="back-home">← Back to Home</a>
</div>
</form>
</div>
</body>
</html>