-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprofAnnouncements.php
359 lines (315 loc) · 9.9 KB
/
profAnnouncements.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
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
<?php
session_start();
date_default_timezone_set("Asia/Calcutta");
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "classroom";
try {
$conn = new mysqli($servername, $username, $password, $dbname);
$sql = "CREATE TABLE IF NOT EXISTS announcements (
coursecode VARCHAR(255) ,
`date` datetime ,
announce longtext ,
email varchar(255)
)";
$conn->query($sql);
$conn->close();
} catch (Exception $e) {
echo "";
}
try {
$conn = new mysqli($servername, $username, $password, $dbname);
$sql = "CREATE TABLE IF NOT EXISTS comments (
comment longtext ,
sender_email varchar(255) ,
receiver_email varchar(255) ,
sender_date datetime ,
msg_date datetime
)";
$conn->query($sql);
$conn->close();
} catch (Exception $e) {
echo "";
}
try {
$conn = new mysqli($servername, $username, $password, $dbname);
$sql = "CREATE TABLE IF NOT EXISTS test_question (
question varchar(255) ,
answer int ,
testId int ,
questionId int
)";
$conn->query($sql);
$conn->close();
} catch (Exception $e) {
echo "";
}
try {
$conn = new mysqli($servername, $username, $password, $dbname);
$sql = "CREATE TABLE IF NOT EXISTS studentcourses (
coursecode varchar(255),
student_email varchar(255)
)";
$conn->query($sql);
$conn->close();
} catch (Exception $e) {
echo "";
}
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (isset($_POST['coursecode'])) {
$_SESSION['coursecode'] = $_POST['coursecode'];
}
$coursecode = $_SESSION['coursecode'];
if (isset($_POST['announcement'])) {
$email = $_SESSION["email"];
$announcement = $_POST["announcement"];
$date_clicked = date('Y-m-d H:i:s');
$_SESSION['date_clicked'] = $date_clicked;
$conn = new mysqli($servername, $username, $password, $dbname);
$sql3 = "INSERT INTO announcements(coursecode,date,announce,email) VALUES ('$coursecode','$date_clicked','$announcement','$email')";
$res = $conn->query($sql3);
$conn->close();
}
if (isset($_POST['submit_comment'])) {
$conn = new mysqli($servername, $username, $password, $dbname);
$comment = $_POST['comment'];
$msg_date = $_POST['date'];
$rec_email = $_POST['email'];
$sender_email = $_SESSION['email'];
$live_date = date('Y-m-d H:i:s');
$sql = "INSERT INTO comments(comment,sender_email,receiver_email,sender_date,msg_date) VALUES('$comment','$sender_email','$rec_email','$live_date','$msg_date')";
$conn->query($sql);
$conn->close();
}
}
$conn = new mysqli($servername, $username, $password, $dbname);
$coursecode = $_SESSION['coursecode'];
$sql = "SELECT coursename,subject FROM courses WHERE coursecode='$coursecode'";
$resu = $conn->query($sql);
$display = $resu->fetch_assoc();
$conn->close();
?>
<html>
<head>
<style>
.one_announce {
padding-left: 20px;
width: 60%;
border: 1.5px solid #D0D0D0;
border-radius: 10px;
margin: 10px auto 10px auto;
word-wrap: break-word;
}
.date {
position: relative;
bottom: 17px;
}
.comm {
position: relative;
bottom: 21px;
}
.btn {
margin-bottom: 10px;
background-color: white;
border-color: white;
}
.in {
border: 1px solid #B5B5B5;
}
</style>
</head>
<body>
<div class="bar">
<div class="home">
<form action="professorHome.php">
<input class="topbtn" type='submit' value='HOME'>
</form>
</div>
<div class="test">
<form method="post" action="createTest.php">
<input class="topbtn" type="submit" value="Create Test">
</form>
</div>
<div class="asssection">
<form method="post" action="proftest.php">
<input class="topbtn" type="submit" value="Tests">
</form>
</div>
</div>
<div class="announce">
<img src="./images/img3.png" alt="Class Photo" class="ig">
<h1><?php echo $display['coursename'] . ":" . $display['subject'] ?></h1>
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>">
<textarea class="areatext" rows="3" name="announcement" cols="100" placeholder="Announce Something To Your Class" required></textarea>
<br><br>
<input class="postbtn" type="submit" name="click" value="POST">
</form>
</div>
<?php
$conn = new mysqli($servername, $username, $password, $dbname);
$sql2 = "SELECT announce,date,email FROM announcements WHERE coursecode='$coursecode' ORDER BY date DESC";
$res = $conn->query($sql2);
if ($res->num_rows > 0) {
while ($row = $res->fetch_assoc()) {
$e = $row['email'];
$a = $row['announce'];
$d = $row['date'];
$goodd = strtotime($d);
$goodd = date('M d h:i', $goodd);
$sql4 = "SELECT firstname,lastname FROM students WHERE email='$e' UNION SELECT firstname,lastname FROM professors WHERE email='$e'";
$pr = $conn->query($sql4);
$pr_name = $pr->fetch_assoc();
$full_name = $pr_name['firstname'] . " " . $pr_name['lastname'];
echo "<div class='one_announce'>
<form action='profAnnouncements.php' method='post'>
<input type='hidden' value='$d' name='date'>
<input type='hidden' value='$e' name='email'>
</form>" ?>
<?php
echo "
<h4 class='fname'>$full_name</h4>
<p class='date'>$goodd</p>
<p class='comm'>$a</p>
<form action='profAnnouncements.php' method='post'>
<input type='hidden' value='$d' name='date'>
<input type='hidden' value='$e' name='email'>
<input class='in' type='text' placeholder='Add a class comment...' name='comment' size='110' style='height: 35px;border-radius: 10px;'required>
<input class='sub' type='submit' value='Post' name='submit_comment'>
</form>
";
?>
<button class='btn' onclick='showcomments(<?php echo strtotime($d); ?>)'><img src='./images/comm.png' width="120px" height="30px"></img></button>
<?php
$sqlcomm = "SELECT * FROM comments WHERE msg_date='$d' AND receiver_email='$e' ORDER BY sender_date DESC";
$kk = strtotime($d);
$res100 = $conn->query($sqlcomm);
echo "<div id='$kk' style='display:none'>";
if ($res100->num_rows > 0) {
while ($r2 = $res100->fetch_assoc()) {
$se = $r2['sender_email'];
$cp = $r2['comment'];
$sd = $r2['sender_date'];
$sql41 = "SELECT firstname,lastname FROM students WHERE email='$se' UNION SELECT firstname,lastname FROM professors WHERE email='$se'";
$pro = $conn->query($sql41);
$pro_name = $pro->fetch_assoc();
$f_name = $pro_name['firstname'] . " " . $pro_name['lastname'];
$good2 = strtotime($sd);
$good2 = date('M d h:i', $good2);
echo "
<hr>
<div>
<h4>$f_name</h4>
</h4>$good2</h4>
<p>$cp</p>
</div>
";
}
} else {
echo "<h4>No comments yet</h4>";
}
echo "</div>";
echo "</div>";
}
} else {
echo "<h1>No announcements</h1>";
}
$conn->close();
echo "
<script>
function showcomments(y){
var x= document.getElementById(y);
if (x.style.display === 'none') {
x.style.display = 'block';
} else {
x.style.display = 'none';
}
}
</script>
";
?>
</body>
</html>
<style>
body {
background-color: white;
}
.announce {
margin-left: 15%;
margin-right: 15%;
border-radius: 10px;
background-color: #ABD9FF;
padding-left: 20px;
width: 60%;
/* border: 1px solid black; */
border-radius: 8px;
margin: 10px auto 10px auto;
word-wrap: break-word;
}
.one_announce {
padding-left: 20px;
width: 60%;
/* border: 1px solid black; */
border-radius: 8px;
margin: 10px auto 10px auto;
word-wrap: break-word;
background-color: #F2F2F2;
}
.bar {
display: flex;
justify-content: space-around;
padding-bottom: 40px;
}
.home {
position: relative;
right: 136px;
top: 20px;
}
.test {
position: relative;
left: 450px;
top: 20px;
}
.asssection {
position: relative;
left: 136px;
top: 20px;
}
.topbtn {
background-color: #81C6E8;
border: none;
color: white;
padding: 6px 24px;
text-decoration: none;
margin: 6px 2px;
cursor: pointer;
border-radius: 10px;
}
.topbtn:hover {
transform: scale(1.1);
}
.postbtn {
background-color: #81C6E8;
border: solid black;
border-width: 1px;
color: white;
padding: 10px 24px;
text-decoration: none;
margin: 6px 2px;
cursor: pointer;
border-radius: 10px;
}
.postbtn:hover {
transform: scale(1.1);
}
.areatext {
border-radius: 11px;
width: 95%;
}
.ig {
width: 98%;
object-fit: contain;
margin-top: 21px;
border-radius: 9px;
}
</style>