343 lines
16 KiB
PHP
343 lines
16 KiB
PHP
<?php
|
|
require_once 'class/c_login.php';
|
|
require_once 'include/bd_pdo.php';
|
|
|
|
if(!isset($_SESSION['user'])){
|
|
header('Location: index.php');
|
|
exit;
|
|
}
|
|
else
|
|
$user = unserialize($_SESSION['user']);
|
|
$user->access();
|
|
if($user->acceso == null){
|
|
header('Location: main.php?error=1');
|
|
}else{
|
|
$user->print_to_log('Dias_festivos');
|
|
}
|
|
if(isset($_GET['facultad'])){
|
|
$fac = $_GET['facultad'];
|
|
}else if($user->admin){
|
|
$fac = null;
|
|
}else{
|
|
$fac = $user->facultad['facultad_id'];
|
|
}
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Días Festivos</title>
|
|
<link rel="stylesheet" href="css/jquery-ui.css">
|
|
<link rel="stylesheet" href="css/calendar.css">
|
|
<link rel="stylesheet" href="css/toggle.css" type="text/css">
|
|
<?php
|
|
include 'import/html_css_files.php';
|
|
?>
|
|
</head>
|
|
|
|
<body>
|
|
<?php
|
|
include "import/html_header.php";
|
|
html_header(
|
|
"DÍAS FESTIVOS",
|
|
"Gestión de Checador "
|
|
);
|
|
$user->access();
|
|
$fs_dias_festivos = query("SELECT * FROM fs_diasfestivos(:facultad, null, null, null) ORDER BY diasfestivos_dia", [':facultad' => $fac], false);
|
|
$fs_periodos = query("SELECT * FROM fs_periodos(null, null) WHERE estado = 'Activo'", null, false);
|
|
$fs_dias_festivos_generales = query("SELECT * FROM fs_diasfestivos(null, null) ORDER BY diasfestivos_dia", null, false);
|
|
?>
|
|
<main class="content marco">
|
|
<?php if($user->admin){ ?>
|
|
<div class="col-12 text-right">
|
|
<button type="button" class="btn btn-outline-secondary" data-toggle="modal" data-target="#modal" data-tipo="1"><span class="ing-mas ing-fw"></span> Agregar Día Festivo</button>
|
|
</div>
|
|
<?php } ?>
|
|
<div id="message"></div>
|
|
<!-- Tabla -->
|
|
<?php if($fs_dias_festivos || $fs_dias_festivos_generales){ ?>
|
|
<div class="row mt-3">
|
|
<div class="col-12 table-responsive">
|
|
<table class="table table-sm table-striped table-white">
|
|
<thead class="thead-dark">
|
|
<tr>
|
|
<th>Día</th>
|
|
<th>Periodo</th>
|
|
<th>Nivel</th>
|
|
<?php if($user->admin){ ?>
|
|
<th>Facultad</th>
|
|
<th>Acciones</th>
|
|
<?php } ?>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php foreach($fs_dias_festivos as $dia){ ?>
|
|
<tr data-id="<?= $dia['diasfestivos_id'] ?>" id="<?= $dia['diasfestivos_id'] ?>" data-periodo="1">
|
|
<td class="text-center"><?php $day = explode("-", $dia['diasfestivos_dia']);
|
|
echo $day['2']."-".$day['1']."-".$day['0'];
|
|
?></td>
|
|
<td class="text-center"><?= $dia['periodo_nombre'] ?></td>
|
|
<td class="text-center"><?= $dia['nivel_nombre'] ?></td>
|
|
<?php if($user->admin){ ?>
|
|
<td class="text-center"><?= $dia['facultad_nombre'] ?></td>
|
|
<td class="text-center icono-acciones">
|
|
<a href="#" data-toggle="modal" data-target="#modal" data-tipo="2" title="Editar"><span class="ing-editar ing-fw"></span></a>
|
|
<a href="#" data-toggle="modal" data-target="#modal_confirm" title="Borrar"><span class="ing-basura ing-fw"></span></a>
|
|
</td>
|
|
<?php } ?>
|
|
</tr>
|
|
<?php } ?>
|
|
<?php foreach($fs_dias_festivos_generales as $dia){ ?>
|
|
<tr data-id="<?= $dia['diasfestivos_id'] ?>" id="<?= $dia['diasfestivos_id'] ?>" data-periodo="0">
|
|
<td class="text-center"><?php $day = explode("-", $dia['diasfestivos_dia']);
|
|
echo $day['2']."-".$day['1']."-".$day['0'];
|
|
?></td>
|
|
<td class="text-center">Todos</td>
|
|
<td class="text-center">Todos</td>
|
|
<?php if($user->admin){ ?>
|
|
<td class="text-center">Todas</td>
|
|
<td class="text-center icono-acciones">
|
|
<a href="#" data-toggle="modal" data-target="#modal" data-tipo="2" title="Editar"><span class="ing-editar ing-fw"></span></a>
|
|
<a href="#" data-toggle="modal" data-target="#modal_confirm" title="Borrar"><span class="ing-basura ing-fw"></span></a>
|
|
</td>
|
|
<?php } ?>
|
|
</tr>
|
|
<?php } ?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
<?php } ?>
|
|
</main>
|
|
<!-- Footer -->
|
|
<?php
|
|
include "import/html_footer.php";
|
|
?>
|
|
<!-- Modal -->
|
|
<div class="modal fade" id="modal" tabindex="-1" role="dialog" aria-labelledby="modal" aria-hidden="true">
|
|
<div class="modal-dialog modal-dialog-centered" role="document">
|
|
<div class="modal-content">
|
|
<div class="modal-header">
|
|
<h4 class="col-12 modal-title text-center">
|
|
<span id="modalLabel">
|
|
Editar Día Festivo
|
|
</span>
|
|
<button type="button" class="close text-white" data-dismiss="modal" aria-label="Close">
|
|
<span aria-hidden="true">×</span>
|
|
</button>
|
|
</h4>
|
|
</div>
|
|
<div class="modal-body">
|
|
<form action="" method="post" id="formaModal" onsubmit="return valida_campos()">
|
|
<input type="hidden" name="id" id="id">
|
|
<div class="form-box">
|
|
<div class="form-group row">
|
|
<label for="periodo" class="col-3 col-form-label">Periodo *</label>
|
|
<div class="col-8">
|
|
<div class="datalist datalist-select mb-1 w-100">
|
|
<div class="datalist-input" id="fac">Mostrar todos</div>
|
|
<span class="ing-buscar icono"></span>
|
|
<ul style="display:none">
|
|
<li data-id="0" class="pl4-">Todos</li>
|
|
<?php foreach($fs_periodos as $periodo){ ?>
|
|
<li data-id="<?= $periodo['id'] ?>" class="pl4-"> <?php echo $periodo['periodo']." ".$periodo['facultad']." - ".$periodo['nivel']; ?></li>
|
|
<?php } ?>
|
|
</ul>
|
|
<input type="hidden" id="periodo" name="periodo" value="">
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="form-group row" id="rangoDiv">
|
|
<label for="rango" class="col-3 col-form-label">Rango</label>
|
|
<div class="col-8">
|
|
<input type="checkbox" data-toggle="toggle" data-onstyle="success" data-offstyle="danger" data-on="SI" data-off="NO" data-size="s" id="rango" name="rango">
|
|
</div>
|
|
</div>
|
|
<div class="form-group row" id="diasFestivos">
|
|
<label for="diaFestivo" class="col-3 col-form-label">Día festivo *</label>
|
|
<div class="col-4" id="dia">
|
|
<input id="diaFestivo" name="diaFestivo" type="text" class="form-control date-picker" placeholder="dd/mm/aaaa" maxlength="10" required="required" readonly="">
|
|
</div>
|
|
<div class="col-1 diaFestivoRango">
|
|
-
|
|
</div>
|
|
<div class="col-4 diaFestivoRango" id="diaFestivoRango">
|
|
<input id="diaFestivoFin" name="diaFestivoFin" type="text" class="form-control date-picker" placeholder="dd/mm/aaaa" maxlength="10" required="required" readonly="">
|
|
</div>
|
|
<div class="invalid-feedback">Debe seleccionar una fecha</div>
|
|
</div>
|
|
<div class="form-group row">
|
|
<div class="offset-4 col-8">
|
|
<button type="submit" class="btn btn-outline-primary" id="submitBtn" data-tipo="1">
|
|
<span class="ing-aceptar ing-fw"></span> Guardar
|
|
</button>
|
|
<button type="reset" class="btn btn-outline-danger" data-dismiss="modal">
|
|
<span class="ing-cancelar ing-fw"></span> Cancelar
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="modal fade" id="modal_confirm" tabindex="-1" role="dialog" aria-labelledby="modal" aria-hidden="true">
|
|
<div class="modal-dialog modal-dialog-centered" role="document">
|
|
<div class="modal-content">
|
|
<div class="modal-body">
|
|
<div class="row">
|
|
<div class="col">
|
|
<p class="font-weight-bold">¿Estás seguro de querer borrar el día festivo?</p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="modal-footer">
|
|
<input type="hidden" id="id_borrar" value="">
|
|
<button type="button" class="btn btn-outline-primary btn-borrar"><span class="ing-aceptar ing-fw"></span> Borrar</button>
|
|
<button type="button" class="btn btn-outline-danger" data-dismiss="modal" aria-label="Close"><span class="ing-cancelar ing-fw"></span> Cancelar</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<script src="js/jquery.min.js"></script>
|
|
<script src="js/jquery-ui.js"></script>
|
|
<script src="js/bootstrap/bootstrap.min.js"></script>
|
|
<script src="js/datalist.js"></script>
|
|
<script src="js/datepicker-es.js"></script>
|
|
<script src="js/toggle.js"></script>
|
|
<?php
|
|
require_once 'js/messages.php';
|
|
?>
|
|
<script>
|
|
$(document).ready(function(){
|
|
$('.diaFestivoRango').hide();
|
|
});
|
|
$('#rango').change(function(){
|
|
if($(this).is(':checked')){
|
|
$('#diaFestivoFin').val('');
|
|
$('.diaFestivoRango').show();
|
|
$('#diaFestivoFin').datepicker("setDate", today);
|
|
}
|
|
else{
|
|
$('.diaFestivoRango').hide();
|
|
}
|
|
});
|
|
|
|
$('#modal_confirm').on('show.bs.modal', function(event){
|
|
var button = $(event.relatedTarget);
|
|
var id = button.parents("tr").data("id");
|
|
$("#id_borrar").val(id);
|
|
});
|
|
|
|
$(".btn-borrar").click(function(){
|
|
var id = $("#id_borrar").val();
|
|
$.ajax({
|
|
url: 'action/action_diasfestivos_borra.php',
|
|
type: 'post',
|
|
dataType: 'json',
|
|
data:{id: id},
|
|
success:function(result){
|
|
location.reload();
|
|
},
|
|
error: function(){console.log("Error")}
|
|
});
|
|
});
|
|
|
|
var today = new Date();
|
|
$(".date-picker").datepicker($.datepicker.regional["es"]);
|
|
$(".date-picker").datepicker({
|
|
dateFormat: "dd/mm/yyyy",
|
|
changeMonth: true,
|
|
});
|
|
|
|
<?php if(!$fs_dias_festivos && !$fs_dias_festivos_generales){ ?>
|
|
triggerMessage("No se encontraron días festivos", "Error");
|
|
<?php } ?>
|
|
|
|
$('#modal').on('show.bs.modal', function (event){
|
|
var button = $(event.relatedTarget);
|
|
var tipo = button.data('tipo');
|
|
var modal = $(this);
|
|
if(tipo==1){//agregar
|
|
$('#modalLabel').html("Agregar Día Festivo");
|
|
$('#submitBtn').data('tipo', 1);
|
|
$('#diaFestivo').datepicker("setDate", today);
|
|
$('#diaFestivoFin').datepicker("setDate", today);
|
|
setDatalistFirst("#periodo");
|
|
$('#rangoDiv').show();
|
|
$('#dia').removeClass('col-9');
|
|
$('#dia').addClass('col-4');
|
|
}
|
|
else{
|
|
$('#modalLabel').html("Editar Día Festivo");
|
|
$('#submitBtn').data('tipo', 2);
|
|
$('#rangoDiv').hide();
|
|
$('#dia').removeClass('col-4');
|
|
$('#dia').addClass('col-9');
|
|
var id = $(event.relatedTarget).parents('tr').data('id');
|
|
var periodo = $(event.relatedTarget).parents('tr').data('periodo');
|
|
$.ajax({
|
|
url:"action/action_diasfestivos_select.php",
|
|
type:"post",
|
|
dataType:"json",
|
|
data:{id: id, periodo: periodo},
|
|
success:function(result){
|
|
console.log(result);
|
|
$('#id').val(result['diasfestivos_id']);
|
|
if(!result['periodo_id']){
|
|
setDatalist('#periodo', 0);
|
|
}else{
|
|
setDatalist('#periodo', result['periodo_id']);
|
|
}
|
|
var date = new Date(result['diasfestivos_dia']);
|
|
date.setDate(date.getDate() + 1);
|
|
$('#diaFestivo').datepicker("setDate", date);
|
|
},
|
|
error: function(){console.log("Error")}
|
|
});
|
|
}
|
|
});
|
|
|
|
function valida_campos(){
|
|
var error=false;
|
|
if($("#diaFestivo").val()==""){
|
|
$("#diaFestivo").addClass("is-invalid");
|
|
error=true;
|
|
}
|
|
var inicio = $("#diaFestivo").val();
|
|
var fin = $("#diaFestivoFin").val();
|
|
var aux = inicio.split("/");
|
|
inicio = aux[2] +"-"+ aux[1] +"-"+ aux[0];
|
|
aux = fin.split("/");
|
|
fin = aux[2] +"-"+ aux[1] +"-"+ aux[0];
|
|
console.log(inicio);
|
|
if((fin < inicio || fin == inicio) && $("#rango").is(':checked')){
|
|
$('#diaFestivoFin').addClass("is-invalid");
|
|
error=true;
|
|
}
|
|
if(error){
|
|
return false;
|
|
}else{
|
|
var btn = $("#submitBtn");
|
|
if(btn.data("tipo") == 2){//update
|
|
$("#formaModal").prop("action", "./action/action_diasfestivos_update.php");
|
|
}
|
|
else{//insert
|
|
$("#formaModal").prop("action", "./action/action_diasfestivos_insert.php");
|
|
}
|
|
}
|
|
}
|
|
|
|
<?php if(isset($_GET['error'])){
|
|
if($_GET['error'] == 1){ ?>
|
|
triggerMessage("Este dia festivo ya existe", "Error");
|
|
<?php }
|
|
} ?>
|
|
</script>
|
|
</body>
|
|
</html>
|