materias.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. <style>
  2. details {
  3. border: 1px solid #aaa;
  4. border-radius: 4px;
  5. padding: 0.5em 0.5em 0;
  6. margin: 0.5em 0;
  7. }
  8. summary {
  9. font-weight: bold;
  10. margin: -0.5em -0.5em 0;
  11. padding: 0.5em;
  12. }
  13. details[open] {
  14. padding: 0.5em;
  15. }
  16. details[open] summary {
  17. border-bottom: 1px solid #aaa;
  18. margin-bottom: 0.5em;
  19. }
  20. table {
  21. width: 100%;
  22. border-collapse: collapse;
  23. margin: 20px 0;
  24. }
  25. th,
  26. td {
  27. padding: 8px;
  28. border: 1px solid #ccc;
  29. text-align: left;
  30. }
  31. th {
  32. background-color: #f2f2f2;
  33. }
  34. tr:nth-child(even):not(.empty):not(.area-comun) {
  35. background-color: #f9f9f9;
  36. }
  37. .json-container {
  38. white-space: pre-wrap;
  39. /* Since JSON is formatted with whitespace, this will keep formatting */
  40. word-break: break-word;
  41. /* To prevent horizontal scrolling */
  42. max-height: 150px;
  43. /* Set a max-height and add scroll to prevent very long JSON from cluttering the table */
  44. overflow-y: auto;
  45. }
  46. .empty {
  47. /* rosa pastel */
  48. background-color: #ffe8f4;
  49. }
  50. .area-comun {
  51. /* naranja pastel */
  52. background-color: #ffe9d4;
  53. }
  54. </style>
  55. <?php
  56. /*
  57. idPeriodo: identificador del periodo a consultar (obligatorio, número entero)
  58. claveFacultad: clave de la facultad a consultar (opcional, cadena)
  59. claveCarrera: clave de la carrera a consultar (opcional, cadena)
  60. claveProfesor: clave del empleado a consultar (opcional, cadena)
  61. fecha: fecha de la clase (opcional, cadena en formato yyyy-MM-dd)
  62. */
  63. ini_set('display_errors', 1);
  64. ini_set('display_startup_errors', 1);
  65. ini_set('post_max_size', 1);
  66. ini_set('max_execution_time', 8 * 60);
  67. error_reporting(E_ALL);
  68. date_default_timezone_set('America/Mexico_City');
  69. $ruta = "../";
  70. $ruta_superior = dirname(__DIR__);
  71. require_once $ruta_superior . "/include/bd_pdo.php";
  72. require_once __DIR__ . "/token.php";
  73. require_once __DIR__ . "/LogCambios.php";
  74. $fecha = isset($_GET["fecha"]) ? $_GET["fecha"] : date("Y-m-d");
  75. $periodos = $db
  76. ->where("id_periodo_sgu", 0, ">")
  77. ->where("periodo_fecha_inicio", $fecha, "<=")
  78. ->where("periodo_fecha_fin", $fecha, ">=")
  79. ->orderBy("periodo_id")
  80. ->get("periodo");
  81. ?>
  82. <nav>
  83. <form action="" method="get">
  84. <label for="fecha">Fecha</label>
  85. <input type="date" name="fecha" id="fecha" value="<?= $fecha ?>">
  86. <button type="submit">Buscar</button>
  87. </form>
  88. <details>
  89. <summary>Periodos</summary>
  90. <pre>
  91. <code><?= json_encode($periodos, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) ?></code>
  92. </pre>
  93. </details>
  94. <?php
  95. $horarios = array();
  96. foreach (array_column($periodos, "id_periodo_sgu") as $idPeriodo) {
  97. $curl = curl_init();
  98. $params = array(
  99. 'idPeriodo' => $idPeriodo,
  100. 'fecha' => $fecha,
  101. );
  102. curl_setopt_array($curl, [
  103. CURLOPT_URL => 'https://portal.ulsa.edu.mx/servicios/AuditoriaAsistencialRest/AuditoriaAsistencialService.svc/auditoriaAsistencial/seleccionar',
  104. CURLOPT_RETURNTRANSFER => true,
  105. CURLOPT_POSTFIELDS => json_encode($params),
  106. CURLOPT_HTTPHEADER => [
  107. "token: $token",
  108. 'username: SGU_APSA_AUD_ASIST',
  109. 'Content-Type: application/json',
  110. ],
  111. ]);
  112. $response = curl_exec($curl);
  113. $err = curl_error($curl);
  114. curl_close($curl);
  115. $response = json_decode($response, true, 512, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
  116. $horarios = array_merge($horarios, $response);
  117. ?>
  118. <details>
  119. <summary>Periodo
  120. <?= $idPeriodo ?>
  121. </summary>
  122. <pre><code><?= json_encode($response, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) ?></code></pre>
  123. </details>
  124. <?php } ?>
  125. </nav>
  126. <main>
  127. <p>
  128. <?= count($horarios) ?> horarios encontrados para
  129. <?= $fecha ?>
  130. </p>
  131. <table>
  132. <thead>
  133. <tr>
  134. <th>Materia en SGU</th>
  135. <th>Materia en Postgres</th>
  136. </tr>
  137. </thead>
  138. <tbody>
  139. <?php
  140. // $horarios with unique "NombreMateria" field
  141. $horarios = array_map("unserialize", array_unique(array_map("serialize", $horarios)));
  142. foreach ($horarios as $horario) {
  143. $materias = $db
  144. ->where("materia_nombre", trim($horario["NombreMateria"]), "ILIKE")
  145. ->join("carrera", "carrera.carrera_id = materia.carrera_id")
  146. ->join("facultad", "facultad.facultad_id = carrera.facultad_id")
  147. ->get("materia");
  148. if (
  149. count(array_filter($materias, fn($m) =>
  150. $m["clave_materia"] == trim($horario["ClaveMateria"]) and
  151. $m["clave_carrera"] == trim($horario["ClaveCarrera"]))) > 0
  152. ) {
  153. continue;
  154. }
  155. // si de las materias alguna tiene carrera_id entre 1 y 4 entonces es de área común
  156. $area_comun = count(array_filter($materias, fn($m) => $m["carrera_id"] >= 1 and $m["carrera_id"] <= 4)) > 0;
  157. $vacío = count($materias) == 0;
  158. ?>
  159. <!-- si es vacío ponle la clase empty y si es área común ponle la clase area-comun -->
  160. <tr class="<?= $vacío ? "empty" : "" ?> <?= $area_comun ? "area-comun" : "" ?>">
  161. <td class="json-container">
  162. <details>
  163. <summary>Horario</summary>
  164. <pre><code><?= json_encode($horario, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) ?></code></pre>
  165. </details>
  166. <?= json_encode(array_intersect_key($horario, array_flip(["ClaveMateria", "NombreMateria", "ClaveCarrera", "Dependencia"])), JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) ?>
  167. </td>
  168. <td class="json-container">
  169. <?php if ($vacío) { ?>
  170. <p>No se encontraron materias</p>
  171. <?php } else { ?>
  172. <details>
  173. <summary>Materias</summary>
  174. <pre><code><?= json_encode($materias, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) ?></code></pre>
  175. </details>
  176. <table>
  177. <thead>
  178. <tr>
  179. <th>Materia</th>
  180. <th>Carrera</th>
  181. <th>Facultad</th>
  182. <th>Acciones</th>
  183. </tr>
  184. </thead>
  185. <tbody>
  186. <script>
  187. <<<<<<< HEAD
  188. async function borrarMateria(id) {
  189. const url = `https://paad.lci.ulsa.mx/postgrest/materia?materia_id=eq.${id}`;
  190. const options = {
  191. method: 'DELETE',
  192. };
  193. const response = await fetch(url, options)
  194. .then(response => response.json())
  195. console.log(`Materia borrada: ${id}`);
  196. =======
  197. async function copiar_seleccionados() {
  198. // en mi clipboard quiero (join con ,)
  199. const materias_seleccionadas = Array.from(document.querySelectorAll("input[name='materia_id']:checked"))
  200. .map(input => input.value)
  201. .join(",");
  202. // copiar al clipboard
  203. await navigator.clipboard.writeText(materias_seleccionadas);
  204. // mostrar mensaje de éxito
  205. alert("Copiado al portapapeles");
  206. >>>>>>> 7688f1aac1824c234bc5f19b154e9ad1f4808d4f
  207. }
  208. </script>
  209. <?php foreach ($materias as $materia) { ?>
  210. <tr>
  211. <td>
  212. <<<<<<< HEAD
  213. =======
  214. <input type="checkbox" name="materia_id" id="materia_id"
  215. value="<?= $materia["materia_id"] ?>">
  216. </td>
  217. <td>
  218. >>>>>>> 7688f1aac1824c234bc5f19b154e9ad1f4808d4f
  219. <?= $materia["materia_id"] ?>
  220. <small>
  221. (
  222. <?= $materia["clave_materia"] ?>)
  223. </small>
  224. <?= $materia["materia_nombre"] ?>
  225. </td>
  226. <td>
  227. <small>
  228. (
  229. <?= $materia["clave_carrera"] ?>)
  230. </small>
  231. <?= $materia["carrera_nombre"] ?>
  232. </td>
  233. <td>
  234. <small>
  235. (
  236. <?= $materia["clave_dependencia"] ?>)
  237. </small>
  238. <?= $materia["facultad_nombre"] ?>
  239. </td>
  240. <<<<<<< HEAD
  241. <td>
  242. <button
  243. onclick="borrarMateria(<?= $materia['materia_id'] ?>)">Borrar</button>
  244. <button>Editar</button>
  245. </td>
  246. =======
  247. >>>>>>> 7688f1aac1824c234bc5f19b154e9ad1f4808d4f
  248. </tr>
  249. <?php } ?>
  250. </tbody>
  251. </table>
  252. <?php } ?>
  253. </td>
  254. </tr>
  255. <?php } ?>
  256. </tbody>
  257. </table>
  258. </main>