codice:
<?php
require_once('../php/functions.php');
sec_session_start();
$id_user = $_SESSION['user_id'];
?>
<div id="chatwindows" class="chatwindows"></div><!--chatwindows-->
<div class="onlineuserpanel">
<div id="chatscroll" class="onlineusers">
<ul>
<?php
// Create connection
$conn = mysqli_connect($hostname_alliance, $username_alliance, $password_alliance, $database_alliance);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
?>
<?php
$sql = "SELECT * FROM users_online JOIN members on users_online.userid = members.id WHERE members.id <> ".$id_user." ORDER BY cognome ASC";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
$uId = 'u-'.$row['id'];
?>
<li id="u-<?php echo $uId;?>" class="">
<div style="border:1px solid #ccc;width:25px;float:left;margin:1px;">
<div style="height:25px;overflow:hidden;">
<img style=" width:25px" src="<?php echo $row['foto_profilo'];?>" />
</div>
</div>
<span><?php echo strtoupper($row['cognome']);?> <?php echo strtoupper($row['nome']);?></span>
</li>
<?php
}
}
$conn->close();
?>
</ul>
</div><!--onlineusers-->
</div><!--onlineuserpanel-->
<script type="text/javascript">
jQuery("#u-90").addClass("on");
jQuery(document).ready(function(){
// jQuery.ajax({
// url: '../php/chat/stream_users.php',
// type: 'POST',
// dataType: 'json',
// success: function( payload ){
// jQuery.each( payload.data, function(i,msg){
// jQuery( 'ul li#u-'+ msg.id_user).removeClass('on off').addClass(msg.online);
// });
// }
// });
// setInterval(function(){
// jQuery.ajax({
// url: '../php/chat/stream_users.php',
// type: 'POST',
// dataType: 'json',
// success: function( payload ){
// jQuery.each( payload.data, function(i,msg){
// jQuery( 'ul li#u-'+ msg.id_user).removeClass('on off').addClass(msg.online);
// });
// }
// });
// },60000);
// chat slim scroll
if(jQuery('#chatscroll').length > 0) {
jQuery('#chatscroll').slimscroll({
color: '#999',
size: '15px',
width: '200px',
height: '100%'
});
jQuery('#chatscroll li').click(function() {
// store user ids in a cookie
var i = jQuery(this).attr('id');
if(jQuery.cookie('user-selected')) {
var c = jQuery.cookie('user-selected').split(',');
// we make sure that what we inserted is not yet existing
var ue = false;
for(a = 0; a < c.length; a++) {
if(c[a] == i) ue = true;
}
if(!ue) {
c.push(i);
jQuery.cookie('user-selected', c.join(','), { path: '/' });
}
} else {
jQuery.cookie('user-selected', i, { path: '/' });
}
var n = jQuery(this).find('span').text();
var id = jQuery(this).attr('id');
var userxist = checkUser(id);
var wincount = jQuery('#chatwindows .chatwin').length;
if(wincount < 4) {
// check if user already opened a window
if(userxist == false) {
var chatwin = appendUser(n,id);
jQuery('#chatwindows').append(chatwin);
}
} else {
if(jQuery('#chatwinlist').length > 0) {
if(!userxist) {
jQuery('#chatwinlist ul').append('<li id="c_'+ id +'"><h4>'+ n +'</h4></li>').show();
jQuery('#chatwinlist i').text(jQuery('#chatwinlist li').length);
}
} else {
if(!userxist) {
jQuery('#chatwindows').append('<div id="chatwinlist"><span class="iconfa-comment"></span><i>1</i></div>');
jQuery('#chatwinlist').append('<ul><li id="'+ id +'"><h4>'+ n +'</h4></li></ul>');
}
}
}
}); // end of #chatscroll li click
jQuery('.chatwin .close').live('click', function(){
var p = jQuery(this).parent().remove();
if(jQuery('#chatwinlist li').length > 0) {
var n = jQuery('#chatwinlist li:last-child h4').text();
var id = jQuery('#chatwinlist li:last-child').attr('id');
var chatwin = appendUser(n,id, false);
jQuery(chatwin).insertBefore('#chatwinlist');
jQuery('#chatwinlist li:last-child').remove();
jQuery('#chatwinlist i').text(jQuery('#chatwinlist li').length);
}
if(jQuery('#chatwinlist li').length == 0)
jQuery('#chatwinlist').remove();
// remove from cookies
var md = jQuery(this).parent().attr('id').split('_');
if(jQuery.cookie('user-selected')) {
var nc = [];
var oc = jQuery.cookie('user-selected').split(',');
for(a = 0; a < oc.length; a++) {
if(oc[a] != md[1]) nc.push(oc[a]);
}
jQuery.cookie('user-selected', nc.join(','), { path: '/' });
}
});
jQuery('#chatwinlist span').live('click', function(){
var p = jQuery(this).parent().find('ul');
if(p.is(':visible')) p.hide(); else p.show();
});
jQuery('#chatwinlist li').live('click', function(){
var n = jQuery(this).find('h4').text();
var id = jQuery(this).attr('id');
var chatwin = appendUser(n,id);
var cu = jQuery('.chatwin:nth-child(4) h4').text();
jQuery(this).remove();
jQuery('#chatwinlist ul').append('<li><h4>'+ cu +'</h4></li>');
jQuery(chatwin).insertBefore('#chatwinlist');
jQuery('.chatwin:nth-child(4)').remove();
});
if(jQuery.cookie('user-selected')) {
var uc = jQuery.cookie('user-selected').split(',');
var maxwin = 4;
if(jQuery(document).width() < 769) maxwin = 2;
if(jQuery(document).width() < 641) maxwin = 1;
//alert(jQuery(document).width());
for(a = 0; a < uc.length; a++) {
var n = jQuery('#'+uc[a]).find('span').text();
var id = jQuery('#'+uc[a]).attr('id');
var userxist = checkUser(id);
if(a < maxwin) {
if(!userxist) {
var chatwin = appendUser(n,id,false);
jQuery('#chatwindows').append(chatwin);
}
} else {
if(jQuery('#chatwinlist').length > 0) {
if(!userxist) {
jQuery('#chatwinlist ul').append('<li id="'+ id +'"><h4>'+ n +'</h4></li>');
jQuery('#chatwinlist').find('i').text(jQuery('#chatwinlist ul li').length);
}
} else {
if(!userxist) {
jQuery('#chatwindows').append('<div id="chatwinlist"><span class="iconfa-comment"></span><i>1</i></div>');
jQuery('#chatwinlist').append('<ul><li id="cu-'+ id +'"><h4>'+ n +'</h4></li></ul>');
}
}
}
}
}
jQuery('.chatinput').live('keypress', function(e){
var t = jQuery(this);
var v = t.val();
if(e.which == 13) {
t.val('');
t.parents('.chatwin').find('.chatmsg').append('<li><strong>You:</strong> '+ v +'</li>');
}
});
} // end of slimscroll length
function checkUser(id) {
userxist = false;
jQuery('#chatwindows h4').each(function(){
var i = jQuery(this).parent().attr('id').split('_');
if(id == i[1]) {
userxist = true;
var p = jQuery(this).parent();
p.removeClass('animate0 bounceInUp')
.addClass('animate0 bounce')
.on('webkitAnimationEnd oanimationend oAnimationEnd msAnimationEnd animationend',function(){
p.removeClass('animate0 bounce');
});
}
});
return userxist;
}
function appendUser(n,id,animate) {
var a = (animate == null || animate == true)? 'animate0 bounceInUp' : '';
var chatwin = '<div id="c_'+id+'" class="chatwin '+ a +'">'
+ '<a class="close">×</a>'
+ '<h4>'+ n +'</h4>'
+ '<ul class="chatmsg"></ul>'
+ '<div class="chattext">'
+ '<input name="text" class="form-control chatinput input-block-level" placeholder="Scrivi un messaggio e premi invio..." />'
+ '</div><!--chattext-->'
+ '</div><!--chatwin-->';
return chatwin;
}
});
</script>
questo invece è il link alla pagina: