<script>
  function load(){
    Swal({
      title: 'Cargando...',
      text: 'Por favor espere',
      onBeforeOpen: () => {
        Swal.showLoading()
      }
    })
  }
<?php
include_once('../../../php/db/dbExec.php');
include_once('../../../php/functions.php');

# VARIABLES GLOBALES PARA LLAVE PRIMARIA
$usuCod=utf8_decode($_SESSION['usuCod']);

# QUERYS
$sUsuarios = "SELECT * FROM usuarios WHERE usu_cod='$usuCod'";
$sMod = "SELECT * FROM modulos";
$sOpcUsu = "SELECT * FROM op_usu";

function sOp($mod) {
  global $usuCod;
  return "SELECT * FROM usuop u LEFT JOIN op_$mod o ON u.usuo_form=o.opcForm WHERE u.usuo_usu='$usuCod' AND u.usuo_stat=1 AND u.usuo_mod='$mod' ORDER BY o.opcForm ASC";
}

# EJECUCION DE QUERYS
$dbOpc = new dbExec();
$fa["usuarios"] = $dbOpc->sFetchAssoc($sUsuarios);
$s["modulos"] = $dbOpc->query($sMod);
$s["op_usu"] = $dbOpc->query($sOpcUsu);
#$dbOpc->close();

$func = new functions();

while ($recMod = $dbOpc->fetchAssoc($s['modulos'])) {
  $modCod = $recMod['modCod'];

  if ($fa['usuarios'][$recMod['modCampo']]) {
    $mod[$modCod]=array(
      1=>'',
      2=>'',
      3=>'',
      4=>''
    );

    $s["op"] = $dbOpc->query(sOp($modCod));
    while ($rec = $dbOpc->fetchAssoc($s['op'])) {
      $form = $rec['opcForm'];
      $ico = $rec['opcIco'];
      $nom = utf8_encode($rec['opcNom']);

      switch ($form[3]) {
        case '1':
          $mod[$modCod][1] .= $func->htmlOpcA($form, $ico, $nom, $modCod.'1');
          break;

        case '2':
          $mod[$modCod][2] .= $func->htmlOpcA($form, $ico, $nom, $modCod.'2');
          break;
          
        case '3':
          $mod[$modCod][3] .= $func->htmlOpcA($form, $ico, $nom, $modCod.'3');
          break;

        default:
          $mod[$modCod][4] .= $func->htmlOpcA($form, $ico, $nom, $modCod.'4');
          break;
      }
    }
  }
}

$mod["usu"][1]="";
while ($rec = $dbOpc->fetchAssoc($s['op_usu'])) {
  $form = $rec['opcForm'];
  $ico = $rec['opcIco'];
  $nom = $rec['opcNom'];

  $mod["usu"][1] .= $func->htmlOpcA($form, $ico, $nom);
}
?>
</script>
