<?php

    //validamos si la session no ha sido declarada, para incicializarla

    if (session_status() === PHP_SESSION_NONE) {

      session_start();

    }

    if(empty($_SESSION['login_appquadrata'])){

        echo"<script language='javascript'>window.location='../../../login'</script>;";

        exit();

    }

$time_log_assets=time();

    /*inicializamos valores para la configuracion del template*/

$setting_template='../../../settings_template.txt';

$variables=[];

$_Color='';

$_Template='';

$_Theme_Template='';

$_Css='';

$_Js='';

if (file_exists($setting_template)) {

    $lines = file($setting_template, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);

    foreach ($lines as $line) {

        list($nombre_variable, $valor) = explode('=', $line);

        $variables[$nombre_variable] = $valor;

    }

    /*recogemos los valores de las variables*/

    if (isset($variables['Color'])) {

        $_Color = $variables['Color'];



        //echo "El color es: $_Color";

    }

    if (isset($variables['Template'])) {

        $_Template = $variables['Template'];

        //echo "El Template es: $_template";

    }

    if (isset($variables['Theme_Template'])) {

        $_Theme_Template = $variables['Theme_Template'];

        //echo "El Theme_Template es: $_Theme_Template";

    }

    if (isset($variables['css'])) {

        $_Css = $variables['css'];

        //echo "El css es: $_Css";

    }

    if (isset($variables['js'])) {

        $_Js = $variables['js'];

        //echo "El js es: $_Js";

    }

}

/*terminan valores de configuracion pára el template*/

?>

<html  style="background-color: rgb(241, 245, 249);"  lang="es" class="<?php if($_Color!=''){ echo 'theme-user'; }else{ echo $_Theme_Template; }?>">

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

<meta name='description' content='Información sobre contenido de tu pagina'>

<meta name='keywords' content='aqui van los tags para ser encontrados por los boots de google ejemplo fibora,ti hyper solutions'>



<HEAD>



<?php

    include('../../path.php');

    //require('../modelo/modulo_app.php');

    require(ROOT_CONFIG);  

?>



    <link href='http://netdna.bootstrapcdn.com/bootstrap/3.1.0/css/bootstrap.min.css' rel='stylesheet'>

    <!---<link href='../assets/css/fileinput.css' media='all' rel='stylesheet' type='text/css' />

    <link href='../assets/css/honey.css' media='all' rel='stylesheet' type='text/css' />-->

    <script src='http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.js'></script>

    <!--<script src='../assets/js/fileinput.min.js' type='text/javascript'></script>

    <link rel="stylesheet" type="text/css" href="tableresponsive.css">-->

    <meta name="viewport" content="width=device-width,initial-scale=1">

    <!-- BEGIN: CSS Assets-->

    <link rel="stylesheet" href="../../../dist/css/<?=$_Css;?>?time=<?=$time_log_assets;?>" />

    <link rel="stylesheet" href="../../../dist/css/app_style.css?time=<?=$time_log_assets;?>" />

    <!-- END: CSS Assets-->

    <script src="../../../dist/js/noback.js?time=<?=$time_log_assets;?>" type="text/javascript"></script>

    <!--Comienza plugins JTABLE--->

    <script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script>

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>



    <!--Termina plugins JTABLE--->

        <style>

::-webkit-scrollbar {

    display: none;

}



.accordion {

  color: white;

  cursor: pointer;

  padding: 18px;

  width: 95%;

  border: none;

  text-align: left;

  outline: none;

  font-size: 15px;

  transition: 0.4s;

}



.active, .accordion:hover {

  background-color: #ccc; 

}



.panel {

  padding: 0 18px;

  display: none;

  background-color: white;

  overflow: hidden;

}



</style>

<?php



$action=!empty($_REQUEST['action'])?$_REQUEST['action']:'';

$pagina=!empty($_REQUEST['pagina'])?$_REQUEST['pagina']:'';

$_ScrollTo=!empty($_REQUEST['_ScrollTo'])?$_REQUEST['_ScrollTo']:'';

$Id_Rol=!empty($_REQUEST['Id_Rol'])?$_REQUEST['Id_Rol']:'';



$Titulo_Rol=!empty($_REQUEST['Titulo_Rol'])?$_REQUEST['Titulo_Rol']:'';





switch ($action) {

    case 'editar':



        echo"<TITLE>Editar modulo_app</TITLE>";

        break;



    default:

        echo"<TITLE>Registrar modulo_app</TITLE>";

        break;

}



?>    

<script src="../js/noback.js" type="text/javascript"></script>

