Fix editar avisos
This commit is contained in:
@@ -2,30 +2,26 @@
|
||||
require_once 'class/c_login.php';
|
||||
require_once 'include/bd_pdo.php';
|
||||
|
||||
if(!isset($_SESSION['user'])){
|
||||
if (!isset($_SESSION['user'])) {
|
||||
header('Location: index.php');
|
||||
exit;
|
||||
}
|
||||
else
|
||||
} else
|
||||
$user = unserialize($_SESSION['user']);
|
||||
$user->access('Avisos');
|
||||
if(!$user->admin && $user->acceso == 'n'){
|
||||
if (!$user->admin && $user->acceso == 'n') {
|
||||
header('Location: main.php?error=1');
|
||||
}else{
|
||||
} else {
|
||||
$user->print_to_log('Avisos Editar');
|
||||
}
|
||||
$fac = $user->facultad['facultad_id'];
|
||||
if($user->admin){
|
||||
if ($user->admin) {
|
||||
$fac = null;
|
||||
}
|
||||
$fs_aviso = query('SELECT * FROM fs_aviso(:aviso_id, null, :facultad_id, null, 0, null)', [':aviso_id' => $_GET['id'], ':facultad_id' => $fac], true);
|
||||
$fs_carreras = query('SELECT * FROM fs_carreras(:fac, null, null)', [':fac' => $fs_aviso['facultad_id']], false);
|
||||
$fs_usr = query('SELECT * FROM fs_profesor_aviso(:aviso_id)', [':aviso_id' => $_GET['id']], false);
|
||||
$today = date('Y-m-d');
|
||||
$edit = true;
|
||||
if($today >= $fs_aviso['aviso_fecha_inicial']){
|
||||
$edit = false;
|
||||
}
|
||||
$edit = $today < $fs_aviso['aviso_fecha_inicial'];
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
@@ -61,12 +57,16 @@ if($today >= $fs_aviso['aviso_fecha_inicial']){
|
||||
<div class="form-group row">
|
||||
<label for="fecha_inicial" class="col-4 col-form-label">Fecha inicial</label>
|
||||
<div class="col-8 col-sm-4">
|
||||
<?php if($edit == true){ ?>
|
||||
<input id="fecha_inicial" name="fecha_inicial" type="text" class="form-control date-picker" placeholder="dd/mm/aaaa" maxlength="10" required="required" readonly="readonly" value="<?php $day = explode("-", $fs_aviso['aviso_fecha_inicial']); $dia_inicial = $day['2'].'/'.$day['1'].'/'.$day[0]; echo $dia_inicial;?>">
|
||||
<?php if ($edit) { ?>
|
||||
<input id="fecha_inicial" name="fecha_inicial" type="text" class="form-control date-picker" placeholder="dd/mm/aaaa" maxlength="10" required="required" readonly="readonly" value="<?php $day = explode("-", $fs_aviso['aviso_fecha_inicial']);
|
||||
$dia_inicial = $day['2'] . '/' . $day['1'] . '/' . $day[0];
|
||||
echo $dia_inicial; ?>">
|
||||
<div class="invalid-feedback">No es una fecha valida</div>
|
||||
<?php }else{ ?>
|
||||
<?php } else { ?>
|
||||
<div>
|
||||
<?php $day = explode("-", $fs_aviso['aviso_fecha_inicial']); $dia_inicial = $day['2'].'/'.$day['1'].'/'.$day[0]; echo $dia_inicial;?>
|
||||
<?php $day = explode("-", $fs_aviso['aviso_fecha_inicial']);
|
||||
$dia_inicial = $day['2'] . '/' . $day['1'] . '/' . $day[0];
|
||||
echo $dia_inicial; ?>
|
||||
</div>
|
||||
<?php } ?>
|
||||
</div>
|
||||
@@ -74,21 +74,23 @@ if($today >= $fs_aviso['aviso_fecha_inicial']){
|
||||
<div class="form-group row">
|
||||
<label for="fecha_final" class="col-4 col-form-label">Fecha Final *</label>
|
||||
<div class="col-8 col-sm-4">
|
||||
<input id="fecha_final" name="fecha_final" type="text" class="form-control date-picker" placeholder="dd/mm/aaaa" maxlength="10" required="required" readonly="readonly" value="<?php $day = explode("-", $fs_aviso['aviso_fecha_final']); $dia_final = $day['2'].'/'.$day['1'].'/'.$day[0]; echo $dia_final;?>">
|
||||
<input id="fecha_final" name="fecha_final" type="text" class="form-control date-picker" placeholder="dd/mm/aaaa" maxlength="10" required="required" readonly="readonly" value="<?php $day = explode("-", $fs_aviso['aviso_fecha_final']);
|
||||
$dia_final = $day['2'] . '/' . $day['1'] . '/' . $day[0];
|
||||
echo $dia_final; ?>">
|
||||
<div class="invalid-feedback">No es una fecha valida</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group row">
|
||||
<label for="texto" class="col-4 col-form-label">Aviso *</label>
|
||||
<div class="col-8">
|
||||
<?php if($edit == true){ ?>
|
||||
<?php if ($edit == true) { ?>
|
||||
<textarea name="texto" id="texto" class="richtext" rows="10" readonly="readonly"><?= $fs_aviso['aviso_texto'] ?></textarea>
|
||||
<?php }else{ ?>
|
||||
<?php } else { ?>
|
||||
<p><?= $fs_aviso['aviso_texto'] ?></p>
|
||||
<?php } ?>
|
||||
</div>
|
||||
</div>
|
||||
<?php if($edit){ ?>
|
||||
<?php if ($edit) { ?>
|
||||
<div class="form-group row tipo_aviso">
|
||||
<label class="col-4 col-form-label">Enviar aviso:</label>
|
||||
<div class="col-4 pt-2">
|
||||
@@ -127,8 +129,8 @@ if($today >= $fs_aviso['aviso_fecha_inicial']){
|
||||
<div class="col-10">
|
||||
<select name="usuario[]" id="usuario_box" class="form-control" multiple="multiple" size="5">
|
||||
<?php
|
||||
foreach($fs_usr as $usuario){
|
||||
echo "<option value='".$usuario['profesor_id']."'>".$usuario['profesor_nombre']."</option>";
|
||||
foreach ($fs_usr as $usuario) {
|
||||
echo "<option value='" . $usuario['profesor_id'] . "'>" . $usuario['profesor_nombre'] . "</option>";
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
@@ -140,16 +142,16 @@ if($today >= $fs_aviso['aviso_fecha_inicial']){
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php }else{
|
||||
$num_prof = round(count($fs_usr)/2);
|
||||
<?php } else {
|
||||
$num_prof = round(count($fs_usr) / 2);
|
||||
?>
|
||||
<h3>Profesores que recibirán el aviso</h3>
|
||||
<div class="row" style="max-height:400px; overflow-y:auto; overflow-x:hidden;">
|
||||
<div class="col-5">
|
||||
<div>
|
||||
<ul>
|
||||
<?php for($i = 0; $i < $num_prof; $i++){
|
||||
echo "<li>".$fs_usr[$i]['profesor_nombre']."</li>";
|
||||
<?php for ($i = 0; $i < $num_prof; $i++) {
|
||||
echo "<li>" . $fs_usr[$i]['profesor_nombre'] . "</li>";
|
||||
} ?>
|
||||
</ul>
|
||||
</div>
|
||||
@@ -157,8 +159,8 @@ if($today >= $fs_aviso['aviso_fecha_inicial']){
|
||||
<div class="col-5">
|
||||
<div>
|
||||
<ul>
|
||||
<?php for($i = $i; $i < count($fs_usr); $i++){
|
||||
echo "<li>".$fs_usr[$i]['profesor_nombre']."</li>";
|
||||
<?php for ($i = $i; $i < count($fs_usr); $i++) {
|
||||
echo "<li>" . $fs_usr[$i]['profesor_nombre'] . "</li>";
|
||||
} ?>
|
||||
</ul>
|
||||
</div>
|
||||
@@ -201,7 +203,7 @@ if($today >= $fs_aviso['aviso_fecha_inicial']){
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php $count = 1;
|
||||
foreach($fs_carreras as $carrera){ ?>
|
||||
foreach ($fs_carreras as $carrera) { ?>
|
||||
<tr class="tipo-row" id="arow_<?= $carrera['carrera_id'] ?>">
|
||||
<td><?= $carrera['carrera_nombre'] ?></td>
|
||||
<td class="text-center"><button type="button" class="btn btn-outline-primary btn-sm btn-agrega-tipo" data-id="<?= $carrera['carrera_id'] ?>" data-text="<?= $carrera['carrera_nombre'] ?>"><span class="ing-mas"></span></button></td>
|
||||
@@ -286,58 +288,57 @@ if($today >= $fs_aviso['aviso_fecha_inicial']){
|
||||
dateFormat: "dd/mm/yyyy",
|
||||
changeMonth: true,
|
||||
});
|
||||
$(document).ready(function(){
|
||||
$(document).ready(function() {
|
||||
$('.richtext').richText();
|
||||
$("#fecha_final").datepicker("option", "minDate", today);
|
||||
$("#fecha_inicial").datepicker("option", "minDate", today);
|
||||
<?php
|
||||
if(count($fs_usr) > 0){ ?>
|
||||
if (count($fs_usr) > 0) { ?>
|
||||
$('#bloque_usr').prop("checked", true);
|
||||
$('#administrativoBox').collapse('show');
|
||||
<? }
|
||||
if($edit == false){ ?>
|
||||
<?php } if ($edit == false) { ?>
|
||||
$('.richText-editor').removeAttr("contentEditable");
|
||||
<?php }
|
||||
?>
|
||||
|
||||
});
|
||||
|
||||
$(document).on( "change", ".tipo-switch", function(event){
|
||||
if($(this).data("box") !== undefined){
|
||||
if($(this).prop('checked')){
|
||||
$('#'+$(this).data("box")).collapse('show');
|
||||
}else{
|
||||
$('#'+$(this).data("box")).collapse('hide');
|
||||
$(document).on("change", ".tipo-switch", function(event) {
|
||||
if ($(this).data("box") !== undefined) {
|
||||
if ($(this).prop('checked')) {
|
||||
$('#' + $(this).data("box")).collapse('show');
|
||||
} else {
|
||||
$('#' + $(this).data("box")).collapse('hide');
|
||||
}
|
||||
}
|
||||
$('#bloque_tipo').removeClass("is-invalid");
|
||||
$('#bloque_usr').removeClass("is-invalid");
|
||||
});
|
||||
|
||||
$(document).on( "click", ".btn-agrega-tipo", function(event){
|
||||
$(document).on("click", ".btn-agrega-tipo", function(event) {
|
||||
var id = $(this).data("id");
|
||||
var text = $(this).data("text");
|
||||
if($('#tipo_box option[value="' + id + '"]').length == 0){
|
||||
$("#tipo_box").append($("<option></option>").attr("value",id).text(text));
|
||||
if ($('#tipo_box option[value="' + id + '"]').length == 0) {
|
||||
$("#tipo_box").append($("<option></option>").attr("value", id).text(text));
|
||||
}
|
||||
$(this).parents("tr").addClass("d-none");
|
||||
});
|
||||
|
||||
$(document).on( "click", ".btn-quita-tipo", function(event){
|
||||
$(document).on("click", ".btn-quita-tipo", function(event) {
|
||||
var id = $("#tipo_box option:selected").val();
|
||||
$("#arow_"+id).removeClass("d-none");
|
||||
$("#arow_" + id).removeClass("d-none");
|
||||
$("#tipo_box option:selected").remove();
|
||||
});
|
||||
|
||||
$(document).on( "click", ".modal-open", function(event){
|
||||
$(document).on("click", ".modal-open", function(event) {
|
||||
$(".area-row").removeClass("d-none");
|
||||
$('#area > option').each(function() {
|
||||
$("#row_"+$(this).val()).addClass("d-none");
|
||||
$("#row_" + $(this).val()).addClass("d-none");
|
||||
});
|
||||
$('#modal').modal("show");
|
||||
});
|
||||
|
||||
$(document).on('click', '#btn-busca-usr', function(event){
|
||||
$(document).on('click', '#btn-busca-usr', function(event) {
|
||||
var nombre = $('#filter_desc').val();
|
||||
var clave = $('#filter_clave').val();
|
||||
var fac = $('#facultad').val();
|
||||
@@ -346,25 +347,29 @@ if($today >= $fs_aviso['aviso_fecha_inicial']){
|
||||
url: 'action/usuario_find.php',
|
||||
type: 'POST',
|
||||
dataType: 'json',
|
||||
data: {nombre: nombre, clave: clave, facultad: fac},
|
||||
success: function(result){
|
||||
data: {
|
||||
nombre: nombre,
|
||||
clave: clave,
|
||||
facultad: fac
|
||||
},
|
||||
success: function(result) {
|
||||
console.log(result.length);
|
||||
$("#table-result-usr").find(".usr-nombre").html("");
|
||||
$("#table-result-usr").find(".usr-agrega button").addClass("invisible");
|
||||
var rows = $("#table-result-usr > tr").length;//limpia tabla actual
|
||||
if(rows > result.length){
|
||||
while(rows > result.length && rows > 1){
|
||||
var rows = $("#table-result-usr > tr").length; //limpia tabla actual
|
||||
if (rows > result.length) {
|
||||
while (rows > result.length && rows > 1) {
|
||||
$("#table-result-usr .usr-row:last-child").remove();
|
||||
rows--;
|
||||
}
|
||||
}else{
|
||||
for(var i=rows; i<result.length; i++){
|
||||
} else {
|
||||
for (var i = rows; i < result.length; i++) {
|
||||
$("#table-result-usr .usr-row:first-child").clone(true).appendTo("#table-result-usr");
|
||||
}
|
||||
}
|
||||
if(result.length != 0){
|
||||
$('#table-result-usr').children().each(function(index){
|
||||
if(index < result.length){
|
||||
if (result.length != 0) {
|
||||
$('#table-result-usr').children().each(function(index) {
|
||||
if (index < result.length) {
|
||||
$(this).find('.usr-nombre').html(result[index]['profesor_nombre']);
|
||||
$(this).find('.usr-agrega button').data("id", result[index]['profesor_id']);
|
||||
$(this).find('.usr-agrega button').data("text", result[index]['profesor_nombre']);
|
||||
@@ -374,53 +379,53 @@ if($today >= $fs_aviso['aviso_fecha_inicial']){
|
||||
})
|
||||
}
|
||||
},
|
||||
error: function(){
|
||||
error: function() {
|
||||
console.log('error');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
$(document).on( "click", ".btn-agrega-usr", function(event){
|
||||
$(document).on("click", ".btn-agrega-usr", function(event) {
|
||||
var id = $(this).data("id");
|
||||
var text = $(this).data("text");
|
||||
var rows = $("#table-result-usr > tr").length;//limpia tabla actual
|
||||
var rows = $("#table-result-usr > tr").length; //limpia tabla actual
|
||||
|
||||
if($('#usuario_box option[value="' + id + '"]').length == 0){
|
||||
$("#usuario_box").append($("<option></option>").attr("value",id).text(text));
|
||||
if ($('#usuario_box option[value="' + id + '"]').length == 0) {
|
||||
$("#usuario_box").append($("<option></option>").attr("value", id).text(text));
|
||||
}
|
||||
if(rows > 1)
|
||||
if (rows > 1)
|
||||
$(this).parents("tr").remove();
|
||||
else{
|
||||
else {
|
||||
$(this).parents("tr").hide();
|
||||
$("#filter_desc-usr").val("");
|
||||
}
|
||||
});
|
||||
|
||||
$(document).on( "click", ".btn-quita-usr", function(event){
|
||||
$(document).on("click", ".btn-quita-usr", function(event) {
|
||||
$("#usuario_box option:selected").remove();
|
||||
});
|
||||
|
||||
function validaCampos(){
|
||||
function validaCampos() {
|
||||
var error = false;
|
||||
var inicio = $('#fecha_inicial').val();
|
||||
var fin = $('#fecha_final').val();
|
||||
var aux = inicio.split('/');
|
||||
inicio = aux[2]+'-'+aux[1]+'-'+aux[0];
|
||||
inicio = aux[2] + '-' + aux[1] + '-' + aux[0];
|
||||
aux = fin.split('/');
|
||||
fin = aux[2]+'-'+aux[1]+'-'+aux[0];
|
||||
if(fin < inicio){
|
||||
fin = aux[2] + '-' + aux[1] + '-' + aux[0];
|
||||
if (fin < inicio) {
|
||||
$('#fecha_final').addClass('is-invalid');
|
||||
error = true;
|
||||
}
|
||||
if($('select').find('option').length == 0){
|
||||
if ($('select').find('option').length == 0) {
|
||||
error = true;
|
||||
$('.tipo_aviso').addClass('is-invalid');
|
||||
}else{
|
||||
} else {
|
||||
$('.tipo_aviso').removeClass('is-invalid');
|
||||
}
|
||||
if(error){
|
||||
if (error) {
|
||||
return false;
|
||||
}else{
|
||||
} else {
|
||||
$('#tipo_box option').prop('selected', true);
|
||||
$('#usuario_box option').prop('selected', true);
|
||||
$('#formaModal').prp('action', './action/action_avisos_update.php');
|
||||
@@ -428,4 +433,5 @@ if($today >= $fs_aviso['aviso_fecha_inicial']){
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
Reference in New Issue
Block a user