<?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>";
}
*/
?>

<strong><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>

<link rel="icon"  href="../lipre.ico" />

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

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

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

</head>

<body >

<?php

@session_start();

include "../conexion.php";

$vl_login=$_REQUEST['vl_login'];





if(isset($_REQUEST['oculto']))

  { $vl_login=$_REQUEST["login"];



     if(isset ($_REQUEST['modificar']))

        {  

				$sql_insert=mysqli_query($conexion,"delete from nivel_usuario where usuario='".$vl_login."'"); 



			    $c=1; $canti=$_REQUEST['cantir'];

				while($c<=$canti)

				{  

					if(isset($_REQUEST['ch'.$c])) {$val=1; }  else {$val=0;}

					if($val==1)

					  {  

					    $id=$_REQUEST['id'.$c];	

						$sql_insert = mysqli_query($conexion,"insert into nivel_usuario (usuario,nivel)

													   values ('".$vl_login."',".$id.")");

													   

					  }

					$c=$c+1;

		        }//fin cliclo	

        }//fin modifica

		

   }//fin  oculto



?>

<?php

// if($vp_vvalida[0]==1)

 //{

?>

<form name="form1" method="post" action="">

<div align="center">

 <input name="login" type="hidden" class="form-control" id="login" onFocus="this.style.background='#ccffff'" onBlur="this.style.background='#ffffff'"

  value="<?php echo $vl_login; ?>" style="width: 100px" readonly>

 <input name="modificar" type="submit" id="modificar"  value="Procesar" class="btn btn-primary">

    <input type="hidden" name="oculto"> 

    <?php

	

		$rs_perfiles= mysqli_query($conexion, "SELECT id,nombre FROM nivel  where estado='A' order by id asc");

									   

						$c=1;

						echo "<br><center>";

						echo "<table cellspacing='0' cellpadding='0' border='1'  class='table table-hover' > \n";

						echo "<tr  class='btn-primary' >

								<td  class='tituloTabla'>ACTIVAR</td>

								<td  class='tituloTabla'>NIVEL ATENCION</td>

							 </tr>";

						while($row=mysqli_fetch_row($rs_perfiles))

						 { $vr_codigo=$row[0];

						   $nombre=$row[1];

						   $contar=0;

						   $sql_contarobs=mysqli_query($conexion,"select count(*) from nivel_usuario

																	where usuario='".$_REQUEST['vl_login']."'

																	and nivel='".$vr_codigo."'"); 		

							while($datosobs=mysqli_fetch_row($sql_contarobs))   {	$contar=$datosobs[0];   	   }

						 

						  if($contar==1)  {$checked="checked";} else {$checked="";}

						  

						  echo "<tr >

								<td>

									<input name='id$c' type='hidden' id='id$c'  value='$vr_codigo'>

									<input type='checkbox' name='ch$c' style='width: 15px' $checked ></td>

								<td>$nombre</td>

							</tr>";

								$c++;

						  

						 }

		 echo "</table></center>";

		 $canti=$c-1;

		 echo "<input type='hidden' name='cantir' value='$canti' readonly size='10'>";	



								

	  ?>

  </div>

</form>

</body>

</html>