<script language='JavaScript'> 

var statSend = false;

function checkSubmit() {

    if (!statSend) {

        statSend = true;

        return true;

    } else {

        alert('La Informaci\u00F3n ya se est\u00E1 enviando, por favor espere...');

        return false;

    }

}

</script> 

</HEAD>

    <center>

    <BODY onload="noback();">



  <?php

    //Comienza form del formulario

echo "<div class='intro-y box form-box'>";

    

    switch ($action) {

    case 'editar':

        echo "

            <div class='flex items-center p-5 border-b border-slate-200/60 dark:border-darkmode-400'>

                <h2 class='font-medium text-base mr-auto'>

                    EDITAR MODULO APP

                </h2>

            </div>";

        break;

    

    default:

        echo"

            <div class='flex items-center p-5 border-b border-slate-200/60 dark:border-darkmode-400'>

                <h2 class='font-medium text-base mr-auto'>

                    ASIGNAR PERMISOS DE USUARIO 

                </h2>

            </div>";

        break;

    }



    echo " <div class='grid grid-cols-12 gap-x-5'>

                <div class='col-span-12 xl:col-span-12' style='margin-bottom:40px;'>";

                echo "<a href='./' type='button' class='btn btn-secondary btn-lg' style='margin-bottom:30px;'>Volver atrás</a>";

        $Odbj_conexion = new odbconexion;

        $conexion=$Odbj_conexion->openconection();

        $consulta="SELECT * FROM modulo_app_appquadrata WHERE Id_Modulo_App!=1";

        $Adapter_map=$conexion->query($consulta);

        $conexion->close();

        while($Field_map=$Adapter_map->fetch_assoc())

        {

            $Href_Modulo=$Field_map['Href_Modulo'];

            echo "

            <form onsubmit='loadingpage();return checkSubmit();' id='frm_permisos{$Field_map['Id_Modulo_App']}' action='controller_permisos.php' method='post'>

            <input type='hidden' value='{$Id_Rol}' name='Id_Rol'>

            <input type='hidden' value='{$Titulo_Rol}' name='Titulo_Rol'>

            <input type='hidden' value='{$Field_map['Href_Modulo']}' name='table'>

            <input type='hidden' value='{$Field_map['Id_Modulo_App']}' name='Id_Modulo_App'>

            <input type='hidden' value='{$Field_map['Titulo_Modulo']}' name='Titulo_Modulo'>

            

            <button type='button' class='accordion btn-primary'>{$Field_map['Titulo_Modulo']}</button>

            <div class='panel' style='display:none;'>

                <div class='intro-y box mt-5'>";

                            $Odbj_conexion = new odbconexion;

                            $conexion=$Odbj_conexion->openconection();

                            $consulta="SELECT * FROM permiso_app_appquadrata where Id_Fk_Rol='$Id_Rol' AND Tabla_Modulo='$Href_Modulo'";

                            $Adapter_permisos_modulo=$conexion->query($consulta);

                            $conexion->close();

                                $checked='';

                                if($Adapter_permisos_modulo->num_rows>0){

                                while($Field_permisos_modulo=$Adapter_permisos_modulo->fetch_assoc())

                                {

                                echo "<div class='mt-3'>

                                        <label for='update-profile-form-7' class='form-label'>PERMISOS SOBRE EL MÓDULO: </label>";

                                        echo "<p>Marca la casilla del permiso que desea asignar al usuario.</p>";

                                         echo "<div id='checkPermisos'  style='margin-top:10px;'>";

                                         echo "<div class='flex flex-col sm:flex-row items-center p-5 border-b border-slate-200/60 dark:border-darkmode-400'>";

                                         if($Field_permisos_modulo['Registrar']=='Si'){

                                            $checked='checked';

                                         }else{

                                            $checked='';

                                         }

                                         echo "<div class='form-check form-switch w-full sm:w-auto sm:ml-auto mt-3 sm:mt-0'>";

                                            echo " <label for='cbox1{$Id_Rol}' class='mr-4'>Registrar <input type='checkbox' class='show-code form-check-input mr-0 ml-3' id='cbox1{$Id_Rol}' {$checked} value='Si' name='Registrar{$Id_Rol}'></label>";

                                        echo "</div>";

                                         if($Field_permisos_modulo['Editar']=='Si'){

                                            $checked='checked';

                                         }else{

                                            $checked='';

                                         }

                                         echo "<div class='form-check form-switch w-full sm:w-auto sm:ml-auto mt-3 sm:mt-0'>";

                                            echo " <label for='cbox2{$Id_Rol}' class='mr-4'>Editar <input type='checkbox' class='show-code form-check-input mr-0 ml-3' id='cbox2{$Id_Rol}' {$checked} value='Si' name='Editar{$Id_Rol}'></label>";

                                         echo "</div>";

                                         if($Field_permisos_modulo['Leer']=='Si'){

                                            $checked='checked';

                                         }else{

                                            $checked='';

                                         }

                                         echo "<div class='form-check form-switch w-full sm:w-auto sm:ml-auto mt-3 sm:mt-0'>";

                                            echo " <label for='cbox3{$Id_Rol}' class='mr-4'>Leer <input type='checkbox' class='show-code form-check-input mr-0 ml-3' id='cbox3{$Id_Rol}' {$checked} value='Si' name='Leer{$Id_Rol}'></label>";

                                         echo "</div>";

                                         if($Field_permisos_modulo['Exportar']=='Si'){

                                            $checked='checked';

                                         }else{

                                            $checked='';

                                         }

                                         echo "<div class='form-check form-switch w-full sm:w-auto sm:ml-auto mt-3 sm:mt-0'>";

                                            echo " <label for='cbox4{$Id_Rol}' class='mr-4'>Exportar <input type='checkbox' class='show-code form-check-input mr-0 ml-3' id='cbox4{$Id_Rol}' {$checked} value='Si' name='Exportar{$Id_Rol}'></label>";

                                         echo "</div>";

                                         if($Field_permisos_modulo['Eliminar']=='Si'){

                                            $checked='checked';

                                         }else{

                                            $checked='';

                                         }

                                         echo "<div class='form-check form-switch w-full sm:w-auto sm:ml-auto mt-3 sm:mt-0'>";

                                            echo " <label for='cbox5{$Id_Rol}' class='mr-4'>Eliminar <input type='checkbox' class='show-code form-check-input mr-0 ml-3' id='cbox5{$Id_Rol}' {$checked} value='Si' name='Eliminar{$Id_Rol}'></label>";

                                         echo "</div>";

                                         echo "</div>";

                                         echo "</div>";

                                    echo "</div>";

                                }

                            }else{

                                 echo "<div class='mt-3'>

                                        <label for='update-profile-form-7' class='form-label'>PERMISOS SOBRE EL MÓDULO: </label>";

                                        echo "<p>Marca la casilla del permiso que desea asignar al usuario.</p>";

                                         echo "<div id='checkPermisos'  style='margin-top:10px;'>";

                                             echo "<div class='flex flex-col sm:flex-row items-center p-5 border-b border-slate-200/60 dark:border-darkmode-400'>";

                                                echo "<div class='form-check form-switch w-full sm:w-auto sm:ml-auto mt-3 sm:mt-0'>";

                                                 echo " <label for='cbox1{$Id_Rol}' class='mr-4'>Registrar <input type='checkbox' class='show-code form-check-input mr-0 ml-3' id='cbox1{$Id_Rol}' value='Si' name='Registrar{$Id_Rol}'></label>";

                                                 echo "</div>";



                                                echo "<div class='form-check form-switch w-full sm:w-auto sm:ml-auto mt-3 sm:mt-0'>";

                                                 echo " <label for='cbox2{$Id_Rol}' class='mr-4'>Editar <input type='checkbox' class='show-code form-check-input mr-0 ml-3' id='cbox2{$Id_Rol}' value='Si' name='Editar{$Id_Rol}'> </label>";

                                                 echo "</div>";



                                                echo "<div class='form-check form-switch w-full sm:w-auto sm:ml-auto mt-3 sm:mt-0'>";

                                                 echo " <label for='cbox3{$Id_Rol}' class='mr-4'>Leer <input type='checkbox' class='show-code form-check-input mr-0 ml-3' id='cbox3{$Id_Rol}' value='Si' name='Leer{$Id_Rol}'> </label>";

                                                 echo "</div>";



                                                echo "<div class='form-check form-switch w-full sm:w-auto sm:ml-auto mt-3 sm:mt-0'>";

                                                 echo " <label for='cbox4{$Id_Rol}' class='mr-4'>Exportar <input type='checkbox' class='show-code form-check-input mr-0 ml-3' id='cbox4{$Id_Rol}' value='Si' name='Exportar{$Id_Rol}'> </label>";

                                                 echo "</div>";



                                                echo "<div class='form-check form-switch w-full sm:w-auto sm:ml-auto mt-3 sm:mt-0'>";

                                                  echo " <label for='cbox5{$Id_Rol}' class='mr-4'>Eliminar <input type='checkbox' class='show-code form-check-input mr-0 ml-3' id='cbox5{$Id_Rol}' value='Si' name='Eliminar{$Id_Rol}'> </label>";

                                                 echo "</div>";

                                            echo "</div>";

                                         echo "</div>";

                                    echo "</div>";

                            }

                                 echo "<div class='mt-3 mp-6' style='margin-top:35px;'>

                                    <label for='update-profile-form-7' class='form-label'>PERMISOS SOBRE LAS COLUMNAS DEL MÓDULO: </label>";

                                    echo "<table class='table'>";

                                    echo "<tr><th>Titulo de la columna </th><th>Registrar</th><th>Listar</th><th>Editar</th><th>Exportar</th></tr>";

                                        $Odbj_conexion = new odbconexion;

                                        $conexion=$Odbj_conexion->openconection();

                                        $consulta="SELECT * FROM permiso_columna_appquadrata WHERE Tabla_Modulo='$Href_Modulo' AND Id_Fk_Rol='$Id_Rol'";

                                        $Adapter_columna=$conexion->query($consulta);

                                        $conexion->close();

                                        $checked='';

                                        if($Adapter_columna->num_rows>0){

                                            while($Field_columna=$Adapter_columna->fetch_assoc())

                                            {

                                                echo "<tr><td>{$Field_columna['Titulo_Columna']}</td>";

                                                if($Field_columna['Registrar_Columna']=='Si'){

                                                    $checked='checked';

                                                 }else{

                                                    $checked='';

                                                 }



                                                echo "<td>";

                                                echo "<div class='flex flex-col sm:flex-row items-center p-5 border-b border-slate-200/60 dark:border-darkmode-400'>";

                                                echo "<div class='form-check form-switch w-full sm:w-auto sm:ml-auto mt-3 sm:mt-0'>";

                                                    echo "<label class='mr-3'>Registrar <input {$checked} type='checkbox' class='show-code form-check-input mr-0 ml-3' value='Si' name='Registrar_Columna{$Field_columna['Titulo_Columna']}'></label>";

                                                    echo "</div>";

                                                    echo "</div>";

                                                echo "</td>";



                                                if($Field_columna['Leer_Columna']=='Si'){

                                                    $checked='checked';

                                                 }else{

                                                    $checked='';

                                                 }

                                                echo "<td>";

                                                    echo "<div class='flex flex-col sm:flex-row items-center p-5 border-b border-slate-200/60 dark:border-darkmode-400'>";

                                                    echo "<div class='form-check form-switch w-full sm:w-auto sm:ml-auto mt-3 sm:mt-0'>";

                                                        echo "<label class='mr-3'>Leer <input {$checked} type='checkbox' class='show-code form-check-input mr-0 ml-3' value='Si' name='Leer_Columna{$Field_columna['Titulo_Columna']}'></label>";

                                                        echo "</div>";

                                                    echo "</div>";

                                                echo "</td>";

                                                if($Field_columna['Editar_Columna']=='Si'){

                                                    $checked='checked';

                                                 }else{

                                                    $checked='';

                                                 }

                                                echo "<td>";

                                                    echo "<div class='flex flex-col sm:flex-row items-center p-5 border-b border-slate-200/60 dark:border-darkmode-400'>";

                                                    echo "<div class='form-check form-switch w-full sm:w-auto sm:ml-auto mt-3 sm:mt-0'>";

                                                    echo "<label class='mr-3'>Editar <input {$checked} type='checkbox' class='show-code form-check-input mr-0 ml-3' value='Si' name='Editar_Columna{$Field_columna['Titulo_Columna']}'></label>";

                                                        echo "</div>";

                                                    echo "</div>";

                                                echo "</td>";

                                                if($Field_columna['Exportar_Columna']=='Si'){

                                                    $checked='checked';

                                                 }else{

                                                    $checked='';

                                                 }

                                                echo "<td>";

                                                    echo "<div class='flex flex-col sm:flex-row items-center p-5 border-b border-slate-200/60 dark:border-darkmode-400'>";

                                                    echo "<div class='form-check form-switch w-full sm:w-auto sm:ml-auto mt-3 sm:mt-0'>";

                                                        echo "<label class='mr-3'>Exportar <input {$checked} type='checkbox' class='show-code form-check-input mr-0 ml-3' value='Si' name='Exportar_Columna{$Field_columna['Titulo_Columna']}'></label>";

                                                        echo "</div>";

                                                    echo "</div>";

                                                echo "</td></tr>";

                                            }

                                        }else{

                                            $Odbj_conexion = new odbconexion;

                                            $conexion=$Odbj_conexion->openconection();

                                            $consulta="select COLUMN_NAME from INFORMATION_SCHEMA.COLUMNS where TABLE_NAME = '$Href_Modulo'";

                                            $Adapter_columna=$conexion->query($consulta);

                                            $conexion->close();

                                            while($Field_columna=$Adapter_columna->fetch_assoc())

                                            {

                                                echo "<tr>";

                                                echo "<td>{$Field_columna['COLUMN_NAME']}</td>";

                                                echo "<td>";

                                                    echo "<div class='flex flex-col sm:flex-row items-center p-5 border-b border-slate-200/60 dark:border-darkmode-400'>";

                                                    echo "<div class='form-check form-switch w-full sm:w-auto sm:ml-auto mt-3 sm:mt-0'>";

                                                    echo "<label class='mr-4'>Registrar <input checked type='checkbox' class='show-code form-check-input mr-0 ml-3' value='Si' name='Registrar_Columna{$Field_columna['COLUMN_NAME']}'></label>";

                                                    echo "</div>";

                                                    echo "</div>";

                                                echo "</td>";

                                                echo "<td>";

                                                    echo "<div class='flex flex-col sm:flex-row items-center p-5 border-b border-slate-200/60 dark:border-darkmode-400'>";

                                                    echo "<div class='form-check form-switch w-full sm:w-auto sm:ml-auto mt-3 sm:mt-0'>";

                                                    echo "<label class='mr-4'>Leer <input checked type='checkbox' class='show-code form-check-input mr-0 ml-3' value='Si' name='Leer_Columna{$Field_columna['COLUMN_NAME']}'></label>";

                                                    echo "</div>";

                                                    echo "</div>";

                                                echo "</td>";

                                                echo "<td>";

                                                    echo "<div class='flex flex-col sm:flex-row items-center p-5 border-b border-slate-200/60 dark:border-darkmode-400'>";

                                                    echo "<div class='form-check form-switch w-full sm:w-auto sm:ml-auto mt-3 sm:mt-0'>";

                                                    echo "<label class='mr-4'>Editar <input checked type='checkbox' class='show-code form-check-input mr-0 ml-3' value='Si' name='Editar_Columna{$Field_columna['COLUMN_NAME']}'></label>";

                                                    echo "</div>";

                                                    echo "</div>";

                                                echo "</td>";

                                                echo "<td>";

                                                    echo "<div class='flex flex-col sm:flex-row items-center p-5 border-b border-slate-200/60 dark:border-darkmode-400'>";

                                                    echo "<div class='form-check form-switch w-full sm:w-auto sm:ml-auto mt-3 sm:mt-0'>";

                                                    echo "<label class='mr-4'>Exportar <input checked type='checkbox' class='show-code form-check-input mr-0 ml-3' value='Si' name='Exportar_Columna{$Field_columna['COLUMN_NAME']}'></label>";

                                                    echo "</div>";

                                                    echo "</div>";

                                                echo "</td>";

                                                echo "</tr>";

                                            }

                                        }

                                    echo "</table>";



                            echo "<button type='button' onclick='submit_frm({$Field_map['Id_Modulo_App']});loadingpage();' class='btn btn-success' style='margin-top:20px;margin-bottom:20px;'>Guardar cambios<button>";

                            echo "</div>";

                echo "</div>



            </div>";

            echo "</form>";

        }    

    echo "</div></div>"



    //Termina form del formulario

?>



    </BODY>

    <script src="../../../dist/js/app.js?time=<?=$time_log_assets;?>"></script> 

            <script type="text/javascript">

          window.onload=function(){

            parent.document.getElementById('loadingpage').style.display='none';

          }



          function loadingpage(){

              parent.document.getElementById('loadingpage').style.display='block';                     

           }

        </script>  

    <script>

var acc = document.getElementsByClassName("accordion");

var i;



for (i = 0; i < acc.length; i++) {

  acc[i].addEventListener("click", function() {

    this.classList.toggle("active");

    var panel = this.nextElementSibling;

    if (panel.style.display === "block") {

      panel.style.display = "none";

    } else {

      panel.style.display = "block";

    }

  });

}

</script>

<script type="text/javascript">

    function submit_frm(e){

        document.getElementById('frm_permisos'+e).submit();

        loadingpage();

    }

</script>

    </center>

</HTML>