-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrefresh_messages.php
52 lines (52 loc) · 2.41 KB
/
refresh_messages.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
<?php
session_start();
$my_email = openssl_decrypt($_SESSION['token'], "AES-128-CTR", "11112000", 0, "1234567890123456");
$pdo = new PDO('mysql:host=localhost;dbname=users', 'root', 'pwd');
$q4 = $pdo->prepare("select * from chatters where email=?");
$q4->bindValue(1, $my_email);
$q4->execute();
$res = $q4->fetch(PDO::FETCH_ASSOC);
$my_number = $res['id'] % 70 + 1;
if(strpos($_GET['with'], "r")===false) {
$q = $pdo->prepare("select * from chatters where id=?");
$q->bindValue(1, $_GET['with']);
$q->execute();
$r = $q->fetch(PDO::FETCH_ASSOC);
$query = $pdo->prepare("select * from message where (sender=? and receiver=?) or (sender=? and receiver=?) order by date");
$query->bindValue(1, $my_email);
$query->bindValue(2, $r['email']);
$query->bindValue(3, $r['email']);
$query->bindValue(4, $my_email);
$query->execute();
$q3 = $pdo->prepare('update message set isRead=true where sender=? and receiver=? and isRead=false');
$q3->bindValue(1, $r['email']);
$q3->bindValue(2, $my_email);
$q3->execute();
$his_number = $r['id'] % 70 + 1;
while ($result = $query->fetch(PDO::FETCH_ASSOC)) {
echo "<li class='" . ($result['sender'] == $my_email ? "sender" : "receiver") . "'>"
. "<img src='https://i.pravatar.cc/150?img=" . ($result['sender'] == $my_email ? $my_number : $his_number) . "
'/><span>" . $result['message'] . "</span>
</li>";
}
}
else {
$query = $pdo->prepare("select * from message where receiver=?");
$query->bindValue(1, $_GET['with']);
$query->execute();
$his_number = 0;
while($result = $query->fetch(PDO::FETCH_ASSOC)) {
if ($result['sender'] != $my_email) {
$q7 = $pdo->prepare("select * from chatters where email=?");
$q7->bindValue(1, $result['sender']);
$q7->execute();
$temp = $q7->fetch(PDO::FETCH_ASSOC);
$his_number = $temp['id']%70 + 1;
}
echo "<li class='" . ($result['sender'] == $my_email ? "sender" : "receiver") . "'>"
. "<img src='https://i.pravatar.cc/150?img=" . ($result['sender'] == $my_email ? $my_number : $his_number) . "'/>"
. "<span>" . $result['message'] . "</span>" .
"</li>";
}
}
?>