0
I have a system that I am using Fullcalendar for CRUD. It is working OK, but I was attack to a detail that had gone unnoticed. When the user drags a particular event to another date at the same time, I would like a modal informing that there is already an event at this time.
The structure is that way:
......
$.ajax({
url:"alterar-dia-agenda.php",
type:"POST",
data:{start:start,id:id},
success:function(sucesso){
$('#confirmar').modal('show');
temporiza();
setTimeout(function() {
$('.modal').modal('hide');
}, 2000);
calendar.fullCalendar('refetchEvents');
}
});
......
alter-agenda.php
public function alterarDiaAgenda($id,$titulo,$cor,$data){
$sqlVerificar = mysqli_query($this->conexao,"SELECT * FROM pe_agenda WHERE DataAgenda = IdAgenda = '".mysqli_real_escape_string($this->conexao,$id)."' AND '".mysqli_real_escape_string($this->conexao,$data)."';");
if(mysqli_num_rows($sqlVerificar) > 0){
//return algo;
}else{
mysqli_query($this->conexao,"UPDATE pe_agenda SET DataAgenda = '".$data."' WHERE IdAgenda = '".$id."';");
}
}
When the change occurs, it activates this modal:
<div class="modal fade" id="confirmar" role="dialog">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header btn-success">
<h4 class="modal-title text-center"><i class="fas fa-check"></i> Evento Alterado com sucesso!</h4>
</div>
</div>
</div>
</div>
But I would like to do the same if there is an event at the same time, activate the modal below:
<div class="modal fade" id="erro" role="dialog">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header btn-danger">
<h4 class="modal-title text-center"><i class="fas fa-check"></i> Já existe um evento nesse horário!</h4>
</div>
</div>
</div>
</div>
In the archive
alterar-agenda.phpaddecho json_encode(["hasEvent" => mysqli_num_rows($sqlVerificar) > 0]);and in your Ajax utilizedataType: 'JSON',to indicate that you will receive an object and functionsuccessyou do the checkingif (sucesso.hasEvent) { /* Existe */ } else { /* Não Existe */ }. Ps.: Adding the code of thealterar-dia-agenda.phpmakes it easier to help you, but the logic is the same, returntruewhen an event already exists and otherwise returnfalse.– Valdeir Psr
Perfect Valdeir. It worked. Thank you very much!
– user24136