salon.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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. .json-container {
  35. white-space: pre-wrap;
  36. /* Since JSON is formatted with whitespace, this will keep formatting */
  37. word-break: break-word;
  38. /* To prevent horizontal scrolling */
  39. max-height: 150px;
  40. /* Set a max-height and add scroll to prevent very long JSON from cluttering the table */
  41. overflow-y: auto;
  42. }
  43. .empty {
  44. /* rosa pastel */
  45. background-color: #ffe8f4;
  46. }
  47. .no-igual {
  48. /* púrpura pastel */
  49. background-color: #f4e8ff;
  50. }
  51. </style>
  52. <?php
  53. /*
  54. idPeriodo: identificador del periodo a consultar (obligatorio, número entero)
  55. claveFacultad: clave de la facultad a consultar (opcional, cadena)
  56. claveCarrera: clave de la carrera a consultar (opcional, cadena)
  57. claveProfesor: clave del empleado a consultar (opcional, cadena)
  58. fecha: fecha de la clase (opcional, cadena en formato yyyy-MM-dd)
  59. */
  60. ini_set('display_errors', 1);
  61. ini_set('display_startup_errors', 1);
  62. ini_set('post_max_size', 1);
  63. ini_set('max_execution_time', 8 * 60);
  64. error_reporting(E_ALL);
  65. date_default_timezone_set('America/Mexico_City');
  66. $ruta = "../";
  67. $ruta_superior = dirname(__DIR__);
  68. require_once $ruta_superior . "/include/bd_pdo.php";
  69. require_once __DIR__ . "/token.php";
  70. require_once __DIR__ . "/LogCambios.php";
  71. $salon = array();
  72. $curl = curl_init();
  73. curl_setopt_array($curl, [
  74. CURLOPT_URL =>
  75. 'https://portal.ulsa.edu.mx/servicios/AuditoriaAsistencialRest/AuditoriaAsistencialService.svc/auditoriaAsistencial/catalogos/espacios/seleccionar',
  76. CURLOPT_RETURNTRANSFER => true,
  77. CURLOPT_POSTFIELDS => json_encode([]),
  78. CURLOPT_HTTPHEADER => [
  79. "token: $token",
  80. 'username: SGU_APSA_AUD_ASIST',
  81. 'Content-Type: application/json',
  82. ],
  83. ]);
  84. $response = curl_exec($curl);
  85. $err = curl_error($curl);
  86. curl_close($curl);
  87. $json_flags = JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT;
  88. $salones = json_decode($response, true, 512, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
  89. ?>
  90. <main>
  91. <p>
  92. <?= count($salones) ?> salones encontrados
  93. </p>
  94. <table>
  95. <thead>
  96. <tr>
  97. <th>Salones en SGU</th>
  98. <th>SALONES en Postgres</th>
  99. </tr>
  100. </thead>
  101. <tbody>
  102. <?php
  103. foreach ($salones as $salon) {
  104. $salon_db = $db->where("id_espacio_sgu", $salon["IdEspacio"])->get("salon");
  105. // si de el salon es igual NombreEspacio == salon
  106. $vacío = empty($salon_db);
  107. $igual = $salon["NombreEspacio"] == ($salon["salon"] ?? "");
  108. if ($vacío) {
  109. $db->insert("salon", [
  110. "id_espacio_sgu" => $salon["IdEspacio"],
  111. "salon" => $salon["NombreEspacio"],
  112. "id_espacio_padre" => $salon["IdEspacioPadre"] > 0 ? $salon["IdEspacioPadre"] : null,
  113. ]);
  114. } else if (!$igual) {
  115. $db->where("id_espacio_sgu", $salon["IdEspacio"])->update("salon", [
  116. "salon" => $salon["NombreEspacio"],
  117. // "id_espacio_padre" => $salon["IdEspacioPadre"] > 0 ? $salon["IdEspacioPadre"] : null,
  118. ]);
  119. }
  120. ?>
  121. <tr class="<?= $igual ? "empty" : "no-igual" ?>">
  122. <td class="json-container">
  123. <?= json_encode($salon, $json_flags) ?>
  124. </td>
  125. <td class="json-container">
  126. <?= json_encode($salon_db, $json_flags) ?>
  127. </td>
  128. </tr>
  129. <?php } ?>
  130. </tbody>
  131. </table>
  132. </main>