123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252 |
- <style>
- details {
- border: 1px solid #aaa;
- border-radius: 4px;
- padding: 0.5em 0.5em 0;
- margin: 0.5em 0;
- }
- summary {
- font-weight: bold;
- margin: -0.5em -0.5em 0;
- padding: 0.5em;
- }
- details[open] {
- padding: 0.5em;
- }
- details[open] summary {
- border-bottom: 1px solid #aaa;
- margin-bottom: 0.5em;
- }
- table {
- width: 100%;
- border-collapse: collapse;
- margin: 20px 0;
- }
- th,
- td {
- padding: 8px;
- border: 1px solid #ccc;
- text-align: left;
- }
- th {
- background-color: #f2f2f2;
- }
- tr:nth-child(even):not(.empty):not(.area-comun) {
- background-color: #f9f9f9;
- }
- .json-container {
- white-space: pre-wrap;
- /* Since JSON is formatted with whitespace, this will keep formatting */
- word-break: break-word;
- /* To prevent horizontal scrolling */
- max-height: 150px;
- /* Set a max-height and add scroll to prevent very long JSON from cluttering the table */
- overflow-y: auto;
- }
- .empty {
- /* rosa pastel */
- background-color: #ffe8f4;
- }
- .area-comun {
- /* naranja pastel */
- background-color: #ffe9d4;
- }
- </style>
- <?php
- /*
- idPeriodo: identificador del periodo a consultar (obligatorio, número entero)
- claveFacultad: clave de la facultad a consultar (opcional, cadena)
- claveCarrera: clave de la carrera a consultar (opcional, cadena)
- claveProfesor: clave del empleado a consultar (opcional, cadena)
- fecha: fecha de la clase (opcional, cadena en formato yyyy-MM-dd)
- */
- ini_set('display_errors', 1);
- ini_set('display_startup_errors', 1);
- ini_set('post_max_size', 1);
- ini_set('max_execution_time', 8 * 60);
- error_reporting(E_ALL);
- date_default_timezone_set('America/Mexico_City');
- $ruta = "../";
- $ruta_superior = dirname(__DIR__);
- require_once $ruta_superior . "/include/bd_pdo.php";
- require_once __DIR__ . "/token.php";
- require_once __DIR__ . "/LogCambios.php";
- $fecha = isset($_GET["fecha"]) ? $_GET["fecha"] : date("Y-m-d");
- $periodos = $db
- ->where("id_periodo_sgu", 0, ">")
- ->where("periodo_fecha_inicio", $fecha, "<=")
- ->where("periodo_fecha_fin", $fecha, ">=")
- ->orderBy("periodo_id")
- ->get("periodo");
- ?>
- <nav>
- <form action="" method="get">
- <label for="fecha">Fecha</label>
- <input type="date" name="fecha" id="fecha" value="<?= $fecha ?>">
- <button type="submit">Buscar</button>
- </form>
- <details>
- <summary>Periodos</summary>
- <pre>
- <code><?= json_encode($periodos, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) ?></code>
- </pre>
- </details>
- <?php
- $horarios = array();
- foreach (array_column($periodos, "id_periodo_sgu") as $idPeriodo) {
- $curl = curl_init();
- $params = array(
- 'idPeriodo' => $idPeriodo,
- 'fecha' => $fecha,
- );
- curl_setopt_array($curl, [
- CURLOPT_URL => 'https://portal.ulsa.edu.mx/servicios/AuditoriaAsistencialRest/AuditoriaAsistencialService.svc/auditoriaAsistencial/seleccionar',
- CURLOPT_RETURNTRANSFER => true,
- CURLOPT_POSTFIELDS => json_encode($params),
- CURLOPT_HTTPHEADER => [
- "token: $token",
- 'username: SGU_APSA_AUD_ASIST',
- 'Content-Type: application/json',
- ],
- ]);
- $response = curl_exec($curl);
- $err = curl_error($curl);
- curl_close($curl);
- $response = json_decode($response, true, 512, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
- $horarios = array_merge($horarios, $response);
- ?>
- <details>
- <summary>Periodo
- <?= $idPeriodo ?>
- </summary>
- <pre><code><?= json_encode($response, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) ?></code></pre>
- </details>
- <?php } ?>
- </nav>
- <main>
- <p>
- <?= count($horarios) ?> horarios encontrados para
- <?= $fecha ?>
- </p>
- <table>
- <thead>
- <tr>
- <th>Materia en SGU</th>
- <th>Materia en Postgres</th>
- </tr>
- </thead>
- <tbody>
- <?php
- // $horarios with unique "NombreMateria" field
- $horarios = array_map("unserialize", array_unique(array_map("serialize", $horarios)));
- foreach ($horarios as $horario) {
- $materias = $db
- ->where("materia_nombre", trim($horario["NombreMateria"]), "ILIKE")
- ->join("carrera", "carrera.carrera_id = materia.carrera_id")
- ->join("facultad", "facultad.facultad_id = carrera.facultad_id")
- ->get("materia");
- if (
- count(array_filter($materias, fn($m) =>
- $m["clave_materia"] == trim($horario["ClaveMateria"]) and
- $m["clave_carrera"] == trim($horario["ClaveCarrera"]))) > 0
- ) {
- continue;
- }
- // si de las materias alguna tiene carrera_id entre 1 y 4 entonces es de área común
- $area_comun = count(array_filter($materias, fn($m) => $m["carrera_id"] >= 1 and $m["carrera_id"] <= 4)) > 0;
- $vacío = count($materias) == 0;
- ?>
- <!-- si es vacío ponle la clase empty y si es área común ponle la clase area-comun -->
- <tr class="<?= $vacío ? "empty" : "" ?> <?= $area_comun ? "area-comun" : "" ?>">
- <td class="json-container">
- <details>
- <summary>Horario</summary>
- <pre><code><?= json_encode($horario, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) ?></code></pre>
- </details>
- <?= json_encode(array_intersect_key($horario, array_flip(["ClaveMateria", "NombreMateria", "ClaveCarrera", "Dependencia"])), JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) ?>
- </td>
- <td class="json-container">
- <?php if ($vacío) { ?>
- <p>No se encontraron materias</p>
- <?php } else { ?>
- <details>
- <summary>Materias</summary>
- <pre><code><?= json_encode($materias, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) ?></code></pre>
- </details>
- <table>
- <thead>
- <tr>
- <th>Materia</th>
- <th>Carrera</th>
- <th>Facultad</th>
- <th>Acciones</th>
- </tr>
- </thead>
- <tbody>
- <script>
- async function copiar_seleccionados() {
- // en mi clipboard quiero (join con ,)
- const materias_seleccionadas = Array.from(document.querySelectorAll("input[name='materia_id']:checked"))
- .map(input => input.value)
- .join(",");
- // copiar al clipboard
- await navigator.clipboard.writeText(materias_seleccionadas);
- // mostrar mensaje de éxito
- alert("Copiado al portapapeles");
- }
- </script>
- <?php foreach ($materias as $materia) { ?>
- <tr>
- <td>
- <input type="checkbox" name="materia_id" id="materia_id"
- value="<?= $materia["materia_id"] ?>">
- </td>
- <td>
- <?= $materia["materia_id"] ?>
- <small>
- (
- <?= $materia["clave_materia"] ?>)
- </small>
- <?= $materia["materia_nombre"] ?>
- </td>
- <td>
- <small>
- (
- <?= $materia["clave_carrera"] ?>)
- </small>
- <?= $materia["carrera_nombre"] ?>
- </td>
- <td>
- <small>
- (
- <?= $materia["clave_dependencia"] ?>)
- </small>
- <?= $materia["facultad_nombre"] ?>
- </td>
- </tr>
- <?php } ?>
- </tbody>
- </table>
- <?php } ?>
- </td>
- </tr>
- <?php } ?>
- </tbody>
- </table>
- </main>
|