From 0ef9e2a1f4364ad9216a85d7d8899f76f5bcbe8e Mon Sep 17 00:00:00 2001 From: Alejandro Rosales Date: Fri, 22 Sep 2023 17:58:31 +0000 Subject: [PATCH] All --- action/action_auditoria.php | 2 + action/action_carreras.php | 16 +- action/avisos.php | 293 +++++++++++++++++++++++++++++++++ action/reposicion_insert.php | 7 +- action/reposicion_select.php | 17 +- action/reposicion_update.php | 90 ++++++----- auditoria.php | 3 +- avisos.php | 302 ++++++++++++++++++++++++++++++++++- class/c_login.php | 14 +- include/bd_pdo.php | 6 +- js/avisos.js | 147 ++++++++++++++++- js/datalist.js | 3 + package-lock.json | 46 +++--- package.json | 2 +- reposiciones_autorizar.php | 169 +++++++++++++------- reposiciones_crear.php | 24 +-- ts/avisos.ts | 203 ++++++++++++++++++++++- ts/declaration.ts | 2 +- tsconfig.json | 2 +- 19 files changed, 1172 insertions(+), 176 deletions(-) create mode 100644 action/avisos.php diff --git a/action/action_auditoria.php b/action/action_auditoria.php index 1fab385..164048f 100644 --- a/action/action_auditoria.php +++ b/action/action_auditoria.php @@ -2,6 +2,8 @@ #input $_GET['id_espacio_sgu'] #output rutas: [ ...ruta, salones: [{...salon}] ] header('Content-Type: application/json charset=utf-8'); +ini_set('memory_limit', '256M'); +ini_set('post_max_size', '256M'); ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); diff --git a/action/action_carreras.php b/action/action_carreras.php index 8ce5109..658b3f6 100644 --- a/action/action_carreras.php +++ b/action/action_carreras.php @@ -12,13 +12,15 @@ $user = unserialize($_SESSION['user']); $ruta = "../"; require_once "../include/bd_pdo.php"; +$facultad_id = $user->facultad['facultad_id']; +$carreras = $db->query( + "SELECT * FROM carrera + WHERE + (facultad_id = :facultad_id OR :facultad_id IS NULL) + ORDER BY carrera_nombre DESC", + array('facultad_id' => $facultad_id) +); -$nivel = $db->where("id", $_POST['periodo'])->getOne("fs_periodo", "nivel_id"); -$carreras = $db - ->where("nivel", $nivel) - ->where("facultad", $_POST['facultad']) - ->get("fs_carrera", null, "id, carrera"); - -$user->print_to_log("Crea carrera", old: $_POST); +// $user->print_to_log("Crea carrera", old: $_POST); die(json_encode($carreras)); diff --git a/action/avisos.php b/action/avisos.php new file mode 100644 index 0000000..2a0b77a --- /dev/null +++ b/action/avisos.php @@ -0,0 +1,293 @@ + 'No se ha iniciado sesión')); + exit(); +} +$user = Login::get_user(); +try { + + switch ($_SERVER['REQUEST_METHOD']) { + case 'GET': + $facultad_id = $user->facultad['facultad_id']; + $avisos = $db->query( + "SELECT * FROM aviso + WHERE + (CURRENT_DATE BETWEEN aviso_fecha_inicial AND aviso_fecha_final) AND + (facultad_id = :facultad_id OR :facultad_id IS NULL) AND + aviso_estado + ORDER BY aviso_id DESC", + array('facultad_id' => $facultad_id) + ); + + /* + if (empty($avisos)) { + header('HTTP/1.1 404 Not Found'); + echo json_encode(array('error' => 'No hay avisos disponibles')); + exit(); + } + */ + + $avisos = array_map(fn($aviso) => array( + ...$aviso, + 'carreras' => $db->query( + "SELECT carrera_id, carrera_nombre FROM aviso_carrera + JOIN carrera USING (carrera_id) + WHERE aviso_id = :aviso_id", + array('aviso_id' => $aviso['aviso_id']) + ), + 'profesores' => $db->query( + "SELECT profesor_id, profesor_clave, profesor_nombre FROM aviso_profesor + JOIN profesor USING (profesor_id) + WHERE aviso_id = :aviso_id", + array('aviso_id' => $aviso['aviso_id']) + ), + ), $avisos); + echo json_encode($avisos); + break; + case 'POST': + $raw_input = file_get_contents('php://input'); + if (empty($raw_input)) { + header('HTTP/1.1 400 Bad Request'); + echo json_encode(array('error' => 'No se recibieron parámetros')); + exit(); + } + + $input_data = json_decode($raw_input); + if (json_last_error() !== JSON_ERROR_NONE) { + header('HTTP/1.1 400 Bad Request'); + echo json_encode(array('error' => 'Invalid JSON format')); + exit(); + } + + + $schema = <<validate($input_data, json_decode($schema)); + + if (!$validate->isValid()) { + header('HTTP/1.1 400 Bad Request'); + echo json_encode( + array( + 'error' => 'El formato de la solicitud es incorrecto', + 'success' => false, + 'errors' => $validate->getErrors() + ) + ); + exit(); + } + + $aviso_id = $db->insert( + 'aviso', + array( + 'aviso_fecha_inicial' => $input_data->aviso_fecha_inicial, + 'aviso_fecha_final' => $input_data->aviso_fecha_final, + 'aviso_texto' => $input_data->aviso_texto, + 'facultad_id' => $user->facultad['facultad_id'], + ), + 'aviso_id' + ); + + if (isset($input_data->carreras)) { + array_walk($input_data->carreras, fn($carrera_id) => $db->insert('aviso_carrera', array('aviso_id' => $aviso_id, 'carrera_id' => $carrera_id))); + } + if (isset($input_data->profesores)) { + array_walk($input_data->profesores, fn($profesor_id) => $db->insert('aviso_profesor', array('aviso_id' => $aviso_id, 'profesor_id' => $profesor_id))); + } + + echo json_encode( + array( + 'aviso_id' => $aviso_id, + 'msg' => 'Aviso creado exitosamente', + 'success' => true + ) + ); + break; + case 'PUT': + $raw_input = file_get_contents('php://input'); + if (empty($raw_input)) { + header('HTTP/1.1 400 Bad Request'); + echo json_encode(array('error' => 'No se recibieron parámetros')); + exit(); + } + + $input_data = json_decode($raw_input); + if (json_last_error() !== JSON_ERROR_NONE) { + header('HTTP/1.1 400 Bad Request'); + echo json_encode(array('error' => 'Invalid JSON format')); + exit(); + } + + $schema = <<validate($input_data, json_decode($schema)); + + if (!$validate->isValid()) { + header('HTTP/1.1 400 Bad Request'); + echo json_encode( + array( + 'error' => 'El formato de la solicitud es incorrecto', + 'errors' => $validate->getErrors(), + 'success' => false, + ) + ); + exit(); + } + + $db->where('aviso_id', $input_data->aviso_id) + ->update( + 'aviso', + array( + 'aviso_fecha_final' => $input_data->aviso_fecha_final, + ), + ); + + if (isset($input_data->carreras)) { + $db->where('aviso_id', $input_data->aviso_id)->delete('aviso_carrera'); + array_walk($input_data->carreras, fn($carrera_id) => $db->insert('aviso_carrera', array('aviso_id' => $input_data->aviso_id, 'carrera_id' => $carrera_id))); + } + + if (isset($input_data->profesores)) { + $db->where('aviso_id', $input_data->aviso_id)->delete('aviso_profesor'); + array_walk($input_data->profesores, fn($profesor_id) => $db->insert('aviso_profesor', array('aviso_id' => $input_data->aviso_id, 'profesor_id' => $profesor_id))); + } + + echo json_encode( + array( + 'msg' => 'Aviso actualizado exitosamente', + 'success' => true + ) + ); + break; + + case 'DELETE': + $raw_input = file_get_contents('php://input'); + if (empty($raw_input)) { + header('HTTP/1.1 400 Bad Request'); + echo json_encode(array('error' => 'No se recibieron parámetros')); + exit(); + } + + $input_data = json_decode($raw_input); + if (json_last_error() !== JSON_ERROR_NONE) { + header('HTTP/1.1 400 Bad Request'); + echo json_encode(array('error' => 'Invalid JSON format')); + exit(); + } + + $schema = <<validate($input_data, json_decode($schema)); + + if (!$validate->isValid()) { + header('HTTP/1.1 400 Bad Request'); + echo json_encode( + array( + 'error' => 'El formato de la solicitud es incorrecto', + 'errors' => $validate->getErrors(), + 'success' => false, + ) + ); + exit(); + } + + $result = $db->where('aviso_id', $input_data->aviso_id)->update('aviso', array('aviso_estado' => false)); + echo json_encode( + array( + 'msg' => 'Aviso eliminado exitosamente', + 'success' => true, + 'result' => $result + ) + ); + + break; + } +} catch (PDOException $e) { + echo json_encode( + array( + 'error' => $e->getMessage(), + 'query' => $db->getLastQuery(), + 'exception' => $e->getTraceAsString() + ) + ); +} \ No newline at end of file diff --git a/action/reposicion_insert.php b/action/reposicion_insert.php index a63d543..fdedcad 100644 --- a/action/reposicion_insert.php +++ b/action/reposicion_insert.php @@ -13,10 +13,9 @@ if (!isset($_SESSION['user'])) $user = unserialize($_SESSION['user']); //$user->access(); -$duracion_id = filter_input(INPUT_POST, "duracion", FILTER_SANITIZE_NUMBER_INT);//1 Repo , 0 Cambio -$bloque = filter_input(INPUT_POST, "bloque", FILTER_SANITIZE_NUMBER_INT);//1 Repo , 0 Cambio -$ciclo = filter_input(INPUT_POST, "ciclo", FILTER_SANITIZE_NUMBER_INT);//1 Repo , 0 Cambio -$fecha_falta = trim(htmlspecialchars($_POST["fecha_falta"], ENT_QUOTES, "UTF-8"));//limpia texto +$duracion_id = filter_input(INPUT_POST, "duracion", FILTER_SANITIZE_NUMBER_INT);//Id reposicion +$bloque = filter_input(INPUT_POST, "bloque", FILTER_SANITIZE_NUMBER_INT);// +$ciclo = filter_input(INPUT_POST, "ciclo", FILTER_SANITIZE_NUMBER_INT);// $fecha_falta = trim(htmlspecialchars($_POST["fecha_falta"], ENT_QUOTES, "UTF-8"));//limpia texto $fecha = trim(htmlspecialchars($_POST["fecha_inicial"], ENT_QUOTES, "UTF-8"));//limpia texto $fecha_cambio = trim(htmlspecialchars($_POST["fecha_cambio"], ENT_QUOTES, "UTF-8"));//limpia texto diff --git a/action/reposicion_select.php b/action/reposicion_select.php index a4d2bfd..a8d4193 100644 --- a/action/reposicion_select.php +++ b/action/reposicion_select.php @@ -7,7 +7,12 @@ $ruta = "../"; require_once "../class/c_login.php"; // check if the session is started -$user = Login::get_user(); +if (!isset($_SESSION['user'])) + die('No se ha iniciado sesión'); + +$user = unserialize($_SESSION['user']); + + //--- Objeto para validar usuario. El id de usuario lo lee desde sesión /*if(!$objSesion->tieneAcceso()){ $return["error"] = "Error! No tienes permisos para realizar esta acción."; @@ -25,6 +30,7 @@ $user = Login::get_user(); }catch(Exception $e){ $return["error"] = "Ocurrió un error al leer los datos de la reposición."; echo json_encode($return); + exit(); } @@ -36,15 +42,16 @@ $user = Login::get_user(); $hora_nueva_fin = explode(":",$rs["hora_nueva_fin"]); $return["hora_fin"] = $hora_nueva_fin[0]; $return["min_fin"] = $hora_nueva_fin[1]; - $return["duracion"] = $rs["duracion_total"]; + $return["duracion"] = $rs["duracion_interval"]; // $return["carrera"] = $rs["PlanEstudio_desc"]; $return["horario"] = $rs["horario_id"]; $return["materia"] = $rs["materia_id"]; $return["materia_desc"] = $rs["materia_nombre"]; $return["salon"] = $rs["salon_id"]; - $return["salon_desc"] = $rs["Salon_desc"]=="" ? "-Pendiente-": $rs["Salon_desc"]; - $return["grupo"] = $rs["horario_grupo"]; + $return["salon_desc"] = $rs["salon"]=="" ? "-Pendiente-": $rs["salon"]; + $return["ciclo"] = $rs["ciclo"]; + $return["bloque"] = $rs["bloque"]; $return["profesor"] = $rs["profesor_id"]; $return["profesor_nombre"] = $rs["profesor_nombre"]; $return["comentario"] = $rs["descripcion"]; @@ -54,6 +61,8 @@ $user = Login::get_user(); $return["aula_desc"] = $rs["tipoaula_nombre"]; $return["aula_supervisor"] = $rs["tipoaula_supervisor"]; $return["dia"] = date('w', strtotime($rs["fecha_clase"])); + $return["motivo_cancelacion"] = $rs["motivo_cancelacion"]; + $return["estado"] = $rs["estado_reposicion_id"]; } echo json_encode($return); ?> diff --git a/action/reposicion_update.php b/action/reposicion_update.php index 5f692fe..04c949b 100644 --- a/action/reposicion_update.php +++ b/action/reposicion_update.php @@ -8,46 +8,58 @@ $ruta = "../"; require_once "../class/c_login.php"; // check if the session is started -$user = Login::get_user(); +if (!isset($_SESSION['user'])) + die('No se ha iniciado sesión'); + +$user = unserialize($_SESSION['user']); + + /*if(!isset($_POST["id"]) || !isset($_POST["fecha_falta"]) || !isset($_POST["fecha_inicial"]) || !isset($_POST["hora_ini"]) || !isset($_POST["min_ini"]) || !isset($_POST["materia"]) || !isset($_POST["grupo"])){ header("Location: ".$pag."?error=0"); exit(); }*/ $id = filter_input(INPUT_POST, "id", FILTER_SANITIZE_NUMBER_INT);//limpia texto -$fecha_falta = trim(filter_input(INPUT_POST, "fecha_falta", FILTER_SANITIZE_STRING,array('flags' => FILTER_FLAG_STRIP_LOW)));//limpia texto -$fecha = trim(filter_input(INPUT_POST, "fecha_inicial", FILTER_SANITIZE_STRING,array('flags' => FILTER_FLAG_STRIP_LOW)));//limpia texto -$fecha_cambio = trim(filter_input(INPUT_POST, "fecha_cambio", FILTER_SANITIZE_STRING,array('flags' => FILTER_FLAG_STRIP_LOW)));//limpia texto +$duracion_id = filter_input(INPUT_POST, "duracion", FILTER_SANITIZE_NUMBER_INT);//Id reposicion +$bloque = filter_input(INPUT_POST, "bloque", FILTER_SANITIZE_NUMBER_INT);// +$ciclo = filter_input(INPUT_POST, "ciclo", FILTER_SANITIZE_NUMBER_INT);// +$fecha_falta = trim(htmlspecialchars($_POST["fecha_falta"], ENT_QUOTES, "UTF-8"));//limpia texto +$fecha = trim(htmlspecialchars($_POST["fecha_inicial"], ENT_QUOTES, "UTF-8"));//limpia texto +$fecha_cambio = trim(htmlspecialchars($_POST["fecha_cambio"], ENT_QUOTES, "UTF-8"));//limpia texto $hora_ini = filter_input(INPUT_POST, "hora_ini", FILTER_SANITIZE_NUMBER_INT);//limpia texto $min_ini = filter_input(INPUT_POST, "min_ini", FILTER_SANITIZE_NUMBER_INT);//limpia texto $hor = filter_input(INPUT_POST, "horario", FILTER_SANITIZE_NUMBER_INT);//limpia texto -$prof = $_SESSION["usuario_id"]; -//if(isset($_POST["salon"]) && $_POST["salon"] != "") -//$salon = trim(filter_input(INPUT_POST, "salon", FILTER_SANITIZE_STRING,array('flags' => FILTER_FLAG_STRIP_LOW)));//limpia texto -$comentario = trim(filter_input(INPUT_POST, "comentario", FILTER_SANITIZE_STRING,array('flags' => FILTER_FLAG_STRIP_LOW)));//limpia texto - $alumnos = filter_input(INPUT_POST, "alumnos", FILTER_SANITIZE_NUMBER_INT);//limpia texto $tipo = filter_input(INPUT_POST, "tipo", FILTER_SANITIZE_NUMBER_INT);//1 Repo , 0 Cambio $aula = filter_input(INPUT_POST, "aula", FILTER_SANITIZE_NUMBER_INT);//1 regular , 2 sala computo, 3 otro facultad -$comentario = trim(filter_input(INPUT_POST, "comentario", FILTER_SANITIZE_STRING,array('flags' => FILTER_FLAG_STRIP_LOW)));//limpia texto -$horario_rs = $db->querySingle('SELECT * from fs_horario_basic where id = :hor', +if(empty($_POST["prof"])) + $prof = $user["id"]; +else + $prof = filter_input(INPUT_POST, "prof", FILTER_SANITIZE_NUMBER_INT);//limpia texto + +//if(isset($_POST["salon"]) && $_POST["salon"] != "") +//$salon = trim(filter_input(INPUT_POST, "salon", FILTER_SANITIZE_STRING,array('flags' => FILTER_FLAG_STRIP_LOW)));//limpia texto +$comentario = trim(htmlspecialchars($_POST["comentario"], ENT_QUOTES, "UTF-8"));//limpia texto + +$duracion_rs = $db->querySingle("select * from duracion where duracion_id = :id", [":id"=>$duracion_id]); +$duracion_tiempo = $duracion_rs["duracion_interval"]; + +$horario_rs = $db->querySingle('SELECT * from horario_view where horario_id = :hor', [':hor' => $hor] ); $materia = $horario_rs["materia_id"]; -$gpo = $horario_rs["grupo"]; -$duracion = $horario_rs["duracion_total"]; -$dia = $horario_rs["dia"]; +$dia = $horario_rs["horario_dia"]; $hora = $hora_ini.":".$min_ini.":00"; $fecha_new = DateTime::createFromFormat('d/m/Y', $fecha)->format('Y-m-d')." ".$hora; -$fecha_fin_new = date("Y-m-d H:i:00", strtotime($fecha_new.' + '.$duracion.' minute')); +$fecha_fin_new = date("Y-m-d", strtotime($fecha_new))." ".$duracion_tiempo; $dia_new = date('w', strtotime($fecha_new)); -echo $fecha_new."
"; -echo $fecha_fin_new."
"; +//echo $fecha_new."
"; +//echo $fecha_fin_new."
"; if($tipo == 1){//Reposición $fecha_falta = DateTime::createFromFormat('d/m/Y', $fecha_falta)->format('Y-m-d'); $dia_falta = date('w', strtotime($fecha_falta)); @@ -76,40 +88,36 @@ if($tipo == 1){//Reposición //Valida que profesor no este en 2 reposiciones al mismo tiempo */ $traslape = $db->querySingle('SELECT * from traslape_profesor_reposicion(:prof, :fecha, :hora, :dur)', - [':prof' => $prof, ':fecha'=>$fecha_falta, ':hora'=>$hora, ':dur'=>$duracion] + [':prof' => $prof, ':fecha'=>DateTime::createFromFormat('d/m/Y', $fecha)->format('Y-m-d'), ':hora'=>$hora, ':dur'=>$duracion_tiempo] )["traslape_profesor_reposicion"]; if($traslape){ - header("Location:".$pag."?error=9"); + //header("Location:".$pag."?error=9"); + echo "traslape"; exit(); } - try{ - $db->query('SELECT * from fu_reposicion(:id, :f_falta, :f_nueva, :hora_nueva, NULL, 1, :desc, :alumnos, true, :aula)', - [':id'=> $id, ':f_falta' => $fecha_falta, ':f_nueva' => $fecha_new, ':hora_nueva' => $hora, - ':desc' => $comentario, ':alumnos' => $alumnos, ':aula' => $aula - ] - ); - }catch(Exception $e){ - header("Location: ".$pag."?error=2"); - exit(); - } + /* $log = new LogActividad(); $desc_log = "Actualiza reposición ID[".$id."] Fechas[".$fecha_ini."][".$fecha_fin."] Periodo[".$_SESSION["periodo_id"]."] Materia[".$materia."] Profesor[".$prof."] Salon[".$salon."] Horario[".$hor."]"; $log->appendLog($_SESSION["usuario_id"], $_SESSION["usuario_nombre"]." ".$_SESSION["usuario_apellidos"], $desc_log);*/ -}else{ +} - try{ - $db->query('SELECT * from fu_reposicion(:id, :f_falta, :f_nueva, :hora_nueva, NULL, 1, :desc, :alumnos, true, :aula)', - [':id'=> $id, ':f_falta' => $fecha_falta, ':f_nueva' => $fecha_new, ':hora_nueva' => $hora, - ':desc' => $comentario, ':alumnos' => $alumnos, ':aula' => $aula - ] - ); - }catch(Exception $e){ - header("Location: ".$pag."?error=2"); - exit(); - } - +try{ + $db->query('SELECT * from fu_reposicion_solicitud(:id, :f_falta, :f_nueva, :hora_nueva, NULL, 1, :desc, :alumnos, :aula, :duracion_id, NULL)', + [':id'=> $id, ':f_falta' => $fecha_falta, ':f_nueva' => $fecha_new, ':hora_nueva' => $hora, + ':desc' => $comentario, ':alumnos' => $alumnos, ':aula' => $aula, ':duracion_id' => $duracion_id + ] + ); +}catch(Exception $e){ + //header("Location: ".$pag."?error=2"); + print_r($e->getMessage()); + echo "SELECT * from fu_reposicion_solicitud(:id, :f_falta, :f_nueva, :hora_nueva, NULL, 1, :desc, :alumnos, :aula, :duracion_id, NULL)'"; + print_r( + [':id'=> $id, ':f_falta' => $fecha_falta, ':f_nueva' => $fecha_new, ':hora_nueva' => $hora, + ':desc' => $comentario, ':alumnos' => $alumnos, ':aula' => $aula, ':duracion_id' => $duracion_id + ]); + exit(); } header("Location: ".$pag); exit(); diff --git a/auditoria.php b/auditoria.php index fa630b2..f62b77d 100644 --- a/auditoria.php +++ b/auditoria.php @@ -313,8 +313,7 @@ - {{ registro.usuario_nombre - }} + {{ registro.usuario_nombre }}
Hora diff --git a/avisos.php b/avisos.php index d2481b7..e0c0fdf 100644 --- a/avisos.php +++ b/avisos.php @@ -8,6 +8,7 @@ + + + + + + + @@ -136,7 +160,7 @@ if(!empty($user->periodo)){
- periodo)){ ?> + periodo_id!= ""){ ?>
@@ -191,10 +215,10 @@ if(!empty($user->periodo)){ Nuevas reposiciones
+
+
+

Ciclo y bloque

+
+
+

Ciclo:

+
+
+

Bloque:

+
+
+

Tipo

@@ -438,6 +476,14 @@ if(!empty($user->periodo)){
+
+
+

Motivo de cancelación

+
+
+

+
+
@@ -495,12 +541,7 @@ if(!empty($user->periodo)){ ?> - - - - - - + periodo)){ var _periodo_fecha_final = ""; var datepickerOptions = { dateFormat: "dd/mm/yy", minDate:_periodo_fecha_inicial, maxDate:_periodo_fecha_final }; - $(document).ready(function(){ - $(".date-picker-filtro" ).datepicker(datepickerOptions); - $(".date-picker-filtro" ).datepicker( $.datepicker.regional[ "es" ] ); - $('#tab-tab').tab('show'); - }); function valida(){ periodo)){ } $(document).ready(function(){ - + $(".date-picker-filtro" ).datepicker(datepickerOptions); + $(".date-picker-filtro" ).datepicker( $.datepicker.regional[ "es" ] ); + $('#tab-tab').tab('show'); + $('#modal_confirm').on('show.bs.modal', function (event) { var button = $(event.relatedTarget); // Button that triggered the modal var id = button.parents("tr").data("id"); @@ -566,10 +605,11 @@ if(!empty($user->periodo)){ $('#modal_aprobar').on('show.bs.modal', function (event) { var button = $(event.relatedTarget); // Button that triggered the modal - //console.log(button.data("tipo")); + console.log("Abre:"+button.data("tipo")); var id = button.parents("tr").data("id"); var edo = button.data('tipo'); + //1 ver, 2 aprobar, 3 autorizar $("#edo").val(edo); $("#id").val(id); @@ -587,7 +627,9 @@ if(!empty($user->periodo)){ }else{ $("#modal_aprobar .rep-prof").text(result["profesor_nombre"]); - $("#modal_aprobar .rep-mat").text(result["materia_desc"]+" ["+result["grupo"]+"]" ); + $("#modal_aprobar .rep-mat").text(result["materia_desc"]); + $("#modal_aprobar .rep-ciclo").text(result["ciclo"]); + $("#modal_aprobar .rep-bloque").text(result["bloque"]); if(result["tipo"]) $("#modal_aprobar .rep-tipo").text("Reposición"); else @@ -605,14 +647,21 @@ if(!empty($user->periodo)){ $("#modal_aprobar .rep-comentarios").text(result["comentario"]); $('#modal_aprobar .rep-alumnos').text(result["alumnos"]); - if(button.data("tipo") == 1){//ver + if(result["estado"] == 4){//cancelada + $('#modal_aprobar .rep-motivo').text(result["motivo_cancelacion"]); + $("#cancelada-block").show(); + }else{ + $("#cancelada-block").hide(); + } + + if(edo == 1){// 1 ver $("#modalLabel").text("Detalle de reposición"); $(".aprobar-block").hide(); $("#salon-ver").show(); $("#salon-editar").hide(); }else{ - if(parseInt($("#modal_aprobar .rep-aula").data("aula")) == 1){//ver + if(parseInt($("#modal_aprobar .rep-aula").data("aula")) == 1){//tipo aula 1 (salon normal) - ver $("#modalLabel").text("Detalle de reposición"); $(".aprobar-block").hide(); $("#salon-ver").show(); @@ -620,7 +669,7 @@ if(!empty($user->periodo)){ }else{ $("#modalLabel").text("Aprobar reposición"); $(".aprobar-block").show(); - if(button.data("tipo") == 3){//aprobar (con salón) + if(edo == 3){//aprobar (con salón) $("#salon-ver").hide(); $("#salon-editar").show(); @@ -629,13 +678,13 @@ if(!empty($user->periodo)){ } if(result["aula_supervisor"]){//Solo supervisor - supervisor){ ?> + $("#salon-editar").attr("disabled", false); $("#salon-editar").attr("disabled", true); }else{// Facultad - supervisor){ ?> + $("#salon-editar").attr("disabled", false); $("#salon-editar").attr("disabled", true); diff --git a/reposiciones_crear.php b/reposiciones_crear.php index 7f792b1..01daf66 100644 --- a/reposiciones_crear.php +++ b/reposiciones_crear.php @@ -19,10 +19,10 @@ echo "|****|"; print_r($user->facultad["facultad_id"]); exit();*/ //profesor, admin, rol, facultad -/*if ($user->acceso === null || !$user->admin){ - die(header('Location: index.php')); +if ($user->acceso === null && !$user->admin){ + //die(header('Location: index.php')); exit(); -}*/ +} //if (!$user->admin && in_array($user->acceso, ['n'])) @@ -161,7 +161,7 @@ $fecha_fin_db = $date->format('Y-m-d'); query('SELECT * FROM fs_reposiciones_solicitud(:f_ini, :f_fin, :usr ,NULL, NULL)', [':f_ini' => $fecha_ini_db, ':f_fin' => $fecha_fin_db, ':usr' => $user->user["id"]]); - echo "SELECT * FROM fs_reposiciones_solicitud('$fecha_ini_db', '$fecha_fin_db', ".$user->user["id"]." ,NULL, NULL)".date("Y-m-d",strtotime($fecha_fin)); + ?>
@@ -755,6 +755,7 @@ $fecha_fin_db = $date->format('Y-m-d'); type: 'POST', dataType: 'json', data: { id: pid, }, + async: false, success: function(result) { if(result["error"]!= "" && result["error"] !== undefined){ triggerMessage(result["error"], "Error"); @@ -813,6 +814,7 @@ $fecha_fin_db = $date->format('Y-m-d'); $(this).prop('selected', true); } }); + console.log("fin materia click"); } }, @@ -870,8 +872,6 @@ $fecha_fin_db = $date->format('Y-m-d'); $("#modal .is-invalid").removeClass("is-invalid"); //$(this).find(".form-control:first-child").focus(); - - $("#errorBox").collapse('hide'); $("#errorBox_text").html(""); @@ -903,6 +903,7 @@ $fecha_fin_db = $date->format('Y-m-d'); //$("#materia").attr("readonly", true); disableDatalist("#horario"); disableDatalist("#tipo"); + disableDatalist("#prof"); /*if($("#prof").length>0) disableDatalist("#prof"); $("#prof").attr("readonly", true);*/ @@ -919,14 +920,16 @@ $fecha_fin_db = $date->format('Y-m-d'); $("#modal").modal('hide'); }else{ //setDatalist("#prof", result["profesor"]); - $('#salon').val(result["salon"]); + setDatalist("#prof", result["profesor"]) + //$('#salon').val(result["salon"]); $("#fecha_falta").val(result["fecha_clase"]); $('#hora_ini').val(result["hora_ini"]); $('#min_ini').val(result["min_ini"]); $('#comentario').val(result["comentario"]); $('#alumnos').val(result["alumnos"]); - setDatalist("#horario", result["horario"]); - setDatalist("#profesor", result["profesor"]); + $('#ciclo').val(result["ciclo"]); + $('#bloque').val(result["bloque"]); + if(result["tipo"]){ setDatalist("#tipo", 1); cambiaTipo(1); @@ -939,6 +942,8 @@ $fecha_fin_db = $date->format('Y-m-d'); _dia_valido = parseInt(result["dia"]); $(".date-picker" ).datepicker(datepickerOptions); $("#dlTipo ul li:selected").click(); + console.log("llega a cambio horario"+result["horario"]); + setTimeout(setDatalist("#horario", result["horario"]), 20);// No se actualiza TODO setDatalist("#aula", result["aula"]); modal.modal('show'); } @@ -950,7 +955,6 @@ $fecha_fin_db = $date->format('Y-m-d'); } });//ajax } - });//show }); diff --git a/ts/avisos.ts b/ts/avisos.ts index 3e2c2e4..a4fb012 100644 --- a/ts/avisos.ts +++ b/ts/avisos.ts @@ -1,6 +1,207 @@ import { createApp, reactive } from 'https://unpkg.com/petite-vue?module' +type Profesor = { + profesor_clave: string; + profesor_correo: null | string; + profesor_grado: null | string; + profesor_id: number; + profesor_nombre: string; +} + +type Carrera = { + carrera_activa: boolean; + carrera_comun: boolean; + carrera_id: number; + carrera_nombre: string; + clave_carrera: string; + facultad_id: number | null; + nivel_id: number; +} + +type Periodo = { + created_at: Date; + estado_id: number; + fecha_final: Date; + id_periodo_sgu: number; + nivel_id: number; + periodo_clave: string; + periodo_fecha_fin: Date; + periodo_fecha_inicio: Date; + periodo_id: number; + periodo_nombre: string; +} + +type Aviso = { + aviso_estado: boolean; + aviso_titulo: string; + aviso_fecha_final: Date; + aviso_fecha_inicial: Date; + aviso_id: number; + aviso_texto: string; + carreras: Carrera[]; + facultad_id: null; + profesores: Profesor[]; +} + +const new_aviso = reactive({ + titulo: '', + descripcion: '', + fechaInicio: '', + fechaFin: '', + profesores: [] as Array, + carreras: [] as Array, + reset() { + this.titulo = '' + this.descripcion = '' + this.fechaInicio = '' + this.fechaFin = '' + this.profesores = [] + this.carreras = [] + }, + get isValid() { + return this.titulo !== '' && this.descripcion !== '' && this.fechaInicio !== '' && this.fechaFin !== '' && (this.profesores.length > 0 || this.carreras.length > 0) && this.facultad_id !== null + }, +}) +// define datepicker method + const app = createApp({ - mounted() { + new_aviso, + profesores: [] as Array, + carreras: [] as Array, + avisos: [] as Array, + + profesor: null as String | null, + formatProfesor(profesor: Profesor) { + return `(${profesor.profesor_clave}) ${profesor.profesor_nombre}` + }, + addProfesor() { + const profesorObj = this.profesores.find((profesor: Profesor) => this.profesor === this.formatProfesor(profesor)) + if (profesorObj) { + this.new_aviso.profesores.push(profesorObj) + this.profesor = null + } + }, + + aviso_shown: null as Aviso | null, + // int? + aviso_suspendido: null as number | null, + suspenderAviso() { + if (this.aviso_suspendido) { + const aviso = this.avisos.find((aviso: Aviso) => aviso.aviso_id === this.aviso_suspendido) + if (aviso) { + this.deleteAviso(aviso) + } + } + }, + + get relevant_profesores() { + // not in array new_aviso.profesores + const relevant = this.profesores.filter((profesor: Profesor) => !this.new_aviso.profesores.map((profesor: Profesor) => profesor.profesor_id).includes(profesor.profesor_id)) + // console.log('profesores:', this.profesores.map((profesor: Profesor) => profesor.profesor_nombre), 'relevant:', relevant.map((profesor: Profesor) => profesor.profesor_nombre), 'new_aviso:', this.new_aviso.profesores.map((profesor: Profesor) => profesor.profesor_nombre)) + return relevant + }, + + get relevant_carreras() { + // not in array new_aviso.carreras + return this.carreras.filter((carrera: Carrera) => !this.new_aviso.carreras.includes(carrera)) + }, + + createAviso() { + const data = { + aviso_titulo: this.new_aviso.titulo, + aviso_texto: this.new_aviso.descripcion, + aviso_fecha_inicial: this.new_aviso.fechaInicio, + aviso_fecha_final: this.new_aviso.fechaFin, + profesores: this.new_aviso.profesores.map((profesor: Profesor) => profesor.profesor_id), + carreras: this.new_aviso.carreras.map((carrera: Carrera) => carrera.carrera_id), + } + fetch('/action/avisos.php', { + method: 'POST', + body: JSON.stringify(data) + }).then(res => res.json()).then(res => { + if (res.success) { + // hydrate with carreras and profesores + this.avisos.push({ + ...data, + carreras: this.carreras.filter((carrera: Carrera) => data.carreras.includes(carrera.carrera_id)), + profesores: this.profesores.filter((profesor: Profesor) => data.profesores.includes(profesor.profesor_id)), + aviso_estado: true, + aviso_id: res.aviso_id, + }) + this.new_aviso.reset() + } + else { + alert(res.error) + console.log(res.errors) + } + }) + }, + + deleteAviso(aviso: Aviso) { + fetch(`/action/avisos.php`, { + method: 'DELETE', + body: JSON.stringify({ aviso_id: aviso.aviso_id }) + }).then(res => res.json()).then(res => { + if (res.success) { + this.avisos = this.avisos.filter((aviso: Aviso) => aviso.aviso_id !== this.aviso_suspendido) + this.aviso_suspendido = null + } + else { + alert(res.error) + console.log(res.errors) + } + }) + }, + + updateAviso() { + fetch(`/action/avisos.php`, { + method: 'PUT', + body: JSON.stringify({ + aviso_id: this.aviso_shown.aviso_id, + aviso_fecha_final: this.aviso_shown.aviso_fecha_final, + }) + }).then(res => res.json()).then(res => { + if (res.success) { + } + else { + alert(res.error) + console.log(res.errors) + } + }) + }, + + async initializeDatepickers($el: HTMLElement) { + const periodo = await fetch('action/periodo_datos.php'); + const periodo_data = await periodo.json() as Periodo; + + $('.date-picker').datepicker({ + dateFormat: 'yy-mm-dd', + maxDate: periodo_data.periodo_fecha_fin, + minDate: 0, + }); + + $($el).on('change', () => { + this.aviso_shown.aviso_fecha_final = $($el).val() as string; + }); + }, + + async mounted() { + this.avisos = await fetch("/action/avisos.php").then(res => res.json()) as Array + this.profesores = await fetch('/action/action_profesor.php').then(res => res.json()) as Array + this.carreras = await fetch('/action/action_carreras.php').then(res => res.json()) as Array + + await this.initializeDatepickers() + + const fechaInicio = $('#fechaInicio.date-picker') + const fechaFin = $('#fechaFin.date-picker') + fechaInicio.on("change", function () { + new_aviso.fechaInicio = fechaInicio.val() as string + fechaFin.datepicker("option", "minDate", fechaInicio.val()); + }); + + fechaFin.on("change", function () { + new_aviso.fechaFin = fechaFin.val() as string + fechaInicio.datepicker("option", "maxDate", fechaFin.val()); + }); } }).mount('#app') \ No newline at end of file diff --git a/ts/declaration.ts b/ts/declaration.ts index 5cf2c7c..d6b8601 100644 --- a/ts/declaration.ts +++ b/ts/declaration.ts @@ -1 +1 @@ -declare module 'https://*' \ No newline at end of file +declare module 'https://*' diff --git a/tsconfig.json b/tsconfig.json index 886cab1..67dc9ce 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -8,7 +8,7 @@ "rootDir": "ts", "target": "ES2022", "moduleResolution": "node", - "module": "ESNext" + "module": "ESNext", // ts/auditoría.ts:1:37 - error TS2307: Cannot find module 'https://unpkg.com/petite-vue?module' or its corresponding type declarations. } } \ No newline at end of file