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
| <?php
session_start();
include "".$_SERVER['DOCUMENT_ROOT']."/include/mysql_connect.php";
?>
<script>
var interval;
clearInterval(interval);
function update(){
var id_update = $('#affiche_mess div:last').attr('id'); // on récupère le dernier ID
var exp = $('#affiche_mess div:last').attr('data-exp');
var dest = $('#affiche_mess div:last').attr('data-dest');
$.ajax({
url : "/fiche_cli/update_mess.php?id=" + id_update + "&exp=" + exp + "&dest=" + dest, // on passe l'id le plus récent au fichier de chargement
method : 'GET',
success : function(html){
$('#affiche_mess').append(html);
}
});
}
interval = setInterval(function() {update();}, 1000);
$(document).ready(function() {
//var interval;
$("body").on('click', '.chat_profils_homme',function(event) {
event.preventDefault();
var afficheMess = document.getElementById('affiche_mess');
var id_refresh = $('#affiche_mess div:first').attr('id');
var exp = $('.chat_profils_homme').attr('data-exp');
var dest = $('.chat_profils_homme').attr('data-dest');
clearInterval(interval);
var url = $(this).prop('href');
$.ajax({url:url}).done(function(data) {
$("#affiche_mess").html(data);
afficheMess.scrollTop = afficheMess.scrollHeight;
});
$.ajax({
url: '/fiche_cli/ajoute_mess.php?exp=' + exp + '&dest=' + dest
}).done(function(data) {
$("#chat_ecrire").html(data);
});
interval = setInterval(function() {update();}, 1000);
});
$('#ajoute_mess').on('submit', function(e) {
e.preventDefault();
var $form = $(this);
$.ajax({
url: '/fiche_cli/affiche_mess.php',
method: 'GET',
dataType: 'html',
data: $form.serialize()
}).then(function (data) {
$("#affiche_mess").html(data); // Mise à jour des messages
$.ajax({
url: '/fiche_cli/liste_profil.php',
method: 'GET',
dataType: 'html',
data: $form.serialize()
}).then(function (data) {
$("#list_profil").html(data);
$('.chat_profils_homme');
document.forms['ajoute_mess'].reset();
document.getElementById('affiche_mess').scrollTop=document.getElementById('affiche_mess').scrollHeight;
}).catch(function (error) {
console.log(error);
});
}).catch(function (error) {
console.log(error);
});
});
});
document.getElementById('affiche_mess').scrollTop=document.getElementById('affiche_mess').scrollHeight;
</script>
<br>
<div class="chatter">
<div id="list_profil" class="chat_profils">
<?php
$sql2 = "SELECT dest FROM chat WHERE exp='".$_SESSION["pseudo"]."' GROUP BY dest";
$req2 = mysql_query($sql2) or die('Erreur SQL !<br>'.$sql2.'<br>'.mysql_error());
while($data2 = mysql_fetch_array($req2))
{
$sql3 = mysql_query("SELECT sexe FROM membres WHERE pseudo='".$data2['dest']."'") or die (mysql_error());
list($sexe) = mysql_fetch_row($sql3);
if ($sexe == 'Homme')
{
echo '<A data-exp="'.$_SESSION['pseudo'].'" data-dest="'.$data2['dest'].'" style="margin-bottom: -15px; color: #007ba2;" class="chat_profils_homme" href="/fiche_cli/affiche_mess.php?exp='.$_SESSION['pseudo'].'&dest='.$data2['dest'].'">'.$data2['dest'].'</a>';
}
else
{
echo '<A data-exp="'.$_SESSION['pseudo'].'" data-dest="'.$data2['dest'].'" style="margin-bottom: -15px; color: #f40e63;" class="chat_profils_homme" href="/fiche_cli/affiche_mess.php?exp='.$_SESSION['pseudo'].'&dest='.$data2['dest'].'">'.$data2['dest'].'</a>';
}
}
?>
</div>
<div id="chat_ecrire" class="chat_ecrire">
<form id="ajoute_mess" name="ajoute_mess" action="" method="get">
<?php
if (isset($_SESSION['pseudo']))
{
echo '<input type="hidden" name="action" value="envoyer">';
}
else
{
echo '<input type="hidden" name="action" value="no_connect">';
}
?>
<input type="hidden" name="dest" value="<?php echo $_GET['dest']; ?>">
<input type="hidden" name="exp" value="<?php echo $_GET['exp']; ?>">
<INPUT type="text" name="message" placeholder="Entrez votre message" value="">
<button class="btn">Envoyer</button>
</form>
</div>
<div id="affiche_mess" style="line-height: 10px;" class="messages">
<?php
$aujourdhui = date("Y-m-d H:i:s");
if (isset($_GET['message']))
{
$sql1 = "INSERT INTO chat (exp,dest,mess,date,nouv) VALUES('".$_GET['exp']."','".$_GET['dest']."','".$_GET['message']."','$aujourdhui','oui')";
mysql_query($sql1) or die('Erreur SQL !'.$sql1.'<br>'.mysql_error());
}
$sql2 = "SELECT exp,dest,mess,id FROM chat WHERE exp='".$_GET["exp"]."' AND dest='".$_GET['dest']."' OR exp='".$_GET['dest']."' AND dest='".$_GET["exp"]."' ORDER BY id ASC";
$req2 = mysql_query($sql2) or die('Erreur SQL !<br>'.$sql2.'<br>'.mysql_error());
while($data2 = mysql_fetch_array($req2))
{
if ($data2['exp']==$_GET['exp'])
{
echo '<div data-exp="'.$_GET["exp"].'" data-dest="'.$_GET["dest"].'" id="'.$data2['id'].'">Moi: '.$data2['mess'].'</div><br>';
}
if ($data2['exp']==$_GET['dest'])
{
echo '<div data-exp="'.$_GET["exp"].'" data-dest="'.$_GET["dest"].'" id="'.$data2['id'].'">'.$data2['exp'].': '.$data2['mess'].'</div><br>';
}
}
?>
</div>
</div> |
Partager