<?php
@session_start();
$vg_login=$_SESSION["usuario"];
if($vg_login<>""){}
else
{echo "<script>";
 echo "window.location='../index.php';";
 echo "</script>";
}	
include "../valida_permisos.php";
$vg_programa = F_programa();
include "../seguridad.php";
$sql_entrada= mysqli_query($conseg,"select login,nombre,perfil,programa,cedula,pais from permiso     
					  where login='".trim($vg_login)."'  and programa=".$vg_programa."");
while($datos= mysqli_fetch_row($sql_entrada))
	  { $vg_nombre=$datos[1];
		$vg_perfil=$datos[2];				
	  } 

//permisos a formularios
$modulo="Seguridad";
$permisos=validar_permiso($vg_login,$modulo,$vg_perfil,$vg_programa);
include "../permisos.php";
$valpermiso=F_permiso($permisos);

if($valpermiso[0]==1){}
else
{echo "<script>";
echo "window.location='../erroracceso.php?formulario=Parametros_Usuarios';";
echo "</script>";
}

?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3c.org/TR/1999/REC-html401-19991224/loose.dtd">

<html>

<head>

<title>SEGURIDAD</title>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<LINK href="../general.css" type=text/css rel=stylesheet>

<script src="../js/jquery.min.js"></script>

  <link href="../bootstrap/css/bootstrap.min.css" rel="stylesheet">

  <script src="../bootstrap/js/bootstrap.min.js"></script>

  <link href="../icono.ico" rel="shortcut icon">

  <link rel="stylesheet" href="../plugins/datatables-bs4/css/dataTables.bootstrap4.min.css">
  <link rel="stylesheet" href="../plugins/datatables-responsive/css/responsive.bootstrap4.min.css">
  <link rel="stylesheet" href="../plugins/datatables-buttons/css/buttons.bootstrap4.min.css">
  
</head>

 

<BODY >

<?php





include "../conexion.php";

$usuario=$_REQUEST["usuario"];
if(isset($_REQUEST["oculto"]))
{ 
	
	
		if($_REQUEST["oguardar"]==1)
		  {  
				$c=1; $canti=$_REQUEST['cantir'];
				$sql_datoscanti =mysqli_query( $conexion,"delete from  empresa_usuario where usuario='".$usuario."'");
				while($c<=$canti)
				{  
					if(isset($_REQUEST['ch'.$c])) {$val=1; }  else {$val=0;} 
					$id=$_REQUEST['id'.$c];
					if($val==1)
					  {  
						$sql_insert=mysqli_query($conexion,"insert into empresa_usuario (empresa,usuario)
															values ('".$id."','".$usuario."')"); 
					  }
					$c=$c+1;
		        }//fin cliclo	  
		 }//fin guardar


}


?>

<form name="parametros" method="post" action="" >
<div align="center">
    <div class="panel panel-primary" >
      <div class="panel-heading">CONFIGURACION EMPRESA USUARIO</div>
       <div align="center">

				  
				  <table width="100%" border="0" cellspacing="0" cellpadding="0"  >
                    <tr> 
                      <td width="600"><div align="center">
                        <input name="guardar" type="submit"  id="guardar"  value="Guardar/Modificar" onClick="oguardar.value=1;" class="btn btn-primary" />
                          <br>
                          <input name="oguardar" type="hidden" id="oguardar">
                          <input name="Obuscar" type="hidden" id="Obuscar">
                          <input name="omodificar" type="hidden" id="omodificar">
                          <input name="oreporte" type="hidden" id="oreporte">
                          <input name="obuscadato" type="hidden" id="obuscadato">
                          <input name="oculto" type="hidden" id="oculto">
                          <br>
                        </div></td>
                    </tr>
                  </table>
     
     
      <!-- /.card-header -->
      <?php
          $sql_contar=mysqli_query($conexion,"SELECT empresa FROM empresa_usuario  where usuario='".$usuario."'");
		  while($datoscontar= mysqli_fetch_row($sql_contar)){ $empresa=$datoscontar[0];
		  
		  	$sql_contare=mysqli_query($conexion,"SELECT nombre FROM empresa  where id='".$empresa."'");
		  	while($datoscontare= mysqli_fetch_row($sql_contare)){ $nempresa=$datoscontare[0];}
		  
		  echo "<strong>Empresas Asignadas a Usuario: $nempresa </strong>";
		  }
	  ?>
      
              <div class="card-body">
                <table id="example1" class="table table-bordered table-striped" style="font-size:11px;">
                  <thead>
                  <tr>
                    <th class="btn-primary" width="90%">EMPRESA</th>
                    <th class="btn-primary">ACTIVAR</th>
                  </tr>
                  </thead>                 
                  <tbody>
                  <?php
				  $c=1;
				 $sql_datos =mysqli_query($conexion,"select id,nombre from empresa order by id asc");
				  while($datoslog= mysqli_fetch_row($sql_datos))//01
				  {
					  $id=$datoslog[0];
					  $nombre=$datoslog[1];
	
					  $sql_contar=mysqli_query($conexion,"SELECT count(*) FROM empresa_usuario 
															  where empresa='".$id."' and usuario='".$usuario."'");
					  while($datoscontar= mysqli_fetch_row($sql_contar)){ $contar=$datoscontar[0];}
					  if($contar>=1){$checked="checked"; } else { $checked=""; } 
				
					echo "<tr>
							<td>$nombre</td>
							<td>
							<input name='id$c' type='hidden' id='id$c'  value='$id'>
							<input type='checkbox' name='ch$c' style='width: 15px' $checked ></td>
						</tr>";
					$c++;
				  }
					 $canti=$c-1;
					 echo "<input type='text' name='cantir' value='$canti' readonly size='10' style='width:1px; height=1px;' readonly>";	
				  ?>
                  </tbody>
                 
                </table>
              </div>
              <!-- /.card-body -->
</div>
</div>	


<div id="resultado"></div>


<!-- jQuery -->
<script src="../plugins/jquery/jquery.min.js"></script>
<!-- Bootstrap 4 -->
<script src="../plugins/bootstrap/js/bootstrap.bundle.min.js"></script>
<!-- DataTabls  & Plugins -->
<script src="../plugins/datatables/jquery.dataTables.min.js"></script>
<script src="../plugins/datatables-bs4/js/dataTables.bootstrap4.min.js"></script>
<script src="../plugins/datatables-responsive/js/dataTables.responsive.min.js"></script>
<script src="../plugins/datatables-responsive/js/responsive.bootstrap4.min.js"></script>
<script src="../plugins/datatables-buttons/js/dataTables.buttons.min.js"></script>
<script src="../plugins/datatables-buttons/js/buttons.bootstrap4.min.js"></script>
<script src="../plugins/jszip/jszip.min.js"></script>
<script src="../plugins/pdfmake/pdfmake.min.js"></script>
<script src="../plugins/pdfmake/vfs_fonts.js"></script>
<script src="../plugins/datatables-buttons/js/buttons.html5.min.js"></script>
<script src="../plugins/datatables-buttons/js/buttons.print.min.js"></script>
<script src="../plugins/datatables-buttons/js/buttons.colVis.min.js"></script>
<!-- AdminLTE App -->
<script src="../dist/js/adminlte.min.js"></script>
<!-- AdminLTE for demo purposes -->
<script src="../dist/js/demo.js"></script>
<!-- Page specific script -->
<script>
  $(function () {
    $("#example1").DataTable({
      "responsive": true, "lengthChange": false, "autoWidth": false,
      "buttons": ["copy", "csv", "excel", "pdf", "print", "colvis"]
    }).buttons().container().appendTo('#example1_wrapper .col-md-6:eq(0)');
    $('#example2').DataTable({
      "paging": true,
      "lengthChange": false,
      "searching": false,
      "ordering": true,
      "info": true,
      "autoWidth": false,
      "responsive": true,
    });
  });
  
 
</script>

</form>
</body>
</html>