-
Notifications
You must be signed in to change notification settings - Fork 0
/
broadcastTeacher.php
369 lines (347 loc) · 15.9 KB
/
broadcastTeacher.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
360
361
362
363
364
365
366
367
368
369
<?php
session_start();
$base_url = 'http://' . $_SERVER['HTTP_HOST'] . '/Hacettepe-KDSE-BPYS';
require_once("config-students.php");
if (isset($_SESSION['userlogin'])) {
$myUser = $_SESSION['userlogin']['id'];
$myEmail = $_SESSION['userlogin']['email'];
$name = $_SESSION['userlogin']['name'];
$surname = $_SESSION['userlogin']['surname'];
$student_list = 'none';
$teacher_list = 'none';
$all_messages = 'none';
$sql = "SELECT * FROM students";
$stmt = $db->prepare($sql);
$stmt->execute();
$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
if ($result) {
$student_list = $result;
} else {
echo '';
}
$sql = "SELECT * FROM teachers where email != '$myEmail'";
$stmt = $db->prepare($sql);
$stmt->execute();
$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
if ($result) {
$teacher_list = $result;
} else {
echo '';
}
}
$sql = "SELECT * FROM messages WHERE (FIND_IN_SET(:userid, reciever_list) OR FIND_IN_SET('all_teachers', reciever_list)) ORDER BY id DESC";
$stmt = $db->prepare($sql);
$stmt->bindParam(':userid', $myUser, PDO::PARAM_STR);
$stmt->execute();
$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
if ($result) {
$all_messages = $result;
} else {
echo '';
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.btn-active{
color : white;
background-color: rgb(171, 93, 164) !important;
border-top-right-radius: 50px ;
border-bottom-right-radius: 50px ;
}
.message-content {
word-wrap: break-word;
width: 100%;
}
#all-messages-container *{
font-size : 15px;
font-weight : 800;
color: black;
}
textarea::placeholder{
color: black;
text
}
</style>
</head>
<body>
<div class="container-fluid pt-4 px-4" style="overflow: hidden;">
<div class="send-patient w-100" style="overflow: hidden;">
<div class="w-100 p-4">
<button class="btn btn-success mb-3 w-50 p-3" id="show-all-messages">Tüm Mesajları Göster</button>
<div id="all-messages-container" class="input-section" style="display:none;">
<?php
if($all_messages != 'none'){
foreach($all_messages as $message){
echo '<div class="input-section d-flex flex-column justify-content-center border-bottom p-4 text-sm">';
echo '<div class="mb-2 text-sm"><strong>Gönderen:</strong> '.$message['sender_name'].'</div>';
echo '<div class="mb-2 text-sm"><strong>Konu</strong> '.$message['subject'].'</div>';
echo '<div><strong>Mesaj:<textarea class="w-100 input-section mt-4" disabled rows="5" placeholder="'.$message['message'].'"></textarea></div>';
echo '</div>';
}
} else{
echo '<p>There is no message</p>';
}
?>
</div>
</div>
<div class="w-100 p-4">
<button class="btn btn-success mb-3 w-50 p-3" id="send-to-student">Öğrencilere mesaj gönderme</button>
<div id="send-to-student-dropdown" class="input-section" style="display: none;">
<p>Konu Girin:</p>
<input type="text" class="form-control w-100" name="student-subject" />
<p>Mesaj Girin:</p>
<textarea class="form-control w-100" name="student-message" id="student-message" rows="10"></textarea>
<div class="d-flex justify-content-around">
<div class="d-flex align-items-center">
<p>Herkese gönder?</p>
<input type="checkbox" class="form-check-input" id="broadcast-to-students">
</div>
<button class="btn btn-success w-25 m-3" id="student-selection">Öğrenci Seç</button>
</div>
<div id="student_list_container" class="" style="display: none;">
<?php
if($student_list != 'none'){
foreach($student_list as $student){
echo '<div class="d-flex align-items-center justify-content-end border-bottom"><p class="">'.$student['email'].'</p><input type="checkbox" class="form-check-input" id="student-'.$student['id'].'"></div>';
}
} else{
echo '<p>There is no student</p>';
}
?>
</div>
<button class="btn btn-success w-100" id="send-message-students">Gönder</button>
</div>
</div>
<div class="w-100 p-4">
<button class="btn btn-success mb-3 w-50 p-3" id="send-to-teacher">Öğretmene mesaj gönderme</button>
<div id="send-to-teacher-dropdown" class="input-section" style="display: none;">
<p>Konu Girin:</p>
<input type="text" class="form-control w-100" name="teacher-subject" />
<p>Mesaj Girin:</p>
<textarea class="form-control w-100" name="teacher-message" id="teacher-message" rows="10"></textarea>
<div class="d-flex justify-content-around">
<div class="d-flex align-items-center">
<p>Herkese gönder?</p>
<input type="checkbox" class="form-check-input" id="broadcast-to-teachers">
</div>
<button class="btn btn-success w-25 m-3" id="teacher-selection">Öğretmen Seç</button>
</div>
<div id="teacher_list_container" class="" style="display: none;">
<?php
if($teacher_list != 'none'){
foreach($teacher_list as $teacher){
echo '<div class="d-flex align-items-center justify-content-end border-bottom"><p class="">'.$teacher['email'].'</p><input type="checkbox" class="form-check-input" id="teacher-'.$teacher['id'].'"></div>';
}
} else{
echo '<p>There is no teacher</p>';
}
?>
</div>
<button class="btn btn-success w-100" id="send-message-teachers">Gönder</button>
</div>
</div>
</div>
</div>
</body>
<script>
$('#send-to-student').click(function (e) {
e.preventDefault();
$(this).toggleClass('btn-active');
$(this).next().toggle('slow');
$('#send-to-teacher-dropdown').css('display', 'none');
$('#send-to-teacher').removeClass('btn-active');
$('#teacher-selection').removeClass('btn-active');
$('#teacher_list_container').css('display', 'none');
});
$('#broadcast-to-students').on('change', function() {
$('#student-selection').toggle();
$('#student-selection').removeClass('btn-active');
$('#student_list_container').css('display', 'none');
});
$('#student-selection').click(function(e){
$(this).toggleClass('btn-active');
$('#student_list_container').toggle();
$('#student_list_container').toggleClass('input-section');
});
$('#send-message-students').click(function (e){
var message = $('#student-message').val();
var subject = $('input[name="student-subject"]').val();
if('<?php echo json_encode($student_list); ?>' == 'none') return alert('There is no student')
if(subject == '' || message == '') return alert('Please fill all the fields')
e.preventDefault();
if($('#broadcast-to-students').is(':checked')){
$.ajax({
type: "POST",
url: "<?php echo $base_url; ?>/handleForum/broadCastToStudent.php",
data: {
sender_email : '<?php echo $myEmail; ?>',
senderName : '<?php echo $name.' '.$surname; ?>',
subject: subject,
message: message,
broadcast: true
},
success: function (response) {
if(response == 'success'){
alert('Mesaj gönderildi');
$('#send-to-student-dropdown').toggle('slow');
$('input[name="student-subject"]').val('');
$('input[name="student-message"]').val('');
$('#student_list_container').css('display', 'none');
$('#student_list_container input[type="checkbox"]').each(function(){
$(this).prop('checked', false);
});
$('#send-to-student').removeClass('btn-active');
}},
error: function (response) {
console.log(response);
alert('Error')
}
});
}else{
console.log('inelse')
var student_list = [];
if($('#student_list_container input[type="checkbox"]:checked').length == 0) return alert('Please select at least one student')
$('#student_list_container input[type="checkbox"]').each(function(){
if($(this).is(':checked')){
student_list.push($(this).attr('id').split('-')[1]);
}
});
console.log('hello')
$.ajax({
type: "POST",
url: "<?php echo $base_url; ?>/handleForum/broadCastToStudent.php",
data: {
sender_email : '<?php echo $myEmail; ?>',
subject: subject,
message: message,
senderName : '<?php echo $name.' '.$surname; ?>',
student_list: student_list
},
success: function (response) {
console.log(response)
if(response == 'success'){
alert('Mesaj gönderildi');
$('#send-to-student-dropdown').toggle('slow');
$('input[name="student-subject"]').val('');
$('input[name="student-message"]').val('');
$('#student_list_container').css('display', 'none');
$('#student_list_container input[type="checkbox"]').each(function(){
$(this).prop('checked', false);
});
$('#send-to-student').removeClass('btn-active');
}
},
error: function (response) {
console.log(response);
alert('Error')
}
});
}
})
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
$('#send-to-teacher').click(function (e) {
e.preventDefault();
$(this).toggleClass('btn-active');
$(this).next().toggle('slow');
$('#send-to-student-dropdown').css('display', 'none');
$('#send-to-student').removeClass('btn-active');
$('#student-selection').removeClass('btn-active');
$('#student_list_container').css('display', 'none');
});
$('#broadcast-to-teachers').on('change', function() {
$('#teacher-selection').toggle();
$('#teacher-selection').removeClass('btn-active');
$('#teacher_list_container').css('display', 'none');
});
$('#teacher-selection').click(function(e){
$(this).toggleClass('btn-active');
$('#teacher_list_container').toggle();
$('#teacher_list_container').toggleClass('input-section');
});
$('#send-message-teachers').click(function (e){
var message = $('#teacher-message').val();
var subject = $('input[name="teacher-subject"]').val();
if('<?php echo $teacher_list; ?>' == 'none') return alert('There is no teacher');
if(subject == '' || message == '') return alert('Please fill all the fields')
e.preventDefault();
if($('#broadcast-to-teachers').is(':checked')){
$.ajax({
type: "POST",
url: "<?php echo $base_url; ?>/handleForum/broadCastToTeacher.php",
data: {
sender_email : '<?php echo $myEmail; ?>',
senderName : '<?php echo $name.' '.$surname; ?>',
subject: subject,
message: message,
broadcast: true
},
success: function (response) {
if(response == 'success'){
alert('message send');
$('#send-to-teacher-dropdown').toggle('slow');
$('input[name="teacher-subject"]').val('');
$('input[name="teacher-message"]').val('');
$('#teacher_list_container').css('display', 'none');
$('#teacher_list_container input[type="checkbox"]').each(function(){
$(this).prop('checked', false);
});
$('#send-to-teacher').removeClass('btn-active');
}},
error: function (response) {
console.log(response);
alert('Error')
}
});
}else{
console.log('inelse')
var teacher_list = [];
if($('#teacher_list_container input[type="checkbox"]:checked').length == 0) return alert('Please select at least one teacher')
$('#teacher_list_container input[type="checkbox"]').each(function(){
if($(this).is(':checked')){
teacher_list.push($(this).attr('id').split('-')[1]);
}
});
$.ajax({
type: "POST",
url: "<?php echo $base_url; ?>/handleForum/broadCastToTeacher.php",
data: {
sender_email : '<?php echo $myEmail; ?>',
subject: subject,
message: message,
senderName : '<?php echo $name.' '.$surname; ?>',
teacher_list: student_list
},
success: function (response) {
console.log(response)
if(response == 'success'){
alert('message send');
$('#send-to-teacher-dropdown').toggle('slow');
$('input[name="teacher-subject"]').val('');
$('input[name="teacher-message"]').val('');
$('#teacher_list_container').css('display', 'none');
$('#teacher_list_container input[type="checkbox"]').each(function(){
$(this).prop('checked', false);
});
$('#send-to-teacher').removeClass('btn-active');
}
},
error: function (response) {
console.log(response);
alert('Error')
}
});
}
})
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
$('#show-all-messages').click(function(e){
e.preventDefault();
$('#all-messages-container').toggle('slow');
$(this).toggleClass('btn-active');
})
</script>
</html>