registro_supervisor.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?
  2. #input $_GET['id_espacio_sgu']
  3. define("INFORMATION", [
  4. 'POST' => [
  5. 'profesor_id',
  6. 'horario_id',
  7. 'estado',
  8. 'comentario',
  9. 'supervisor_id',
  10. ],
  11. ]);
  12. #output rutas: [ ...ruta, salones: [{...salon}] ]
  13. header('Content-Type: application/json charset=utf-8');
  14. #return html
  15. $ruta = "../";
  16. require_once "../class/c_login.php";
  17. // check method
  18. try {
  19. if ($_SERVER['REQUEST_METHOD'] === 'POST') {
  20. // check parameters
  21. $raw = file_get_contents('php://input');
  22. $post_data = json_decode($raw, true);
  23. // if it's a list
  24. // step 1: get subrutas
  25. if (empty($post_data)) {
  26. http_response_code(400);
  27. echo json_encode(['error' => 'No hay clases pendientes']);
  28. exit;
  29. }
  30. $data = $db->query(
  31. 'INSERT INTO registro (profesor_id, horario_id, registro_fecha_supervisor, estado_supervisor_id, registro_fecha_ideal, supervisor_id, comentario)
  32. VALUES' .
  33. implode(',', array_map(fn($x) => "({$x['profesor_id']} , {$x['horario_id']}, NOW()," . (is_null($x['estado']) ? 'null' : $x['estado']) . ", NOW(), {$x['supervisor_id']}," . (empty($x['comentario']) ? 'null' : "'{$x['comentario']}'") . ')', $post_data))
  34. . ' ON CONFLICT (profesor_id, horario_id, registro_fecha_ideal) DO UPDATE SET estado_supervisor_id = EXCLUDED.estado_supervisor_id, registro_fecha_supervisor = NOW(), comentario = EXCLUDED.comentario, supervisor_id = EXCLUDED.supervisor_id
  35. RETURNING *'
  36. );
  37. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  38. } else {
  39. http_response_code(405);
  40. echo json_encode(['error' => 'method not allowed']);
  41. exit;
  42. }
  43. } catch (PDOException $th) {
  44. http_response_code(500);
  45. echo json_encode([
  46. 'error' => $th->getMessage(),
  47. 'query' => $db->getLastQuery(),
  48. 'post_data' => $post_data,
  49. ], JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  50. exit;
  51. } catch (Exception $th) {
  52. http_response_code(500);
  53. echo json_encode([
  54. 'error' => $th->getMessage(),
  55. ], JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  56. exit;
  57. }