Ingen beskrivning

special2.php 5.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. <?php
  2. require_once 'processes/config.php';
  3. require_once 'processes/dbh.inc.php';
  4. require_once 'processes/checkLogin.php';
  5. /* THIS SCRIPT POPULATES THE CALENDAR WITH THE EXPERIENCE'S EVENTS */
  6. /*
  7. function chooseColor($string) {
  8. // Define color palette...
  9. $colors = [
  10. '#0074D9',
  11. '#7FDBFF',
  12. '#39CCCC',
  13. '#A4262C', // red
  14. '#CA5010', // orange
  15. '#8F7034', // gold
  16. '#407855', // green
  17. '#038387', // teal
  18. '#0078D4', // blue
  19. '#40587C', // dark blue
  20. '#4052AB', // indigo
  21. '#854085', // plum
  22. '#8764B8', // purple
  23. '#737373', // cool grey
  24. '#867365' // warm grey
  25. ];
  26. $hash = substr(sha1($string), 0, 10);
  27. $colorIndex = hexdec($hash) % count($colors);
  28. return $colors[$colorIndex];
  29. }
  30. */
  31. if(isset($_POST['experienceID'])) {
  32. // Extract experience ID and use it to retrieve the experience, moments, etc.
  33. $experienceID = mysqli_real_escape_string($connection, trim($_POST['experienceID']));
  34. // Check that experienceID is not an empty string
  35. // And that experienceID is in the database
  36. if($experienceID === "") {
  37. http_response_code(400);
  38. echo json_encode(array("error" => "Please specify experience ID."));
  39. exit();
  40. } else if(!mysqli_query($connection, "SELECT * FROM experience WHERE id = $experienceID;")) {
  41. http_response_code(400);
  42. echo json_encode(array("error" => "Given experience ID ($experienceID) not in database."));
  43. exit();
  44. }
  45. // Set the plugins of FullCalendar.io
  46. $plugins = array('dayGrid', 'timeGrid', 'interaction');
  47. $calendarConfig = new stdClass();
  48. $calendarConfig->plugins = $plugins;
  49. // Set the headers of FullCalendar.io
  50. $header->left = 'prev,next today';
  51. $header->center = 'title';
  52. $header->right = 'dayGridMonth,timeGridWeek,timeGridDay';
  53. $calendarConfig->header = $header;
  54. // Get the start date of the experience...
  55. $queryExperience = "SELECT * FROM experience WHERE id = $experienceID;";
  56. $resultExperience = mysqli_query($connection, $queryExperience);
  57. $rowExperience = mysqli_fetch_assoc($resultExperience);
  58. $calendarConfig->defaultDate = $rowExperience['start_date'];
  59. // Add the start and end dates of the experience as background color...
  60. $startDate = new stdClass();
  61. $startDate->start = $rowExperience['start_date'];
  62. $startDate->end = $rowExperience['start_date'];
  63. $startDate->overlap = true;
  64. $startDate->rendering = 'background';
  65. $startDate->color = '#ff9f89';
  66. $events[] = $startDate;
  67. $endDate = new stdClass();
  68. $endDate->start = $rowExperience['end_date'];
  69. $endDate->end = $rowExperience['end_date'];
  70. $endDate->overlap = true;
  71. $endDate->rendering = 'background';
  72. $endDate->color = '#ff9f89';
  73. $events[] = $endDate;
  74. // Create a new event for each moment
  75. $queryMoments = "SELECT * FROM `subquestionnair` WHERE id_questionnair IN (SELECT id_questionnair FROM `experience_questionnair` WHERE id_experience = $experienceID);";
  76. $resultMoments = mysqli_query($connection, $queryMoments);
  77. while($rowMoments = mysqli_fetch_assoc($resultMoments)) {
  78. // Create a new moment object that will contain the title, start date and end date...
  79. $moment = new stdClass();
  80. $moment->id = $rowMoments['id'] . '-moment';
  81. $moment->title = $rowMoments['title'];
  82. $moment->start = $rowMoments['date_to_administer'];//explode(" ", $rowMoments['date_to_administer'])[0];
  83. // Compute end with expiry_time from experience...
  84. $computedEndTimestamp = strtotime($rowMoments['date_to_administer'] . ' + ' . $rowExperience['expiry_time'] .' minutes');
  85. $moment->end = date('Y-m-d H:i:s', $computedEndTimestamp);
  86. // Add the remaining properties...
  87. $moment->durationEditable = false;
  88. $moment->color = '#40587C';//chooseColor($rowMoments['id_questionnair']);
  89. // Append the moment to the $events array
  90. $events[] = $moment;
  91. }
  92. // Create a new event for each milestone
  93. $queryMilestones = "SELECT * FROM `milestone` WHERE id_experience = $experienceID;";
  94. $resultMilestones = mysqli_query($connection, $queryMilestones);
  95. while($rowMilestones = mysqli_fetch_assoc($resultMilestones)) {
  96. // Create a new milestone object that will contain the title, start date and end date...
  97. $milestone = new stdClass();
  98. $milestone->id = $rowMilestones['id'] . '-milestone';
  99. $milestone->title = $rowMilestones['title'];
  100. $milestone->start = $rowMilestones['date'];
  101. $milestone->end = $rowMilestones['date'];
  102. $milestone->durationEditable = false;
  103. $milestone->color = '#A4262C';//chooseColor($row['id_experience']);
  104. // Append the milestone to the $events array
  105. $events[] = $milestone;
  106. }
  107. // Finally include all events...
  108. $calendarConfig->events = $events;
  109. // Other settings...
  110. // $calendarConfig->navLinks = true;
  111. $calendarConfig->businessHours = true;
  112. $calendarConfig->editable = true;
  113. echo json_encode($calendarConfig);
  114. }
  115. /*
  116. var calendarConfig = {
  117. plugins: [ 'dayGrid', 'timeGrid' ],
  118. header: {
  119. left: 'prev,next today',
  120. center: 'title',
  121. right: 'dayGridMonth,timeGridWeek,timeGridDay'
  122. },
  123. events: [
  124. {
  125. title: 'Halloween',
  126. start: '2019-10-31',
  127. end: '2019-10-31',
  128. color: 'orange'
  129. },
  130. {
  131. title: 'Veteran\'s Day',
  132. start: '2019-11-11',
  133. end: '2019-11-11',
  134. color: 'blue'
  135. },
  136. {
  137. title: 'Reunión con Corrada',
  138. start: '2019-11-08',
  139. end: '2019-11-08',
  140. color: 'red'
  141. }
  142. ]
  143. };
  144. */
  145. ?>