123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200 |
- <?php
-
- require_once 'processes/config.php';
- require_once 'processes/dbh.inc.php';
- require_once 'processes/checkLogin.php';
-
- /* THIS SCRIPT POPULATES THE CALENDAR WITH THE EXPERIENCE'S EVENTS */
-
- /*
- function chooseColor($string) {
-
- // Define color palette...
- $colors = [
- '#0074D9',
- '#7FDBFF',
- '#39CCCC',
- '#A4262C', // red
- '#CA5010', // orange
- '#8F7034', // gold
- '#407855', // green
- '#038387', // teal
- '#0078D4', // blue
- '#40587C', // dark blue
- '#4052AB', // indigo
- '#854085', // plum
- '#8764B8', // purple
- '#737373', // cool grey
- '#867365' // warm grey
- ];
-
- $hash = substr(sha1($string), 0, 10);
- $colorIndex = hexdec($hash) % count($colors);
-
- return $colors[$colorIndex];
-
- }
- */
-
- if(isset($_POST['experienceID'])) {
-
-
- // Extract experience ID and use it to retrieve the experience, moments, etc.
- $experienceID = mysqli_real_escape_string($connection, trim($_POST['experienceID']));
-
-
- // Check that experienceID is not an empty string
- // And that experienceID is in the database
- if($experienceID === "") {
- http_response_code(400);
- echo json_encode(array("error" => "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'
- }
- ]
- };
-
-
-
-
- */
-
-
- ?>
|