<?php
// Using isset to safely check for variables before extraction
$request_vars = array_merge($_GET ?? [], $_POST ?? [], $_REQUEST ?? []);
$g_vars = [];
$p_vars = [];

// Safer extraction with prefixes
foreach ($request_vars as $key => $value) {
    $g_vars["G_$key"] = $value;
    $p_vars["P_$key"] = $value;
}

// Extract with defined variables instead of direct extraction
extract($g_vars);
extract($p_vars);

include_once "utils_database.php";
include_once "utils.php";
require_once "session_check.php";

// Ensure $G_opc is defined
$opc = $G_opc ?? null;
?>
<!DOCTYPE html>
<html lang="es">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="">
    <meta name="author" content="">
    <title>Panamtrauma 2025</title>
    <link rel="stylesheet" href="../css/font-awesome.min.css">
    <link rel="stylesheet" href="../css/bootstrap.min.css">
    <link rel="stylesheet" href="../css/style.css">
    <link href='http://fonts.googleapis.com/css?family=Open+Sans:600italic,400,800,700,300' rel='stylesheet' type='text/css'>
    <link href='http://fonts.googleapis.com/css?family=BenchNine:300,400,700' rel='stylesheet' type='text/css'>
    <script src="../js/modernizr.js"></script>
    <link href="../css/default.css" rel="stylesheet" type="text/css" />
 
<script>
   function areas(vFormulario) {
      with (document.forms[vFormulario]) {  
          var ValorGrupo = grupo[grupo.selectedIndex].value; 
          var n = area.length;  
          
          area.disabled = false;  
          
          // Clear existing options
          while (area.options.length > 0) {
              area.remove(0);
          }
          
          if (ValorGrupo != 'null') {  
<?php
            $vGrupos = GetFile("tgrupoarea", "", "codigo");
            if ($vGrupos) {
                while ($vGrupo = mysqli_fetch_assoc($vGrupos)) {
?>
                    if (ValorGrupo == '<?php echo htmlspecialchars($vGrupo['codigo'], ENT_QUOTES); ?>') {
<?php
                        $vAreas = GetFile("tarea", "cod_grupo='" . mysqli_real_escape_string($GLOBALS['conn'] ?? null, $vGrupo['codigo']) . "'", "descripcion");
                        if ($vAreas) {
                            while ($vArea = mysqli_fetch_assoc($vAreas)) {
?>
                                area.options[area.options.length] = new Option("<?php echo htmlspecialchars($vArea['descripcion'], ENT_QUOTES); ?>", '<?php echo htmlspecialchars($vArea['codigo'], ENT_QUOTES); ?>');
<?php
                            }
                            mysqli_free_result($vAreas);
                        }
?>
                    }
<?php
                }
                mysqli_free_result($vGrupos);
            }
?>
                area.focus();  
          } else {
                area.disabled = true;  
                grupo.focus();  
          }
          area.selectedIndex = 0;
      }
   }
</script>
<noscript>
    <img src="images/nojavascript.png" alt="Javascript" />
</noscript>
    
    <!--[if lt IE 9]>
      <script src="../js/html5shiv.js"></script>
      <script src="../js/respond.min.js"></script>
    <![endif]-->
</head>
<body>
    
<?php 
    $Var = transfor($opc ?? '') . ".php";
    if (file_exists($Var)) {
        include_once($Var);
    } else {
        echo "<p>Page not found.</p>";
    }
?>

<footer class="footer clearfix">
    <div class="container">
        <div class="row">
            <div class="col-xs-6 footer-para">
                <p>&copy;Contactos SAS All right reserved</p>
            </div>
            <div class="col-xs-6 text-right">
                <a href="https://www.facebook.com/contactossas/"><i class="fa fa-facebook"></i></a>
                <a href="https://twitter.com/ContactosSAS"><i class="fa fa-twitter"></i></a>
                <a href="skype:contactos.sistemas?call"><i class="fa fa-skype"></i></a>
            </div>
        </div>
    </div>
</footer>
</body>
</html>