-
Notifications
You must be signed in to change notification settings - Fork 0
/
chat-ajax.php
executable file
·111 lines (99 loc) · 3.63 KB
/
chat-ajax.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
<?php
include('./requiert/php-global.php');
if ($_GET['a'] == 'refreshco')
{
if ($mbreBanniChat == 1) {
?>
<script LANGUAGE="JavaScript">
document.location.href="./"
</script>
<?php
exit();
}
if ($mbreNom != '' && $mbrePrenom != '')
{
$retour = $pdo->query('SELECT COUNT(*) AS \'nbre_entrees\' FROM connectes WHERE ip=\'' . $_SERVER['REMOTE_ADDR'] . '\'');
$donnees = $retour->fetch(PDO::FETCH_ASSOC);
if ($donnees['nbre_entrees'] == 0) // L'ip ne se trouve pas dans la table, on va l'ajouter
{
$pdo->exec("INSERT INTO `connectes`(`ip`, `timestamp`, `idUser`) VALUES('".$_SERVER['REMOTE_ADDR']."', '".time()."', '".$mbreHashId."')");
}
else // L'ip se trouve d�j� dans la table, on met juste � jour le timestamp
{
$pdo->exec('UPDATE connectes SET timestamp=' . time() . ', idUser=\''.$mbreHashId.'\' WHERE ip=\'' . $_SERVER['REMOTE_ADDR'] . '\'');
}
}
//@ars updat timestam order by with timestamp
$top_connectes = $pdo->query("SELECT COUNT(*), idUser FROM connectes as C WHERE idUser != '' GROUP BY idUser ORDER BY idUser ");
$i = 0;
$all_top_connectes = $top_connectes->fetchAll(PDO::FETCH_ASSOC);
$j = 0;
foreach ($all_top_connectes as $dones_connectes)
{
$j++;
}
foreach ($all_top_connectes as $dones_connectes)
{
$us = $pdo->query("SELECT nom, prenom, level FROM users WHERE hashId = '".$dones_connectes['idUser']."'");
$dones_us = $us->fetch(PDO::FETCH_ASSOC);
$nom = substr($dones_us['nom'], 0, 2).'.';
$prenom = $dones_us['prenom'];
?>
<li class="item-connecte" <?php if ($dones_us['level'] == '99') {
echo ' style="color: #dc6666; font-weight: bold;"';
} else if ($dones_us['level'] == '9') {
echo ' style="color: green; font-weight: bold;"';
} else if ($dones_us['level'] == '1') {
echo ' style="color: #444;"';
} ?>><?php echo $prenom; ?> <?php echo $nom; ?></li><?php
// if ($i < $j - 1) {
// echo ',';
// }
//}
$i++;
}
$timestamp_1min = time() - (60 * 1); // 60 * 1 = nombre de secondes �coul�es en 1min
$pdo->exec("DELETE FROM connectes WHERE timestamp < '".$timestamp_1min."'");
}
if ($_GET['a'] == 'refreshchat')
{
$sc = $pdo->query("SELECT id, time, idUser, message FROM tchat ORDER BY time DESC LIMIT 0, 30");
$i = 0;
$all_sc = $sc->fetchAll(PDO::FETCH_ASSOC);
foreach ($all_sc as $dones_chat)
{
$id = $dones_chat['id'];
$us = $pdo->query("SELECT nom, prenom, level FROM users WHERE hashId = '".$dones_chat['idUser']."'");
$dones_us = $us->fetch(PDO::FETCH_ASSOC);
if ($dones_us['level'] == '1') { $color = '#444444'; }
else if ($dones_us['level'] == '99') { $color = '#dc6666'; }
else if ($dones_us['level'] == '9') { $color = 'green'; }
$message = $dones_chat['message'];
$nom = substr($dones_us['nom'], 0, 2).'.';
$prenom = $dones_us['prenom'];
$timer = explode(" ",$dones_chat['time']);
$when = "";
if (date('Y-m-d', strtotime('-1 day')) == $timer[0])
{
$when = "Hier à ";
}
else if (date('Y-m-d', strtotime('-2 day')) == $timer[0])
{
$when = "Avant-hier à";
}
?>
<div class="message-bubble">
<div class="message-avatar"><img src="http://www.gravatar.com/avatar/00000000000000000000000000000000?d=mm&s=70" alt="" /></div>
<div class="message-text">
<b><?= $prenom; ?> <?= $nom; ?></b>
<small>
[<?= $when.substr($timer[1],0, strlen($timer[1]) - 3); ?>]
</small>
<p><?= nl2br($message); ?></p>
</div>
</div>
<?php
$i++;
}
}
?>