Add new files and make code improvements
This commit is contained in:
252
rest/materias.php
Normal file
252
rest/materias.php
Normal file
@@ -0,0 +1,252 @@
|
||||
<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>
|
||||
Reference in New Issue
Block a user