<?php 
include 'db_con_splitrow_users.php';

/* start the session */
session_start();

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

if (isset($_SESSION['username'])) {       
    $data = mysqli_query($conn,"SELECT * FROM usr_profile 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='../E-Leave/Login/login.php';</script>";
    }

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

$list = "SELECT employee_id FROM usr_profile WHERE user_id ='".$_SESSION['username']."'";
$rs_list = $conn->query($list);

while($row_list = $rs_list->fetch_assoc()) {						
    $list_empID = $row_list['employee_id'];                        		
}
$getname = "SELECT name FROM employee WHERE employee_id ='".$list_empID."'";
$rs_getname = $conn->query($getname);

while($row_getname = $rs_getname->fetch_assoc()) {						
    $list_empName = $row_getname['name'];                        		
}     
?>

<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="">
  
  <link rel="stylesheet" href="iconfont/material-icons.css">
  <link rel="stylesheet" href="css/bootstrap.min.css">  
  <link rel="stylesheet" href="iconfont/material-icons.css">
  <!-- Custom styles material-icons-param -->
  <link rel="stylesheet" href="iconfont/material-icons-param.css">  
  
  <!--CSS for mainmenu -->
  <!-- Bootstrap core CSS -->
  <link href="vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">
  <!-- Custom styles for this template -->
  <link href="css/simple-sidebar.css" rel="stylesheet">
  <!-- Custom styles material-icons -->

  <title>Halaman Utama</title>
 
  <style type="text/css">
    body {
        color: #566787;
		background: #f5f5f5;
		font-family: 'Varela Round', sans-serif;
		font-size: 13px;
	}
	.table-wrapper {
        background: #fff;
        padding: 20px 25px;
        margin: 30px 0;
		border-radius: 3px;
        box-shadow: 0 1px 1px rgba(0,0,0,.05);        
    }
	.table-title {        
		padding-bottom: 15px;
		background: #435d7d;
		color: #fff;
		padding: 16px 30px;
		margin: -20px -25px 10px;
		border-radius: 3px 3px 0 0;
    }
    .table-title h2 {
		margin: 5px 0 0;
		font-size: 24px;
	}
	.table-title .btn-group {
		float: right;
	}
	.table-title .btn {
		color: #fff;
		float: right;
		font-size: 13px;
		border: none;
		min-width: 50px;
		border-radius: 2px;
		border: none;
		outline: none !important;
		margin-left: 10px;
	}
	.table-title .btn i {
		float: left;
		font-size: 21px;
		margin-right: 5px;
	}
	.table-title .btn span {
		float: left;
		margin-top: 2px;
	}
    table.table tr th, table.table tr td {
        border-color: #e9e9e9;
		padding: 12px 15px;
		vertical-align: middle;
    }
	table.table tr th:first-child {
		width: 60px;
	}
	table.table tr th:last-child {
		width: 100px;
	}
    table.table-striped tbody tr:nth-of-type(odd) {
    	background-color: #fcfcfc;
	}
	table.table-striped.table-hover tbody tr:hover {
		background: #f5f5f5;
	}
    table.table th i {
        font-size: 13px;
        margin: 0 5px;
        cursor: pointer;
    }	
    table.table td:last-child i {
		opacity: 0.9;
		font-size: 22px;
        margin: 0 5px;
    }
	table.table td a {
		font-weight: bold;
		color: #566787;
		display: inline-block;
		text-decoration: none;
		outline: none !important;
	}
	table.table td a:hover {
		color: #2196F3;
	}
	table.table td a.edit {
        color: #FFC107;       
    }
        
    table.table td a.delete {
        color: #F44336;
    }
    table.table td i {
        font-size: 19px;
    }
	table.table .avatar {
		border-radius: 50%;
		vertical-align: middle;
		margin-right: 10px;
	}
    .pagination {
        float: right;
        margin: 0 0 5px;
    }
    .pagination li a {
        border: none;
        font-size: 13px;
        min-width: 30px;
        min-height: 30px;
        color: #999;
        margin: 0 2px;
        line-height: 30px;
        border-radius: 2px !important;
        text-align: center;
        padding: 0 6px;
    }
    .pagination li a:hover {
        color: #666;
    }	
    .pagination li.active a, .pagination li.active a.page-link {
        background: #03A9F4;
    }
    .pagination li.active a:hover {        
        background: #0397d6;
    }
	.pagination li.disabled i {
        color: #ccc;
    }
    .pagination li i {
        font-size: 16px;
        padding-top: 6px
    }
    .hint-text {
        float: left;
        margin-top: 10px;
        font-size: 13px;
    }    
	/* Custom checkbox */
	.custom-checkbox {
		position: relative;
	}
	.custom-checkbox input[type="checkbox"] {    
		opacity: 0;
		position: absolute;
		margin: 5px 0 0 3px;
		z-index: 9;
	}
	.custom-checkbox label:before{
		width: 18px;
		height: 18px;
	}
	.custom-checkbox label:before {
		content: '';
		margin-right: 10px;
		display: inline-block;
		vertical-align: text-top;
		background: white;
		border: 1px solid #bbb;
		border-radius: 2px;
		box-sizing: border-box;
		z-index: 2;
	}
	.custom-checkbox input[type="checkbox"]:checked + label:after {
		content: '';
		position: absolute;
		left: 6px;
		top: 3px;
		width: 6px;
		height: 11px;
		border: solid #000;
		border-width: 0 3px 3px 0;
		transform: inherit;
		z-index: 3;
		transform: rotateZ(45deg);
	}
	.custom-checkbox input[type="checkbox"]:checked + label:before {
		border-color: #03A9F4;
		background: #03A9F4;
	}
	.custom-checkbox input[type="checkbox"]:checked + label:after {
		border-color: #fff;
	}
	.custom-checkbox input[type="checkbox"]:disabled + label:before {
		color: #b8b8b8;
		cursor: auto;
		box-shadow: none;
		background: #ddd;
	}
	/* Modal styles */
	.modal .modal-dialog {
		max-width: 400px;
	}
	.modal .modal-header, .modal .modal-body, .modal .modal-footer {
		padding: 20px 30px;
	}
	.modal .modal-content {
		border-radius: 3px;
	}
	.modal .modal-footer {
		background: #ecf0f1;
		border-radius: 0 0 3px 3px;
	}
    .modal .modal-title {
        display: inline-block;
    }
	.modal .form-control {
		border-radius: 2px;
		box-shadow: none;
		border-color: #dddddd;
	}
	.modal textarea.form-control {
		resize: vertical;
	}
	.modal .btn {
		border-radius: 2px;
		min-width: 100px;
	}	
	.modal form label {
		font-weight: normal;
	}
        
        div.posisi {
            position: relative;
            left: 152px;
            width: 90%;
            }
</style>

  <script src="../E-Leave/jquery/jquery.min.js"></script>
  <script src="../E-Leave/jquery/bootstrap.min.js"></script>
  <script src="../E-Leave/jquery/jquery-3.4.1.min.js"></script>
    
<script type="text/javascript">
/*    
$(document).ready(function(){
	// Activate tooltip
	$('[data-toggle="tooltip"]').tooltip();	
});
*/    
</script>

<script type="text/javascript">
//alert("myEdit");
$(function(){ //jQuery shortcut for .ready (ensures DOM ready)
 $('.edit').click(function(){  
  var serviceID = this.id;
  //alert(serviceID);
  var dept = $('#dept_'+serviceID).text();
  //alert(dept);
  var desc = $('#desc_'+serviceID).text();
  //alert(desc);
  var levl = $('#levl_'+serviceID).text();
  //alert(levl);
  
  $('#modaldept').val(dept);
  $('#modaldesc').val(desc);
  $('#Id_val').val(serviceID);
 
  if(levl==0){
	$("#editUsersID").prop("checked", true);
  }else{
	$("#editApprovalID").prop("checked", true);
  }

 });
});
</script>

<script type="text/javascript">
//alert("myEdit");
$(function(){ //jQuery shortcut for .ready (ensures DOM ready)
 $('.delete').click(function(){  
  var serviceID = this.id;    
  $('#Id_del').val(serviceID);
 
 });
});
</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='../E-Leave/logout.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: '..//E-Leave/activity_upd.php',                     
                     success:function(){
                         //alert("Update Timestamp");
                         //window.location.href='..//E-Leave/index.php';
                         //return true;
                     }
                 });
             }, 600000);
         });
