hotspot_answers.as.php 3.6 KB

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