Eventclick Full Callendar pass id to PHP

Asked

Viewed 172 times

1

I’ve managed to get the variable id in a div with this

$('#eventID_faturar_outro').val(event.id);

How can I pass the value of Event.id for php via jqueery, so I can check if there is an event id clicked in the database with PHP?

$resultado3 = "SELECT * FROM contas_receber WHERE id_evento = '".$id_evento."'";

$listaCliente3 = mysql_query($resultado3) or die (mysql_error());
while ($listagem3= mysql_fetch_array($listaCliente3)){
$nome_cliente = $listagem3 ["nome"];


}

Js

eventClick:  function(event, jsEvent, view) {
                         endtime = $.fullCalendar.moment(event.end).format('h:mm');
                         starttime = $.fullCalendar.moment(event.start).format('dddd, D MMMM YYYY, h:mm');
                         var mywhen = starttime + ' - ' + endtime;
                         $('#modalTitle_excluir').html(event.title);
                         $('#modalWhen_excluir').text(mywhen);
                         $('#eventID_excluir').val(event.id);
                         $('#calendarModal_calendar2').modal();
                         $('#eventID_faturar_outro').val(event.id);
                         $('#id_do_form_faturar').attr('data-formid', event.id);
                         $('div[identificador = "Mesbla"]').attr('id', 'resultado_empresa_' + event.id); 

                     },

Full JS of the code

$('#calendar2').fullCalendar({




                    height: 1500,
         businessHours: [ // specify an array instead
           {
             dow: [ 1, 2, 3, 4, 5, 6, 7 ], // Monday, Tuesday, Wednesday
             start: '07:00', // 8am
             end: '23:00' // 6pm
           }
         ],  

                    header: {
               left: 'prev,next',
               center: 'title',
               right: 'agendaFiveDay, agendaDay, month, listWeek'
             },

             views: {
               agendaFiveDay: {
                 type: 'agenda',
                 duration: { days: 2 }
               }

             },





            validRange: {
            start: moment().day(),         // data atual
            end:  moment().add(200, 'days') // data atual + 14 (15 com a data atual)
         },
                timeFormat: 'H:mm', //this will return 23:00 time format    
            groupByResource: true,      
                    defaultView: 'listWeek',
                   contentHeight: 'auto',
             groupByDateAndResource: true,
                     selectable: false,

                     allDaySlot: false,

             groupByResource: true,
             editable:true,




             /*  viewRender: function(i){
            var ini = moment();
            if(ini >= i.start && ini <= i.end){
               $(".fc-prev-button")
               .prop('disabled', true) 
               .addClass('fc-state-disabled'); 
            }else{
               $(".fc-prev-button")
               .removeClass('fc-state-disabled')
               .prop('disabled', false); 
            }
         },*/






                     events: "cadastrar_consultas_manoel.php?view2=1",


                     eventClick:  function(event, jsEvent, view) {
                         endtime = $.fullCalendar.moment(event.end).format('h:mm');
                         starttime = $.fullCalendar.moment(event.start).format('dddd, D MMMM YYYY, h:mm');
                         var mywhen = starttime + ' - ' + endtime;
                         $('#modalTitle_excluir').html(event.title);
                         $('#modalWhen_excluir').text(mywhen);
                         $('#eventID_excluir').val(event.id);
                         $('#calendarModal_calendar2').modal();
                         $('#eventID_faturar_outro').val(event.id);
                         $('#id_do_form_faturar').attr('data-formid', event.id);
                         $('div[identificador = "Mesbla"]').attr('id', 'resultado_empresa_' + event.id); 

                         $('#modalTitle_excluir2').text('<? $id= '+event.id+'; ?>');

                     },

                     //header and other values
                     select: function(start, end, jsEvent) {
                         endtime = $.fullCalendar.moment(end).format('h:mm');
                         starttime = $.fullCalendar.moment(start).format('dddd, MMMM Do YYYY, h:mm');
                         var mywhen = starttime + ' - ' + endtime;
                         start = moment(start).format();
                         end = moment(end).format();
                         $('#createEventModal #startTime').val(start);
                         $('#createEventModal #endTime').val(end);
                         $('#createEventModal #when').text(mywhen);
                         $('#createEventModal').modal('toggle');
                    },
                    eventDrop: function(event, delta){
                        $.ajax({
                            url: 'cadastrar_consultas_manoel.php',
                            data:
'action=update&title='+event.title+'&start='+moment(event.start).format()+'&end='+moment(event.end).format()+'&id='+event.id ,
                            type: "POST",
                            success: function(json) {
                            //alert(json);
                            }
                        });
                    },
                    eventResize: function(event) {
                        $.ajax({
                            url: 'cadastrar_consultas_manoel.php',
                            data:
'action=update&title='+event.title+'&start='+moment(event.start).format()+'&end='+moment(event.end).format()+'&id='+event.id,
                            type: "POST",
                            success: function(json) {
                                //alert(json);
                            }
                        });
                    }
                 });

                $('#submitButton').on('click', function(e){
                    // We don't want this to act as a link so cancel the link action
                    e.preventDefault();
                    doSubmit();
                });

                $('#deleteButton').on('click', function(e){
             // We don't want this to act as a link so cancel the link action
             e.preventDefault();

             if (confirm('Realmente deseja excluir o registro?')) {
                 doDelete_excluir();
             }
         });

                function doDelete_excluir(){
                    $("#calendarModal_calendar2").modal('hide');
                    var eventID = $('#eventID_excluir').val();
                    $.ajax({
                        url: 'cadastrar_consultas_manoel.php',
                        data: 'action=delete&id='+eventID,
                        type: "POST",
                        success: function(json) {
                            if(json == 1)
                                 $("#calendar2").fullCalendar('removeEvents',eventID);
                            else
                                 return false;


                        }
                    });
                }
                function doSubmit(){
                    $("#createEventModal").modal('hide');
                    var title = $('#title').val();
                    var atendente = $('#atendente').val();
                    var startTime = $('#startTime').val();
                    var endTime = $('#endTime').val();



                    $.ajax({
                        url: 'cadastrar_consultas_manoel.php',
                        data: 'action=add&title='+title+'&atendente='+atendente+'&start='+startTime+'&end='+endTime,
                        type: "POST",
                        success: function(json) {
                            $("#calendar2").fullCalendar('renderEvent',
                            {
                                id: json.id,
                                title: title,
                                atendente: atendente,
                                start: startTime,
                                end: endTime,
                            },
                            true);
                        }
                    });

                }
            $('#calendar2').fullCalendar('option', 'locale', 'pt-br');


             });