</script>

</head>

<body>

  <div class="d-flex" id="wrapper">

    <!-- Sidebar -->
    <div class="border-right" id="sidebar-wrapper">     
        <div class="list-group list-group-flush">
            <div style=" padding: 0.875rem 1.25rem; font-size: 1.2rem; width: 200px; height: 60px;">
                <h1>Start</h1> 
            </div>
        <button class="dropdown-btn list-group-item list-group-item-action">
                Manage <i class="nav-drop-icon material-icons">keyboard_arrow_down</i>
        </button>
        <div class="dropdown-container" style="display: none;">
            <a href="group.php" class="list-group-item list-group-item-action">Group</a>
            <a href="employee.php" class="list-group-item list-group-item-action">Employee</a>
            <a href="users.php" class="list-group-item list-group-item-action">Users</a>
            <a href="leave_types.php" class="list-group-item list-group-item-action">Leave Types</a>
        </div>
        <button class="dropdown-btn list-group-item list-group-item-action">
                Setting <i class="nav-drop-icon material-icons">keyboard_arrow_down</i>
            </button>
        <div class="dropdown-container" style="display: none;">
            <a href="holiday_date.php" class="list-group-item list-group-item-action">Holiday Date</a>
            <a href="users_permission.php" class="list-group-item list-group-item-action">Users Permission</a>
            <a href="leaves_parameter.php" class="list-group-item list-group-item-action">Leaves Parameter</a>
        </div>
                   
        <a href="leave_request.php" class="list-group-item list-group-item-action bg-light">Leave Request</a>                  
        <a href="leave_approval.php" class="list-group-item list-group-item-action bg-light">Leave Approval</a>
        <a href="#" class="list-group-item list-group-item-action bg-light">Events</a>
        <a href="#" class="list-group-item list-group-item-action bg-light">Profile</a>
        <a href="#" class="list-group-item list-group-item-action bg-light">Status</a>
      </div>
    </div>
    
