-
Notifications
You must be signed in to change notification settings - Fork 0
/
conversations.php
184 lines (160 loc) · 5.91 KB
/
conversations.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
<?php
include 'connect/connect.php';
if(!isset($_SESSION["email"])){
echo "<meta http-equiv=\"refresh\" content=\"0; url=http://areal.x10host.com\">";
}
?>
<link rel="stylesheet" type="text/css" href="css/jquery.emojipicker.css">
<link rel="stylesheet" type="text/css" href="css/jquery.emojipicker.a.css">
<link rel="stylesheet" type="text/css" href="css/jquery.emojipicker.a1.css">
<link rel="stylesheet" type="text/css" href="css/jquery.emojipicker.a2.css">
<link rel="stylesheet" type="text/css" href="css/jquery.emojipicker.a3.css">
<link rel="stylesheet" type="text/css" href="css/jquery.emojipicker.a4.css">
<div class="w3-container" style="margin-top:80px; margin-right: 5%; margin-left: 5%;">
<div class="w3-quarter">
<div class="w3-container" style="height: 850px; overflow: scroll;">
<ul class="w3-ul w3-card">
<?php
$email = $_SESSION['email'];
$query = "SELECT * FROM `conversations` WHERE user_from='".$email."' OR user_to= '". $email."' ;";
$queryResults = $connection->query($query);
while($row = $queryResults->fetch_array(MYSQLI_BOTH)){
$id = $row['id'];
$from = $row['user_from'];
$to = $row['user_to'];
$name = $from;
if($name == $email){
$name = $to;
}
$get = "SELECT * FROM `Users` WHERE email = '".$name."';";
$queryResults1 = $connection->query($get);
$rower = $queryResults1->fetch_array(MYSQLI_BOTH);
$firstName = $rower['first'];
$name = $firstName;
echo '<li class="w3-padding-hor-16 w3-hover-shadow"><span onclick="this.parentElement.style.display=\'none\'" class="w3-closebtn w3-padding w3-margin-right w3-small">x</span><img src="../images/image1.png" class="w3-left w3-circle w3-margin-right" style="width:50px; height: 50px"><span class="w3-medium"><b class="userName">'. ucfirst($name) .'</b></span><br><i style="font-size: 10px;">Last Seen 11:10AM</i></li>';
}
?>
</ul>
</div>
</div>
<div class="w3-rest" id="msgContainer" style="display: none;">
<div class="w3-container w3-padding-large w3-light-grey">
<span class="w3-large userNameChange"><?php echo ucfirst($name); ?></span>
<div class="w3-right">
<a href="#" id="delete"><i class="material-icons w3-padding-left" title="delete">delete</i></a>
<a href="#" id="favorite"><i class="material-icons w3-padding-left" title="favorite">favorite</i></a>
</div>
</div>
<div class="w3-container" id="messages" style="height: 700px; overflow: scroll;">
<br>
<?php
include 'connect/getMsg.php';
?>
</div>
<div class="w3-container w3-padding w3-light-grey">
<div class="w3-row">
<div class="w3-col" style="width:88%;">
<textarea class="w3-input" id="message" type="text" style="resize: vertical; max-height: 200px;"></textarea>
</div>
<div class="w3-right">
<a href="#" id="camera"><i class="material-icons" title="camera">camera_alt</i></a>
<a href="#" id="sender"><i class="material-icons w3-padding sender" title="send Message">send</i></a>
<a href="#" id="emotion"><i class="material-icons emojiable-option" title="emotions">insert_emoticon</i></a>
</div>
</div>
</div>
</div>
</div>
<script type="text/javascript" src="js/jquery.emojipicker.js"></script>
<script type="text/javascript" src="js/jquery.emojis.js"></script>
<script>
setInterval("updateContent();", 1000 );
function updateContent() {
var email = '<?php echo $email;?>';
var reciever = $('.userNameChange').text();
$.ajax({
url: "connect/getMsg.php",
type: "POST",
cache: false,
data: {
email: email,
reciever: reciever
},
success: function(data){
$('#messages').html(data);
},
error: function(data){
console.log("");
}
});
scroller();
}
$(".w3-ul li").click(function(){
var userName = $(this).find('.userName').text();
$("#msgContainer").removeAttr("style");
$('.userNameChange').text(userName);
$(".w3-ul li").each(function(){
$(this).removeClass("w3-green");
});
$(this).addClass("w3-green");
});
function scroller(){
$("#messages").animate({ scrollTop: $("#messages")[0].scrollHeight});
}
$(document).ready(function(e){
$("#message").emojiPicker({
height: '200px',
button: false
});
});
$("#emotion").click(function(e){
e.preventDefault();
$('#message').emojiPicker('toggle');
});
$("#sender").click(function(){
if( $("#message").val().length === 0 ) {
$("#message").val('');
} else{
var msg = $("#message").val();
var user_from = '<?php echo $email; ?>';
var user_to = $('.userNameChange').text();
$("#message").val('');
$.ajax({
url: "connect/sendMsg.php",
type: "POST",
cache: false,
data: {
message: msg,
user_from: user_from,
user_to: user_to
},
success: function(){
$("#message").val('');
},
error: function(){
console.log("");
}
});
msg = msg.replace(":)", '<img src="images/emotions/smile.png">');
msg = msg.replace(":D", '<img src="images/emotions/laugh.png">');
msg = msg.replace("<3", '<img src="images/emotions/love.png">');
msg = msg.replace(";p", '<img src="images/emotions/winkTongue.png">');
msg = msg.replace(";P", '<img src="images/emotions/winkTongue.png">');
msg = msg.replace(';)', '<img src="images/emotions/wink.png">');
$("#messages").append('<div class="w3-container"><div class="w3-right w3-round-xlarge w3-padding w3-blue w3-animate-bottom" style="max-width: 50%;">'+ msg +'</div></div><hr class="heightChange">');
scroller();
}
});
$("#message").keypress(function(e){
if(e.which=='13'){
if( $("#message").val().length === 0 ) {
e.preventDefault();
} else{
e.preventDefault();
$("#sender").click();
}
}
});
</script>
</body>
</html>