123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- <?
- #input $_GET['id_espacio_sgu']
- define("INFORMATION", [
- 'POST' => [
- 'profesor_id',
- 'horario_id',
- 'estado',
- 'comentario',
- 'supervisor_id',
- ],
- ]);
- #output rutas: [ ...ruta, salones: [{...salon}] ]
- header('Content-Type: application/json charset=utf-8');
- #return html
- $ruta = "../";
- require_once "../class/c_login.php";
- // check method
- try {
- if ($_SERVER['REQUEST_METHOD'] === 'POST') {
- // check parameters
- $raw = file_get_contents('php://input');
- $post_data = json_decode($raw, true);
- // if it's a list
- // step 1: get subrutas
- if (empty($post_data)) {
- http_response_code(400);
- echo json_encode(['error' => 'No hay clases pendientes']);
- exit;
- }
- $data = $db->query(
- 'INSERT INTO registro (profesor_id, horario_id, registro_fecha_supervisor, estado_supervisor_id, registro_fecha_ideal, supervisor_id, comentario)
- VALUES' .
- 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))
- . ' 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
- RETURNING *'
- );
- echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
- } else {
- http_response_code(405);
- echo json_encode(['error' => 'method not allowed']);
- exit;
- }
- } catch (PDOException $th) {
- http_response_code(500);
- echo json_encode([
- 'error' => $th->getMessage(),
- 'query' => $db->getLastQuery(),
- 'post_data' => $post_data,
- ], JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
- exit;
- } catch (Exception $th) {
- http_response_code(500);
- echo json_encode([
- 'error' => $th->getMessage(),
- ], JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
- exit;
- }
|