<?php include "includes/header.php";?>

<?php include "includes/navbar.php";?>

  <div id="wrapper">

    <!-- Sidebar -->
   <?php include "includes/sidebar.php";?>

    <div id="content-wrapper">

      <div class="container-fluid">

        <!-- Breadcrumbs-->
        <ol class="breadcrumb">
          <li class="breadcrumb-item">
            <a href="#">Ola</a>
          </li>
          <li class="breadcrumb-item active"><?php echo $_SESSION['nome'];?></li>
        </ol>

        <!-- Icon Cards-->
        <div class="row">
         <table class="table">
		  <thead>
		   <tr>
		    <th>Nome</th>
		    <th>Nivel</th>
		    <th>Estado</th>
		    <th>Foto</th>
		    <th>Acesso</th>
		    <th>Editar</th>
		    <th>Eliminar</th>		   
		   </tr>
		    </thead>
			
			<tbody>
			<?php 
			$busca = "SELECT * FROM usuarios";
			$fetch = mysqli_query($con,$busca);
			while($row = mysqli_fetch_assoc($fetch)){
				
				$id = $row['id_user'];
				$nome = $row['nome'];
				$nivel = $row['nivel'];
				$estado = $row['status'];
				$foto = $row['foto'];
	     	
			?>
			
			
			
			 <tr>
			  <td><?php echo $nome;?></td>
			  <td><?php echo $nivel;?></td>
			  <td><?php echo $estado;?></td>
			  <td><img src="img/<?php echo $foto;?>" width="50px" height="50px"></td>
			  
			  <?php 
			   if($_SESSION['nivel']==1 || $_SESSION['nivel']==2){
			  
			  if($estado == "Activo"){
				  ?>
				<td><button type="button" class="btn btn-warning btn-sm"><a href="lista_users.php?bloquear=<?php echo $id;?>"
			  style="text-decoration:none; color:white;"><span>Bloquear</span></a></button></td> 
				  
				  
			  <?php }else{
				  ?>
				  
				   <td><button type="button" class="btn btn-success btn-sm"><a href="lista_users.php?activar=<?php echo $id;?>"
			  style="text-decoration:none; color:white;"><span>Activar</span></a></button></td>
				  
			  <?php }
			  
			  ?>		  
			  
			  <td><button type="button" class="btn btn-info btn-sm"><a href="editar_user.php?editar=<?php echo $id;?>"
			  style="text-decoration:none; color:white;"><span>Editar</span></a></button></td>
			  <td><button type="button" class="btn btn-danger btn-sm"><a href="lista_users.php?apagar=<?php echo $id;?>"
			  style="text-decoration:none; color:white;"><span>Apagar</span></a></button></td>
			  
			  <?php }else{
				  
				  echo "<td><font color='red'>N/A</font></td>";
				  echo "<td><font color='red'>N/A</font></td>";
				  echo "<td><font color='red'>N/A</font></td>";
			  } ?>
			  
			 </tr>
			
			<?php }
			
			
			?>
			
			</tbody>
		
		 </table>
	   
	   
	   
	  <!-- ACCOES DE USUARIO-->

	  <?php
    if(isset($_GET['bloquear']) && !empty($_GET['bloquear'])){
		
		$id_bloquear = $_GET['bloquear'];
		
		$actualiza_status = "UPDATE usuarios SET status='Inactivo' WHERE id_user='$id_bloquear'";
		$legal = mysqli_query($con,$actualiza_status);
		
		if($legal){
			
			echo "<script>window.open('lista_users.php','_self')</script>";
		}else{
			
			echo "ERRRRRRRRRRRRRROOOOOOORRRRRRRRRRR";
		}
		
		
	}
	
	
	
	if(isset($_GET['activar']) && !empty($_GET['activar'])){
		
		$id_activar = $_GET['activar'];
		
		$actualiza_status1 = "UPDATE usuarios SET status='Activo' WHERE id_user='$id_activar'";
		$legal1 = mysqli_query($con,$actualiza_status1);
		
		if($legal1){
			
			echo "<script>window.open('lista_users.php','_self')</script>";
		}else{
			
			echo "ERRRRRRRRRRRRRROOOOOOORRRRRRRRRRR";
		}
		
		
	}
	
	
	
	if(isset($_GET['apagar']) && !empty($_GET['apagar'])){
		
		$id_apagar = $_GET['apagar'];
		
		$actualiza_status2 = "DELETE FROM usuarios WHERE id_user='$id_apagar'";
		$legal2 = mysqli_query($con,$actualiza_status2);
		
		if($legal2){
			
			echo "<script>window.open('lista_users.php','_self')</script>";
		}else{
			
			echo "ERRRRRRRRRRRRRROOOOOOORRRRRRRRRRR";
		}
		
		
	}
	

	  ?>
	   
	   
        
        
        </div>

     
        

      </div>
      <!-- /.container-fluid -->

      <!-- Sticky Footer -->
      <?php include "includes/footer.php";?>

    </div>
    <!-- /.content-wrapper -->

  </div>
  <!-- /#wrapper -->

  <!-- Scroll to Top Button-->
  <a class="scroll-to-top rounded" href="#page-top">
    <i class="fas fa-angle-up"></i>
  </a>

  <!-- Logout Modal-->
 <?php include "includes/logout_modal.php";?>

  <!-- Bootstrap core JavaScript-->
  <script src="vendor/jquery/jquery.min.js"></script>
  <script src="vendor/bootstrap/js/bootstrap.bundle.min.js"></script>

  <!-- Core plugin JavaScript-->
  <script src="vendor/jquery-easing/jquery.easing.min.js"></script>

  <!-- Page level plugin JavaScript-->
  <script src="vendor/chart.js/Chart.min.js"></script>
  <script src="vendor/datatables/jquery.dataTables.js"></script>
  <script src="vendor/datatables/dataTables.bootstrap4.js"></script>

  <!-- Custom scripts for all pages-->
  <script src="js/sb-admin.min.js"></script>

  <!-- Demo scripts for this page-->
  <script src="js/demo/datatables-demo.js"></script>
  <script src="js/demo/chart-area-demo.js"></script>

</body>

</html>
