
<?php

require_once 'core.php';

function pemberitahuan($admin,$guest){

  global $link;

  $query = "
      SELECT * FROM txmessage_guest WHERE ftemail='$guest' 
      AND ftrecipient_msg='$admin' AND fnstatus ='1'
  ";

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

  $data = mysqli_num_rows($result);

  return $data;
}

function tampil_chat($email_guest,$admin_name){

    global $link;
    
    $querys = "SELECT * FROM txmessage_guest 
              WHERE (ftemail ='$email_guest' 
              AND ftrecipient_msg ='$admin_name' ) 
              OR
              (ftemail = '$admin_name'
              AND ftrecipient_msg='$email_guest')
              ORDER BY fdcreated_date ASC";
    
    $results = mysqli_query($link,$querys);

    $output = '<ul class="list-unstyled id="animasi">';
 
    while($data = mysqli_fetch_assoc($results)){
     $user_name = '';
     $color ='';
     $posisi ='';
    if($data["ftemail"] == $email){
   
    $user_name = '<b class="text-success"></b>';
    $color = '#f4f5f6';
    $posisi = "align='right'";

    $user = $data['ftfill_msg'].' '. $user_name;
    }else{
     
      $user_name = '<b class="text-danger">'.tampil_nama($data["ftusername"]).'</b>';
      $color = '#dfe7f9';
      $user =  $user_name.' - '.$data['ftfill_msg']; 
    }
      $output .= '
     
      <p'.$posisi.' style="background-color:'.$color.'; border:solid;  border-width:0; border-radius: 13px; padding: 10px 10px 10px 10px;  margin-top:10px; margin-bottom:5px;">
      '.$user.'
        <div '.$posisi.'">
         <small><em>'.$data['fdcreated_date'].'</em></small>
        </div>
      </p>
      </li>
      ';
    }
    $output .= '</ul>';

    return $output;

}  


function tampil_chat_toadmin($admin_name,$email_guest){

  global $link;

  $querys = "SELECT * FROM txmessage_guest 
            WHERE (ftemail ='$email_guest' 
            AND ftrecipient_msg ='$admin_name' ) 
            OR
            (ftemail = '$admin_name'
            AND ftrecipient_msg='$email_guest')
            ORDER BY fdcreated_date asc";
  
  $results = mysqli_query($link,$querys);

  $output = '<ul class="list-unstyled id="animasi">';

  while($data = mysqli_fetch_assoc($results)){
   $user_name = '';
   $color ='';
   $posisi ='';
  if($data["ftemail"] != $admin_name){
 
  $user_name = '<b class="text-success"></b>';
  $color = '#f4f5f6';
  $posisi = "align='right'";

  $user = $data['ftfill_msg'].' '. $user_name;
  }else{
   
    $user_name = '<b class="text-danger">'.$admin_name.'</b>';
    $color = '#dfe7f9';
    $user =  $user_name.' - '.$data['ftfill_msg']; 
  }
  $output .= '
  
  <p '.$posisi.' style="background-color:'.$color.'; border:solid;  border-width:0; border-radius: 13px; padding: 10px 10px 10px 10px;  margin-top:10px; margin-bottom:5px;">
  '.$user.'
    <div '.$posisi.'">
     <small><em>'.$data['fdcreated_date'].'</em></small>
    </div>
  </p>

  ';
  }
  $output .= '</ul>';

  return $output;

}  


function tampil_nama($nama){

 global $link;
//     if ($nama != $_SESSION['user_id']){
    $query  = "SELECT ftfirst_name FROM tluser WHERE fnid = '$nama'";
    $result = mysqli_query($link,$query);
    $data   = mysqli_fetch_assoc($result);
    return $data['ftfirst_name']; 
//     }else{
    // return $nama;
    // }
}

?>
