-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFaculty_Chat.php
494 lines (403 loc) · 19.6 KB
/
Faculty_Chat.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
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
<?php
require "Connection.php";
require "Input_Validate.php";
?>
<?php
session_start();
if(!($_SESSION['fac_id']))
{
echo '<script type="text/javascript"> alert("Please login to continue.") </script>';
echo '<script type="text/javascript"> location.href="./Faculty_Login.php" </script>';
}
?>
<!DOCTYPE html>
<html>
<head>
<title>FRIENDZY | Faculty Chat</title>
<style type="text/css">
.profile { height:510px; width: 300px; background-color: rgba(0,0,0,0.8); margin-left: 10px; }
.main-section { height:510px; width: 725px; background-color: rgba(0,0,0,0.4); margin-left: 320px; margin-top: -510px; overflow: auto; position: fixed;}
.post-area { height:510px; width: 300px; background-color: rgba(0,0,0,0.8); margin-left:1055px; margin-top: -510px; }
.profile-pic { background-color: rgba(0,0,0,0.8); margin-left: 85px; padding: 0px; height: 130px; width: 130px;
border-radius: 100px; border-color: rgba(255,0,0,1.0); border-width: 5px;
text-decoration: none; overflow: hidden;
background-repeat: no-repeat; background-size: cover; position:relative; }
#lbl { color: white; font-family: Bookman Old Style; font-size: 22px; margin-top: 0px;
padding-top: 10px;}
.details { color:white; padding-left:10px; padding-top:10px; font-size:16px; font-family:Bookman Old Style;
padding-bottom: 10px;}
.post { height:auto; width: 690px; background-color: rgba(0,0,0,0.85); margin-top: 10px; margin-bottom: 10px;
margin-left: 10px;
border-color: rgba(255,0,0,1.0); border-radius: 5px;}
.accept-request { margin-top: 0px; height: 70px; width: 725px; background-color: rgba(0,0,0,0.7);}
#details { color: white; text-align: center; font-family: Bookman Old Style; font-size: 17px;}
.btn { border-radius:5px; width:200px; margin-top:15px; margin-left:50px; padding:8px;
font-weight:none;
border-width:2px; color: white; cursor: pointer; font-size: 15px; font-family: Verdana;
border-color: rgba(255,0,0,1.0); text-decoration: none;background-color: rgba(0,0,0,0.6); transition: .5s; }
.btn:hover { background-color: rgba(255,0,0,1.0); transition: .3s ease;}
.request-tab { height: 50px; width:725px ; background-color: rgba(0,0,0,0.8);}
.chat-request { height: 390px; width: 725px; background-color: rgba(0,0,0,0); }
.textbox { border-radius:5px; background-color:rgba(0,0,0,0.95); height:25px; color: white;
font-family: Bookman Old Style; margin-top:15px; margin-left: 5px;
font-size: 16px; width: 200px; border-color:rgba(0,0,0,0.85); transition: .3s;}
.chat-request { height: 380px; width: 725px; background-color: rgba(0,0,0,0); overflow: auto;}
.chat-request::-webkit-scrollbar { width: 6px; }
.chat-request::-webkit-scrollbar-thumb { background-color: rgba(255,0,0,0.7); outline: 0; border-radius: 50px;
box-shadow: 0 4px 10px rgba(0,0,0,0.5); }
.post-box { margin-top: 25px; float: left; margin-right: 0px; margin-left: 25px;
height: 150px; width:240px; background-color: rgba(0,0,0,0.6); color:white;
font-family: Bookman Old Style; font-size: 15px; border-color: black;
border-radius: 5px; }
.post-box::-webkit-scrollbar { width: 6px; }
.post-box::-webkit-scrollbar-thumb { background-color: rgba(255,0,0,0.7); outline: 0; border-radius: 50px;
box-shadow: 0 4px 10px rgba(0,0,0,0.5); }
</style>
<link rel="stylesheet" type="text/css" href="./css/homestyle.css">
</head>
<body>
<header>
<nav>
<h1>FRIENDZY</h1>
<ul id="list">
<li> <a class="colblack" href="#">Home</a> </li>
<li> <a class="colblack" href="#">Student Corner</a> </li>
<li> <a class="colred" href="#">Faculty Corner</a> </li>
<li> <a class="colblack" href="#">HOD Corner</a> </li>
<li> <a class="colblack" href="#">Admin Corner</a> </li>
</ul>
</nav>
</header>
<?php
$fac_id=$_SESSION['fac_id'];
$query="select * from faculty_details where f_id='$fac_id'";
$result=mysqli_query($con,$query);
if($result)
{
$row_count=mysqli_num_rows($result);
if($row_count==1)
{
$row=mysqli_fetch_assoc($result);
$name=$row['f_name']." ".$row['m_name']." ".$row['l_name'];
$email=$row['email'];
$phone=$row['phone'];
$fac_id=$row['f_id'];
$img=$row['profile_pic'];
$f_id=substr($fac_id,0,3);
}
}
$query="select d_name from department_details where d_id='$f_id'";
$result=mysqli_query($con,$query);
if($result)
{
$row_count=mysqli_num_rows($result);
if($row_count==1)
{
$row=mysqli_fetch_assoc($result);
$department=$row['d_name'];
}
}
?>
<div class="divider"></div>
<div class="backimg">
<div class="profile">
<p id="lbl" align="center">Faculty profile</p>
<div class="profile-pic">
<img src=<?php echo $img;?> height="132" width="132">
</div>
<p id="details"><?php echo $name;?></p>
<p id="details"><?php echo $email;?></p>
<p id="details">+91 <?php echo $phone;?></p>
<p id="details"><?php echo $department;?></p>
<form action="./Faculty_View.php">
<button class="btn" type="submit" >View Complete Profile</button>
</form>
<form action="./Faculty_Settings.php">
<button class="btn" type="submit" >Settings</button>
</form>
</div>
<div class="main-section">
<div class="request-tab">
<center style="color:white; font-family:Bookman Old Style; font-size:18px; padding-top:15px;"><?php echo "Chat Center - ".$name." - Friends"?></center>
</div>
<div class="chat-request">
<?php
$query="select * from request_details where (sender='$fac_id' or reciever ='$fac_id') and request='1'";
$result=mysqli_query($con,$query);
if($result)
{
$row_count=mysqli_num_rows($result);
if($row_count>0)
{
while($row=mysqli_fetch_assoc($result))
{
if($row['sender']==$fac_id)
$id=$row['reciever'];
else if($row['reciever']==$fac_id)
$id=$row['sender'];
$len=strlen($id);
if($len==8)
$query="select * from student_details where roll_no='$id'";
else if($len==6)
$query="select * from faculty_details where f_id='$id'";
$result1=mysqli_query($con,$query);
if($result1)
{
$row1=mysqli_fetch_assoc($result1);
$chat_name=$row1['f_name']." ".$row1['m_name']." ".$row1['l_name'];
echo "<div class='post'>
<form>
<table>
<tr class='details'>
<td style='padding-left:10px;'><p>$id</p></td>
<td style='padding-left:10px;'><p>$chat_name</p></td>
</tr>
</table>
</form>
</div>";
}
}
}
}
?>
</div>
<div class="accept-request">
<form method="post">
<table>
<tr>
<td><input class="textbox" type="text" name="txt_roll_fid" placeholder="Roll No/Faculty ID"></td>
<td><input class="btn" type="submit" value="Open Chat" name="btn_open"></td>
<td><input class="btn" type="submit" value="Send Request" name="btn_send_request"></td>
</tr>
</table>
</form>
</div>
</div>
<div class="post-area">
<form action="" method="post" enctype='multipart/form-data'>
<textarea class="post-box" name="post_text" placeholder="Write Here" cols="30"></textarea>
<table>
<tr>
<td style="color:white; font-family:Bookman Old Style; font-size:18px; padding-top:10px; padding-left:40px;"><center> Upload image</center></td>
</tr>
<tr>
<td><input type="file" class="btn" name='select_image'></td>
</tr>
<tr>
<td><input class="btn" type="submit" value="Post" name="btn_post"></td>
</tr>
</table>
</form>
<form action="./Faculty_Accept_Request.php">
<input class="btn" type="submit" value="Chat Requests">
</form>
<form action="./Faculty_Home.php">
<input class="btn" type="submit" value="Close Chat Center">
</form>
<form action="./Faculty_Logout.php">
<button class="btn" type="submit" >Logout</button>
</form>
</div>
</div>
<div class="divider"></div>
<footer></footer>
</body>
</html>
<?php
if(isset($_POST['btn_send_request']))
{
$reciever_id=test_input($_POST['txt_roll_fid']);
$sender_id=$fac_id;
$request="0";
if($reciever_id=="")
{
echo '<script type="text/javascript"> alert("Please Enter Roll No/Faculty ID to send a request.") </script>';
mysqli_close($con);
echo '<script type="text/javascript"> location.href="./Faculty_Chat.php"</script>';
}
$len=strlen($reciever_id);
if($len==8)
$query="select * from student_details where roll_no='$reciever_id'";
else if($len==6)
$query="select * from faculty_details where f_id='$reciever_id'";
else
{
echo '<script type="text/javascript"> alert("Wrong Roll No/Faculty ID.") </script>';
mysqli_close($con);
echo '<script type="text/javascript"> location.href="./Faculty_Chat.php"</script>';
}
$result=mysqli_query($con,$query);
if($result)
{
$row_count=mysqli_num_rows($result);
if($row_count==0)
{
echo '<script type="text/javascript"> alert("This Roll No/Faculty ID does not exist.") </script>';
mysqli_close($con);
echo '<script type="text/javascript"> location.href="./Faculty_Chat.php"</script>';
}
}
$query="select * from request_details where sender='$sender_id' and reciever='$reciever_id'";
$result=mysqli_query($con,$query);
if($result)
{
$row_count=mysqli_num_rows($result);
if($row_count==1)
{
$row=mysqli_fetch_assoc($result);
$req_id=$row['request'];
if($req_id=="0")
echo '<script type="text/javascript"> alert("Request already sent. Please wait until the reciever accepts it.") </script>';
else if($req_id=="1")
echo '<script type="text/javascript"> alert("Request already accepted. You can chat now.") </script>';
}
else
{
if($reciever_id==$sender_id)
{
echo '<script type="text/javascript"> alert("You cannot send request to yourself.") </script>';
mysqli_close($con);
echo '<script type="text/javascript"> location.href="./Faculty_Chat.php"</script>';
}
else
{
$query1="select * from request_details where sender='$reciever_id' and reciever='$sender_id'";
$result1=mysqli_query($con,$query1);
if($query1)
{
$row_count=mysqli_num_rows($result1);
if($row_count==1)
{
$row1=mysqli_fetch_assoc($result1);
$req_id=$row1['request'];
if($req_id=="0")
echo '<script type="text/javascript"> alert("You have recieved request. Please accept.") </script>';
else if($req_id=="1")
echo '<script type="text/javascript"> alert("Request already accepted. You can chat now.") </script>';
mysqli_close($con);
echo '<script type="text/javascript"> location.href="./Student_Chat.php"</script>';
}
}
$query1="insert into request_details(sender,reciever,request) values('{$sender_id}','{$reciever_id}','{$request}')";
$result1=mysqli_query($con,$query1);
if($query1)
echo '<script type="text/javascript"> alert("Chat Request Sent. Reciever will appear in your chat center once he/she accepts your request.") </script>';
}
}
mysqli_close($con);
echo '<script type="text/javascript"> location.href="./Faculty_Chat.php"</script>';
}
}
?>
<?php
if(isset($_POST['btn_open']))
{
$roll_fid=test_input($_POST['txt_roll_fid']);
if($roll_fid=="")
{
echo '<script type="text/javascript"> alert("Please enter Roll No/Faculty ID to open the chat.") </script>';
mysqli_close($con);
echo '<script type="text/javascript"> location.href="./Faculty_Chat.php"</script>';
}
else
{
$len=strlen($roll_fid);
if($len==8)
$query="select * from student_details where roll_no='$roll_fid'";
else if($len==6)
$query="select * from faculty_details where f_id='$roll_fid'";
else
{
echo '<script type="text/javascript"> alert("Wrong Roll No/Faculty ID.") </script>';
mysqli_close($con);
echo '<script type="text/javascript"> location.href="./Faculty_Chat.php"</script>';
}
$result=mysqli_query($con,$query);
if($result)
{
$row_count=mysqli_num_rows($result);
if($row_count==0)
{
echo '<script type="text/javascript"> alert("This Roll No/Faculty ID does not exist.") </script>';
mysqli_close($con);
echo '<script type="text/javascript"> location.href="./Faculty_Chat.php"</script>';
}
}
if($roll_fid==$fac_id)
{
echo '<script type="text/javascript"> alert("You cannot open chat with yourself.") </script>';
mysqli_close($con);
echo '<script type="text/javascript"> location.href="./Faculty_Chat.php"</script>';
}
$query="select * from request_details where (sender='$roll_fid' and reciever ='$fac_id') or (reciever ='$roll_fid' and sender ='$fac_id') ";
$result=mysqli_query($con,$query);
if($result)
{
$row_count=mysqli_num_rows($result);
if($row_count==0)
{
echo '<script type="text/javascript"> alert("Please send a request or wait for the other person to send. You can chat once requests are accepted.") </script>';
mysqli_close($con);
echo '<script type="text/javascript"> location.href="./Faculty_Chat.php"</script>';
}
$row=mysqli_fetch_assoc($result);
if($row['request']=="0")
{
echo '<script type="text/javascript"> alert("Chat Request is not accepted yet.") </script>';
mysqli_close($con);
echo '<script type="text/javascript"> location.href="./Faculty_Chat.php"</script>';
}
else if($row['request']=="1")
{
$_SESSION['chat_id']=$roll_fid;
mysqli_close($con);
echo '<script type="text/javascript"> location.href="./Faculty_Open_Chat.php"</script>';
}
}
}
}
?>
<?php
if(isset($_POST['btn_post']))
{
$p_text=test_input($_POST['post_text']);
$file_tmp=$_FILES['select_image']['tmp_name'];
if(($p_text=="" and $file_tmp==""))
{
echo '<script type="text/javascript"> alert("Please write something or select an image to post.") </script>';
mysqli_close($con);
echo '<script type="text/javascript"> location.href="./Faculty_Chat.php"</script>';
}
else
{
$file_type=$_FILES['select_image']['type'];
if(($file_tmp!="") and (!($file_type=="image/jpeg" or $file_type=="image/jpg" or $file_type=="image/png")))
{
echo '<script type="text/javascript"> alert("Please select an image with jpg , jpeg and png formats only.") </script>';
mysqli_close($con);
echo '<script type="text/javascript"> location.href="./Faculty_Chat.php"</script>';
}
else
{
if($file_tmp!="")
{
$file_name=$_FILES['select_image']['name'];
$file_size=$_FILES['select_image']['size'];
$image_base64=base64_encode(file_get_contents($file_tmp));
$p_image='data:image/'.$image_file_type.';base64,'.$image_base64;
}
else
$p_image="";
date_default_timezone_set('Asia/Calcutta');
$date_time=date("d/m/Y H:i:s");
$query="insert into post_details (p_text,p_image,p_id,date_time) values ('{$p_text}','{$p_image}','{$fac_id}','{$date_time}') ";
$result=mysqli_query($con,$query);
if($result)
{
mysqli_close($con);
echo '<script type="text/javascript"> location.href="./Faculty_Home.php"</script>';
}
}
}
}
?>