-
Notifications
You must be signed in to change notification settings - Fork 154
/
message.php
190 lines (151 loc) · 8.13 KB
/
message.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
<?php
session_start();
require 'includes/dbh.inc.php';
define('TITLE',"Inbox | KLiK");
if(!isset($_SESSION['userId']))
{
header("Location: login.php");
exit();
}
include 'includes/HTML-head.php';
?>
<link href="css/inbox.css" rel="stylesheet">
</head>
<body>
<?php include 'includes/navbar.php'; ?>
<div class="cover">
<div class="messaging">
<div class="inbox_msg">
<div class="inbox_people">
<div class="headind_srch">
<div class="recent_heading">
<h2>Inbox</h2>
</div>
</div>
<div class="inbox_chat">
<?php
$sql = "select * from users where idUsers != ?";
$stmt = mysqli_stmt_init($conn);
if (!mysqli_stmt_prepare($stmt, $sql))
{
die('sql error');
}
else
{
mysqli_stmt_bind_param($stmt, "s", $_SESSION['userId']);
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);
while ($row = mysqli_fetch_assoc($result))
{
?>
<a href='./message.php?id=<?php echo $row['idUsers']; ?>'><div class="chat_list ">
<div class="chat_people">
<div class="chat_img">
<img class="chat_people_img" src="uploads/<?php echo $row['userImg'] ?>">
</div>
<div class="chat_ib">
<h5>
<?php echo ucwords($row['uidUsers']) ?>
<span class="chat_date">KLiK User</span>
</h5>
<p>Click on the User to start chatting</p>
</div>
</div>
</div></a>
<?php
}
}
?>
</div>
</div>
<div class="mesgs">
<div class="msg_history">
<?php
if(isset($_GET['id'])){
$user_two = trim(mysqli_real_escape_string($conn, $_GET['id']));
$sql = "select idUsers from users where idUsers = ? and idUsers != ?";
$stmt = mysqli_stmt_init($conn);
if (!mysqli_stmt_prepare($stmt, $sql))
{
die("SQL error");
}
else
{
mysqli_stmt_bind_param($stmt, "ss", $user_two, $_SESSION['userId']);
mysqli_stmt_execute($stmt);
mysqli_stmt_store_result($stmt);
$resultCheck = mysqli_stmt_num_rows($stmt);
if ($resultCheck === 0)
{
die("Invalid $_GET ID.");
}
else
{
$sql = "select * from conversation "
. "where (user_one = ? AND user_two = ?) "
. "or (user_one = ? AND user_two = ?)";
$stmt = mysqli_stmt_init($conn);
if (!mysqli_stmt_prepare($stmt, $sql))
{
die("SQL error");
}
else
{
mysqli_stmt_bind_param($stmt, "ssss", $user_two, $_SESSION['userId'],
$_SESSION['userId'], $user_two);
mysqli_stmt_execute($stmt);
$conver = mysqli_stmt_get_result($stmt);
mysqli_stmt_store_result($stmt);
if (mysqli_num_rows($conver) > 0)
{
$fetch = mysqli_fetch_assoc($conver);
$conversation_id = $fetch['id'];
}
else
{
$sql = "insert into conversation(user_one, user_two) "
. "values (?,?)";
$stmt = mysqli_stmt_init($conn);
if (!mysqli_stmt_prepare($stmt, $sql))
{
die("SQL error");
}
else
{
mysqli_stmt_bind_param($stmt, "ss", $_SESSION['userId'], $user_two);
mysqli_stmt_execute($stmt);
mysqli_stmt_store_result($stmt);
$conversation_id = mysqli_insert_id($conn);
}
}
}
}
}
}else {
die("<div class='text-center'>
<br><br><br>
<h1 class='text-white'>Click on a person to start chatting</h1>
</div>");
}
?>
</div>
<div class="type_msg">
<div class="input_msg_write">
<input type="hidden" id="conversation_id" value="<?php echo base64_encode($conversation_id); ?>">
<input type="hidden" id="user_form" value="<?php echo base64_encode($_SESSION['userId']); ?>">
<input type="hidden" id="user_to" value="<?php echo base64_encode($user_two); ?>">
<textarea id="message" type="text" class="write_msg form-control-plaintext" style="background-color: white;"
placeholder="Type a message"></textarea>
<button id="reply" class="msg_send_btn"
type="button"><i class="fa fa-paper-plane-o" aria-hidden="true"></i></button>
</div>
</div>
</div>
</div>
</div>
</div>
<script src="js/jquery.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script type="text/javascript" src="js/script.js"></script>
</body>
</html>