설명 없음

special2.php 5.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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 SQ.* FROM subquestionnair AS SQ JOIN experience_subquestionnair AS ES WHERE SQ.id = ES.id_subquestionnair AND ES.id_experience = '$experienceID';";
  76. // $queryMoments = "SELECT * FROM `subquestionnair` WHERE id_questionnair IN (SELECT id_questionnair FROM `experience_questionnair` WHERE id_experience = '$experienceID');";
  77. $resultMoments = mysqli_query($connection, $queryMoments);
  78. while($rowMoments = mysqli_fetch_assoc($resultMoments)) {
  79. // Create a new moment object that will contain the title, start date and end date...
  80. $moment = new stdClass();
  81. $moment->id = $rowMoments['id'] . '-moment';
  82. $moment->title = $rowMoments['title'];
  83. $moment->start = $rowMoments['date_to_administer'];//explode(" ", $rowMoments['date_to_administer'])[0];
  84. // Compute end with expiry_time from experience...
  85. $computedEndTimestamp = strtotime($rowMoments['date_to_administer'] . ' + ' . $rowExperience['expiry_time'] .' minutes');
  86. $moment->end = date('Y-m-d H:i:s', $computedEndTimestamp);
  87. // Add the remaining properties...
  88. $moment->durationEditable = false;
  89. $moment->color = '#40587C';//chooseColor($rowMoments['id_questionnair']);
  90. // Append the moment to the $events array
  91. $events[] = $moment;
  92. }
  93. // Create a new event for each milestone
  94. $queryMilestones = "SELECT * FROM `milestone` WHERE id_experience = '$experienceID';";
  95. $resultMilestones = mysqli_query($connection, $queryMilestones);
  96. while($rowMilestones = mysqli_fetch_assoc($resultMilestones)) {
  97. // Create a new milestone object that will contain the title, start date and end date...
  98. $milestone = new stdClass();
  99. $milestone->id = $rowMilestones['id'] . '-milestone';
  100. $milestone->title = $rowMilestones['title'];
  101. $milestone->start = $rowMilestones['date'];
  102. $milestone->end = $rowMilestones['date'];
  103. $milestone->durationEditable = false;
  104. $milestone->color = '#A4262C';//chooseColor($row['id_experience']);
  105. // Append the milestone to the $events array
  106. $events[] = $milestone;
  107. }
  108. // Finally include all events...
  109. $calendarConfig->events = $events;
  110. // Other settings...
  111. // $calendarConfig->navLinks = true;
  112. $calendarConfig->businessHours = true;
  113. $calendarConfig->editable = true;
  114. echo json_encode($calendarConfig);
  115. }
  116. /*
  117. var calendarConfig = {
  118. plugins: [ 'dayGrid', 'timeGrid' ],
  119. header: {
  120. left: 'prev,next today',
  121. center: 'title',
  122. right: 'dayGridMonth,timeGridWeek,timeGridDay'
  123. },
  124. events: [
  125. {
  126. title: 'Halloween',
  127. start: '2019-10-31',
  128. end: '2019-10-31',
  129. color: 'orange'
  130. },
  131. {
  132. title: 'Veteran\'s Day',
  133. start: '2019-11-11',
  134. end: '2019-11-11',
  135. color: 'blue'
  136. },
  137. {
  138. title: 'Reunión con Corrada',
  139. start: '2019-11-08',
  140. end: '2019-11-08',
  141. color: 'red'
  142. }
  143. ]
  144. };
  145. */
  146. ?>