hotspot_answers.as.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * This file generates the ActionScript variables code used by the
  5. * HotSpot .swf
  6. * @package chamilo.exercise
  7. * @author Toon Keppens, Julio Montoya adding hotspot "medical" support
  8. */
  9. include('../inc/global.inc.php');
  10. // Set vars
  11. $questionId = intval($_GET['modifyAnswers']);
  12. $exe_id = intval($_GET['exe_id']);
  13. $from_db = isset($_GET['from_db']) ? $_GET['from_db'] : 0;
  14. $objQuestion = Question :: read($questionId);
  15. $TBL_ANSWERS = Database::get_course_table(TABLE_QUIZ_ANSWER);
  16. $documentPath = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document';
  17. $picturePath = $documentPath.'/images';
  18. $pictureName = $objQuestion->selectPicture();
  19. $pictureSize = getimagesize($picturePath.'/'.$objQuestion->selectPicture());
  20. $pictureWidth = $pictureSize[0];
  21. $pictureHeight = $pictureSize[1];
  22. $courseLang = $_course['language'];
  23. $course_code = Database::escape_string($_course['id']);
  24. $coursePath = $_course['path'];
  25. $answer_type = $objQuestion->selectType();
  26. $course_id = api_get_course_int_id();
  27. if ($answer_type == HOT_SPOT_DELINEATION) {
  28. // Query db for answers
  29. $sql = "SELECT id, answer, hotspot_coordinates, hotspot_type FROM $TBL_ANSWERS
  30. WHERE c_id = $course_id AND question_id = ".intval($questionId)." AND hotspot_type <> 'noerror' ORDER BY id";
  31. } else {
  32. $sql = "SELECT id, answer, hotspot_coordinates, hotspot_type FROM $TBL_ANSWERS
  33. WHERE c_id = $course_id AND question_id = ".intval($questionId)." ORDER BY id";
  34. }
  35. $result = Database::query($sql);
  36. // Init
  37. $output = "hotspot_lang=$courseLang&hotspot_image=$pictureName&hotspot_image_width=$pictureWidth&hotspot_image_height=$pictureHeight&courseCode=$coursePath";
  38. $i = 0;
  39. while ($hotspot = Database::fetch_array($result)) {
  40. $output .= "&hotspot_".$hotspot['id']."=true";
  41. // Square or rectancle
  42. if ($hotspot['hotspot_type'] == 'square' ) {
  43. $output .= "&hotspot_".$hotspot['id']."_type=square";
  44. }
  45. // Circle or ovale
  46. if ($hotspot['hotspot_type'] == 'circle') {
  47. $output .= "&hotspot_".$hotspot['id']."_type=circle";
  48. }
  49. // Polygon
  50. if ($hotspot['hotspot_type'] == 'poly') {
  51. $output .= "&hotspot_".$hotspot['id']."_type=poly";
  52. }
  53. // Delineation
  54. if ($hotspot['hotspot_type'] == 'delineation') {
  55. $output .= "&hotspot_".$hotspot['id']."_type=delineation";
  56. }
  57. // oar
  58. if ($hotspot['hotspot_type'] == 'oar') {
  59. $output .= "&hotspot_".$hotspot['id']."_type=delineation";
  60. }
  61. $output .= "&hotspot_".$hotspot['id']."_coord=".$hotspot['hotspot_coordinates']."";
  62. $i++;
  63. }
  64. // Generate empty (the maximum number of points is 12 - it is said so in the user interface)
  65. $i++;
  66. for ($i; $i <= 12; $i++) {
  67. $output .= "&hotspot_".$i."=false";
  68. }
  69. // Get clicks
  70. if(isset($_SESSION['exerciseResultCoordinates']) && $from_db==0) {
  71. foreach ($_SESSION['exerciseResultCoordinates'][$questionId] as $coordinate) {
  72. $output2 .= $coordinate."|";
  73. }
  74. } else {
  75. // get it from db
  76. $tbl_track_e_hotspot = Database::get_main_table(TABLE_STATISTIC_TRACK_E_HOTSPOT);
  77. $sql = "SELECT hotspot_coordinate
  78. FROM $tbl_track_e_hotspot
  79. WHERE hotspot_question_id = $questionId AND
  80. c_id = $course_id AND
  81. hotspot_exe_id = $exe_id
  82. ORDER by hotspot_id";
  83. $rs = @Database::query($sql); // don't output error because we are in Flash execution.
  84. while($row = Database :: fetch_array($rs)) {
  85. $output2 .= $row['hotspot_coordinate']."|";
  86. }
  87. }
  88. $output .= "&p_hotspot_answers=".api_substr($output2,0,-1)."&done=done";
  89. $explode = explode('&', $output);
  90. echo $output;