
<?php
require_once 'core.php';

date_default_timezone_set('Asia/Jakarta'); // set waktu di jakarta

$id_user = $_SESSION['user_id'];

$query = "SELECT * FROM tluser WHERE fnid !='$id_user' ";
  
$result = mysqli_query($link,$query);
$no = 1;

?>
  <?php
  while ($value = mysqli_fetch_assoc($result)) {
  $waktu_sekarang = strtotime(date('Y-m-d H:i:s'). '-10 second'); 
  $waktu_sekarang = date('Y-m-d H:i:s',$waktu_sekarang);
  $last_activity  = tampil_user_aktifitas_terakhir($value['fnid']);
    
  ?>
    <tr>
      <td class="start_chat" aria-haspopup="true" aria-expanded="false" data-toggle="tooltip" data-placement="bottom" title="Klik 2X" onClick="hide_modal()" data-touserid="<?=$value['fnid'];?>" data-fromuserid="<?=$id_user?>" data-tousername="<?=$value['ftusername'];?>"><?=$value['ftusername']?></td>
      <td>
       <?php if ($last_activity  > $waktu_sekarang){ ?> 
        <a href="#" class="badge badge-primary start_chat"   data-touserid="<?=$value['fnid'];?>" data-tousername="<?=$value['ftusername'];?>">Online </a> 
        <?php if(pemberitahuan($value['fnid'],$id_user) == 0) {

        }else{ ?>
        <span class="badge badge-danger"><?php echo pemberitahuan($value['fnid'],$id_user);?></span>
  <?php } ?>

        <?php }else{?>
          <a href="#" class="badge badge-pill badge-secondary start_chat" data-touserid="<?=$value['fnid'];?>" data-tousername="<?=$value['ftusername'];?>">Offline</a>
          <?php if(pemberitahuan($value['fnid'],$id_user) != 0) { ?>
            <span class="badge badge-danger"><?php echo pemberitahuan($value['fnid'],$id_user);?></span>
          <?php } ?>
          
       <?php } ?>
    </td>
     
      <!-- <td> -->
      <!-- <button type="button" class="btn btn-info btn-sm start_chat" data-touserid="<?=$value['fnid'];?>" data-tousername="<?=$value['ftusername'];?>" onClick="">Chat</button>
    </td> -->
    </tr>
          <?php
          $no++;
        }
?>


<script>
      function hide_modal(){
             $('#user_chat').modal('hide');
            }
</script>
