1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- <?
- header('Content-Type: application/json charset=utf-8');
- #return html
- $ruta = "../";
- require_once "../class/c_login.php";
- // check method
- if (!isset($_SESSION['user'])) {
- http_response_code(401);
- echo json_encode(['error' => 'unauthorized']);
- exit;
- }
- $user = unserialize($_SESSION['user']);
- try {
- if ($_SERVER['REQUEST_METHOD'] === 'PUT') {
- // 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->querySingle(
- '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(
- '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'],
- )
- );
- echo json_encode(array_merge($data, $data_justificador), 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;
- }
|