Html Modal

<div id="calendarModal_calendar2" class="modal fade">
                     <div class="modal-dialog">
                        <div class="modal-content">
                           <div class="modal-header">
                              <h4 class="modal-title center">Detalhes da Consulta</h4>
                              <button type="button" class="close pull-right" data-dismiss="modal">&times;</button>
                           </div>
                           <div id="modalBody" class="modal-body">
                              <span class="titulo_modal">Título</span>
                              <h4 id="modalTitle_excluir" class="modal-title"></h4>

                              <h4 id="modalTitle_excluir2" class="modal-title"></h4>

                              <span class="titulo_modal">Data e Hora</span>
                              <div id="modalWhen_excluir" style="margin-top:5px;"></div>
                              <div class="modal-footer">
                                 <form role="form" id="formId" action="" method="post">
                                    <input type="hidden" id="eventID_excluir" name="eventID_excluir"/>
                                    <input type="hidden" id="modalTitle_excluirs" name="modalTitle_excluirs"/>
                                    <input type="hidden" id="eventID" value="eventID_excluir">
                                    <button type="submit"  name="desmarcar" onclick="clicked(event)"  id="desmarcar" class="btn btn-info
pull-right"><i class="fas fa-calendar-times"></i> Desmarcar Consulta</button>
                                    <input type="submit" name="editar" value="Editar" class="btn btn-info"></input>
                                    <button type="submit" class="btn btn-danger" id="deleteButton"><i class="fas fa-trash-alt"></i>
Excluir</button>
                                    <button class="btn" data-dismiss="modal" aria-hidden="true">Cancelar</button>
                                 </form>



                                 <form id="id_do_form_faturar" class="formAjax"  method="post" enctype="multipart/form-data">
                                    <input type="hidden" name="event_id" id="eventID_faturar_outro"  />
                                    <div id="resultado_empresa_" identificador="Mesbla"> <button type="submit" class="btn btn-light
btn-sm" style="border:0">Faturar</button>
                                    </div>
                                 </form>

                              </div>
                           </div>
                        </div>
                     </div>
                  </div>
  • 3

    You have to do an ajax, you would have to create a function that would do this search in the database and would return a json to the view with the information you want! give a look here https://stackoverflow.com/questions/9436534/ajax-tutorial-for-post-and-get

  • could show how to do this in practice by creating ajax function and returning a json with the event id? In the link that showed only ajax!

  • edited mimha reply with modal html and full Js code

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.