"Please specify experience ID.")); exit(); } else if(!mysqli_query($connection, "SELECT * FROM experience WHERE id = '$experienceID';")) { http_response_code(400); echo json_encode(array("error" => "Given experience ID ($experienceID) not in database.")); exit(); } // Set the plugins of FullCalendar.io $plugins = array('dayGrid', 'timeGrid', 'interaction'); $calendarConfig = new stdClass(); $calendarConfig->plugins = $plugins; // Set the headers of FullCalendar.io $header->left = 'prev,next today'; $header->center = 'title'; $header->right = 'dayGridMonth,timeGridWeek,timeGridDay'; $calendarConfig->header = $header; // Get the start date of the experience... $queryExperience = "SELECT * FROM experience WHERE id = '$experienceID';"; $resultExperience = mysqli_query($connection, $queryExperience); $rowExperience = mysqli_fetch_assoc($resultExperience); $calendarConfig->defaultDate = $rowExperience['start_date']; // Add the start and end dates of the experience as background color... $startDate = new stdClass(); $startDate->start = $rowExperience['start_date']; $startDate->end = $rowExperience['start_date']; $startDate->overlap = true; $startDate->rendering = 'background'; $startDate->color = '#ff9f89'; $events[] = $startDate; $endDate = new stdClass(); $endDate->start = $rowExperience['end_date']; $endDate->end = $rowExperience['end_date']; $endDate->overlap = true; $endDate->rendering = 'background'; $endDate->color = '#ff9f89'; $events[] = $endDate; // Create a new event for each moment $queryMoments = "SELECT SQ.* FROM subquestionnair AS SQ JOIN experience_subquestionnair AS ES WHERE SQ.id = ES.id_subquestionnair AND ES.id_experience = '$experienceID';"; // $queryMoments = "SELECT * FROM `subquestionnair` WHERE id_questionnair IN (SELECT id_questionnair FROM `experience_questionnair` WHERE id_experience = '$experienceID');"; $resultMoments = mysqli_query($connection, $queryMoments); while($rowMoments = mysqli_fetch_assoc($resultMoments)) { // Create a new moment object that will contain the title, start date and end date... $moment = new stdClass(); $moment->id = $rowMoments['id'] . '-moment'; $moment->title = $rowMoments['title']; $moment->start = $rowMoments['date_to_administer'];//explode(" ", $rowMoments['date_to_administer'])[0]; // Compute end with expiry_time from experience... $computedEndTimestamp = strtotime($rowMoments['date_to_administer'] . ' + ' . $rowExperience['expiry_time'] .' minutes'); $moment->end = date('Y-m-d H:i:s', $computedEndTimestamp); // Add the remaining properties... $moment->durationEditable = false; $moment->color = '#40587C';//chooseColor($rowMoments['id_questionnair']); // Append the moment to the $events array $events[] = $moment; } // Create a new event for each milestone $queryMilestones = "SELECT * FROM `milestone` WHERE id_experience = '$experienceID';"; $resultMilestones = mysqli_query($connection, $queryMilestones); while($rowMilestones = mysqli_fetch_assoc($resultMilestones)) { // Create a new milestone object that will contain the title, start date and end date... $milestone = new stdClass(); $milestone->id = $rowMilestones['id'] . '-milestone'; $milestone->title = $rowMilestones['title']; $milestone->start = $rowMilestones['date']; $milestone->end = $rowMilestones['date']; $milestone->durationEditable = false; $milestone->color = '#A4262C';//chooseColor($row['id_experience']); // Append the milestone to the $events array $events[] = $milestone; } // Finally include all events... $calendarConfig->events = $events; // Other settings... // $calendarConfig->navLinks = true; $calendarConfig->businessHours = true; $calendarConfig->editable = true; echo json_encode($calendarConfig); } /* var calendarConfig = { plugins: [ 'dayGrid', 'timeGrid' ], header: { left: 'prev,next today', center: 'title', right: 'dayGridMonth,timeGridWeek,timeGridDay' }, events: [ { title: 'Halloween', start: '2019-10-31', end: '2019-10-31', color: 'orange' }, { title: 'Veteran\'s Day', start: '2019-11-11', end: '2019-11-11', color: 'blue' }, { title: 'ReuniĆ³n con Corrada', start: '2019-11-08', end: '2019-11-08', color: 'red' } ] }; */ ?>