<script>
/* Loop through all dropdown buttons to toggle between hiding and showing its dropdown content - This allows the user to have multiple dropdowns without any conflict */
var dropdown = document.getElementsByClassName("dropdown-btn");
var i;

for (i = 0; i < dropdown.length; i++) {
  dropdown[i].addEventListener("click", function() {
  this.classList.toggle("active");
  var dropdownContent = this.nextElementSibling;
  if (dropdownContent.style.display === "block") {
  dropdownContent.style.display = "none";
  } else {
  dropdownContent.style.display = "block";
  }
  });
}
</script>            
    <!-- /#sidebar-wrapper -->

    <!-- Page Content -->
    <div class="posisi">

      <nav class="navbar navbar-expand-lg bg-light border-bottom">
        <button class="btn btn-primary" id="menu-toggle" style="display:none;">Toggle Menu</button>

        <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
          <span class="navbar-toggler-icon"></span>
        </button>

        <div class="collapse navbar-collapse" id="navbarSupportedContent">
          <ul class="navbar-nav ml-auto mt-2 mt-lg-0">
            <li class="nav-item active">
              <a class="nav-link">Welcome 
              <?php
                //echo("{$_SESSION['username']}"."<br />");                
                echo $list_empName;
              ?>    
              <span class="sr-only">(current)</span></a>
            </li>            
            <li class="nav-item dropdown">
              <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                <i class="nav-drop-icon material-icons">person_pin</i>
              </a>
              <div class="dropdown-menu dropdown-menu-right" aria-labelledby="navbarDropdown">
                <a class="dropdown-item" href="#">Profile</a>
                <a class="dropdown-item" href="change_password.php">Change Password</a>
                <div class="dropdown-divider"></div>
                <a class="dropdown-item" href="logout.php">Logout</a>
              </div>
            </li>
          </ul>
        </div>
      </nav>
    </div> 
   
<?php    
    //cek level user
if($_SESSION['level'] ==='Users'){ // Jika session level users kita redirect to index page    
    echo '
            <script src="sweetalert-master/docs/assets/sweetalert/sweetalert.min.js"></script>
            <script>                      
               swal("Warning!", "Not Authorize to Access This menu", "warning").then(function() {
                            window.location.href="..//E-Leave/index.php";
                            });  
            </script>;            
        ';         
    }
?>    
    
</body>

</html>
