<?php 
include 'db_connection.php';

/* start the session */
session_start();

if(!isset($_SESSION['username'])){ // Jika session username ada berarti dia sudah login   
  echo "<script>  window.location.href='login.php';</script>"; // Kita Redirect ke halaman welcome.php
}

if (isset($_SESSION['username'])) {       
    $data = mysqli_query($conn,"SELECT * FROM user WHERE status IN ('I','D') AND user_id ='".$_SESSION['username']."'");
    $cek_usrBaned = mysqli_num_rows($data);

    if($cek_usrBaned > 0){ // found the banned user
       session_destroy(); 
       echo "<script>  window.location.href='login.php';</script>";
    }

} else {    
//echo "You need to login!";
}

?>

<html lang="en">    
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  <meta name="description" content="">
  <meta name="author" content="">
  
  <script src="../../pages/js/jquery-3.4.1.min.js"></script>
    



<script>
//cek idle user on client side (5 menit)
var timeoutID; 
function setup() {
    this.addEventListener("mousemove", resetTimer, false);
    this.addEventListener("mousedown", resetTimer, false);
    this.addEventListener("keypress", resetTimer, false);
    this.addEventListener("DOMMouseScroll", resetTimer, false);
    this.addEventListener("mousewheel", resetTimer, false);
    this.addEventListener("touchmove", resetTimer, false);
    this.addEventListener("MSPointerMove", resetTimer, false);
 
    startTimer();
}
setup();
 
function startTimer() {
    // wait 5 minutes before calling goInactive
    timeoutID = window.setTimeout(goInactive, 300000);	
}
 
function resetTimer(e) {
    window.clearTimeout(timeoutID);
    goActive();
}
 
function goInactive() {
    // do something
    //alert('Idle');
    window.location.href='logout_idx.php';    
}
 
function goActive() {
    // do something
         
    startTimer();
}    
</script>    

<script type="text/javascript">
    //cek interval setiap 10 menit
         jQuery(document).ready(function(){
             setInterval(function(){
                 jQuery.ajax({
                     type: 'POST',
                     url: 'activity_upd_idx.php',                     
                     success:function(){
                         
                     }
                 });
             }, 600000);
         });
</script>

</head>

<body>
</body>    


</html>
