'No se ha iniciado sesión']); exit(); } $user = Login::get_user(); try { switch ($_SERVER['REQUEST_METHOD']) { case 'POST': // check parameters $raw = file_get_contents('php://input'); $post_data = json_decode($raw, true); $data = $db->querySingle( 'WITH HORARIOS AS ( SELECT * FROM horario JOIN horario_profesor USING (horario_id) WHERE horario.periodo_id = :periodo_id ) INSERT INTO registro (profesor_id, horario_id, registro_fecha_ideal, registro_justificada, justificador_id, registro_fecha_justificacion, justificacion) VALUES (:profesor_id, :horario_id, :registro_fecha_ideal, :registro_justificada, :justificador_id, NOW(), :justificacion) ON CONFLICT (profesor_id, horario_id, registro_fecha_ideal) DO UPDATE SET registro_justificada = :registro_justificada, justificador_id = :justificador_id, registro_fecha_justificacion = NOW(), justificacion = :justificacion RETURNING *', array( 'periodo_id' => $user->periodo_id, 'profesor_id' => $post_data['profesor_id'], 'horario_id' => $post_data['horario_id'], 'registro_fecha_ideal' => $post_data['registro_fecha_ideal'], 'registro_justificada' => $post_data['registro_justificada'], 'justificador_id' => $user->user['id'], 'justificacion' => empty($post_data['justificacion']) ? null : $post_data['justificacion'], ) ); $data_justificador = $db->querySingle( "SELECT justificador.usuario_nombre as justificador_nombre, justificador.usuario_clave as justificador_clave, facultad.facultad_nombre as justificador_facultad, rol.rol_titulo as justificador_rol FROM USUARIO JUSTIFICADOR JOIN ROL on ROL.rol_id = justificador.rol_id LEFT JOIN facultad on facultad.facultad_id = justificador.facultad_id where justificador.usuario_id = :justificador_id", array( 'justificador_id' => $user->user['id'], ) ); // exit('exit'); echo json_encode(array_merge($data, $data_justificador), JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT); break; default: header('HTTP/1.1 405 Method Not Allowed'); echo json_encode(['error' => 'Método no permitido']); } } catch (PDOException $e) { echo json_encode([ 'error' => $e->getMessage(), 'query' => $db->getLastQuery(), 'exception' => $e->getTraceAsString() ]); } catch (Exception $e) { echo json_encode([ 'error' => $e->getMessage(), 'exception' => $e->getTraceAsString() ]); }