-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstudentAnnouncements.php
305 lines (273 loc) · 9.68 KB
/
studentAnnouncements.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
<?php
session_start();
date_default_timezone_set("Asia/Calcutta");
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "classroom";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (isset($_POST['coursecode'])) {
$_SESSION['coursecode'] = $_POST['coursecode'];
}
$coursecode = $_SESSION['coursecode'];
if (isset($_POST['announcement'])) {
$email = $_SESSION["studentEmail"];
$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['studentEmail'];
$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;
}
.date1 {
position: relative;
bottom: 17px;
}
.comm {
position: relative;
bottom: 21px;
}
.comm1 {
position: relative;
bottom: 13px;
}
.btn {
margin-bottom: 10px;
background-color: white;
border-color: white;
}
.in {
border: 1px solid #B5B5B5;
}
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;
}
.btn33{
position: relative;
bottom: 10px;
}
</style>
</head>
<body>
<body>
<div class="bar">
<div class="home">
<form action="stHome.php">
<input class="topbtn" type='submit' value='HOME'>
</form>
</div>
<div class="test">
<form action="studentTest.php" method="post">
<input class="topbtn" type="submit" value="TESTS">
</form>
</div>
<div class="asssection">
<form action="submitassignment.php" method="post">
<input class="topbtn" type="submit" name="submitassignment" value="ASSIGNMENT">
</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);
//$conn = new mysqli($servername, $username, $password, $dbname);
$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='studentAnnouncements.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='studentAnnouncements.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' class='btn33' type='submit' value='Post' name='submit_comment'>
</form>
";
?>
<button class='btn' class='postbtn' 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 class='fname1'>$f_name</h4>
<p class='date1'>$good2</p>
<p class='comm1'>$cp</p>
</div>";
}
} else {
echo "<h4>No comments yet</h4>";
}
echo "</div>";
echo "</div>";
}
} else {
echo "<h1>No announcements</h1>";
}
$conn->close();
?>
<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>