<?php
session_start();
require_once ("../../config/Cado.php");
require_once ("cUsuario.php");
$oUsuario = new cUsuario();
require_once ("../usuario/cUsuarioprograma.php");
$oUsuarioprograma = new cUsuarioprograma();
require_once ("../formatos/formatos.php");
require_once ("../modulo/cModulo.php");
$oModulo = new cModulo();


$dts1=$oModulo->filtrarUsuario();
	

?>
				
					<input name="action_usuario" id="action_usuario" type="hidden" value="<?php echo $_POST['action']?>">
					<input name="hdd_usu_id" id="hdd_usu_id" type="hidden" value="<?php echo $_POST['usu_id']?>">    
					<input name="hdd_emp_id" id="hdd_emp_id" type="hidden" value="<?php echo $_SESSION['empresa_id']?>">
					<div class="box-header">
						<h3 class="box-title">Información de Programas</h3>
					</div>
					<div class="box-body">
						
						<!--
						<div class="form-group">
							<div class="row">        
								<div class="col-lg-5 col-xs-6">
									<label for="cmb_mod_id">Modulo:</label>
									<td><select name="cmb_mod_id" id="cmb_mod_id"  class="form-control"></select> 
								</div>
									
								<div class="col-lg-2 col-xs-6" style="padding-top: 30px;">
										<button class="btn btn-primary" id="btn_agregarprograma"><i class="fas fa-angle-double-down"></i></button>
								</div>
							</div>
						</div>
						-->
						
						<table>
						<td>
						
						
							<div class="col-lg-12 col-md-12 col-xs-12" style="padding:0px;">
 									
									
								<?php while($dt1 = mysqli_fetch_array($dts1))
								{
									
									$dts=$oUsuarioprograma->mostrar_uno($_POST['usu_id'],$dt1['tb_modulo_id']);
									$num_rows= mysqli_num_rows($dts);
									if($num_rows>0){
										$entra = true;
									}else{
										$entra = false;
									}
									
									
								?>
								
									
									<div class="col-lg-4 col-md-4 col-xs-12 float-right" style="padding:1px;margin-bottom:2px" >
									
									<div class="div_checkbox_<?php echo $dt1['tb_modulo_id']; ?> float-left">
									<input type="checkbox" onclick="agregarPrograma('<?php echo $dt1['tb_modulo_id']; ?>','<?php echo $_POST['usu_id']; ?>');" name="chk_imprimir; ?>" id="chk_imprimir_<?php echo $dt1['tb_modulo_id']; ?>" value="1" 
									<?php 
										if($entra){echo 'checked="true"';}else{}
									?>
									/>
										<label class="lbl_chk_<?php echo $dt1['tb_modulo_id']; ?>" for="chk_imprimir_<?php echo $dt1['tb_modulo_id']; ?>"></label>
										</div>
										<strong style="margin-left:3px" ><?php echo " ".$dt1['tb_modulo_nom']; ?></strong>
										
									
									</div>
									
									
									<style type="text/css">
										input[type=checkbox] {
										 cursor:pointer;
										}
										#chk_imprimir_<?php echo $dt1['tb_modulo_id']; ?> {
										  visibility: hidden;
										}
										.div_checkbox_<?php echo $dt1['tb_modulo_id']; ?> {
											width: 60px;
											height: 20px;
										 	border:1px solid #FF8800;
											margin-left: 0px;
											border-radius: 6px;
											padding:12px;
											position: relative;
										  font-family: 'Aldrich', sans-serif; 
										}
										.div_checkbox_<?php echo $dt1['tb_modulo_id']; ?>:before {
											content: 'Sí';
											position: absolute;
											top: 2px;
											left: 12px;
											color: #1DE9B6;
											font-size: 13px;
										  line-height: 15px;
										  text-shadow: 0 0 2px #1DE9B6;
										}
										.div_checkbox_<?php echo $dt1['tb_modulo_id']; ?>:after {
											content: 'No';
										  color: #D32F2F;
											position: absolute;
											top: 2px;
											right: 5px;
											font-size: 13px;
										  line-height: 15px;
										  text-shadow: 0 0 1px #D32F2F;
										}
										.div_checkbox_<?php echo $dt1['tb_modulo_id']; ?> .lbl_chk_<?php echo $dt1['tb_modulo_id']; ?> { 
											background: #D32F2F;
											display: block;
											width: 25px;
											height: 15px;
											padding:10px;
											border-radius: 4px;
											transition: all .7s ease;
											cursor: pointer;
											position: absolute;
											top: 2px;
											z-index: 1;
											left: 5px;
										}
										.div_checkbox_<?php echo $dt1['tb_modulo_id']; ?> #chk_imprimir_<?php echo $dt1['tb_modulo_id']; ?>:checked + .lbl_chk_<?php echo $dt1['tb_modulo_id']; ?> {
											left: 30px;
											background: #1DE9B6;
										}
										</style>
											
	
					
								<?php
								}
								mysqli_free_result($dts1);
								?>
									
 							</div> 
						
						</td>
						</table>
							
							
							<!--
							<div class="col-lg-12 col-md-12 col-xs-12" style="padding:5px;">
 									<div id="div_programa_tabla"></div>
 							</div> 	
							-->	
					</div>
					
					<div class="col-lg-12 col-md-12 col-xs-12" style="height:20px;"></div> 
							
				<div class="box-footer float-right">
					<button type="button" data-dismiss="modal" class="btn btn-default cancel">Cancelar</button>
				</div>
						
						
		<script type="text/javascript">

 
$(function() {
	
		

});

			
			
function agregarPrograma(mod_id,usu_id){
		if($("#chk_imprimir_"+mod_id).is(':checked')){
			agregar_modulo('agregar',mod_id,usu_id);
		}else{
			agregar_modulo('anular',mod_id,usu_id);
		}
}

			
function agregar_modulo(act, mod_id,usu_id)
{	
	$.ajax({
		type: "POST",
		url: "../usuario/agregar_modulo.php",
		async:true,
		dataType: "json",                      
		data: ({
			action:	act,
			usu_id: usu_id,
			mod_id: mod_id
		}),
		beforeSend: function() {

		},
		success: function(data){
			toastr["info"](data.msj);
		
		},
		complete: function(data)
		{
			
		}
	});
}

	</script>