diff --git a/src/appointment-feed.php b/src/appointment-feed.php deleted file mode 100644 index 0d1091e..0000000 --- a/src/appointment-feed.php +++ /dev/null @@ -1,8 +0,0 @@ - diff --git a/src/appointment_feed.php b/src/appointment_feed.php new file mode 100644 index 0000000..3a8b08f --- /dev/null +++ b/src/appointment_feed.php @@ -0,0 +1,40 @@ +modify("+{$row["duracion"]} minutes"); + $time_string = $time->format('H:i:s'); + $row += ["end" => $time_string]; + } +} + + +function renameArray($data){ + computeEndTime($data); + $events = array(); + foreach($data as $row){ + $events[] = array( + "id" => $row["id"], + "title" => "Cita de " . $row["apellido"], + "start" => $row["fecha"] . " " . $row["hora"], + "end" => $row["fecha"] . " " . $row["end"], + ); + } + return $events; +} + +function fetchDatabase(){ + $pdo = connectDatabase(); + $data = listEvents($pdo); + closeDatabase($pdo); + return $data; +} + + +$result = fetchDatabase(); +$events = renameArray($result); +echo json_encode($events); + +?> diff --git a/src/calendar.js b/src/calendar.js index b56b3eb..84da0a0 100644 --- a/src/calendar.js +++ b/src/calendar.js @@ -1,154 +1,28 @@ $(document).ready(function() { - var date = new Date(); + var calendar = $('#calendar').fullCalendar({ - var d = date.getDate(); + editable: true, - var m = date.getMonth(); + header: { + left: 'prev,next,today', + right: 'month,agendaWeek,agendaDay' + }, - var y = date.getFullYear(); + events: "appointment_feed.php", + selectable: true, - var calendar = $('#calendar').fullCalendar({ - - editable: true, - - header: { - - left: 'prev,next,today', - - center: 'patient', - - right: 'month,agendaWeek,agendaDay' - - }, - - - events: "appointment-feed.php", - - - eventRender: function(event, element, view) { - - if (event.allDay === 'true') { - - event.allDay = true; - - } else { - - event.allDay = false; - - } - - }, - - selectable: true, - - selectHelper: true, + selectHelper: true, select: function(start, end, allDay) { - $("#dialog-form").dialog({ modal: true, patient: event.paciente, width:450}); + $("#dialog-form").dialog({ modal: true, width:450}); + var date = $.fullCalendar.formatDate(start, 'YYYY-MM-DD'); - calendar.fullCalendar('renderEvent', - { + $("#fecha").val(date); + } - start: start, - - end: end, - - allDay: allDay - - }, - - - ); - - - calendar.fullCalendar('unselect'); - - }, - - - editable: true, - - eventDrop: function(event, delta) { - - var start = $.fullCalendar.formatDate(event.start, "Y-MM-DD HH:mm:ss"); - - var end = $.fullCalendar.formatDate(event.end, "Y-MM-DD HH:mm:ss"); - - $.ajax({ - - url: 'update_events.php', - - data: 'patient='+ event.patient+'&start='+ start +'&end='+ end +'&id='+ event.id , - - type: "POST", - - success: function(json) { - - alert("Updated Successfully"); - - } - - }); - - }, - - eventClick: function(event) { - - element.click(function() { }); - - - $.ajax({ - - type: "POST", - - url: "delete_event.php", - - data: "&id=" + event.id, - - success: function(json) { - - $('#calendar').fullCalendar('removeEvents', event.id); - - alert("Updated Successfully");} - - }); - - - }, - - eventResize: function(event) { - - var start = $.fullCalendar.formatDate(event.start, "yyyy-MM-dd HH:mm:ss"); - - var end = $.fullCalendar.formatDate(event.end, "yyyy-MM-dd HH:mm:ss"); - - $.ajax({ - - url: 'update_events.php', - - data: 'patient='+ event.patient+'&start='+ start +'&end='+ end +'&id='+ event.id , - - type: "POST", - - success: function(json) { - - alert("Updated Successfully"); - - } - - }); - - } - - - - }); - - - - }); +}); diff --git a/src/database.php b/src/database.php index 6a3822e..96bac8c 100644 --- a/src/database.php +++ b/src/database.php @@ -370,7 +370,9 @@ function configureCalendar($pdo, $data) function fetchCalendarEvents($pdo, $doctor) { - $query = "SELECT * from cita WHERE medico=?"; + $query = "SELECT cita.id, fecha, hora, duracion, medico, observaciones, apellido, documento_identificativo from cita + INNER JOIN paciente ON cita.paciente = paciente.id + WHERE medico=?"; $result = $pdo->prepare($query); $result->execute([$doctor]); $data = $result->fetchAll(PDO::FETCH_ASSOC);