Sin descripción

special2.php 5.8KB

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