diff --git a/action/action_auditoria.php b/action/action_auditoria.php index 2a31bcf..fdbe8dd 100644 --- a/action/action_auditoria.php +++ b/action/action_auditoria.php @@ -2,29 +2,24 @@ #input $_GET['id_espacio_sgu'] #output rutas: [ ...ruta, salones: [{...salon}] ] header('Content-Type: application/json charset=utf-8'); -$information = [ - 'GET' => [ - #'periodo_id', - ], -]; +ini_set('display_errors', 1); +ini_set('display_startup_errors', 1); +error_reporting(E_ALL); + $ruta = "../"; -require_once "../class/c_login.php"; +require_once $ruta . "class/c_login.php"; +if (!isset($_SESSION['user'])) { + http_response_code(401); + die(json_encode(['error' => 'unauthorized'])); +} +$user = unserialize($_SESSION['user']); + // check method try { - - if ($_SERVER['REQUEST_METHOD'] === 'GET') { - array_walk($information['GET'], function ($value) { - if (!array_key_exists($value, $_GET)) { - http_response_code(400); - echo json_encode(['error' => "$value is required"]); - exit; - } - }); - $data = $db->query( "WITH horarios AS ( - SELECT * FROM horario_view WHERE (periodo_id, facultad_id) = (:periodo_id, :facultad_id) + SELECT * FROM horario_view WHERE (periodo_id, facultad_id) = (:periodo_id, COALESCE(:facultad_id, facultad_id)) ), fechas AS ( SELECT fechas_clase(h.horario_id) as registro_fecha_ideal, h.horario_id @@ -37,10 +32,11 @@ try { JOIN profesor using (profesor_id) LEFT JOIN registro USING (horario_id, registro_fecha_ideal, profesor_id) left join estado_supervisor using (estado_supervisor_id) - LEFT JOIN USUARIO ON USUARIO.usuario_id = REGISTRO.supervisor_id", + LEFT JOIN USUARIO ON USUARIO.usuario_id = REGISTRO.supervisor_id + ORDER BY fechas.registro_fecha_ideal DESC, horarios.horario_id, profesor_nombre", [ - ':periodo_id' => $_GET['periodo_id'], - ':facultad_id' => $_GET['facultad_id'], + ':periodo_id' => $user->periodo_id, + ':facultad_id' => $user->facultad['facultad_id'], ] ); @@ -53,9 +49,7 @@ try { http_response_code(405); echo json_encode(['error' => 'method not allowed']); exit; - } - } catch (PDOException $th) { http_response_code(500); echo json_encode([ diff --git a/action/action_periodousuario_update.php b/action/action_periodousuario_update.php index 279b774..f02e8c7 100644 --- a/action/action_periodousuario_update.php +++ b/action/action_periodousuario_update.php @@ -9,19 +9,10 @@ if (!isset($_SESSION['user'])) { $user = unserialize($_SESSION['user']); $params = array(':id' => $user->user['id'], ':per' => $_POST['id']); -$user->print_to_log('Actualizando periodo from ' . $user->periodo . ' to ' . $_POST['id']); +$user->print_to_log('Actualizando periodo from ' . $user->periodo_id . ' to ' . $_POST['id']); query("SELECT FU_UPDATEPERIODO(:id, :per)", $params); -$user->periodo = $params[':per']; - -# if the user is admin, also update the facultad in user object -if ($user->admin) { - $facultad = query("SELECT FACULTAD_ID id, FACULTAD f FROM FS_PERIODO WHERE ID = :id", [':id' => $user->periodo]); - $user->facultad = array( - 'facultad_id' => $facultad["id"], - 'facultad' => $facultad["f"], - ); -} +$user->periodo_id = $params[':per']; $_SESSION['user'] = serialize($user); header("Location: {$_POST["target"]}"); diff --git a/action/periodo_datos.php b/action/periodo_datos.php new file mode 100644 index 0000000..7da8339 --- /dev/null +++ b/action/periodo_datos.php @@ -0,0 +1,44 @@ + +#input $_GET['id_espacio_sgu'] +#output rutas: [ ...ruta, salones: [{...salon}] ] +header('Content-Type: application/json charset=utf-8'); +ini_set('display_errors', 1); +ini_set('display_startup_errors', 1); +error_reporting(E_ALL); + +$ruta = "../"; +require_once $ruta . "class/c_login.php"; + +if (!isset($_SESSION['user'])) { + http_response_code(401); + die(json_encode(['error' => 'unauthorized'])); +} +$user = unserialize($_SESSION['user']); +// check method +if ($_SERVER['REQUEST_METHOD'] !== 'GET') { + http_response_code(405); + die(json_encode(['error' => 'method not allowed'])); +} + +const JSON_OPTIONS = JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_PARTIAL_OUTPUT_ON_ERROR; +try { + $data = $db->querySingle("SELECT *, LEAST(periodo_fecha_fin, CURRENT_DATE) as fecha_final FROM periodo WHERE periodo_id = ?", array($user->periodo_id)); + $last_query = [ + 'query' => $db->getLastQuery(), + ]; + + echo json_encode($data, JSON_OPTIONS); +} catch (PDOException $th) { + http_response_code(500); + echo json_encode([ + 'error' => $th->getMessage(), + 'query' => $db->getLastQuery(), + ], JSON_OPTIONS); + exit; +} catch (Exception $th) { + http_response_code(500); + echo json_encode([ + 'error' => $th->getMessage(), + ], JSON_OPTIONS); + exit; +} \ No newline at end of file diff --git a/alta_de_horario.php b/alta_de_horario.php index 82e9116..4c88fdc 100644 --- a/alta_de_horario.php +++ b/alta_de_horario.php @@ -41,7 +41,7 @@ $user->print_to_log('Consultar: Alta de horario');