-
Notifications
You must be signed in to change notification settings - Fork 0
/
eventCreater.php
154 lines (131 loc) · 4.72 KB
/
eventCreater.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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
<?php
session_start();
// Check if not logged in, redirect to login page
if (!isset($_SESSION['loggedin']) || $_SESSION['loggedin'] !== true) {
header("Location: evelogin.php");
exit;
}
// Database connection details
include_once('db_connection.php');
// Define subject codes and names
$subjects = array(
2000601 => "E&SU",
2018602 => "SE",
2018603 => "DW&DM",
2018604 => "CNS",
2000605 => "IoT Adv."
);
// Check if form is submitted
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$subjectCode = $_POST["subject"];
$date = $_POST["date"];
$maxStudents = $_POST["max_students"];
// Prepare SQL statement to insert data into attendanceRecord
$sql = "INSERT INTO tempattendancerecord (subject, date";
// Adding columns 1 to 60 for "A" (absent)
for ($i = 1; $i <= 60; $i++) {
$sql .= ", `$i`";
}
// Adding columns 301, 302, 303, 351, 352 for "A" (absent)
$sql .= ", `301`, `302`, `303`, `351`, `352`, `604`, `max_students`) VALUES ('$subjectCode', '$date'";
for ($i = 1; $i <= 60; $i++) {
$sql .= ", 'A'";
}
// Adding columns 301, 302, 303, 351, 352 for "A" (absent)
$sql .= ", 'A', 'A', 'A', 'A', 'A', 'A', '$maxStudents')";
// Execute the SQL statement
if ($conn->query($sql) === TRUE) {
echo "<script>alert('New record created successfully');</script>";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
}
// Close the database connection
$conn->close();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Attendance Form</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/datepicker/1.0.10/datepicker.min.css">
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
background-color: #f7f7f7;
}
.form-container {
width: 400px;
padding: 20px;
background-color: #fff;
border-radius: 8px;
box-shadow: 0px 2px 10px rgba(0, 0, 0, 0.1);
}
label {
display: block;
margin-bottom: 10px;
}
input[type="text"],
select,
input[type="date"],
button {
width: 100%;
padding: 10px;
margin-bottom: 15px;
box-sizing: border-box;
}
button {
background-color: #007bff;
color: white;
border: none;
cursor: pointer;
}
button:hover {
background-color: #0056b3;
}
</style>
</head>
<body>
<div class="form-container">
<a href="index.html">
<svg xmlns="http://www.w3.org/2000/svg" x="0px" y="0px" height="30" viewBox="0 0 32 32">
<path d="M 16 2.59375 L 15.28125 3.28125 L 2.28125 16.28125 L 3.71875 17.71875 L 5 16.4375 L 5 28 L 14 28 L 14 18 L 18 18 L 18 28 L 27 28 L 27 16.4375 L 28.28125 17.71875 L 29.71875 16.28125 L 16.71875 3.28125 Z M 16 5.4375 L 25 14.4375 L 25 26 L 20 26 L 20 16 L 12 16 L 12 26 L 7 26 L 7 14.4375 Z"></path>
</svg>
</a>
<a class="logout-link" href="evelogout.php">Logout</a>
<h2 style="text-align: center;">Create Attendance Event</h2>
<form method="POST" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>">
<label for="subject">Subject:</label>
<select name="subject" id="subject">
<?php
// Display options for subjects
foreach ($subjects as $code => $name) {
echo "<option value=\"$code\">$name</option>";
}
?>
</select>
<label for="date">Date:</label>
<input type="date" name="date" id="date" autocomplete="off">
<label for="max_students">Max Students:</label>
<input type="number" name="max_students" id="max_students" min="1" required>
<button type="submit">Create Event</button>
</form>
</div>
<!-- Include datepicker library -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/datepicker/1.0.10/datepicker.min.js"></script>
<script>
// Initialize datepicker
const datepicker = new Datepicker(document.getElementById('date'), {
autohide: true,
format: 'yyyy-mm-dd'
});
</script>
</body>
</html>