-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathchat.php
More file actions
101 lines (85 loc) · 2.78 KB
/
Copy pathchat.php
File metadata and controls
101 lines (85 loc) · 2.78 KB
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
<?php
error_reporting(0);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv = "refresh" content = "3">
<link rel="stylesheet" href="ex_css/chat1.css">
<script src="js/jquery.min.js"></script>
<title>Chats</title>
</head>
<body>
<div class="btn-grp">
<a href="profile.php"><button class="btn-1">My Profile</button></a>
<a href="feed.php"><button class="btn-1">My Feeds</button></a>
</div>
<?php
require "config.php";
session_start();
$sender_reg = $_SESSION["reg"];
$sql = "SELECT DISTINCT to_id FROM chats WHERE from_id = '$sender_reg';";
$q = mysqli_query($con,$sql);
$total_chats = mysqli_num_rows($q);
echo "<div class='container'><div class='title'>All Chats</div>";
if($total_chats==0)
{
echo<<<_END
<div class='chat-body'>You have no chats</div>
_END;
}
else
{
while($r = mysqli_fetch_assoc($q))
{
$start_chat = "other_profile.php?target=".$r["to_id"];
$sql2 = "SELECT name,dept,image from users where reg=$r[to_id];";
$q2 = mysqli_query($con,$sql2);
$r2 = mysqli_fetch_assoc($q2);
echo<<<_END
<div class='chat-item'>
<a href='$start_chat' title='$r2[name] from $r2[dept]'>
<img src='$r2[image]' class='img-chat'></a>
<a href='$start_chat' title='Department of $r2[dept]'><button class='chat-item-btn'>$r2[name] , $r2[dept]</button></a>
</div>
_END;
}
}
?>
<?php
echo <<<_END
</div>
<div class='container'><div class='title'>Chat Requests</div>
_END;
$chat_request_sql = "SELECT DISTINCT from_id from chats where to_id='$sender_reg' AND from_id NOT IN(SELECT DISTINCT to_id from chats where from_id='$sender_reg');";
$chat_request_query = mysqli_query($con,$chat_request_sql);
$total_request = mysqli_num_rows($chat_request_query);
if($total_request==0)
{
echo<<<_END
<div class='chat-body'>You have no chat requests</div>
_END;
}
else
{
while($requests = mysqli_fetch_assoc($chat_request_query))
{
$start_chat = "other_profile.php?target=".$requests["from_id"];
$sql3 = "SELECT name,dept,image from users where reg=$requests[from_id];";
$q3 = mysqli_query($con,$sql3);
$r3 = mysqli_fetch_assoc($q3);
echo<<<_END
<div class='chat-item'>
<a href='$start_chat' title='$r3[name] from $r3[dept]'>
<img src='$r3[image]' class='img-chat'></a>
<a href='$start_chat' title='Department of $r3[dept]'><button class='chat-item-btn'>$r3[name] , $r3[dept]</button></a>
</div>
_END;
}
}
?>
</div>
</body>
</html>