<?php 
require_once 'core.php';

$ftusername = $_SESSION['username'];

$query = "SELECT DISTINCT ftemail FROM `txmessage_guest` WHERE `ftrecipient_msg` = '$ftusername' order by fnid";

$result = mysqli_query($link,$query);

//mengambil username dengan email 
function get_username($email){

  global $link; 

  $query = "SELECT ftusername FROM txmessage_guest WHERE ftemail='$email'";
  $result = mysqli_query($link,$query);
  $data = mysqli_fetch_assoc($result);

  return $data['ftusername'];
}


?>
<div class="container">
<br>

<table id="table_guest" class="display" style="font-size:13px;">
<center><h3>Data Tamu</h3></center>
<hr>
<thead>
 <tr>
   <th scope="col">Email</th>
   <th scope="col"></th>
   <th scope="col"></th>
 </tr>
</thead>
<tbody>

<?php while($data = mysqli_fetch_assoc($result)){ ?>
<tr>
<td>
<?=$data['ftemail']?>
</td>
<td>
<?php if (pemberitahuan($ftusername,$data['ftemail']) == 0) {?>

<?php }else{ ?>
  <span class="badge badge-danger"><?=pemberitahuan($ftusername,$data['ftemail']);?></span>
<?php } ?>
</td>
<td>
<button type="button" class="btn btn-primary"  onClick="open_book('<?=get_username($data['ftemail']);?>','<?=$data['ftemail'];?>') + hide_modal()">Buka</button>
</td>

</tr>
<?php } ?>
</tbody>
</table>
<br>
</div>
<div class="modal-footer">
  <!-- <button type="button" class="btn btn-primary" onClick="" data-toggle="modal" data-target="#buatpesan">Buat Pesan</button> -->
  <button type="button" class="btn btn-secondary" data-dismiss="modal">Tutup</button>
</div>
<script>
$(document).ready( function () {

$('#table_guest').DataTable({
  "pageLength": 5

});

function hide_modal(){
  $('#guest_chat').modal('hide');
}

});



</script>