<?php
session_start();
require_once('../conexion.php');
require_once('../include/sesiones.php'); 
 $user=$_GET['user'];
$registros1=mysqli_query($con,"SELECT * from menu_superior") or die(mysqli_error($con));
while ($row1=mysqli_fetch_array($registros1))
    {
        $men_id=$row1['men_id'];
        $men_nombre=$row1['men_nombre'];
?>
<div class="col-sm-3" style="height:630px;">  
<?php
    $registros2=mysqli_query($con,"SELECT * from menu_permiso where menu_superior='$men_id' and usuario='$user'") or die(mysqli_error($con));
    $row2=mysqli_fetch_array($registros2);
    $estado=$row2['estado'];
?>
    <table class="table table-striped table-bordered">
        <thead>
            <tr>
                <th ><?php echo $men_nombre; ?></th>
                <th width="5%">
                    <?php if($estado=='Activo')
                    { ?>
                        <a href="#" onclick="estado_menu(<?php echo $men_id; ?>,<?php echo $user; ?>)"> <span class="" title="Activo"><i class="fas fa-check-circle fa-2x"></i></span></a>
                    <?php } 
                    else
                    { ?>
                        <a href="#" onclick="estado_menu(<?php echo $men_id; ?>,<?php echo $user; ?>)"> <span class="" title="Inactivo"><i class="far fa-circle fa-2x"></i></span></a>
                  <?php  }
                    ?> 
                </th>
            </tr>
        </thead>
        <tbody  class="buscar">
            <?php
                $registros=mysqli_query($con,"SELECT * from modulo where mod_menu='$men_id' and estado='Activo' ") or die(mysqli_error($con));
                    while ($row3=mysqli_fetch_array($registros))
                    {
                        $mod_id=$row3['mod_id'];
                        $regis=mysqli_query($con,"SELECT * from permiso where modulo_mod_id='$mod_id' and usuario_usu_id='$user'  ") or die(mysqli_error($con));
                        $reg=mysqli_fetch_array($regis);
            ?>
            <tr>
                <td ><strong><?php  echo $row3['mod_nombre']; ?></strong></td>
                <td>
                <?php  
                    if($reg['per_visualizar']=="Activo")
                        {
                            echo  $estados='<a href="#" onclick="estado('.$reg['per_id'].','.$men_id.','.$user.')"> <span class="" title="Desactivar"><i class="fas fa-check-circle fa-2x" style="color:#0F8509;"></i></span></a>';
                        }
                        else  
                        {
                            echo  $estados='<a href="#"  onclick="estado('.$reg['per_id'].','.$men_id.','.$user.')"><span class="" title="Activar"> <i class="far fa-times-circle fa-2x" style="color:#EE121A;"></i></span></a>';
                        }
                    ?>
                  </td>
            </tr>
            <?php
                $count_query=mysqli_query($con, "SELECT count(*) AS numrows FROM modulo_permiso where mod_id='$mod_id' and usuario='$user' ");
                $row= mysqli_fetch_array($count_query);
                $numrows = $row['numrows'];
                if ($numrows>0)
                {
            ?>

            <tr style="padding:0px;">
                <td colspan="2">
                     
             <?php
                $registros3=mysqli_query($con,"SELECT * from modulo_permiso where mod_id='$mod_id' and usuario='$user' ") or die(mysqli_error($con));
                    while ($row4=mysqli_fetch_array($registros3))
                    {
            ?>
                    <?php  
                    if($row4['estado']=="Activo")
                        {
                           echo $estados='<input type="checkbox" id="sabor" name="sabor[]" value="" checked>
                                <label class="lab" for="sabor"  onclick="estado_funciones('.$row4['modpe_id'].')">'.$row4['modp_nombre'].'</label>';
                        }
                        else  
                        {
                            echo $estados='<input type="checkbox" id="sabor" name="sabor[]" value=""  >
                                <label class="lab" for="sabor"  onclick="estado_funciones('.$row4['modpe_id'].')" >'.$row4['modp_nombre'].'</label>';
                           
                        }
                    ?></p>
              
            <?php } ?>


                </td>
            </tr>
        <?php } }?>
        </tbody>
    </table>
        </div>
<?php }?>
<style>

.lab {
    font-weight: 600;
    color: #777777;
    margin-bottom: 8px;
    width: 100%;
    float: left;
    cursor: pointer;
    padding: 0 0.6em;
    box-sizing: border-box;
    background: #FA9D8A;
    transition: all 0.5s ease 0s;
    float: right;
}

input[type="checkbox"] {
    display: none;
}

input[type="checkbox"] + label {
    line-height: 3em;
}


input[type="checkbox"]:disabled + label {
    color: #ccc !important;
    cursor: not-allowed;
}
input[type="checkbox"]:checked:disabled + label:after {
    border-color: #ccc;
}

input[type="checkbox"] + label:before {
    content: "";
    width: 26px;
    height: 26px;
    float: left;
    margin-right: 0.5em;
    border: 2px solid red;
    background: #fff;
    margin-top: 0.5em;
}

input[type="checkbox"]:checked + label {
    background: #c1eec2;
}


input[type="checkbox"]:checked + label:after {
    content: "";
    width: 12px;
    height: 6px;
    border: 4px solid #0fbf12;
    float: left;
    margin-left: -1.95em;
    border-right: 0;
    border-top: 0;
    margin-top: 1em;
    transform: rotate(-55deg);
}

input[type="checkbox"]:checked + label:before {
    border-color: #0fbf12;
}

input[type="checkbox"]:checked:disabled + label {
    background: #ccc;
    color: #fff !important;
}

input[type="checkbox"]:checked:disabled + label:before {
    border-color: #bdbdbd;
}

@media (max-width: 650px) {
    .content {
        width: 100%;
    }
}
</style>