<?php
require_once ("../../config/Cado.php");
require_once ("cCategoria.php");
$oCategoria = new cCategoria();
$dts=$oCategoria->mostrarTodos();
$num_rows= mysqli_num_rows($dts);
mysqli_free_result($dts);
?>
<style type="text/css">
.div_muestra{
width:10px;
height:10px;	
}
</style>

<section class="content">
	<div class="container-fluid">
	<div class="row">
	    <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
		    <div class="card">
				<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12" style="padding:5px;">
	
	<div class="table-responsive">
		
        <table id="tabla_categoria" class="table table-bordered table-striped">
                <thead>
                    <tr>
                        <th>NOMBRE</th>
                        <th>ID</th>
                        <th>VER</th>
                        <th>COLOR</th>
                        <th>&nbsp;</th>
                    </tr>
                </thead>
                <?php
                if($num_rows>0){
                    ?>
                    <tbody>
                        <?php
                        $dts1=$oCategoria->mostrar_cat_idp();
                        $num_rows1= mysqli_num_rows($dts1);
                        if($num_rows1>0){
                            while($dt1 = mysqli_fetch_array($dts1)){
								
								$ver = $dt1['tb_categoria_verped'];
								
								if($ver==0){
									$vermos = 'NO';
								}else if($ver==1){
									$vermos = 'SI';
								}
								
                                ?>
                                <tr class="even">
                                    <td><span style="font-size:11px; font-weight: bold;" title="<?php echo $dt1['tb_categoria_id']?>"><?php echo $dt1['tb_categoria_nom']?></span></td>
                                    <td align="center"><?php echo $dt1['tb_categoria_id']?></td>
                                    <td align="center"><?php echo $vermos; ?></td>
                                    <td align="center">
									<div class="div_muestra" style="background-color:<?php echo $dt1['tb_categoria_color']; ?>; " ></div>
									</td>
                                    <td nowrap align="center">
   
	<button class="btn btn-sm btn-primary" onClick="categoria_form('editar','<?php echo $dt1['tb_categoria_id']?>')" ><i class="fas fa-edit"></i></button>
	<button class="btn btn-sm btn-primary" onClick="eliminar_categoria('<?php echo $dt1['tb_categoria_id']?>')" ><i class="fas fa-trash"></i></button>
						
								   </td>
                                </tr>
                                <?php
        //nivel 2
                                $dts2=$oCategoria->mostrar_por_idp($dt1['tb_categoria_id']);
                                $num_rows2= mysqli_num_rows($dts2);
                                if($num_rows2>0){
                                    while($dt2 = mysqli_fetch_array($dts2)){
                                        ?>
                                        <tr class="even">
                                            <td><span style="font-size:11px; margin-left:15px;" title="<?php echo $dt2['tb_categoria_id']?>"><?php echo '-'.$dt2['tb_categoria_nom']?></span></td>
                                            <td align="center"><?php echo $dt2['tb_categoria_id']?></td>
											 <td align="center">
									<div class="div_muestra" style="background-color:<?php echo $dt1['tb_categoria_color']; ?>; " ></div>
									</td>
                                    <td align="center">
                                          
		<button class="btn btn-sm btn-primary" onClick="categoria_form('editar','<?php echo $dt2['tb_categoria_id']?>')" ><i class="fas fa-edit"></i></button>
	<button class="btn btn-sm btn-primary" onClick="eliminar_categoria('<?php echo $dt2['tb_categoria_id']?>')" ><i class="fas fa-trash"></i></button>
								
									
									
									
									</td>
                                        </tr>
                                        <?php
        //nivel 3
                                        $dts3=$oCategoria->mostrar_por_idp($dt2['tb_categoria_id']);
                                        $num_rows3= mysqli_num_rows($dts3);
                                        if($num_rows3>0){
                                            while($dt3 = mysqli_fetch_array($dts3)){
                                                ?>
                                    <tr class="even">
                                    <td><span style="font-size:10px; margin-left:30px;" title="<?php echo $dt3['tb_categoria_id']?>"><?php echo '-'.$dt3['tb_categoria_nom']?></span></td>
                                    <td align="center"><?php echo $dt3['tb_categoria_id']?></td>
									<td align="center">
									<div class="div_muestra" style="background-color:<?php echo $dt1['tb_categoria_color']; ?>; " ></div>
									</td>
                                    <td align="center">
                                              
                                     <span title="Editar" class="btn btn-primary glyphicon glyphicon-pencil" onClick="categoria_form('editar','<?php echo $dt3['tb_categoria_id']?>')" ></span>
									<span title="Eliminar" class="btn btn-primary glyphicon glyphicon-trash" onClick="eliminar_categoria('<?php echo $dt3['tb_categoria_id']?>')" ></span>
									
									
									</td>
                                   </tr>
                                                <?php
                                            }
                                            mysqli_free_result($dts3);
        }//fin nivel 3
        
    }
    mysqli_free_result($dts2);
        }//fin nivel 2
        
    }
    mysqli_free_result($dts1);
    }//fin nivel 1
    ?>
</tbody>
<?php }?>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
</section>

<script type="text/javascript">
    $(function() { 	  
	  
	   $('#tabla_categoria').DataTable({
 
        "language": {
                "lengthMenu": "Mostrar _MENU_ registros",
                "zeroRecords": "No se encontraron resultados",
                "info": "Mostrando registros del _START_ al _END_ de un total de _TOTAL_ registros",
                "infoEmpty": "Mostrando registros del 0 al 0 de un total de 0 registros",
                "infoFiltered": "(filtrado de un total de _MAX_ registros)",
                "sSearch": "Buscar:",
                "oPaginate": {
                    "sFirst": "Primero",
                    "sLast":"Último",
                    "sNext":"Siguiente",
                    "sPrevious": "Anterior"
			     },
			     "sProcessing":"Procesando...",
            }
    });  
	
    });
</script>