I am trying to make a version of fullcalendar that will load from a database and allow recurring events. This is my code.
<script>
$(document).ready(function() {
$.ajax({
url: 'process.php',
type: 'POST',
data: 'type=fetch',
async: false,
success: function(s){
json_events = s;
}
});
$('#calendar').fullCalendar({
events: JSON.parse(json_events),
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
defaultView: 'month',
editable: true,
slotDuration: '00:30:00',
eventRender: function(event){
return (event.ranges.filter(function(range){
return (event.start.isBefore(range.dowend) && event.end.isAfter(range.dowstart));
}).length) > 0;
},
eventReceive: function(event){
var title = event.title;
var start = event.start.format("YYYY-MM-DD[T]HH:mm:SS");
$.ajax({
url: 'process.php',
data: 'type=new&title='+title+'&startdate='+start+'&zone='+zone,
type: 'POST',
dataType: 'json',
success: function(response){
event.id = response.eventid;
$('#calendar').fullCalendar('updateEvent',event);
},
error: function(e){
console.log(e.responseText);
}
});
}
});
});
</script>
This is process.php
<?php
include('config.php');
{
$events = array();
$query = mysqli_query($con, "SELECT * FROM revent");
while($fetch = mysqli_fetch_array($query,MYSQLI_ASSOC))
{
$e = array();
$e['id'] = $fetch['id'];
$e['start'] = $fetch['start'];
$e['end'] = $fetch['end'];
$e['title'] = $fetch['title'];
$e['dow'] = $fetch['dow'];
$e['ranges'] = [ array("dowstart" => $fetch['dowstart'],"dowend" => $fetch['dowend'])];
$e['color'] = $fetch['color'];
array_push($events, $e);
}
echo json_encode($events);
};
?>
This is the relevant table
This is the json created by process.php
[
{"id":"1","start":"10:00","end":"12:00","title":"my event1","dow":"2","ranges":[{"dowstart":"2018-06-07","dowend":"2018-06-27"}],"color":"lightgreen"},
{"id":"2","start":"14:00","end":"18:00","title":"my event2","dow":"0,5","ranges":[{"dowstart":"2018-06-07","dowend":"2018-07-07"}],"color":"lightblue"},
{"id":"4","start":"14:00","end":"16:00","title":"my event3","dow":"1,4","ranges":[{"dowstart":"2018-06-07","dowend":"2018-07-07"}],"color":"pink"},
{"id":"5","start":"14:00","end":"16:00","title":"my event4","dow":"1,4","ranges":[{"dowstart":"2018-08-08","dowend":"2018-08-18"}],"color":"pink"}
]
This is working now! It needed this line $e['ranges'] = [ array("dowstart" => $fetch['dowstart'],"dowend" => $fetch['dowend'])]; and I changed ranges to range in eventRender.